}
}
protected void runScript(Subject subject, String scriptURI, String script, QName functionName, List<Expression> args) {
final Database db = getDatabase();
DBBroker broker = null;
try {
broker = db.get(subject);
final Source source = getQuerySource(broker, scriptURI, script);
if(source == null) {return;}
final XQuery xquery = broker.getXQueryService();
final XQueryContext context = xquery.newContext(AccessContext.XMLDB);
final CompiledXQuery compiled = xquery.compile(context, source);
// Sequence result = xquery.execute(compiled, subject.getName());
final ProcessMonitor pm = db.getProcessMonitor();
//execute the XQuery
try {
final UserDefinedFunction function = context.resolveFunction(functionName, 0);
if (function != null) {
context.getProfiler().traceQueryStart();
pm.queryStarted(context.getWatchDog());
final FunctionCall call = new FunctionCall(context, function);
if (args != null)
{call.setArguments(args);}
call.analyze(new AnalyzeContextInfo());
call.eval(NodeSet.EMPTY_SET);
}
} catch(final XPathException e) {
//XXX: log
e.printStackTrace();
} finally {
if (pm != null) {
context.getProfiler().traceQueryEnd(context);
pm.queryCompleted(context.getWatchDog());
}
compiled.reset();
context.reset();
}
} catch (final Exception e) {
//XXX: log
e.printStackTrace();
} finally {
db.release(broker);
}
}