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 2007/10/01 22:18:32 UTC

svn commit: r581061 - in /geronimo/sandbox/gshell/trunk: gshell-cli/src/main/resources/META-INF/plexus/ gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/descriptor/ gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gs...

Author: jdillon
Date: Mon Oct  1 13:18:31 2007
New Revision: 581061

URL: http://svn.apache.org/viewvc?rev=581061&view=rev
Log:
Split up the registry from the plexus discovery listener
Add a component to handle injection custom URL muck

Added:
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/URLHandlerFactory.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/CommandDiscoveryListener.java   (contents, props changed)
      - copied, changed from r580765, geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/CommandRegistry.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/registry/
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/registry/CommandRegistry.java
      - copied, changed from r580765, geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/CommandRegistry.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/registry/DefaultCommandRegistry.java   (with props)
Removed:
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/CommandRegistry.java
Modified:
    geronimo/sandbox/gshell/trunk/gshell-cli/src/main/resources/META-INF/plexus/plexus.xml
    geronimo/sandbox/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/descriptor/CommandDescriptor.java
    geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java
    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/layout/DefaultLayoutManager.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/CommandDiscoverer.java

Modified: geronimo/sandbox/gshell/trunk/gshell-cli/src/main/resources/META-INF/plexus/plexus.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-cli/src/main/resources/META-INF/plexus/plexus.xml?rev=581061&r1=581060&r2=581061&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-cli/src/main/resources/META-INF/plexus/plexus.xml (original)
+++ geronimo/sandbox/gshell/trunk/gshell-cli/src/main/resources/META-INF/plexus/plexus.xml Mon Oct  1 13:18:31 2007
@@ -24,8 +24,8 @@
     <component-discoverer-manager implementation="org.codehaus.plexus.component.discovery.DefaultComponentDiscovererManager">
         <listeners>
             <listener implementation="org.codehaus.plexus.component.discovery.DiscoveryListenerDescriptor">
-                <role>org.apache.geronimo.gshell.plugin.CommandRegistry</role>
-                <role-hint>default</role-hint>
+                <role>org.codehaus.plexus.component.discovery.ComponentDiscoveryListener</role>
+                <role-hint>command</role-hint>
             </listener>
         </listeners>
 
@@ -45,12 +45,27 @@
         </component>
 
         <!--
-        Configure the collector, needs to be done here since we are using it above as a discovery listener.
+        Configure the registry.
         -->
         <component>
-            <role>org.apache.geronimo.gshell.plugin.CommandRegistry</role>
+            <role>org.apache.geronimo.gshell.registry.CommandRegistry</role>
             <role-hint>default</role-hint>
-            <implementation>org.apache.geronimo.gshell.plugin.CommandRegistry</implementation>
+            <implementation>org.apache.geronimo.gshell.registry.DefaultCommandRegistry</implementation>
+        </component>
+
+        <!--
+        Configure the discovery listener to register commands
+        -->
+        <component>
+            <role>org.codehaus.plexus.component.discovery.ComponentDiscoveryListener</role>
+            <role-hint>command</role-hint>
+            <implementation>org.apache.geronimo.gshell.plugin.CommandDiscoveryListener</implementation>
+            <requirements>
+                <requirement>
+                    <role>org.apache.geronimo.gshell.registry.CommandRegistry</role>
+                    <field-name>registry</field-name>
+                </requirement>
+            </requirements>
         </component>
         
         <!--

Modified: geronimo/sandbox/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/descriptor/CommandDescriptor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/descriptor/CommandDescriptor.java?rev=581061&r1=581060&r2=581061&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/descriptor/CommandDescriptor.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-command-api/src/main/java/org/apache/geronimo/gshell/command/descriptor/CommandDescriptor.java Mon Oct  1 13:18:31 2007
@@ -22,6 +22,10 @@
 import org.codehaus.plexus.component.repository.ComponentDescriptor;
 import org.apache.geronimo.gshell.common.tostring.ReflectionToStringBuilder;
 
