commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Heger <oliver.he...@oliver-heger.de>
Subject Re: [configuration] CombinedConfiguration#clone() not cloning changed properties
Date Wed, 05 Dec 2012 20:51:42 GMT
Am 05.12.2012 16:32, schrieb Andre Weihe:
> CombinedConfiguration#clone() does not clone properties set/changed on the CombinedConfiguration
that are stored in combinedRoot (which seems NOT to be cloned).
>
> Bug, feature or "You are using it wrong!"?

Probably a kind of missing feature...

This seems to be the same problem as for updates of a 
CombinedConfiguration as described in the user's guide [1].

When the CombinedConfiguration is cloned, its nodes structure is not 
cloned, but only the list of child configurations. (From these 
configurations the nodes tree is constructed again.) If changes were 
made which could not be assigned to one of the source configurations, 
they are lost.

I guess, a specific strategy has to be defined how to handle updates of 
a CombinedConfiguration in general. Currently, it is certainly not ideal.

Oliver

[1] 
http://commons.apache.org/configuration/userguide/howto_combinedconfiguration.html#Dealing_with_changes
>
>
> Demonstration program:
> import org.apache.commons.configuration.*;
> import org.apache.commons.configuration.tree.OverrideCombiner;
> import java.util.Iterator;
>
> public class CommonsConfigurationTester {
>      private static final String FOO_KEY = "Test.foo";
>      private static final String BAR_KEY = "Test.bar";
>
>      public static void main(String[] args) {
>          new CommonsConfigurationTester().ccTest();
>      }
>
>      void ccTest() {
>          HierarchicalConfiguration defaultConfig = new HierarchicalConfiguration();
>          defaultConfig.addProperty(FOO_KEY, Integer.valueOf(1));
>          defaultConfig.addProperty(BAR_KEY, Integer.valueOf(2));
>
>          System.out.println("Default config:\n" + configToString(defaultConfig));
>
>          HierarchicalConfiguration individualConfig = new HierarchicalConfiguration();
>          individualConfig.addProperty(FOO_KEY, Integer.valueOf(3));
>          individualConfig.addProperty(BAR_KEY, Integer.valueOf(4));
>
>          System.out.println("Individual config (has precedence):\n" + configToString(individualConfig));
>
>          CombinedConfiguration combinedConfig = new CombinedConfiguration(new OverrideCombiner());
>          combinedConfig.addConfiguration(individualConfig);
>          combinedConfig.addConfiguration(defaultConfig);
>
>          System.out.println("Combined config (default + individual):\n" + configToString(combinedConfig));
>
>          combinedConfig.setProperty(FOO_KEY, Integer.valueOf(5));
>          combinedConfig.setProperty(BAR_KEY, Integer.valueOf(6));
>
>          System.out.println("Changed config (default + individual):\n" + configToString(combinedConfig));
>
>          CombinedConfiguration combinedConfig2 = (CombinedConfiguration)combinedConfig.clone();
>
>          System.out.println("Cloned changed config (default + individual):\n" + configToString(combinedConfig2));
>      }
>
>
>      /**
>       * A little helper method to get all the settings of a configuration into a String
>       * @param config the Configuration whose String representation we want
>       * @return a String containing the key-value pairs
>       */
>      static String configToString(Configuration config) {
>          String pairs = new String();
>          for (Iterator keys = config.getKeys(); keys.hasNext();) {
>              String key = (String)keys.next();
>              pairs = pairs + key + '=' + config.getProperty(key) + '\n';
>          }
>
>          return pairs;
>      }
> }
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message