dion        2004/08/11 21:25:43

  Modified:    jelly/src/test/org/apache/commons/jelly/core
                        testInvokeTag.jelly TestInvokeStaticTag.java
                        TestInvokeTag.java testInvokeStaticTag.jelly
               jelly/src/java/org/apache/commons/jelly/tags/core
                        InvokeStaticTag.java InvokeTag.java
  Added:       jelly/src/test/org/apache/commons/jelly/core
                        ExceptionBean.java
  Log:
  Apply JELLY-116.
  
  Revision  Changes    Path
  1.4       +19 -0     
jakarta-commons/jelly/src/test/org/apache/commons/jelly/core/testInvokeTag.jelly
  
  Index: testInvokeTag.jelly
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/jelly/src/test/org/apache/commons/jelly/core/testInvokeTag.jelly,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- testInvokeTag.jelly       25 Feb 2004 05:09:57 -0000      1.3
  +++ testInvokeTag.jelly       12 Aug 2004 04:25:42 -0000      1.4
  @@ -59,5 +59,24 @@
               <j:arg><j:invoke on="${list}" method="get" var="argtwo"><j:arg 
type="int" value="1"/></j:invoke></j:arg>
           </j:new>
       </j:if>
  +    
  +    <j:if test="${test.invokeThatThrowsException}">
  +        <j:set var="exceptionMessage" value="method threw an exception"/>
  +        <j:new var="exceptionBean" 
className="org.apache.commons.jelly.core.ExceptionBean"/>
  +        <j:catch var="jellyException">
  +             <j:invoke on="${exceptionBean}" method="instanceMethod" 
exceptionVar="exceptionThrown">
  +                     <j:arg value="${exceptionMessage}"/>
  +             </j:invoke>
  +        </j:catch>
  +    </j:if>
  +    <j:if test="${test.invokeThatDoesNotHandleException}">
  +        <j:set var="exceptionMessage" value="method threw an exception"/>
  +        <j:new var="exceptionBean" 
className="org.apache.commons.jelly.core.ExceptionBean"/>
  +        <j:catch var="jellyException">
  +             <j:invoke on="${exceptionBean}" method="instanceMethod">
  +                     <j:arg value="${exceptionMessage}"/>
  +             </j:invoke>
  +        </j:catch>
  +    </j:if>
   
   </j:jelly>
  
  
  
  1.5       +30 -1     
jakarta-commons/jelly/src/test/org/apache/commons/jelly/core/TestInvokeStaticTag.java
  
  Index: TestInvokeStaticTag.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/jelly/src/test/org/apache/commons/jelly/core/TestInvokeStaticTag.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestInvokeStaticTag.java  24 Feb 2004 14:19:58 -0000      1.4
  +++ TestInvokeStaticTag.java  12 Aug 2004 04:25:42 -0000      1.5
  @@ -99,4 +99,33 @@
           assertTrue( getJellyContext().getVariable("message").equals("Is not Jelly 
the coolest thing you have ever used?") );
           
       }
  +    
  +    public void testInvokeThatThrowsException() throws Exception {
  +        setUpScript( "testInvokeStaticTag.jelly" );
  +        Script script = getJelly().compileScript();
  +        
getJellyContext().setVariable("test.invokeThatThrowsException",Boolean.TRUE);
  +        script.run(getJellyContext(),getXMLOutput());
  +        String exceptionMessage = (String) 
getJellyContext().getVariable("exceptionMessage");
  +        assertNotNull( exceptionMessage );
  +        Exception jellyException = (Exception) 
getJellyContext().getVariable("jellyException");
  +        assertNull( jellyException );
  +        Exception exception = (Exception) 
getJellyContext().getVariable("exceptionThrown");
  +        assertNotNull( exception );
  +        assertEquals( exceptionMessage, exception.getMessage() );
  +    }
  +    
  +    public void testInvokeThatDoesNotHandleException() throws Exception {
  +        setUpScript( "testInvokeStaticTag.jelly" );
  +        Script script = getJelly().compileScript();
  +        
getJellyContext().setVariable("test.invokeThatDoesNotHandleException",Boolean.TRUE);
  +        script.run(getJellyContext(),getXMLOutput());
  +        String exceptionMessage = (String) 
getJellyContext().getVariable("exceptionMessage");
  +        assertNotNull( exceptionMessage );
  +        Exception jellyException = (Exception) 
getJellyContext().getVariable("jellyException");
  +        assertNotNull( jellyException );
  +        assertTrue( "messages are the same", ! 
exceptionMessage.equals(jellyException.getMessage()) );
  +        assertTrue( "exception '" + jellyException.getMessage() + "' does not ends 
with '" +
  +                     exceptionMessage+"'", 
jellyException.getMessage().endsWith(exceptionMessage) );
  +    }
  +    
   }
  
  
  
  1.5       +32 -1     
