XQueryContext context = new XQueryContext(broker);
CachedQuery cached = getCachedQuery(xpath); PathExpr expr = null; if (cached == null) { expr = compile(user, broker, xpath, parameters); cached = new CachedQuery(expr, xpath); cachedExpressions.add(cached); } else { LOG.debug("reusing compiled expression"); expr = cached.expression; } String baseURI = (String) parameters.get(RpcAPI.BASE_URI); XQueryContext context = expr.getContext();
	protected Sequence doQuery(		User user,		DBBroker broker,		String xpath,		DocumentSet docs,		NodeSet contextSet,		String baseURI)		throws Exception {		if (docs == null)			docs = broker.getAllDocuments(new DocumentSet());		XQueryContext context = new XQueryContext(broker);		context.setBaseURI(baseURI);		context.setStaticallyKnownDocuments(docs);		LOG.debug("query = " + xpath);		XPathLexer2 lexer = new XPathLexer2(new StringReader(xpath));		XPathParser2 parser = new XPathParser2(lexer, false);		XPathTreeParser2 treeParser = new XPathTreeParser2(context);		parser.xpath();		if (parser.foundErrors()) {			throw new EXistException(parser.getErrorMessage());		}		AST ast = parser.getAST();		LOG.debug("generated AST: " + ast.toStringTree());		PathExpr expr = new PathExpr(context);		treeParser.xpath(ast, expr);		if (treeParser.foundErrors()) {			throw new EXistException(treeParser.getErrorMessage());		}		LOG.info("compiled: " + expr.pprint());		long start = System.currentTimeMillis();		Sequence result = expr.eval(contextSet, null);		LOG.info("query took " + (System.currentTimeMillis() - start) + "ms.");		return result;	}