You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2008/10/27 20:18:43 UTC

svn commit: r708281 - in /servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main: java/org/apache/geronimo/ java/org/apache/servicemix/kernel/gshell/core/ java/org/apache/servicemix/kernel/gshell/core/config/ resources/META-INF/spring/

Author: gnodet
Date: Mon Oct 27 12:18:42 2008
New Revision: 708281

URL: http://svn.apache.org/viewvc?rev=708281&view=rev
Log:
SMX4KNL-129: Make sure aliases and links work correctly with the new gshell integration

Added:
    servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/Alias.java
    servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/Link.java
    servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/OsgiAliasRegistry.java
    servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/ShellWrapper.java
Removed:
    servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/geronimo/
Modified:
    servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/CommandBundle.java
    servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/OsgiCommandRegistry.java
    servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/config/CommandParser.java
    servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-local.xml
    servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-osgi.xml

Added: servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/Alias.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/Alias.java?rev=708281&view=auto
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/Alias.java (added)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/Alias.java Mon Oct 27 12:18:42 2008
@@ -0,0 +1,23 @@
+/*
+ * 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.servicemix.kernel.gshell.core;
+
+public interface Alias {
+
+}

Modified: servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/CommandBundle.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/CommandBundle.java?rev=708281&r1=708280&r2=708281&view=diff
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/CommandBundle.java (original)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/CommandBundle.java Mon Oct 27 12:18:42 2008
@@ -36,6 +36,10 @@
 import org.apache.geronimo.gshell.registry.CommandRegistry;
 import org.apache.geronimo.gshell.registry.AliasRegistry;
 import org.apache.geronimo.gshell.wisdom.command.CommandSupport;
+import org.apache.geronimo.gshell.wisdom.command.LinkCommand;
+import org.apache.geronimo.gshell.wisdom.registry.CommandLocationImpl;
+import org.apache.geronimo.gshell.spring.BeanContainerAware;
+import org.apache.geronimo.gshell.spring.BeanContainer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -51,6 +55,8 @@
 
     private List<Command> commands;
 
+    private Map<String,String> links;
+
     private Map<String,String> aliases;
 
     private ApplicationContext applicationContext;
@@ -74,6 +80,14 @@
         this.commands = commands;
     }
 
+    public Map<String, String> getLinks() {
+        return links;
+    }
+
+    public void setLinks(Map<String, String> links) {
+        this.links = links;
+    }
+
     public Map<String, String> getAliases() {
         return aliases;
     }
@@ -104,24 +118,53 @@
         }
         if (commandRegistry != null && aliasRegistry != null) {
             log.debug("Command bundle is using the auto wired command/alias registry");
-            for (Command command : commands) {
-                log.debug("Registering command: {}", command.getLocation());
-                commandRegistry.registerCommand(command);
-            }
-            for (String name : aliases.keySet()) {
-                log.debug("Registering alias: {}", name);
-                aliasRegistry.registerAlias(name, aliases.get(name));
+            if (commands != null) {
+                for (Command command : commands) {
+                    log.debug("Registering command: {}", command.getLocation());
+                    commandRegistry.registerCommand(command);
+                }
+            }
+            if (links != null) {
+                for (String name : links.keySet()) {
+                    log.debug("Registering link: {}", name);
+                    LinkCommand link = new LinkCommand(commandRegistry, links.get(name));
+                    link.setLocation(new CommandLocationImpl(name));
+                    commandRegistry.registerCommand(link);
+                }
+            }
+            if (aliases != null) {
+                for (String name : aliases.keySet()) {
+                    log.debug("Registering alias: {}", name);
+                    aliasRegistry.registerAlias(name, aliases.get(name));
+                }
             }
         } else if (bundleContext != null) {
-            if (aliases != null && aliases.size() > 0) {
-                throw new Exception("Aliases are not supported in OSGi");
-            }
             log.debug("Command bundle is using the OSGi registry");
-            for (Command command : commands) {
-                log.debug("Registering command: {}", command.getLocation());
-                Dictionary props = new Properties();
-                props.put(OsgiCommandRegistry.NAME, command.getLocation().getFullPath());
-                registrations.add(bundleContext.registerService(Command.class.getName(), command, props));
+            if (commands != null) {
+                for (Command command : commands) {
+                    log.debug("Registering command: {}", command.getLocation());
+                    Dictionary props = new Properties();
+                    props.put(OsgiCommandRegistry.NAME, command.getLocation().getFullPath());
+                    registrations.add(bundleContext.registerService(Command.class.getName(), command, props));
+                }
+            }
+            if (links != null) {
+                for (String name : links.keySet()) {
+                    log.debug("Registering link: {}", name);
+                    Dictionary props = new Properties();
+                    props.put(OsgiCommandRegistry.NAME, name);
+                    props.put(OsgiCommandRegistry.TARGET, links.get(name));
+                    registrations.add(bundleContext.registerService(Link.class.getName(), new Link() {}, props));
+                }
+            }
+            if (aliases != null) {
+                for (String name : aliases.keySet()) {
+                    log.debug("Registering alias: {}", name);
+                    Dictionary props = new Properties();
+                    props.put(OsgiAliasRegistry.NAME, name);
+                    props.put(OsgiAliasRegistry.ALIAS, aliases.get(name));
+                    registrations.add(bundleContext.registerService(Alias.class.getName(), new Alias() {}, props));
+                }
             }
         } else {
             throw new Exception("Command bundle should be wired to the command/alias registry or be used in an OSGi context");

Added: servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/Link.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/Link.java?rev=708281&view=auto
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/Link.java (added)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/Link.java Mon Oct 27 12:18:42 2008
@@ -0,0 +1,23 @@
+/*
+ * 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.servicemix.kernel.gshell.core;
+
+public interface Link {
+
+}

Added: servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/OsgiAliasRegistry.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/OsgiAliasRegistry.java?rev=708281&view=auto
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/OsgiAliasRegistry.java (added)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/OsgiAliasRegistry.java Mon Oct 27 12:18:42 2008
@@ -0,0 +1,44 @@
+/*
+ * 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.servicemix.kernel.gshell.core;
+
+import java.util.Map;
+
+import org.apache.geronimo.gshell.registry.AliasRegistry;
+
+public class OsgiAliasRegistry {
+
+    public static final String NAME = "name";
+    public static final String ALIAS = "alias";
+
+    private AliasRegistry aliasRegistry;
+
+    public OsgiAliasRegistry(AliasRegistry aliasRegistry) {
+        this.aliasRegistry = aliasRegistry;
+    }
+
+    public void register(final Alias alias, Map<String, ?> properties) throws Exception {
+        aliasRegistry.registerAlias((String) properties.get(NAME), (String) properties.get(ALIAS));
+    }
+
+    public void unregister(final Alias alias, Map<String, ?> properties) throws Exception {
+        aliasRegistry.removeAlias((String) properties.get(NAME));
+    }
+
+}

Modified: servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/OsgiCommandRegistry.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/OsgiCommandRegistry.java?rev=708281&r1=708280&r2=708281&view=diff
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/OsgiCommandRegistry.java (original)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/OsgiCommandRegistry.java Mon Oct 27 12:18:42 2008
@@ -21,12 +21,16 @@
 import java.util.Map;
 
 import org.apache.geronimo.gshell.command.Command;
+import org.apache.geronimo.gshell.command.CommandResult;
 import org.apache.geronimo.gshell.registry.CommandRegistry;
-import org.springframework.beans.factory.annotation.Autowired;
+import org.apache.geronimo.gshell.wisdom.command.LinkCommand;
+import org.apache.geronimo.gshell.wisdom.registry.CommandLocationImpl;
+import org.apache.geronimo.gshell.shell.ShellContext;
 
 public class OsgiCommandRegistry {
 
     public static final String NAME = "name";
+    public static final String TARGET = "target";
 
     private CommandRegistry commandRegistry;
 
@@ -42,4 +46,14 @@
         commandRegistry.removeCommand(command);
     }
 
+    public void register(final Link link, Map<String, ?> properties) throws Exception {
+        LinkCommand cmd = new LinkCommand(commandRegistry, (String) properties.get(TARGET));
+        cmd.setLocation(new CommandLocationImpl((String) properties.get(NAME)));
+        commandRegistry.registerCommand(cmd);
+    }
+
+    public void unregister(final Link link, Map<String, ?> properties) throws Exception {
+        commandRegistry.removeCommand(commandRegistry.getCommand((String) properties.get(NAME)));
+    }
+
 }

Added: servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/ShellWrapper.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/ShellWrapper.java?rev=708281&view=auto
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/ShellWrapper.java (added)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/ShellWrapper.java Mon Oct 27 12:18:42 2008
@@ -0,0 +1,86 @@
+/*
+ * 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.servicemix.kernel.gshell.core;
+
+import org.apache.geronimo.gshell.shell.Shell;
+import org.apache.geronimo.gshell.shell.ShellContext;
+import org.apache.geronimo.gshell.shell.ShellContextHolder;
+
+public class ShellWrapper implements Shell {
+
+    private Shell delegate;
+
+    public ShellWrapper(Shell delegate) {
+        this.delegate = delegate;
+    }
+
+    public ShellContext getContext() {
+        return delegate.getContext();
+    }
+
+    public Object execute(String s) throws Exception {
+        ShellContext ctx = ShellContextHolder.get(true);
+        try {
+            ShellContextHolder.set(getContext());
+            return delegate.execute(s);
+        } finally {
+            ShellContextHolder.set(ctx);
+        }
+    }
+
+    public Object execute(String s, Object[] objects) throws Exception {
+        ShellContext ctx = ShellContextHolder.get(true);
+        try {
+            ShellContextHolder.set(getContext());
+            return delegate.execute(s, objects);
+        } finally {
+            ShellContextHolder.set(ctx);
+        }
+    }
+
+    public Object execute(Object... objects) throws Exception {
+        ShellContext ctx = ShellContextHolder.get(true);
+        try {
+            ShellContextHolder.set(getContext());
+            return delegate.execute(objects);
+        } finally {
+            ShellContextHolder.set(ctx);
+        }
+    }
+
+    public boolean isOpened() {
+        return delegate.isOpened();
+    }
+
+    public void close() {
+        delegate.close();
+    }
+
+    public boolean isInteractive() {
+        return delegate.isInteractive();
+    }
+
+    public void run(Object... objects) throws Exception {
+        ShellContext ctx = ShellContextHolder.get(true);
+        try {
+            ShellContextHolder.set(getContext());
+            delegate.run(objects);
+        } finally {
+            ShellContextHolder.set(ctx);
+        }
+    }
+}

Modified: servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/config/CommandParser.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/config/CommandParser.java?rev=708281&r1=708280&r2=708281&view=diff
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/config/CommandParser.java (original)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/java/org/apache/servicemix/kernel/gshell/core/config/CommandParser.java Mon Oct 27 12:18:42 2008
@@ -42,7 +42,6 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.geronimo.gshell.wisdom.command.ConfigurableCommandCompleter;
-import org.apache.geronimo.gshell.wisdom.command.LinkCommand;
 import org.apache.geronimo.gshell.wisdom.registry.CommandLocationImpl;
 import org.apache.servicemix.kernel.gshell.core.CommandBundle;
 
@@ -96,6 +95,8 @@
 
     public static final String LINK = "link";
 
+    public static final String LINKS = "links";
+
     public static final String TARGET = "target";
 
     @Override
@@ -277,14 +278,15 @@
             //
 
             ManagedList commands = new ManagedList();
-            // noinspection unchecked
+
             commands.addAll(parseCommands(element));
-            // noinspection unchecked
-            commands.addAll(parseLinks(element));
             bundle.addPropertyValue(COMMANDS, commands);
 
+            ManagedMap links = new ManagedMap();
+            links.putAll(parseLinks(element));
+            bundle.addPropertyValue(LINKS, links);
+
             ManagedMap aliases = new ManagedMap();
-            // noinspection unchecked
             aliases.putAll(parseAliases(element));
             bundle.addPropertyValue(ALIASES, aliases);
 
@@ -427,27 +429,20 @@
         // <gshell:link>
         //
 
-        private List<BeanDefinition> parseLinks(final Element element) {
+        private Map<String,String> parseLinks(final Element element) {
             assert element != null;
 
             log.trace("Parse links; element; {}", element);
 
-            List<BeanDefinition> links = new ArrayList<BeanDefinition>();
+            Map<String,String> links = new LinkedHashMap<String,String>();
 
             List<Element> children = getChildElements(element, LINK);
 
             for (Element child : children) {
-                BeanDefinitionBuilder link = BeanDefinitionBuilder.rootBeanDefinition(LinkCommand.class);
-                link.addConstructorArgReference("commandRegistry");
-                link.addConstructorArgValue(child.getAttribute(TARGET));
-
                 String name = child.getAttribute(NAME);
-                BeanDefinition def = new GenericBeanDefinition();
-                def.setBeanClassName(CommandLocationImpl.class.getName());
-                def.getConstructorArgumentValues().addGenericArgumentValue(name);
-                link.addPropertyValue(LOCATION, def);
+                String target = child.getAttribute(TARGET);
 
-                links.add(link.getBeanDefinition());
+                links.put(name, target);
             }
 
             return links;

Modified: servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-local.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-local.xml?rev=708281&r1=708280&r2=708281&view=diff
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-local.xml (original)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-local.xml Mon Oct 27 12:18:42 2008
@@ -33,7 +33,11 @@
        default-init-method="init"
        default-destroy-method="destroy">
 
-    <bean id="localShell" parent="shell" init-method="init" destroy-method="close"/>
+    <bean id="localShellWrapped" parent="shell" init-method="init" destroy-method="close"/>
+
+    <bean id="localShell" class="org.apache.servicemix.kernel.gshell.core.ShellWrapper">
+        <constructor-arg ref="localShellWrapped" />
+    </bean>
 
     <osgi:reference id="mainService" interface="org.apache.servicemix.kernel.main.spi.MainService"/>
 

Modified: servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-osgi.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-osgi.xml?rev=708281&r1=708280&r2=708281&view=diff
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-osgi.xml (original)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-core/src/main/resources/META-INF/spring/gshell-osgi.xml Mon Oct 27 12:18:42 2008
@@ -40,10 +40,21 @@
         <constructor-arg ref="commandRegistry" />
     </bean>
 
+    <bean id="osgiAliasRegistry" class="org.apache.servicemix.kernel.gshell.core.OsgiAliasRegistry">
+        <constructor-arg ref="aliasRegistry" />
+    </bean>
+
     <osgi:list id="osgiCommands" interface="org.apache.geronimo.gshell.command.Command" cardinality="0..N">
         <osgi:listener ref="osgiCommandRegistry" bind-method="register" unbind-method="unregister" />
     </osgi:list>
 
+    <osgi:list id="osgiLinkCommands" interface="org.apache.servicemix.kernel.gshell.core.Link" cardinality="0..N">
+        <osgi:listener ref="osgiCommandRegistry" bind-method="register" unbind-method="unregister" />
+    </osgi:list>
+
+    <osgi:list id="osgiAliases" interface="org.apache.servicemix.kernel.gshell.core.Alias" cardinality="0..N">
+        <osgi:listener ref="osgiAliasRegistry" bind-method="register" unbind-method="unregister" />
+    </osgi:list>
 
     <osgi:service ref="localShell" interface="org.apache.geronimo.gshell.shell.Shell">
     </osgi:service>