return Sequence.EMPTY_SEQUENCE; // no controller found
}
final String basePath = staticRewrite == null ? "." : staticRewrite.getTarget();
final XQuery xquery = broker.getXQueryService();
final XQueryPool xqyPool = xquery.getXQueryPool();
CompiledXQuery compiled = null;
if (compiledCache) {
compiled = xqyPool.borrowCompiledXQuery(broker, sourceInfo.source);
}
XQueryContext queryContext;
if (compiled == null) {
queryContext = xquery.newContext(AccessContext.REST);
} else {
queryContext = compiled.getContext();
}
// Find correct module load path
queryContext.setModuleLoadPath(sourceInfo.moduleLoadPath);
declareVariables(queryContext, sourceInfo, staticRewrite, basePath, request, response);
if (compiled == null) {
try {
compiled = xquery.compile(queryContext, sourceInfo.source);
} catch (final IOException e) {
throw new ServletException("Failed to read query from " + query, e);
}
}
model.setSourceInfo(sourceInfo);
// This used by controller.xql only ?
// String xdebug = request.getParameter("XDEBUG_SESSION_START");
// if (xdebug != null)
// compiled.getContext().setDebugMode(true);
// outputProperties.put("base-uri", collectionURI.toString());
try {
return xquery.execute(compiled, null, outputProperties);
} finally {
queryContext.runCleanupTasks();
xqyPool.returnCompiledXQuery(sourceInfo.source, compiled);
}
}