commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From marcus.dow...@breathe.com
Subject [configuration] Mutability of CompositeConfiguration
Date Wed, 15 Sep 2004 15:27:12 GMT
I am unsure whether CompositeConfiguration is mutable or immutable. 

 From the documentation, I was under the impression that it would be
immutable. By this, I mean that if you load it with configuration and then
add more configuration, if you repeat the same key in both sets of
configuration, the first definition of the key is the one that will be
returned when you look-up its value. 

If the second configuration updated the value of the key which had been
initially defined in the first configuration, I would consider it to be
mutable. 

I am trying to load configuration from a set of files but allow this
configuration to be overridden by System Properties. So I am loading the
system properties first and then adding the configuration from files. My
understanding is that configuration settings in CompositeConfiguration
would be immutable but my experience seems to be that this is not the case.
If I load a system property which is also included in the configuration
files, the one from configuration files is what is subsequently available.
Is this the behaviour that I should expect? 

Here is the code that I am using. 

     CompositeConfiguration compositeConfiguration = new
CompositeConfiguration(); 

     // load system properties - these override all others
     Properties properties = System.getProperties();
     Enumeration e = properties.propertyNames();
     String key;
     while (e.hasMoreElements()) {
           key = (String) e.nextElement();
           compositeConfiguration.setProperty(key,
properties.getProperty(key));
     } 

     // load file based properties
     ConfigurationFactory factory = new ConfigurationFactory();
     factory.setConfigurationURL(aConfigFileURL);
     Configuration configuration = factory.getConfiguration();
     compositeConfiguration.addConfiguration(configuration); 

So if I specify a system setting key/value pair of keyX=valueY where
configuration in my files sets keyX=valueZ, what should I get when I
retrieve the value after this set-up? 


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


Mime
View raw message