Author: oheger Date: Mon Aug 15 20:07:42 2011 New Revision: 1157974 URL: http://svn.apache.org/viewvc?rev=1157974&view=rev Log: [CONFIGURATION-460] Ensure that the CombinedConfiguration used for sources in the additional section is correctly initialized, so that reloading works.
Modified: commons/proper/configuration/trunk/conf/testComplexInitialization.xml commons/proper/configuration/trunk/src/changes/changes.xml commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/DefaultConfigurationBuilder.java commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestDefaultConfigurationBuilder.java Modified: commons/proper/configuration/trunk/conf/testComplexInitialization.xml URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/conf/testComplexInitialization.xml?rev=1157974&r1=1157973&r2=1157974&view=diff ============================================================================== --- commons/proper/configuration/trunk/conf/testComplexInitialization.xml (original) +++ commons/proper/configuration/trunk/conf/testComplexInitialization.xml Mon Aug 15 20:07:42 2011 @@ -2,7 +2,8 @@ <!-- Test configuration definition file that demonstrates complex initialization --> <configuration> <header> - <result delimiterParsingDisabled="true"> + <result delimiterParsingDisabled="true" forceReloadCheck="true" + ignoreReloadExceptions="true"> <nodeCombiner config-class="org.apache.commons.configuration.tree.OverrideCombiner"/> <expressionEngine config-class="org.apache.commons.configuration.tree.xpath.XPathExpressionEngine"/> </result> Modified: commons/proper/configuration/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/changes/changes.xml?rev=1157974&r1=1157973&r2=1157974&view=diff ============================================================================== --- commons/proper/configuration/trunk/src/changes/changes.xml (original) +++ commons/proper/configuration/trunk/src/changes/changes.xml Mon Aug 15 20:07:42 2011 @@ -23,6 +23,11 @@ <body> <release version="1.7" date="in SVN" description=""> + <action dev="oheger" type="fix" issue="CONFIGURATION-460"> + Reloading now also works for configuration sources declared in the + additional section of a configuration definition file for + DefaultConfigurationBuilder. + </action> <action dev="oheger" type="add" issue="CONFIGURATION-458"> HierarchicalConfiguration now provides a specific implementation of the clear() method. This is more efficient and also solves some other Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/DefaultConfigurationBuilder.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/DefaultConfigurationBuilder.java?rev=1157974&r1=1157973&r2=1157974&view=diff ============================================================================== --- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/DefaultConfigurationBuilder.java (original) +++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/DefaultConfigurationBuilder.java Mon Aug 15 20:07:42 2011 @@ -603,8 +603,7 @@ public class DefaultConfigurationBuilder List additionals = fetchChildConfigs(KEY_UNION); if (!additionals.isEmpty()) { - CombinedConfiguration addConfig = new CombinedConfiguration( - new UnionCombiner()); + CombinedConfiguration addConfig = createAdditionalsConfiguration(result); result.addConfiguration(addConfig, ADDITIONAL_NAME); initCombinedConfiguration(addConfig, additionals, KEY_ADDITIONAL_LIST); @@ -641,12 +640,38 @@ public class DefaultConfigurationBuilder } /** + * Creates the <code>CombinedConfiguration</code> for the configuration + * sources in the <code><additional></code> section. This method is + * called when the builder constructs the final configuration. It creates a + * new <code>CombinedConfiguration</code> and initializes some properties + * from the result configuration. + * + * @param resultConfig the result configuration (this is the configuration + * that will be returned by the builder) + * @return the <code>CombinedConfiguration</code> for the additional + * configuration sources + * @since 1.7 + */ + protected CombinedConfiguration createAdditionalsConfiguration( + CombinedConfiguration resultConfig) + { + CombinedConfiguration addConfig = + new CombinedConfiguration(new UnionCombiner()); + addConfig.setDelimiterParsingDisabled(resultConfig + .isDelimiterParsingDisabled()); + addConfig.setForceReloadCheck(resultConfig.isForceReloadCheck()); + addConfig.setIgnoreReloadExceptions(resultConfig + .isIgnoreReloadExceptions()); + return addConfig; + } + + /** * Initializes a combined configuration for the configurations of a specific * section. This method is called for the override and for the additional * section (if it exists). * * @param config the configuration to be initialized - * @param containedConfigs the list with the declaratinos of the contained + * @param containedConfigs the list with the declarations of the contained * configurations * @param keyListNodes a list with the declaration of list nodes * @throws ConfigurationException if an error occurs Modified: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestDefaultConfigurationBuilder.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestDefaultConfigurationBuilder.java?rev=1157974&r1=1157973&r2=1157974&view=diff ============================================================================== --- commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestDefaultConfigurationBuilder.java (original) +++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestDefaultConfigurationBuilder.java Mon Aug 15 20:07:42 2011 @@ -730,7 +730,7 @@ public class TestDefaultConfigurationBui /** * Tests if the returned combined configuration has the expected structure. */ - public void testCombinedConfiguration() throws ConfigurationException + public void testCombinedConfigurationStructure() throws ConfigurationException { factory.setFile(INIT_FILE); CombinedConfiguration cc = (CombinedConfiguration) factory @@ -752,6 +752,35 @@ public class TestDefaultConfigurationBui } /** + * Helper method for testing the attributes of a combined configuration + * created by the builder. + * + * @param cc the configuration to be checked + */ + private void checkCombinedConfigAttrs(CombinedConfiguration cc) + { + assertTrue("Wrong delimiter parsing flag", + cc.isDelimiterParsingDisabled()); + assertTrue("Wrong reload check", cc.isForceReloadCheck()); + assertTrue("Wrong ignore reload ex flag", cc.isIgnoreReloadExceptions()); + } + + /** + * Tests whether attributes are correctly set on the combined configurations + * for the override and additional sections. + */ + public void testCombinedConfigurationAttributes() throws ConfigurationException + { + factory.setFile(INIT_FILE); + CombinedConfiguration cc = (CombinedConfiguration) factory + .getConfiguration(); + checkCombinedConfigAttrs(cc); + CombinedConfiguration cc2 = (CombinedConfiguration) cc + .getConfiguration(DefaultConfigurationBuilder.ADDITIONAL_NAME); + checkCombinedConfigAttrs(cc2); + } + + /** * Tests the structure of the returned combined configuration if there is no * additional section. */