You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by ge...@apache.org on 2002/04/21 22:57:25 UTC
cvs commit: jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node AbstractExecutor.java BooleanPropertyExecutor.java GetExecutor.java PropertyExecutor.java
geirm 02/04/21 13:57:25
Modified: src/java/org/apache/velocity/runtime/parser/node
AbstractExecutor.java BooleanPropertyExecutor.java
GetExecutor.java PropertyExecutor.java
Log:
minor mods - switching to RuntimeLogger, for example
Revision Changes Path
1.11 +13 -6 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.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- AbstractExecutor.java 22 Oct 2001 03:53:25 -0000 1.10
+++ AbstractExecutor.java 21 Apr 2002 20:57:25 -0000 1.11
@@ -62,6 +62,7 @@
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.runtime.RuntimeServices;
+import org.apache.velocity.runtime.RuntimeLogger;
/**
* Abstract class that is used to execute an arbitrary
@@ -69,11 +70,12 @@
* for the GetExecutor and PropertyExecutor.
*
* @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
- * @version $Id: AbstractExecutor.java,v 1.10 2001/10/22 03:53:25 jon Exp $
+ * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
+ * @version $Id: AbstractExecutor.java,v 1.11 2002/04/21 20:57:25 geirm Exp $
*/
public abstract class AbstractExecutor
{
- protected RuntimeServices rsvc = null;
+ protected RuntimeLogger rlog = null;
/**
* Method to be executed.
@@ -83,9 +85,9 @@
/**
* Execute method against context.
*/
- public abstract Object execute(Object o, InternalContextAdapter context)
- throws IllegalAccessException, MethodInvocationException;
-
+ public abstract Object execute(Object o)
+ throws IllegalAccessException, InvocationTargetException;
+
/**
* Tell whether the executor is alive by looking
* at the value of the method.
@@ -93,5 +95,10 @@
public boolean isAlive()
{
return (method != null);
- }
+ }
+
+ public Method getMethod()
+ {
+ return method;
+ }
}
1.2 +17 -19 jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/BooleanPropertyExecutor.java
Index: BooleanPropertyExecutor.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/BooleanPropertyExecutor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BooleanPropertyExecutor.java 19 Nov 2001 13:52:30 -0000 1.1
+++ BooleanPropertyExecutor.java 21 Apr 2002 20:57:25 -0000 1.2
@@ -63,30 +63,31 @@
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.runtime.RuntimeServices;
+import org.apache.velocity.runtime.RuntimeLogger;
import org.apache.velocity.util.introspection.Introspector;
/**
- * Handles discovery and valuation of a
+ * Handles discovery and valuation of a
* boolean object property, of the
* form public boolean is<property> when executed.
*
* We do this separately as to preserve the current
* quasi-broken semantics of get<as is property>
- * get< flip 1st char> get("property") and now followed
+ * get< flip 1st char> get("property") and now followed
* by is<Property>
*
* @author <a href="geirm@apache.org">Geir Magnusson Jr.</a>
- * @version $Id: BooleanPropertyExecutor.java,v 1.1 2001/11/19 13:52:30 geirm Exp $
+ * @version $Id: BooleanPropertyExecutor.java,v 1.2 2002/04/21 20:57:25 geirm Exp $
*/
public class BooleanPropertyExecutor extends PropertyExecutor
{
- public BooleanPropertyExecutor( RuntimeServices r, Class clazz, String property)
+ public BooleanPropertyExecutor(RuntimeLogger rlog, Introspector is, Class clazz, String property)
{
- super( r, clazz, property );
+ super(rlog, is, clazz, property);
}
- protected void discover( Class clazz, String property )
+ protected void discover(Class clazz, String property)
{
try
{
@@ -94,24 +95,23 @@
StringBuffer sb;
Object[] params = { };
- Introspector introspector = rsvc.getIntrospector();
-
+
/*
* now look for a boolean isFoo
*/
-
- sb = new StringBuffer( "is" );
- sb.append( property );
+
+ sb = new StringBuffer("is");
+ sb.append(property);
c = sb.charAt(2);
- if( Character.isLowerCase(c) )
+ if (Character.isLowerCase(c))
{
- sb.setCharAt( 2 , Character.toUpperCase(c) );
+ sb.setCharAt(2, Character.toUpperCase(c));
}
methodUsed = sb.toString();
- method = introspector.getMethod( clazz, methodUsed, params);
+ method = introspector.getMethod(clazz, methodUsed, params);
if (method != null)
{
@@ -119,17 +119,15 @@
* now, this has to return a boolean
*/
- if ( method.getReturnType() == Boolean.TYPE )
+ if (method.getReturnType() == Boolean.TYPE)
return;
method = null;
}
}
- catch( Exception e )
+ catch(Exception e)
{
- rsvc.error("PROGRAMMER ERROR : BooleanPropertyExector() : " + e );
+ rlog.error("PROGRAMMER ERROR : BooleanPropertyExector() : " + e);
}
}
}
-
-
1.7 +21 -8 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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- GetExecutor.java 22 Oct 2001 03:53:25 -0000 1.6
+++ GetExecutor.java 21 Apr 2002 20:57:25 -0000 1.7
@@ -62,6 +62,7 @@
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.runtime.RuntimeServices;
+import org.apache.velocity.runtime.RuntimeLogger;
/**
@@ -72,7 +73,7 @@
* the case.
*
* @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
- * @version $Id: GetExecutor.java,v 1.6 2001/10/22 03:53:25 jon Exp $
+ * @version $Id: GetExecutor.java,v 1.7 2002/04/21 20:57:25 geirm Exp $
*/
public class GetExecutor extends AbstractExecutor
{
@@ -85,18 +86,30 @@
/**
* Default constructor.
*/
- public GetExecutor( RuntimeServices r, Class c, String key)
+ public GetExecutor(RuntimeLogger r, Introspector ispect, Class c, String key)
throws Exception
{
- rsvc = r;
+ rlog = r;
args[0] = key;
- method = rsvc.getIntrospector().getMethod(c, "get", args);
+ method = ispect.getMethod(c, "get", args);
}
/**
* Execute method against context.
*/
- public Object execute(Object o, InternalContextAdapter context)
+ public Object execute(Object o)
+ throws IllegalAccessException, InvocationTargetException
+ {
+ if (method == null)
+ return null;
+
+ return method.invoke(o, args);
+ }
+
+ /**
+ * Execute method against context.
+ */
+ public Object OLDexecute(Object o, InternalContextAdapter context)
throws IllegalAccessException, MethodInvocationException
{
if (method == null)
@@ -106,7 +119,7 @@
{
return method.invoke(o, args);
}
- catch( InvocationTargetException ite )
+ catch(InvocationTargetException ite)
{
/*
* the method we invoked threw an exception.
@@ -118,9 +131,9 @@
+ " in " + o.getClass()
+ " threw exception "
+ ite.getTargetException().getClass(),
- ite.getTargetException(), "get" );
+ ite.getTargetException(), "get");
}
- catch( IllegalArgumentException iae )
+ catch(IllegalArgumentException iae)
{
return null;
}
1.14 +29 -74 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.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- PropertyExecutor.java 19 Nov 2001 13:54:01 -0000 1.13
+++ PropertyExecutor.java 21 Apr 2002 20:57:25 -0000 1.14
@@ -2,7 +2,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
+ * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -63,6 +63,7 @@
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.runtime.RuntimeServices;
+import org.apache.velocity.runtime.RuntimeLogger;
import org.apache.velocity.util.introspection.Introspector;
@@ -71,16 +72,20 @@
*/
public class PropertyExecutor extends AbstractExecutor
{
+ protected Introspector introspector = null;
+
protected String methodUsed = null;
- public PropertyExecutor( RuntimeServices r, Class clazz, String property)
+ public PropertyExecutor(RuntimeLogger r, Introspector ispctr,
+ Class clazz, String property)
{
- rsvc = r;
-
- discover( clazz, property );
+ rlog = r;
+ introspector = ispctr;
+
+ discover(clazz, property);
}
- protected void discover( Class clazz, String property )
+ protected void discover(Class clazz, String property)
{
/*
* this is gross and linear, but it keeps it straightforward.
@@ -92,19 +97,18 @@
StringBuffer sb;
Object[] params = { };
- Introspector introspector = rsvc.getIntrospector();
-
+
/*
* start with get<property>
* this leaves the property name
* as is...
*/
- sb = new StringBuffer( "get" );
- sb.append( property );
+ sb = new StringBuffer("get");
+ sb.append(property);
methodUsed = sb.toString();
- method = introspector.getMethod( clazz, methodUsed, params);
+ method = introspector.getMethod(clazz, methodUsed, params);
if (method != null)
return;
@@ -113,93 +117,44 @@
* now the convenience, flip the 1st character
*/
- sb = new StringBuffer( "get" );
- sb.append( property );
+ sb = new StringBuffer("get");
+ sb.append(property);
c = sb.charAt(3);
- if( Character.isLowerCase( c ) )
+ if (Character.isLowerCase(c))
{
- sb.setCharAt( 3 , Character.toUpperCase( c ) );
+ sb.setCharAt(3, Character.toUpperCase(c));
}
else
{
- sb.setCharAt( 3 , Character.toLowerCase( c ) );
+ sb.setCharAt(3, Character.toLowerCase(c));
}
methodUsed = sb.toString();
- method = introspector.getMethod( clazz, methodUsed, params);
+ method = introspector.getMethod(clazz, methodUsed, params);
- if ( method != null)
+ if (method != null)
return;
}
- catch( Exception e )
+ catch(Exception e)
{
- rsvc.error("PROGRAMMER ERROR : PropertyExector() : " + e );
+ rlog.error("PROGRAMMER ERROR : PropertyExector() : " + e );
}
}
-
+
+
/**
* Execute method against context.
*/
- public Object execute(Object o, InternalContextAdapter context)
- throws IllegalAccessException, MethodInvocationException
+ public Object execute(Object o)
+ throws IllegalAccessException, InvocationTargetException
{
if (method == null)
return null;
-
- try
- {
- return method.invoke(o, null);
- }
- catch( InvocationTargetException ite )
- {
- EventCartridge ec = context.getEventCartridge();
-
- /*
- * if we have an event cartridge, see if it wants to veto
- * also, let non-Exception Throwables go...
- */
-
- if ( ec != null && ite.getTargetException() instanceof java.lang.Exception)
- {
- try
- {
- return ec.methodException( o.getClass(), methodUsed, (Exception)ite.getTargetException() );
- }
- catch( Exception e )
- {
- throw new MethodInvocationException(
- "Invocation of method '" + methodUsed + "'"
- + " in " + o.getClass()
- + " threw exception "
- + ite.getTargetException().getClass() + " : "
- + ite.getTargetException().getMessage(),
- ite.getTargetException(), methodUsed );
- }
- }
- else
- {
- /*
- * no event cartridge to override. Just throw
- */
-
- throw new MethodInvocationException(
- "Invocation of method '" + methodUsed + "'"
- + " in " + o.getClass()
- + " threw exception "
- + ite.getTargetException().getClass() + " : "
- + ite.getTargetException().getMessage(),
- ite.getTargetException(), methodUsed );
-
- }
- }
- catch( IllegalArgumentException iae )
- {
- return null;
- }
+ return method.invoke(o, null);
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>