2

I have two configuration files :

override.xml looks like this ...
<paths>
 <path>1</path>
 <path>2</path>
 <path>3</path>
</paths> 
<numbers>
 <number>100</number>
 <number>200</number>
</numbers>

default.xml looks like this ...
<paths>
 <path>4</path>
 <path>5</path>
 <path>6</path>
</paths>
<alphabets>
 <alphabet>A</alphabet>
 <alphabet>B</alphabet>
</alphabets>

I'm using a CompositeConfiguration. Adding override.xml first and then default.xml.

When I do a getList("paths.path") on the CompositeConfiguration, I get back 1,2,3,4,5,6. 

This tells me I'm getting back values from both override.xml and default.xml. Is there any way to get back values only from override.xml only since it overrides the default.xml values ?

At the same time if I were to do a getList("numbers.number"), I would expect 100,200 to be returned. A getList("alphabets.alphabet") to return A,B.

Adam
  • 21
  • 4

1 Answers1

1

Combining the contents of the list is the default behavior of getList of CompositeConfiguration. What you need to use is a CombinedConfiguration with appropriate NodeCombiner. For your use case, OverrideCombiner is appropriate. Sample code :

XMLConfiguration x1 = new XMLConfiguration();
....
XMLConfiguration x2 = new XMLConfiguration();
....
CombinedConfiguration config = new CombinedConfiguration(new OverrideCombiner());
config.addConfiguration(x1);
config.addConfiguration(x2);

Here the list defined in configuration x1 is returned when you do a config.getList("numbers.number")

linkcrux
  • 328
  • 4
  • 13