You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jd...@apache.org on 2008/09/27 23:21:11 UTC

svn commit: r699741 - in /geronimo/gshell/trunk: gshell-commands/gshell-builtins/src/main/resources/META-INF/spring/components.xml gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completer/VariableNameCompleter.java

Author: jdillon
Date: Sat Sep 27 14:21:10 2008
New Revision: 699741

URL: http://svn.apache.org/viewvc?rev=699741&view=rev
Log:
Add application variable completion for the 'unset' command

Added:
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completer/VariableNameCompleter.java   (contents, props changed)
      - copied, changed from r699733, geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completer/AliasNameCompleter.java
Modified:
    geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/META-INF/spring/components.xml

Modified: geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/META-INF/spring/components.xml
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/META-INF/spring/components.xml?rev=699741&r1=699740&r2=699741&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/META-INF/spring/components.xml (original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/META-INF/spring/components.xml Sat Sep 27 14:21:10 2008
@@ -88,6 +88,14 @@
 
             <gshell:command name="unset">
                 <gshell:action class="org.apache.geronimo.gshell.commands.builtins.UnsetAction"/>
+                <gshell:completer class="org.apache.geronimo.gshell.wisdom.command.ConfigurableCommandCompleter">
+                    <property name="completers">
+                        <list>
+                            <bean class="org.apache.geronimo.gshell.wisdom.shell.completer.VariableNameCompleter"/>
+                            <null/>
+                        </list>
+                    </property>
+                </gshell:completer>
             </gshell:command>
 
             <gshell:command name="alias">

Copied: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completer/VariableNameCompleter.java (from r699733, geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completer/AliasNameCompleter.java)
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completer/VariableNameCompleter.java?p2=geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completer/VariableNameCompleter.java&p1=geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completer/AliasNameCompleter.java&r1=699733&r2=699741&rev=699741&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completer/AliasNameCompleter.java (original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completer/VariableNameCompleter.java Sat Sep 27 14:21:10 2008
@@ -19,65 +19,41 @@
 
 package org.apache.geronimo.gshell.wisdom.shell.completer;
 
+import jline.Completor;
+import org.apache.geronimo.gshell.application.Application;
+import org.apache.geronimo.gshell.application.ApplicationManager;
+import org.apache.geronimo.gshell.command.Variables;
 import org.apache.geronimo.gshell.console.completer.StringsCompleter;
-import org.apache.geronimo.gshell.event.Event;
-import org.apache.geronimo.gshell.event.EventListener;
-import org.apache.geronimo.gshell.event.EventManager;
-import org.apache.geronimo.gshell.registry.AliasRegistry;
-import org.apache.geronimo.gshell.wisdom.registry.AliasRegisteredEvent;
-import org.apache.geronimo.gshell.wisdom.registry.AliasRemovedEvent;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 
-import javax.annotation.PostConstruct;
 import java.util.Collection;
+import java.util.Iterator;
 import java.util.List;
 
-import jline.Completor;
-
 /**
- * {@link Completor} for alias names.
+ * {@link jline.Completor} for {@link Application} variable names.
  *
  * @version $Rev$ $Date$
  */
-public class AliasNameCompleter
+public class VariableNameCompleter
     implements Completor
 {
-    private final Logger log = LoggerFactory.getLogger(getClass());
-
     @Autowired
-    private EventManager eventManager;
+    private ApplicationManager applicationManager;
 
-    @Autowired
-    private AliasRegistry aliasRegistry;
-
-    private final StringsCompleter delegate = new StringsCompleter();
+    public int complete(final String buffer, final int cursor, final List candidates) {
+        assert applicationManager != null;
+        Variables vars = applicationManager.getApplication().getVariables();
 
-    @PostConstruct
-    public void init() {
-        log.debug("Initializing");
-
-        // Populate the initial list of alias names
-        Collection<String> names = aliasRegistry.getAliasNames();
-        delegate.getStrings().addAll(names);
-
-        // Register for updates to alias registrations
-        eventManager.addListener(new EventListener() {
-            public void onEvent(final Event event) throws Exception {
-                if (event instanceof AliasRegisteredEvent) {
-                    AliasRegisteredEvent targetEvent = (AliasRegisteredEvent)event;
-                    delegate.getStrings().add(targetEvent.getName());
-                }
-                else if (event instanceof AliasRemovedEvent) {
-                    AliasRemovedEvent targetEvent = (AliasRemovedEvent)event;
-                    delegate.getStrings().remove(targetEvent.getName());
-                }
-            }
-        });
-    }
+        // There are no events for variables muck, so each time we have to rebuild the list.
+        StringsCompleter delegate = new StringsCompleter();
+        Collection<String> strings = delegate.getStrings();
+
+        Iterator<String> iter = vars.names();
+        while (iter.hasNext()) {
+            strings.add(iter.next());
+        }
 
-    public int complete(final String buffer, final int cursor, final List candidates) {
         return delegate.complete(buffer, cursor, candidates);
     }
 }
\ No newline at end of file

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completer/VariableNameCompleter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completer/VariableNameCompleter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completer/VariableNameCompleter.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Propchange: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/shell/completer/VariableNameCompleter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain