felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dsav...@apache.org
Subject svn commit: r995661 - in /felix/trunk/sigil/common/core/src/org/apache/felix/sigil/common/config: BldConfig.java BldProject.java IBldProject.java
Date Fri, 10 Sep 2010 04:06:22 GMT
Author: dsavage
Date: Fri Sep 10 04:06:22 2010
New Revision: 995661

URL: http://svn.apache.org/viewvc?rev=995661&view=rev
Log:
add clone support for config objects

Modified:
    felix/trunk/sigil/common/core/src/org/apache/felix/sigil/common/config/BldConfig.java
    felix/trunk/sigil/common/core/src/org/apache/felix/sigil/common/config/BldProject.java
    felix/trunk/sigil/common/core/src/org/apache/felix/sigil/common/config/IBldProject.java

Modified: felix/trunk/sigil/common/core/src/org/apache/felix/sigil/common/config/BldConfig.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/core/src/org/apache/felix/sigil/common/config/BldConfig.java?rev=995661&r1=995660&r2=995661&view=diff
==============================================================================
--- felix/trunk/sigil/common/core/src/org/apache/felix/sigil/common/config/BldConfig.java
(original)
+++ felix/trunk/sigil/common/core/src/org/apache/felix/sigil/common/config/BldConfig.java
Fri Sep 10 04:06:22 2010
@@ -32,7 +32,7 @@ import java.util.TreeMap;
 
 import org.apache.felix.sigil.common.util.QuoteUtil;
 
-public class BldConfig
+public class BldConfig implements Cloneable
 {
     // control properties
     public static final String C_BUNDLES = "-bundles";
@@ -593,4 +593,66 @@ public class BldConfig
         return "STRING: " + string + " LIST:" + list + " MAP: " + map + " PROPERTY: "
             + property + " CONFIG:" + config + "\nDFLT{ " + dflt + "}";
     }
+    
+    public BldConfig clone() {
+        try
+        {
+            BldConfig bc = (BldConfig) super.clone();
+            bc.string = new TreeMap<String, String>(bc.string);
+            bc.list = cloneMap(bc.list);
+            bc.map = cloneMap(bc.map);
+            bc.config = new TreeMap<String, BldConfig>(bc.config);
+            bc.property = new TreeMap<String, Properties>(bc.property);
+
+            // default config - not modified or saved
+            // bc.dflt = bc.dflt.clone();
+
+            bc.unknown = cloneProps(bc.unknown);
+            
+            return bc;
+        }
+        catch (CloneNotSupportedException e)
+        {
+            throw new IllegalStateException(e);
+        }
+    }
+    
+    @SuppressWarnings("unchecked")
+    private static <K, V> Map<K, V> cloneMap(Map<K,V> map) {
+        Map clone = new TreeMap();
+        for (Map.Entry<?,?> e : map.entrySet()) {
+            if ( e.getValue() == null ) {
+                clone.put(e.getKey(), null);
+            }
+            else if ( e.getValue() instanceof List<?> ) {
+                clone.put(e.getKey(), new ArrayList((List<?>) e.getValue()));
+            }
+            else if (e.getValue() instanceof Map<?,?>) {
+                clone.put(e.getKey(), cloneMap((Map<?,?>)e.getValue()));
+            }
+            else if (e.getValue() instanceof String) {
+                clone.put(e.getKey(), e.getValue());
+            }
+            else if (e.getValue() instanceof BldConfig) {
+                BldConfig c = (BldConfig) e.getValue();
+                clone.put(e.getKey(), c.clone());
+            }
+            else if (e.getValue() instanceof Properties) {
+                Properties p = (Properties) e.getValue();
+                clone.put(e.getKey(), cloneProps(p));
+            }
+            else {
+                throw new IllegalStateException("Unexpected value: " + e.getValue());
+            }
+        }
+        return clone;
+    }
+    
+    private static Properties cloneProps(Properties p) {
+        Properties props = new Properties();
+        for (Map.Entry<?,?> pe : props.entrySet()) {
+            props.put(pe.getKey(), pe.getValue());
+        }
+        return props;
+    }
 }

Modified: felix/trunk/sigil/common/core/src/org/apache/felix/sigil/common/config/BldProject.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/core/src/org/apache/felix/sigil/common/config/BldProject.java?rev=995661&r1=995660&r2=995661&view=diff
==============================================================================
--- felix/trunk/sigil/common/core/src/org/apache/felix/sigil/common/config/BldProject.java
(original)
+++ felix/trunk/sigil/common/core/src/org/apache/felix/sigil/common/config/BldProject.java
Fri Sep 10 04:06:22 2010
@@ -57,7 +57,7 @@ import org.apache.felix.sigil.common.mod
 import org.apache.felix.sigil.common.osgi.VersionRange;
 import org.apache.felix.sigil.common.osgi.VersionTable;
 
-public class BldProject implements IBldProject, IRepositoryConfig
+public class BldProject implements IBldProject, IRepositoryConfig, Cloneable
 {
     private static final String OVERRIDE_PREFIX = "sigil.";
     private static final int MAX_HEADER = 10240;
@@ -840,6 +840,22 @@ public class BldProject implements IBldP
         for (File d : dirs)
             findSrcPkgs(d, pkg, result);
     }
+    
+    public BldProject clone() {
+        BldProject p;
+        try
+        {
+            p = (BldProject) super.clone();
+            p.config = p.config.clone();
+            p.convert = new BldConverter(p.config);
+            p.requirements = p.requirements == null ? null : p.requirements.clone();
+        }
+        catch (CloneNotSupportedException e)
+        {
+            throw new IllegalStateException(e);
+        }
+        return p;
+    }
 
     /**
      * BldBundle

Modified: felix/trunk/sigil/common/core/src/org/apache/felix/sigil/common/config/IBldProject.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/core/src/org/apache/felix/sigil/common/config/IBldProject.java?rev=995661&r1=995660&r2=995661&view=diff
==============================================================================
--- felix/trunk/sigil/common/core/src/org/apache/felix/sigil/common/config/IBldProject.java
(original)
+++ felix/trunk/sigil/common/core/src/org/apache/felix/sigil/common/config/IBldProject.java
Fri Sep 10 04:06:22 2010
@@ -129,6 +129,8 @@ public interface IBldProject
      * gets the last modification date of the project file.
      */
     long getLastModified();
+    
+    IBldProject clone();
 
     interface IBldBundle
     {



Mime
View raw message