karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject [2/2] git commit: [KARAF-1560] config:update throws ClassCastException when used on a Configuration with boolean fields created in the web console Use generics for configuration Dictionary
Date Thu, 10 Jul 2014 13:28:23 GMT
[KARAF-1560] config:update throws ClassCastException when used on a Configuration with boolean
fields created in the web console
Use generics for configuration Dictionary


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

Branch: refs/heads/karaf-2.3.x
Commit: b846b03e34fc7a3a380fc62ebff0048e3c6b9556
Parents: 932f712
Author: Guillaume Nodet <gnodet@gmail.com>
Authored: Thu Jul 10 15:07:14 2014 +0200
Committer: Guillaume Nodet <gnodet@gmail.com>
Committed: Thu Jul 10 15:28:07 2014 +0200

----------------------------------------------------------------------
 .../shell/config/ConfigCommandSupport.java      | 22 +++++++++++---------
 .../config/ConfigPropertyCommandSupport.java    | 10 +++++----
 .../apache/karaf/shell/config/EditCommand.java  |  5 +++--
 .../karaf/shell/config/PropAppendCommand.java   |  2 +-
 .../karaf/shell/config/PropDelCommand.java      |  2 +-
 .../karaf/shell/config/PropListCommand.java     |  6 +++---
 .../karaf/shell/config/PropSetCommand.java      |  2 +-
 .../karaf/shell/config/UpdateCommand.java       |  2 +-
 8 files changed, 28 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/b846b03e/shell/config/src/main/java/org/apache/karaf/shell/config/ConfigCommandSupport.java
----------------------------------------------------------------------
diff --git a/shell/config/src/main/java/org/apache/karaf/shell/config/ConfigCommandSupport.java
b/shell/config/src/main/java/org/apache/karaf/shell/config/ConfigCommandSupport.java
index c972033..111bcf7 100644
--- a/shell/config/src/main/java/org/apache/karaf/shell/config/ConfigCommandSupport.java
+++ b/shell/config/src/main/java/org/apache/karaf/shell/config/ConfigCommandSupport.java
@@ -69,8 +69,8 @@ public abstract class ConfigCommandSupport extends OsgiCommandSupport {
         return null;
     }
 
