geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r699828 - in /geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src: main/java/org/apache/geronimo/gshell/wisdom/config/ main/resources/org/apache/geronimo/gshell/wisdom/config/ test/resources/org/apache/geronimo/gshell/wisdom/config/
Date Sun, 28 Sep 2008 14:35:28 GMT
Author: jdillon
Date: Sun Sep 28 07:35:27 2008
New Revision: 699828

URL: http://svn.apache.org/viewvc?rev=699828&view=rev
Log:
Added <gshell:completers> to simplify the creation of ConfigurableCommandCompleter muck

Modified:
    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/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=699828&r1=699827&r2=699828&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
Sun Sep 28 07:35:27 2008
@@ -19,18 +19,20 @@
 
 package org.apache.geronimo.gshell.wisdom.config;
 
-import org.apache.geronimo.gshell.wisdom.plugin.bundle.CommandBundle;
 import org.apache.geronimo.gshell.wisdom.command.LinkCommand;
-import org.apache.geronimo.gshell.application.plugin.Plugin;
+import org.apache.geronimo.gshell.wisdom.command.ConfigurableCommandCompleter;
+import org.apache.geronimo.gshell.wisdom.plugin.bundle.CommandBundle;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.BeanDefinitionStoreException;
 import org.springframework.beans.factory.config.BeanDefinition;
 import org.springframework.beans.factory.config.BeanDefinitionHolder;
+import org.springframework.beans.factory.config.RuntimeBeanReference;
+import org.springframework.beans.factory.config.TypedStringValue;
 import org.springframework.beans.factory.support.AbstractBeanDefinition;
 import org.springframework.beans.factory.support.BeanDefinitionBuilder;
-import org.springframework.beans.factory.support.ManagedMap;
 import org.springframework.beans.factory.support.ManagedList;
+import org.springframework.beans.factory.support.ManagedMap;
 import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
 import org.springframework.beans.factory.xml.BeanDefinitionParserDelegate;
 import org.springframework.beans.factory.xml.ParserContext;
@@ -38,7 +40,6 @@
 import org.springframework.util.xml.DomUtils;
 import org.w3c.dom.Element;
 
-import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -77,6 +78,14 @@
 
     private static final String COMPLETER = "completer";
 
+    private static final String COMPLETERS = "completers";
+
+    private static final String BEAN = "bean";
+
+    private static final String REF = "ref";
+
+    private static final String NULL = "null";
+
     private static final String MESSAGE_SOURCE = "message-source";
 
     private static final String MESSAGES = "messages";
@@ -185,6 +194,14 @@
         }
 
         @SuppressWarnings({"unchecked"})
+        private List<Element> getChildElements(final Element element, final String[]
names) {
+            assert element != null;
+            assert names != null;
+
+            return DomUtils.getChildElementsByTagName(element, names);
+        }
+
+        @SuppressWarnings({"unchecked"})
         private Element getChildElement(final Element element, final String name) {
             assert element != null;
             assert name != null;
@@ -196,11 +213,18 @@
             return null;
         }
 
-        private BeanDefinitionHolder parseBeanDefinitionElement(final Element element) {
+        private BeanDefinitionParserDelegate createBeanDefinitionParserDelegate(final Element
element) {
             assert element != null;
 
             BeanDefinitionParserDelegate parser = new BeanDefinitionParserDelegate(context.getReaderContext());
             parser.initDefaults(element.getOwnerDocument().getDocumentElement());
+            return parser;
+        }
+
+        private BeanDefinitionHolder parseBeanDefinitionElement(final Element element) {
+            assert element != null;
+
+            BeanDefinitionParserDelegate parser = createBeanDefinitionParserDelegate(element);
             return parser.parseBeanDefinitionElement(element);
         }
 
@@ -318,8 +342,7 @@
             parseAndApplyDescription(element, bundle);
 
             //
-            // NOTE: Seems we have to use ManagedMap to inject things properly.
-            //       But they are not generic, so so limit their usage here.
+            // 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();
@@ -390,6 +413,12 @@
                 command.addPropertyValue(COMPLETER, holder.getBeanDefinition());
             }
 