+//
+// TODO: Detach from Plexus' ComponentDescriptor
+//
+
 /**
  * Descriptor for a command.
  *

Modified: geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java?rev=581061&r1=581060&r2=581061&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java Mon Oct  1 13:18:31 2007
@@ -23,12 +23,12 @@
 
 import org.apache.geronimo.gshell.ansi.Code;
 import org.apache.geronimo.gshell.ansi.Renderer;
+import org.apache.geronimo.gshell.branding.Branding;
 import org.apache.geronimo.gshell.command.CommandSupport;
 import org.apache.geronimo.gshell.command.annotation.CommandComponent;
 import org.apache.geronimo.gshell.command.descriptor.CommandDescriptor;
-import org.apache.geronimo.gshell.branding.Branding;
 import org.apache.geronimo.gshell.layout.LayoutManager;
-import org.apache.geronimo.gshell.plugin.CommandRegistry;
+import org.apache.geronimo.gshell.registry.CommandRegistry;
 import org.codehaus.plexus.component.annotations.Requirement;
 import org.codehaus.plexus.util.StringUtils;
 
@@ -62,7 +62,7 @@
 
         io.out.println("Available commands:");
 
-        Collection<CommandDescriptor> commands = commandRegistry.getCommandDescriptors();
+        Collection<CommandDescriptor> commands = commandRegistry.descriptors();
 
         // Figure out the maximum length of a command name
         int maxNameLen = 0;

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=581061&r1=581060&r2=581061&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 Mon Oct  1 13:18:31 2007
@@ -81,6 +81,9 @@
             config.setClassWorld(classWorld);
             container = new DefaultPlexusContainer(config);
 
+            // Get our URL handler factory installed
+            container.lookup(URLHandlerFactory.class);
+
             // We first need to stuff in the IO context for the new shell instance
             IOLookup.set(container, io);
 

Added: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/URLHandlerFactory.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/URLHandlerFactory.java?rev=581061&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/URLHandlerFactory.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/URLHandlerFactory.java Mon Oct  1 13:18:31 2007
@@ -0,0 +1,258 @@
+/*
+ * 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;
+
+import java.net.URL;
+import java.net.URLStreamHandler;
+import java.net.URLStreamHandlerFactory;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.annotations.Requirement;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Provides access to URL internals.
+ *
+ * @version $Rev$ $Date$
+ */
+@Component(role=URLHandlerFactory.class, instantiationStrategy="singleton-keep-alive")
+public final class URLHandlerFactory
+    implements Initializable
+{
+    private static URLHandlerFactory SINGLETON;
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private final Factory factory = new Factory();
+
+    @Requirement(role=URLStreamHandler.class)
+    private Map<String,URLStreamHandler> handlers;
+
+    public URLHandlerFactory() {
+        // Just sanity check that only one of these puppies gets constructed... ever
+        synchronized (URLHandlerFactory.class) {
+            if (SINGLETON != null) {
+                throw new IllegalStateException("Singleton instance already constructed");
+            }
+            SINGLETON = this;
+        }
+    }
+
+    public void initialize() throws InitializationException {
+        try {
+            URL.setURLStreamHandlerFactory(factory);
+            
+            log.debug("URL stream handler factory installed");
+        }
+        catch (Throwable t) {
+            throw new InitializationException("Failed to install URL stream handler factory", t);
+        }
+
+        // Log the initial handlers which were injected
+        if (!handlers.isEmpty()) {
+            log.debug("Initial URL stream handlers:");
+            for (Map.Entry entry : handlers.entrySet()) {
+                log.debug("    {} -> {}", entry.getKey(), entry.getValue());
+            }
+        }
+        else {
+            log.warn("No URL stream handlers are currently registered; somethings probably misconfigured");
+        }
+    }
+
+    public void register(final String protocol, final URLStreamHandler handler) {
+        factory.register(protocol, handler);
+    }
+
+    public URLStreamHandler getHandler(final String protocol) {
+        return factory.getHandler(protocol);
+    }
+
+    public Map<String,URLStreamHandler> handlers() {
+        return factory.handlers();
+    }
+
+    /*
+    public static void forceInstall() throws Error, SecurityException {
+        if (!installed) {
+            // This way is "naughty" but works great
+            Throwable t = (Throwable) AccessController.doPrivileged(new PrivilegedAction() {
+                public Object run() {
+                    try {
+                        // get a reference to the URL stream handler lock... we need to
+                        // synchronize on this field to be safe
+                        Field streamHandlerLockField = URL.class.getDeclaredField("streamHandlerLock");
+                        streamHandlerLockField.setAccessible(true);
+                        Object streamHandlerLock = streamHandlerLockField.get(null);
+
+                        synchronized (streamHandlerLock) {
+                            // get a reference to the factory field and change the permissions
+                            // to make it accessable (factory is a package protected field)
+                            Field factoryField = URL.class.getDeclaredField("factory");
+                            factoryField.setAccessible(true);
+
+                            // get a reference to the handlers field and change the permissions
+                            // to make it accessable (handlers is a package protected field)
+                            Field handlersField = URL.class.getDeclaredField("handlers");
+                            handlersField.setAccessible(true);
+
+                            // the the handlers map first
+                            Map handlers = (Map) handlersField.get(null);
+
+                            // set the factory field to our factory
+                            factoryField.set(null, factory);
+
+                            // clear the handlers
+                            handlers.clear();
+                        }
+                    } catch (Throwable e) {
+                        return e;
+                    }
+                    return null;
+                }
+            });
+
+            if (t != null) {
+                if (t instanceof SecurityException) {
+                    throw (SecurityException) t;
+                } else if (t instanceof Error) {
+                    throw (Error) t;
+                }
+                throw new Error("Unknown error while force installing URL factory", t);
+            }
+            installed = true;
+        }
+    }
+    */
+
+    //
+    // Factory
+    //
+
+    private class Factory
+        implements URLStreamHandlerFactory
+    {
+        private final List<String> handlerPackages = new LinkedList<String>();
+
+        private Factory() {
+            // Add the packages listed in the standard system property
+            String systemPackages = System.getProperty("java.protocol.handler.pkgs");
+
+            if (systemPackages != null) {
+                StringTokenizer stok = new StringTokenizer(systemPackages, "|");
+
+                while (stok.hasMoreTokens()) {
+                    handlerPackages.add(stok.nextToken().trim());
+                }
+            }
+
+            // Always add the sun handlers
+            handlerPackages.add("sun.net.www.protocol");
+        }
+
+        public URLStreamHandler createURLStreamHandler(String protocol) {
+            assert protocol != null;
+
+            protocol = protocol.trim();
+
+            log.trace("Create URL stream handler: {}", protocol);
+
+            URLStreamHandler handler;
+
+            // First check the registered handlers
+            synchronized (this) {
+                handler = handlers.get(protocol);
+            }
+
+            if (handler != null) {
+                log.trace("Using registered handler: {}", handler);
+
+                return handler;
+            }
+            
+            // Try to get the stream handler from the registered package list
+            Class<?> type = findProtocolHandler(protocol);
+            
+            if (type == null) {
+                throw new IllegalArgumentException("Unknown protocol: " + protocol);
+            }
+
+            try {
+                return (URLStreamHandler) type.newInstance();
+            }
+            catch (Exception e) {
+                throw new IllegalArgumentException("Failed to construct handler for protocol: " + protocol, e);
+            }
+        }
+
+        private synchronized void register(final String protocol, final URLStreamHandler handler) {
+            assert protocol != null;
+            assert handler != null;
+
+            if (handlers.containsKey(protocol)) {
+                throw new IllegalStateException("Protocol already has a registered handler: " + protocol);
+            }
+
+            handlers.put(protocol, handler);
+
+            log.debug("Registered {} -> {}", protocol, handler);
+        }
+
+        private synchronized URLStreamHandler getHandler(final String protocol) {
+            assert protocol != null;
+
+            return handlers.get(protocol);
+        }
+
+        private synchronized Map<String,URLStreamHandler> handlers() {
+            return Collections.unmodifiableMap(handlers);
+        }
+        
+        private Class<?> findProtocolHandler(final String protocol) {
+            assert protocol != null;
+
+            log.trace("Finding protocol handler: {}", protocol);
+            
+            ClassLoader cl = Thread.currentThread().getContextClassLoader();
+            if (cl == null) {
+                cl = ClassLoader.getSystemClassLoader();
+            }
+
+            for (String pkg : handlerPackages) {
+                String classname = pkg + "." + protocol + ".Handler";
+
+                try {
+                    return cl.loadClass(classname);
+                }
+                catch (Throwable ignore) {}
+            }
+
+            return null;
+        }
+    }
+}

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

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

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

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/DefaultLayoutManager.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/DefaultLayoutManager.java?rev=581061&r1=581060&r2=581061&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/DefaultLayoutManager.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/layout/DefaultLayoutManager.java Mon Oct  1 13:18:31 2007
@@ -22,7 +22,7 @@
 import org.apache.geronimo.gshell.command.descriptor.CommandDescriptor;
 import org.apache.geronimo.gshell.layout.loader.LayoutLoader;
 import org.apache.geronimo.gshell.layout.model.Layout;
