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.math.BigDecimal; |
20 |
|
import java.math.BigInteger; |
21 |
|
import java.util.ArrayList; |
22 |
|
import java.util.Iterator; |
23 |
|
import java.util.List; |
24 |
|
import java.util.NoSuchElementException; |
25 |
|
import java.util.Properties; |
26 |
|
|
27 |
|
import org.apache.commons.collections.Predicate; |
28 |
|
import org.apache.commons.collections.iterators.FilterIterator; |
29 |
|
import org.apache.commons.lang.BooleanUtils; |
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
4564 |
public abstract class AbstractConfiguration implements Configuration |
43 |
|
{ |
44 |
|
|
45 |
|
protected static final String START_TOKEN = "${"; |
46 |
|
|
47 |
|
|
48 |
|
protected static final String END_TOKEN = "}"; |
49 |
|
|
50 |
|
|
51 |
123 |
private static char delimiter = ','; |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
private boolean throwExceptionOnMissing; |
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
public static void setDelimiter(char delimiter) |
66 |
|
{ |
67 |
9 |
AbstractConfiguration.delimiter = delimiter; |
68 |
9 |
} |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
public static char getDelimiter() |
76 |
|
{ |
77 |
94760 |
return AbstractConfiguration.delimiter; |
78 |
|
} |
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
public void setThrowExceptionOnMissing(boolean throwExceptionOnMissing) |
92 |
|
{ |
93 |
1092 |
this.throwExceptionOnMissing = throwExceptionOnMissing; |
94 |
1092 |
} |
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
public boolean isThrowExceptionOnMissing() |
102 |
|
{ |
103 |
828 |
return throwExceptionOnMissing; |
104 |
|
} |
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
public void addProperty(String key, Object value) |
110 |
|
{ |
111 |
75099 |
Iterator it = PropertyConverter.toIterator(value, getDelimiter()); |
112 |
233844 |
while (it.hasNext()) |
113 |
|
{ |
114 |
83649 |
addPropertyDirect(key, it.next()); |
115 |
|
} |
116 |
75096 |
} |
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
protected abstract void addPropertyDirect(String key, Object value); |
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
protected String interpolate(String base) |
135 |
|
{ |
136 |
3060 |
return interpolateHelper(base, null); |
137 |
|
} |
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
protected Object interpolate(Object value) |
147 |
|
{ |
148 |
3030 |
if (value instanceof String) |
149 |
|
{ |
150 |
1941 |
return interpolate((String) value); |
151 |
|
} |
152 |
|
else |
153 |
|
{ |
154 |
1089 |
return value; |
155 |
|
} |
156 |
|
} |
157 |
|
|
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
protected String interpolateHelper(String base, List priorVariables) |
172 |
|
{ |
173 |
3306 |
if (base == null) |
174 |
|
{ |
175 |
48 |
return null; |
176 |
|
} |
177 |
|
|
178 |
|
|
179 |
|
|
180 |
3258 |
if (priorVariables == null) |
181 |
|
{ |
182 |
3012 |
priorVariables = new ArrayList(); |
183 |
3012 |
priorVariables.add(base); |
184 |
|
} |
185 |
|
|
186 |
3258 |
int begin = -1; |
187 |
3258 |
int end = -1; |
188 |
3258 |
int prec = 0 - END_TOKEN.length(); |
189 |
3258 |
StringBuffer result = new StringBuffer(); |
190 |
|
|
191 |
|
|
192 |
3258 |
while (((begin = base.indexOf(START_TOKEN, prec + END_TOKEN.length())) > -1) |
193 |
3498 |
&& ((end = base.indexOf(END_TOKEN, begin)) > -1)) |
194 |
|
{ |
195 |
258 |
result.append(base.substring(prec + END_TOKEN.length(), begin)); |
196 |
258 |
String variable = base.substring(begin + START_TOKEN.length(), end); |
197 |
|
|
198 |
|
|
199 |
258 |
if (priorVariables.contains(variable)) |
200 |
|
{ |
201 |
6 |
String initialBase = priorVariables.remove(0).toString(); |
202 |
6 |
priorVariables.add(variable); |
203 |
6 |
StringBuffer priorVariableSb = new StringBuffer(); |
204 |
|
|
205 |
|
|
206 |
|
|
207 |
30 |
for (Iterator it = priorVariables.iterator(); it.hasNext();) |
208 |
|
{ |
209 |
18 |
priorVariableSb.append(it.next()); |
210 |
18 |
if (it.hasNext()) |
211 |
|
{ |
212 |
12 |
priorVariableSb.append("->"); |
213 |
|
} |
214 |
|
} |
215 |
|
|
216 |
6 |
throw new IllegalStateException("infinite loop in property interpolation of " + initialBase + ": " |
217 |
|
+ priorVariableSb.toString()); |
218 |
|
} |
219 |
|
|
220 |
|
else |
221 |
|
{ |
222 |
252 |
priorVariables.add(variable); |
223 |
|
} |
224 |
|
|
225 |
252 |
Object value = resolveContainerStore(variable); |
226 |
252 |
if (value != null) |
227 |
|
{ |
228 |
246 |
result.append(interpolateHelper(value.toString(), priorVariables)); |
229 |
|
|
230 |
|
|
231 |
|
|
232 |
|
|
233 |
|
|
234 |
234 |
priorVariables.remove(priorVariables.size() - 1); |
235 |
|
} |
236 |
|
else |
237 |
|
{ |
238 |
|
|
239 |
6 |
result.append(START_TOKEN).append(variable).append(END_TOKEN); |
240 |
|
} |
241 |
|
|
242 |
240 |
prec = end; |
243 |
|
} |
244 |
3240 |
result.append(base.substring(prec + END_TOKEN.length(), base.length())); |
245 |
3240 |
return result.toString(); |
246 |
|
} |
247 |
|
|
248 |
|
|
249 |
|
|
250 |
|
|
251 |
|
public Configuration subset(String prefix) |
252 |
|
{ |
253 |
120 |
return new SubsetConfiguration(this, prefix, "."); |
254 |
|
} |
255 |
|
|
256 |
|
|
257 |
|
|
258 |
|
|
259 |
|
public abstract boolean isEmpty(); |
260 |
|
|
261 |
|
|
262 |
|
|
263 |
|
|
264 |
|
public abstract boolean containsKey(String key); |
265 |
|
|
266 |
|
|
267 |
|
|
268 |
|
|
269 |
|
public void setProperty(String key, Object value) |
270 |
|
{ |
271 |
2316 |
clearProperty(key); |
272 |
2316 |
addProperty(key, value); |
273 |
2316 |
} |
274 |
|
|
275 |
|
|
276 |
|
|
277 |
|
|
278 |
|
public abstract void clearProperty(String key); |
279 |
|
|
280 |
|
|
281 |
|
|
282 |
|
|
283 |
|
public void clear() |
284 |
|
{ |
285 |
15 |
Iterator it = getKeys(); |
286 |
291 |
while (it.hasNext()) |
287 |
|
{ |
288 |
261 |
String key = (String) it.next(); |
289 |
261 |
it.remove(); |
290 |
|
|
291 |
261 |
if (containsKey(key)) |
292 |
|
{ |
293 |
|
|
294 |
258 |
clearProperty(key); |
295 |
|
} |
296 |
|
} |
297 |
15 |
} |
298 |
|
|
299 |
|
|
300 |
|
|
301 |
|
|
302 |
|
public abstract Iterator getKeys(); |
303 |
|
|
304 |
|
|
305 |
|
|
306 |
|
|
307 |
|
public Iterator getKeys(final String prefix) |
308 |
|
{ |
309 |
111 |
return new FilterIterator(getKeys(), class="keyword">new Predicate() |
310 |
|
{ |
311 |
|
public boolean evaluate(Object obj) |
312 |
|
{ |
313 |
|
String key = (String) obj; |
314 |
|
return key.startsWith(prefix + ".") || key.equals(prefix); |
315 |
|
} |
316 |
|
}); |
317 |
|
} |
318 |
|
|
319 |
|
|
320 |
|
|
321 |
|
|
322 |
|
public Properties getProperties(String key) |
323 |
|
{ |
324 |
12 |
return getProperties(key, null); |
325 |
|
} |
326 |
|
|
327 |
|
|
328 |
|
|
329 |
|
|
330 |
|
|
331 |
|
|
332 |
|
|
333 |
|
|
334 |
|
|
335 |
|
|
336 |
|
|
337 |
|
|
338 |
|
|
339 |
|
|
340 |
|
|
341 |
|
|
342 |
|
public Properties getProperties(String key, Properties defaults) |
343 |
|
{ |
344 |
|
|
345 |
|
|
346 |
|
|
347 |
12 |
String[] tokens = getStringArray(key); |
348 |
|
|
349 |
|
|
350 |
|
|
351 |
|
|
352 |
12 |
Properties props = defaults == null ? new Properties() : class="keyword">new Properties(defaults); |
353 |
30 |
for (int i = 0; i < tokens.length; i++) |
354 |
|
{ |
355 |
24 |
String token = tokens[i]; |
356 |
24 |
int equalSign = token.indexOf('='); |
357 |
24 |
if (equalSign > 0) |
358 |
|
{ |
359 |
18 |
String pkey = token.substring(0, equalSign).trim(); |
360 |
18 |
String pvalue = token.substring(equalSign + 1).trim(); |
361 |
18 |
props.put(pkey, pvalue); |
362 |
|
} |
363 |
6 |
else if (tokens.length == 1 && "".equals(token)) |
364 |
|
{ |
365 |
|
|
366 |
|
|
367 |
6 |
break; |
368 |
|
} |
369 |
|
else |
370 |
|
{ |
371 |
0 |
throw new IllegalArgumentException('\'' + token + "' does not contain an equals sign"); |
372 |
|
} |
373 |
|
} |
374 |
12 |
return props; |
375 |
|
} |
376 |
|
|
377 |
|
|
378 |
|
|
379 |
|
|
380 |
|
public boolean getBoolean(String key) |
381 |
|
{ |
382 |
123 |
Boolean b = getBoolean(key, null); |
383 |
117 |
if (b != null) |
384 |
|
{ |
385 |
111 |
return b.booleanValue(); |
386 |
|
} |
387 |
|
else |
388 |
|
{ |
389 |
6 |
throw new NoSuchElementException('\'' + key + "' doesn't map to an existing object"); |
390 |
|
} |
391 |
|
} |
392 |
|
|
393 |
|
|
394 |
|
|
395 |
|
|
396 |
|
public boolean getBoolean(String key, class="keyword">boolean defaultValue) |
397 |
|
{ |
398 |
33 |
return getBoolean(key, BooleanUtils.toBooleanObject(defaultValue)).booleanValue(); |
399 |
|
} |
400 |
|
|
401 |
|
|
402 |
|
|
403 |
|
|
404 |
|
public Boolean getBoolean(String key, Boolean defaultValue) |
405 |
|
{ |
406 |
174 |
Object value = resolveContainerStore(key); |
407 |
|
|
408 |
174 |
if (value == null) |
409 |
|
{ |
410 |
42 |
return defaultValue; |
411 |
|
} |
412 |
|
else |
413 |
|
{ |
414 |
|
try |
415 |
|
{ |
416 |
132 |
return PropertyConverter.toBoolean(interpolate(value)); |
417 |
|
} |
418 |
|
catch (ConversionException e) |
419 |
|
{ |
420 |
6 |
throw new ConversionException('\'' + key + "' doesn't map to a Boolean object", e); |
421 |
|
} |
422 |
|
} |
423 |
|
} |
424 |
|
|
425 |
|
|
426 |
|
|
427 |
|
|
428 |
|
public byte getByte(String key) |
429 |
|
{ |
430 |
42 |
Byte b = getByte(key, null); |
431 |
36 |
if (b != null) |
432 |
|
{ |
433 |
30 |
return b.byteValue(); |
434 |
|
} |
435 |
|
else |
436 |
|
{ |
437 |
6 |
throw new NoSuchElementException('\'' + key + " doesn't map to an existing object"); |
438 |
|
} |
439 |
|
} |
440 |
|
|
441 |
|
|
442 |
|
|
443 |
|
|
444 |
|
public byte getByte(String key, byte defaultValue) |
445 |
|
{ |
446 |
12 |
return getByte(key, new Byte(defaultValue)).byteValue(); |
447 |
|
} |
448 |
|
|
449 |
|
|
450 |
|
|
451 |
|
|
452 |
|
public Byte getByte(String key, Byte defaultValue) |
453 |
|
{ |
454 |
63 |
Object value = resolveContainerStore(key); |
455 |
|
|
456 |
63 |
if (value == null) |
457 |
|
{ |
458 |
12 |
return defaultValue; |
459 |
|
} |
460 |
|
else |
461 |
|
{ |
462 |
|
try |
463 |
|
{ |
464 |
51 |
return PropertyConverter.toByte(interpolate(value)); |
465 |
|
} |
466 |
|
catch (ConversionException e) |
467 |
|
{ |
468 |
6 |
throw new ConversionException('\'' + key + "' doesn't map to a Byte object", e); |
469 |
|
} |
470 |
|
} |
471 |
|
} |
472 |
|
|
473 |
|
|
474 |
|
|
475 |
|
|
476 |
|
public double getDouble(String key) |
477 |
|
{ |
478 |
42 |
Double d = getDouble(key, null); |
479 |
36 |
if (d != null) |
480 |
|
{ |
481 |
30 |
return d.doubleValue(); |
482 |
|
} |
483 |
|
else |
484 |
|
{ |
485 |
6 |
throw new NoSuchElementException('\'' + key + "' doesn't map to an existing object"); |
486 |
|
} |
487 |
|
} |
488 |
|
|
489 |
|
|
490 |
|
|
491 |
|
|
492 |
|
public double getDouble(String key, class="keyword">double defaultValue) |
493 |
|
{ |
494 |
33 |
return getDouble(key, new Double(defaultValue)).doubleValue(); |
495 |
|
} |
496 |
|
|
497 |
|
|
498 |
|
|
499 |
|
|
500 |
|
public Double getDouble(String key, Double defaultValue) |
501 |
|
{ |
502 |
84 |
Object value = resolveContainerStore(key); |
503 |
|
|
504 |
84 |
if (value == null) |
505 |
|
{ |
506 |
33 |
return defaultValue; |
507 |
|
} |
508 |
|
else |
509 |
|
{ |
510 |
|
try |
511 |
|
{ |
512 |
51 |
return PropertyConverter.toDouble(interpolate(value)); |
513 |
|
} |
514 |
|
catch (ConversionException e) |
515 |
|
{ |
516 |
6 |
throw new ConversionException('\'' + key + "' doesn't map to a Double object", e); |
517 |
|
} |
518 |
|
} |
519 |
|
} |
520 |
|
|
521 |
|
|
522 |
|
|
523 |
|
|
524 |
|
public float getFloat(String key) |
525 |
|
{ |
526 |
39 |
Float f = getFloat(key, null); |
527 |
33 |
if (f != null) |
528 |
|
{ |
529 |
27 |
return f.floatValue(); |
530 |
|
} |
531 |
|
else |
532 |
|
{ |
533 |
6 |
throw new NoSuchElementException('\'' + key + "' doesn't map to an existing object"); |
534 |
|
} |
535 |
|
} |
536 |
|
|
537 |
|
|
538 |
|
|
539 |
|
|
540 |
|
public float getFloat(String key, class="keyword">float defaultValue) |
541 |
|
{ |
542 |
21 |
return getFloat(key, new Float(defaultValue)).floatValue(); |
543 |
|
} |
544 |
|
|
545 |
|
|
546 |
|
|
547 |
|
|
548 |
|
public Float getFloat(String key, Float defaultValue) |
549 |
|
{ |
550 |
69 |
Object value = resolveContainerStore(key); |
551 |
|
|
552 |
69 |
if (value == null) |
553 |
|
{ |
554 |
21 |
return defaultValue; |
555 |
|
} |
556 |
|
else |
557 |
|
{ |
558 |
|
try |
559 |
|
{ |
560 |
48 |
return PropertyConverter.toFloat(interpolate(value)); |
561 |
|
} |
562 |
|
catch (ConversionException e) |
563 |
|
{ |
564 |
6 |
throw new ConversionException('\'' + key + "' doesn't map to a Float object", e); |
565 |
|
} |
566 |
|
} |
567 |
|
} |
568 |
|
|
569 |
|
|
570 |
|
|
571 |
|
|
572 |
|
public int getInt(String key) |
573 |
|
{ |
574 |
75 |
Integer i = getInteger(key, null); |
575 |
75 |
if (i != null) |
576 |
|
{ |
577 |
75 |
return i.intValue(); |
578 |
|
} |
579 |
|
else |
580 |
|
{ |
581 |
0 |
throw new NoSuchElementException('\'' + key + "' doesn't map to an existing object"); |
582 |
|
} |
583 |
|
} |
584 |
|
|
585 |
|
|
586 |
|
|
587 |
|
|
588 |
|
public int getInt(String key, class="keyword">int defaultValue) |
589 |
|
{ |
590 |
9 |
Integer i = getInteger(key, null); |
591 |
|
|
592 |
9 |
if (i == null) |
593 |
|
{ |
594 |
9 |
return defaultValue; |
595 |
|
} |
596 |
|
|
597 |
0 |
return i.intValue(); |
598 |
|
} |
599 |
|
|
600 |
|
|
601 |
|
|
602 |
|
|
603 |
|
public Integer getInteger(String key, Integer defaultValue) |
604 |
|
{ |
605 |
87 |
Object value = resolveContainerStore(key); |
606 |
|
|
607 |
87 |
if (value == null) |
608 |
|
{ |
609 |
9 |
return defaultValue; |
610 |
|
} |
611 |
|
else |
612 |
|
{ |
613 |
|
try |
614 |
|
{ |
615 |
78 |
return PropertyConverter.toInteger(interpolate(value)); |
616 |
|
} |
617 |
|
catch (ConversionException e) |
618 |
|
{ |
619 |
0 |
throw new ConversionException('\'' + key + "' doesn't map to an Integer object", e); |
620 |
|
} |
621 |
|
} |
622 |
|
} |
623 |
|
|
624 |
|
|
625 |
|
|
626 |
|
|
627 |
|
public long getLong(String key) |
628 |
|
{ |
629 |
42 |
Long l = getLong(key, null); |
630 |
36 |
if (l != null) |
631 |
|
{ |
632 |
30 |
return l.longValue(); |
633 |
|
} |
634 |
|
else |
635 |
|
{ |
636 |
6 |
throw new NoSuchElementException('\'' + key + "' doesn't map to an existing object"); |
637 |
|
} |
638 |
|
} |
639 |
|
|
640 |
|
|
641 |
|
|
642 |
|
|
643 |
|
public long getLong(String key, class="keyword">long defaultValue) |
644 |
|
{ |
645 |
21 |
return getLong(key, new Long(defaultValue)).longValue(); |
646 |
|
} |
647 |
|
|
648 |
|
|
649 |
|
|
650 |
|
|
651 |
|
public Long getLong(String key, Long defaultValue) |
652 |
|
{ |
653 |
72 |
Object value = resolveContainerStore(key); |
654 |
|
|
655 |
72 |
if (value == null) |
656 |
|
{ |
657 |
21 |
return defaultValue; |
658 |
|
} |
659 |
|
else |
660 |
|
{ |
661 |
|
try |
662 |
|
{ |
663 |
51 |
return PropertyConverter.toLong(interpolate(value)); |
664 |
|
} |
665 |
|
catch (ConversionException e) |
666 |
|
{ |
667 |
6 |
throw new ConversionException('\'' + key + "' doesn't map to a Long object", e); |
668 |
|
} |
669 |
|
} |
670 |
|
} |
671 |
|
|
672 |
|
|
673 |
|
|
674 |
|
|
675 |
|
public short getShort(String key) |
676 |
|
{ |
677 |
51 |
Short s = getShort(key, null); |
678 |
45 |
if (s != null) |
679 |
|
{ |
680 |
39 |
return s.shortValue(); |
681 |
|
} |
682 |
|
else |
683 |
|
{ |
684 |
6 |
throw new NoSuchElementException('\'' + key + "' doesn't map to an existing object"); |
685 |
|
} |
686 |
|
} |
687 |
|
|
688 |
|
|
689 |
|
|
690 |
|
|
691 |
|
public short getShort(String key, class="keyword">short defaultValue) |
692 |
|
{ |
693 |
21 |
return getShort(key, new Short(defaultValue)).shortValue(); |
694 |
|
} |
695 |
|
|
696 |
|
|
697 |
|
|
698 |
|
|
699 |
|
public Short getShort(String key, Short defaultValue) |
700 |
|
{ |
701 |
93 |
Object value = resolveContainerStore(key); |
702 |
|
|
703 |
93 |
if (value == null) |
704 |
|
{ |
705 |
27 |
return defaultValue; |
706 |
|
} |
707 |
|
else |
708 |
|
{ |
709 |
|
try |
710 |
|
{ |
711 |
66 |
return PropertyConverter.toShort(interpolate(value)); |
712 |
|
} |
713 |
|
catch (ConversionException e) |
714 |
|
{ |
715 |
6 |
throw new ConversionException('\'' + key + "' doesn't map to a Short object", e); |
716 |
|
} |
717 |
|
} |
718 |
|
} |
719 |
|
|
720 |
|
|
721 |
|
|
722 |
|
|
723 |
|
public BigDecimal getBigDecimal(String key) |
724 |
|
{ |
725 |
18 |
BigDecimal number = getBigDecimal(key, null); |
726 |
12 |
if (number != null) |
727 |
|
{ |
728 |
6 |
return number; |
729 |
|
} |
730 |
6 |
else if (isThrowExceptionOnMissing()) |
731 |
|
{ |
732 |
3 |
throw new NoSuchElementException('\'' + key + "' doesn't map to an existing object"); |
733 |
|
} |
734 |
|
else |
735 |
|
{ |
736 |
3 |
return null; |
737 |
|
} |
738 |
|
} |
739 |
|
|
740 |
|
|
741 |
|
|
742 |
|
|
743 |
|
public BigDecimal getBigDecimal(String key, BigDecimal defaultValue) |
744 |
|
{ |
745 |
33 |
Object value = resolveContainerStore(key); |
746 |
|
|
747 |
33 |
if (value == null) |
748 |
|
{ |
749 |
12 |
return defaultValue; |
750 |
|
} |
751 |
|
else |
752 |
|
{ |
753 |
|
try |
754 |
|
{ |
755 |
21 |
return PropertyConverter.toBigDecimal(interpolate(value)); |
756 |
|
} |
757 |
|
catch (ConversionException e) |
758 |
|
{ |
759 |
6 |
throw new ConversionException('\'' + key + "' doesn't map to a BigDecimal object", e); |
760 |
|
} |
761 |
|
} |
762 |
|
} |
763 |
|
|
764 |
|
|
765 |
|
|
766 |
|
|
767 |
|
public BigInteger getBigInteger(String key) |
768 |
|
{ |
769 |
21 |
BigInteger number = getBigInteger(key, null); |
770 |
15 |
if (number != null) |
771 |
|
{ |
772 |
9 |
return number; |
773 |
|
} |
774 |
6 |
else if (isThrowExceptionOnMissing()) |
775 |
|
{ |
776 |
3 |
throw new NoSuchElementException('\'' + key + "' doesn't map to an existing object"); |
777 |
|
} |
778 |
|
else |
779 |
|
{ |
780 |
3 |
return null; |
781 |
|
} |
782 |
|
} |
783 |
|
|
784 |
|
|
785 |
|
|
786 |
|
|
787 |
|
public BigInteger getBigInteger(String key, BigInteger defaultValue) |
788 |
|
{ |
789 |
36 |
Object value = resolveContainerStore(key); |
790 |
|
|
791 |
36 |
if (value == null) |
792 |
|
{ |
793 |
12 |
return defaultValue; |
794 |
|
} |
795 |
|
else |
796 |
|
{ |
797 |
|
try |
798 |
|
{ |
799 |
24 |
return PropertyConverter.toBigInteger(interpolate(value)); |
800 |
|
} |
801 |
|
catch (ConversionException e) |
802 |
|
{ |
803 |
6 |
throw new ConversionException('\'' + key + "' doesn't map to a BigDecimal object", e); |
804 |
|
} |
805 |
|
} |
806 |
|
} |
807 |
|
|
808 |
|
|
809 |
|
|
810 |
|
|
811 |
|
public String getString(String key) |
812 |
|
{ |
813 |
567 |
String s = getString(key, null); |
814 |
561 |
if (s != null) |
815 |
|
{ |
816 |
513 |
return s; |
817 |
|
} |
818 |
48 |
else if (isThrowExceptionOnMissing()) |
819 |
|
{ |
820 |
18 |
throw new NoSuchElementException('\'' + key + "' doesn't map to an existing object"); |
821 |
|
} |
822 |
|
else |
823 |
|
{ |
824 |
30 |
return null; |
825 |
|
} |
826 |
|
} |
827 |
|
|
828 |
|
|
829 |
|
|
830 |
|
|
831 |
|
public String getString(String key, String defaultValue) |
832 |
|
{ |
833 |
834 |
Object value = resolveContainerStore(key); |
834 |
|
|
835 |
834 |
if (value instanceof String) |
836 |
|
{ |
837 |
762 |
return interpolate((String) value); |
838 |
|
} |
839 |
72 |
else if (value == null) |
840 |
|
{ |
841 |
72 |
return interpolate(defaultValue); |
842 |
|
} |
843 |
|
else |
844 |
|
{ |
845 |
0 |
throw new ConversionException('\'' + key + "' doesn't map to a String object"); |
846 |
|
} |
847 |
|
} |
848 |
|
|
849 |
|
|
850 |
|
|
851 |
|
|
852 |
|
public String[] getStringArray(String key) |
853 |
|
{ |
854 |
54 |
Object value = getProperty(key); |
855 |
|
|
856 |
|
String[] array; |
857 |
|
|
858 |
54 |
if (value instanceof String) |
859 |
|
{ |
860 |
30 |
array = new String[1]; |
861 |
|
|
862 |
30 |
array[0] = interpolate((String) value); |
863 |
|
} |
864 |
24 |
else if (value instanceof List) |
865 |
|
{ |
866 |
18 |
List list = (List) value; |
867 |
18 |
array = new String[list.size()]; |
868 |
|
|
869 |
66 |
for (int i = 0; i < array.length; i++) |
870 |
|
{ |
871 |
48 |
array[i] = interpolate((String) list.get(i)); |
872 |
|
} |
873 |
|
} |
874 |
6 |
else if (value == null) |
875 |
|
{ |
876 |
6 |
array = new String[0]; |
877 |
|
} |
878 |
|
else |
879 |
|
{ |
880 |
0 |
throw new ConversionException('\'' + key + "' doesn't map to a String/List object"); |
881 |
|
} |
882 |
54 |
return array; |
883 |
|
} |
884 |
|
|
885 |
|
|
886 |
|
|
887 |
|
|
888 |
|
public List getList(String key) |
889 |
|
{ |
890 |
645 |
return getList(key, new ArrayList()); |
891 |
|
} |
892 |
|
|
893 |
|
|
894 |
|
|
895 |
|
|
896 |
|
public List getList(String key, List defaultValue) |
897 |
|
{ |
898 |
525 |
Object value = getProperty(key); |
899 |
|
List list; |
900 |
|
|
901 |
525 |
if (value instanceof String) |
902 |
|
{ |
903 |
147 |
list = new ArrayList(1); |
904 |
147 |
list.add(interpolate((String) value)); |
905 |
|
} |
906 |
378 |
else if (value instanceof List) |
907 |
|
{ |
908 |
282 |
list = new ArrayList(); |
909 |
282 |
List l = (List) value; |
910 |
|
|
911 |
|
|
912 |
282 |
Iterator it = l.iterator(); |
913 |
1551 |
while (it.hasNext()) |
914 |
|
{ |
915 |
987 |
list.add(interpolate(it.next())); |
916 |
|
} |
917 |
|
|
918 |
|
} |
919 |
96 |
else if (value == null) |
920 |
|
{ |
921 |
93 |
list = defaultValue; |
922 |
|
} |
923 |
|
else |
924 |
|
{ |
925 |
3 |
throw new ConversionException('\'' + key + "' doesn't map to a List object: " + value + ", a " |
926 |
|
+ value.getClass().getName()); |
927 |
|
} |
928 |
522 |
return list; |
929 |
|
} |
930 |
|
|
931 |
|
|
932 |
|
|
933 |
|
|
934 |
|
|
935 |
|
|
936 |
|
|
937 |
|
|
938 |
|
|
939 |
|
protected Object resolveContainerStore(String key) |
940 |
|
{ |
941 |
1884 |
Object value = getProperty(key); |
942 |
1884 |
if (value != null) |
943 |
|
{ |
944 |
1605 |
if (value instanceof List) |
945 |
|
{ |
946 |
27 |
List list = (List) value; |
947 |
27 |
value = list.isEmpty() ? null : list.get(0); |
948 |
|
} |
949 |
1578 |
else if (value instanceof Object[]) |
950 |
|
{ |
951 |
3 |
Object[] array = (Object[]) value; |
952 |
3 |
value = array.length == 0 ? null : array[0]; |
953 |
|
} |
954 |
1575 |
else if (value instanceof boolean[]) |
955 |
|
{ |
956 |
3 |
boolean[] array = (class="keyword">boolean[]) value; |
957 |
3 |
value = array.length == 0 ? null : new Boolean(array[0]); |
958 |
|
} |
959 |
1572 |
else if (value instanceof byte[]) |
960 |
|
{ |
961 |
3 |
byte[] array = (byte[]) value; |
962 |
3 |
value = array.length == 0 ? null : new Byte(array[0]); |
963 |
|
} |
964 |
1569 |
else if (value instanceof short[]) |
965 |
|
{ |
966 |
3 |
short[] array = (class="keyword">short[]) value; |
967 |
3 |
value = array.length == 0 ? null : new Short(array[0]); |
968 |
|
} |
969 |
1566 |
else if (value instanceof int[]) |
970 |
|
{ |
971 |
3 |
int[] array = (class="keyword">int[]) value; |
972 |
3 |
value = array.length == 0 ? null : new Integer(array[0]); |
973 |
|
} |
974 |
1563 |
else if (value instanceof long[]) |
975 |
|
{ |
976 |
3 |
long[] array = (class="keyword">long[]) value; |
977 |
3 |
value = array.length == 0 ? null : new Long(array[0]); |
978 |
|
} |
979 |
1560 |
else if (value instanceof float[]) |
980 |
|
{ |
981 |
3 |
float[] array = (class="keyword">float[]) value; |
982 |
3 |
value = array.length == 0 ? null : new Float(array[0]); |
983 |
|
} |
984 |
1557 |
else if (value instanceof double[]) |
985 |
|
{ |
986 |
3 |
double[] array = (class="keyword">double[]) value; |
987 |
3 |
value = array.length == 0 ? null : new Double(array[0]); |
988 |
|
} |
989 |
|
} |
990 |
|
|
991 |
1884 |
return value; |
992 |
|
} |
993 |
|
|
994 |
|
} |