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:[EMAIL PROTECTED]
> 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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to