You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Emmanuel Bourg <eb...@apache.org> on 2005/04/14 10:55:56 UTC

Re: [configuration] IniFile support

Oliver Siegmar wrote:

> Does your implementation has default (a.k.a. global, a.k.a. common) section 
> support?

What do you mean by default section exactly ? Currently my 
implementation does the following:

- config.addProperty("foo.bar.xyz", "123") creates a [foo] section with 
a bar.xyz property:

     [foo]
     bar.xyz = 123

- config.addProperty("foo", "123") creates a foo property with no 
section, the property appears at the beginning of the file before the 
first section.

     foo = 123

     [section1]
     bar = 456


Emmanuel Bourg

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


Re: [configuration] IniFile support

Posted by Oliver Siegmar <ol...@siegmar.net>.
On Thursday 14 April 2005 11:42, Emmanuel Bourg wrote:
> Ok I see your point. There was a support for default values in
> PropertiesConfiguration some time ago but we removed it in favor of
> CompositeConfiguration. For consistency I think we will apply the same
> reasoning for INIConfiguration, that means you can emulate a similar
> behaviour with:

Sounds reasonable.

> Configuration iniconf = new INIConfiguration("config.ini");
> CompositeConfiguration conf = new CompositeConfiguration();
> conf.addConfiguration(iniconf.subset("section1"));
> conf.addConfiguration(iniconf.subset("default"));
>
> conf.getString("val") -> returns 50
>
>
> To make it easier I could add a method in INIConfiguration that build
> this CompositeConfiguration automatically. Something like:
>
> Configuration conf = iniconf.getSection("section1", "default");
> conf.getString("val");

I can live with that. The only drawback I see is, you have to know all 
sections your application will use in advance, right?


Best,
Oliver

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


Re: [configuration] IniFile support

Posted by Emmanuel Bourg <eb...@apache.org>.
Oliver Siegmar wrote:

> Many application ini files have some kind of default-section. Consider the 
> following ini-file:
> 
> --------------------------------
> [default]
> foo = 30
> val = 50
> 
> [section1]
> foo = 10
> --------------------------------

Ok I see your point. There was a support for default values in 
PropertiesConfiguration some time ago but we removed it in favor of 
CompositeConfiguration. For consistency I think we will apply the same 
reasoning for INIConfiguration, that means you can emulate a similar 
behaviour with:

Configuration iniconf = new INIConfiguration("config.ini");
CompositeConfiguration conf = new CompositeConfiguration();
conf.addConfiguration(iniconf.subset("section1"));
conf.addConfiguration(iniconf.subset("default"));

conf.getString("val") -> returns 50


To make it easier I could add a method in INIConfiguration that build 
this CompositeConfiguration automatically. Something like:

Configuration conf = iniconf.getSection("section1", "default");
conf.getString("val");

Emmanuel Bourg

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


Re: [configuration] IniFile support

Posted by Oliver Siegmar <ol...@siegmar.net>.
On Thursday 14 April 2005 10:55, Emmanuel Bourg wrote:
> Oliver Siegmar wrote:
> > Does your implementation has default (a.k.a. global, a.k.a. common)
> > section support?
>
> What do you mean by default section exactly ? Currently my
> implementation does the following:

Many application ini files have some kind of default-section. Consider the 
following ini-file:

--------------------------------
[default]
foo = 30
val = 50

[section1]
foo = 10
--------------------------------

In some applications the [default]-section is called [common] or [global] - or 
even different.

One of the constructors could be:

public IniFileConfiguration(String fileName, String defaultSection)


The application could be:

Configuration conf = new IniFileConfiguration("/tmp/test.ini", "default");

conf.getString("section1.foo") -> would return 10
conf.getString("section1.val") -> would return 50


Best,
Oliver

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