jakarta-commons/jelly/src/test/org/apache/commons/jelly/core/TestInvokeTag.java
  
  Index: TestInvokeTag.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/jelly/src/test/org/apache/commons/jelly/core/TestInvokeTag.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestInvokeTag.java        24 Feb 2004 14:19:58 -0000      1.4
  +++ TestInvokeTag.java        12 Aug 2004 04:25:42 -0000      1.5
  @@ -93,5 +93,36 @@
           assertNotNull(getJellyContext().getVariable("argtwo"));
           assertEquals("Chicago",getJellyContext().getVariable("argtwo"));
       }
  +    
  +    public void testInvokeThatThrowsException() throws Exception {
  +        setUpScript("testInvokeTag.jelly");
  +        Script script = getJelly().compileScript();
  +        
getJellyContext().setVariable("test.invokeThatThrowsException",Boolean.TRUE);
  +        script.run(getJellyContext(),getXMLOutput());
  +        String exceptionMessage = (String) 
getJellyContext().getVariable("exceptionMessage");
  +        assertNotNull( exceptionMessage );
  +        assertNotNull( getJellyContext().getVariable("exceptionBean"));
  +        Exception jellyException = (Exception) 
getJellyContext().getVariable("jellyException");
  +        assertNull( jellyException );
  +        Exception exception = (Exception) 
getJellyContext().getVariable("exceptionThrown");
  +        assertNotNull( exception );
  +        assertEquals( exceptionMessage, exception.getMessage() );
  +    }
  +    
  +    public void testInvokeThatDoesNotHandleException() throws Exception {
  +        setUpScript("testInvokeTag.jelly");
  +        Script script = getJelly().compileScript();
  +        
getJellyContext().setVariable("test.invokeThatDoesNotHandleException",Boolean.TRUE);
  +        script.run(getJellyContext(),getXMLOutput());
  +        String exceptionMessage = (String) 
getJellyContext().getVariable("exceptionMessage");
  +        assertNotNull( exceptionMessage );
  +        assertNotNull( getJellyContext().getVariable("exceptionBean"));
  +        Exception jellyException = (Exception) 
getJellyContext().getVariable("jellyException");
  +        assertNotNull( jellyException );
  +        assertTrue( "messages are the same", ! 
exceptionMessage.equals(jellyException.getMessage()) );
  +        assertTrue( "exception '" + jellyException.getMessage() + "' does not ends 
with '" +
  +                     exceptionMessage+"'", 
jellyException.getMessage().endsWith(exceptionMessage) );
  +    }
  +    
   
   }
  
  
  
  1.3       +19 -0     
jakarta-commons/jelly/src/test/org/apache/commons/jelly/core/testInvokeStaticTag.jelly
  
  Index: testInvokeStaticTag.jelly
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/jelly/src/test/org/apache/commons/jelly/core/testInvokeStaticTag.jelly,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- testInvokeStaticTag.jelly 25 Feb 2004 05:09:57 -0000      1.2
  +++ testInvokeStaticTag.jelly 12 Aug 2004 04:25:42 -0000      1.3
  @@ -35,5 +35,24 @@
               <j:arg value="${args}" />

           </j:invokeStatic>

       </j:if>

  +    

  +    <j:if test="${test.invokeThatThrowsException}">

  +        <j:set var="exceptionMessage" value="method threw an exception"/>

  +        <j:catch var="jellyException">

  +             <j:invokeStatic 
className="org.apache.commons.jelly.core.ExceptionBean" method="staticMethod" 
exceptionVar="exceptionThrown">

  +                     <j:arg value="${exceptionMessage}"/>

  +             </j:invokeStatic>

  +        </j:catch>

  +    </j:if>

  +    <j:if test="${test.invokeThatDoesNotHandleException}">

  +        <j:set var="exceptionMessage" value="method threw an exception"/>

  +        <j:catch var="jellyException">

  +             <j:invokeStatic 
