geirm 01/04/18 05:25:29
Modified: src/java/org/apache/velocity/runtime/parser/node
ASTIdentifier.java ASTMethod.java
AbstractExecutor.java GetExecutor.java
PropertyExecutor.java
Log:
Added support for MethodInvocationException error propogation. I forgot
that when it was done for ASTMethod. Whoops. Sorry.
Also, added log msg for ASTMethod.execute() so it didn't eat
non-ITE exceptions.
Revision Changes Path
1.10 +31 -7
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java
Index: ASTIdentifier.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- ASTIdentifier.java 2001/03/19 18:33:10 1.9
+++ ASTIdentifier.java 2001/04/18 12:25:27 1.10
@@ -58,10 +58,13 @@
import java.lang.reflect.Method;
import org.apache.velocity.context.InternalContextAdapter;
-import org.apache.velocity.runtime.parser.*;
+import org.apache.velocity.runtime.parser.Parser;
import org.apache.velocity.util.introspection.IntrospectionCacheData;
import org.apache.velocity.util.introspection.Introspector;
+import org.apache.velocity.exception.MethodInvocationException;
+import java.lang.reflect.InvocationTargetException;
+
/**
* ASTIdentifier.java
*
@@ -76,7 +79,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
- * @version $Id: ASTIdentifier.java,v 1.9 2001/03/19 18:33:10 geirm Exp $
+ * @version $Id: ASTIdentifier.java,v 1.10 2001/04/18 12:25:27 geirm Exp $
*/
public class ASTIdentifier extends SimpleNode
{
@@ -136,7 +139,9 @@
executor = new PropertyExecutor(data, identifier);
if (executor.isAlive() == false)
+ {
executor = new GetExecutor(data, identifier);
+ }
return executor;
}
@@ -145,6 +150,7 @@
* invokes the method on the object passed in
*/
public Object execute(Object o, InternalContextAdapter context)
+ throws MethodInvocationException
{
AbstractExecutor executor = null;
@@ -185,7 +191,6 @@
context.icachePut( this, icd );
}
}
-
}
catch( Exception e)
{
@@ -194,13 +199,32 @@
+ identifier + " : " + e );
}
- if (executor != null)
+ /*
+ * we have no executor... punt...
+ */
+ if (executor == null)
{
+ return null;
+ }
+
+ /*
+ * now try and execute. If we get a MIE, throw that
+ * as the app wants to get these. If not, log and punt.
+ */
+ try
+ {
return executor.execute(o, context);
- }
- else
+ }
+ catch( MethodInvocationException mie )
+ {
+ throw mie;
+ }
+ catch( Exception e )
{
- return null;
+ System.out.println("ASTIdentifier() : exception invoking method '"
+ + identifier + "' in " + o.getClass() + " : " + e );
}
+
+ return null;
}
}
1.14 +4 -1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTMethod.java
Index: ASTMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTMethod.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- ASTMethod.java 2001/03/24 04:16:40 1.13
+++ ASTMethod.java 2001/04/18 12:25:28 1.14
@@ -68,7 +68,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
- * @version $Id: ASTMethod.java,v 1.13 2001/03/24 04:16:40 geirm Exp $
+ * @version $Id: ASTMethod.java,v 1.14 2001/04/18 12:25:28 geirm Exp $
*/
package org.apache.velocity.runtime.parser.node;
@@ -271,6 +271,9 @@
}
catch( Exception e )
{
+ System.out.println("ASTMethod.execute() : exception invoking method '"
+ + methodName + "' in " + o.getClass() + " : " + e );
+
return null;
}
}
1.6 +7 -3
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/AbstractExecutor.java
Index: AbstractExecutor.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/AbstractExecutor.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- AbstractExecutor.java 2001/03/19 18:53:53 1.5
+++ AbstractExecutor.java 2001/04/18 12:25:28 1.6
@@ -58,6 +58,8 @@
import java.lang.reflect.Method;
import org.apache.velocity.context.InternalContextAdapter;
+import java.lang.reflect.InvocationTargetException;
+import org.apache.velocity.exception.MethodInvocationException;
/**
* Abstract class that is used to execute an arbitrary
@@ -65,7 +67,7 @@
* for the GetExecutor and PropertyExecutor.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
- * @version $Id: AbstractExecutor.java,v 1.5 2001/03/19 18:53:53 geirm Exp $
+ * @version $Id: AbstractExecutor.java,v 1.6 2001/04/18 12:25:28 geirm Exp $
*/
public abstract class AbstractExecutor
{
@@ -77,8 +79,9 @@
/**
* Execute method against context.
*/
- public abstract Object execute(Object o, InternalContextAdapter context);
-
+ public abstract Object execute(Object o, InternalContextAdapter context)
+ throws IllegalAccessException, MethodInvocationException;
+
/**
* Tell whether the executor is alive by looking
* at the value of the method.
@@ -92,3 +95,4 @@
}
}
+
1.4 +36 -11
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/GetExecutor.java
Index: GetExecutor.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/GetExecutor.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- GetExecutor.java 2001/03/19 18:53:54 1.3
+++ GetExecutor.java 2001/04/18 12:25:28 1.4
@@ -58,6 +58,9 @@
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.util.introspection.Introspector;
+import java.lang.reflect.InvocationTargetException;
+import org.apache.velocity.exception.MethodInvocationException;
+
/**
* Executor that simply tries to execute a get(key)
* operation. This will try to find a get(key) method
@@ -66,7 +69,7 @@
* the case.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
- * @version $Id: GetExecutor.java,v 1.3 2001/03/19 18:53:54 geirm Exp $
+ * @version $Id: GetExecutor.java,v 1.4 2001/04/18 12:25:28 geirm Exp $
*/
public class GetExecutor extends AbstractExecutor
{
@@ -85,24 +88,46 @@
args[0] = key;
method = Introspector.getMethod(c, "get", args);
}
-
+
/**
- * Try and execute the get(key) method for this
- * object. There is no longer a requirement that
- * this object implement the Map interface.
+ * Execute method against context.
*/
public Object execute(Object o, InternalContextAdapter context)
+ throws IllegalAccessException, MethodInvocationException
{
- try
+ if (method == null)
+ return null;
+
+ try
+ {
+ return method.invoke(o, args);
+ }
+ catch( InvocationTargetException ite )
{
- if (method == null)
- return null;
-
- return method.invoke(o, args);
+ /*
+ * the method we invoked threw an exception.
+ * package and pass it up
+ */
+
+ throw new MethodInvocationException(
+ "Invocation of method 'get(\"" + args[0] + "\")'"
+ + " in " + o.getClass()
+ + " threw exception "
+ + ite.getTargetException().getClass(),
+ ite.getTargetException(), "get" );
}
- catch (Exception e)
+ catch( IllegalArgumentException iae )
{
return null;
}
}
}
+
+
+
+
+
+
+
+
+
1.6 +35 -10
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/PropertyExecutor.java
Index: PropertyExecutor.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/PropertyExecutor.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- PropertyExecutor.java 2001/03/19 18:53:55 1.5
+++ PropertyExecutor.java 2001/04/18 12:25:28 1.6
@@ -57,11 +57,16 @@
import org.apache.velocity.context.InternalContextAdapter;
+import java.lang.reflect.InvocationTargetException;
+import org.apache.velocity.exception.MethodInvocationException;
+
/**
* Returned the value of object property when executed.
*/
public class PropertyExecutor extends AbstractExecutor
{
+ private String methodUsed = null;
+
public PropertyExecutor(Class c, String property)
{
/*
@@ -72,7 +77,9 @@
try
{
- method = c.getMethod("get" + property, null);
+ methodUsed = "get" + property;
+
+ method = c.getMethod( methodUsed, null);
}
catch (NoSuchMethodException nsme)
{
@@ -105,30 +112,48 @@
try
{
- method = c.getMethod( sb.toString(), null);
+ methodUsed = sb.toString();
+ method = c.getMethod( methodUsed, null);
}
catch ( NoSuchMethodException nsme2 )
{
}
}
}
-
+
/**
- * Get the value of the specified property.
+ * Execute method against context.
*/
public Object execute(Object o, InternalContextAdapter context)
+ throws IllegalAccessException, MethodInvocationException
{
- try
+ if (method == null)
+ return null;
+
+ try
{
- if (method == null)
- return null;
-
- return method.invoke(o, null);
+ return method.invoke(o, null);
}
- catch (Exception e)
+ catch( InvocationTargetException ite )
{
+ /*
+ * the method we invoked threw an exception.
+ * package and pass it up
+ */
+
+ throw new MethodInvocationException(
+ "Invocation of method '" + methodUsed + "'"
+ + " in " + o.getClass()
+ + " threw exception "
+ + ite.getTargetException().getClass(),
+ ite.getTargetException(), methodUsed );
+ }
+ catch( IllegalArgumentException iae )
+ {
return null;
}
}
}
+
+