convertedArgs,
exprContext);
putToCache(methodKey, null, methodArgs, c);
if (TransformerImpl.S_DEBUG) {
TransformerImpl trans = (TransformerImpl)exprContext.getXPathContext().getOwnerObject();
trans.getTraceManager().fireExtensionEvent(new ExtensionEvent(trans, c, convertedArgs[0]));
Object result;
try {
result = c.newInstance(convertedArgs[0]);
} catch (Exception e) {
throw e;
} finally {
trans.getTraceManager().fireExtensionEndEvent(new ExtensionEvent(trans, c, convertedArgs[0]));
}
return result;
} else
return c.newInstance(convertedArgs[0]);
}
else
{
int resolveType;
Object targetObject = null;
methodArgs = new Object[args.size()];
convertedArgs = new Object[1][];
for (int i = 0; i < methodArgs.length; i++)
{
methodArgs[i] = args.elementAt(i);
}
Method m = (Method) getFromCache(methodKey, null, methodArgs);
if (m != null && !TransformerImpl.S_DEBUG)
{
try
{
paramTypes = m.getParameterTypes();
MethodResolver.convertParams(methodArgs, convertedArgs, paramTypes, exprContext);
if (Modifier.isStatic(m.getModifiers()))
return m.invoke(null, convertedArgs[0]);
else
{
// This is tricky. We get the actual number of target arguments (excluding any
// ExpressionContext). If we passed in the same number, we need the implied object.
int nTargetArgs = convertedArgs[0].length;
if (ExpressionContext.class.isAssignableFrom(paramTypes[0]))
nTargetArgs--;
if (methodArgs.length <= nTargetArgs)
return m.invoke(m_defaultInstance, convertedArgs[0]);
else
{
targetObject = methodArgs[0];
if (targetObject instanceof XObject)
targetObject = ((XObject) targetObject).object();
return m.invoke(targetObject, convertedArgs[0]);
}
}
}
catch (InvocationTargetException ite)
{
throw ite;
}
catch(Exception e)
{
// Must not have been the right one
}
}
if (args.size() > 0)
{
targetObject = methodArgs[0];
if (targetObject instanceof XObject)
targetObject = ((XObject) targetObject).object();
if (m_classObj.isAssignableFrom(targetObject.getClass()))
resolveType = MethodResolver.DYNAMIC;
else
resolveType = MethodResolver.STATIC_AND_INSTANCE;
}
else
{
targetObject = null;
resolveType = MethodResolver.STATIC_AND_INSTANCE;
}
m = MethodResolver.getMethod(m_classObj,
funcName,
methodArgs,
convertedArgs,
exprContext,
resolveType);
putToCache(methodKey, null, methodArgs, m);
if (MethodResolver.DYNAMIC == resolveType) { // First argument was object type
if (TransformerImpl.S_DEBUG) {
TransformerImpl trans = (TransformerImpl)exprContext.getXPathContext().getOwnerObject();
trans.getTraceManager().fireExtensionEvent(m, targetObject, convertedArgs[0]);
Object result;
try {
result = m.invoke(targetObject, convertedArgs[0]);
} catch (Exception e) {
throw e;
} finally {
trans.getTraceManager().fireExtensionEndEvent(m, targetObject, convertedArgs[0]);
}
return result;
} else
return m.invoke(targetObject, convertedArgs[0]);
}
else // First arg was not object. See if we need the implied object.
{
if (Modifier.isStatic(m.getModifiers())) {
if (TransformerImpl.S_DEBUG) {
TransformerImpl trans = (TransformerImpl)exprContext.getXPathContext().getOwnerObject();
trans.getTraceManager().fireExtensionEvent(m, null, convertedArgs[0]);
Object result;
try {
result = m.invoke(null, convertedArgs[0]);
} catch (Exception e) {
throw e;
} finally {
trans.getTraceManager().fireExtensionEndEvent(m, null, convertedArgs[0]);
}
return result;
} else
return m.invoke(null, convertedArgs[0]);
}
else
{
if (null == m_defaultInstance)
{
if (TransformerImpl.S_DEBUG) {
TransformerImpl trans = (TransformerImpl)exprContext.getXPathContext().getOwnerObject();
trans.getTraceManager().fireExtensionEvent(new ExtensionEvent(trans, m_classObj));
try {
m_defaultInstance = m_classObj.newInstance();
} catch (Exception e) {
throw e;
} finally {
trans.getTraceManager().fireExtensionEndEvent(new ExtensionEvent(trans, m_classObj));
}
} else
m_defaultInstance = m_classObj.newInstance();
}
if (TransformerImpl.S_DEBUG) {