className="org.apache.commons.jelly.core.ExceptionBean" method="staticMethod">

  +                     <j:arg value="${exceptionMessage}"/>

  +             </j:invokeStatic>

  +        </j:catch>

  +    </j:if>

  +    

  +    

   </j:jelly>

   

  
  
  
  1.1                  
jakarta-commons/jelly/src/test/org/apache/commons/jelly/core/ExceptionBean.java
  
  Index: ExceptionBean.java
  ===================================================================
  /*
   * Copyright 2002,2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.commons.jelly.core;
  
  /** 
   * A sample bean that throws exceptions when its methods are invoked.
   */
  public class ExceptionBean {
          
      public ExceptionBean() {
      }
          
      public void instanceMethod( String msg) throws Exception {
        throw new Exception( msg ); 
      }
  
      public static void staticMethod( String msg) throws Exception {
        throw new Exception( msg ); 
      }
  
  }
  
  
  
  1.6       +17 -2     
jakarta-commons/jelly/src/java/org/apache/commons/jelly/tags/core/InvokeStaticTag.java
  
  Index: InvokeStaticTag.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/jelly/src/java/org/apache/commons/jelly/tags/core/InvokeStaticTag.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- InvokeStaticTag.java      24 Feb 2004 14:10:40 -0000      1.5
  +++ InvokeStaticTag.java      12 Aug 2004 04:25:43 -0000      1.6
  @@ -49,6 +49,9 @@
       /** the variable exported */
       private String var;
       
  +    /** the variable where the method's exception is exported */
  +    private String exceptionVar;
  +    
       /** the method to invoke */
       private String methodName;
       
  @@ -70,6 +73,13 @@
           this.var = var;
       }
       
  +    /** Sets the name of a variable that exports the exception thrown by
  +     * the method's invocation (if any)
  +     */
  +    public void setExceptionVar(String var) {
  +        this.exceptionVar = var;
  +    }
  +    
       /**
        * Sets the name of the method to invoke
        *
  @@ -131,7 +141,12 @@
               throw createLoadClassFailedException(e);
           } 
           catch (InvocationTargetException e) {
  -            throw createLoadClassFailedException(e);
  +             if(null != exceptionVar) {
  +                     context.setVariable(exceptionVar,e.getTargetException());
  +             } else {
  +                     throw new JellyTagException("method " + methodName + 
  +                     " threw exception: "+ e.getTargetException().getMessage(), e );
  +             }
           }
           finally {
               paramTypes.clear();
  
  
  
  1.7       +21 -5     
jakarta-commons/jelly/src/java/org/apache/commons/jelly/tags/core/InvokeTag.java
  
  Index: InvokeTag.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/jelly/src/java/org/apache/commons/jelly/tags/core/InvokeTag.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- InvokeTag.java    24 Feb 2004 14:10:38 -0000      1.6
  +++ InvokeTag.java    12 Aug 2004 04:25:43 -0000      1.7
  @@ -35,6 +35,9 @@
       /** the variable exported */
       private String var;
       
  +    /** the variable where the method's exception is exported */
  +    private String exceptionVar;
  +    
       /** the method to invoke */
       private String methodName;
       
  @@ -52,6 +55,13 @@
           this.var = var;
       }
       
  +    /** Sets the name of a variable that exports the exception thrown by
  +     * the method's invocation (if any)
  +     */
  +    public void setExceptionVar(String var) {
  +        this.exceptionVar = var;
  +    }
  +    
       public void setMethod(String method) {
           this.methodName = method;
       }
  @@ -91,11 +101,17 @@
               throw new JellyTagException(e);
           } 
           catch (InvocationTargetException e) {
  -            throw new JellyTagException(e);
  +             if(null != exceptionVar) {
  +                     context.setVariable(exceptionVar,e.getTargetException());
  +             } else {
  +                     throw new JellyTagException("method " + methodName + 
  +                     " threw exception: "+ e.getTargetException().getMessage(), e );
  +             }
  +        }
  +        finally {
  +             paramTypes.clear();
  +             paramValues.clear();
           }
  -        
  -        paramTypes.clear();
  -        paramValues.clear();
           
           ArgTag parentArg = (ArgTag)(findAncestorWithClass(ArgTag.class));
           if(null != parentArg) {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to