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/test/org/apache/commons/digester/xmlrules DigesterLoaderTest.java TestObject.java test.xml testrules.xml
Date Mon, 08 Jul 2002 21:25:30 GMT
rdonkin     2002/07/08 14:25:30

  Modified:    digester/src/java/org/apache/commons/digester/xmlrules
                        DigesterRuleParser.java digester-rules.dtd
               digester/src/test/org/apache/commons/digester
                        RuleTestCase.java
               digester/src/test/org/apache/commons/digester/xmlrules
                        DigesterLoaderTest.java TestObject.java test.xml
                        testrules.xml
  Added:       digester/src/test/org/apache/commons/digester Test6.xml
  Log:
  FIXED BUG 8244. This provides support for calls to empty methods for digestion specified
by xmlrules (rather than programmatically). Michael Marrotte reported the bug and provided
a patch. I prefered to commit an alternate solution for stylistic reasons.
  
  Revision  Changes    Path
  1.5       +23 -12    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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DigesterRuleParser.java	8 Jul 2002 18:26:13 -0000	1.4
  +++ DigesterRuleParser.java	8 Jul 2002 21:25:29 -0000	1.5
  @@ -489,21 +489,32 @@
       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");
  -            String paramTypesAttr = attributes.getValue("paramtypes");
  -            if (paramTypesAttr == null || paramTypesAttr.length() == 0) {
  -                callMethodRule = new CallMethodRule(targetDigester, methodName,
  -                                                    paramCount);
  +            if (attributes.getValue("paramcount") == null) {
  +                // call against empty method
  +                callMethodRule = new CallMethodRule(methodName);
  +                
               } 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());
  +                int paramCount = Integer.parseInt(attributes.getValue("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]));
                   }
  -                callMethodRule = new CallMethodRule(targetDigester, methodName, paramCount,
(String[])paramTypes.toArray(new String[0]));
               }
               return callMethodRule;
           }
  
  
  
  1.3       +2 -2      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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- digester-rules.dtd	8 Jul 2002 18:26:13 -0000	1.2
  +++ digester-rules.dtd	8 Jul 2002 21:25:29 -0000	1.3
  @@ -71,7 +71,7 @@
   <!ATTLIST call-method-rule
       pattern    CDATA #IMPLIED
       methodname CDATA #REQUIRED
  -    paramcount CDATA #REQUIRED
  +    paramcount CDATA #IMPLIED
       paramtypes CDATA #IMPLIED>
   
   <!-- CallParamRule -->
  
  
  
  1.15      +5 -4      jakarta-commons/digester/src/test/org/apache/commons/digester/RuleTestCase.java
  
  Index: RuleTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/test/org/apache/commons/digester/RuleTestCase.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- RuleTestCase.java	8 Jul 2002 18:26:13 -0000	1.14
  +++ RuleTestCase.java	8 Jul 2002 21:25:30 -0000	1.15
  @@ -67,6 +67,7 @@
   import java.io.InputStream;
   
   import java.util.ArrayList;
  +import java.util.Hashtable;
   
   import junit.framework.Test;
   import junit.framework.TestCase;
  
  
  
  1.1                  jakarta-commons/digester/src/test/org/apache/commons/digester/Test6.xml
  
  Index: Test6.xml
  ===================================================================
  <?xml version="1.0"?>
  <toplevel>
  	<element>
  		<field1>Value 1</field1>
  		<field2>Value 2</field2>
  	</element>
  	<element>
  		<field1>Value 3</field1>
  		<field2>Value 4</field2>
  	</element>
  </toplevel>
  
  
  1.6       +4 -0      jakarta-commons/digester/src/test/org/apache/commons/digester/xmlrules/DigesterLoaderTest.java
  
  Index: DigesterLoaderTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/test/org/apache/commons/digester/xmlrules/DigesterLoaderTest.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DigesterLoaderTest.java	8 Jul 2002 18:26:14 -0000	1.5
  +++ DigesterLoaderTest.java	8 Jul 2002 21:25:30 -0000	1.6
  @@ -146,7 +146,11 @@
           if (!(root instanceof ArrayList)) {
               fail("Unexpected object returned from DigesterLoader. Expected ArrayList; got
" + root.getClass().getName());
           }
  +        ArrayList list = (ArrayList) root;
           assertEquals(root.toString(), "[foo1 baz1 foo2, foo3 foo4]");
  +        assertEquals("Wrong number of classes created", 2 , list.size());
  +        assertEquals("Pushed first", true , ((TestObject)list.get(0)).isPushed());
  +        assertEquals("Didn't push second", false , ((TestObject)list.get(1)).isPushed());
       }
   
   
  
  
  
  1.5       +9 -0      jakarta-commons/digester/src/test/org/apache/commons/digester/xmlrules/TestObject.java
  
  Index: TestObject.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/test/org/apache/commons/digester/xmlrules/TestObject.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestObject.java	8 Jul 2002 18:26:14 -0000	1.4
  +++ TestObject.java	8 Jul 2002 21:25:30 -0000	1.5
  @@ -74,6 +74,8 @@
       private String value = "";
       private Long longValue = new Long(-1L);
   
  +    private boolean pushed = false;
  +    
       public TestObject() {
       }
   
  @@ -106,4 +108,11 @@
       public void setStringValue(String val) {
       }
   
  +    public boolean isPushed() {
  +        return pushed;
  +    }
  +    
  +    public void push() {
  +        pushed = true;
  +    }
   }
  
  
  
  1.3       +1 -0      jakarta-commons/digester/src/test/org/apache/commons/digester/xmlrules/test.xml
  
  Index: test.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/test/org/apache/commons/digester/xmlrules/test.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- test.xml	8 Jul 2002 18:26:14 -0000	1.2
  +++ test.xml	8 Jul 2002 21:25:30 -0000	1.3
  @@ -8,6 +8,7 @@
       <call-method-rule-tests value="cmr1">
         <longValue>555</longValue>
         <defaultParamType>somestringvalue</defaultParamType>
  +      <pushIt/>
       </call-method-rule-tests>
     </foo>
     <baz value="baz2"/>
  
  
  
  1.3       +2 -1      jakarta-commons/digester/src/test/org/apache/commons/digester/xmlrules/testrules.xml
  
  Index: testrules.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/test/org/apache/commons/digester/xmlrules/testrules.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- testrules.xml	8 Jul 2002 18:26:14 -0000	1.2
  +++ testrules.xml	8 Jul 2002 21:25:30 -0000	1.3
  @@ -7,8 +7,9 @@
   	  <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="longValue" methodname="setLongValue" paramcount="0"
paramtypes="java.lang.Long"/>
           <call-method-rule pattern="defaultParamType" methodname="setStringValue" paramcount="0"/>
  +        <call-method-rule pattern="pushIt" methodname="push"/>
        </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>


Mime
View raw message