henning 2003/07/06 08:19:08 Modified: configuration/src/java/org/apache/commons/configuration CompositeConfiguration.java Log: One of the properties of the "normal" configuration objects like the PropertiesConfiguration is, that it keeps the sequence of keys the same as it was added. To get this from the CompositeConfiguration, it is necessary to keep the additional inMemory Keys at the back of the configuration list. Else things like adding single keys to an existing configuration (just as needed e.g. by Turbine) won't work. Revision Changes Path 1.14 +25 -9 jakarta-commons-sandbox/configuration/src/java/org/apache/commons/configuration/CompositeConfiguration.java Index: CompositeConfiguration.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/configuration/src/java/org/apache/commons/configuration/CompositeConfiguration.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- CompositeConfiguration.java 20 Jun 2003 07:50:47 -0000 1.13 +++ CompositeConfiguration.java 6 Jul 2003 15:19:08 -0000 1.14 @@ -52,13 +52,16 @@ * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ + import java.util.ArrayList; import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import java.util.ListIterator; import java.util.NoSuchElementException; import java.util.Properties; import java.util.Vector; + /** * This Configuration class allows you to add multiple different types of Configuration * to this CompositeConfiguration. If you add Configuration1, and then Configuration2, @@ -67,35 +70,48 @@ * If Configuration1 doesn't have the property, then Configuration2 will be checked. * * @author <a href="mailto:[EMAIL PROTECTED]">Eric Pugh</a> + * @author <a href="mailto:[EMAIL PROTECTED]">Henning P. Schmiedehausen</a> * @version $Id$ */ public class CompositeConfiguration implements Configuration { /** Array holding all the configuration */ - private ArrayList configList = new ArrayList(); - /** Configuration that holds in memory stuff. Inserted as first so any - * setProperty() override anything else added. + private LinkedList configList = new LinkedList(); + + /** + * Configuration that holds in memory stuff. Inserted as first so any + * setProperty() override anything else added. */ private BaseConfiguration inMemoryConfiguration; + /** * Creates an empty CompositeConfiguration object which can then * be added some other Configuration files */ public CompositeConfiguration() { - inMemoryConfiguration = new BaseConfiguration(); - addConfiguration(inMemoryConfiguration); + clear(); } + public void addConfiguration(Configuration config) { if (!configList.contains(config)) { - configList.add(config); + // As the inMemoryConfiguration contains all manually added keys, + // we must make sure that it is always last. "Normal", non composed + // configuration add their keys at the end of the configuration and + // we want to mimic this behaviour. + configList.add(configList.indexOf(inMemoryConfiguration), config); } } public void removeConfiguration(Configuration config) { - configList.remove(config); + // Make sure that you can't remove the inMemoryConfiguration from + // the CompositeConfiguration object + if (!config.equals(inMemoryConfiguration)) + { + configList.remove(config); + } } public int getNumberOfConfigurations() { @@ -106,7 +122,7 @@ configList.clear(); // recreate the in memory configuration inMemoryConfiguration = new BaseConfiguration(); - addConfiguration(inMemoryConfiguration); + configList.addLast(inMemoryConfiguration); } /** * CompositeConfigurations can not be added to
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]