Oliver Siegmar wrote on Thursday, April 14, 2005 11:12 AM:

> 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:
 
[snip]

well, such a behaviour would be different from all other configuration 
implemnetations and I don't think it is worth the hassle. You can have the same 
functionality with CompositeConfiguration either by using two files or two 
subsections:

========= %< ==========

 app.ini:
 [section1]
 foo=10

 defaults.ini:
 [section1]
 foo=30
 val=50


 CompositeConfiguration config = new CompositeConfiguration();
 config.add(new IniConfiguration("app.ini"));
 config.add(new IniConfiguration("defaults.ini"));

 assertEquals(10,config.getInt("section1.foo"));
 assertEquals(50,config.getInt("section1.val"));

========= %< ==========

or 

========= %< ==========

 app.ini:
 [default]
 foo=30
 val=50
 [section1]
 foo=10


 CompositeConfiguration config = new CompositeConfiguration();
 Configuration iniConfig = new IniConfiguration("app.ini");
 config.add(iniConfig.subset("section1"));
 config.add(iniConfig.subset("default"));

 assertEquals(10,config.getInt("foo"));
 assertEquals(50,config.getInt("val"));

========= %< ==========

this mechanism is portable for all configurations (even mixed ones). You might 
keep your defaults in a DB and overwrite some from command line.

- Jörg

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

Reply via email to