-    protected Dictionary getEditedProps() throws Exception {
-        return (Dictionary) this.session.get(PROPERTY_CONFIG_PROPS);
+    protected Dictionary<String, Object> getEditedProps() throws Exception {
+        return (Dictionary<String, Object>) this.session.get(PROPERTY_CONFIG_PROPS);
     }
 
     protected ConfigurationAdmin getConfigurationAdmin() {
@@ -134,7 +134,7 @@ public abstract class ConfigCommandSupport extends OsgiCommandSupport
{
      * @param bypassStorage
      * @throws IOException
      */
-    protected void update(ConfigurationAdmin admin, String pid, Dictionary props, boolean
bypassStorage) throws IOException {
+    protected void update(ConfigurationAdmin admin, String pid, Dictionary<String, Object>
props, boolean bypassStorage) throws IOException {
         if (!bypassStorage && storage != null) {
             persistConfiguration(admin, pid, props);
         } else {
@@ -150,7 +150,7 @@ public abstract class ConfigCommandSupport extends OsgiCommandSupport
{
      * @param props
      * @throws IOException
      */
-    protected void persistConfiguration(ConfigurationAdmin admin, String pid, Dictionary
props) throws IOException {
+    protected void persistConfiguration(ConfigurationAdmin admin, String pid, Dictionary<String,
Object> props) throws IOException {
         File storageFile = new File(storage, pid + ".cfg");
         Configuration cfg = admin.getConfiguration(pid, null);
         if (cfg != null && cfg.getProperties() != null) {
@@ -170,22 +170,24 @@ public abstract class ConfigCommandSupport extends OsgiCommandSupport
{
             }
         }
         Properties p = new Properties(storageFile);
-        for (Enumeration keys = props.keys(); keys.hasMoreElements(); ) {
-            Object key = keys.nextElement();
+        for (Enumeration<String> keys = props.keys(); keys.hasMoreElements(); ) {
+            String key = keys.nextElement();
             if (!Constants.SERVICE_PID.equals(key)
                     && !ConfigurationAdmin.SERVICE_FACTORYPID.equals(key)
                     && !FILEINSTALL_FILE_NAME.equals(key)) {
-                p.put((String) key, (String) props.get(key));
+                if (props.get(key) != null) {
+                    p.put(key, props.get(key).toString());
+                }
             }
         }
         // remove "removed" properties from the file
         ArrayList<String> propertiesToRemove = new ArrayList<String>();
-        for (Object key : p.keySet()) {
+        for (String key : p.keySet()) {
             if (props.get(key) == null
                     && !Constants.SERVICE_PID.equals(key)
                     && !ConfigurationAdmin.SERVICE_FACTORYPID.equals(key)
                     && !FILEINSTALL_FILE_NAME.equals(key)) {
-                propertiesToRemove.add(key.toString());
+                propertiesToRemove.add(key);
             }
         }
         for (String key : propertiesToRemove) {
@@ -225,7 +227,7 @@ public abstract class ConfigCommandSupport extends OsgiCommandSupport
{
      * @param props
      * @throws IOException
      */
-    public void updateConfiguration(ConfigurationAdmin admin, String pid, Dictionary props)
throws IOException {
+    public void updateConfiguration(ConfigurationAdmin admin, String pid, Dictionary<String,
Object> props) throws IOException {
         Configuration cfg = admin.getConfiguration(pid, null);
         if (cfg.getProperties() == null) {
             String[] pids = parsePid(pid);

http://git-wip-us.apache.org/repos/asf/karaf/blob/b846b03e/shell/config/src/main/java/org/apache/karaf/shell/config/ConfigPropertyCommandSupport.java
----------------------------------------------------------------------
diff --git a/shell/config/src/main/java/org/apache/karaf/shell/config/ConfigPropertyCommandSupport.java
b/shell/config/src/main/java/org/apache/karaf/shell/config/ConfigPropertyCommandSupport.java
index b4dfada..e69a8f7 100644
--- a/shell/config/src/main/java/org/apache/karaf/shell/config/ConfigPropertyCommandSupport.java
+++ b/shell/config/src/main/java/org/apache/karaf/shell/config/ConfigPropertyCommandSupport.java
@@ -21,6 +21,8 @@ package org.apache.karaf.shell.config;
 import java.util.Dictionary;
 
 import org.apache.felix.gogo.commands.Option;
+
+import java.util.Hashtable;
 import java.util.Properties;
 import org.osgi.service.cm.Configuration;
 import org.osgi.service.cm.ConfigurationAdmin;
@@ -38,7 +40,7 @@ public abstract class ConfigPropertyCommandSupport extends ConfigCommandSupport
 
 
     protected void doExecute(ConfigurationAdmin admin) throws Exception {
-        Dictionary props = getEditedProps();
+        Dictionary<String, Object> props = getEditedProps();
         if (bypassStorage && pid == null) {
         	System.err.println("Warning: option -b does not have any effect unless -p is also
specified.");
         }
@@ -46,7 +48,7 @@ public abstract class ConfigPropertyCommandSupport extends ConfigCommandSupport
             System.err.println("No configuration is being edited--run the edit command first");
         } else {
             if (props == null) {
-                props = new Properties();
+                props = new Hashtable<String, Object>();
             }
             propertyAction(props);
             if(requiresUpdate(pid)) {
@@ -59,7 +61,7 @@ public abstract class ConfigPropertyCommandSupport extends ConfigCommandSupport
      * Perform an action on the properties.
      * @param props
      */
-    protected abstract void propertyAction(Dictionary props);
+    protected abstract void propertyAction(Dictionary<String, Object> props);
 
     /**
      * Checks if the configuration requires to be updated.
@@ -82,7 +84,7 @@ public abstract class ConfigPropertyCommandSupport extends ConfigCommandSupport
      * @throws Exception
      */
     @Override
-    protected Dictionary getEditedProps() throws Exception {
+    protected Dictionary<String, Object> getEditedProps() throws Exception {
         if(pid != null) {
             ConfigurationAdmin configurationAdmin = getConfigurationAdmin();
             if (configurationAdmin != null) {

http://git-wip-us.apache.org/repos/asf/karaf/blob/b846b03e/shell/config/src/main/java/org/apache/karaf/shell/config/EditCommand.java
----------------------------------------------------------------------
diff --git a/shell/config/src/main/java/org/apache/karaf/shell/config/EditCommand.java b/shell/config/src/main/java/org/apache/karaf/shell/config/EditCommand.java
index ae43af9..96dc866 100644
--- a/shell/config/src/main/java/org/apache/karaf/shell/config/EditCommand.java
+++ b/shell/config/src/main/java/org/apache/karaf/shell/config/EditCommand.java
@@ -17,6 +17,7 @@
 package org.apache.karaf.shell.config;
 
 import java.util.Dictionary;
+import java.util.Hashtable;
 import java.util.Properties;
 
 import org.apache.felix.gogo.commands.Argument;
@@ -43,7 +44,7 @@ public class EditCommand extends ConfigCommandSupport {
             System.err.println("Another config is being edited.  Cancel / update first, or
use the --force option");
             return;
         }
-	    Dictionary props;
+	    Dictionary<String, Object> props;
 
 	    //User selected to use file instead.
         if (useFile) {
@@ -58,7 +59,7 @@ public class EditCommand extends ConfigCommandSupport {
             Configuration configuration = admin.getConfiguration(pid, null);
             props = configuration.getProperties();
             if (props == null) {
-                props = new Properties();
+                props = new Hashtable<String, Object>();
             }
         }
         this.session.put(PROPERTY_CONFIG_PID, pid);

http://git-wip-us.apache.org/repos/asf/karaf/blob/b846b03e/shell/config/src/main/java/org/apache/karaf/shell/config/PropAppendCommand.java
----------------------------------------------------------------------
diff --git a/shell/config/src/main/java/org/apache/karaf/shell/config/PropAppendCommand.java
b/shell/config/src/main/java/org/apache/karaf/shell/config/PropAppendCommand.java
index 39272a7..9a7c628 100644
--- a/shell/config/src/main/java/org/apache/karaf/shell/config/PropAppendCommand.java
+++ b/shell/config/src/main/java/org/apache/karaf/shell/config/PropAppendCommand.java
@@ -33,7 +33,7 @@ public class PropAppendCommand extends ConfigPropertyCommandSupport {
     String value;
 
     @Override
-    public void propertyAction(Dictionary props) {
+    public void propertyAction(Dictionary<String, Object> props) {
         final Object currentValue = props.get(prop);
         if (currentValue == null) {
             props.put(prop, value);

http://git-wip-us.apache.org/repos/asf/karaf/blob/b846b03e/shell/config/src/main/java/org/apache/karaf/shell/config/PropDelCommand.java
----------------------------------------------------------------------
diff --git a/shell/config/src/main/java/org/apache/karaf/shell/config/PropDelCommand.java
b/shell/config/src/main/java/org/apache/karaf/shell/config/PropDelCommand.java
index c8a5d11..a11c1f2 100644
--- a/shell/config/src/main/java/org/apache/karaf/shell/config/PropDelCommand.java
+++ b/shell/config/src/main/java/org/apache/karaf/shell/config/PropDelCommand.java
@@ -27,7 +27,7 @@ public class PropDelCommand extends ConfigPropertyCommandSupport {
     String prop;
 
     @Override
-    public void propertyAction(Dictionary props) {
+    public void propertyAction(Dictionary<String, Object> props) {
         props.remove(prop);
     }
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/b846b03e/shell/config/src/main/java/org/apache/karaf/shell/config/PropListCommand.java
----------------------------------------------------------------------
diff --git a/shell/config/src/main/java/org/apache/karaf/shell/config/PropListCommand.java
b/shell/config/src/main/java/org/apache/karaf/shell/config/PropListCommand.java
index ed2f45b..328ae9d 100644
--- a/shell/config/src/main/java/org/apache/karaf/shell/config/PropListCommand.java
+++ b/shell/config/src/main/java/org/apache/karaf/shell/config/PropListCommand.java
@@ -24,9 +24,9 @@ import org.apache.felix.gogo.commands.Command;
 public class PropListCommand extends ConfigPropertyCommandSupport {
 
     @Override
-    public void propertyAction(Dictionary props) {
-        for (Enumeration e = props.keys(); e.hasMoreElements(); ) {
-            Object key = e.nextElement();
+    public void propertyAction(Dictionary<String, Object> props) {
+        for (Enumeration<String> e = props.keys(); e.hasMoreElements(); ) {
+            String key = e.nextElement();
             System.out.println("   " + key + " = " + props.get(key));
         }
     }

http://git-wip-us.apache.org/repos/asf/karaf/blob/b846b03e/shell/config/src/main/java/org/apache/karaf/shell/config/PropSetCommand.java
----------------------------------------------------------------------
diff --git a/shell/config/src/main/java/org/apache/karaf/shell/config/PropSetCommand.java
b/shell/config/src/main/java/org/apache/karaf/shell/config/PropSetCommand.java
index 245340a..ba25eb5 100644
--- a/shell/config/src/main/java/org/apache/karaf/shell/config/PropSetCommand.java
+++ b/shell/config/src/main/java/org/apache/karaf/shell/config/PropSetCommand.java
@@ -32,7 +32,7 @@ public class PropSetCommand extends ConfigPropertyCommandSupport {
     String value;
 
     @Override
-    public void propertyAction(Dictionary props) {
+    public void propertyAction(Dictionary<String, Object> props) {
         props.put(prop, value);
     }
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/b846b03e/shell/config/src/main/java/org/apache/karaf/shell/config/UpdateCommand.java
----------------------------------------------------------------------
diff --git a/shell/config/src/main/java/org/apache/karaf/shell/config/UpdateCommand.java b/shell/config/src/main/java/org/apache/karaf/shell/config/UpdateCommand.java
index 6c99e12..0525a8b 100644
--- a/shell/config/src/main/java/org/apache/karaf/shell/config/UpdateCommand.java
+++ b/shell/config/src/main/java/org/apache/karaf/shell/config/UpdateCommand.java
@@ -31,7 +31,7 @@ public class UpdateCommand extends ConfigCommandSupport {
     protected boolean bypassStorage;
     
     protected void doExecute(ConfigurationAdmin admin) throws Exception {
-        Dictionary props = getEditedProps();
+        Dictionary<String, Object> props = getEditedProps();
         if (props == null) {
             System.err.println("No configuration is being edited--run the edit command first");
             return;


Mime
View raw message