Inspector | Message | Severity | Location |
---|---|---|---|
Java Inspector 048 | Copyrights information should be present in each file. | 1 | |
Java Inspector 070-A | Cyclomatic complexity is too high: 14, maximum allowed is 12 | 2 | 65:9 |
Java Inspector 077 | To reduce probability of NullPointerException, use "string literal".equals(variable) instead of variable.equals("string literal"). | 2 | 70:43 |
Java Inspector 082 | Parenthesis are redundant. | 2 | 74:32 |
Java Inspector 089 | Undocumented field | 2 | 35:9 |
Java Inspector 089 | Undocumented constructor | 2 | 37:9 |
Java Inspector 089 | Undocumented method | 2 | 41:9 |
Java Inspector 089 | Undocumented method | 2 | 42:9 |
Java Inspector 089 | Undocumented method | 2 | 44:9 |
Java Inspector 089 | Method is not properly documented | 2 | 100:9 |
Java Inspector 089 | Undocumented method | 2 | 103:25 |
Java Inspector 089 | Undocumented method | 2 | 107:25 |
Java Inspector 024 | Avoid hardwired character literals | 3 | 77:38 |
Java Inspector 025 | Avoid hardwired numeric literals. Allowed literals: [1, -1, 0] | 3 | 74:110 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 66:37 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 70:44 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 71:28 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 73:44 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 79:45 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 83:32 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 87:32 |
Java Inspector 051 | It is good practice to call in any case super() in a constructor. | 3 | 37:9 |
Java Inspector 090 | Unnecessary else part in if. The main part terminates control flow (return, break, throw, or continue). | 3 | 66:17 |
Java Inspector 090 | Unnecessary else part in if. The main part terminates control flow (return, break, throw, or continue). | 3 | 71:24 |
1/*
2 * hgcommons 9
3 * Hammurapi Group Common Library
4 * Copyright (C) 2003 Hammurapi Group
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * URL: http://www.hammurapi.biz/hammurapi-biz/ef/xmenu/hammurapi-group/products/products/hgcommons/index.html
21 * e-Mail: support@hammurapi.biz
22 */
23package biz.hammurapi.config;
24
25import biz.hammurapi.util.Attributable;
26
27/**
28 * Helper class to navigate context trees. Follows unix filesystem naming convention: / is a path separator,
29 * . is current element, .. is parent element, absolute path starts with /
30 * @author Pavel Vlasov
31 * @revision $Revision$
32 */
33public abstract class PathNavigator implements Context {
34
35 protected Object master;
36
37 public PathNavigator(Object master) {
38 this.master=master;
39 }
40
41 protected abstract Object getParent();
42 protected abstract Object getChild(String name);
43
44 public Object get(String name) {
45 try {
46 Object ret=lookup(name);
47 if (ret instanceof Service) {
48 ((Service) ret).start();
49 }
50
51 if (ret instanceof Wrapper) {
52 ret = ((Wrapper) ret).getMaster();
53 }
54
55 if (ret instanceof Service) {
56 ((Service) ret).start();
57 }
58
59 return ret;
60 } catch (ConfigurationException e) {
61 throw new RuntimeConfigurationException(e);
62 }
63 }
64
65 private Object lookup(String name) {
66 if (name.startsWith("/")) {
67 if (getParent() instanceof Context) {
68 return ((Context) getParent()).get(name);
69 }
70 return name.equals("/") ? master : get(name.substring(1));
71 } else if ("..".equals(name)) {
72 return getParent();
73 } else if (name.startsWith("../")) {
74 return (getParent() instanceof Context) ? ((Context) getParent()).get(name.substring(3)) : null;
75 }
76
77 int idx=name.indexOf('/');
78 if (idx==-1) {
79 if (name.startsWith("@") && master instanceof Attributable) {
80 return ((Attributable) master).getAttribute(name.substring(1));
81 }
82
83 return ".".equals(name) ? master : getChild(name);
84 }
85
86 String nameElement = name.substring(0, idx);
87 Object child = ".".equals(nameElement) ? master : getChild(nameElement);
88 if (child instanceof Context) {
89 return ((Context) child).get(name.substring(idx+1));
90 }
91
92 return null;
93 }
94
95 /**
96 * @param master Master context.
97 * @param parent Parent object.
98 * @return Instance of PathNavigator.
99 */
100 public static Context newInstance(Context master, final Object parent) {
101 return new PathNavigator(master) {
102
103 protected Object getParent() {
104 return parent;
105 }
106
107 protected Object getChild(String name) {
108 return ((Context) master).get(name);
109 }
110
111 };
112 }
113
114}
115