ohmu
ohmu

Reputation: 19780

How do you use a CombinedConfiguration to override a default configuration?

When adding configurations to a CombinedConfiguration (from Apache Commons Configuration 2), how do you specify that one configuration overrides another?

For example, say I have a default configuration and a user configuration. If I want the user to override the default, how do I setup the the combined configuration?

XMLConfiguration defaultConfig = ...;
XMLConfiguration userConfig = ...;

CombinedConfiguration config = new CombinedConfiguration();
config.addConfiguration(defaultConfig);
config.addConfiguration(userConfig);

Upvotes: 0

Views: 901

Answers (2)

ohmu
ohmu

Reputation: 19780

The solution was to use an OverrideCombiner, and the configurations need to be added from highest to lowest priority.

CombinedConfiguration config = new CombinedConfiguration(new OverrideCombiner());
config.addConfiguration(userConfig);
config.addConfiguration(defaultConfig);

Upvotes: 1

miskender
miskender

Reputation: 7968

It depends on the which NodeCombiner passed to the constructor of the CombinedConfiguration class. For example if OverrideCombiner is used first item added to the configuration will take precedence over other nodes. If you call default constructor of CombinedConfiguration, UnionCombiner will be used.

OverrideCombiner Docs

MergeCombiner Docs

UnionCombiner Docs

Upvotes: 1

Related Questions