1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package net.smartlab.config;
24
25 import java.util.Collection;
26
27
28
29
30 public class Reference extends Element {
31
32
33
34
35
36 protected final static String REFERENCE = "refid";
37
38
39
40
41 protected final static String IDENTIFIER = "id";
42
43
44
45
46 protected Node node;
47
48
49
50
51
52
53 protected String id;
54
55
56
57
58
59
60
61
62
63
64 protected Reference(Node parent, String name, String id) {
65 super(parent, name);
66 this.id = id;
67 }
68
69
70
71
72
73 public String getId() {
74 return id;
75 }
76
77
78
79
80 public Collection getElements() throws ConfigurationException {
81 if (node == null) {
82 node = parent.resolve(name, id);
83 }
84 try {
85 return node.getElements();
86 } catch (NullPointerException npe) {
87 throw new ConfigurationException("Undefined reference to node " + id);
88 }
89 }
90
91
92
93
94 public Collection getElements(String name) throws ConfigurationException {
95 if (node == null) {
96 node = parent.resolve(this.name, id);
97 }
98 try {
99 return node.getElements(name);
100 } catch (NullPointerException npe) {
101 throw new ConfigurationException("Undefined reference to node " + id);
102 }
103 }
104
105
106
107
108
109 public Element getElement(String name, String attribute, String value) throws ConfigurationException {
110 if (node == null) {
111 node = parent.resolve(this.name, id);
112 }
113 try {
114 return node.getElement(name, attribute, value);
115 } catch (NullPointerException npe) {
116 throw new ConfigurationException("Undefined reference to node " + id);
117 }
118 }
119
120
121
122
123 public Collection getAttributes() throws ConfigurationException {
124 if (node == null) {
125 node = parent.resolve(name, id);
126 }
127 try {
128 return node.getAttributes();
129 } catch (NullPointerException npe) {
130 throw new ConfigurationException("Undefined reference to node " + id);
131 }
132 }
133
134
135
136
137 public Collection getAttributeNames() throws ConfigurationException {
138 if (node == null) {
139 node = parent.resolve(name, id);
140 }
141 try {
142 return node.getAttributeNames();
143 } catch (NullPointerException npe) {
144 throw new ConfigurationException("Undefined reference to node " + id);
145 }
146 }
147
148
149
150
151 public String getAttribute(String name) throws ConfigurationException {
152 if (name.equalsIgnoreCase(REFERENCE)) {
153 return this.id;
154 }
155 if (node == null) {
156 node = parent.resolve(this.name, id);
157 }
158 try {
159 return node.getAttribute(name);
160 } catch (NullPointerException npe) {
161 throw new ConfigurationException("Undefined reference to node " + id);
162 }
163 }
164
165
166
167
168 public String getContent() throws ConfigurationException {
169 if (node == null) {
170 node = parent.resolve(name, id);
171 }
172 try {
173 return node.content;
174 } catch (NullPointerException npe) {
175 throw new ConfigurationException("Undefined reference to node " + id);
176 }
177 }
178
179
180
181
182 public void resolve() throws ConfigurationException {
183 if (node == null) {
184 node = parent.resolve(name, id);
185 }
186 }
187 }