karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject svn commit: r1496165 - /karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java
Date Mon, 24 Jun 2013 19:12:07 GMT
Author: jbonofre
Date: Mon Jun 24 19:12:06 2013
New Revision: 1496165

URL: http://svn.apache.org/r1496165
Log:
[KARAF-2347] Small improvements on the Cellar configuration

Modified:
    karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java

Modified: karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java?rev=1496165&r1=1496164&r2=1496165&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java
(original)
+++ karaf/cellar/branches/cellar-2.3.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java
Mon Jun 24 19:12:06 2013
@@ -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 extend
      */
     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 extend
         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 extend
                 return false;
         }
 
-        if (source.size() != target.size())
-            return false;
-
         return true;
     }
 
@@ -108,7 +103,7 @@ public class ConfigurationSupport extend
             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 extend
                         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