commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Emmanuel Bourg <ebo...@micropole-univers.com>
Subject Re: [configuration] Refactor AbstractConfiguration(Configuration defaults)
Date Mon, 16 Feb 2004 16:23:30 GMT
Eric Pugh wrote:

> Are we sure we want to do the deprecated?  Seems odd to have 1.0 have a
> deprecated method..  It may make more sense to just add another howto:  How
> to save your properties set in CompositeConfiguration?  Basically should be
> able to just grab out the inmemory and save it by hand...

That seems quite complicated, using a CompositeConfiguration we would 
have (I'm not familiar with this class so let me know if my use case is 
wrong) :

// loading
Configuration default = new PropertiesConfiguration("default.properties");

Configuration config = new PropertiesConfiguration("myapp.properties");

CompositeConfiguration cc = new CompositeConfiguration();
cc.addConfiguration(default);
cc.addConfiguration(config);

// using/modifying
cc.addProperty("foo", "bar");

// saving (assuming the previous reference is not available here)
PropertiesConfiguration pc = (PropertiesConfiguration) 
cc.getConfiguration(1);
Configuration inmemory = cc.getConfiguration(0);
Iterator it = inmemory.getKeys();
while (it.hasNext()) {
     String key = (String) it.next();
     pc.addProperty(key, inmemory.getProperty(key));
}
pc.save();


using an unmodified PropertiesConfiguration this would be reduced to :

// loading
Configuration default = new PropertiesConfiguration("default.properties");

PropertiesConfiguration config = new 
PropertiesConfiguration("myapp.properties", default);

// using
config.addProperty("foo", "bar");

// saving
config.save();


Emmanuel






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


Mime
View raw message