// call method - if supplied and script engine supports direct invocation
if ( method != null && (this.scriptEngine instanceof Invocable)) {
try {
((Invocable)scriptEngine).invokeFunction(method, Arrays.asList(args).toArray());
} catch (NoSuchMethodException e) {
throw new ScriptEvaluationException(this.scriptName, "Method " + method + " not found in script.", e);
}
}
// optionall flush the output channel
Object flushObject = bindings.get(FLUSH);
if (flushObject instanceof Boolean && (Boolean) flushObject) {
ctx.getWriter().flush();
}
// allways flush the error channel
ctx.getErrorWriter().flush();
return result;
} catch (IOException ioe) {
throw new ScriptEvaluationException(this.scriptName, ioe.getMessage(),
ioe);
} catch (ScriptException se) {
Throwable cause = (se.getCause() == null) ? se : se.getCause();
throw new ScriptEvaluationException(this.scriptName, se.getMessage(),
cause);
} finally {
if ( props.getRequest() != null ) {
requestResourceResolver.set(oldResolver);