geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r410895 - in /geronimo/sandbox/gshell/trunk: ./ gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/ gshell-core/ gshell-core/src/main/java/org/apache/geronimo/gshell/ gshell-core/src/main/java/org/a...
Date Thu, 01 Jun 2006 17:34:49 GMT
Author: jdillon
Date: Thu Jun  1 10:34:48 2006
New Revision: 410895

URL: http://svn.apache.org/viewvc?rev=410895&view=rev
Log:
Finally have an IoC container again, this time using PicoContainer, seems to be the smallest
that gets the job done (that I know of at least)

Added:
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ShellContainer.java
  (with props)
Modified:
    geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/HelpCommand.java
    geronimo/sandbox/gshell/trunk/gshell-core/pom.xml
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/GShell.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandExecutor.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandManager.java
    geronimo/sandbox/gshell/trunk/pom.xml

Modified: geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/HelpCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/HelpCommand.java?rev=410895&r1=410894&r2=410895&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/HelpCommand.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/HelpCommand.java
Thu Jun  1 10:34:48 2006
@@ -36,8 +36,30 @@
 public class HelpCommand
     extends CommandSupport
 {
-    public HelpCommand() {
+    private CommandManager commandManager;
+
+    public HelpCommand(final CommandManager commandManager) {
         super("help");
+
+        assert commandManager != null;
+
+        this.commandManager = commandManager;
+    }
+
+    /*
+
+    TODO: Setter injection needs help...
+    
+    public void setCommandManager(final CommandManager commandManager) {
+        this.commandManager = commandManager;
+    }
+    */
+
+    private CommandManager getCommandManager() {
+        if (commandManager == null) {
+            throw new IllegalStateException("Not initialized; missing command manger");
+        }
+        return commandManager;
     }
 
     protected int doExecute(final String[] args) throws Exception {
@@ -96,6 +118,8 @@
             return Command.SUCCESS;
         }
 
+        CommandManager manager = getCommandManager();
+
         //
         // TODO: Reuse our command bits...
         //
@@ -107,12 +131,6 @@
             io.out.println();
         }
         else if (topic.equals("commands")) {
-            //
-            // HACK: Need to DI this guy, but for now this will work
-            //
-
-            CommandManager manager = new CommandManager();
-
             io.out.println("Available commands:");
 
             //

Modified: geronimo/sandbox/gshell/trunk/gshell-core/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/pom.xml?rev=410895&r1=410894&r2=410895&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/pom.xml (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/pom.xml Thu Jun  1 10:34:48 2006
@@ -25,7 +25,7 @@
             <groupId>commons-cli</groupId>
             <artifactId>commons-cli</artifactId>
         </dependency>
-        
+
         <dependency>
             <groupId>jline</groupId>
             <artifactId>jline</artifactId>
@@ -34,6 +34,11 @@
         <dependency>
             <groupId>org.apache.xbean</groupId>
             <artifactId>xbean-finder</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>picocontainer</groupId>
+            <artifactId>picocontainer</artifactId>
         </dependency>
     </dependencies>
 

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/GShell.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/GShell.java?rev=410895&r1=410894&r2=410895&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/GShell.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/GShell.java
Thu Jun  1 10:34:48 2006
@@ -27,6 +27,7 @@
 import org.apache.geronimo.gshell.command.Variables;
 import org.apache.geronimo.gshell.command.VariablesMap;
 import org.apache.geronimo.gshell.command.CommandException;
+import org.apache.geronimo.gshell.command.CommandDefinition;
 import org.apache.geronimo.gshell.commandline.CommandLineBuilder;
 import org.apache.geronimo.gshell.commandline.CommandLine;
 import org.apache.geronimo.gshell.util.Arguments;
@@ -43,6 +44,8 @@
 
     private final IO io;
 
+    private final ShellContainer shellContainer = new ShellContainer();
+
     private final CommandManager commandManager;
 
     private final CommandLineBuilder commandLineBuilder;
@@ -56,14 +59,18 @@
 
         this.io = io;
 
+        shellContainer.registerComponentInstance(this);
+        shellContainer.registerComponentImplementation(CommandManager.class);
+        shellContainer.registerComponentImplementation(CommandLineBuilder.class);
+
         //
-        // HACK: DI components...  Maybe need to setup the top-level container here
+        // TODO: Refactor to use the container, now that we have one
         //
 
-        this.commandManager = new CommandManager();
-        this.commandLineBuilder = new CommandLineBuilder(this);
+        this.commandManager = (CommandManager) shellContainer.getComponentInstanceOfType(CommandManager.class);
+        this.commandLineBuilder = (CommandLineBuilder) shellContainer.getComponentInstanceOfType(CommandLineBuilder.class);
     }
-    
+
     public GShell() throws CommandException {
         this(new IO());
     }
@@ -103,11 +110,16 @@
 
         log.info("Executing (" + commandName + "): " + Arguments.asString(args));
 
-        //
-        // TODO: Insert CommandContainer bits here
-        //
+        // Setup the command container
+        ShellContainer container = new ShellContainer(shellContainer);
+
+        CommandDefinition def = commandManager.getCommandDefinition(commandName);
+        container.registerComponentInstance(def);
+        container.registerComponentImplementation(def.loadClass());
 
-        Command cmd = commandManager.getCommand(commandName);
+        // container.start() ?
+
+        Command cmd = (Command) container.getComponentInstanceOfType(Command.class);
 
         //
         // TODO: DI all bits if we can, then free up "context" to replace "category" as a
term
@@ -145,6 +157,9 @@
         }
         finally {
             cmd.destroy();
+
+            shellContainer.removeChildContainer(container);
+            // container.stop() container.dispose() ?
         }
 
         return status;

Added: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ShellContainer.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ShellContainer.java?rev=410895&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ShellContainer.java
(added)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ShellContainer.java
Thu Jun  1 10:34:48 2006
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed 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;
+
+import org.picocontainer.defaults.DefaultPicoContainer;
+import org.picocontainer.PicoContainer;
+
+/**
+ * ???
+ *
+ * @version $Id$
+ */
+public class ShellContainer
+    extends DefaultPicoContainer
+{
+    public ShellContainer() {
+        super();
+    }
+
+    public ShellContainer(final PicoContainer parent) {
+        super(parent);
+    }
+
+    //
+    // TODO: Add access helpers
+    //
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ShellContainer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ShellContainer.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ShellContainer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandExecutor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandExecutor.java?rev=410895&r1=410894&r2=410895&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandExecutor.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandExecutor.java
Thu Jun  1 10:34:48 2006
@@ -17,7 +17,10 @@
 package org.apache.geronimo.gshell.command;
 
 /**
- * ???
+ * Defines the basic interface for executing commands.
+ *
+ * <p>
+ * <b>NOTE</b>: This interface is meant to handle post parsing arguments.
  *
  * @version $Id$
  */

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandManager.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandManager.java?rev=410895&r1=410894&r2=410895&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandManager.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/command/CommandManager.java
Thu Jun  1 10:34:48 2006
@@ -34,6 +34,10 @@
  */
 public class CommandManager
 {
+    //
+    // TODO: Rename, this has become a registry
+    //
+    
     private static final Log log = LogFactory.getLog(CommandManager.class);
 
     private Map<String,CommandDefinition> commandDefMap = new HashMap<String,CommandDefinition>();
@@ -97,27 +101,6 @@
         return def;
     }
 
-    public Command getCommand(final String name) throws CommandNotFoundException, CommandInstantiationException
{
-        // name checked by getCommandDefinition()
-
-        CommandDefinition def = getCommandDefinition(name);
-
-        //
-        // TODO: This might change if we DI the class and let the container create
-        //
-
-        Command cmd;
-        try {
-            Class type = def.loadClass();
-            cmd = (Command)type.newInstance();
-        }
-        catch (Exception e) {
-            throw new CommandInstantiationException(name, e);
-        }
-
-        return cmd;
-    }
-    
     public Set<String> commandNames() {
         return Collections.unmodifiableSet(commandDefMap.keySet());
     }

Modified: geronimo/sandbox/gshell/trunk/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/pom.xml?rev=410895&r1=410894&r2=410895&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/pom.xml (original)
+++ geronimo/sandbox/gshell/trunk/pom.xml Thu Jun  1 10:34:48 2006
@@ -155,6 +155,14 @@
                 <type>jar</type>
                 <scope>compile</scope>
             </dependency>
+
+            <dependency>
+                <groupId>picocontainer</groupId>
+                <artifactId>picocontainer</artifactId>
+                <version>1.2</version>
+                <type>jar</type>
+                <scope>compile</scope>
+            </dependency>
         </dependencies>
     </dependencyManagement>
     



Mime
View raw message