commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Heger <heg...@med.uni-marburg.de>
Subject Re: [configuration] Mutability of CompositeConfiguration
Date Thu, 16 Sep 2004 05:49:51 GMT
You can try the following:

Create a new PropertiesConfiguration object and copy the system 
properties in this object. Then add this configuration to the composite 
configuration.

After that load your configuration file using ConfigurationFactory and 
add the resulting Configuration to the composite configuration. Then the 
system properties should override the properties from file.

The reason for this behavior is that CompositeConfiguration operates on 
the Configuration objects it contains rather than on single properties.

HTH
Oliver

marcus.downes@breathe.com wrote:
> 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
> 
> 

---------------------------------------------------------------------
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