Author: germuska
Date: Wed May 25 18:48:57 2005
New Revision: 178565
URL: http://svn.apache.org/viewcvs?rev=178565&view=rev
Log:
Catch InvocationTargetException and throw its cause instead, except when the
cause is not an instance of Exception.
Modified:
jakarta/commons/proper/chain/trunk/src/java/org/apache/commons/chain/generic/DispatchCommand.java
Modified:
jakarta/commons/proper/chain/trunk/src/java/org/apache/commons/chain/generic/DispatchCommand.java
URL:
http://svn.apache.org/viewcvs/jakarta/commons/proper/chain/trunk/src/java/org/apache/commons/chain/generic/DispatchCommand.java?rev=178565&r1=178564&r2=178565&view=diff
==============================================================================
---
jakarta/commons/proper/chain/trunk/src/java/org/apache/commons/chain/generic/DispatchCommand.java
(original)
+++
jakarta/commons/proper/chain/trunk/src/java/org/apache/commons/chain/generic/DispatchCommand.java
Wed May 25 18:48:57 2005
@@ -2,6 +2,8 @@
import org.apache.commons.chain.Command;
import org.apache.commons.chain.Context;
+
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.WeakHashMap;
@@ -30,7 +32,11 @@
* returning a boolean value as interpreted by <code>evaluateResult</code>.
* @param context
* @return
- * @throws Exception
+ * @throws IllegalStateException if neither 'method' nor 'methodKey'
properties are defined
+ * @throws Exception if any is thrown by the invocation. Note that if
invoking the method
+ * results in an InvocationTargetException, the cause of that exception is
thrown instead of
+ * the exception itself, unless the cause is an <code>Error</code> or
other <code>Throwable</code>
+ * which is not an <code>Exception</code>.
*/
public boolean execute(Context context) throws Exception {
@@ -40,7 +46,12 @@
Method methodObject = extractMethod(context);
- return evaluateResult(methodObject.invoke(this,
getArguments(context)));
+ try {
+ return evaluateResult(methodObject.invoke(this,
getArguments(context)));
+ } catch (InvocationTargetException e) {
+ if (e instanceof Exception) throw (Exception) e.getCause();
+ throw e;
+ }
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]