-import org.apache.geronimo.gshell.plugin.CommandRegistry;
+import org.apache.geronimo.gshell.registry.CommandRegistry;
 import org.apache.geronimo.gshell.shell.Environment;
 import org.codehaus.plexus.component.annotations.Component;
 import org.codehaus.plexus.component.annotations.Requirement;
@@ -87,6 +87,6 @@
         // HACK: For now, assume the path is just the id... should eventually change this
         //
 
-        return commandRegistry.getCommandDescriptor(path);
+        return commandRegistry.lookup(path);
     }
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/CommandDiscoverer.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/CommandDiscoverer.java?rev=581061&r1=581060&r2=581061&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/CommandDiscoverer.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/CommandDiscoverer.java Mon Oct  1 13:18:31 2007
@@ -34,7 +34,7 @@
  *
  * @version $Rev$ $Date$
  */
-@Component(role=ComponentDiscoverer.class)
+@Component(role=ComponentDiscoverer.class, hint="command")
 public class CommandDiscoverer
     extends AbstractComponentDiscoverer
 {

Copied: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/CommandDiscoveryListener.java (from r580765, geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/CommandRegistry.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/CommandDiscoveryListener.java?p2=geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/CommandDiscoveryListener.java&p1=geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/CommandRegistry.java&r1=580765&r2=581061&rev=581061&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/CommandRegistry.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/CommandDiscoveryListener.java Mon Oct  1 13:18:31 2007
@@ -19,13 +19,11 @@
 
 package org.apache.geronimo.gshell.plugin;
 
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
 import org.apache.geronimo.gshell.command.descriptor.CommandDescriptor;
 import org.apache.geronimo.gshell.command.descriptor.CommandSetDescriptor;
+import org.apache.geronimo.gshell.registry.CommandRegistry;
 import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.annotations.Requirement;
 import org.codehaus.plexus.component.discovery.ComponentDiscoveryEvent;
 import org.codehaus.plexus.component.discovery.ComponentDiscoveryListener;
 import org.codehaus.plexus.component.repository.ComponentSetDescriptor;
@@ -33,53 +31,36 @@
 import org.slf4j.LoggerFactory;
 
 /**
- * Registers command components as they are discovered by the container.
+ * Registers commands with the registry as they are discovered by the container.
  * 
  * @version $Rev$ $Date$
  */
-@Component(role= CommandRegistry.class)
-public class CommandRegistry
+@Component(role=ComponentDiscoveryListener.class, hint="command")
+public class CommandDiscoveryListener
     implements ComponentDiscoveryListener
 {
-    public static final String ID = "gshell-command-regsitry";
-
     private final Logger log = LoggerFactory.getLogger(getClass());
 
-    private Map<String,CommandDescriptor> commandDescriptors = new HashMap<String,CommandDescriptor>();
+    @Requirement
+    private CommandRegistry registry;
 
     public String getId() {
-        return ID;
+        return getClass().getSimpleName();
     }
     
     public void componentDiscovered(final ComponentDiscoveryEvent event) {
         assert event != null;
 
-        ComponentSetDescriptor setDescriptor = event.getComponentSetDescriptor();
+        log.trace("Event: {}", event);
 
-        if (setDescriptor instanceof CommandSetDescriptor) {
-            CommandSetDescriptor commands = (CommandSetDescriptor) setDescriptor;
+        ComponentSetDescriptor set = event.getComponentSetDescriptor();
 
-            for (CommandDescriptor desc : commands.getCommandDescriptors()) {
-                String id = desc.getId();
+        if (set instanceof CommandSetDescriptor) {
+            CommandSetDescriptor commands = (CommandSetDescriptor) set;
 
-                if (commandDescriptors.containsKey(id)) {
-                    log.error("Ignoring duplicate command id: {}", id);
-                }
-                else {
-                    log.debug("Found command: {}", id);
-                    commandDescriptors.put(id, desc);
-                }
+            for (CommandDescriptor descriptor : commands.getCommandDescriptors()) {
+                registry.register(descriptor);
             }
         }
-    }
-
-    public Collection<CommandDescriptor> getCommandDescriptors() {
-        return commandDescriptors.values();
-    }
-
-    public CommandDescriptor getCommandDescriptor(final String id) {
-        assert id != null;
-
-        return commandDescriptors.get(id);
     }
 }

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

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

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

Copied: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/registry/CommandRegistry.java (from r580765, geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/CommandRegistry.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/registry/CommandRegistry.java?p2=geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/registry/CommandRegistry.java&p1=geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/CommandRegistry.java&r1=580765&r2=581061&rev=581061&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/plugin/CommandRegistry.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/registry/CommandRegistry.java Mon Oct  1 13:18:31 2007
@@ -17,69 +17,22 @@
  * under the License.
  */
 
-package org.apache.geronimo.gshell.plugin;
+package org.apache.geronimo.gshell.registry;
 
 import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
 
 import org.apache.geronimo.gshell.command.descriptor.CommandDescriptor;
-import org.apache.geronimo.gshell.command.descriptor.CommandSetDescriptor;
-import org.codehaus.plexus.component.annotations.Component;
-import org.codehaus.plexus.component.discovery.ComponentDiscoveryEvent;
-import org.codehaus.plexus.component.discovery.ComponentDiscoveryListener;
-import org.codehaus.plexus.component.repository.ComponentSetDescriptor;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
- * Registers command components as they are discovered by the container.
- * 
+ * ???
+ *
  * @version $Rev$ $Date$
  */
-@Component(role= CommandRegistry.class)
-public class CommandRegistry
-    implements ComponentDiscoveryListener
+public interface CommandRegistry
 {
-    public static final String ID = "gshell-command-regsitry";
+    void register(CommandDescriptor descriptor);
 
-    private final Logger log = LoggerFactory.getLogger(getClass());
-
-    private Map<String,CommandDescriptor> commandDescriptors = new HashMap<String,CommandDescriptor>();
-
-    public String getId() {
-        return ID;
-    }
+    Collection<CommandDescriptor> descriptors();
     
-    public void componentDiscovered(final ComponentDiscoveryEvent event) {
-        assert event != null;
-
-        ComponentSetDescriptor setDescriptor = event.getComponentSetDescriptor();
-
-        if (setDescriptor instanceof CommandSetDescriptor) {
-            CommandSetDescriptor commands = (CommandSetDescriptor) setDescriptor;
-
-            for (CommandDescriptor desc : commands.getCommandDescriptors()) {
-                String id = desc.getId();
-
-                if (commandDescriptors.containsKey(id)) {
-                    log.error("Ignoring duplicate command id: {}", id);
-                }
-                else {
-                    log.debug("Found command: {}", id);
-                    commandDescriptors.put(id, desc);
-                }
-            }
-        }
-    }
-
-    public Collection<CommandDescriptor> getCommandDescriptors() {
-        return commandDescriptors.values();
-    }
-
-    public CommandDescriptor getCommandDescriptor(final String id) {
-        assert id != null;
-
-        return commandDescriptors.get(id);
-    }
+    CommandDescriptor lookup(String id);
 }

Added: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/registry/DefaultCommandRegistry.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/registry/DefaultCommandRegistry.java?rev=581061&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/registry/DefaultCommandRegistry.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/registry/DefaultCommandRegistry.java Mon Oct  1 13:18:31 2007
@@ -0,0 +1,68 @@
+/*
+ * 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.registry;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.geronimo.gshell.command.descriptor.CommandDescriptor;
+import org.codehaus.plexus.component.annotations.Component;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Registers command components as they are discovered by the container.
+ *
+ * @version $Rev$ $Date$
+ */
+@Component(role=CommandRegistry.class, hint="default")
+public class DefaultCommandRegistry
+    implements CommandRegistry
+{
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private Map<String, CommandDescriptor> descriptors = new HashMap<String,CommandDescriptor>();
+
+    public void register(final CommandDescriptor descriptor) {
+        assert descriptor != null;
+
+        String id = descriptor.getId();
+
+        if (descriptors.containsKey(id)) {
+            log.error("Ignoring duplicate: {}", id);
+        }
+        else {
+            descriptors.put(id, descriptor);
+            log.debug("Registered: {}", id);
+        }
+    }
+
+    public CommandDescriptor lookup(final String id) {
+        assert id != null;
+
+        return descriptors.get(id);
+    }
+
+    public Collection<CommandDescriptor> descriptors() {
+        return Collections.unmodifiableCollection(descriptors.values());
+    }
+}
\ No newline at end of file

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

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

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