} else {
StaticQueryContext env = saConfig.newStaticQueryContext();
env.setModuleURIResolver(new XQTSModuleURIResolver(testCase));
env.setBaseURI(new File(absQueryName).toURI().toString());
env.setLanguageVersion(languageVersion);
XQueryExpression xqe;
try {
xqe = env.compileQuery(new FileInputStream(absQueryName), "UTF-8");
} catch (XPathException err) {
processError(err, testCase, testName, filePath + queryName + ".xq", expectedErrorNT, specVersionAtt);
continue;
}
NodeInfo optElement = getChildElement(testCase, optimizationNT);
if (optElement != null) {
String explain = optElement.getAttributeValue(explainAtt);
if ("true".equals(explain) || "1".equals(explain)) {
ExpressionPresenter presenter = new ExpressionPresenter(saConfig);
xqe.explain(presenter);
presenter.close();
}
String assertion = optElement.getAttributeValue(assertAtt);
if (assertion != null) {
TinyBuilder builder = new TinyBuilder();
builder.setPipelineConfiguration(saConfig.makePipelineConfiguration());
ExpressionPresenter presenter = new ExpressionPresenter(saConfig, builder);
xqe.explain(presenter);
presenter.close();
NodeInfo expressionTree = builder.getCurrentRoot();
XPathEvaluator xpe = new XPathEvaluator(saConfig);
XPathExpression exp = xpe.createExpression(assertion);
try {
Boolean bv = (Boolean)exp.evaluateSingle(expressionTree);
if (bv == null || !bv.booleanValue()) {
log.println("** Optimization assertion failed");
optimizationOK = false;
}
} catch (Exception e) {
log.println("** Optimization assertion result is not a boolean: " + assertion +
"(" + e.getMessage() + ")");
}
}
}
DynamicQueryContext dqc = new DynamicQueryContext(saConfig);
NodeInfo contextItemElement = getChildElement(testCase, contextItemNT);
if (contextItemElement != null) {
DocumentInfo contextNode = loadDocument(contextItemElement.getStringValue());
dqc.setContextItem(contextNode);
}
processInputQueries(testCase, inputQueryNT, variableAtt, nameAtt, filePath, dqc);
processInputDocuments(testCase, inputFileNT, variableAtt, dqc);
setQueryParameters(catalog, testCase, dqc, inputUriNT, variableAtt, collectionNT, idAtt);
NodeInfo defaultCollection = getChildElement(testCase, defaultCollectionNT);
if (defaultCollection != null) {
String docName = defaultCollection.getStringValue();
NodeInfo collectionElement = getCollectionElement(catalog, docName, collectionNT, idAtt);
CollectionURIResolver r =
new XQTSCollectionURIResolver(catalog, collectionElement, true);
saConfig.setCollectionURIResolver(r);
}
// Run the query
String outputDir = saxonDir + "/results/" + filePath;
if (outputDir.endsWith("/")) {
outputDir = outputDir.substring(0, outputDir.length()-1);
}
new File(outputDir).mkdirs();
outputFile = outputDir + "/" + testName + ".out";
File outputFileF = new File(outputFile);
outputFileF.createNewFile();
StreamResult result = new StreamResult(outputFileF);
try {
if (usePull) {
xqe.pull(dqc, result, outputProps);
} else {
xqe.run(dqc, result, outputProps);
}
} catch (XPathException err) {
processError(err, testCase, testName, filePath + queryName + ".xq", expectedErrorNT, specVersionAtt);
continue;
}