|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| package org.objectledge.parameters; |
|
30 |
| |
|
31 |
| import java.util.ArrayList; |
|
32 |
| import java.util.Arrays; |
|
33 |
| import java.util.Date; |
|
34 |
| import java.util.Iterator; |
|
35 |
| import java.util.List; |
|
36 |
| import java.util.Set; |
|
37 |
| import java.util.SortedSet; |
|
38 |
| import java.util.TreeSet; |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| public class CompoundParameters implements Parameters |
|
48 |
| { |
|
49 |
| |
|
50 |
| private List<Parameters> containers; |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
0
| public CompoundParameters(Parameters... containers)
|
|
61 |
| { |
|
62 |
0
| this.containers = Arrays.asList(containers);
|
|
63 |
| } |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
0
| public CompoundParameters(List<Parameters> list)
|
|
74 |
| { |
|
75 |
0
| containers = list;
|
|
76 |
0
| Iterator i = list.iterator();
|
|
77 |
0
| while(i.hasNext())
|
|
78 |
| { |
|
79 |
0
| Object obj = i.next();
|
|
80 |
0
| if(!(obj instanceof Parameters))
|
|
81 |
| { |
|
82 |
0
| throw new ClassCastException(obj.getClass().getName());
|
|
83 |
| } |
|
84 |
| } |
|
85 |
| } |
|
86 |
| |
|
87 |
| |
|
88 |
| |
|
89 |
| |
|
90 |
| |
|
91 |
0
| public boolean isDefined(String name)
|
|
92 |
| { |
|
93 |
0
| Iterator i = containers.iterator();
|
|
94 |
0
| while(i.hasNext())
|
|
95 |
| { |
|
96 |
0
| Parameters c = (Parameters)i.next();
|
|
97 |
0
| if(c.isDefined(name))
|
|
98 |
| { |
|
99 |
0
| return true;
|
|
100 |
| } |
|
101 |
| } |
|
102 |
0
| return false;
|
|
103 |
| } |
|
104 |
| |
|
105 |
| |
|
106 |
| |
|
107 |
| |
|
108 |
0
| public String[] getParameterNames()
|
|
109 |
| { |
|
110 |
0
| SortedSet<String> keys = new TreeSet<String>();
|
|
111 |
0
| Iterator i = containers.iterator();
|
|
112 |
0
| while(i.hasNext())
|
|
113 |
| { |
|
114 |
0
| Parameters c = (Parameters)i.next();
|
|
115 |
0
| keys.addAll(Arrays.asList(c.getParameterNames()));
|
|
116 |
| } |
|
117 |
0
| String[] result = new String[keys.size()];
|
|
118 |
0
| keys.toArray(result);
|
|
119 |
0
| return result;
|
|
120 |
| } |
|
121 |
| |
|
122 |
| |
|
123 |
| |
|
124 |
| |
|
125 |
0
| public String get(String name)
|
|
126 |
| { |
|
127 |
0
| Iterator i = containers.iterator();
|
|
128 |
0
| while(i.hasNext())
|
|
129 |
| { |
|
130 |
0
| Parameters c = (Parameters)i.next();
|
|
131 |
0
| if(c.isDefined(name))
|
|
132 |
| { |
|
133 |
0
| return c.get(name);
|
|
134 |
| } |
|
135 |
| } |
|
136 |
0
| throw new UndefinedParameterException("Parameter '" + name + "'is undefined");
|
|
137 |
| } |
|
138 |
| |
|
139 |
| |
|
140 |
| |
|
141 |
| |
|
142 |
0
| public String get(String name, String defaultValue)
|
|
143 |
| { |
|
144 |
0
| Iterator i = containers.iterator();
|
|
145 |
0
| while(i.hasNext())
|
|
146 |
| { |
|
147 |
0
| Parameters c = (Parameters)i.next();
|
|
148 |
0
| if(c.isDefined(name))
|
|
149 |
| { |
|
150 |
0
| return c.get(name);
|
|
151 |
| } |
|
152 |
| } |
|
153 |
0
| return defaultValue;
|
|
154 |
| } |
|
155 |
| |
|
156 |
| |
|
157 |
| |
|
158 |
| |
|
159 |
0
| public String[] getStrings(String name)
|
|
160 |
| { |
|
161 |
0
| Iterator i = containers.iterator();
|
|
162 |
0
| while(i.hasNext())
|
|
163 |
| { |
|
164 |
0
| Parameters c = (Parameters)i.next();
|
|
165 |
0
| if(c.isDefined(name))
|
|
166 |
| { |
|
167 |
0
| return c.getStrings(name);
|
|
168 |
| } |
|
169 |
| } |
|
170 |
0
| return new String[0];
|
|
171 |
| } |
|
172 |
| |
|
173 |
| |
|
174 |
| |
|
175 |
| |
|
176 |
0
| public boolean getBoolean(String name)
|
|
177 |
| { |
|
178 |
0
| Iterator i = containers.iterator();
|
|
179 |
0
| while(i.hasNext())
|
|
180 |
| { |
|
181 |
0
| Parameters c = (Parameters)i.next();
|
|
182 |
0
| if(c.isDefined(name))
|
|
183 |
| { |
|
184 |
0
| return c.getBoolean(name);
|
|
185 |
| } |
|
186 |
| } |
|
187 |
0
| throw new UndefinedParameterException("Parameter '" + name + "'is undefined");
|
|
188 |
| } |
|
189 |
| |
|
190 |
| |
|
191 |
| |
|
192 |
| |
|
193 |
0
| public boolean getBoolean(String name, boolean defaultValue)
|
|
194 |
| { |
|
195 |
0
| Iterator i = containers.iterator();
|
|
196 |
0
| while(i.hasNext())
|
|
197 |
| { |
|
198 |
0
| Parameters c = (Parameters)i.next();
|
|
199 |
0
| if(c.isDefined(name))
|
|
200 |
| { |
|
201 |
0
| return c.getBoolean(name);
|
|
202 |
| } |
|
203 |
| } |
|
204 |
0
| return defaultValue;
|
|
205 |
| } |
|
206 |
| |
|
207 |
| |
|
208 |
| |
|
209 |
| |
|
210 |
0
| public boolean[] getBooleans(String name)
|
|
211 |
| { |
|
212 |
0
| Iterator i = containers.iterator();
|
|
213 |
0
| while(i.hasNext())
|
|
214 |
| { |
|
215 |
0
| Parameters c = (Parameters)i.next();
|
|
216 |
0
| if(c.isDefined(name))
|
|
217 |
| { |
|
218 |
0
| return c.getBooleans(name);
|
|
219 |
| } |
|
220 |
| } |
|
221 |
0
| return new boolean[0];
|
|
222 |
| } |
|
223 |
| |
|
224 |
| |
|
225 |
| |
|
226 |
| |
|
227 |
0
| public Date getDate(String name)
|
|
228 |
| { |
|
229 |
0
| Iterator i = containers.iterator();
|
|
230 |
0
| while(i.hasNext())
|
|
231 |
| { |
|
232 |
0
| Parameters c = (Parameters)i.next();
|
|
233 |
0
| if(c.isDefined(name))
|
|
234 |
| { |
|
235 |
0
| return c.getDate(name);
|
|
236 |
| } |
|
237 |
| } |
|
238 |
0
| throw new UndefinedParameterException("Parameter '" + name + "'is undefined");
|
|
239 |
| } |
|
240 |
| |
|
241 |
| |
|
242 |
| |
|
243 |
| |
|
244 |
0
| public Date getDate(String name, Date defaultValue)
|
|
245 |
| { |
|
246 |
0
| Iterator i = containers.iterator();
|
|
247 |
0
| while(i.hasNext())
|
|
248 |
| { |
|
249 |
0
| Parameters c = (Parameters)i.next();
|
|
250 |
0
| if(c.isDefined(name))
|
|
251 |
| { |
|
252 |
0
| return c.getDate(name, defaultValue);
|
|
253 |
| } |
|
254 |
| } |
|
255 |
0
| return defaultValue;
|
|
256 |
| } |
|
257 |
| |
|
258 |
| |
|
259 |
| |
|
260 |
| |
|
261 |
0
| public Date[] getDates(String name)
|
|
262 |
| { |
|
263 |
0
| Iterator i = containers.iterator();
|
|
264 |
0
| while(i.hasNext())
|
|
265 |
| { |
|
266 |
0
| Parameters c = (Parameters)i.next();
|
|
267 |
0
| if(c.isDefined(name))
|
|
268 |
| { |
|
269 |
0
| return c.getDates(name);
|
|
270 |
| } |
|
271 |
| } |
|
272 |
0
| return new Date[0];
|
|
273 |
| } |
|
274 |
| |
|
275 |
| |
|
276 |
| |
|
277 |
| |
|
278 |
0
| public int getInt(String name)
|
|
279 |
| { |
|
280 |
0
| Iterator i = containers.iterator();
|
|
281 |
0
| while(i.hasNext())
|
|
282 |
| { |
|
283 |
0
| Parameters c = (Parameters)i.next();
|
|
284 |
0
| if(c.isDefined(name))
|
|
285 |
| { |
|
286 |
0
| return c.getInt(name);
|
|
287 |
| } |
|
288 |
| } |
|
289 |
0
| throw new UndefinedParameterException("Parameter '" + name + "'is undefined");
|
|
290 |
| } |
|
291 |
| |
|
292 |
| |
|
293 |
| |
|
294 |
| |
|
295 |
0
| public int getInt(String name, int defaultValue)
|
|
296 |
| { |
|
297 |
0
| Iterator i = containers.iterator();
|
|
298 |
0
| while(i.hasNext())
|
|
299 |
| { |
|
300 |
0
| Parameters c = (Parameters)i.next();
|
|
301 |
0
| if(c.isDefined(name))
|
|
302 |
| { |
|
303 |
0
| return c.getInt(name, defaultValue);
|
|
304 |
| } |
|
305 |
| } |
|
306 |
0
| return defaultValue;
|
|
307 |
| } |
|
308 |
| |
|
309 |
| |
|
310 |
| |
|
311 |
| |
|
312 |
0
| public int[] getInts(String name)
|
|
313 |
| { |
|
314 |
0
| Iterator i = containers.iterator();
|
|
315 |
0
| while(i.hasNext())
|
|
316 |
| { |
|
317 |
0
| Parameters c = (Parameters)i.next();
|
|
318 |
0
| if(c.isDefined(name))
|
|
319 |
| { |
|
320 |
0
| return c.getInts(name);
|
|
321 |
| } |
|
322 |
| } |
|
323 |
0
| return new int[0];
|
|
324 |
| } |
|
325 |
| |
|
326 |
| |
|
327 |
| |
|
328 |
| |
|
329 |
0
| public long getLong(String name)
|
|
330 |
| { |
|
331 |
0
| Iterator i = containers.iterator();
|
|
332 |
0
| while(i.hasNext())
|
|
333 |
| { |
|
334 |
0
| Parameters c = (Parameters)i.next();
|
|
335 |
0
| if(c.isDefined(name))
|
|
336 |
| { |
|
337 |
0
| return c.getLong(name);
|
|
338 |
| } |
|
339 |
| } |
|
340 |
0
| throw new UndefinedParameterException("Parameter '" + name + "'is undefined");
|
|
341 |
| } |
|
342 |
| |
|
343 |
| |
|
344 |
| |
|
345 |
| |
|
346 |
0
| public long getLong(String name, long defaultValue)
|
|
347 |
| { |
|
348 |
0
| Iterator i = containers.iterator();
|
|
349 |
0
| while(i.hasNext())
|
|
350 |
| { |
|
351 |
0
| Parameters c = (Parameters)i.next();
|
|
352 |
0
| if(c.isDefined(name))
|
|
353 |
| { |
|
354 |
0
| return c.getLong(name, defaultValue);
|
|
355 |
| } |
|
356 |
| } |
|
357 |
0
| return defaultValue;
|
|
358 |
| } |
|
359 |
| |
|
360 |
| |
|
361 |
| |
|
362 |
| |
|
363 |
0
| public long[] getLongs(String name)
|
|
364 |
| { |
|
365 |
0
| Iterator i = containers.iterator();
|
|
366 |
0
| while(i.hasNext())
|
|
367 |
| { |
|
368 |
0
| Parameters c = (Parameters)i.next();
|
|
369 |
0
| if(c.isDefined(name))
|
|
370 |
| { |
|
371 |
0
| return c.getLongs(name);
|
|
372 |
| } |
|
373 |
| } |
|
374 |
0
| return new long[0];
|
|
375 |
| } |
|
376 |
| |
|
377 |
| |
|
378 |
| |
|
379 |
| |
|
380 |
0
| public float getFloat(String name)
|
|
381 |
| { |
|
382 |
0
| Iterator i = containers.iterator();
|
|
383 |
0
| while(i.hasNext())
|
|
384 |
| { |
|
385 |
0
| Parameters c = (Parameters)i.next();
|
|
386 |
0
| if(c.isDefined(name))
|
|
387 |
| { |
|
388 |
0
| return c.getFloat(name);
|
|
389 |
| } |
|
390 |
| } |
|
391 |
0
| throw new UndefinedParameterException("Parameter '" + name + "'is undefined");
|
|
392 |
| } |
|
393 |
| |
|
394 |
| |
|
395 |
| |
|
396 |
| |
|
397 |
0
| public float getFloat(String name, float defaultValue)
|
|
398 |
| { |
|
399 |
0
| Iterator i = containers.iterator();
|
|
400 |
0
| while(i.hasNext())
|
|
401 |
| { |
|
402 |
0
| Parameters c = (Parameters)i.next();
|
|
403 |
0
| if(c.isDefined(name))
|
|
404 |
| { |
|
405 |
0
| return c.getFloat(name, defaultValue);
|
|
406 |
| } |
|
407 |
| } |
|
408 |
0
| return defaultValue;
|
|
409 |
| } |
|
410 |
| |
|
411 |
| |
|
412 |
| |
|
413 |
| |
|
414 |
0
| public float[] getFloats(String name)
|
|
415 |
| { |
|
416 |
0
| Iterator i = containers.iterator();
|
|
417 |
0
| while(i.hasNext())
|
|
418 |
| { |
|
419 |
0
| Parameters c = (Parameters)i.next();
|
|
420 |
0
| if(c.isDefined(name))
|
|
421 |
| { |
|
422 |
0
| return c.getFloats(name);
|
|
423 |
| } |
|
424 |
| } |
|
425 |
0
| return new float[0];
|
|
426 |
| } |
|
427 |
| |
|
428 |
| |
|
429 |
| |
|
430 |
| |
|
431 |
0
| public Parameters getChild(String prefix)
|
|
432 |
| { |
|
433 |
0
| List<Parameters> list = new ArrayList<Parameters>();
|
|
434 |
0
| Iterator i = containers.iterator();
|
|
435 |
0
| while(i.hasNext())
|
|
436 |
| { |
|
437 |
0
| Parameters c = (Parameters)i.next();
|
|
438 |
0
| list.add(c.getChild(prefix));
|
|
439 |
| } |
|
440 |
0
| return new CompoundParameters(list);
|
|
441 |
| } |
|
442 |
| |
|
443 |
| |
|
444 |
| |
|
445 |
| |
|
446 |
| |
|
447 |
| |
|
448 |
0
| public void remove()
|
|
449 |
| { |
|
450 |
0
| throw new UnsupportedOperationException();
|
|
451 |
| } |
|
452 |
| |
|
453 |
| |
|
454 |
| |
|
455 |
| |
|
456 |
0
| public void remove(String name)
|
|
457 |
| { |
|
458 |
0
| throw new UnsupportedOperationException();
|
|
459 |
| } |
|
460 |
| |
|
461 |
| |
|
462 |
| |
|
463 |
| |
|
464 |
0
| public void remove(String name, String value)
|
|
465 |
| { |
|
466 |
0
| throw new UnsupportedOperationException();
|
|
467 |
| } |
|
468 |
| |
|
469 |
| |
|
470 |
| |
|
471 |
| |
|
472 |
0
| public void remove(String name, Date value)
|
|
473 |
| { |
|
474 |
0
| throw new UnsupportedOperationException();
|
|
475 |
| } |
|
476 |
| |
|
477 |
| |
|
478 |
| |
|
479 |
| |
|
480 |
0
| public void remove(String name, float value)
|
|
481 |
| { |
|
482 |
0
| throw new UnsupportedOperationException();
|
|
483 |
| } |
|
484 |
| |
|
485 |
| |
|
486 |
| |