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 RuleTestCase.java
Date Wed, 05 Jun 2002 21:23:24 GMT
rdonkin     2002/06/05 14:23:24

  Modified:    digester/src/java/org/apache/commons/digester
                        CallMethodRule.java
               digester/src/test/org/apache/commons/digester
                        RuleTestCase.java
  Log:
  Fixed bug with CallMethodRule introduced when constructors accepting the digester as a parameter
were depricated. CallMethodRule now waits until the digester is set before loading classes
from classnames
  
  Revision  Changes    Path
  1.17      +38 -13    jakarta-commons/digester/src/java/org/apache/commons/digester/CallMethodRule.java
  
  Index: CallMethodRule.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/CallMethodRule.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- CallMethodRule.java	18 Apr 2002 21:23:44 -0000	1.16
  +++ CallMethodRule.java	5 Jun 2002 21:23:23 -0000	1.17
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/CallMethodRule.java,v
1.16 2002/04/18 21:23:44 rdonkin Exp $
  - * $Revision: 1.16 $
  - * $Date: 2002/04/18 21:23:44 $
  + * $Header: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/CallMethodRule.java,v
1.17 2002/06/05 21:23:23 rdonkin Exp $
  + * $Revision: 1.17 $
  + * $Date: 2002/06/05 21:23:23 $
    *
    * ====================================================================
    *
  @@ -82,7 +82,7 @@
    *
    * @author Craig McClanahan
    * @author Scott Sanders
  - * @version $Revision: 1.16 $ $Date: 2002/04/18 21:23:44 $
  + * @version $Revision: 1.17 $ $Date: 2002/06/05 21:23:23 $
    */
   
   public class CallMethodRule extends Rule {
  @@ -223,14 +223,11 @@
                   this.paramTypes[i] = "abc".getClass();
               }
           } else {
  -            this.paramTypes = new Class[paramTypes.length];
  -            for (int i = 0; i < this.paramTypes.length; i++) {
  -                try {
  -                    this.paramTypes[i] =
  -                            digester.getClassLoader().loadClass(paramTypes[i]);
  -                } catch (ClassNotFoundException e) {
  -                    this.paramTypes[i] = null; // Will cause NPE later
  -                }
  +            // copy the parameter class names into an array
  +            // the classes will be loaded when the digester is set 
  +            this.paramClassNames = new String[paramTypes.length];
  +            for (int i = 0; i < this.paramClassNames.length; i++) {
  +                this.paramClassNames[i] = paramTypes[i];
               }
           }
   
  @@ -303,9 +300,37 @@
        */
       protected Class paramTypes[] = null;
   
  -
  +    /**
  +     * The names of the classes of the parameters to be collected.
  +     * This attribute allows creation of the classes to be postponed until the digester
is set.
  +     */
  +    private String paramClassNames[] = null;
  +    
       // --------------------------------------------------------- Public Methods
   
  +    /**
  +     * Set the associated digester.
  +     * If needed, this class loads the parameter classes from their names.
  +     */
  +    public void setDigester(Digester digester)
  +    {
  +        // call superclass
  +        super.setDigester(digester);
  +        // if necessary, load parameter classes
  +        if (this.paramClassNames != null) {
  +            this.paramTypes = new Class[paramClassNames.length];
  +            for (int i = 0; i < this.paramClassNames.length; i++) {
  +                try {
  +                    this.paramTypes[i] =
  +                            digester.getClassLoader().loadClass(this.paramClassNames[i]);
  +                } catch (ClassNotFoundException e) {
  +                    // use the digester log
  +                    digester.getLogger().error("(CallMethodRule) Cannot load class " +
this.paramClassNames[i], e);
  +                    this.paramTypes[i] = null; // Will cause NPE later
  +                }
  +            }
  +        }
  +    }
   
       /**
        * Process the start of this element.
  
  
  
  1.13      +33 -5     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.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- RuleTestCase.java	18 Apr 2002 21:23:44 -0000	1.12
  +++ RuleTestCase.java	5 Jun 2002 21:23:24 -0000	1.13
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/digester/src/test/org/apache/commons/digester/RuleTestCase.java,v
1.12 2002/04/18 21:23:44 rdonkin Exp $
  - * $Revision: 1.12 $
  - * $Date: 2002/04/18 21:23:44 $
  + * $Header: /home/cvs/jakarta-commons/digester/src/test/org/apache/commons/digester/RuleTestCase.java,v
1.13 2002/06/05 21:23:24 rdonkin Exp $
  + * $Revision: 1.13 $
  + * $Date: 2002/06/05 21:23:24 $
    *
    * ====================================================================
    *
  @@ -79,7 +79,7 @@
    *
    * @author Craig R. McClanahan
    * @author Janek Bogucki
  - * @version $Revision: 1.12 $ $Date: 2002/04/18 21:23:44 $
  + * @version $Revision: 1.13 $ $Date: 2002/06/05 21:23:24 $
    */
   
   public class RuleTestCase extends TestCase {
  @@ -660,6 +660,35 @@
   
       }
   
  +    /**
  +     * Test method calls with the CallMethodRule rule. It should be possible
  +     * to call any accessible method of the object on the top of the stack,
  +     * even methods with no arguments.
  +     
  +     */
  +    public void testCallMethod2() throws Exception {
  +        
  +        // 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);
  +
  +        // Parse our test input
  +        Object root1 = null;
  +        try {
  +            // an exception will be thrown if the method can't be found
  +            root1 = digester.parse(getInputStream("Test5.xml"));
  +            Employee employee = (Employee) root1;
  +            assertEquals("Failed to call Employee.setLastName", "Last Name", employee.getLastName());

  +            
  +        } catch (Throwable t) {
  +            // this means that the method can't be found and so the test fails
  +            fail("Digester threw Exception:  " + t);
  +        }
  +
  +    }
  +
   
       // ------------------------------------------------ Utility Support Methods
   
  @@ -724,5 +753,4 @@
                   office.getZipCode());
   
       }
  -
   }
  
  
  

--
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