epugh 2003/03/19 09:20:12 Modified: configuration/src/java/org/apache/commons/configuration CompositeConfiguration.java Log: Fixes for .subset method Revision Changes Path 1.6 +25 -10 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.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- CompositeConfiguration.java 19 Mar 2003 10:32:23 -0000 1.5 +++ CompositeConfiguration.java 19 Mar 2003 17:20:12 -0000 1.6 @@ -226,7 +226,7 @@ public void setProperty(String key, Object value) { clearProperty(key); - addProperty(key,value); + addProperty(key, value); } /** @@ -261,22 +261,28 @@ } /** - * Create an ExtendedProperties object that is a subset - * of this one. Take into account duplicate keys - * by using the setProperty() in ExtendedProperties. + * Create a CompositeConfiguration object that is a subset + * of this one. Cycles over all the config objects, and calls + * their subset method and then just adds that. * * @param prefix */ public Configuration subset(String prefix) { - CompositeConfiguration subsetConfig = new CompositeConfiguration(); + + CompositeConfiguration subsetCompositeConfiguration = + new CompositeConfiguration(); for (ListIterator i = configList.listIterator(); i.hasNext();) { Configuration config = (Configuration) i.next(); - subsetConfig.addConfiguration(config.subset(prefix)); + Configuration subset = config.subset(prefix); + if (subset != null) + { + subsetCompositeConfiguration.addConfiguration(subset); + } } - return subsetConfig; + return subsetCompositeConfiguration; } @@ -728,7 +734,15 @@ */ public String[] getStringArray(String key) { - return getFirstMatchingConfig(key).getStringArray(key); + try + { + + return getFirstMatchingConfig(key).getStringArray(key); + } + catch (NoSuchElementException nsee) + { + return new String[0]; + } } /** @@ -771,12 +785,13 @@ for (ListIterator i = configList.listIterator(); i.hasNext();) { Configuration config = (Configuration) i.next(); + if (config.containsKey(key)) { return config; } - } + } throw new NoSuchElementException( '\'' + key + "' doesn't map to an existing object"); }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]