geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r705507 - in /geronimo/gshell/trunk: gshell-api/src/main/java/org/apache/geronimo/gshell/command/ gshell-api/src/main/java/org/apache/geronimo/gshell/registry/ gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom...
Date Fri, 17 Oct 2008 08:22:12 GMT
Author: gnodet
Date: Fri Oct 17 01:22:12 2008
New Revision: 705507

URL: http://svn.apache.org/viewvc?rev=705507&view=rev
Log:
Remove the setLocation method from the Command interface.  It is now set by the plugin parser

Added:
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/CommandLocationImpl.java
Modified:
    geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Command.java
    geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandLocation.java
    geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/registry/CommandRegistry.java
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/AliasCommand.java
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/GroupCommand.java
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/config/PluginParser.java
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/bundle/CommandBundle.java
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/CommandRegistryImpl.java

Modified: geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Command.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Command.java?rev=705507&r1=705506&r2=705507&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Command.java
(original)
+++ geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/Command.java
Fri Oct 17 01:22:12 2008
@@ -29,10 +29,13 @@
  */
 public interface Command
 {
+    /**
+     * Returns the location of the command
+     *
+     * @return The command location; never null
+     */
     CommandLocation getLocation();
 
-    void setLocation(CommandLocation location);
-
     /**
      * Returns the action of the command.
      *

Modified: geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandLocation.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandLocation.java?rev=705507&r1=705506&r2=705507&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandLocation.java
(original)
+++ geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandLocation.java
Fri Oct 17 01:22:12 2008
@@ -32,4 +32,6 @@
     String getName();
 
     String getPath();
+
+    String getFullPath();
 }
\ No newline at end of file

Modified: geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/registry/CommandRegistry.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/registry/CommandRegistry.java?rev=705507&r1=705506&r2=705507&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/registry/CommandRegistry.java
(original)
+++ geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/registry/CommandRegistry.java
Fri Oct 17 01:22:12 2008
@@ -30,9 +30,9 @@
  */
 public interface CommandRegistry
 {
-    void registerCommand(String name, Command command) throws DuplicateCommandException;
+    void registerCommand(Command command) throws DuplicateCommandException;
 
-    void removeCommand(String name) throws NoSuchCommandException;
+    void removeCommand(Command command) throws NoSuchCommandException;
 
     Command getCommand(String name) throws NoSuchCommandException;
 

Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/AliasCommand.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/AliasCommand.java?rev=705507&r1=705506&r2=705507&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/AliasCommand.java
(original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/AliasCommand.java
Fri Oct 17 01:22:12 2008
@@ -29,6 +29,7 @@
 import org.apache.geronimo.gshell.i18n.ResourceBundleMessageSource;
 import org.apache.geronimo.gshell.io.IO;
 import org.apache.geronimo.gshell.shell.ShellContext;
+import org.apache.geronimo.gshell.wisdom.registry.CommandLocationImpl;
 import org.springframework.beans.factory.annotation.Autowired;
 
 import java.util.Iterator;
@@ -53,22 +54,13 @@
         // name could be null
         // alias could be null
 
-        this.name = name;
         this.alias = alias;
 
+        setName(name);
         setAction(new AliasCommandAction());
         setDocumenter(new AliasCommandDocumenter());
         setCompleter(new NullCommandCompleter());
         setMessages(new AliasCommandMessageSource());
-        setLocation(new CommandLocation() {
-            public String getName() {
-                return name;
-            }
-
-            public String getPath() {
-                return null;
-            }
-        });
     }
 
     public AliasCommand() {
@@ -84,6 +76,9 @@
 
     public void setName(final String name) {
         this.name = name;
+        if (name != null) {
+            setLocation(new CommandLocationImpl(name));
+        }
     }
 
     public String getAlias() {

Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/GroupCommand.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/GroupCommand.java?rev=705507&r1=705506&r2=705507&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/GroupCommand.java
(original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/GroupCommand.java
Fri Oct 17 01:22:12 2008
@@ -26,6 +26,7 @@
 import org.apache.geronimo.gshell.i18n.MessageSource;
 import org.apache.geronimo.gshell.i18n.ResourceBundleMessageSource;
 import org.apache.geronimo.gshell.registry.CommandResolver;
+import org.apache.geronimo.gshell.wisdom.registry.CommandLocationImpl;
 
 /**
  * Group {@link org.apache.geronimo.gshell.command.Command} component.
@@ -39,23 +40,11 @@
 
     public GroupCommand(final FileObject file) {
         // file could be null
-        
-        this.file = file;
-
+        setFile(file);
         setAction(new GroupCommandAction());
         setDocumenter(new GroupCommandDocumenter());
         setCompleter(new NullCommandCompleter());
         setMessages(new GroupCommandMessageSource());
-        setLocation(new CommandLocation() {
-            public String getName() {
-                return getFile().getName().getBaseName();
-            }
-
-            public String getPath() {
-                // FIXME: This isn't going to be correct, need to strip off the /commands
stuff.
-                return getFile().getName().getPath();
-            }
-        });
     }
 
     public GroupCommand() {
@@ -71,6 +60,14 @@
 
     public void setFile(final FileObject file) {
         this.file = file;
+        if (file != null) {
+            // FIXME: This isn't going to be correct, need to strip off the /commands stuff.
+            String location = file.getName().getPath();
+            if (location.startsWith("/commands")) {
+                location = location.substring("/commands".length());
+            }
+            setLocation(new CommandLocationImpl(location));
+        }
     }
 
     /**

Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/config/PluginParser.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/config/PluginParser.java?rev=705507&r1=705506&r2=705507&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/config/PluginParser.java
(original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/config/PluginParser.java
Fri Oct 17 01:22:12 2008
@@ -22,6 +22,8 @@
 import org.apache.geronimo.gshell.wisdom.command.ConfigurableCommandCompleter;
 import org.apache.geronimo.gshell.wisdom.command.LinkCommand;
 import org.apache.geronimo.gshell.wisdom.plugin.bundle.CommandBundle;
+import org.apache.geronimo.gshell.wisdom.registry.CommandLocationImpl;
+import org.apache.geronimo.gshell.command.CommandLocation;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.BeanDefinitionStoreException;
@@ -32,6 +34,7 @@
 import org.springframework.beans.factory.support.BeanDefinitionBuilder;
 import org.springframework.beans.factory.support.ManagedList;
 import org.springframework.beans.factory.support.ManagedMap;
+import org.springframework.beans.factory.support.GenericBeanDefinition;
 import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
 import org.springframework.beans.factory.xml.BeanDefinitionParserDelegate;
 import org.springframework.beans.factory.xml.ParserContext;
@@ -42,6 +45,7 @@
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.ArrayList;
 
 /**
  * Parser for the <gshell:plugin/> element.
@@ -65,6 +69,8 @@
 
     private static final String NAME = "name";
 
+    private static final String LOCATION = "location";
+
     private static final String COMMANDS = "commands";
 
     private static final String COMMAND = "command";
@@ -342,11 +348,11 @@
             // TODO: Figure out how we can save the order of <gshell:command> and <gshell:link>
so that 'help' displays them in the order they are defined
             //
 
-            ManagedMap commands = new ManagedMap();
+            ManagedList commands = new ManagedList();
             // noinspection unchecked
-            commands.putAll(parseCommands(element));
+            commands.addAll(parseCommands(element));
             // noinspection unchecked
-            commands.putAll(parseLinks(element));
+            commands.addAll(parseLinks(element));
             bundle.addPropertyValue(COMMANDS, commands);
 
             ManagedMap aliases = new ManagedMap();
@@ -361,19 +367,18 @@
         // <gshell:command>
         //
 
-        private Map<String,BeanDefinition> parseCommands(final Element element) {
+        private List<BeanDefinition> parseCommands(final Element element) {
             assert element != null;
 
             log.trace("Parse commands; element; {}", element);
 
-            Map<String,BeanDefinition> commands = new LinkedHashMap<String,BeanDefinition>();
+            List<BeanDefinition> commands = new ArrayList<BeanDefinition>();
 
             List<Element> children = getChildElements(element, COMMAND);
 
             for (Element child : children) {
-                String name = child.getAttribute(NAME);
                 BeanDefinitionBuilder command = parseCommand(child);
-                commands.put(name, command.getBeanDefinition());
+                commands.add(command.getBeanDefinition());
             }
 
             return commands;
@@ -392,6 +397,12 @@
 
             // Required children elements
 
+            String name = element.getAttribute(NAME);
+            BeanDefinition def = new GenericBeanDefinition();
+            def.setBeanClassName(CommandLocationImpl.class.getName());
+            def.getConstructorArgumentValues().addGenericArgumentValue(name);
+            command.addPropertyValue(LOCATION, def);
+
             child = getChildElement(element, ACTION);
             BeanDefinitionHolder action = parseCommandAction(child);
             type.wire(command, action);
@@ -485,12 +496,12 @@
         // <gshell:link>
         //
 
-        private Map<String,BeanDefinition> parseLinks(final Element element) {
+        private List<BeanDefinition> parseLinks(final Element element) {
             assert element != null;
 
             log.trace("Parse links; element; {}", element);
 
-            Map<String,BeanDefinition> links = new LinkedHashMap<String,BeanDefinition>();
+            List<BeanDefinition> links = new ArrayList<BeanDefinition>();
 
             List<Element> children = getChildElements(element, LINK);
 
@@ -499,7 +510,12 @@
                 link.addConstructorArgValue(child.getAttribute(TARGET));
 
                 String name = child.getAttribute(NAME);
-                links.put(name, link.getBeanDefinition());
+                BeanDefinition def = new GenericBeanDefinition();
+                def.setBeanClassName(CommandLocationImpl.class.getName());
+                def.getConstructorArgumentValues().addGenericArgumentValue(name);
+                link.addPropertyValue(LOCATION, def);
+
+                links.add(link.getBeanDefinition());
             }
 
             return links;

Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/bundle/CommandBundle.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/bundle/CommandBundle.java?rev=705507&r1=705506&r2=705507&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/bundle/CommandBundle.java
(original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/plugin/bundle/CommandBundle.java
Fri Oct 17 01:22:12 2008
@@ -25,6 +25,7 @@
 import org.springframework.beans.factory.annotation.Autowired;
 
 import java.util.Map;
+import java.util.List;
 
 /**
  * A bundle of {@link Command} instances.
@@ -40,7 +41,7 @@
     @Autowired
     private AliasRegistry aliasRegistry;
 
-    private Map<String,Command> commands;
+    private List<Command> commands;
 
     private Map<String,String> aliases;
 
@@ -48,11 +49,11 @@
         super(name);
     }
 
-    public Map<String, Command> getCommands() {
+    public List<Command> getCommands() {
         return commands;
     }
 
-    public void setCommands(final Map<String, Command> commands) {
+    public void setCommands(final List<Command> commands) {
         assert commands != null;
         
         this.commands = commands;
@@ -70,8 +71,8 @@
 
     protected void doEnable() throws Exception {
         assert commandRegistry != null;
-        for (String name : commands.keySet()) {
-            commandRegistry.registerCommand(name, commands.get(name));
+        for (Command command : commands) {
+            commandRegistry.registerCommand(command);
         }
 
         assert aliasRegistry != null;
@@ -82,8 +83,8 @@
 
     protected void doDisable() throws Exception {
         assert commandRegistry != null;
-        for (String name : commands.keySet()) {
-            commandRegistry.removeCommand(name);
+        for (Command command : commands) {
+            commandRegistry.removeCommand(command);
         }
 
         assert aliasRegistry != null;

Added: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/CommandLocationImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/CommandLocationImpl.java?rev=705507&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/CommandLocationImpl.java
(added)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/CommandLocationImpl.java
Fri Oct 17 01:22:12 2008
@@ -0,0 +1,62 @@
+/*
+ * 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.geronimo.gshell.wisdom.registry;
+
+import org.apache.geronimo.gshell.command.CommandLocation;
+
+public class CommandLocationImpl
+    implements CommandLocation
+{
+    private final String name;
+
+    private final String path;
+
+    public CommandLocationImpl(final String name) {
+        assert name != null;
+
+        int i = name.lastIndexOf("/");
+        if (i != -1) {
+            this.name = name.substring(i + 1, name.length());
+            this.path = name.substring(0, i);
+        }
+        else {
+            this.name = name;
+            this.path = null;
+        }
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public String getPath() {
+        return path;
+    }
+
+    public String getFullPath() {
+        if (path != null) {
+            return path + "/" + name;
+        }
+        return name;
+    }
+
+    public String toString() {
+        return getFullPath();
+    }
+}

Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/CommandRegistryImpl.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/CommandRegistryImpl.java?rev=705507&r1=705506&r2=705507&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/CommandRegistryImpl.java
(original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/registry/CommandRegistryImpl.java
Fri Oct 17 01:22:12 2008
@@ -50,25 +50,28 @@
 
     private final Map<String,Command> commands = new LinkedHashMap<String,Command>();
 
-    public void registerCommand(final String name, final Command command) throws DuplicateCommandException
{
-        assert name != null;
+    public void registerCommand(final Command command) throws DuplicateCommandException {
         assert command != null;
 
+        // TODO: add a method on the CommandLocation to avoid using toString()
+        String name = command.getLocation().getFullPath();
+
         log.debug("Registering command: {} -> {}", name, command);
 
         if (containsCommand(name)) {
             throw new DuplicateCommandException(name);
         }
 
-        command.setLocation(new CommandLocationImpl(name));
-
         commands.put(name, command);
 
         eventPublisher.publish(new CommandRegisteredEvent(name, command));
     }
 
-    public void removeCommand(final String name) throws NoSuchCommandException {
-        assert name != null;
+    public void removeCommand(final Command command) throws NoSuchCommandException {
+        assert command != null;
+
+        // TODO: add a method on the CommandLocation to avoid using toString()
+        String name = command.getLocation().getFullPath();
 
         log.debug("Removing command: {}", name);
 
@@ -105,40 +108,4 @@
     // CommandLocationImpl
     //
 
-    private class CommandLocationImpl
-        implements CommandLocation
-    {
-        private final String name;
-
-        private final String path;
-
-        public CommandLocationImpl(final String name) {
-            assert name != null;
-
-            int i = name.lastIndexOf("/");
-            if (i != -1) {
-                this.name = name.substring(i + 1, name.length());
-                this.path = name.substring(0, i);
-            }
-            else {
-                this.name = name;
-                this.path = null;
-            }
-        }
-
-        public String getName() {
-            return name;
-        }
-
-        public String getPath() {
-            return path;
-        }
-
-        public String toString() {
-            if (path != null) {
-                return path + "/" + name;
-            }
-            return name;
-        }
-    }
 }
\ No newline at end of file



Mime
View raw message