henning 2003/07/06 11:17:56
Modified: configuration/src/java/org/apache/commons/configuration
CompositeConfiguration.java
Log:
Changed getStringArray() and getVector() to return all the
configuration values referenced in all sub configurations.
Now CompositeConfiguration and Simple Configurations behave just the same
Revision Changes Path
1.15 +20 -23
jakarta-commons-sandbox/configuration/src/java/org/apache/commons/configuration/CompositeConfiguration.java
Index: CompositeConfiguration.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/configuration/src/java/org/apache/commons/configuration/CompositeConfiguration.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- CompositeConfiguration.java 6 Jul 2003 15:19:08 -0000 1.14
+++ CompositeConfiguration.java 6 Jul 2003 18:17:56 -0000 1.15
@@ -698,15 +698,10 @@
*/
public String[] getStringArray(String key)
{
- try
- {
- return getFirstMatchingConfig(key).getStringArray(key);
- }
- catch (NoSuchElementException nsee)
- {
- return new String[0];
- }
+ Vector v = getVector(key);
+ return (String []) v.toArray(new String [0]);
}
+
/**
* Get a Vector of strings associated with the given configuration key.
*
@@ -717,15 +712,20 @@
*/
public Vector getVector(String key)
{
- try
+ Vector v = new Vector();
+
+ for (ListIterator li = configList.listIterator(); li.hasNext();)
{
- return getFirstMatchingConfig(key).getVector(key);
- }
- catch (NoSuchElementException nsee)
- {
- return new Vector();
+ Configuration config = (Configuration) li.next();
+ if (config.containsKey(key))
+ {
+ v.addAll(config.getVector(key));
+ }
}
+
+ return v;
}
+
/**
* Get a Vector of strings associated with the given configuration key.
*
@@ -737,15 +737,11 @@
*/
public Vector getVector(String key, Vector defaultValue)
{
- try
- {
- return getFirstMatchingConfig(key).getVector(key, defaultValue);
- }
- catch (NoSuchElementException nsee)
- {
- return defaultValue;
- }
+ Vector v = getVector(key);
+
+ return (v.size() == 0) ? defaultValue : v;
}
+
private Configuration getFirstMatchingConfig(String key)
{
for (ListIterator i = configList.listIterator(); i.hasNext();)
@@ -759,6 +755,7 @@
throw new NoSuchElementException(
'\'' + key + "' doesn't map to an existing object");
}
+
public Configuration getConfiguration(int index)
{
return (Configuration) configList.get(index);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]