You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2013/12/18 13:27:48 UTC

[33/50] git commit: [KARAF-2347] Small improvements on the Cellar configuration

[KARAF-2347] Small improvements on the Cellar configuration

git-svn-id: https://svn.apache.org/repos/asf/karaf/cellar/branches/cellar-2.3.x@1496165 13f79535-47bb-0310-9956-ffa450edef68


Project: http://git-wip-us.apache.org/repos/asf/karaf-cellar/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf-cellar/commit/d0f45086
Tree: http://git-wip-us.apache.org/repos/asf/karaf-cellar/tree/d0f45086
Diff: http://git-wip-us.apache.org/repos/asf/karaf-cellar/diff/d0f45086

Branch: refs/heads/cellar-2.3.x
Commit: d0f4508609ae42fe6771f6e52470bf61130f0172
Parents: e021b41
Author: jbonofre <jb...@13f79535-47bb-0310-9956-ffa450edef68>
Authored: Mon Jun 24 19:12:06 2013 +0000
Committer: jbonofre <jb...@13f79535-47bb-0310-9956-ffa450edef68>
Committed: Mon Jun 24 19:12:06 2013 +0000

----------------------------------------------------------------------
 .../cellar/config/ConfigurationSupport.java     | 55 ++++++++++----------
 1 file changed, 27 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/d0f45086/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java
----------------------------------------------------------------------
diff --git a/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java b/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java
index 8d0ac2a..673e7be 100644
--- a/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java
+++ b/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java
@@ -21,10 +21,7 @@ import java.io.File;
 import java.io.IOException;
 import java.net.URI;
 import java.net.URL;
-import java.util.ArrayList;
-import java.util.Dictionary;
-import java.util.Enumeration;
-import java.util.Properties;
+import java.util.*;
 
 /**
  * Generic configuration support.
@@ -45,13 +42,11 @@ public class ConfigurationSupport extends CellarSupport {
      */
     public Properties dictionaryToProperties(Dictionary dictionary) {
         Properties properties = new Properties();
-        if (dictionary != null && dictionary.keys() != null) {
-
+        if (dictionary != null) {
             Enumeration keys = dictionary.keys();
             while (keys.hasMoreElements()) {
-                String key = (String) keys.nextElement();
+                Object key = keys.nextElement();
                 if (key != null && dictionary.get(key) != null) {
-                    String value = (String) dictionary.get(key);
                     properties.put(key, dictionary.get(key));
                 }
             }
@@ -76,11 +71,14 @@ public class ConfigurationSupport extends CellarSupport {
         if (source.isEmpty() && target.isEmpty())
             return true;
 
+        if (source.size() != target.size())
+            return false;
+
         Enumeration sourceKeys = source.keys();
         while (sourceKeys.hasMoreElements()) {
-            String key = (String) sourceKeys.nextElement();
-            String sourceValue = String.valueOf(source.get(key));
-            String targetValue = String.valueOf(target.get(key));
+            Object key = sourceKeys.nextElement();
+            Object sourceValue = source.get(key);
+            Object targetValue = target.get(key);
             if (sourceValue != null && targetValue == null)
                 return false;
             if (sourceValue == null && targetValue != null)
@@ -89,9 +87,6 @@ public class ConfigurationSupport extends CellarSupport {
                 return false;
         }
 
-        if (source.size() != target.size())
-            return false;
-
         return true;
     }
 
@@ -108,7 +103,7 @@ public class ConfigurationSupport extends CellarSupport {
             while (sourceKeys.hasMoreElements()) {
                 String key = (String) sourceKeys.nextElement();
                 if (!isExcludedProperty(key)) {
-                    String value = String.valueOf(dictionary.get(key));
+                    Object value = dictionary.get(key);
                     result.put(key, value);
                 }
             }
@@ -158,31 +153,35 @@ public class ConfigurationSupport extends CellarSupport {
                         storageFile = new File(new URL((String) val).toURI());
                     }
                 } catch (Exception e) {
-                    throw (IOException) new IOException(e.getMessage()).initCause(e);
+                    throw new IOException(e.getMessage(), e);
                 }
             }
+
             org.apache.felix.utils.properties.Properties p = new org.apache.felix.utils.properties.Properties(storageFile);
-            for (Enumeration keys = props.keys(); keys.hasMoreElements(); ) {
-                Object key = keys.nextElement();
+            List<String> propertiesToRemove = new ArrayList<String>();
+            Set<String> set = p.keySet();
+
+            for (String key : set) {
                 if (!org.osgi.framework.Constants.SERVICE_PID.equals(key)
                         && !ConfigurationAdmin.SERVICE_FACTORYPID.equals(key)
                         && !FELIX_FILEINSTALL_FILENAME.equals(key)) {
-                    p.put((String) key, (String) props.get(key));
+                    propertiesToRemove.add(key);
                 }
             }
-            // remove "removed" properties from the file
-            ArrayList<String> propertiesToRemove = new ArrayList<String>();
-            for (Object key : p.keySet()) {
-                if (props.get(key) == null
-                        && !org.osgi.framework.Constants.SERVICE_PID.equals(key)
+
+            for (String key : propertiesToRemove) {
+                p.remove(key);
+            }
+
+            for (Enumeration<String> keys = props.keys(); keys.hasMoreElements(); ) {
+                String key = keys.nextElement();
+                if (!org.osgi.framework.Constants.SERVICE_PID.equals(key)
                         && !ConfigurationAdmin.SERVICE_FACTORYPID.equals(key)
                         && !FELIX_FILEINSTALL_FILENAME.equals(key)) {
-                    propertiesToRemove.add(key.toString());
+                    p.put(key, (String) props.get(key));
                 }
             }
-            for (String key : propertiesToRemove) {
-                p.remove(key);
-            }
+
             // save the cfg file
             storage.mkdirs();
             p.save();