1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.commons.configuration; |
18 |
|
|
19 |
|
import java.io.Reader; |
20 |
|
import java.io.Writer; |
21 |
|
import java.io.File; |
22 |
|
import java.io.InputStream; |
23 |
|
import java.io.OutputStream; |
24 |
|
import java.net.URL; |
25 |
|
import java.util.Iterator; |
26 |
|
|
27 |
|
import org.apache.commons.configuration.reloading.ReloadingStrategy; |
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
public abstract class AbstractHierarchicalFileConfiguration |
42 |
|
extends HierarchicalConfiguration implements FileConfiguration |
43 |
|
{ |
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
private FileConfigurationDelegate delegate = createDelegate(); |
48 |
|
|
49 |
|
protected AbstractHierarchicalFileConfiguration() |
50 |
|
{ |
51 |
|
} |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
public AbstractHierarchicalFileConfiguration(String fileName) throws ConfigurationException |
60 |
|
{ |
61 |
|
|
62 |
|
delegate.setPath(fileName); |
63 |
|
|
64 |
|
|
65 |
|
load(); |
66 |
|
} |
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
public AbstractHierarchicalFileConfiguration(File file) throws ConfigurationException |
75 |
|
{ |
76 |
|
|
77 |
|
setFile(file); |
78 |
|
|
79 |
|
|
80 |
|
if (file.exists()) |
81 |
|
{ |
82 |
|
load(); |
83 |
|
} |
84 |
|
} |
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
public AbstractHierarchicalFileConfiguration(URL url) throws ConfigurationException |
93 |
|
{ |
94 |
|
|
95 |
|
setURL(url); |
96 |
|
|
97 |
|
|
98 |
|
load(); |
99 |
|
} |
100 |
|
|
101 |
|
protected void addPropertyDirect(String key, Object obj) |
102 |
|
{ |
103 |
|
super.addPropertyDirect(key, obj); |
104 |
|
delegate.possiblySave(); |
105 |
|
} |
106 |
|
|
107 |
|
public void clearProperty(String key) |
108 |
|
{ |
109 |
|
super.clearProperty(key); |
110 |
|
delegate.possiblySave(); |
111 |
|
} |
112 |
|
|
113 |
|
public void clearTree(String key) |
114 |
|
{ |
115 |
|
super.clearTree(key); |
116 |
|
delegate.possiblySave(); |
117 |
|
} |
118 |
|
|
119 |
|
public void setProperty(String key, Object value) |
120 |
|
{ |
121 |
|
super.setProperty(key, value); |
122 |
|
delegate.possiblySave(); |
123 |
|
} |
124 |
|
|
125 |
|
public void load() throws ConfigurationException |
126 |
|
{ |
127 |
|
delegate.load(); |
128 |
|
} |
129 |
|
|
130 |
|
public void load(String fileName) throws ConfigurationException |
131 |
|
{ |
132 |
|
delegate.load(fileName); |
133 |
|
} |
134 |
|
|
135 |
|
public void load(File file) throws ConfigurationException |
136 |
|
{ |
137 |
|
delegate.load(file); |
138 |
|
} |
139 |
|
|
140 |
|
public void load(URL url) throws ConfigurationException |
141 |
|
{ |
142 |
|
delegate.load(url); |
143 |
|
} |
144 |
|
|
145 |
|
public void load(InputStream in) throws ConfigurationException |
146 |
|
{ |
147 |
|
delegate.load(in); |
148 |
|
} |
149 |
|
|
150 |
|
public void load(InputStream in, String encoding) throws ConfigurationException |
151 |
|
{ |
152 |
|
delegate.load(in, encoding); |
153 |
|
} |
154 |
|
|
155 |
|
public void save() throws ConfigurationException |
156 |
|
{ |
157 |
|
delegate.save(); |
158 |
|
} |
159 |
|
|
160 |
|
public void save(String fileName) throws ConfigurationException |
161 |
|
{ |
162 |
|
delegate.save(fileName); |
163 |
|
} |
164 |
|
|
165 |
|
public void save(File file) throws ConfigurationException |
166 |
|
{ |
167 |
|
delegate.save(file); |
168 |
|
} |
169 |
|
|
170 |
|
public void save(URL url) throws ConfigurationException |
171 |
|
{ |
172 |
|
delegate.save(url); |
173 |
|
} |
174 |
|
|
175 |
|
public void save(OutputStream out) throws ConfigurationException |
176 |
|
{ |
177 |
|
delegate.save(out); |
178 |
|
} |
179 |
|
|
180 |
|
public void save(OutputStream out, String encoding) throws ConfigurationException |
181 |
|
{ |
182 |
|
delegate.save(out, encoding); |
183 |
|
} |
184 |
|
|
185 |
|
public String getFileName() |
186 |
|
{ |
187 |
|
return delegate.getFileName(); |
188 |
|
} |
189 |
|
|
190 |
|
public void setFileName(String fileName) |
191 |
|
{ |
192 |
|
delegate.setFileName(fileName); |
193 |
|
} |
194 |
|
|
195 |
|
public String getBasePath() |
196 |
|
{ |
197 |
|
return delegate.getBasePath(); |
198 |
|
} |
199 |
|
|
200 |
|
public void setBasePath(String basePath) |
201 |
|
{ |
202 |
|
delegate.setBasePath(basePath); |
203 |
|
} |
204 |
|
|
205 |
|
public File getFile() |
206 |
|
{ |
207 |
|
return delegate.getFile(); |
208 |
|
} |
209 |
|
|
210 |
|
public void setFile(File file) |
211 |
|
{ |
212 |
|
delegate.setFile(file); |
213 |
|
} |
214 |
|
|
215 |
|
public URL getURL() |
216 |
|
{ |
217 |
|
return delegate.getURL(); |
218 |
|
} |
219 |
|
|
220 |
|
public void setURL(URL url) |
221 |
|
{ |
222 |
|
delegate.setURL(url); |
223 |
|
} |
224 |
|
|
225 |
|
public void setAutoSave(boolean autoSave) |
226 |
|
{ |
227 |
|
delegate.setAutoSave(autoSave); |
228 |
|
} |
229 |
|
|
230 |
|
public boolean isAutoSave() |
231 |
|
{ |
232 |
|
return delegate.isAutoSave(); |
233 |
|
} |
234 |
|
|
235 |
|
public ReloadingStrategy getReloadingStrategy() |
236 |
|
{ |
237 |
|
return delegate.getReloadingStrategy(); |
238 |
|
} |
239 |
|
|
240 |
|
public void setReloadingStrategy(ReloadingStrategy strategy) |
241 |
|
{ |
242 |
|
delegate.setReloadingStrategy(strategy); |
243 |
|
} |
244 |
|
|
245 |
|
public void reload() |
246 |
|
{ |
247 |
|
delegate.reload(); |
248 |
|
} |
249 |
|
|
250 |
|
public String getEncoding() |
251 |
|
{ |
252 |
|
return delegate.getEncoding(); |
253 |
|
} |
254 |
|
|
255 |
|
public void setEncoding(String encoding) |
256 |
|
{ |
257 |
|
delegate.setEncoding(encoding); |
258 |
|
} |
259 |
|
|
260 |
|
public boolean containsKey(String key) |
261 |
|
{ |
262 |
|
reload(); |
263 |
|
return super.containsKey(key); |
264 |
|
} |
265 |
|
|
266 |
|
public Iterator getKeys(String prefix) |
267 |
|
{ |
268 |
|
reload(); |
269 |
|
return super.getKeys(prefix); |
270 |
|
} |
271 |
|
|
272 |
|
public Object getProperty(String key) |
273 |
|
{ |
274 |
|
reload(); |
275 |
|
return super.getProperty(key); |
276 |
|
} |
277 |
|
|
278 |
|
public boolean isEmpty() |
279 |
|
{ |
280 |
|
reload(); |
281 |
|
return super.isEmpty(); |
282 |
|
} |
283 |
|
|
284 |
|
|
285 |
|
|
286 |
|
|
287 |
|
|
288 |
|
|
289 |
|
|
290 |
|
|
291 |
|
|
292 |
|
|
293 |
|
protected FileConfigurationDelegate createDelegate() |
294 |
|
{ |
295 |
|
return new FileConfigurationDelegate(); |
296 |
|
} |
297 |
|
|
298 |
|
|
299 |
|
|
300 |
|
|
301 |
|
|
302 |
|
|
303 |
|
protected FileConfigurationDelegate getDelegate() |
304 |
|
{ |
305 |
|
return delegate; |
306 |
|
} |
307 |
|
|
308 |
|
|
309 |
|
|
310 |
|
|
311 |
|
|
312 |
|
protected void setDelegate(FileConfigurationDelegate delegate) |
313 |
|
{ |
314 |
|
this.delegate = delegate; |
315 |
|
} |
316 |
|
|
317 |
|
|
318 |
|
|
319 |
|
|
320 |
|
|
321 |
|
|
322 |
939 |
protected class FileConfigurationDelegate extends AbstractFileConfiguration |
323 |
|
{ |
324 |
|
public void load(Reader in) throws ConfigurationException |
325 |
|
{ |
326 |
81 |
AbstractHierarchicalFileConfiguration.this.load(in); |
327 |
81 |
} |
328 |
|
|
329 |
|
public void save(Writer out) throws ConfigurationException |
330 |
|
{ |
331 |
51 |
AbstractHierarchicalFileConfiguration.this.save(out); |
332 |
51 |
} |
333 |
|
|
334 |
|
public void clear() |
335 |
|
{ |
336 |
3 |
AbstractHierarchicalFileConfiguration.this.clear(); |
337 |
3 |
} |
338 |
|
} |
339 |
|
} |