You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by cc...@apache.org on 2009/03/16 06:01:42 UTC

svn commit: r754816 - in /servicemix/smx4/kernel/trunk/gshell/gshell-config/src/main: java/org/apache/servicemix/kernel/gshell/config/completers/ConfigurationPropertyCompleter.java resources/META-INF/spring/gshell-config.xml

Author: ccustine
Date: Mon Mar 16 05:01:35 2009
New Revision: 754816

URL: http://svn.apache.org/viewvc?rev=754816&view=rev
Log:
SMX4KNL-233 - Add argument completion for core gshell commands
- Added config properties

Added:
    servicemix/smx4/kernel/trunk/gshell/gshell-config/src/main/java/org/apache/servicemix/kernel/gshell/config/completers/ConfigurationPropertyCompleter.java
      - copied, changed from r752291, servicemix/smx4/kernel/trunk/gshell/gshell-config/src/main/java/org/apache/servicemix/kernel/gshell/config/completers/ConfigurationCompleter.java
Modified:
    servicemix/smx4/kernel/trunk/gshell/gshell-config/src/main/resources/META-INF/spring/gshell-config.xml

Copied: servicemix/smx4/kernel/trunk/gshell/gshell-config/src/main/java/org/apache/servicemix/kernel/gshell/config/completers/ConfigurationPropertyCompleter.java (from r752291, servicemix/smx4/kernel/trunk/gshell/gshell-config/src/main/java/org/apache/servicemix/kernel/gshell/config/completers/ConfigurationCompleter.java)
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-config/src/main/java/org/apache/servicemix/kernel/gshell/config/completers/ConfigurationPropertyCompleter.java?p2=servicemix/smx4/kernel/trunk/gshell/gshell-config/src/main/java/org/apache/servicemix/kernel/gshell/config/completers/ConfigurationPropertyCompleter.java&p1=servicemix/smx4/kernel/trunk/gshell/gshell-config/src/main/java/org/apache/servicemix/kernel/gshell/config/completers/ConfigurationCompleter.java&r1=752291&r2=754816&rev=754816&view=diff
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-config/src/main/java/org/apache/servicemix/kernel/gshell/config/completers/ConfigurationCompleter.java (original)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-config/src/main/java/org/apache/servicemix/kernel/gshell/config/completers/ConfigurationPropertyCompleter.java Mon Mar 16 05:01:35 2009
@@ -19,68 +19,38 @@
 
 package org.apache.servicemix.kernel.gshell.config.completers;
 
-import java.util.ArrayList;
-import java.util.Collection;
+import java.util.Dictionary;
+import java.util.Enumeration;
 import java.util.List;
 
-import javax.annotation.PostConstruct;
-
 import jline.Completor;
+import org.apache.geronimo.gshell.command.Variables;
 import org.apache.geronimo.gshell.console.completer.StringsCompleter;
-import org.osgi.service.cm.Configuration;
-import org.osgi.service.cm.ConfigurationAdmin;
-import org.osgi.service.cm.ConfigurationEvent;
-import org.osgi.service.cm.ConfigurationListener;
+import org.apache.geronimo.gshell.shell.ShellContextHolder;
+import org.apache.servicemix.kernel.gshell.config.ConfigCommandSupport;
 
 /**
- * {@link jline.Completor} for Configuration Admin configurations.
+ * {@link jline.Completor} for Configuration Admin properties.
  *
- * Displays a list of existing config admin configurations for completion.
+ * Displays a list of existing properties based on the current configuration being edited.
  *
  */
