public void run(DynamicQueryContext env, Result result, Properties outputProperties) throws XPathException {
if (isUpdating) {
throw new XPathException("Cannot call run() on an updating query");
}
Controller controller = newController();
initializeController(env, controller);
if (allowDocumentProjection) {
controller.setUseDocumentProjection(getPathMap());
}
Properties actualProperties = validateOutputProperties(controller, outputProperties);
controller.defineGlobalParameters();
XPathContextMajor context = initialContext(env, controller);
// In tracing/debugging mode, evaluate all the global variables first
TraceListener tracer = controller.getTraceListener();
if (tracer != null) {
controller.preEvaluateGlobals(context);
tracer.open();
}
context.openStackFrame(stackFrameMap);
boolean mustClose = (result instanceof StreamResult &&
((StreamResult)result).getOutputStream() == null);
context.changeOutputDestination(actualProperties, result, true,
Configuration.XQUERY, Validation.PRESERVE, null);
context.getReceiver().open();
// Run the query
try {
expression.process(context);
} catch (XPathException err) {
controller.reportFatalError(err);
throw err;
}
if (tracer != null) {
tracer.close();