Author: oheger Date: Mon Jul 9 13:34:27 2007 New Revision: 554757 URL: http://svn.apache.org/viewvc?view=rev&rev=554757 Log: CONFIGURATION-275: AbstractConfiguration.addProperty() now correctly deals with list and array properties if delimiter parsing is disabled
Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractConfiguration.java jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestAbstractConfigurationBasicFeatures.java jakarta/commons/proper/configuration/trunk/xdocs/changes.xml Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractConfiguration.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractConfiguration.java?view=diff&rev=554757&r1=554756&r2=554757 ============================================================================== --- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractConfiguration.java (original) +++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractConfiguration.java Mon Jul 9 13:34:27 2007 @@ -117,6 +117,13 @@ /** end token */ protected static final String END_TOKEN = "}"; + /** + * Constant for the disabled list delimiter. This character is passed to the + * list parsing methods if delimiter parsing is disabled. So this character + * should not occur in string property values. + */ + private static final char DISABLED_DELIMITER = '\0'; + /** The default value for listDelimiter */ private static char defaultListDelimiter = ','; @@ -381,17 +388,12 @@ { fireEvent(EVENT_ADD_PROPERTY, key, value, true); - if (!isDelimiterParsingDisabled()) - { - Iterator it = PropertyConverter.toIterator(value, getListDelimiter()); - while (it.hasNext()) - { - addPropertyDirect(key, it.next()); - } - } - else + Iterator it = PropertyConverter.toIterator(value, + isDelimiterParsingDisabled() ? DISABLED_DELIMITER + : getListDelimiter()); + while (it.hasNext()) { - addPropertyDirect(key, value); + addPropertyDirect(key, it.next()); } fireEvent(EVENT_ADD_PROPERTY, key, value, false); @@ -399,7 +401,7 @@ /** * Adds a key/value pair to the Configuration. Override this method to - * provide write acces to underlying Configuration store. + * provide write access to underlying Configuration store. * * @param key key to use for mapping * @param value object to store Modified: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestAbstractConfigurationBasicFeatures.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestAbstractConfigurationBasicFeatures.java?view=diff&rev=554757&r1=554756&r2=554757 ============================================================================== --- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestAbstractConfigurationBasicFeatures.java (original) +++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestAbstractConfigurationBasicFeatures.java Mon Jul 9 13:34:27 2007 @@ -20,6 +20,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Iterator; +import java.util.List; import org.apache.commons.collections.CollectionUtils; @@ -76,6 +77,50 @@ "Wrong interpolated value", "${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc.jar,${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc_license_cu.jar", config.getString("mypath")); + } + + /** + * Tests adding list properties. The single elements of the list should be + * added. + */ + public void testAddPropertyList() + { + checkAddListProperty(new TestConfigurationImpl( + new PropertiesConfiguration())); + } + + /** + * Tests adding list properties when delimiter parsing is disabled. + */ + public void testAddPropertyListNoDelimiterParsing() + { + AbstractConfiguration config = new TestConfigurationImpl( + new PropertiesConfiguration()); + config.setDelimiterParsingDisabled(true); + checkAddListProperty(config); + } + + /** + * Helper method for adding properties with multiple values. + * + * @param config the configuration to be used for testing + */ + private void checkAddListProperty(AbstractConfiguration config) + { + config.addProperty("test", "value1"); + Object[] lstValues1 = new Object[] + { "value2", "value3" }; + Object[] lstValues2 = new Object[] + { "value4", "value5", "value6" }; + config.addProperty("test", lstValues1); + config.addProperty("test", Arrays.asList(lstValues2)); + List lst = config.getList("test"); + assertEquals("Wrong number of list elements", 6, lst.size()); + for (int i = 0; i < lst.size(); i++) + { + assertEquals("Wrong list element at " + i, "value" + (i + 1), lst + .get(i)); + } } /** Modified: jakarta/commons/proper/configuration/trunk/xdocs/changes.xml URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/xdocs/changes.xml?view=diff&rev=554757&r1=554756&r2=554757 ============================================================================== --- jakarta/commons/proper/configuration/trunk/xdocs/changes.xml (original) +++ jakarta/commons/proper/configuration/trunk/xdocs/changes.xml Mon Jul 9 13:34:27 2007 @@ -23,6 +23,10 @@ <body> <release version="1.5-SNAPSHOT" date="in SVN" description=""> + <action dev="oheger" type="fix" issue="CONFIGURATION-275"> + AbstractConfiguration.addProperty() now correctly deals with list and + array properties if delimiter parsing is disabled. + </action> <action dev="oheger" type="fix" issue="CONFIGURATION-282"> The default expression engine used by HierarchicalConfiguration instances is now lazily initialized. This avoids NullPointerExceptions --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]