+            child = getChildElement(element, COMPLETERS);
+            if (child != null) {
+                BeanDefinitionBuilder completer = parseCommandCompleters(child);
+                command.addPropertyValue(COMPLETER, completer.getBeanDefinition());
+            }
+
             child = getChildElement(element, MESSAGE_SOURCE);
             if (child != null) {
                 BeanDefinitionHolder holder = parseBeanDefinitionElement(child);
@@ -400,6 +429,42 @@
         }
 
         //
+        // <gshell:completers>
+        //
+
+        private BeanDefinitionBuilder parseCommandCompleters(final Element element) {
+            assert element != null;
+
+            BeanDefinitionBuilder command = BeanDefinitionBuilder.rootBeanDefinition(ConfigurableCommandCompleter.class);
+
+            ManagedList completers = new ManagedList();
+
+            List<Element> children = getChildElements(element, new String[] {BEAN,
REF, NULL});
+
+            for (Element child : children) {
+                if (DomUtils.nodeNameEquals(child, BEAN)) {
+                    BeanDefinitionHolder holder = parseBeanDefinitionElement(child);
+                    // noinspection unchecked
+                    completers.add(holder.getBeanDefinition());
+                }
+                else if (DomUtils.nodeNameEquals(child, REF)) {
+                    BeanDefinitionParserDelegate parser = createBeanDefinitionParserDelegate(child);
+                    RuntimeBeanReference ref = (RuntimeBeanReference) parser.parsePropertySubElement(child,
command.getRawBeanDefinition());
+                    // noinspection unchecked
+                    completers.add(ref);
+                }
+                else if (DomUtils.nodeNameEquals(child, NULL)) {
+                    // noinspection unchecked
+                    completers.add(null);
+                }
+            }
+
+            command.addPropertyValue(COMPLETERS, completers);
+
+            return command;
+        }
+
+        //
         // <gshell:action>
         //
 

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=699828&r1=699827&r2=699828&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
Sun Sep 28 07:35:27 2008
@@ -85,7 +85,10 @@
                 -->
                 <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:choice minOccurs="0" maxOccurs="1">
+                    <xsd:element ref="completer"/>
+                    <xsd:element ref="completers"/>
+                </xsd:choice>
                 <xsd:element ref="message-source" minOccurs="0" maxOccurs="1"/>
             </xsd:sequence>
             <xsd:attribute name="name" type="xsd:string" use="required"/>
@@ -235,6 +238,23 @@
         </xsd:complexType>
     </xsd:element>
 
+    <xsd:element name="completers">
+        <xsd:complexType>
+            <xsd:annotation>
+                <xsd:documentation>
+                    Defines a configurable command completer with a set of completers.
+                </xsd:documentation>
+            </xsd:annotation>
+            <xsd:sequence>
+                <xsd:choice minOccurs="1" maxOccurs="unbounded">
+                    <xsd:element ref="beans:bean"/>
+                    <xsd:element ref="beans:ref"/>
+                    <xsd:element ref="beans:null"/>
+                </xsd:choice>
+            </xsd:sequence>
+        </xsd:complexType>
+    </xsd:element>
+
     <xsd:element name="message-source">
         <xsd:complexType>
             <xsd:annotation>

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=699828&r1=699827&r2=699828&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
Sun Sep 28 07:35:27 2008
@@ -112,6 +112,11 @@
                 </description>
 
                 <gshell:action class="org.apache.geronimo.gshell.wisdom.config.DummyAction"/>
+                <gshell:completers>
+                    <ref bean="fileObjectNameCompleter"/>
+                    <ref bean="fileObjectNameCompleter"/>
+                    <null/>
+                </gshell:completers>
             </gshell:command>
         </gshell:command-bundle>
     </gshell:plugin>



Mime
View raw message