* @throws XPathException if the query fails.
*/
public void run(DynamicQueryContext env, Result result, Properties outputProperties) throws XPathException {
if (isUpdating) {
throw new XPathException("Cannot call run() on an updating query");
}
if (!env.getConfiguration().isCompatible(getExecutable().getConfiguration())) {
throw new XPathException("The query must be compiled and executed under the same Configuration");
}
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);
SerializerFactory sf = context.getConfiguration().getSerializerFactory();
PipelineConfiguration pipe = controller.makePipelineConfiguration();
pipe.setHostLanguage(Configuration.XQUERY);
Receiver receiver = sf.getReceiver(result, pipe, actualProperties);
context.changeOutputDestination(receiver, true,
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();
}
context.getReceiver().close();
if (mustClose) {
OutputStream os = ((StreamResult)result).getOutputStream();
if (os != null) {
try {
os.close();
} catch (java.io.IOException err) {
throw new XPathException(err);
}
}
}
}