Author: hlship
Date: Fri Feb 19 18:53:12 2010
New Revision: 911909

URL: http://svn.apache.org/viewvc?rev=911909&view=rev
Log:
Add rethrow() to Invocation, which will check for a thrown (checked) exception 
and re-throw it wrapped inside a RuntimeException

Modified:
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AbstractComponentMethodInvocation.java
    
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/Invocation.java
    
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/AbstractInvocation.java

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AbstractComponentMethodInvocation.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AbstractComponentMethodInvocation.java?rev=911909&r1=911908&r2=911909&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AbstractComponentMethodInvocation.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/AbstractComponentMethodInvocation.java
 Fri Feb 19 18:53:12 2010
@@ -96,6 +96,12 @@
         return thrown != null;
     }
 
+    public void rethrow()
+    {
+        if (thrown != null)
+            throw new RuntimeException(thrown);
+    }
+
     public <T extends Throwable> T getThrown(Class<T> throwableClass)
     {
         if (throwableClass.isInstance(thrown))
@@ -116,8 +122,8 @@
         }
 
         throw new IllegalArgumentException(String.format(
-                "Exception class %s is not a declared exception type for 
method %s().", thrown
-                        .getClass(), info.getMethodName()));
+                "Exception class %s is not a declared exception type for 
method %s().", thrown.getClass(), info
+                        .getMethodName()));
     }
 
     public Object getResult()
@@ -131,11 +137,9 @@
         {
             Class expectedType = info.getEffectiveResultType();
 
-            if (!expectedType.isInstance(newResult)) { throw new 
IllegalArgumentException(
-                    String
-                            .format(
-                                    "Invalid result value (%s) does not match 
return type %s for method %s.",
-                                    newResult, expectedType.getName(), 
info.getMethodName())); }
+            if (!expectedType.isInstance(newResult)) { throw new 
IllegalArgumentException(String.format(
+                    "Invalid result value (%s) does not match return type %s 
for method %s.", newResult, expectedType
+                            .getName(), info.getMethodName())); }
         }
 
         result = newResult;

Modified: 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/Invocation.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/Invocation.java?rev=911909&r1=911908&r2=911909&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/Invocation.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/Invocation.java
 Fri Feb 19 18:53:12 2010
@@ -4,7 +4,7 @@
 // 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
+// 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,
@@ -47,14 +47,16 @@
 
     /**
      * Replaces a parameter in the invocation.
-     *
-     * @param index        of parameter to update
-     * @param newParameter new parameter value (may be null)
+     * 
+     * @param index
+     *            of parameter to update
+     * @param newParameter
+     *            new parameter value (may be null)
      */
     void override(int index, Object newParameter);
 
     /**
-     * Proceed with the invocation of the advised method.  If the invocation 
results in a <em>runtime</em> exception,
+     * Proceed with the invocation of the advised method. If the invocation 
results in a <em>runtime</em> exception,
      * that is thrown. A checked exception is detected by invoking {...@link 
#isFail()}.
      */
     void proceed();
@@ -65,21 +67,31 @@
     boolean isFail();
 
     /**
+     * If the invocation failed (with a checked exception), then rethrow the 
exception wrapped in a
+     * RuntimeException.
+     * 
+     * @since 5.2.0
+     */
+    void rethrow();
+
+    /**
      * After invoking {...@link #proceed()}, used to obtain the thrown 
(checked) exception, if assignable to the provided
      * type.
-     *
-     * @param throwableClass the type of exception to match
+     * 
+     * @param throwableClass
+     *            the type of exception to match
      * @return the exception, if the proceeded invocation threw a checked 
exception, and the exception is assignable to
-     *         the provided type.  In other cases, null is returned.
+     *         the provided type. In other cases, null is returned.
      */
     <T extends Throwable> T getThrown(Class<T> throwableClass);
 
     /**
      * Overrides the thrown exception. The passed exception should be a 
checked exception of the method. Note that for
      * runtime exceptions, or even {...@link Error}s, those can just be 
thrown. Sets the fail flag.
-     *
+     * 
      * @param thrown
-     * @throws IllegalArgumentException if thrown is null, or not a declared 
exception of the method
+     * @throws IllegalArgumentException
+     *             if thrown is null, or not a declared exception of the method
      */
     void overrideThrown(Exception thrown);
 

Modified: 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/AbstractInvocation.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/AbstractInvocation.java?rev=911909&r1=911908&r2=911909&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/AbstractInvocation.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/AbstractInvocation.java
 Fri Feb 19 18:53:12 2010
@@ -4,7 +4,7 @@
 // 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
+// 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,
@@ -73,11 +73,18 @@
         return thrown != null;
     }
 
+    public void rethrow()
+    {
+        if (thrown != null)
+            throw new RuntimeException(thrown);
+    }
+
     public <T extends Throwable> T getThrown(Class<T> throwableClass)
     {
         Defense.notNull(throwableClass, "throwableClass");
 
-        if (throwableClass.isInstance(thrown)) return 
throwableClass.cast(thrown);
+        if (throwableClass.isInstance(thrown))
+            return throwableClass.cast(thrown);
 
         return null;
     }
@@ -96,7 +103,7 @@
         }
 
         throw new IllegalArgumentException(String.format("Exception %s is not 
a declared exception of method %s.",
-                                                         
thrown.getClass().getName(), method));
+                thrown.getClass().getName(), method));
     }
 
     public Object getResult()


Reply via email to