log.debug("Calling: " + name);
}
try {
@SuppressWarnings("unused")
Method apiMethod = null;
Invocable invocable = (Invocable) engine;
if (null == instance) {
o = invocable.invokeFunction(name, args);
} else {
try {
o = invocable.invokeMethod(instance, name, args);
} catch (NoSuchMethodException nex) {
log.debug("Method not found: " + name);
try {
// try to invoke it directly, this will work if the
// function is in the engine context
// ie. the script has been already evaluated
o = invocable.invokeFunction(name, args);
} catch (Exception ex) {
log.debug("Function not found: " + name);
Class[] interfaces = (Class[]) engine.get("interfaces");
for (Class clazz : interfaces) {
// java6 style
o = invocable.getInterface(engine.get((String) engine.get("className")), clazz);
if (null != o) {
log.debug("Interface return type: " + o.getClass().getName());
break;
}
}