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 2008/09/26 10:51:36 UTC

svn commit: r699224 - in /geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main: java/org/apache/geronimo/gshell/wisdom/config/PluginParser.java resources/org/apache/geronimo/gshell/wisdom/config/wisdom-gshell.xsd

Author: jdillon
Date: Fri Sep 26 01:51:35 2008
New Revision: 699224

URL: http://svn.apache.org/viewvc?rev=699224&view=rev
Log:
Using string constants for plugin parsing
Use a custom type to avoid duplicating all that beans:* muck
Changed the schema to limit the attributes of command components, things like abstract and scope are not valid

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

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=699224&r1=699223&r2=699224&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 Fri Sep 26 01:51:35 2008
@@ -49,6 +49,38 @@
 public class PluginParser
     extends AbstractBeanDefinitionParser
 {
+    private static final String ID = "id";
+    
+    private static final String ACTION = "action";
+
+    private static final String ACTION_ID = "actionId";
+
+    private static final String COMMAND_TEMPLATE_SUFFIX = "CommandTemplate";
+
+    private static final String COMMAND_BUNDLE = "command-bundle";
+
+    private static final String NAME = "name";
+
+    private static final String COMMANDS = "commands";
+
+    private static final String COMMAND = "command";
+
+    private static final String TYPE = "type";
+
+    private static final String DOCUMENTER = "documenter";
+
+    private static final String COMPLETER = "completer";
+
+    private static final String MESSAGE_SOURCE = "message-source";
+
+    private static final String MESSAGES = "messages";
+
+    private static final String PROTOTYPE = "prototype";
+
+    private static final String ALIAS = "alias";
+
+    private static final String TARGET = "target";
+
     @Override
     protected boolean shouldGenerateId() {
 		return true;
@@ -83,7 +115,7 @@
         }
 
         public String getTemplateName() {
-            return name().toLowerCase() + "CommandTemplate";
+            return name().toLowerCase() + COMMAND_TEMPLATE_SUFFIX;
         }
 
         public void wire(final BeanDefinitionBuilder command, final BeanDefinitionHolder action) {
@@ -92,11 +124,11 @@
 
             switch (this) {
                 case STATELESS:
-                    command.addPropertyReference("action", action.getBeanName());
+                    command.addPropertyReference(ACTION, action.getBeanName());
                     break;
 
                 case STATEFUL:
-                    command.addPropertyValue("actionId", action.getBeanName());
+                    command.addPropertyValue(ACTION_ID, action.getBeanName());
                     break;
             }
         }
@@ -212,7 +244,7 @@
             log.trace("Parse plugin; element: {}", element);
 
             BeanDefinitionBuilder plugin = BeanDefinitionBuilder.rootBeanDefinition(PluginImpl.class);
-            plugin.addPropertyValue("id", element.getAttribute("name"));
+            plugin.addPropertyValue(ID, element.getAttribute(NAME));
 
             return plugin;
         }
@@ -226,7 +258,7 @@
 
             log.trace("Parse command bundles; element: {}", element);
 
-            List<Element> children = getChildElements(element, "command-bundle");
+            List<Element> children = getChildElements(element, COMMAND_BUNDLE);
             List<BeanDefinitionHolder> holders = new ArrayList<BeanDefinitionHolder>();
 
             for (Element child : children) {
@@ -250,7 +282,7 @@
             log.trace("Parse command bundle; element; {}", element);
 
             BeanDefinitionBuilder bundle = BeanDefinitionBuilder.rootBeanDefinition(CommandBundle.class);
-            bundle.addPropertyValue("id", element.getAttribute("name"));
+            bundle.addPropertyValue(ID, element.getAttribute(NAME));
             bundle.setLazyInit(true);
 
             List commands = parseCommands(element);
@@ -259,7 +291,7 @@
             // noinspection unchecked
             commands.addAll(aliases);
 
-            bundle.addPropertyValue("commands", commands);
+            bundle.addPropertyValue(COMMANDS, commands);
             
             return bundle;
         }
