commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Heger <oliver.he...@t-online.de>
Subject Re: [Configuration] save
Date Sat, 13 May 2006 14:08:48 GMT
Hello Borut,

Borut BolĨina wrote:

> Hello,
>
> when instantiating CompositeConfiguration with
>
>      ConfigurationFactory factory = new
> ConfigurationFactory(confDefinition);
>      try {
>         CompositeConfiguration config = (CompositeConfiguration)
> factory.getConfiguration();
>                return config;
>      } catch (ConfigurationException e) {
>         e.printStackTrace();
>      }
>
> where confDefinition is a configuration.xml file defining several
> properties file
>
>    <?xml version="1.0" encoding="ISO-8859-1" ?>
>    <configuration>
>      <properties fileName="i-want-to-save-here.properties"/>
>      <xml fileName="a.xml"/>
>      <xml fileName="b.xml"/>
>      <xml fileName="c.xml"/>
>    </configuration>
>
> it would be nice to define which properties to save to by something like
>
>    config.setDefaultSaveConfiguration(config.getConfiguration(0)); //
>    would be "i-want-to-save-here.properties"
>    // or even better by "named-and-not-by-index" configuration
>
> then calling
>
>    config.save()
>
> would save any changes made by
>
>    config.setProperty("newProperty","new value");
>
> to i-want-to-save-here.properties.
>
> Currently, one must extract
>
>    PropertiesConfiguration pc = (PropertiesConfiguration)
>    config.getConfiguration(0);
>
> set the desired property
>
>    pc.setProperty("newProperty","new value");
>    or
>    config.setProperty("newProperty","new value");
>    if instantiated by
>
>    PropertiesConfiguration pc = new
>    PropertiesConfiguration(fileToSaveChangesIn);
>    Configuration config = new CompositeConfiguration(saveConfiguration);
>
> and call
>
>    pc.save();
>
> Or did I miss something?
>
> Regards,
> Borut
>
>
CompositeConfiguration at least supports a so-called "in-memory
configuration", to which all new properties are added. This can play the
role of your "default save configuration". However there seems to be no
possibility to set the in-memory configuration after the composite
configuration was created.

After having looked at the source code I fear it won't be easy to
implement the behavior you suggested because the current implementation
does not expect the in-memory configuration to belong to the regular
list of configurations that have been added to the composite. It is
treated differently at many places.

Well, while the problems mentioned above can surely be solved, I am
reluctant of adding a save() method to CompositeConfiguration. A save()
operation is special to file-based configurations while a
CompositeConfiguration supports all types of configurations. In this
case I think, it is acceptable for the user to do something like this:

((FileConfiguration) config.getInMemoryConfiguration()).save());

Oliver

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