commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Heger <oliver.he...@oliver-heger.de>
Subject Re: [configuration] Merging overrides with defaults
Date Wed, 17 Jun 2009 20:29:19 GMT
Alec Swan schrieb:
> This is really unfortunate. The merged configuration is required to preserve
> comments from defaults, but not necessarily overrides.
> 
> Are there any plans to add this functionality in the near future?
> 
> Thanks.

This is a new feature that was not considered before.

I think, it is not trivial to implement in a really generic way. Your 
use case requires that one configuration overrides a default 
configuration. For another use case a different merge algorithm may be 
required. There are some details to think about.

However, you can open an enhancement request in our bug tracking system 
[1]. I don't know if somebody finds the time to work on this feature 
soon. But if you really need it, you can try to create a patch yourself. 
This is open source ;-)

Oliver

[1] http://commons.apache.org/configuration/issue-tracking.html

> 
> On Wed, Jun 17, 2009 at 1:54 PM, Oliver Heger
> <oliver.heger@oliver-heger.de>wrote:
> 
>> Alec Swan schrieb:
>>
>>> I wrote the code following the example on
>>>
>>> http://commons.apache.org/configuration/userguide-1.2/howto_compositeconfiguration.html
>>>
>>> There is no save() method in CompositeConfiguration. How can I save it?
>>>
>>> Thanks.
>>>
>> The merged configuration produced by CompositeConfiguration is only
>> virtual, i.e. there is no physical PropertiesConfiguration containing the
>> merged properties. It lives only in memory and cannot be saved.
>>
>> I am afraid, Commons Configuration does not provide an easy solution for
>> your problem. You can copy the content of the composite configuration into a
>> properties configuration, e.g.:
>>
>> PropertiesConfiguration propConfig = new PropertiesConfiguration();
>> propConfig.copy(compositeConfig);
>> propConfig.save(someFile);
>>
>> But this will copy only the properties and not the comments or the overall
>> layout.
>>
>> Oliver
>>
>>
>>
>>> On Wed, Jun 17, 2009 at 11:23 AM, Jörg Schaible <joerg.schaible@gmx.de
>>>> wrote:
>>>  Alec Swan wrote at Mittwoch, 17. Juni 2009 18:39:
>>>>  Thank you for updating the subject, Jörg.
>>>>> I changed the order in which I add defaults and overrides. The following
>>>>> is the new code:
>>>>>
>>>>>                    // merge overrides with defaults
>>>>>                    CompositeConfiguration compositeConfig = new
>>>>> CompositeConfiguration(overridingConfig);
>>>>>                    compositeConfig.addConfiguration(defaultConfig);
>>>>>
>>>>>                    // convert merged properties to string
>>>>>                    StringWriter writer = new StringWriter();
>>>>>                    overridingConfig.save(writer);
>>>>>
>>>>> defaultConfig contains the following properties:
>>>>> # A property
>>>>> A = 1
>>>>> # B property
>>>>> B = 2
>>>>>
>>>>> overridingConfig contains the following properties:
>>>>> B = 3
>>>>>
>>>>> I expected the merged content written to the writer to contain these
>>>>> properties:
>>>>> # A property
>>>>> A = 1
>>>>> # B property
>>>>> B = 3
>>>>>
>>>>> Instead, the merged content written to the writer is the same as the
>>>>> overridingConfig:
>>>>> B = 3
>>>>>
>>>>> Could anybody tell me what's wrong with my code?
>>>>>
>>>> You saved the overridingConfiguration and not the compositeConfig.
>>>>
>>>> - Jörg
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>>
>>>>
>>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>>
> 


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


Mime
View raw message