@@ -273,7 +305,7 @@
 
             log.trace("Parse commands; element; {}", element);
 
-            List<Element> children = getChildElements(element, "command");
+            List<Element> children = getChildElements(element, COMMAND);
             ManagedList defs = new ManagedList();
 
             for (Element child : children) {
@@ -291,7 +323,7 @@
 
             log.trace("Parse command; element; {}", element);
 
-            CommandType type = CommandType.parse(element.getAttribute("type"));
+            CommandType type = CommandType.parse(element.getAttribute(TYPE));
             BeanDefinitionBuilder command = BeanDefinitionBuilder.childBeanDefinition(type.getTemplateName());
 
             // TODO: Currently name is pulled from the documentor, need to change that
@@ -301,28 +333,28 @@
 
             // Required children elements
 
-            child = getChildElement(element, "action");
+            child = getChildElement(element, ACTION);
             BeanDefinitionHolder action = parseCommandAction(child);
             type.wire(command, action);
 
             // Optional children elements
 
-            child = getChildElement(element, "documenter");
+            child = getChildElement(element, DOCUMENTER);
             if (child != null) {
                 BeanDefinitionHolder holder = parseBeanDefinitionElement(child);
-                command.addPropertyValue("documenter", holder.getBeanDefinition());
+                command.addPropertyValue(DOCUMENTER, holder.getBeanDefinition());
             }
 
-            child = getChildElement(element, "completer");
+            child = getChildElement(element, COMPLETER);
             if (child != null) {
                 BeanDefinitionHolder holder = parseBeanDefinitionElement(child);
-                command.addPropertyValue("completer", holder.getBeanDefinition());
+                command.addPropertyValue(COMPLETER, holder.getBeanDefinition());
             }
 
-            child = getChildElement(element, "message-source");
+            child = getChildElement(element, MESSAGE_SOURCE);
             if (child != null) {
                 BeanDefinitionHolder holder = parseBeanDefinitionElement(child);
-                command.addPropertyValue("messages", holder.getBeanDefinition());
+                command.addPropertyValue(MESSAGES, holder.getBeanDefinition());
             }
 
             return command;
@@ -341,7 +373,7 @@
             BeanDefinition action = parseBeanDefinitionElement(element).getBeanDefinition();
             
             // All actions are configured as prototypes
-            action.setScope("prototype");
+            action.setScope(PROTOTYPE);
 
             // Generate id and register the bean
             String id = resolveId(element, action);
@@ -357,7 +389,7 @@
 
             log.trace("Parse aliases; element; {}", element);
 
-            List<Element> children = getChildElements(element, "alias");
+            List<Element> children = getChildElements(element, ALIAS);
             ManagedList defs = new ManagedList();
 
             for (Element child : children) {
@@ -376,8 +408,8 @@
             log.trace("Parse alias; element; {}", element);
 
             BeanDefinitionBuilder alias = BeanDefinitionBuilder.rootBeanDefinition(AliasCommand.class);
-            alias.addConstructorArgValue(element.getAttribute("name"));
-            alias.addConstructorArgValue(element.getAttribute("target"));
+            alias.addConstructorArgValue(element.getAttribute(NAME));
+            alias.addConstructorArgValue(element.getAttribute(TARGET));
 
             return alias;
         }

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=699224&r1=699223&r2=699224&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 Fri Sep 26 01:51:35 2008
@@ -94,6 +94,63 @@
         </xsd:complexType>
     </xsd:element>
 
+    <xsd:attributeGroup name="commandComponentAttributes">
+        <xsd:annotation>
+            <xsd:documentation>
+                Defines the valid attributes for command components.  This is based on beans:beanAttributes,
+                stripping off the bits which are not valid in the command component context.
+            </xsd:documentation>
+        </xsd:annotation>
+		<xsd:attribute name="name" type="xsd:string"/>
+		<xsd:attribute name="class" type="xsd:string"/>
+		<xsd:attribute name="parent" type="xsd:string"/>
+		<xsd:attribute name="autowire" default="default">
+			<xsd:simpleType>
+				<xsd:restriction base="xsd:NMTOKEN">
+					<xsd:enumeration value="default"/>
+					<xsd:enumeration value="no"/>
+					<xsd:enumeration value="byName"/>
+					<xsd:enumeration value="byType"/>
+					<xsd:enumeration value="constructor"/>
+					<xsd:enumeration value="autodetect"/>
+				</xsd:restriction>
+			</xsd:simpleType>
+		</xsd:attribute>
+		<xsd:attribute name="dependency-check" default="default">
+			<xsd:simpleType>
+				<xsd:restriction base="xsd:NMTOKEN">
+					<xsd:enumeration value="default"/>
+					<xsd:enumeration value="none"/>
+					<xsd:enumeration value="simple"/>
+					<xsd:enumeration value="objects"/>
+					<xsd:enumeration value="all"/>
+				</xsd:restriction>
+			</xsd:simpleType>
+		</xsd:attribute>
+		<xsd:attribute name="depends-on" type="xsd:string"/>
+		<xsd:attribute name="autowire-candidate" default="default" type="beans:defaultable-boolean"/>
+		<xsd:attribute name="primary" type="xsd:boolean"/>
+		<xsd:attribute name="init-method" type="xsd:string"/>
+		<xsd:attribute name="destroy-method" type="xsd:string"/>
+		<xsd:attribute name="factory-method" type="xsd:string"/>
+		<xsd:attribute name="factory-bean" type="xsd:string"/>
+		<xsd:anyAttribute namespace="##other" processContents="lax"/>
+	</xsd:attributeGroup>
+
+    <xsd:complexType name="commandComponent" abstract="true">
+        <xsd:annotation>
+            <xsd:documentation>
+                Support for command component elements, which are all basically just beans.
+            </xsd:documentation>
+        </xsd:annotation>
+        <xsd:complexContent>
+            <xsd:extension base="beans:identifiedType">
+                <xsd:group ref="beans:beanElements"/>
+                <xsd:attributeGroup ref="commandComponentAttributes"/>
+            </xsd:extension>
+        </xsd:complexContent>
+    </xsd:complexType>
+    
     <xsd:element name="action">
         <xsd:complexType>
             <xsd:annotation>
@@ -102,10 +159,7 @@
                 </xsd:documentation>
             </xsd:annotation>
             <xsd:complexContent>
-                <xsd:extension base="beans:identifiedType">
-                    <xsd:group ref="beans:beanElements"/>
-                    <xsd:attributeGroup ref="beans:beanAttributes"/>
-                </xsd:extension>
+                <xsd:extension base="commandComponent"/>
             </xsd:complexContent>
         </xsd:complexType>
     </xsd:element>
@@ -118,10 +172,7 @@
                 </xsd:documentation>
             </xsd:annotation>
             <xsd:complexContent>
-                <xsd:extension base="beans:identifiedType">
-                    <xsd:group ref="beans:beanElements"/>
-                    <xsd:attributeGroup ref="beans:beanAttributes"/>
-                </xsd:extension>
+                <xsd:extension base="commandComponent"/>
             </xsd:complexContent>
         </xsd:complexType>
     </xsd:element>
@@ -134,10 +185,7 @@
                 </xsd:documentation>
             </xsd:annotation>
             <xsd:complexContent>
-                <xsd:extension base="beans:identifiedType">
-                    <xsd:group ref="beans:beanElements"/>
-                    <xsd:attributeGroup ref="beans:beanAttributes"/>
-                </xsd:extension>
+                <xsd:extension base="commandComponent"/>
             </xsd:complexContent>
         </xsd:complexType>
     </xsd:element>
@@ -150,10 +198,7 @@
                 </xsd:documentation>
             </xsd:annotation>
             <xsd:complexContent>
-                <xsd:extension base="beans:identifiedType">
-                    <xsd:group ref="beans:beanElements"/>
-                    <xsd:attributeGroup ref="beans:beanAttributes"/>
-                </xsd:extension>
+                <xsd:extension base="commandComponent"/>
             </xsd:complexContent>
         </xsd:complexType>
     </xsd:element>