* to be thread- as well as context-safe, we *must* do it now,
* at execution time. There can be no in-node caching,
* but if we are careful, we can do it in the context.
*/
VelMethod method = null;
Object [] params = new Object[paramCount];
try
{
/*
* sadly, we do need recalc the values of the args, as this can
* change from visit to visit
*/
final Class[] paramClasses = paramCount > 0 ? new Class[paramCount] : ArrayUtils.EMPTY_CLASS_ARRAY;
for (int j = 0; j < paramCount; j++)
{
params[j] = jjtGetChild(j + 1).value(context);
if (params[j] != null)
{
paramClasses[j] = params[j].getClass();
}
}
/*
* check the cache
*/
MethodCacheKey mck = new MethodCacheKey(methodName, paramClasses);
IntrospectionCacheData icd = context.icacheGet( mck );
/*
* like ASTIdentifier, if we have cache information, and the
* Class of Object o is the same as that in the cache, we are
* safe.
*/
if ( icd != null && (o != null && icd.contextData == o.getClass()) )
{
/*
* get the method from the cache
*/
method = (VelMethod) icd.thingy;
}
else
{
/*
* otherwise, do the introspection, and then
* cache it
*/
for (int j = 0; j < paramCount; j++)
params[j] = jjtGetChild(j + 1).value(context);
method = rsvc.getUberspect().getMethod(o, methodName, params, new Info(context.getCurrentTemplateName(), getLine(), getColumn()));
if ((method != null) && (o != null))
{
icd = new IntrospectionCacheData();
icd.contextData = o.getClass();
icd.thingy = method;
context.icachePut( mck, icd );
}
}
/*
* if we still haven't gotten the method, either we are calling
* a method that doesn't exist (which is fine...) or I screwed
* it up.
*/
if (method == null)
{
return null;
}
}
catch( MethodInvocationException mie )
{
/*
* this can come from the doIntrospection(), as the arg values
* are evaluated to find the right method signature. We just
* want to propogate it here, not do anything fancy
*/
throw mie;
}
/**
* pass through application level runtime exceptions
*/
catch( RuntimeException e )
{
throw e;
}
catch( Exception e )
{
/*
* can come from the doIntropection() also, from Introspector
*/
log.error("ASTMethod.execute() : exception from introspection", e);
return null;
}
try
{
/*
* get the returned object. It may be null, and that is
* valid for something declared with a void return type.
* Since the caller is expecting something to be returned,
* as long as things are peachy, we can return an empty
* String so ASTReference() correctly figures out that
* all is well.
*/
Object obj = method.invoke(o, params);
if (obj == null)
{
if( method.getReturnType() == Void.TYPE)
{
return "";
}
}