KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > myvietnam > mvncore > configuration > CompositeConfiguration


1 package net.myvietnam.mvncore.configuration;
2 /* ====================================================================
3  * The Apache Software License, Version 1.1
4  *
5  * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution, if
21  * any, must include the following acknowledgement:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgement may appear in the software itself,
25  * if and wherever such third-party acknowledgements normally appear.
26  *
27  * 4. The names "The Jakarta Project", "Commons", and "Apache Software
28  * Foundation" must not be used to endorse or promote products derived
29  * from this software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache"
33  * nor may "Apache" appear in their names without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation. For more
52  * information on the Apache Software Foundation, please see
53  * <http://www.apache.org/>.
54  */

55
56 import java.util.ArrayList JavaDoc;
57 import java.util.Iterator JavaDoc;
58 import java.util.LinkedList JavaDoc;
59 import java.util.List JavaDoc;
60 import java.util.ListIterator JavaDoc;
61 import java.util.NoSuchElementException JavaDoc;
62 import java.util.Properties JavaDoc;
63 import java.util.Vector JavaDoc;
64
65 /**
66  * This Configuration class allows you to add multiple different types of Configuration
67  * to this CompositeConfiguration. If you add Configuration1, and then Configuration2,
68  * any properties shared will mean that Configuration1 will be returned.
69  * You can add multiple different types or the same type of properties file.
70  * If Configuration1 doesn't have the property, then Configuration2 will be checked.
71  *
72  * @author <a HREF="mailto:epugh@upstate.com">Eric Pugh</a>
73  * @author <a HREF="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
74  * @version $Id: CompositeConfiguration.java,v 1.2 2004/06/27 01:20:38 skoehler Exp $
75  */

