Return-Path:
Delivered-To: apmail-commons-commits-archive@minotaur.apache.org
Received: (qmail 51842 invoked from network); 22 Aug 2009 19:23:57 -0000
Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3)
by minotaur.apache.org with SMTP; 22 Aug 2009 19:23:57 -0000
Received: (qmail 29262 invoked by uid 500); 22 Aug 2009 19:24:17 -0000
Delivered-To: apmail-commons-commits-archive@commons.apache.org
Received: (qmail 29167 invoked by uid 500); 22 Aug 2009 19:24:17 -0000
Mailing-List: contact commits-help@commons.apache.org; run by ezmlm
Precedence: bulk
List-Help:
List-Unsubscribe:
List-Post:
List-Id:
Reply-To: dev@commons.apache.org
Delivered-To: mailing list commits@commons.apache.org
Received: (qmail 29158 invoked by uid 99); 22 Aug 2009 19:24:17 -0000
Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136)
by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 22 Aug 2009 19:24:17 +0000
X-ASF-Spam-Status: No, hits=-2000.0 required=10.0
tests=ALL_TRUSTED
X-Spam-Check-By: apache.org
Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4)
by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 22 Aug 2009 19:24:15 +0000
Received: by eris.apache.org (Postfix, from userid 65534)
id C737A23888E5; Sat, 22 Aug 2009 19:23:55 +0000 (UTC)
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: svn commit: r806881 - in
/commons/proper/configuration/branches/configuration2_experimental/src:
main/java/org/apache/commons/configuration2/base/MapConfigurationSource.java
test/java/org/apache/commons/configuration2/base/TestMapConfigurationSource.java
Date: Sat, 22 Aug 2009 19:23:55 -0000
To: commits@commons.apache.org
From: oheger@apache.org
X-Mailer: svnmailer-1.0.8
Message-Id: <20090822192355.C737A23888E5@eris.apache.org>
X-Virus-Checked: Checked by ClamAV on apache.org
Author: oheger
Date: Sat Aug 22 19:23:55 2009
New Revision: 806881
URL: http://svn.apache.org/viewvc?rev=806881&view=rev
Log:
Made MapConfigurationSource serializable and added a copy constructor.
Modified:
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/MapConfigurationSource.java
commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/base/TestMapConfigurationSource.java
Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/MapConfigurationSource.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/MapConfigurationSource.java?rev=806881&r1=806880&r2=806881&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/MapConfigurationSource.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/MapConfigurationSource.java Sat Aug 22 19:23:55 2009
@@ -16,7 +16,9 @@
*/
package org.apache.commons.configuration2.base;
+import java.io.Serializable;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
@@ -44,12 +46,24 @@
* that a map-like structure and keep their whole data in memory. An example
* could be a configuration source wrapping a properties file.
*
+ *
+ * {@code MapConfigurationSource} implements the {@code Serializable} interface.
+ * The data that is serialized basically consists of the map used as data store.
+ * Serialization can only be successful if all property values can be
+ * serialized.
+ *
*
* @author Commons Configuration team
* @version $Id$
*/
-public class MapConfigurationSource implements ConfigurationSource
+public class MapConfigurationSource implements ConfigurationSource,
+ Serializable
{
+ /**
+ * The serial version UID.
+ */
+ private static final long serialVersionUID = 3921765607397858876L;
+
/** The map acting as data store. */
private final Map store;
@@ -84,6 +98,42 @@
}
/**
+ * Creates a new instance of {@code MapConfigurationSource} and initializes
+ * it from the data of the specified {@code ConfigurationSource}. This
+ * constructor copies all properties stored in the passed in {@code
+ * ConfigurationSource} into this source.
+ *
+ * @param c the {@code ConfigurationSource} to be copied (must not be
+ * null)
+ * @throws IllegalArgumentException if the source to be copied is
+ * null
+ */
+ public MapConfigurationSource(ConfigurationSource c)
+ {
+ if (c == null)
+ {
+ throw new IllegalArgumentException(
+ "Source to copy must not be null!");
+ }
+
+ store = new LinkedHashMap();
+ for (Iterator it = c.getKeys(); it.hasNext();)
+ {
+ String key = it.next();
+ Object value = c.getProperty(key);
+
+ // special treatment of collection properties: the collections
+ // must be copied, too
+ if (value instanceof Collection>)
+ {
+ value = new ArrayList