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 2016/06/06 16:12:38 UTC

karaf git commit: [KARAF-4557] Add config:property-get command and getProperty operation on ConfigMBean

Repository: karaf
Updated Branches:
  refs/heads/master d0acf872b -> 7a0d78ec9


[KARAF-4557] Add config:property-get command and getProperty operation on ConfigMBean


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

Branch: refs/heads/master
Commit: 7a0d78ec939f337e8ae4843785469d6224d65e67
Parents: d0acf87
Author: Jean-Baptiste Onofr� <jb...@apache.org>
Authored: Mon Jun 6 18:11:09 2016 +0200
Committer: Jean-Baptiste Onofr� <jb...@apache.org>
Committed: Mon Jun 6 18:11:09 2016 +0200

----------------------------------------------------------------------
 .../karaf/config/command/PropGetCommand.java    | 42 ++++++++++++++++++++
 .../apache/karaf/config/core/ConfigMBean.java   |  9 +++++
 .../karaf/config/core/impl/ConfigMBeanImpl.java | 13 ++++++
 3 files changed, 64 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/7a0d78ec/config/src/main/java/org/apache/karaf/config/command/PropGetCommand.java
----------------------------------------------------------------------
diff --git a/config/src/main/java/org/apache/karaf/config/command/PropGetCommand.java b/config/src/main/java/org/apache/karaf/config/command/PropGetCommand.java
new file mode 100644
index 0000000..c38b530
--- /dev/null
+++ b/config/src/main/java/org/apache/karaf/config/command/PropGetCommand.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.config.command;
+
+
+import org.apache.karaf.config.command.completers.ConfigurationPropertyCompleter;
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.Completion;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+
+import java.util.Dictionary;
+
+@Command(scope = "config", name = "property-get", description = "Gets the value of a property in the currently edited configuration.")
+@Service
+public class PropGetCommand extends ConfigPropertyCommandSupport {
+
+    @Argument(index = 0, name = "property", description = "The name of the property to get value for", required = true, multiValued = false)
+    @Completion(ConfigurationPropertyCompleter.class)
+    String prop;
+
+    @Override
+    public void propertyAction(Dictionary props) {
+        System.out.println(props.get(prop));
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/karaf/blob/7a0d78ec/config/src/main/java/org/apache/karaf/config/core/ConfigMBean.java
----------------------------------------------------------------------
diff --git a/config/src/main/java/org/apache/karaf/config/core/ConfigMBean.java b/config/src/main/java/org/apache/karaf/config/core/ConfigMBean.java
index 9c46677..91454ce 100644
--- a/config/src/main/java/org/apache/karaf/config/core/ConfigMBean.java
+++ b/config/src/main/java/org/apache/karaf/config/core/ConfigMBean.java
@@ -85,6 +85,15 @@ public interface ConfigMBean {
     void setProperty(String pid, String key, String value) throws MBeanException;
 
     /**
+     * Get a configuration property.
+     *
+     * @param pid the configuration PID.
+     * @param key the property key.
+     * @throws MBeanException in case of MBean failure.
+     */
+    String getProperty(String pid, String key) throws MBeanException;
+
+    /**
      * Update a complete configuration.
      *
      * @param pid the configuration PID.

http://git-wip-us.apache.org/repos/asf/karaf/blob/7a0d78ec/config/src/main/java/org/apache/karaf/config/core/impl/ConfigMBeanImpl.java
----------------------------------------------------------------------
diff --git a/config/src/main/java/org/apache/karaf/config/core/impl/ConfigMBeanImpl.java b/config/src/main/java/org/apache/karaf/config/core/impl/ConfigMBeanImpl.java
index c133725..cc30538 100644
--- a/config/src/main/java/org/apache/karaf/config/core/impl/ConfigMBeanImpl.java
+++ b/config/src/main/java/org/apache/karaf/config/core/impl/ConfigMBeanImpl.java
@@ -150,6 +150,19 @@ public class ConfigMBeanImpl extends StandardMBean implements ConfigMBean {
         }
     }
 
+    public String getProperty(String pid, String key) throws MBeanException {
+        try {
+            Dictionary dictionary = getConfigProperties(pid);
+            Object value = dictionary.get(key);
+            if (value != null) {
+                return value.toString();
+            }
+            return null;
+        } catch (Exception e) {
+            throw new MBeanException(null, e.getMessage());
+        }
+    }
+
     public void update(String pid, Map<String, String> properties) throws MBeanException {
         try {
             if (properties == null) {