Object result = invokeConstructor(constructor, params);
//Object result = constructor.newInstance(params);
return asIterator(result, context);
} catch (InstantiationException err0) {
DynamicError e = new DynamicError("Cannot instantiate class", err0);
e.setXPathContext(context);
throw e;
} catch (IllegalAccessException err1) {
DynamicError e = new DynamicError("Constructor access is illegal", err1);
e.setXPathContext(context);
throw e;
} catch (IllegalArgumentException err2) {
DynamicError e = new DynamicError("Argument is of wrong type", err2);
e.setXPathContext(context);
throw e;
} catch (NullPointerException err2) {
DynamicError e = new DynamicError("Object is null");
e.setXPathContext(context);
throw e;
} catch (InvocationTargetException err3) {
Throwable ex = err3.getTargetException();
if (ex instanceof XPathException) {
throw (XPathException) ex;
} else {
if (context.getController().isTracing() ||
context.getController().getConfiguration().isTraceExternalFunctions()) {
err3.getTargetException().printStackTrace();
}
DynamicError e = new DynamicError("Exception in extension function: " +
err3.getTargetException().toString(), ex);
e.setXPathContext(context);
throw e;
}
}
} else if (theMethod instanceof Method) {
Method method = (Method) theMethod;
boolean isStatic = Modifier.isStatic(method.getModifiers());
Object theInstance;
theParameterTypes = method.getParameterTypes();
boolean usesContext = theParameterTypes.length > 0 &&
(theParameterTypes[0] == XPathContext.class);
if (isStatic) {
theInstance = null;
} else {
if (argValues.length == 0) {
DynamicError e = new DynamicError("Must supply an argument for an instance-level extension function");
e.setXPathContext(context);
throw e;
}
Value arg0 = argValues[0];
theInstance = arg0.convertToJava(theClass, config, context);
// this fails if the first argument is not of a suitable class
}
Object[] params = new Object[theParameterTypes.length];
if (usesContext) {
params[0] = context;
}
setupParams(argValues, params, theParameterTypes,
(usesContext ? 1 : 0),
(isStatic ? 0 : 1),
context
);
try {
Object result = invokeMethod(method, theInstance, params);
//Object result = method.invoke(theInstance, params);
if (method.getReturnType().toString().equals("void")) {
// method returns void:
// tried (method.getReturnType()==Void.class) unsuccessfully
return EmptyIterator.getInstance();
}
return asIterator(result, context);
} catch (IllegalAccessException err1) {
throw new DynamicError("Method access is illegal", err1);
} catch (IllegalArgumentException err2) {
throw new DynamicError("Argument is of wrong type", err2);
} catch (NullPointerException err2) {
throw new DynamicError("Object is null", err2);
} catch (InvocationTargetException err3) {
Throwable ex = err3.getTargetException();
if (ex instanceof XPathException) {
throw (XPathException) ex;
} else {
if (context.getController().isTracing() ||
context.getController().getConfiguration().isTraceExternalFunctions()) {
err3.getTargetException().printStackTrace();
}
throw new DynamicError("Exception in extension function " +
err3.getTargetException().toString(), ex);
}
}
} else if (theMethod instanceof Field) {
// Start of code added by GS
Field field = (Field) theMethod;
boolean isStatic = Modifier.isStatic(field.getModifiers());
Object theInstance;
if (isStatic) {
theInstance = null;
} else {
if (argValues.length == 0) {
DynamicError e = new DynamicError("Must supply an argument for an instance-level extension function");
e.setXPathContext(context);
throw e;
}
Value arg0 = argValues[0];
theInstance = arg0.convertToJava(theClass, config, context);
// this fails if the first argument is not of a suitable class
}
try {
Object result = getField(field, theInstance);
return asIterator(result, context);
} catch (IllegalAccessException err1) {
DynamicError e = new DynamicError("Field access is illegal", err1);
e.setXPathContext(context);
throw e;
} catch (IllegalArgumentException err2) {
DynamicError e = new DynamicError("Argument is of wrong type", err2);
e.setXPathContext(context);
throw e;
}
} else {
throw new AssertionError("property " + theMethod + " is neither constructor, method, nor field");
}