76 public class CompositeConfiguration implements Configuration
77 {
78     /** Array holding all the configuration */
79     private LinkedList JavaDoc configList = new LinkedList JavaDoc();
80
81     /**
82      * Configuration that holds in memory stuff. Inserted as first so any
83      * setProperty() override anything else added.
84      */

85     private BaseConfiguration inMemoryConfiguration;
86
87     /**
88      * Creates an empty CompositeConfiguration object which can then
89      * be added some other Configuration files
90      */

91     public CompositeConfiguration()
92     {
93         clear();
94     }
95
96     public void addConfiguration(Configuration config)
97     {
98         if (!configList.contains(config))
99         {
100             // As the inMemoryConfiguration contains all manually added keys,
101
// we must make sure that it is always last. "Normal", non composed
102
// configuration add their keys at the end of the configuration and
103
// we want to mimic this behaviour.
104
configList.add(configList.indexOf(inMemoryConfiguration), config);
105         }
106     }
107     public void removeConfiguration(Configuration config)
108     {
109         // Make sure that you can't remove the inMemoryConfiguration from
110
// the CompositeConfiguration object
111
if (!config.equals(inMemoryConfiguration))
112         {
113             configList.remove(config);
114         }
115     }
116     public int getNumberOfConfigurations()
117     {
118         return configList.size();
119     }
120     public void clear()
121     {
122         configList.clear();
123         // recreate the in memory configuration
124
inMemoryConfiguration = new BaseConfiguration();
125         configList.addLast(inMemoryConfiguration);
126     }
127     /**
128      * CompositeConfigurations can not be added to
129      *
130      * @param key The Key to add the property to.
131      * @param token The Value to add.
132      */

133     public void addProperty(String JavaDoc key, Object JavaDoc token)
134     {
135         inMemoryConfiguration.addProperty(key, token);
136     }
137     /**
138      * Get the list of the keys contained in the configuration
139      * repository.
140      *
141      * @return An Iterator.
142      */

143     public Iterator JavaDoc getKeys()
144     {
145         List JavaDoc keys = new ArrayList JavaDoc();
146         for (ListIterator JavaDoc i = configList.listIterator(); i.hasNext();)
147         {
148             Configuration config = (Configuration) i.next();
149             for (Iterator JavaDoc j = config.getKeys(); j.hasNext();)
150             {
151                 String JavaDoc key = (String JavaDoc) j.next();
152                 if (!keys.contains(key))
153                 {
154                     keys.add(key);
155                 }
156             }
157         }
158         return keys.iterator();
159     }
160     /**
161      * Get the list of the keys contained in the configuration
162      * repository.
163      *
164      * @return An Iterator.
165      */

166     public Iterator JavaDoc getKeys(String JavaDoc key)
167     {
168         List JavaDoc keys = new ArrayList JavaDoc();
169         for (ListIterator JavaDoc i = configList.listIterator(); i.hasNext();)
170         {
171             Configuration config = (Configuration) i.next();
172             for (Iterator JavaDoc j = config.getKeys(key); j.hasNext();)
173             {
174                 String JavaDoc newKey = (String JavaDoc) j.next();
175                 if (!keys.contains(newKey))
176                 {
177                     keys.add(newKey);
178                 }
179             }
180         }
181         return keys.iterator();
182     }
183     /**
184      * Get a list of properties associated with the given
185      * configuration key.
186      *
187      * @param key The configuration key.
188      * @return The associated properties if key is found.
189      * @exception ClassCastException is thrown if the key maps to an
190      * object that is not a String/Vector.
191      * @exception IllegalArgumentException if one of the tokens is
192      * malformed (does not contain an equals sign).
193      */

194     public Properties JavaDoc getProperties(String JavaDoc key)
195     {
196         return getFirstMatchingConfig(key).getProperties(key);
197     }
198     public boolean isEmpty()
199     {
200         boolean isEmpty = true;
201         for (ListIterator JavaDoc i = configList.listIterator(); i.hasNext();)
202         {
203             Configuration config = (Configuration) i.next();
204             if (!config.isEmpty())
205             {
206                 return false;
207             }
208         }
209         return isEmpty;
210     }
211     /**
212      * Gets a property from the configuration.
213      *
214      * @param key property to retrieve
215      * @return value as object. Will return user value if exists,
216      * if not then default value if exists, otherwise null
217      */

218     public Object JavaDoc getProperty(String JavaDoc key)
219     {
220         return getFirstMatchingConfig(key).getProperty(key);
221     }
222     /**
223      * Set a property, this will replace any previously
224      * set values. Set values is implicitly a call
225      * to clearProperty(key), addProperty(key,value).
226      *
227      * @param key
228      * @param value
229      */

230     public void setProperty(String JavaDoc key, Object JavaDoc value)
231     {
232         clearProperty(key);
233         addProperty(key, value);
234     }
235     /**
236      * Clear a property in the configuration.
237      *
238      * @param key the key to remove along with corresponding value.
239      */

240     public void clearProperty(String JavaDoc key)
241     {
242         for (ListIterator JavaDoc i = configList.listIterator(); i.hasNext();)
243         {
244             Configuration config = (Configuration) i.next();
245             config.clearProperty(key);
246         }
247     }
248     /**
249      * check if the configuration contains the key
250      */

251     public boolean containsKey(String JavaDoc key)
252     {
253         for (ListIterator JavaDoc i = configList.listIterator(); i.hasNext();)
254         {
255             Configuration config = (Configuration) i.next();
256             if (config.containsKey(key))
257             {
258                 return true;
259             }
260         }
261         return false;
262     }
263     /**
264      * Create a CompositeConfiguration object that is a subset
265      * of this one. Cycles over all the config objects, and calls
266      * their subset method and then just adds that.
267      *
268      * @param prefix
269      */

270     public Configuration subset(String JavaDoc prefix)
271     {
272         CompositeConfiguration subsetCompositeConfiguration =
273             new CompositeConfiguration();
274         Configuration subConf = null;
275         int count = 0;
276         for (ListIterator JavaDoc i = configList.listIterator(); i.hasNext();)
277         {
278             Configuration config = (Configuration) i.next();
279             Configuration subset = config.subset(prefix);
280             if (subset != null)
281             {
282                 subsetCompositeConfiguration.addConfiguration(subset);
283                 subConf = subset;
284                 count++;
285             }
286         }
287         return (count == 1) ? subConf : subsetCompositeConfiguration;
288     }
289     /**
290     * Get a float associated with the given configuration key.
291     *
292     * @ param key The configuration key.
293     * @ return The associated float.
294     * @ exception NoSuchElementException is thrown if the key doesn 't
295     * map to an existing object.
296     * @ exception ClassCastException is thrown if the key maps to an
297     * object that is not a Float.
298     * @ exception NumberFormatException is thrown if the value mapped
299     * by the key has not a valid number format.
300      */

301     public float getFloat(String JavaDoc key)
302     {
303         return getFirstMatchingConfig(key).getFloat(key);
304     }
305     /**
306      * Get a boolean associated with the given configuration key.
307      *
308      * @param key The configuration key.
309      * @return The associated boolean.
310      * @exception NoSuchElementException is thrown if the key doesn't
311      * map to an existing object.
312      * @exception ClassCastException is thrown if the key maps to an
313      * object that is not a Boolean.
314      */

315     public boolean getBoolean(String JavaDoc key)
316     {
317         return getFirstMatchingConfig(key).getBoolean(key);
318     }
319     /**
320      * Get a boolean associated with the given configuration key.
321      *
322      * @param key The configuration key.
323      * @param defaultValue The default value.
324      * @return The associated boolean.
325      * @exception ClassCastException is thrown if the key maps to an
326      * object that is not a Boolean.
327      */

328     public boolean getBoolean(String JavaDoc key, boolean defaultValue)
329     {
330         return getBoolean(key, new Boolean JavaDoc(defaultValue)).booleanValue();
331     }
332     /**
333      * Get a boolean associated with the given configuration key.
334      *
335      * @param key The configuration key.
336      * @param defaultValue The default value.
337      * @return The associated boolean if key is found and has valid
338      * format, default value otherwise.
339      * @exception ClassCastException is thrown if the key maps to an
340      * object that is not a Boolean.
341      */

342     public Boolean JavaDoc getBoolean(String JavaDoc key, Boolean JavaDoc defaultValue)
343     {
344         try
345         {
346             return getFirstMatchingConfig(key).getBoolean(key, defaultValue);
347         }
348         catch (NoSuchElementException JavaDoc nsee)
349         {
350             return defaultValue;
351         }
352     }
353     /**
354      * Get a byte associated with the given configuration key.
355      *
356      * @param key The configuration key.
357      * @return The associated byte.
358      * @exception NoSuchElementException is thrown if the key doesn't
359      * map to an existing object.
360      * @exception ClassCastException is thrown if the key maps to an
361      * object that is not a Byte.
362      * @exception NumberFormatException is thrown if the value mapped
363      * by the key has not a valid number format.
364      */

365     public byte getByte(String JavaDoc key)
366     {
367         return getFirstMatchingConfig(key).getByte(key);
368     }
369     /**
370      * Get a byte associated with the given configuration key.
371      *
372      * @param key The configuration key.
373      * @param defaultValue The default value.
374      * @return The associated byte.
375      * @exception ClassCastException is thrown if the key maps to an
376      * object that is not a Byte.
377      * @exception NumberFormatException is thrown if the value mapped
378      * by the key has not a valid number format.
379      */

380     public byte getByte(String JavaDoc key, byte defaultValue)
381     {
382         return getByte(key, new Byte JavaDoc(defaultValue).byteValue());
383     }
384     /**
385      * Get a byte associated with the given configuration key.
386      *
387      * @param key The configuration key.
388      * @param defaultValue The default value.
389      * @return The associated byte if key is found and has valid format, default
390      * value otherwise.
391      * @exception ClassCastException is thrown if the key maps to an object that
392      * is not a Byte.
393      * @exception NumberFormatException is thrown if the value mapped by the key
394      * has not a valid number format.
395      */

396     public Byte JavaDoc getByte(String JavaDoc key, Byte JavaDoc defaultValue)
397     {
398         try
399         {
400             return getFirstMatchingConfig(key).getByte(key, defaultValue);
401         }
402         catch (NoSuchElementException JavaDoc nsee)
403         {
404             return defaultValue;
405         }
406     }
407     /**
408      * Get a double associated with the given configuration key.
409      *
410      * @param key The configuration key.
411      * @return The associated double.
412      * @exception NoSuchElementException is thrown if the key doesn't
413      * map to an existing object.
414      * @exception ClassCastException is thrown if the key maps to an
415      * object that is not a Double.
416      * @exception NumberFormatException is thrown if the value mapped
417      * by the key has not a valid number format.
418      */

419     public double getDouble(String JavaDoc key)
420     {
421         return getFirstMatchingConfig(key).getDouble(key);
422     }
423     /**
424      * Get a double associated with the given configuration key.
425      *
426      * @param key The configuration key.
427      * @param defaultValue The default value.
428      * @return The associated double.
429      * @exception ClassCastException is thrown if the key maps to an
430      * object that is not a Double.
431      * @exception NumberFormatException is thrown if the value mapped
432      * by the key has not a valid number format.
433      */

434     public double getDouble(String JavaDoc key, double defaultValue)
435     {
436         return getDouble(key, new Double JavaDoc(defaultValue)).doubleValue();
437     }
438     /**
439      * Get a double associated with the given configuration key.
440      *
441      * @param key The configuration key.
442      * @param defaultValue The default value.
443      * @return The associated double if key is found and has valid
444      * format, default value otherwise.
445      * @exception ClassCastException is thrown if the key maps to an
446      * object that is not a Double.
447      * @exception NumberFormatException is thrown if the value mapped
448      * by the key has not a valid number format.
449      */

450     public Double JavaDoc getDouble(String JavaDoc key, Double JavaDoc defaultValue)
451     {
452         try
453         {
454             return getFirstMatchingConfig(key).getDouble(key, defaultValue);
455         }
456         catch (NoSuchElementException JavaDoc nsee)
457         {
458             return defaultValue;
459         }
460     }
461     /**
462      * Get a float associated with the given configuration key.
463      *
464      * @param key The configuration key.
465      * @param defaultValue The default value.
466      * @return The associated float.
467      * @exception ClassCastException is thrown if the key maps to an
468      * object that is not a Float.
469      * @exception NumberFormatException is thrown if the value mapped
470      * by the key has not a valid number format.
471      */

472     public float getFloat(String JavaDoc key, float defaultValue)
473     {
474         return getFloat(key, new Float JavaDoc(defaultValue)).floatValue();
475     }
476     /**
477      * Get a float associated with the given configuration key.
478      *
479      * @param key The configuration key.
480      * @param defaultValue The default value.
481      * @return The associated float if key is found and has valid
482      * format, default value otherwise.
483      * @exception ClassCastException is thrown if the key maps to an
484      * object that is not a Float.
485      * @exception NumberFormatException is thrown if the value mapped
486      * by the key has not a valid number format.
487      */

488     public Float JavaDoc getFloat(String JavaDoc key, Float JavaDoc defaultValue)
489     {
490         try
491         {
492             return getFirstMatchingConfig(key).getFloat(key, defaultValue);
493         }
494         catch (NoSuchElementException JavaDoc nsee)
495         {
496             return defaultValue;
497         }
498     }
499     /**
500      * Get a int associated with the given configuration key.
501      *
502      * @param key The configuration key.
503      * @return The associated int.
504      * @exception NoSuchElementException is thrown if the key doesn't
505      * map to an existing object.
506      * @exception ClassCastException is thrown if the key maps to an
507      * object that is not a Integer.
508      * @exception NumberFormatException is thrown if the value mapped
509      * by the key has not a valid number format.
510      */

511     public int getInt(String JavaDoc key)
512     {
513         return getFirstMatchingConfig(key).getInt(key);
514     }
515     /**
516      * Get a int associated with the given configuration key.
517      *
518      * @param key The configuration key.
519      * @param defaultValue The default value.
520      * @return The associated int.
521      * @exception ClassCastException is thrown if the key maps to an
522      * object that is not a Integer.
523      * @exception NumberFormatException is thrown if the value mapped
524      * by the key has not a valid number format.
525      */

526     public int getInt(String JavaDoc key, int defaultValue)
527     {
528         return getInteger(key, new Integer JavaDoc(defaultValue)).intValue();
529     }
530     /**
531      * Get a int associated with the given configuration key.
532      *
533      * @param key The configuration key.
534      * @param defaultValue The default value.
535      * @return The associated int if key is found and has valid format, default
536      * value otherwise.
537      * @exception ClassCastException is thrown if the key maps to an object that
538      * is not a Integer.
539      * @exception NumberFormatException is thrown if the value mapped by the key
540      * has not a valid number format.
541      */

542     public Integer JavaDoc getInteger(String JavaDoc key, Integer JavaDoc defaultValue)
543     {
544         try
545         {
546             return getFirstMatchingConfig(key).getInteger(key, defaultValue);
547         }
548         catch (NoSuchElementException JavaDoc nsee)
549         {
550             return defaultValue;
551         }
552     }
553     /**
554      * Get a long associated with the given configuration key.
555      *
556      * @param key The configuration key.
557      * @return The associated long.
558      * @exception NoSuchElementException is thrown if the key doesn't
559      * map to an existing object.
560      * @exception ClassCastException is thrown if the key maps to an
561      * object that is not a Long.
562      * @exception NumberFormatException is thrown if the value mapped
563      * by the key has not a valid number format.
564      */

565     public long getLong(String JavaDoc key)
566     {
567         return getFirstMatchingConfig(key).getLong(key);
568     }
569     /**
570      * Get a long associated with the given configuration key.
571      *
572      * @param key The configuration key.
573      * @param defaultValue The default value.
574      * @return The associated long.
575      * @exception ClassCastException is thrown if the key maps to an
576      * object that is not a Long.
577      * @exception NumberFormatException is thrown if the value mapped
578      * by the key has not a valid number format.
579      */

580     public long getLong(String JavaDoc key, long defaultValue)
581     {
582         return getLong(key, new Long JavaDoc(defaultValue)).longValue();
583     }
584     /**
585      * Get a long associated with the given configuration key.
586      *
587      * @param key The configuration key.
588      * @param defaultValue The default value.
589      * @return The associated long if key is found and has valid
590      * format, default value otherwise.
591      * @exception ClassCastException is thrown if the key maps to an
592      * object that is not a Long.
593      * @exception NumberFormatException is thrown if the value mapped
594      * by the key has not a valid number format.
595      */

596     public Long JavaDoc getLong(String JavaDoc key, Long JavaDoc defaultValue)
597     {
598         try
599         {
600             return getFirstMatchingConfig(key).getLong(key, defaultValue);
601         }
602         catch (NoSuchElementException JavaDoc nsee)
603         {
604             return defaultValue;
605         }
606     }
607     /**
608      * Get a short associated with the given configuration key.
609      *
610      * @param key The configuration key.
611      * @return The associated short.
612      * @exception NoSuchElementException is thrown if the key doesn't
613      * map to an existing object.
614      * @exception ClassCastException is thrown if the key maps to an
615      * object that is not a Short.
616      * @exception NumberFormatException is thrown if the value mapped
617      * by the key has not a valid number format.
618      */

619     public short getShort(String JavaDoc key)
620     {
621         return getFirstMatchingConfig(key).getShort(key);
622     }
623     /**
624      * Get a short associated with the given configuration key.
625      *
626      * @param key The configuration key.
627      * @param defaultValue The default value.
628      * @return The associated short.
629      * @exception ClassCastException is thrown if the key maps to an
630      * object that is not a Short.
631      * @exception NumberFormatException is thrown if the value mapped
632      * by the key has not a valid number format.
633      */

634     public short getShort(String JavaDoc key, short defaultValue)
635     {
636         return getShort(key, new Short JavaDoc(defaultValue)).shortValue();
637     }
638     /**
639      * Get a short associated with the given configuration key.
640      *
641      * @param key The configuration key.
642      * @param defaultValue The default value.
643      * @return The associated short if key is found and has valid
644      * format, default value otherwise.
645      * @exception ClassCastException is thrown if the key maps to an
646      * object that is not a Short.
647      * @exception NumberFormatException is thrown if the value mapped
648      * by the key has not a valid number format.
649      */

650     public Short JavaDoc getShort(String JavaDoc key, Short JavaDoc defaultValue)
651     {
652         try
653         {
654             return getFirstMatchingConfig(key).getShort(key, defaultValue);
655         }
656         catch (NoSuchElementException JavaDoc nsee)
657         {
658             return defaultValue;
659         }
660     }
661     /**
662      * Get a string associated with the given configuration key.
663      *
664      * @param key The configuration key.
665      * @return The associated string.
666      * @exception ClassCastException is thrown if the key maps to an object that
667      * is not a String.
668      */

669     public String JavaDoc getString(String JavaDoc key)
670     {
671         return getString(key, null);
672     }
673     /**
674      * Get a string associated with the given configuration key.
675      *
676      * @param key The configuration key.
677      * @param defaultValue The default value.
678      * @return The associated string if key is found, default value otherwise.
679      * @exception ClassCastException is thrown if the key maps to an object that
680      * is not a String.
681      */

682     public String JavaDoc getString(String JavaDoc key, String JavaDoc defaultValue)
683     {
684         try
685         {
686             return getFirstMatchingConfig(key).getString(key, defaultValue);
687         }
688         catch (NoSuchElementException JavaDoc nsee)
689         {
690             return defaultValue;
691         }
692     }
693     /**
694      * Get an array of strings associated with the given configuration
695      * key.
696      *
697      * @param key The configuration key.
698      * @return The associated string array if key is found.
699      * @exception ClassCastException is thrown if the key maps to an
700      * object that is not a String/Vector of Strings.
701      */

702     public String JavaDoc[] getStringArray(String JavaDoc key)
703     {
704         Vector JavaDoc v = getVector(key);
705         return (String JavaDoc []) v.toArray(new String JavaDoc [0]);
706     }
707
708     /**
709      * Get a Vector of strings associated with the given configuration key.
710      *
711      * @param key The configuration key.
712      * @return The associated Vector.
713      * @exception ClassCastException is thrown if the key maps to an
714      * object that is not a Vector.
715      */

716     public Vector JavaDoc getVector(String JavaDoc key)
717     {
718         Vector JavaDoc v = new Vector JavaDoc();
719
720         for (ListIterator JavaDoc li = configList.listIterator(); li.hasNext();)
721         {
722             Configuration config = (Configuration) li.next();
723             if (config.containsKey(key))
724             {
725                 v.addAll(config.getVector(key));
726             }
727         }
728
729         return v;
730     }
731
732     /**
733      * Get a Vector of strings associated with the given configuration key.
734      *
735      * @param key The configuration key.
736      * @param defaultValue The default value.
737      * @return The associated Vector.
738      * @exception ClassCastException is thrown if the key maps to an
739      * object that is not a Vector.
740      */

741     public Vector JavaDoc getVector(String JavaDoc key, Vector JavaDoc defaultValue)
742     {
743         Vector JavaDoc v = getVector(key);
744
745         return (v.size() == 0) ? defaultValue : v;
746     }
747
748     private Configuration getFirstMatchingConfig(String JavaDoc key)
749     {
750         for (ListIterator JavaDoc i = configList.listIterator(); i.hasNext();)
751         {
752             Configuration config = (Configuration) i.next();
753             if (config.containsKey(key))
754             {
755                 return config;
756             }
757         }
758         throw new NoSuchElementException JavaDoc(
759             '\'' + key + "' doesn't map to an existing object");
760     }
761
762     public Configuration getConfiguration(int index)
763     {
764         return (Configuration) configList.get(index);
765     }
766 }
767
Popular Tags