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/11/22 14:39:20 UTC

svn commit: r1544533 - in /karaf/trunk/config/core/src/main/java/org/apache/karaf/config/core: ConfigMBean.java impl/Config.java

Author: jbonofre
Date: Fri Nov 22 13:39:20 2013
New Revision: 1544533

URL: http://svn.apache.org/r1544533
Log:
[KARAF-2264] Wrap exceptions as MBeanException in the ConfigMBean

Modified:
    karaf/trunk/config/core/src/main/java/org/apache/karaf/config/core/ConfigMBean.java
    karaf/trunk/config/core/src/main/java/org/apache/karaf/config/core/impl/Config.java

Modified: karaf/trunk/config/core/src/main/java/org/apache/karaf/config/core/ConfigMBean.java
URL: http://svn.apache.org/viewvc/karaf/trunk/config/core/src/main/java/org/apache/karaf/config/core/ConfigMBean.java?rev=1544533&r1=1544532&r2=1544533&view=diff
==============================================================================
--- karaf/trunk/config/core/src/main/java/org/apache/karaf/config/core/ConfigMBean.java (original)
+++ karaf/trunk/config/core/src/main/java/org/apache/karaf/config/core/ConfigMBean.java Fri Nov 22 13:39:20 2013
@@ -13,6 +13,7 @@
  */
 package org.apache.karaf.config.core;
 
+import javax.management.MBeanException;
 import java.io.IOException;
 import java.util.List;
 import java.util.Map;
@@ -28,7 +29,7 @@ public interface ConfigMBean {
      * @return the list of all configuration PIDs.
      * @throws Exception
      */
-    List<String> getConfigs() throws Exception;
+    List<String> getConfigs() throws MBeanException;
 
     /**
      * Create a new configuration for the given PID.
@@ -36,9 +37,9 @@ public interface ConfigMBean {
      * @param pid the configuration PID.
      * @throws Exception
      */
-    void create(String pid) throws Exception;
+    void create(String pid) throws MBeanException;
     
-    void update(String pid, Map<String, String> properties) throws IOException;
+    void update(String pid, Map<String, String> properties) throws MBeanException;
 
     /**
      * Delete a configuration identified by the given PID.
@@ -46,7 +47,7 @@ public interface ConfigMBean {
      * @param pid the configuration PID to delete.
      * @throws Exception
      */
-    void delete(String pid) throws Exception;
+    void delete(String pid) throws MBeanException;
 
     /**
      * Get the list of properties for a configuration PID.
@@ -55,7 +56,7 @@ public interface ConfigMBean {
      * @return the list of properties.
      * @throws Exception
      */
-    Map<String, String> listProperties(String pid) throws Exception;
+    Map<String, String> listProperties(String pid) throws MBeanException;
 
     /**
      * Remove the configuration property identified by the given key.
@@ -64,7 +65,7 @@ public interface ConfigMBean {
      * @param key the property key.
      * @throws Exception
      */
-    void deleteProperty(String pid, String key) throws Exception;
+    void deleteProperty(String pid, String key) throws MBeanException;
 
     /**
      * Append (or add) a value for the given configuration key.
@@ -74,7 +75,7 @@ public interface ConfigMBean {
      * @param value the value to append to the current property value.
      * @throws Exception
      */
-    void appendProperty(String pid, String key, String value) throws Exception;
+    void appendProperty(String pid, String key, String value) throws MBeanException;
 
     /**
      * Set a configuration property.
@@ -84,6 +85,6 @@ public interface ConfigMBean {
      * @param value the property value.
      * @throws Exception
      */
-    void setProperty(String pid, String key, String value) throws Exception;
+    void setProperty(String pid, String key, String value) throws MBeanException;
 
 }

Modified: karaf/trunk/config/core/src/main/java/org/apache/karaf/config/core/impl/Config.java
URL: http://svn.apache.org/viewvc/karaf/trunk/config/core/src/main/java/org/apache/karaf/config/core/impl/Config.java?rev=1544533&r1=1544532&r2=1544533&view=diff
==============================================================================
--- karaf/trunk/config/core/src/main/java/org/apache/karaf/config/core/impl/Config.java (original)
+++ karaf/trunk/config/core/src/main/java/org/apache/karaf/config/core/impl/Config.java Fri Nov 22 13:39:20 2013
@@ -22,6 +22,7 @@ import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
 
+import javax.management.MBeanException;
 import javax.management.NotCompliantMBeanException;
 import javax.management.StandardMBean;
 
@@ -47,7 +48,7 @@ public class Config extends StandardMBea
         }
         return configuration;
     }
