Author: oheger
Date: Sat Aug 22 15:13:31 2009
New Revision: 806862
URL: http://svn.apache.org/viewvc?rev=806862&view=rev
Log:
[CONFIGURATION-393] Special treatment of collection properties when cloning a
BaseConfiguration.
Modified:
commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/BaseConfiguration.java
commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestBaseConfiguration.java
commons/proper/configuration/trunk/xdocs/changes.xml
Modified:
commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/BaseConfiguration.java
URL:
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/BaseConfiguration.java?rev=806862&r1=806861&r2=806862&view=diff
==============================================================================
---
commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/BaseConfiguration.java
(original)
+++
commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/BaseConfiguration.java
Sat Aug 22 15:13:31 2009
@@ -18,6 +18,7 @@
package org.apache.commons.configuration;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -25,7 +26,7 @@
import org.apache.commons.collections.map.LinkedMap;
/**
- * Basic configuration classe. Stores the configuration data but does not
+ * Basic configuration class. Stores the configuration data but does not
* provide any load or save functions. If you want to load your Configuration
* from a file use PropertiesConfiguration or XmlConfiguration.
*
@@ -45,7 +46,7 @@
* @author <a href="mailto:[email protected]">Martin Poeschl</a>
* @author <a href="mailto:[email protected]">Henning P. Schmiedehausen</a>
* @author <a href="mailto:[email protected]">Konstantin Shaposhnikov</a>
- * @author <a href="mailto:[email protected]">Oliver Heger</a>
+ * @author Oliver Heger
* @version $Id$
*/
public class BaseConfiguration extends AbstractConfiguration implements
Cloneable
@@ -165,6 +166,18 @@
{
BaseConfiguration copy = (BaseConfiguration) super.clone();
copy.store = (Map) ConfigurationUtils.clone(store);
+
+ // Handle collections in the map; they have to be cloned, too
+ for (Iterator it = store.entrySet().iterator(); it.hasNext();)
+ {
+ Map.Entry e = (Map.Entry) it.next();
+ if (e.getValue() instanceof Collection)
+ {
+ copy.store.put(e.getKey(), new ArrayList((Collection) e
+ .getValue()));
+ }
+ }
+
return copy;
}
catch (CloneNotSupportedException cex)
Modified:
commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestBaseConfiguration.java
URL:
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestBaseConfiguration.java?rev=806862&r1=806861&r2=806862&view=diff
==============================================================================
---
commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestBaseConfiguration.java
(original)
+++
commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestBaseConfiguration.java
Sat Aug 22 15:13:31 2009
@@ -804,4 +804,18 @@
assertEquals("Event listener was copied", 0, config2
.getConfigurationListeners().size());
}
+
+ /**
+ * Tests the clone() method if a list property is involved.
+ */
+ public void testCloneListProperty()
+ {
+ final String key = "list";
+ config.addProperty(key, "value1");
+ config.addProperty(key, "value2");
+ BaseConfiguration config2 = (BaseConfiguration) config.clone();
+ config2.addProperty(key, "value3");
+ assertEquals("Wrong number of original properties", 2, config.getList(
+ key).size());
+ }
}
Modified: commons/proper/configuration/trunk/xdocs/changes.xml
URL:
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/xdocs/changes.xml?rev=806862&r1=806861&r2=806862&view=diff
==============================================================================
--- commons/proper/configuration/trunk/xdocs/changes.xml (original)
+++ commons/proper/configuration/trunk/xdocs/changes.xml Sat Aug 22 15:13:31
2009
@@ -23,6 +23,10 @@
<body>
<release version="1.7" date="in SVN" description="">
+ <action dev="oheger" type="fix" issue="CONFIGURATION-393">
+ BaseConfiguration.clone() now also clones collections stored in the
+ internal map. This causes list properties to be handled correctly.
+ </action>
<action dev="rgoers" type="fix" issue="CONFIGURATION-388">
Attribute or element values will not be escaped when attribute or
element splitting are disabled.
</action>