public Object exec(List arguments) throws TemplateModelException {
MemberAndArguments maa = methodMap.getMemberAndArguments(arguments);
Method method = (Method)maa.getMember();
try {
return methodMap.getWrapper().invokeMethod(object, method, maa.getArgs());
}
catch(Exception e)
{
while(e instanceof InvocationTargetException)
{
Throwable t = ((InvocationTargetException)e).getTargetException();
if(t instanceof Exception)
{
e = (Exception)t;
}
else
{
break;
}
}
if((method.getModifiers() & Modifier.STATIC) != 0)
{
throw new TemplateModelException("Method " + method +
" threw an exception", e);
}
else
{
StringBuffer buf = new StringBuffer();
Object[] args = maa.getArgs();
for(int i = 0; i < args.length; ++i)
{
Object arg = args[i];
buf.append(arg == null ? "null" : arg.getClass().getName()).append(',");
}
throw new TemplateModelException("Method " + method +
" threw an exception when invoked on " + object +
" with arguments of types [" + buf + "]", e);
}
}
}
Invokes the method, passing it the arguments from the list. The actual
method to call from several overloaded methods will be chosen based
on the classes of the arguments. |