use of org.apache.commons.jxpath.ExpressionContext in project vorto by eclipse.
the class JavascriptEvalFunction method invoke.
@Override
@SuppressWarnings({ "rawtypes" })
public Object invoke(ExpressionContext context, Object[] parameters) {
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("JavaScript");
try {
engine.eval(functionBody);
} catch (ScriptException e) {
throw new JXPathException("Problem evaluating " + functionName, e);
}
Invocable inv = (Invocable) engine;
try {
Object[] args;
int pi = 0;
Class[] types = toTypes(parameters);
if (types.length >= 1 && ExpressionContext.class.isAssignableFrom(types[0])) {
pi = 1;
}
args = new Object[parameters.length + pi];
if (pi == 1) {
args[0] = context;
}
for (int i = 0; i < parameters.length; i++) {
args[i + pi] = TypeUtils.convert(parameters[i], types[i + pi]);
}
return inv.invokeFunction(functionName, unwrap(args));
} catch (Throwable ex) {
throw new JXPathInvalidAccessException("Cannot invoke " + functionName, ex);
}
}
Aggregations