You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by rd...@apache.org on 2003/07/13 17:57:36 UTC

cvs commit: jakarta-commons/digester/src/test/org/apache/commons/digester CallMethodRuleTestCase.java ParamBean.java

rdonkin     2003/07/13 08:57:36

  Modified:    digester/src/java/org/apache/commons/digester
                        CallMethodRule.java
               digester/src/test/org/apache/commons/digester
                        CallMethodRuleTestCase.java ParamBean.java
  Log:
  Added method to allow subclasses to process result returned by method call.
  
  Revision  Changes    Path
  1.24      +18 -6     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.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- CallMethodRule.java	24 Apr 2003 09:30:24 -0000	1.23
  +++ CallMethodRule.java	13 Jul 2003 15:57:36 -0000	1.24
  @@ -495,16 +495,19 @@
               digester.log.debug(sb.toString());
           }
           
  +        Object result = null;
           if (useExactMatch) {
               // invoke using exact match
  -            MethodUtils.invokeExactMethod(top, methodName,
  +            result = MethodUtils.invokeExactMethod(top, methodName,
                   paramValues, paramTypes);
                   
           } else {
               // invoke using fuzzier match
  -            MethodUtils.invokeMethod(top, methodName,
  +            result = MethodUtils.invokeMethod(top, methodName,
                   paramValues, paramTypes);            
           }
  +        
  +        processMethodCallResult(result);
       }
   
   
  @@ -517,6 +520,15 @@
   
       }
   
  +    /**
  +     * Subclasses may override this method to perform additional processing of the 
  +     * invoked method's result.
  +     *
  +     * @param result the Object returned by the method invoked, possibly null
  +     */
  +    protected void processMethodCallResult(Object result) {
  +        // do nothing
  +    }
   
       /**
        * Render a printable version of this Rule.
  
  
  
  1.8       +38 -0     jakarta-commons/digester/src/test/org/apache/commons/digester/CallMethodRuleTestCase.java
  
  Index: CallMethodRuleTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/test/org/apache/commons/digester/CallMethodRuleTestCase.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- CallMethodRuleTestCase.java	17 Apr 2003 11:08:16 -0000	1.7
  +++ CallMethodRuleTestCase.java	13 Jul 2003 15:57:36 -0000	1.8
  @@ -527,6 +527,44 @@
           bean = (NamedBean) list.get(1);
           assertEquals("Wrong name (5)", "Deepest", bean.getName());
       }
  +    
  +    public void testProcessingHook() throws Exception {
  +        
  +        class TestCallMethodRule extends CallMethodRule {
  +            Object result;
  +            TestCallMethodRule(String methodName, int paramCount)
  +            {
  +                super(methodName, paramCount);
  +            }
  +            protected void processMethodCallResult(Object result) {
  +                this.result = result;
  +            }
  +        }
  +    
  +        StringReader reader = new StringReader(
  +            "<?xml version='1.0' ?><root>"
  +            + "<param class='float' coolness='false'>90</param></root>");
  +        
  +            
  +        Digester digester = new Digester();
  +        //SimpleLog log = new SimpleLog("{testTwoCalls:Digester]");
  +        //log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
  +        //digester.setLogger(log);
  +        
  +        digester.addObjectCreate( "root/param", ParamBean.class );
  +        digester.addSetNext( "root/param", "add" );
  +        TestCallMethodRule rule = new TestCallMethodRule( "setThisAndThat" , 2 );
  +        digester.addRule( "root/param", rule );
  +        digester.addCallParam( "root/param", 0, "class" );
  +        digester.addCallParam( "root/param", 1, "coolness" );
  +        
  +        ArrayList list = new ArrayList();
  +        digester.push(list);
  +        digester.parse(reader);
  +    
  +        assertEquals("Wrong number of objects created", 1, list.size());
  +        assertEquals("Result not passed into hook", "The Other", rule.result);
  +    }
   
       // ------------------------------------------------ Utility Support Methods
   
  
  
  
  1.2       +5 -4      jakarta-commons/digester/src/test/org/apache/commons/digester/ParamBean.java
  
  Index: ParamBean.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/test/org/apache/commons/digester/ParamBean.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ParamBean.java	17 Apr 2003 11:08:17 -0000	1.1
  +++ ParamBean.java	13 Jul 2003 15:57:36 -0000	1.2
  @@ -92,8 +92,9 @@
           return that;
       }
       
  -    public void setThisAndThat(String _this, String that) {
  +    public String setThisAndThat(String _this, String that) {
           this._this = _this;
           this.that = that;
  +        return "The Other";
       }
   }
  
  
  

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