variables.put(name, result);
}
private Sequence processQuery(String select) throws SAXException {
XQueryContext context = null;
try {
context = new XQueryContext(broker.getBrokerPool(), accessCtx);
context.setStaticallyKnownDocuments(documentSet);
Map.Entry<String, String> namespaceEntry;
for (final Iterator<Map.Entry<String, String>> i = namespaces.entrySet().iterator(); i.hasNext();) {
namespaceEntry = (Map.Entry<String, String>) i.next();
context.declareNamespace(
namespaceEntry.getKey(),
namespaceEntry.getValue());
}
Map.Entry<String, Object> entry;
for (final Iterator<Map.Entry<String, Object>> i = variables.entrySet().iterator(); i.hasNext(); ) {
entry = (Map.Entry<String, Object>) i.next();
context.declareVariable(entry.getKey().toString(), entry.getValue());
}
// TODO(pkaminsk2): why replicate XQuery.compile here?
final XQueryLexer lexer = new XQueryLexer(context, new StringReader(select));
final XQueryParser parser = new XQueryParser(lexer);
final XQueryTreeParser treeParser = new XQueryTreeParser(context);
parser.xpath();
if (parser.foundErrors()) {
throw new SAXException(parser.getErrorMessage());
}
final AST ast = parser.getAST();
if (LOG.isDebugEnabled())
{LOG.debug("generated AST: " + ast.toStringTree());}
final PathExpr expr = new PathExpr(context);
treeParser.xpath(ast, expr);
if (treeParser.foundErrors()) {
throw new SAXException(treeParser.getErrorMessage());
}
expr.analyze(new AnalyzeContextInfo());
final Sequence seq = expr.eval(null, null);
return seq;
} catch (final RecognitionException e) {
LOG.warn("error while creating variable", e);
throw new SAXException(e);
} catch (final TokenStreamException e) {
LOG.warn("error while creating variable", e);
throw new SAXException(e);
} catch (final XPathException e) {
throw new SAXException(e);
} finally {
if (context != null)
{context.reset(false);}
}
}