* @throws XPathException if the query fails.
*/
public void run(DynamicQueryContext env, Result result, Properties outputProperties) throws XPathException {
Controller controller = getController();
initializeController(env, controller);
// Validate the serialization properties requested
if (outputProperties == null) {
outputProperties = new Properties();
} else {
Enumeration iter = outputProperties.propertyNames();
while (iter.hasMoreElements()) {
String key = (String)iter.nextElement();
String value = outputProperties.getProperty(key);
try {
SaxonOutputKeys.checkOutputProperty(key, value);
} catch (DynamicError dynamicError) {
try {
controller.getErrorListener().error(dynamicError);
throw dynamicError;
// TODO: could be a warning, but currently all warnings are fatal.
//outputProperties.remove(key);
} catch (TransformerException err2) {
throw DynamicError.wrap(err2);
}
}
}
}
NodeInfo node = env.getContextNode();
Bindery bindery = controller.getBindery();
controller.defineGlobalParameters(bindery);
XPathContextMajor context = controller.newXPathContext();
// In tracing/debugging mode, evaluate all the global variables first
TraceListener tracer = controller.getConfiguration().getTraceListener();
if (tracer != null) {
controller.preEvaluateGlobals(context);
tracer.open();
}
context.openStackFrame(stackFrameMap);
if (node != null) {
context.setCurrentIterator(SingletonIterator.makeIterator(node));
controller.setPrincipalSourceDocument(node.getDocumentRoot());
}
boolean mustClose = (result instanceof StreamResult &&
((StreamResult)result).getOutputStream() == null);
context.changeOutputDestination(outputProperties, result, true, Validation.PRESERVE, null);
// Run the query
try {
documentInstruction.process(context);
} catch (XPathException err) {
try {
controller.getErrorListener().fatalError(err);
} catch (TransformerException e) {
//
}
throw err;
}