XPathLexer2 lexer = new XPathLexer2(new StringReader(query)); XPathParser2 parser = new XPathParser2(lexer); XPathTreeParser2 treeParser = new XPathTreeParser2(context);
DocumentSet docs = broker.getAllDocuments(new DocumentSet()); context.setStaticallyKnownDocuments(docs);  XQueryLexer lexer = new XQueryLexer(new StringReader(query)); XQueryParser parser = new XQueryParser(lexer, true); XQueryTreeParser treeParser = new XQueryTreeParser(context);
	public org.exist.soap.QueryResponse query(String sessionId, java.lang.String query)		throws java.rmi.RemoteException {		Session session = SessionManager.getInstance().getSession(sessionId);		QueryResponse resp = new QueryResponse();		resp.setHits(0);		DBBroker broker = null;		try {			broker = pool.get(session.getUser());			XQueryContext context = new XQueryContext(broker);			XPathLexer2 lexer = new XPathLexer2(new StringReader(query));			XPathParser2 parser = new XPathParser2(lexer);			XPathTreeParser2 treeParser = new XPathTreeParser2(context);			parser.xpath();			if (parser.foundErrors()) {				throw new RemoteException(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("query: " + expr.pprint());			long start = System.currentTimeMillis();			Sequence seq= expr.eval(null, null);			QueryResponseCollection[] collections = null;			if (seq.getItemType() == Type.NODE)				collections = collectQueryInfo(scanResults((NodeSet)seq));			session.addQueryResult(seq);			resp.setCollections(collections);			resp.setHits(seq.getLength());			resp.setQueryTime(System.currentTimeMillis() - start);		} catch (Exception e) {			throw new RemoteException("query execution failed: " + e.getMessage());		} finally {			pool.release(broker);		}		return resp;	}