commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eric Pugh" <ep...@upstate.com>
Subject RE: [configuration] Refactor AbstractConfiguration(Configuration defaults)
Date Mon, 16 Feb 2004 17:06:17 GMT
You are right about that..  It is simpler..  The problem is that it ONLY
works when pass in a default that works like that..  I think maybe a better
approach would be to change CompositeConfiguratoin.  Right now the issue is
that this returns a memory only config object:

Configuration inmemory = cc.getConfiguration(0);

And saving it is a pain!  I think we should a method:

CompositeConfiguration(Configuration changesConfig)
setChangesConfiguration()
getChangesConfgiuration().

By default you get back a inmemory config like we have today.  But, in your
usecase we woudl do this

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

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

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

 // saving
changes.save();
//
PropertiesConfiguration needToSave =
(PropertiesConfiguration)cc.getChangesConfiguration()


although I don't like the name get/setChangesConfiguration, maybe
get/setDeltaConfiguration?

ERic





> -----Original Message-----
> From: Emmanuel Bourg [mailto:ebourg@micropole-univers.com]
> Sent: Monday, February 16, 2004 5:23 PM
> To: Jakarta Commons Developers List
> Subject: Re: [configuration] Refactor
> AbstractConfiguration(Configuration defaults)
>
>
> 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


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