-    
+
     @SuppressWarnings("rawtypes")
     private Dictionary getConfigProperties(String pid) throws IOException {
         Configuration configuration = getConfiguration(pid);
@@ -62,75 +63,107 @@ public class Config extends StandardMBea
     /**
      * Get all config pids
      */
-    public List<String> getConfigs() throws Exception {
-        Configuration[] configurations = this.configRepo.getConfigAdmin().listConfigurations(null);
-        List<String> pids = new ArrayList<String>();
-        for (int i = 0; i < configurations.length; i++) {
-            pids.add(configurations[i].getPid());
+    public List<String> getConfigs() throws MBeanException {
+        try {
+            Configuration[] configurations = this.configRepo.getConfigAdmin().listConfigurations(null);
+            List<String> pids = new ArrayList<String>();
+            for (int i = 0; i < configurations.length; i++) {
+                pids.add(configurations[i].getPid());
+            }
+            return pids;
+        } catch (Exception e) {
+            throw new MBeanException(null, e.getMessage());
         }
-        return pids;
     }
 
     @SuppressWarnings("rawtypes")
-    public void create(String pid) throws Exception {
-        configRepo.update(pid, new Hashtable());
+    public void create(String pid) throws MBeanException {
+        try {
+            configRepo.update(pid, new Hashtable());
+        } catch (Exception e) {
+            throw new MBeanException(null, e.getMessage());
+        }
     }
-    
 
-    public void update(String pid, Map<String, String> properties) throws IOException {
-        if (properties == null) {
-            properties = new HashMap<String, String>();
-        }
-        Dictionary<String, String> dictionary = new Hashtable<String, String>();
-        for (String key : properties.keySet()) {
-            dictionary.put(key, properties.get(key));
+
+    public void update(String pid, Map<String, String> properties) throws MBeanException {
+        try {
+            if (properties == null) {
+                properties = new HashMap<String, String>();
+            }
+            Dictionary<String, String> dictionary = new Hashtable<String, String>();
+            for (String key : properties.keySet()) {
+                dictionary.put(key, properties.get(key));
+            }
+            configRepo.update(pid, dictionary);
+        } catch (Exception e) {
+            throw new MBeanException(null, e.getMessage());
         }
-        configRepo.update(pid, dictionary);
     }
 
-    public void delete(String pid) throws Exception {
-        this.configRepo.delete(pid);
+    public void delete(String pid) throws MBeanException {
+        try {
+            this.configRepo.delete(pid);
+        } catch (Exception e) {
+            throw new MBeanException(null, e.getMessage());
+        }
     }
 
     @SuppressWarnings("rawtypes")
-    public Map<String, String> listProperties(String pid) throws Exception {
-        Dictionary dictionary = getConfigProperties(pid);
-
-        Map<String, String> propertiesMap = new HashMap<String, String>();
-        for (Enumeration e = dictionary.keys(); e.hasMoreElements(); ) {
-            Object key = e.nextElement();
-            Object value = dictionary.get(key);
-            propertiesMap.put(key.toString(), value.toString());
+    public Map<String, String> listProperties(String pid) throws MBeanException {
+        try {
+            Dictionary dictionary = getConfigProperties(pid);
+
+            Map<String, String> propertiesMap = new HashMap<String, String>();
+            for (Enumeration e = dictionary.keys(); e.hasMoreElements(); ) {
+                Object key = e.nextElement();
+                Object value = dictionary.get(key);
+                propertiesMap.put(key.toString(), value.toString());
+            }
+            return propertiesMap;
+        } catch (Exception e) {
+            throw new MBeanException(null, e.getMessage());
         }
-        return propertiesMap;
     }
 
     @SuppressWarnings("rawtypes")
-    public void deleteProperty(String pid, String key) throws Exception {
-        Dictionary dictionary = getConfigProperties(pid);
-        dictionary.remove(key);
-        configRepo.update(pid, dictionary);
+    public void deleteProperty(String pid, String key) throws MBeanException {
+        try {
+            Dictionary dictionary = getConfigProperties(pid);
+            dictionary.remove(key);
+            configRepo.update(pid, dictionary);
+        } catch (Exception e) {
+            throw new MBeanException(null, e.getMessage());
+        }
     }
 
     @SuppressWarnings({"rawtypes", "unchecked"})
-    public void appendProperty(String pid, String key, String value) throws Exception {
-        Dictionary dictionary = getConfigProperties(pid);
-        Object currentValue = dictionary.get(key);
-        if (currentValue == null) {
-            dictionary.put(key, value);
-        } else if (currentValue instanceof String) {
-            dictionary.put(key, currentValue + value);
-        } else {
-            throw new IllegalStateException("Current value is not a String");
+    public void appendProperty(String pid, String key, String value) throws MBeanException {
+        try {
+            Dictionary dictionary = getConfigProperties(pid);
+            Object currentValue = dictionary.get(key);
+            if (currentValue == null) {
+                dictionary.put(key, value);
+            } else if (currentValue instanceof String) {
+                dictionary.put(key, currentValue + value);
+            } else {
+                throw new IllegalStateException("Current value is not a String");
+            }
+            configRepo.update(pid, dictionary);
+        } catch (Exception e) {
+            throw new MBeanException(null, e.getMessage());
         }
-        configRepo.update(pid, dictionary);
     }
 
     @SuppressWarnings({"rawtypes", "unchecked"})
-    public void setProperty(String pid, String key, String value) throws Exception {
-        Dictionary dictionary = getConfigProperties(pid);
-        dictionary.put(key, value);
-        configRepo.update(pid, dictionary);
+    public void setProperty(String pid, String key, String value) throws MBeanException {
+        try {
+            Dictionary dictionary = getConfigProperties(pid);
+            dictionary.put(key, value);
+            configRepo.update(pid, dictionary);
+        } catch (Exception e) {
+            throw new MBeanException(null, e.getMessage());
+        }
     }
 
     public void setConfigRepo(ConfigRepository configRepo) {