karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject [40/50] [abbrv] git commit: [KARAF-2347] Small improvements on the Cellar configuration
Date Wed, 18 Dec 2013 12:23:15 GMT
[KARAF-2347] Small improvements on the Cellar configuration

git-svn-id: https://svn.apache.org/repos/asf/karaf/cellar/trunk@1496172 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/ffad5337
Tree: http://git-wip-us.apache.org/repos/asf/karaf-cellar/tree/ffad5337
Diff: http://git-wip-us.apache.org/repos/asf/karaf-cellar/diff/ffad5337

Branch: refs/heads/master
Commit: ffad53377078878e9b764d5e31451eb3ebde0312
Parents: 111c15c
Author: jbonofre <jbonofre@13f79535-47bb-0310-9956-ffa450edef68>
Authored: Mon Jun 24 19:32:37 2013 +0000
Committer: jbonofre <jbonofre@13f79535-47bb-0310-9956-ffa450edef68>
Committed: Mon Jun 24 19:32:37 2013 +0000

----------------------------------------------------------------------
 .../cellar/config/ConfigurationSupport.java     | 50 ++++++++++----------
 1 file changed, 26 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/ffad5337/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 f33d367..a3ee898 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
@@ -42,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));
                 }
             }
@@ -73,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)
@@ -86,9 +87,6 @@ public class ConfigurationSupport extends CellarSupport {
                 return false;
         }
 
-        if (source.size() != target.size())
-            return false;
-
         return true;
     }
 
@@ -105,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);
                 }
             }
@@ -156,31 +154,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();


Mime
View raw message