private void buildXQueryDynamicContext( XQueryContext context, Object[] params, MutableDocumentSet docsToLock, boolean bindVariables) throws XPathException { context.setBackwardsCompatibility(false); context.setStaticallyKnownDocuments(docs); context.setBaseURI(baseUri == null ? new AnyURIValue("/db") : baseUri); if (bindVariables) { for (Map.Entry<QName, Object> entry : bindings.entrySet()) { context.declareVariable( new org.exist.dom.QName( entry.getKey().getLocalPart(), entry.getKey().getNamespaceURI(), entry.getKey().getPrefix()), convertValue(entry.getValue())); } if (params != null) for (int i = 0; i < params.length; i++) { Object convertedValue = convertValue(params[i]); if (docsToLock != null && convertedValue instanceof Sequence) { docsToLock.addAll(((Sequence) convertedValue).getDocumentSet()); } context.declareVariable("_" + (i + 1), convertedValue); } } }