commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject cvs commit: jakarta-commons/digester/src/java/org/apache/commons/digester/xmlrules DigesterRuleParser.java digester-rules.dtd
Date Thu, 23 Oct 2003 20:06:09 GMT
rdonkin     2003/10/23 13:06:09

  Modified:    digester/src/java/org/apache/commons/digester/xmlrules
                        DigesterRuleParser.java digester-rules.dtd
  Log:
  Added support for ObjectParamRule to xmlrules. Patch contributed by Anton Maslovsky.
  
  Revision  Changes    Path
  1.20      +50 -4     jakarta-commons/digester/src/java/org/apache/commons/digester/xmlrules/DigesterRuleParser.java
  
  Index: DigesterRuleParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/xmlrules/DigesterRuleParser.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- DigesterRuleParser.java	9 Oct 2003 21:09:48 -0000	1.19
  +++ DigesterRuleParser.java	23 Oct 2003 20:06:09 -0000	1.20
  @@ -1,4 +1,4 @@
  -/*
  +  /*
    * $Header$
    * $Revision$
    * $Date$
  @@ -72,7 +72,10 @@
   import java.util.Set;
   import java.util.StringTokenizer;
   
  +import org.apache.commons.beanutils.ConvertUtils;
  +
   import org.apache.commons.collections.ArrayStack;
  +
   import org.apache.commons.digester.AbstractObjectCreationFactory;
   import org.apache.commons.digester.BeanPropertySetterRule;
   import org.apache.commons.digester.CallMethodRule;
  @@ -87,6 +90,8 @@
   import org.apache.commons.digester.SetPropertiesRule;
   import org.apache.commons.digester.SetPropertyRule;
   import org.apache.commons.digester.SetTopRule;
  +import org.apache.commons.digester.ObjectParamRule;
  +
   import org.xml.sax.Attributes;
   import org.xml.sax.SAXException;
   
  @@ -248,6 +253,10 @@
           digester.addFactoryCreate("*/call-method-rule", new CallMethodRuleFactory());
           digester.addRule("*/call-method-rule", new PatternRule("pattern"));
           digester.addSetNext("*/call-method-rule", "add", ruleClassName);
  +
  +        digester.addFactoryCreate("*/object-param-rule", new ObjectParamRuleFactory());
  +        digester.addRule("*/object-param-rule", new PatternRule("pattern"));
  +        digester.addSetNext("*/object-param-rule", "add", ruleClassName);
           
           digester.addFactoryCreate("*/call-param-rule", new CallParamRuleFactory());
           digester.addRule("*/call-param-rule", new PatternRule("pattern"));
  @@ -602,6 +611,43 @@
               return callParamRule;
           }
       }
  +    
  +    /**
  +     * Factory for creating a ObjectParamRule
  +     */
  +    protected class ObjectParamRuleFactory extends AbstractObjectCreationFactory {
  +        public Object createObject(Attributes attributes) throws Exception {
  +            // create callparamrule
  +            int paramIndex = Integer.parseInt(attributes.getValue("paramnumber"));
  +            String attributeName = attributes.getValue("attrname");
  +            String type = attributes.getValue("type");
  +            String value = attributes.getValue("value");
  +
  +            Rule objectParamRule = null;
  +
  +            // type name is requried
  +            if (type == null) {
  +                throw new RuntimeException("Attribute 'type' is required.");
  +            }
  +
  +            // create object instance
  +            Object param = null;
  +            Class clazz = Class.forName(type);
  +            if (value == null) {
  +                param = clazz.newInstance();
  +            } else {
  +                param = ConvertUtils.convert(value, clazz);
  +            }
  +
  +            if (attributeName == null) {
  +                objectParamRule = new ObjectParamRule(paramIndex, param);
  +            } else {
  +                objectParamRule = new ObjectParamRule(paramIndex, attributeName, param);
  +            }
  +            return objectParamRule;
  +        }
  +     }
  +
       
       /**
        * Factory for creating a FactoryCreateRule
  
  
  
  1.10      +26 -3     jakarta-commons/digester/src/java/org/apache/commons/digester/xmlrules/digester-rules.dtd
  
  Index: digester-rules.dtd
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/xmlrules/digester-rules.dtd,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- digester-rules.dtd	7 Jul 2003 20:52:12 -0000	1.9
  +++ digester-rules.dtd	23 Oct 2003 20:06:09 -0000	1.10
  @@ -10,13 +10,14 @@
        Digester is a framework for pattern-matching-based parsing of XML into
        Java objects. See http://jakarta.apache.org/commons/digester.html.  -->
   
  -<!ENTITY % rule-elements "bean-property-setter-rule | call-method-rule | call-param-rule
|
  +<!ENTITY % rule-elements "bean-property-setter-rule | call-method-rule |
  +                   call-param-rule | object-param-rule |
                      factory-create-rule | object-create-rule |
                      set-properties-rule | set-property-rule | set-top-rule |
                      set-next-rule" >
   
   <!-- digester-rules is the root element. -->
  -<!ELEMENT digester-rules (pattern | include | bean-property-setter-rule | call-method-rule
| call-param-rule | factory-create-rule | object-create-rule | set-properties-rule | set-property-rule
| set-top-rule | set-next-rule )*>
  +<!ELEMENT digester-rules (pattern | include | bean-property-setter-rule | call-method-rule
| call-param-rule |  object-param-rule | factory-create-rule | object-create-rule | set-properties-rule
| set-property-rule | set-top-rule | set-next-rule )*>
   
   
   <!-- <pattern> defines a matching pattern, or part of a matching pattern. Any
  @@ -91,6 +92,28 @@
       paramnumber CDATA #REQUIRED
       attrname CDATA #IMPLIED
       from-stack CDATA #IMPLIED>
  +    
  +<!--
  +    ObjectParamRule
  +    attrname  
  +           - an arbitrary Object defined programatically, assigned if the 
  +             element pattern AND specified attribute name are matched
  +    param 
  +           - an arbitrary Object defined programatically, assigned when the 
  +             element pattern associated with the Rule is matched
  +    type 
  +           - class name for object
  +    value 
  +           - initial value for the object
  +    -->
  +<!ELEMENT object-param-rule EMPTY>
  +<!ATTLIST object-param-rule
  +    pattern  CDATA #IMPLIED
  +    paramnumber CDATA #REQUIRED
  +    param CDATA #REQUIRED
  +    attrname CDATA #IMPLIED
  +    type CDATA #REQUIRED
  +    value CDATA #IMPLIED>
   
   <!-- 
       FactoryCreateRule 
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message