commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robert burrell donkin <robertdon...@mac.com>
Subject Re: [PATCH] [digester] call-method-rule with paramtypes
Date Mon, 08 Jul 2002 18:27:50 GMT
applied. many thanks.

- robert


On Friday, July 5, 2002, at 02:47 AM, Mike Flester wrote:

> Hi --
>
> Here is a patch to allow DigesterLoader xml files to
> use call-method-rule with paramtypes as mentioned
> in this message:
>
> http://marc.theaimsgroup.com/?l=jakarta-commons-dev&m=102339883718625&w=2
>
> The patch includes an update to the xmlrules dtd
> to allow the paramtypes, update to the call-method-rule
> handling to process the new attribute, and updated
> test coverage for the call-method-rule stuff.
>
> Mike
> (mikeflester at yahoo dot com)
>
>
> __________________________________________________
> Do You Yahoo!?
> Sign up for SBC Yahoo! Dial - First Month Free
> http://sbc.yahoo.com
>
>
> __________________________________________________
> Do You Yahoo!?
> Sign up for SBC Yahoo! Dial - First Month Free
> http://sbc.yahoo.com
> ? jakarta-commons/xdocs/stylesheets/site.vsl
> Index: jakarta-
> commons/digester/src/java/org/apache/commons/digester/xmlrules/DigesterRuleParser.
> java
> ===================================================================
> RCS file: /home/cvspublic/jakarta-
> commons/digester/src/java/org/apache/commons/digester/xmlrules/DigesterRuleParser.
> java,v
> retrieving revision 1.3
> diff -u -r1.3 DigesterRuleParser.java
> --- jakarta-
> commons/digester/src/java/org/apache/commons/digester/xmlrules/DigesterRuleParser.
> java	9 Jan 2002 20:22:50 -0000	1.3
> +++ jakarta-
> commons/digester/src/java/org/apache/commons/digester/xmlrules/DigesterRuleParser.
> java	5 Jul 2002 01:24:17 -0000
> @@ -63,9 +63,11 @@
>  import java.io.IOException;
>  import java.io.PrintWriter;
>  import java.net.URL;
> +import java.util.ArrayList;
>  import java.util.HashSet;
>  import java.util.List;
>  import java.util.Set;
> +import java.util.StringTokenizer;
>
>  import org.apache.commons.collections.ArrayStack;
>  import org.apache.commons.digester.*;
> @@ -486,10 +488,23 @@
>       */
>      protected class CallMethodRuleFactory extends 
> AbstractObjectCreationFactory {
>          public Object createObject(Attributes attributes) {
> +            Rule callMethodRule = null;
>              int paramCount = 
> Integer.parseInt(attributes.getValue("paramcount"));
>              String methodName = attributes.getValue("methodname");
> -            Rule callMethodRule = new CallMethodRule(digester, 
> methodName,
> -                    paramCount);
> +            String paramTypesAttr = attributes.getValue("paramtypes");
> +            if (paramTypesAttr == null || paramTypesAttr.length() == 0) 
> {
> +                callMethodRule = new CallMethodRule(targetDigester, 
> methodName,
> +                                                    paramCount);
> +            } else {
> +                // Process the comma separated list or paramTypes
> +                // into an array of String class names
> +                ArrayList paramTypes = new ArrayList();
> +                StringTokenizer tokens = new 
> StringTokenizer(paramTypesAttr, " \t\n\r,");
> +                while (tokens.hasMoreTokens()) {
> +                    paramTypes.add(tokens.nextToken());
> +                }
> +                callMethodRule = new CallMethodRule(targetDigester, 
> methodName, paramCount, (String[])paramTypes.toArray(new String[0]));
> +            }
>              return callMethodRule;
>          }
>      }
> Index: jakarta-
> commons/digester/src/java/org/apache/commons/digester/xmlrules/digester-rules.
> dtd
> ===================================================================
> RCS file: /home/cvspublic/jakarta-
> commons/digester/src/java/org/apache/commons/digester/xmlrules/digester-rules.
> dtd,v
> retrieving revision 1.1
> diff -u -r1.1 digester-rules.dtd
> --- jakarta-
> commons/digester/src/java/org/apache/commons/digester/xmlrules/digester-rules.
> dtd	4 Dec 2001 19:49:36 -0000	1.1
> +++ jakarta-
> commons/digester/src/java/org/apache/commons/digester/xmlrules/digester-rules.
> dtd	5 Jul 2002 01:24:17 -0000
> @@ -71,7 +71,8 @@
>  <!ATTLIST call-method-rule
>      pattern    CDATA #IMPLIED
>      methodname CDATA #REQUIRED
> -    paramcount CDATA #REQUIRED>
> +    paramcount CDATA #REQUIRED
> +    paramtypes CDATA #IMPLIED>
>
>  <!-- CallParamRule -->
>  <!ELEMENT call-param-rule EMPTY>
> Index: jakarta-
> commons/digester/src/test/org/apache/commons/digester/xmlrules/DigesterLoaderTest.
> java
> ===================================================================
> RCS file: /home/cvspublic/jakarta-
> commons/digester/src/test/org/apache/commons/digester/xmlrules/DigesterLoaderTest.
> java,v
> retrieving revision 1.4
> diff -u -r1.4 DigesterLoaderTest.java
> --- jakarta-
> commons/digester/src/test/org/apache/commons/digester/xmlrules/DigesterLoaderTest.
> java	23 Jan 2002 22:38:01 -0000	1.4
> +++ jakarta-
> commons/digester/src/test/org/apache/commons/digester/xmlrules/DigesterLoaderTest.
> java	5 Jul 2002 01:24:19 -0000
> @@ -105,7 +105,7 @@
>          Digester digester = DigesterLoader.createDigester(rules);
>          digester.push(new ArrayList());
>          Object root = digester.parse(input.openStream());
> -        assertEquals(root.toString(), "[foo1 baz1 foo2, foo3 foo4]");
> +        assertEquals("[foo1 baz1 foo2, foo3 foo4]",root.toString());
>          //System.out.println(root);
>      }
>
> @@ -124,7 +124,15 @@
>          if (!(root instanceof ArrayList)) {
>              fail("Unexpected object returned from DigesterLoader. 
> Expected ArrayList; got " + root.getClass().getName());
>          }
> -        assertEquals(root.toString(), "[foo1 baz1 foo2, foo3 foo4]");
> +        assertEquals( "[foo1 baz1 foo2, foo3 foo4]",root.toString());
> +
> +        ArrayList al = (ArrayList)root;
> +        Object obj = al.get(0);
> +        if (! (obj instanceof TestObject)) {
> +            fail("Unexpected object returned from DigesterLoader. 
> Expected TestObject; got " + obj.getClass().getName());
> +        }
> +        TestObject to = (TestObject)obj;
> +        assertEquals(new Long(555),to.getLongValue());
>      }
>
>      /**
> Index: jakarta-
> commons/digester/src/test/org/apache/commons/digester/xmlrules/TestObject.
> java
> ===================================================================
> RCS file: /home/cvspublic/jakarta-
> commons/digester/src/test/org/apache/commons/digester/xmlrules/TestObject.
> java,v
> retrieving revision 1.3
> diff -u -r1.3 TestObject.java
> --- jakarta-
> commons/digester/src/test/org/apache/commons/digester/xmlrules/TestObject.
> java	23 Jan 2002 22:38:01 -0000	1.3
> +++ jakarta-
> commons/digester/src/test/org/apache/commons/digester/xmlrules/TestObject.
> java	5 Jul 2002 01:24:19 -0000
> @@ -72,6 +72,7 @@
>
>      private ArrayList children = new ArrayList();
>      private String value = "";
> +    private Long longValue = new Long(-1L);
>
>      public TestObject() {
>      }
> @@ -93,4 +94,16 @@
>      public void setValue(String val) {
>          value = val;
>      }
> +
> +    public void setLongValue(Long val) {
> +        longValue = val;
> +    }
> +
> +    public Long getLongValue() {
> +        return longValue;
> +    }
> +
> +    public void setStringValue(String val) {
> +    }
> +
>  }
> Index: jakarta-
> commons/digester/src/test/org/apache/commons/digester/xmlrules/test.xml
> ===================================================================
> RCS file: /home/cvspublic/jakarta-
> commons/digester/src/test/org/apache/commons/digester/xmlrules/test.xml,v
> retrieving revision 1.1
> diff -u -r1.1 test.xml
> --- jakarta-
> commons/digester/src/test/org/apache/commons/digester/xmlrules/test.xml	4 
> Dec 2001 19:48:22 -0000	1.1
> +++ jakarta-
> commons/digester/src/test/org/apache/commons/digester/xmlrules/test.xml	5 
> Jul 2002 01:24:19 -0000
> @@ -5,6 +5,10 @@
>      <bar>
>        <foo value="foo2"/>
>      </bar>
> +    <call-method-rule-tests value="cmr1">
> +      <longValue>555</longValue>
> +      <defaultParamType>somestringvalue</defaultParamType>
> +    </call-method-rule-tests>
>    </foo>
>    <baz value="baz2"/>
>    <foo value="foo3">
> Index: jakarta-
> commons/digester/src/test/org/apache/commons/digester/xmlrules/testrules.
> xml
> ===================================================================
> RCS file: /home/cvspublic/jakarta-
> commons/digester/src/test/org/apache/commons/digester/xmlrules/testrules.
> xml,v
> retrieving revision 1.1
> diff -u -r1.1 testrules.xml
> --- jakarta-
> commons/digester/src/test/org/apache/commons/digester/xmlrules/testrules.
> xml	4 Dec 2001 19:48:22 -0000	1.1
> +++ jakarta-
> commons/digester/src/test/org/apache/commons/digester/xmlrules/testrules.
> xml	5 Jul 2002 01:24:20 -0000
> @@ -6,5 +6,9 @@
>  	  <set-properties-rule/>
>  	  <include 
> path="org/apache/commons/digester/xmlrules/testrulesinclude.xml"/>
>      <include 
> class="org.apache.commons.digester.xmlrules.TestDigesterRulesSource"/>
> +    <pattern value="call-method-rule-tests">
> +       <call-method-rule pattern="longValue" methodname="setLongValue" 
> paramcount="0" paramtypes="java.lang.Long"/>
> +        <call-method-rule pattern="defaultParamType" 
> methodname="setStringValue" paramcount="0"/>
> +     </pattern>
>    </pattern>
>  </digester-rules>
>
> --
> To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.
> org>
> For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.
> org>


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


Mime
View raw message