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 2011/09/21 14:33:06 UTC
svn commit: r1173595 - in
/karaf/trunk/management/mbeans/config/src/main/java/org/apache/karaf/management/mbeans/config:
ConfigMBean.java internal/ConfigMBeanImpl.java
Author: jbonofre
Date: Wed Sep 21 12:33:05 2011
New Revision: 1173595
URL: http://svn.apache.org/viewvc?rev=1173595&view=rev
Log:
[KARAF-786] Complete the ConfigMBean.
Modified:
karaf/trunk/management/mbeans/config/src/main/java/org/apache/karaf/management/mbeans/config/ConfigMBean.java
karaf/trunk/management/mbeans/config/src/main/java/org/apache/karaf/management/mbeans/config/internal/ConfigMBeanImpl.java
Modified: karaf/trunk/management/mbeans/config/src/main/java/org/apache/karaf/management/mbeans/config/ConfigMBean.java
URL: http://svn.apache.org/viewvc/karaf/trunk/management/mbeans/config/src/main/java/org/apache/karaf/management/mbeans/config/ConfigMBean.java?rev=1173595&r1=1173594&r2=1173595&view=diff
==============================================================================
--- karaf/trunk/management/mbeans/config/src/main/java/org/apache/karaf/management/mbeans/config/ConfigMBean.java (original)
+++ karaf/trunk/management/mbeans/config/src/main/java/org/apache/karaf/management/mbeans/config/ConfigMBean.java Wed Sep 21 12:33:05 2011
@@ -14,17 +14,66 @@
package org.apache.karaf.management.mbeans.config;
+import java.util.List;
+import java.util.Map;
+
/**
* MBean to manipulate the Config layer.
*/
public interface ConfigMBean {
/**
- * Return the list of all configuration PIDs.
+ * Get the list of all configuration PIDs.
*
* @return the list of all configuration PIDs.
* @throws Exception
*/
- String[] list() throws Exception;
+ List<String> list() throws Exception;
+
+ /**
+ * Delete a configuration identified by the given PID.
+ *
+ * @param pid the configuration PID to delete.
+ * @throws Exception
+ */
+ void delete(String pid) throws Exception;
+
+ /**
+ * Get the list of properties for a configuration PID.
+ *
+ * @param pid the configuration PID.
+ * @return the list of properties.
+ * @throws Exception
+ */
+ Map<String, String> proplist(String pid) throws Exception;
+
+ /**
+ * Remove the configuration property identified by the given key.
+ *
+ * @param pid the configuration PID.
+ * @param key the property key.
+ * @throws Exception
+ */
+ void propdel(String pid, String key) throws Exception;
+
+ /**
+ * Append (or add) a value for the given configuration key.
+ *
+ * @param pid the configuration PID.
+ * @param key the property key.
+ * @param value the value to append to the current property value.
+ * @throws Exception
+ */
+ void propappend(String pid, String key, String value) throws Exception;
+
+ /**
+ * Set a configuration property.
+ *
+ * @param pid the configuration PID.
+ * @param key the property key.
+ * @param value the property value.
+ * @throws Exception
+ */
+ void propset(String pid, String key, String value) throws Exception;
}
Modified: karaf/trunk/management/mbeans/config/src/main/java/org/apache/karaf/management/mbeans/config/internal/ConfigMBeanImpl.java
URL: http://svn.apache.org/viewvc/karaf/trunk/management/mbeans/config/src/main/java/org/apache/karaf/management/mbeans/config/internal/ConfigMBeanImpl.java?rev=1173595&r1=1173594&r2=1173595&view=diff
==============================================================================
--- karaf/trunk/management/mbeans/config/src/main/java/org/apache/karaf/management/mbeans/config/internal/ConfigMBeanImpl.java (original)
+++ karaf/trunk/management/mbeans/config/src/main/java/org/apache/karaf/management/mbeans/config/internal/ConfigMBeanImpl.java Wed Sep 21 12:33:05 2011
@@ -19,8 +19,7 @@ import org.osgi.service.cm.Configuration
import javax.management.NotCompliantMBeanException;
import javax.management.StandardMBean;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.*;
/**
* Implementation of the ConfigMBean.
@@ -41,13 +40,70 @@ public class ConfigMBeanImpl extends Sta
super(ConfigMBean.class);
}
- public String[] list() throws Exception {
+ public List<String> list() throws Exception {
Configuration[] configurations = configurationAdmin.listConfigurations(null);
List<String> pids = new ArrayList<String>();
for (int i = 0; i < configurations.length; i++) {
pids.add(configurations[i].getPid());
}
- return pids.toArray(new String[pids.size()]);
+ return pids;
+ }
+
+ public void delete(String pid) throws Exception {
+ Configuration configuration = configurationAdmin.getConfiguration(pid);
+ if (configuration == null) {
+ throw new IllegalArgumentException("Configuration PID " + pid + " doesn't exist");
+ }
+ configuration.delete();
+ }
+
+ public Map<String, String> proplist(String pid) throws Exception {
+ Configuration configuration = configurationAdmin.getConfiguration(pid);
+ if (configuration == null) {
+ throw new IllegalArgumentException("Configuration PID " + pid + " doesn't exist");
+ }
+ Dictionary dictionary = configuration.getProperties();
+ 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;
+ }
+
+ public void propdel(String pid, String key) throws Exception {
+ Configuration configuration = configurationAdmin.getConfiguration(pid);
+ if (configuration == null) {
+ throw new IllegalArgumentException("Configuration PID " + pid + " doesn't exist");
+ }
+ Dictionary dictionary = configuration.getProperties();
+ dictionary.remove(key);
+ }
+
+ public void propappend(String pid, String key, String value) throws Exception {
+ Configuration configuration = configurationAdmin.getConfiguration(pid);
+ if (configuration == null) {
+ throw new IllegalArgumentException("Configuration PID " + pid + " doesn't exist");
+ }
+ Dictionary dictionary = configuration.getProperties();
+ 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 propset(String pid, String key, String value) throws Exception {
+ Configuration configuration = configurationAdmin.getConfiguration(pid);
+ if (configuration == null) {
+ throw new IllegalArgumentException("Configuration PID " + pid + " doesn't exist");
+ }
+ Dictionary dictionary = configuration.getProperties();
+ dictionary.put(key, value);
}
}