geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r698842 - in /geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src: main/java/org/apache/geronimo/gshell/wisdom/command/ main/java/org/apache/geronimo/gshell/wisdom/config/ main/resources/org/apache/geronimo/gshell/wisdom/config/ test...
Date Thu, 25 Sep 2008 07:15:04 GMT
Author: jdillon
Date: Thu Sep 25 00:15:04 2008
New Revision: 698842

URL: http://svn.apache.org/viewvc?rev=698842&view=rev
Log:
Hooked up <gshell:alias>, <gshell:documenter>, <gshell:completer> and <gshell:message-source>
support
Dropped <gshell:command action=""/> short-cut for now

Modified:
    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/config/PluginParser.java
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/resources/org/apache/geronimo/gshell/wisdom/config/wisdom-gshell.xsd
    geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/resources/org/apache/geronimo/gshell/wisdom/config/PluginParserTest-context.xml

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=698842&r1=698841&r2=698842&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
Thu Sep 25 00:15:04 2008
@@ -32,6 +32,18 @@
 public class AliasCommand
     extends CommandSupport
 {
+    private String name;
+
+    private String target;
+
+    public AliasCommand(final String name, final String target) {
+        assert name != null;
+        assert target != null;
+
+        this.name = name;
+        this.target = target;
+    }
+
     @Override
     public CommandResult execute(final ShellContext context, final Object[] args) {
         assert context != null;

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=698842&r1=698841&r2=698842&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
Thu Sep 25 00:15:04 2008
@@ -19,6 +19,7 @@
 
 package org.apache.geronimo.gshell.wisdom.config;
 
+import org.apache.geronimo.gshell.wisdom.command.AliasCommand;
 import org.apache.geronimo.gshell.wisdom.plugin.PluginImpl;
 import org.apache.geronimo.gshell.wisdom.plugin.activation.DefaultCommandBundleActivationRule;
 import org.apache.geronimo.gshell.wisdom.plugin.bundle.CommandBundle;
@@ -35,7 +36,6 @@
 import org.springframework.beans.factory.xml.ParserContext;
 import org.springframework.util.StringUtils;
 import org.springframework.util.xml.DomUtils;
-import org.w3c.dom.Attr;
 import org.w3c.dom.Element;
 
 import java.util.ArrayList;
@@ -177,6 +177,10 @@
             return register(holder);
         }
 
+        //
+        // <gshell:plugin>
+        //
+
         public BeanDefinitionBuilder buildPlugin(final Element element) {
             assert element != null;
 
@@ -195,6 +199,7 @@
             BeanDefinitionBuilder rule = BeanDefinitionBuilder.rootBeanDefinition(DefaultCommandBundleActivationRule.class);
             rule.addPropertyValue("bundleId", "default");
             ManagedList rules = new ManagedList();
+            // noinspection unchecked
             rules.add(rule.getBeanDefinition());
             plugin.addPropertyValue("activationRules", rules);
 
@@ -212,6 +217,10 @@
             return plugin;
         }
 
+        //
+        // <gshell:command-bundle>
+        //
+
         private List<BeanDefinitionHolder> parseCommandBundles(final Element element)
{
             assert element != null;
 
@@ -245,11 +254,20 @@
             bundle.setLazyInit(true);
 
             List commands = parseCommands(element);
+            List aliases = parseAliases(element);
+
+            // noinspection unchecked
+            commands.addAll(aliases);
+
             bundle.addPropertyValue("commands", commands);
             
             return bundle;
         }
 
+        //
+        // <gshell:command>
+        //
+
         private List parseCommands(final Element element) {
             assert element != null;
 
@@ -279,58 +297,49 @@
             // TODO: Currently name is pulled from the documentor, need to change that
             // command.addPropertyValue("name", element.getAttribute("name"));
 
-            BeanDefinitionHolder action = parseCommandAction(element);
+            Element child;
+
+            // Required children elements
 
-            // Wire up the action based on the type
+            child = getChildElement(element, "action");
+            BeanDefinitionHolder action = parseCommandAction(child);
             type.wire(command, action);
 
+            // Optional children elements
+
+            child = getChildElement(element, "documenter");
+            if (child != null) {
+                BeanDefinitionHolder holder = parseBeanDefinitionElement(child);
+                command.addPropertyValue("documenter", holder.getBeanDefinition());
+            }
+
+            child = getChildElement(element, "completer");
+            if (child != null) {
+                BeanDefinitionHolder holder = parseBeanDefinitionElement(child);
+                command.addPropertyValue("completer", holder.getBeanDefinition());
+            }
+
+            child = getChildElement(element, "message-source");
+            if (child != null) {
+                BeanDefinitionHolder holder = parseBeanDefinitionElement(child);
+                command.addPropertyValue("messages", holder.getBeanDefinition());
+            }
+
             return command;
         }
 
+        //
+        // <gshell:action>
+        //
+
         private BeanDefinitionHolder parseCommandAction(final Element element) {
             assert element != null;
 
             log.info("Parse command action; element; {}", element);
 
-            Attr actionAttr = element.getAttributeNode("action");
-            Element actionElement = getChildElement(element, "action");
-
-            // Validate that we only have one action
-            if (actionAttr != null && actionElement != null) {
-                throw new RuntimeException("Must specify only one action attribute or action
element");
-            }
-            if (actionAttr == null && actionElement == null) {
-                throw new RuntimeException("Missing action attribute or action element");
-            }
-
             // Construct the action
-            BeanDefinition action;
-
-            if (actionAttr != null) {
-                action = BeanDefinitionBuilder.rootBeanDefinition(actionAttr.getValue()).getBeanDefinition();
-            }
-            else {
-                // TODO: Can probably just treat the "action" element as a "bean" element?
-                
-                Attr classAttr = actionElement.getAttributeNode("class");
-                Element beanElement = getChildElement(actionElement, "bean");
-
-                // Validate we only have one configuration for the action
-                if (classAttr != null && beanElement != null) {
-                    throw new RuntimeException("Must specify only one class attribute or
bean element");
-                }
-                if (classAttr == null && beanElement == null) {
-                    throw new RuntimeException("Missing action class attribute or action
bean element");
-                }
-
-                if (classAttr != null) {
-                    action = BeanDefinitionBuilder.rootBeanDefinition(classAttr.getValue()).getBeanDefinition();
-                }
-                else {
-                    action = parseBeanDefinitionElement(beanElement).getBeanDefinition();
-                }
-            }
-
+            BeanDefinition action = parseBeanDefinitionElement(element).getBeanDefinition();
+            
             // All actions are configured as prototypes
             action.setScope("prototype");
 
@@ -338,5 +347,40 @@
             String id = resolveId(element, action);
             return register(action, id);
         }
+
+        //
+        // <gshell:alias>
+        //
+
+        private List parseAliases(final Element element) {
+            assert element != null;
+
+            log.info("Parse aliases; element; {}", element);
+
+            List<Element> children = getChildElements(element, "alias");
+            ManagedList defs = new ManagedList();
+
+            for (Element child : children) {
+                BeanDefinitionBuilder command = parseAlias(child);
+
+                // noinspection unchecked
+                defs.add(command.getBeanDefinition());
+            }
+
+            return defs;
+        }
+
+        private BeanDefinitionBuilder parseAlias(final Element element) {
+            assert element != null;
+
+            log.info("Parse alias; element; {}", element);
+
+            BeanDefinitionBuilder alias = BeanDefinitionBuilder.rootBeanDefinition(AliasCommand.class);
+            alias.addConstructorArgValue(element.getAttribute("name"));
+            alias.addConstructorArgValue(element.getAttribute("target"));
+
+            return alias;
+        }
+
     }
 }
\ No newline at end of file

Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/resources/org/apache/geronimo/gshell/wisdom/config/wisdom-gshell.xsd
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/resources/org/apache/geronimo/gshell/wisdom/config/wisdom-gshell.xsd?rev=698842&r1=698841&r2=698842&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/resources/org/apache/geronimo/gshell/wisdom/config/wisdom-gshell.xsd
(original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/resources/org/apache/geronimo/gshell/wisdom/config/wisdom-gshell.xsd
Thu Sep 25 00:15:04 2008
@@ -58,6 +58,7 @@
             </xsd:annotation>
             <xsd:sequence>
                 <xsd:element ref="command" minOccurs="0" maxOccurs="unbounded"/>
+                <xsd:element ref="alias" minOccurs="0" maxOccurs="unbounded"/>
             </xsd:sequence>
             <xsd:attribute name="name" type="xsd:string" use="required"/>
         </xsd:complexType>
@@ -71,7 +72,10 @@
                 </xsd:documentation>
             </xsd:annotation>
             <xsd:sequence>
-                <xsd:element ref="action" minOccurs="0" maxOccurs="1"/>
+                <xsd:element ref="action" minOccurs="1" maxOccurs="1"/>
+                <xsd:element ref="documenter" minOccurs="0" maxOccurs="1"/>
+                <xsd:element ref="completer" minOccurs="0" maxOccurs="1"/>
+                <xsd:element ref="message-source" minOccurs="0" maxOccurs="1"/>
             </xsd:sequence>
             <xsd:attribute name="name" type="xsd:string" use="required"/>
             <xsd:attribute name="type" use="optional" default="stateful">
@@ -87,7 +91,6 @@
                     </xsd:restriction>
                 </xsd:simpleType>
             </xsd:attribute>
-            <xsd:attribute name="action" type="xsd:string" use="optional"/>
         </xsd:complexType>
     </xsd:element>
 
@@ -98,10 +101,72 @@
                     Defines a command action.
                 </xsd:documentation>
             </xsd:annotation>
-            <xsd:sequence>
-                <xsd:element ref="beans:bean" minOccurs="0" maxOccurs="1"/>
-            </xsd:sequence>
-            <xsd:attribute name="class" type="xsd:string" use="optional"/>
+            <xsd:complexContent>
+				<xsd:extension base="beans:identifiedType">
+					<xsd:group ref="beans:beanElements"/>
+					<xsd:attributeGroup ref="beans:beanAttributes"/>
+				</xsd:extension>
+			</xsd:complexContent>
+		</xsd:complexType>
+    </xsd:element>
+
+    <xsd:element name="documenter">
+        <xsd:complexType>
+            <xsd:annotation>
+                <xsd:documentation>
+                    Defines a command documenter.
+                </xsd:documentation>
+            </xsd:annotation>
+            <xsd:complexContent>
+				<xsd:extension base="beans:identifiedType">
+					<xsd:group ref="beans:beanElements"/>
+					<xsd:attributeGroup ref="beans:beanAttributes"/>
+				</xsd:extension>
+			</xsd:complexContent>
+		</xsd:complexType>
+    </xsd:element>
+
+    <xsd:element name="completer">
+        <xsd:complexType>
+            <xsd:annotation>
+                <xsd:documentation>
+                    Defines a command completer.
+                </xsd:documentation>
+            </xsd:annotation>
+            <xsd:complexContent>
+				<xsd:extension base="beans:identifiedType">
+					<xsd:group ref="beans:beanElements"/>
+					<xsd:attributeGroup ref="beans:beanAttributes"/>
+				</xsd:extension>
+			</xsd:complexContent>
+		</xsd:complexType>
+    </xsd:element>
+
+    <xsd:element name="message-source">
+        <xsd:complexType>
+            <xsd:annotation>
+                <xsd:documentation>
+                    Defines a command message source.
+                </xsd:documentation>
+            </xsd:annotation>
+            <xsd:complexContent>
+				<xsd:extension base="beans:identifiedType">
+					<xsd:group ref="beans:beanElements"/>
+					<xsd:attributeGroup ref="beans:beanAttributes"/>
+				</xsd:extension>
+			</xsd:complexContent>
+		</xsd:complexType>
+    </xsd:element>
+
+    <xsd:element name="alias">
+        <xsd:complexType>
+            <xsd:annotation>
+                <xsd:documentation>
+                    Defines an alias.
+                </xsd:documentation>
+            </xsd:annotation>
+            <xsd:attribute name="name" type="xsd:string" use="required"/>
+            <xsd:attribute name="target" type="xsd:string" use="required"/>
         </xsd:complexType>
     </xsd:element>
 

Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/resources/org/apache/geronimo/gshell/wisdom/config/PluginParserTest-context.xml
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/resources/org/apache/geronimo/gshell/wisdom/config/PluginParserTest-context.xml?rev=698842&r1=698841&r2=698842&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/resources/org/apache/geronimo/gshell/wisdom/config/PluginParserTest-context.xml
(original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/test/resources/org/apache/geronimo/gshell/wisdom/config/PluginParserTest-context.xml
Thu Sep 25 00:15:04 2008
@@ -29,23 +29,32 @@
 
     <gshell:plugin name="test-plugin">
         <gshell:command-bundle name="test">
-            <gshell:command name="a" action="org.apache.geronimo.gshell.commands.SomeAction"/>
-
-            <gshell:command name="b" type="stateless" action="org.apache.geronimo.gshell.commands.SomeAction"/>
+            <gshell:command name="a">
+                <gshell:action class="org.apache.geronimo.gshell.wisdom.config.DummyAction"/>
+            </gshell:command>
 
-            <gshell:command name="c" type="stateful" action="org.apache.geronimo.gshell.commands.SomeAction"/>
+            <gshell:command name="b" type="stateless">
+                <gshell:action class="org.apache.geronimo.gshell.wisdom.config.DummyAction"/>
+            </gshell:command>
 
+            <gshell:command name="c" type="stateful">
+                <gshell:action class="org.apache.geronimo.gshell.wisdom.config.DummyAction"/>
+            </gshell:command>
+            
             <gshell:command name="d">
-                <gshell:action>
-                    <bean class="org.apache.geronimo.gshell.wisdom.config.DummyAction">
-                        <property name="text" value="b"/>
-                    </bean>
+                <gshell:action class="org.apache.geronimo.gshell.wisdom.config.DummyAction">
+                    <property name="text" value="b"/>
                 </gshell:action>
             </gshell:command>
 
             <gshell:command name="e">
                 <gshell:action class="org.apache.geronimo.gshell.wisdom.config.DummyAction"/>
+                <gshell:documenter class="org.apache.geronimo.gshell.wisdom.command.CommandDocumenterImpl"/>
+                <gshell:completer class="org.apache.geronimo.gshell.wisdom.command.CommandCompleterImpl"/>
+                <gshell:message-source class="org.apache.geronimo.gshell.wisdom.command.CommandMessageSource"/>
             </gshell:command>
+
+            <gshell:alias name="foo" target="bar"/>
         </gshell:command-bundle>
     </gshell:plugin>
 



Mime
View raw message