Object target = engine.get(objectName);
if (target != null) {
try {
return invocable.invokeMethod(target, functionName, args);
} catch (NoSuchMethodException e) {
throw new ApiException("UnknownFunction", "Method \""+functionName+"\" not defined on object \""+objectName+"\"");
}
}
} else {
try {
return ((Invocable)engine).invokeFunction(functionName, args);
} catch (NoSuchMethodException e) {}
}
} catch (ScriptException e) {
throw new ApiException("ScriptException", e);
}
}
}
throw new ApiException("UnknownFunction", "Function not defined: \""+functionName+"\"");
}