|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| package org.jconfig; |
|
8 |
| |
|
9 |
| import java.io.Serializable; |
|
10 |
| import java.util.Enumeration; |
|
11 |
| import java.util.HashMap; |
|
12 |
| import java.util.Iterator; |
|
13 |
| import java.util.Properties; |
|
14 |
| import java.util.Set; |
|
15 |
| import java.util.SortedMap; |
|
16 |
| import java.util.StringTokenizer; |
|
17 |
| import java.util.TreeMap; |
|
18 |
| import java.util.Vector; |
|
19 |
| import javax.swing.event.EventListenerList; |
|
20 |
| |
|
21 |
| import org.jconfig.event.CategoryChangedEvent; |
|
22 |
| import org.jconfig.event.CategoryListener; |
|
23 |
| import org.jconfig.event.ConfigurationChangedEvent; |
|
24 |
| import org.jconfig.event.ConfigurationChangedEventImpl; |
|
25 |
| import org.jconfig.event.ConfigurationListener; |
|
26 |
| import org.jconfig.event.PropertyChangedEvent; |
|
27 |
| import org.jconfig.event.PropertyListener; |
|
28 |
| import org.jconfig.utils.IncludeEntry; |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| public class DefaultConfiguration implements Serializable,Configuration { |
|
39 |
| |
|
40 |
| protected static final VariableManager vm = VariableManager.getInstance(); |
|
41 |
| |
|
42 |
| protected String configName; |
|
43 |
| |
|
44 |
| protected HashMap categories; |
|
45 |
| |
|
46 |
| protected String mainCategory; |
|
47 |
| |
|
48 |
| private EventListenerList configurationListenerList = new EventListenerList(); |
|
49 |
| |
|
50 |
| private boolean created = true; |
|
51 |
| |
|
52 |
| private String encoding; |
|
53 |
| |
|
54 |
| protected String baseConfigName; |
|
55 |
| |
|
56 |
| private boolean dirtyFlag = false; |
|
57 |
| |
|
58 |
| private Vector includes = new Vector(); |
|
59 |
| |
|
60 |
0
| protected DefaultConfiguration() {
|
|
61 |
| } |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
89
| public DefaultConfiguration(String configName) {
|
|
70 |
89
| categories = new HashMap();
|
|
71 |
89
| this.configName = configName;
|
|
72 |
89
| setCategory("general", true);
|
|
73 |
89
| created = true;
|
|
74 |
| } |
|
75 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
| |
|
79 |
| |
|
80 |
| |
|
81 |
| |
|
82 |
58
| public void setCategory(String name) {
|
|
83 |
58
| setCategory(name, false);
|
|
84 |
| } |
|
85 |
| |
|
86 |
| |
|
87 |
| |
|
88 |
| |
|
89 |
| |
|
90 |
| |
|
91 |
| |
|
92 |
| |
|
93 |
| |
|
94 |
| |
|
95 |
120
| public void setCategory(String name, boolean main) {
|
|
96 |
120
| if (name != null) {
|
|
97 |
120
| if (main) {
|
|
98 |
65
| mainCategory = name;
|
|
99 |
| } |
|
100 |
120
| if (!categories.containsKey(name)) {
|
|
101 |
109
| Category category = new DefaultCategory(name);
|
|
102 |
109
| category.setConfigurationName(configName);
|
|
103 |
109
| category.addCategoryListener(new MyCategoryListener());
|
|
104 |
109
| categories.put(name, category);
|
|
105 |
109
| markDirty();
|
|
106 |
109
| category.fireCategoryChangedEvent(
|
|
107 |
| new ConfigurationChangedEventImpl(ConfigurationChangedEvent.CATEGORY_ADDED, category, null, null, null )); |
|
108 |
109
| fireConfigurationChangedEvent(
|
|
109 |
| new ConfigurationChangedEventImpl(ConfigurationChangedEvent.CATEGORY_ADDED, category, null, null, null )); |
|
110 |
| } |
|
111 |
| } |
|
112 |
| } |
|
113 |
| |
|
114 |
5
| public void setCategory(Category category) {
|
|
115 |
5
| if (!categories.containsKey(category.getCategoryName())) {
|
|
116 |
3
| category.setConfigurationName(configName);
|
|
117 |
3
| category.addCategoryListener(new MyCategoryListener());
|
|
118 |
3
| categories.put(category.getCategoryName(), category);
|
|
119 |
3
| category.fireCategoryChangedEvent(
|
|
120 |
| new ConfigurationChangedEventImpl(ConfigurationChangedEvent.CATEGORY_ADDED, category, null, null, null )); |
|
121 |
3
| fireConfigurationChangedEvent(
|
|
122 |
| new ConfigurationChangedEventImpl(ConfigurationChangedEvent.CATEGORY_ADDED, category, null, null, null )); |
|
123 |
| } |
|
124 |
| } |
|
125 |
| |
|
126 |
| |
|
127 |
| |
|
128 |
| |
|
129 |
| |
|
130 |
| |
|
131 |
2
| public String getMainCategoryName() {
|
|
132 |
2
| return mainCategory;
|
|
133 |
| } |
|
134 |
| |
|
135 |
| |
|
136 |
| |
|
137 |
| |
|
138 |
| |
|
139 |
| |
|
140 |
| |
|
141 |
11
| public String[] getCategoryNames() {
|
|
142 |
11
| return getCategoryNames(true);
|
|
143 |
| } |
|
144 |
| |
|
145 |
14
| protected String[] getCategoryNames(boolean includeParent) {
|
|
146 |
14
| Set allCategories = categories.keySet();
|
|
147 |
14
| Vector all = new Vector(allCategories);
|
|
148 |
14
| if ( baseConfigName != null && includeParent ) {
|
|
149 |
0
| Configuration cfg = ConfigurationManager.getConfiguration(baseConfigName);
|
|
150 |
0
| String[] parentCategories = cfg.getCategoryNames();
|
|
151 |
0
| for ( int i = 0 ; i < parentCategories.length ; i++) {
|
|
152 |
0
| if ( all.indexOf(parentCategories[i]) == -1 ) {
|
|
153 |
0
| all.add(parentCategories[i]);
|
|
154 |
| } |
|
155 |
| } |
|
156 |
| } |
|
157 |
14
| return (String[]) all.toArray(new String[0]);
|
|
158 |
| } |
|
159 |
| |
|
160 |
| |
|
161 |
| |
|
162 |
| |
|
163 |
| |
|
164 |
| |
|
165 |
| |
|
166 |
| |
|
167 |
| |
|
168 |
| |
|
169 |
14
| public String getProperty(String key) {
|
|
170 |
14
| return getProperty(key, null, null);
|
|
171 |
| } |
|
172 |
| |
|
173 |
| |
|
174 |
| |
|
175 |
| |
|
176 |
| |
|
177 |
| |
|
178 |
| |
|
179 |
| |
|
180 |
| |
|
181 |
| |
|
182 |
| |
|
183 |
1
| public String getProperty(String key, String defaultValue) {
|
|
184 |
1
| return getProperty(key, defaultValue, null);
|
|
185 |
| } |
|
186 |
| |
|
187 |
| |
|
188 |
| |
|
189 |
| |
|
190 |
| |
|
191 |
| |
|
192 |
| |
|
193 |
| |
|
194 |
| |
|
195 |
| |
|
196 |
| |
|
197 |
| |
|
198 |
| |
|
199 |
| |
|
200 |
49
| public String getProperty(String key,String defaultValue,String categoryName) {
|
|
201 |
49
| boolean isMainCat = false;
|
|
202 |
49
| if (key == null) {
|
|
203 |
0
| return defaultValue;
|
|
204 |
| } |
|
205 |
49
| if (!categories.containsKey(categoryName)) {
|
|
206 |
12
| isMainCat = true;
|
|
207 |
12
| categoryName = mainCategory;
|
|
208 |
| } |
|
209 |
49
| Category category = getCategory(categoryName);
|
|
210 |
49
| if ( category.getCategoryName().equals(mainCategory)) {
|
|
211 |
24
| isMainCat = true;
|
|
212 |
| } |
|
213 |
49
| String tmp = category.getProperty(key);
|
|
214 |
| |
|
215 |
| |
|
216 |
49
| if ( tmp == null && !isMainCat) {
|
|
217 |
3
| category = getCategory(mainCategory);
|
|
218 |
3
| tmp = category.getProperty(key);
|
|
219 |
| } |
|
220 |
49
| if ( tmp == null ) {
|
|
221 |
8
| if ( baseConfigName != null ) {
|
|
222 |
1
| Configuration cfg = ConfigurationManager.getConfiguration(baseConfigName);
|
|
223 |
1
| tmp = cfg.getProperty(key,defaultValue,categoryName);
|
|
224 |
| } |
|
225 |
| else { |
|
226 |
7
| tmp = defaultValue;
|
|
227 |
| } |
|
228 |
| } |
|
229 |
49
| return tmp;
|
|
230 |
| } |
|
231 |
| |
|
232 |
| |
|
233 |
| |
|
234 |
| |
|
235 |
| |
|
236 |
| |
|
237 |
| |
|
238 |
| |
|
239 |
33
| public void setProperty(String name, String value) {
|
|
240 |
33
| setProperty(name, value, null);
|
|
241 |
| } |
|
242 |
| |
|
243 |
| |
|
244 |
| |
|
245 |
| |
|
246 |
| |
|
247 |
| |
|
248 |
| |
|
249 |
| |
|
250 |
| |
|
251 |
| |
|
252 |
215
| public void setProperty(String name, String value, String categoryName) {
|
|
253 |
215
| if (name != null) {
|
|
254 |
215
| if (categoryName == null) {
|
|
255 |
33
| categoryName = mainCategory;
|
|
256 |
| } |
|
257 |
215
| Category category = getCategory(categoryName);
|
|
258 |
215
| category.setProperty(name, value);
|
|
259 |
215
| markDirty();
|
|
260 |
215
| fireConfigurationChangedEvent(
|
|
261 |
| new ConfigurationChangedEventImpl(ConfigurationChangedEvent.PROPERTY_CHANGED, category, name, value,null )); |
|
262 |
| } |
|
263 |
| } |
|
264 |
| |
|
265 |
| |
|
266 |
| |
|
267 |
| |
|
268 |
| |
|
269 |
| |
|
270 |
| |
|
271 |
1
| public void removeProperty(String name) {
|
|
272 |
1
| if (name != null) {
|
|
273 |
1
| removeProperty(name, null);
|
|
274 |
| } |
|
275 |
| } |
|
276 |
| |
|
277 |
| |
|
278 |
| |
|
279 |
| |
|
280 |
| |
|
281 |
| |
|
282 |
| |
|
283 |
| |
|
284 |
| |
|
285 |
3
| public void removeProperty(String name, String category) {
|
|
286 |
3
| if (category == null) {
|
|
287 |
1
| category = mainCategory;
|
|
288 |
| } |
|
289 |
3
| if (name != null) {
|
|
290 |
| |
|
291 |
3
| Category cat = getCategory(category);
|
|
292 |
3
| String tmp = cat.getProperty(name,null);
|
|
293 |
3
| cat.setProperty(name, null);
|
|
294 |
3
| fireConfigurationChangedEvent(
|
|
295 |
| new ConfigurationChangedEventImpl(ConfigurationChangedEvent.PROPERTY_REMOVED,cat, name, tmp,null )); |
|
296 |
3
| markDirty();
|
|
297 |
| } |
|
298 |
| |
|
299 |
| } |
|
300 |
| |
|
301 |
| |
|
302 |
| |
|
303 |
| |
|
304 |
| |
|
305 |
| |
|
306 |
4
| public int getNumberOfCategories() {
|
|
307 |
4
| return getCategoryNames().length;
|
|
308 |
| } |
|
309 |
| |
|
310 |
| |
|
311 |
| |
|
312 |
| |
|
313 |
| |
|
314 |
| |
|
315 |
1
| public void removeCategory(String category) {
|
|
316 |
1
| if (categories.containsKey(category)) {
|
|
317 |
1
| Category cat = getCategory(category);
|
|
318 |
1
| categories.remove(category);
|
|
319 |
1
| cat.fireCategoryChangedEvent(
|
|
320 |
| new ConfigurationChangedEventImpl(ConfigurationChangedEvent.CATEGORY_REMOVED, cat, null, null, null)); |
|
321 |
1
| fireConfigurationChangedEvent(
|
|
322 |
| new ConfigurationChangedEventImpl(ConfigurationChangedEvent.CATEGORY_REMOVED,cat, null, null,null )); |
|
323 |
1
| cat = null;
|
|
324 |
1
| markDirty();
|
|
325 |
| } |
|
326 |
| } |
|
327 |
| |
|
328 |
1
| public Properties getProperties(String category) {
|
|
329 |
1
| return getProperties(category,true);
|
|
330 |
| } |
|
331 |
| |
|
332 |
1
| public Properties getProperties() {
|
|
333 |
1
| return getProperties(mainCategory,true);
|
|
334 |
| } |
|
335 |
| |
|
336 |
30
| protected Properties getProperties(String category,boolean includeParent) {
|
|
337 |
30
| Category cat = getCategory(category);
|
|
338 |
30
| Properties props = new Properties();
|
|
339 |
30
| if ( cat != null ) {
|
|
340 |
30
| props = (Properties)cat.getProperties().clone();
|
|
341 |
| } |
|
342 |
30
| if ( baseConfigName != null && includeParent ) {
|
|
343 |
1
| Configuration cfg = ConfigurationManager.getConfiguration(baseConfigName);
|
|
344 |
1
| Properties parentProps = cfg.getProperties(category);
|
|
345 |
1
| Enumeration num = parentProps.keys();
|
|
346 |
1
| while ( num.hasMoreElements() ) {
|
|
347 |
5
| String name = (String)num.nextElement();
|
|
348 |
5
| if ( !props.contains(name) ) {
|
|
349 |
5
| props.setProperty(name, (String)parentProps.get(name));
|
|
350 |
| } |
|
351 |
| } |
|
352 |
| } |
|
353 |
30
| return props;
|
|
354 |
| } |
|
355 |
| |
|
356 |
| |
|
357 |
| |
|
358 |
| |
|
359 |
| |
|
360 |
| |
|
361 |
| |
|
362 |
| |
|
363 |
1
| public String[] getPropertyNames(String category) {
|
|
364 |
1
| if ( containsCategory(category) ) {
|
|
365 |
| |
|
366 |
0
| Properties properties = getProperties(category);
|
|
367 |
0
| if (properties != null) {
|
|
368 |
0
| Enumeration en = properties.propertyNames();
|
|
369 |
0
| Vector keys = new Vector();
|
|
370 |
0
| while ( en.hasMoreElements() ) {
|
|
371 |
0
| String nm = (String)en.nextElement();
|
|
372 |
0
| keys.add(nm);
|
|
373 |
| } |
|
374 |
| |
|
375 |
| |
|
376 |
| |
|
377 |
0
| return (String[]) keys.toArray(new String[0]);
|
|
378 |
| } |
|
379 |
| } |
|
380 |
1
| return null;
|
|
381 |
| } |
|
382 |
| |
|
383 |
| |
|
384 |
| |
|
385 |
| |
|
386 |
| |
|
387 |
| |
|
388 |
| |
|
389 |
79
| public void setVariable(String name, String value) {
|
|
390 |
79
| if (name != null && value != null) {
|
|
391 |
79
| vm.addVariable(name, value,configName);
|
|
392 |
| } |
|
393 |
| } |
|
394 |
| |
|
395 |
| |
|
396 |
| |
|
397 |
| |
|
398 |
| |
|
399 |
| |
|
400 |
| |
|
401 |
3
| public HashMap getVariables() {
|
|
402 |
3
| return vm.getVariables(configName);
|
|
403 |
| } |
|
404 |
| |
|
405 |
14
| public String getVariable(String name) {
|
|
406 |
14
| return vm.getVariable(configName, name);
|
|
407 |
| } |
|
408 |
| |
|
409 |
| |
|
410 |
| |
|
411 |
| |
|
412 |
| |
|
413 |
| |
|
414 |
| |
|
415 |
4
| public int getIntProperty(String name, int defaultValue) {
|
|
416 |
4
| return getIntProperty(name, defaultValue, mainCategory);
|
|
417 |
| } |
|
418 |
| |
|
419 |
| |
|
420 |
| |
|
421 |
| |
|
422 |
| |
|
423 |
| |
|
424 |
| |
|
425 |
7
| public int getIntProperty(String name, int defaultValue, String category) {
|
|
426 |
7
| String value = getProperty(name,null,category);
|
|
427 |
7
| if (value == null) {
|
|
428 |
0
| return defaultValue;
|
|
429 |
| } else { |
|
430 |
7
| try {
|
|
431 |
7
| return Integer.parseInt(vm.replaceVariables(value,configName));
|
|
432 |
| } catch (NumberFormatException nfe) { |
|
433 |
0
| return defaultValue;
|
|
434 |
| } |
|
435 |
| } |
|
436 |
| } |
|
437 |
| |
|
438 |
| |
|
439 |
| |
|
440 |
| |
|
441 |
| |
|
442 |
| |
|
443 |
| |
|
444 |
| |
|
445 |
| |
|
446 |
2
| public boolean getBooleanProperty(String name, boolean defaultValue) {
|
|
447 |
2
| return getBooleanProperty(name, defaultValue, mainCategory);
|
|
448 |
| } |
|
449 |
| |
|
450 |
| |
|
451 |
| |
|
452 |
| |
|
453 |
| |
|
454 |
| |
|
455 |
| |
|
456 |
| |
|
457 |
| |
|
458 |
5
| public boolean getBooleanProperty(String name,boolean defaultValue,String categoryName) {
|
|
459 |
5
| String value = getProperty(name,null,categoryName);
|
|
460 |
5
| if ( value == null ) {
|
|
461 |
1
| return defaultValue;
|
|
462 |
| } else { |
|
463 |
4
| try {
|
|
464 |
4
| return Boolean.valueOf(vm.replaceVariables(value,configName)).booleanValue();
|
|
465 |
| } catch (Exception e) { |
|
466 |
0
| return defaultValue;
|
|
467 |
| } |
|
468 |
| } |
|
469 |
| } |
|
470 |
| |
|
471 |
| |
|
472 |
| |
|
473 |
| |
|
474 |
| |
|
475 |
| |
|
476 |
| |
|
477 |
2
| public void setBooleanProperty(String key, boolean value) {
|
|
478 |
2
| getCategory().setBooleanProperty(key, value);
|
|
479 |
| |
|
480 |
| } |
|
481 |
| |
|
482 |
| |
|
483 |
| |
|
484 |
| |
|
485 |
| |
|
486 |
| |
|
487 |
| |
|
488 |
| |
|
489 |
1
| public void setBooleanProperty(String key, boolean value, String category) {
|
|
490 |
1
| getCategory(category).setBooleanProperty(key, value);
|
|
491 |
| } |
|
492 |
| |
|
493 |
| |
|
494 |
| |
|
495 |
| |
|
496 |
| |
|
497 |
| |
|
498 |
| |
|
499 |
| |
|
500 |
2
| public long getLongProperty(String name, long defaultValue) {
|
|
501 |
2
| return getLongProperty(name, defaultValue, mainCategory);
|
|
502 |
| } |
|
503 |
| |
|
504 |
| |
|
505 |
| |
|
506 |
| |
|
507 |
| |
|
508 |
| |
|
509 |
| |
|
510 |
| |
|
511 |
| |
|
512 |
7
| public long getLongProperty(String name,long defaultValue,String categoryName) {
|
|
513 |
7
| String value = getProperty(name,null,categoryName);
|
|
514 |
7
| if (value == null) {
|
|
515 |
0
| return defaultValue;
|
|
516 |
| } else { |
|
517 |
7
| try {
|
|
518 |
7
| return Long.parseLong(vm.replaceVariables(value,configName));
|
|
519 |
| } catch (NumberFormatException nfe) { |
|
520 |
0
| return defaultValue;
|
|
521 |
| } |
|
522 |
| } |
|
523 |
| } |
|
524 |
| |
|
525 |
| |
|
526 |
| |
|
527 |
| |
|
528 |
| |
|
529 |
| |
|
530 |
| |
|
531 |
| |
|
532 |
2
| public double getDoubleProperty(String name, double defaultValue) {
|
|
533 |
2
| return getDoubleProperty(name, defaultValue, mainCategory);
|
|
534 |
| } |
|
535 |
| |
|
536 |
| |
|
537 |
| |
|
538 |
| |
|
539 |
| |
|
540 |
| |
|
541 |
| |
|
542 |
| |
|
543 |
| |
|
544 |
5
| public double getDoubleProperty(String name,double defaultValue,String category) {
|
|
545 |
5
| String value = getProperty(name,null,category);
|
|
546 |
5
| if (value == null) {
|
|
547 |
0
| return defaultValue;
|
|
548 |
| } else { |
|
549 |
5
| try {
|
|
550 |
5
| return Double.parseDouble(vm.replaceVariables(value,configName));
|
|
551 |
| } catch (Exception e) { |
|
552 |
0
| return defaultValue;
|
|
553 |
| } |
|
554 |
| } |
|
555 |
| } |
|
556 |
| |
|
557 |
| |
|
558 |
| |
|
559 |
| |
|
560 |
| |
|
561 |
| |
|
562 |
| |
|
563 |
| |
|
564 |
2
| public char getCharProperty(String name, char defaultValue) {
|
|
565 |
2
| return getCharProperty(name, defaultValue, mainCategory);
|
|
566 |
| } |
|
567 |
| |
|
568 |
| |
|
569 |
| |
|
570 |
| |
|
571 |
| |
|
572 |
| |
|
573 |
| |
|
574 |
| |
|
575 |
| |
|
576 |
5
| public char getCharProperty(
|
|
577 |
| String name, |
|
578 |
| char defaultValue, |
|
579 |
| String category) { |
|
580 |
5
| Category cat = getCategory(category);
|
|
581 |
5
| return cat.getCharProperty(name, defaultValue);
|
|
582 |
| } |
|
583 |
| |
|
584 |
| |
|
585 |
| |
|
586 |
| |
|
587 |
| |
|
588 |
| |
|
589 |
0
| public String toString() {
|
|
590 |
0
| StringBuffer buffer = new StringBuffer();
|
|
591 |
0
| String[] cats = getCategoryNames(false);
|
|
592 |
0
| for (int i = 0; i < cats.length; i++) {
|
|
593 |
0
| buffer.append("Category=");
|
|
594 |
0
| buffer.append(cats[i]);
|
|
595 |
0
| Properties props = getProperties(cats[i],false);
|
|
596 |
0
| if (props != null) {
|
|
597 |
0
| buffer.append("\n");
|
|
598 |
0
| Iterator nit = props.keySet().iterator();
|
|
599 |
0
| while (nit.hasNext()) {
|
|
600 |
0
| String name = (String) nit.next();
|
|
601 |
0
| String value = props.getProperty(name);
|
|
602 |
0
| buffer.append(" ");
|
|
603 |
0
| buffer.append(name);
|
|
604 |
0
| buffer.append("=");
|
|
605 |
0
| buffer.append(value);
|
|
606 |
0
| buffer.append("\n");
|
|
607 |
| } |
|
608 |
| } |
|
609 |
| } |
|
610 |
0
| return buffer.toString();
|
|
611 |
| } |
|
612 |
| |
|
613 |
| |
|
614 |
| |
|
615 |
| |
|
616 |
| |
|
617 |
| |
|
618 |
| |
|
619 |
3
| public String getXMLAsString() {
|
|
620 |
3
| StringBuffer buffer = new StringBuffer();
|
|
621 |
| |
|
622 |
| |
|
623 |
3
| buffer.append("<?xml version=\"1.0\"");
|
|
624 |
3
| if ( getEncoding() != null ) {
|
|
625 |
0
| buffer.append(" encoding=\""+getEncoding()+"\"");
|
|
626 |
| } |
|
627 |
3
| buffer.append(" ?>\n");
|
|
628 |
3
| buffer.append("<properties");
|
|
629 |
3
| if ( baseConfigName != null ) {
|
|
630 |
0
| buffer.append(" extends=\"");
|
|
631 |
0
| buffer.append(baseConfigName);
|
|
632 |
0
| buffer.append("\"");
|
|
633 |
| } |
|
634 |
3
| buffer.append(">\n");
|
|
635 |
3
| addIncludeBlock(buffer);
|
|
636 |
3
| addVariableBlock(buffer);
|
|
637 |
| |
|
638 |
| |
|
639 |
3
| String[] cats = getCategoryNames(false);
|
|
640 |
3
| for (int i = 0; i < cats.length; i++) {
|
|
641 |
12
| buffer.append(" <category name=\"");
|
|
642 |
12
| buffer.append(escapeForXML(cats[i]));
|
|
643 |
12
| buffer.append("\">\n");
|
|
644 |
12
| SortedMap sm = getSortedProperties(cats[i],false);
|
|
645 |
12
| if (sm != null) {
|
|
646 |
12
| Iterator nit = sm.keySet().iterator();
|
|
647 |
12
| while (nit.hasNext()) {
|
|
648 |
57
| String name = (String) nit.next();
|
|
649 |
57
| String value = (String)sm.get(name);
|
|
650 |
57
| buffer.append(" <property name=\"");
|
|
651 |
57
| buffer.append(escapeForXML(name));
|
|
652 |
57
| buffer.append("\" value=\"");
|
|
653 |
| |
|
654 |
57
| buffer.append(escapeForXML(value));
|
|
655 |
57
| buffer.append("\"/>\n");
|
|
656 |
| } |
|
657 |
12
| buffer.append(" </category>\n");
|
|
658 |
| } |
|
659 |
| } |
|
660 |
3
| buffer.append("</properties>\n");
|
|
661 |
3
| return buffer.toString();
|
|
662 |
| } |
|
663 |
| |
|
664 |
28
| protected SortedMap getSortedProperties(String categoryName,boolean includeParent) {
|
|
665 |
28
| Properties props = getProperties(categoryName,includeParent);
|
|
666 |
28
| SortedMap sm = new TreeMap();
|
|
667 |
28
| if (props != null) {
|
|
668 |
28
| Iterator nit = props.keySet().iterator();
|
|
669 |
28
| while (nit.hasNext()) {
|
|
670 |
78
| String name = (String) nit.next();
|
|
671 |
78
| String value = props.getProperty(name);
|
|
672 |
78
| sm.put(name,value);
|
|
673 |
| } |
|
674 |
28
| return sm;
|
|
675 |
| } |
|
676 |
0
| return null;
|
|
677 |
| } |
|
678 |
| |
|
679 |
5
| protected void addIncludeBlock(StringBuffer buffer) {
|
|
680 |
5
| if ( includes.size() > 0 ) {
|
|
681 |
4
| for ( int i = 0; i < includes.size();i++) {
|
|
682 |
4
| IncludeEntry ie = (IncludeEntry)includes.get(i);
|
|
683 |
4
| buffer.append(" <include ");
|
|
684 |
4
| if ( ie.getType() == IncludeEntry.PROPERTIES ) {
|
|
685 |
4
| buffer.append("properties=\"");
|
|
686 |
4
| buffer.append(ie.getName());
|
|
687 |
4
| buffer.append("\"/>\n");
|
|
688 |
| } |
|
689 |
| } |
|
690 |
| } |
|
691 |
| } |
|
692 |
| |
|
693 |
5
| protected void addVariableBlock(StringBuffer buffer) {
|
|
694 |
5
| Iterator it = vm.getVariables(configName).keySet().iterator();
|
|
695 |
5
| boolean vars = false;
|
|
696 |
5
| if (it.hasNext()) {
|
|
697 |
4
| buffer.append(" <variables>\n");
|
|
698 |
4
| vars = true;
|
|
699 |
| } |
|
700 |
5
| while (it.hasNext()) {
|
|
701 |
13
| String varName = (String) it.next();
|
|
702 |
13
| String varText = (String) vm.getVariables(configName).get(varName);
|
|
703 |
13
| buffer.append(" <variable name=\"");
|
|
704 |
13
| buffer.append(escapeForXML(varName));
|
|
705 |
13
| buffer.append("\" value=\"");
|
|
706 |
13
| buffer.append(escapeForXML(varText));
|
|
707 |
13
| buffer.append("\"/>\n");
|
|
708 |
| } |
|
709 |
5
| if (vars) {
|
|
710 |
4
| buffer.append(" </variables>\n");
|
|
711 |
| } |
|
712 |
| } |
|
713 |
| |
|
714 |
231
| protected String escapeForXML(String text) {
|
|
715 |
231
| StringBuffer result = new StringBuffer();
|
|
716 |
231
| for ( int i = 0; i < text.length();i++) {
|
|
717 |
2556
| char character = text.charAt(i);
|
|
718 |
2556
| if (character == '<') {
|
|
719 |
1
| result.append("<");
|
|
720 |
| } |
|
721 |
2555
| else if (character == '>') {
|
|
722 |
1
| result.append(">");
|
|
723 |
| } |
|
724 |
2554
| else if (character == '\"') {
|
|
725 |
1
| result.append(""");
|
|
726 |
| } |
|
727 |
2553
| else if (character == '\'') {
|
|
728 |
0
| result.append("'");
|
|
729 |
| } |
|
730 |
2553
| else if (character == '\\') {
|
|
731 |
0
| result.append("\");
|
|
732 |
| } |
|
733 |
2553
| else if (character == '&') {
|
|
734 |
0
| result.append("&");
|
|
735 |
| } |
|
736 |
| else { |
|
737 |
2553
| result.append(character);
|
|
738 |
| } |
|
739 |
| } |
|
740 |
231
| return result.toString();
|
|
741 |
| } |
|
742 |
| |
|
743 |
| |
|
744 |
| |
|
745 |
| |
|
746 |
| |
|
747 |
| |
|
748 |
| |
|
749 |
| |
|
750 |
| |
|
751 |
| |
|
752 |
| |
|
753 |
| |
|
754 |
| |
|
755 |
0
| public void addPropertyListener(PropertyListener listener) {
|
|
756 |
0
| addPropertyListener(listener, mainCategory);
|
|
757 |
| } |
|
758 |
| |
|
759 |
| |
|
760 |
| |
|
761 |
| |
|
762 |
1
| public void addPropertyListener(PropertyListener listener, String categoryName) {
|
|
763 |
1
| getCategory(categoryName).addPropertyListener(listener);
|
|
764 |
| } |
|
765 |
| |
|
766 |
0
| public void addCategoryListener(CategoryListener listener) {
|
|
767 |
0
| addCategoryListener(listener,mainCategory);
|
|
768 |
| } |
|
769 |
| |
|
770 |
0
| public void addCategoryListener(CategoryListener listener,String categoryName) {
|
|
771 |
0
| getCategory(categoryName).addCategoryListener(listener);
|
|
772 |
| } |
|
773 |
| |
|
774 |
| |
|
775 |
| |
|
776 |
| |
|
777 |
72
| public String getConfigName() {
|
|
778 |
72
| return configName;
|
|
779 |
| } |
|
780 |
| |
|
781 |
0
| public void setConfigName(String configName) {
|
|
782 |
0
| this.configName = configName;
|
|
783 |
| } |
|
784 |
| |
|
785 |
| |
|
786 |
| |
|
787 |
| |
|
788 |
| |
|
789 |
| |
|
790 |
| |
|
791 |
0
| public void addConfigurationListener(ConfigurationListener listener) {
|
|
792 |
0
| configurationListenerList.add(ConfigurationListener.class, listener);
|
|
793 |
| } |
|
794 |
| |
|
795 |
| |
|
796 |
| |
|
797 |
| |
|
798 |
| |
|
799 |
| |
|
800 |
| |
|
801 |
0
| public void removeConfigurationListener(ConfigurationListener listener) {
|
|
802 |
0
| configurationListenerList.remove(ConfigurationListener.class, listener);
|
|
803 |
| } |
|
804 |
| |
|
805 |
| |
|
806 |
| |
|
807 |
| |
|
808 |
| |
|
809 |
| |
|
810 |
| |
|
811 |
931
| public void fireConfigurationChangedEvent(ConfigurationChangedEvent event) {
|
|
812 |
| |
|
813 |
931
| Object[] listeners = configurationListenerList.getListenerList();
|
|
814 |
| |
|
815 |
| |
|
816 |
931
| for (int i = listeners.length - 2; i >= 0; i -= 2) {
|
|
817 |
0
| if (listeners[i] == ConfigurationListener.class) {
|
|
818 |
| |
|
819 |
0
| ((ConfigurationListener) listeners[i + 1]).configurationChanged(event);
|
|
820 |
| } |
|
821 |
| } |
|
822 |
| } |
|
823 |
| |
|
824 |
| |
|
825 |
| |
|
826 |
| |
|
827 |
| |
|
828 |
| |
|
829 |
23
| public Category getCategory() {
|
|
830 |
23
| return getCategory(mainCategory);
|
|
831 |
| } |
|
832 |
| |
|
833 |
| |
|
834 |
| |
|
835 |
| |
|
836 |
| |
|
837 |
| |
|
838 |
355
| public Category getCategory(String name) {
|
|
839 |
355
| if(name == null) {
|
|
840 |
3
| name = mainCategory;
|
|
841 |
| } |
|
842 |
355
| Category category = (Category)categories.get(name);
|
|
843 |
355
| if( category == null ) {
|
|
844 |
18
| category = new DefaultCategory(name);
|
|
845 |
18
| categories.put(name, category);
|
|
846 |
| } |
|
847 |
355
| return category;
|
|
848 |
| } |
|
849 |
| |
|
850 |
| |
|
851 |
| |
|
852 |
| |
|
853 |
| |
|
854 |
| |
|
855 |
| |
|
856 |
| |
|
857 |
1
| public void setLongProperty(String key, long value) {
|
|
858 |
1
| getCategory().setLongProperty(key, value);
|
|
859 |
| } |
|
860 |
| |
|
861 |
| |
|
862 |
| |
|
863 |
| |
|
864 |
| |
|
865 |
| |
|
866 |
| |
|
867 |
| |
|
868 |
1
| public void setIntProperty(String key, int value) {
|
|
869 |
1
| getCategory().setIntProperty(key, value);
|
|
870 |
| |
|
871 |
| } |
|
872 |
| |
|
873 |
| |
|
874 |
| |
|
875 |
| |
|
876 |
| |
|
877 |
| |
|
878 |
| |
|
879 |
| |
|
880 |
1
| public void setCharProperty(String key, char value) {
|
|
881 |
1
| getCategory().setCharProperty(key, value);
|
|
882 |
| } |
|
883 |
| |
|
884 |
| |
|
885 |
| |
|
886 |
| |
|
887 |
| |
|
888 |
| |
|
889 |
| |
|
890 |
| |
|
891 |
1
| public void setCharProperty(String key, char value, String category) {
|
|
892 |
1
| getCategory(category).setCharProperty(key, value);
|
|
893 |
| } |
|
894 |
| |
|
895 |
| |
|
896 |
| |
|
897 |
| |
|
898 |
| |
|
899 |
| |
|
900 |
| |
|
901 |
1
| public void setDoubleProperty(String key, double value) {
|
|
902 |
1
| getCategory().setDoubleProperty(key, value);
|
|
903 |
| |
|
904 |
| } |
|
905 |
| |
|
906 |
| |
|
907 |
| |
|
908 |
| |
|
909 |
| |
|
910 |
| |
|
911 |
| |
|
912 |
| |
|
913 |
1
| public void setLongProperty(String key, long value, String category) {
|
|
914 |
1
| getCategory(category).setLongProperty(key, value);
|
|
915 |
| } |
|
916 |
| |
|
917 |
| |
|
918 |
| |
|
919 |
| |
|
920 |
| |
|
921 |
| |
|
922 |
| |
|
923 |
| |
|
924 |
1
| public void setIntProperty(String key, int value, String category) {
|
|
925 |
1
| getCategory(category).setIntProperty(key, value);
|
|
926 |
| } |
|
927 |
| |
|
928 |
| |
|
929 |
| |
|
930 |
| |
|
931 |
| |
|
932 |
| |
|
933 |
| |
|
934 |
| |
|
935 |
1
| public void setDoubleProperty(String key, double value, String category) {
|
|
936 |
1
| getCategory(category).setDoubleProperty(key, value);
|
|
937 |
| } |
|
938 |
| |
|
939 |
0
| public boolean hasChanged() {
|
|
940 |
0
| return dirtyFlag;
|
|
941 |
| } |
|
942 |
| |
|
943 |
2
| public String[] getArray(String key) {
|
|
944 |
2
| return getArray(key,null);
|
|
945 |
| } |
|
946 |
| |
|
947 |
4
| public String[] getArray(String key, String[] defaultValue) {
|
|
948 |
4
| return getArray(key,defaultValue,mainCategory);
|
|
949 |
| } |
|
950 |
| |
|
951 |
6
| public String[] getArray(String key, String[] defaultValue, String category) {
|
|
952 |
6
| String value = getProperty(key,null,category);
|
|
953 |
6
| if ( value == null ) {
|
|
954 |
3
| return defaultValue;
|
|
955 |
| } |
|
956 |
3
| Vector all = new Vector();
|
|
957 |
3
| StringTokenizer sto = new StringTokenizer(value,",");
|
|
958 |
3
| while ( sto.hasMoreElements() ) {
|
|
959 |
12
| String val = (String)sto.nextElement();
|
|
960 |
12
| val = vm.replaceVariables(val,configName);
|
|
961 |
12
| all.add(val);
|
|
962 |
| } |
|
963 |
3
| return (String[])all.toArray(new String[0]);
|
|
964 |
| } |
|
965 |
| |
|
966 |
3
| public boolean isNew() {
|
|
967 |
3
| return created;
|
|
968 |
| } |
|
969 |
| |
|
970 |
40
| public void resetCreated() {
|
|
971 |
40
| created = false;
|
|
972 |
| } |
|
973 |
| |
|
974 |
5
| public String getEncoding() {
|
|
975 |
5
| return encoding;
|
|
976 |
| } |
|
977 |
| |
|
978 |
480
| protected void markDirty() {
|
|
979 |
480
| dirtyFlag = true;
|
|
980 |
| } |
|
981 |
| |
|
982 |
0
| public void setEncoding(String encoding) {
|
|
983 |
0
| this.encoding = encoding;
|
|
984 |
| } |
|
985 |
| |
|
986 |
1
| public boolean containsCategory(String categoryName) {
|
|
987 |
1
| if(categoryName == null) {
|
|
988 |
0
| return false;
|
|
989 |
| } |
|
990 |
1
| Category category = (Category)categories.get(categoryName);
|
|
991 |
1
| if( category != null ) {
|
|
992 |
0
| return true;
|
|
993 |
| } |
|
994 |
1
| return false;
|
|
995 |
| } |
|
996 |
| |
|
997 |
30
| public void addInclude(int type, String name) {
|
|
998 |
30
| IncludeEntry ie = new IncludeEntry(name,type);
|
|
999 |
30
| includes.add(ie);
|
|
1000 |
| } |
|
1001 |
| |
|
1002 |
0
| public Vector getIncludes() {
|
|
1003 |
0
| return includes;
|
|
1004 |
| } |
|
1005 |
| |
|
1006 |
16
| public void setBaseConfiguration(String name) {
|
|
1007 |
16
| baseConfigName = name;
|
|
1008 |
| } |
|
1009 |
| |
|
1010 |
| protected class MyCategoryListener implements CategoryListener { |
|
1011 |
| |
|
1012 |
| |
|
1013 |
| |
|
1014 |
| |
|
1015 |
600
| public void categoryChanged(CategoryChangedEvent event) {
|
|
1016 |
600
| fireConfigurationChangedEvent((ConfigurationChangedEvent)event);
|
|
1017 |
| |
|
1018 |
| } |
|
1019 |
| |
|
1020 |
| |
|
1021 |
| |
|
1022 |
| |
|
1023 |
0
| public void propertyChanged(PropertyChangedEvent e) {
|
|
1024 |
| } |
|
1025 |
| |
|
1026 |
| } |
|
1027 |
| |
|
1028 |
| } |