-public class ConfigurationCompleter implements Completor, ConfigurationListener {
-
-    private final StringsCompleter delegate = new StringsCompleter();
+public class ConfigurationPropertyCompleter implements Completor {
 
-    private ConfigurationAdmin admin;
-
-    public void setAdmin(ConfigurationAdmin admin) {
-        this.admin = admin;
-    }
-
-    @PostConstruct
-    public void init() {
-        Configuration[] configs;
-        try {
-            configs = admin.listConfigurations(null);
-        } catch (Exception e) {
-            return;
+    public int complete(final String buffer, final int cursor, final List candidates) {
+        Variables vars = ShellContextHolder.get().getVariables();
+        if (vars.get(ConfigCommandSupport.PROPERTY_CONFIG_PID) == null) {
+            return -1;
         }
 
-        Collection<String> pids = new ArrayList<String>();
+        Dictionary props = (Dictionary) vars.get(ConfigCommandSupport.PROPERTY_CONFIG_PROPS);
+        StringsCompleter delegate = new StringsCompleter();
 
-        for (Configuration config : configs) {
-            if (config.getFactoryPid() != null) {
-                pids.add(config.getFactoryPid());
-            } else {
-                pids.add(config.getPid());
-            }
+        for (Enumeration e = props.keys(); e.hasMoreElements();) {
+            String key = (String) e.nextElement();
+            delegate.getStrings().add(key);
         }
 
-        delegate.getStrings().addAll(pids);
-
-    }
-
-    public int complete(final String buffer, final int cursor, final List candidates) {
         return delegate.complete(buffer, cursor, candidates);
     }
-
-    public void configurationEvent(ConfigurationEvent configurationEvent) {
-        String pid = configurationEvent.getFactoryPid()!=null ? configurationEvent.getFactoryPid() : configurationEvent.getPid();
-        if (configurationEvent.getType() == ConfigurationEvent.CM_DELETED) {
-            delegate.getStrings().remove(pid);
-        } else if (configurationEvent.getType() == ConfigurationEvent.CM_UPDATED) {
-            delegate.getStrings().add(pid);
-        }
-    }
-}
+}
\ No newline at end of file

Modified: servicemix/smx4/kernel/trunk/gshell/gshell-config/src/main/resources/META-INF/spring/gshell-config.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-config/src/main/resources/META-INF/spring/gshell-config.xml?rev=754816&r1=754815&r2=754816&view=diff
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-config/src/main/resources/META-INF/spring/gshell-config.xml (original)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-config/src/main/resources/META-INF/spring/gshell-config.xml Mon Mar 16 05:01:35 2009
@@ -44,7 +44,8 @@
         <gshell:command name="config/edit">
             <gshell:action class="org.apache.servicemix.kernel.gshell.config.EditCommand"/>
             <gshell:completers>
-                <ref bean="configCompleter" /> 
+                <ref bean="configCompleter" />
+                <null/>
             </gshell:completers>
         </gshell:command>
         <gshell:command name="config/list">
@@ -52,12 +53,20 @@
         </gshell:command>
         <gshell:command name="config/propdel">
             <gshell:action class="org.apache.servicemix.kernel.gshell.config.PropDelCommand" />
+            <gshell:completers>
+                <ref bean="configPropertyCompleter" />
+                <null/>
+            </gshell:completers>
         </gshell:command>
         <gshell:command name="config/proplist">
             <gshell:action class="org.apache.servicemix.kernel.gshell.config.PropListCommand" />
         </gshell:command>
         <gshell:command name="config/propset">
             <gshell:action class="org.apache.servicemix.kernel.gshell.config.PropSetCommand" />
+            <gshell:completers>
+                <ref bean="configPropertyCompleter" />
+                <null/>
+            </gshell:completers>
         </gshell:command>
         <gshell:command name="config/update">
             <gshell:action class="org.apache.servicemix.kernel.gshell.config.UpdateCommand" />
@@ -68,6 +77,8 @@
         <property name="admin" ref="configAdmin"/>
     </bean>
 
+    <bean id="configPropertyCompleter" class="org.apache.servicemix.kernel.gshell.config.completers.ConfigurationPropertyCompleter" />
+
     <osgi:reference id="configAdmin" interface="org.osgi.service.cm.ConfigurationAdmin"  />
 
     <osgi:service ref="configCompleter" interface="org.osgi.service.cm.ConfigurationListener" />