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 18:26:14 GMT
rdonkin     2002/07/08 11:26:14

  Modified:    digester/src/java/org/apache/commons/digester/xmlrules
                        DigesterRuleParser.java digester-rules.dtd
               digester/src/test/org/apache/commons/digester Employee.java
                        RuleTestCase.java Test5.xml
               digester/src/test/org/apache/commons/digester/xmlrules
                        DigesterLoaderTest.java TestObject.java test.xml
                        testrules.xml
  Log:
  Applied patch provided by Mike Flester. This patch extends the functionality provided by
the xmlrules to allow paramtypes to be passed in.
  
  Revision  Changes    Path
  1.4       +17 -2     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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DigesterRuleParser.java	9 Jan 2002 20:22:50 -0000	1.3
  +++ DigesterRuleParser.java	8 Jul 2002 18:26:13 -0000	1.4
  @@ -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;
           }
       }
  
  
  
  1.2       +3 -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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- digester-rules.dtd	4 Dec 2001 19:49:36 -0000	1.1
  +++ digester-rules.dtd	8 Jul 2002 18:26:13 -0000	1.2
  @@ -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>
  
  
  
  1.4       +16 -3     jakarta-commons/digester/src/test/org/apache/commons/digester/Employee.java
  
  Index: Employee.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/test/org/apache/commons/digester/Employee.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Employee.java	23 Jan 2002 22:38:01 -0000	1.3
  +++ Employee.java	8 Jul 2002 18:26:13 -0000	1.4
  @@ -122,6 +122,19 @@
           this.lastName = lastName;
       }
   
  +    // this is to allow testing of primitive convertion 
  +    private int age;
  +    
  +    public int getAge()
  +    {
  +        return age;
  +    }
  +    
  +    public void setAge(int age)
  +    {
  +        this.age = age;
  +    }
  +
       public String toString() {
           StringBuffer sb = new StringBuffer("Employee[");
           sb.append("firstName=");
  
  
  
  1.14      +13 -6     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.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- RuleTestCase.java	5 Jun 2002 21:23:24 -0000	1.13
  +++ RuleTestCase.java	8 Jul 2002 18:26:13 -0000	1.14
  @@ -667,12 +667,18 @@
        
        */
       public void testCallMethod2() throws Exception {
  -        
  +        /* 
  +            I was preparing this test case to fix another bug
  +            i'll uncomment it once i've fixed it
  +            
           // Configure the digester as required
           digester.addObjectCreate("employee", Employee.class);
           // try all syntax permutations
           digester.addCallMethod("employee", "setLastName", 1, new String[] {"java.lang.String"});
           digester.addCallParam("employee/lastName", 0);
  +        // try out primitive convertion
  +        digester.addCallMethod("employee", "setAge", 1, new Class[] {Integer.class});
  +        digester.addCallParam("employee/age", 0);        
   
           // Parse our test input
           Object root1 = null;
  @@ -681,12 +687,13 @@
               root1 = digester.parse(getInputStream("Test5.xml"));
               Employee employee = (Employee) root1;
               assertEquals("Failed to call Employee.setLastName", "Last Name", employee.getLastName());

  +            assertEquals("Failed to call Employee.setAge", 21, employee.getAge()); 
               
           } catch (Throwable t) {
               // this means that the method can't be found and so the test fails
               fail("Digester threw Exception:  " + t);
           }
  -
  +        */
       }
   
   
  
  
  
  1.2       +1 -1      jakarta-commons/digester/src/test/org/apache/commons/digester/Test5.xml
  
  Index: Test5.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/test/org/apache/commons/digester/Test5.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Test5.xml	18 Apr 2002 21:23:44 -0000	1.1
  +++ Test5.xml	8 Jul 2002 18:26:14 -0000	1.2
  @@ -1 +1 @@
  -<?xml version="1.0"?>
<employee>
  <firstName> First Name  </firstName>
 <lastName>  Last Name </lastName>
  <address>
    <type>home</type>
   <street>Home Street</street>
    <city>Home City</city>
    <state>HS</state>
   <zipCode>HmZip</zipCode>
  </address>
  <address>
    <type>office</type>
   <street>Office Street</street>
    <city>Office City</city>
  
 <state>OS</state>
    <zipCode>OfZip</zipCode>
  </address>
</employee>
  \ No newline at end of file
  +<?xml version="1.0"?>
<employee>
  <firstName> First Name  </firstName>
 <lastName>  Last Name </lastName>
  <age>21</age>
  <address>
   <type>home</type>
    <street>Home Street</street>
    <city>Home
City</city>
    <state>HS</state>
    <zipCode>HmZip</zipCode>
 </address>
  <address>
    <type>office</type>
    <street>Office
Street</street>
    <city>Office City</city>
    <state>OS</state>
   <zipCode>OfZip</zipCode>
  </address>
</employee>
  \ No newline at end of file
  
  
  
  1.5       +10 -2     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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DigesterLoaderTest.java	23 Jan 2002 22:38:01 -0000	1.4
  +++ DigesterLoaderTest.java	8 Jul 2002 18:26:14 -0000	1.5
  @@ -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());
       }
   
       /**
  
  
  
  1.4       +13 -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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestObject.java	23 Jan 2002 22:38:01 -0000	1.3
  +++ TestObject.java	8 Jul 2002 18:26:14 -0000	1.4
  @@ -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) {
  +    }
  +
   }
  
  
  
  1.2       +4 -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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- test.xml	4 Dec 2001 19:48:22 -0000	1.1
  +++ test.xml	8 Jul 2002 18:26:14 -0000	1.2
  @@ -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">
  
  
  
  1.2       +4 -0      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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- testrules.xml	4 Dec 2001 19:48:22 -0000	1.1
  +++ testrules.xml	8 Jul 2002 18:26:14 -0000	1.2
  @@ -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>


Mime
View raw message