Beispiel #1
0
 private void buildXQueryStaticContext(XQueryContext context, boolean importModules)
     throws XPathException {
   context.declareNamespaces(namespaceBindings.getCombinedMap());
   for (Map.Entry<String, Document> entry : moduleMap.entrySet()) {
     context.importModule(entry.getKey(), null, "xmldb:exist:///db" + entry.getValue().path());
   }
 }
Beispiel #2
0
 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);
       }
   }
 }
Beispiel #3
0
 private org.exist.source.Source buildQuerySource(String query, Object[] params, String cookie) {
   Map<String, String> combinedMap = namespaceBindings.getCombinedMap();
   for (Map.Entry<String, Document> entry : moduleMap.entrySet()) {
     combinedMap.put("<module> " + entry.getKey(), entry.getValue().path());
   }
   for (Map.Entry<QName, Object> entry : bindings.entrySet()) {
     combinedMap.put(
         "<var> " + entry.getKey(),
         null); // don't care about values, as long as the same vars are bound
   }
   combinedMap.put("<posvars> " + params.length, null);
   combinedMap.put("<cookie>", cookie);
   // TODO: should include statically known documents and baseURI too?
   return new StringSourceWithMapKey(query, combinedMap);
 }
Beispiel #4
0
 /**
  * Clone this query service, optionally overriding the clone's namespace and variable bindings. If
  * the namespace bindings override or variable bindings override is specified, then that object is
  * cloned and used for its respective purpose. If an override is not specified, the bindings are
  * cloned from the original query service.
  *
  * @param nsBindingsOverride the namespace bindings to clone, or <code>null</code> to clone from
  *     the original
  * @param varBindingsOverride the variable bindings to clone, or <code>null</code> to clone from
  *     the original
  * @return a clone of this query service with bindings optionally overridden
  */
 public QueryService clone(NamespaceMap nsBindingsOverride, Map<QName, ?> varBindingsOverride) {
   try {
     QueryService that = (QueryService) super.clone();
     that.namespaceBindings =
         nsBindingsOverride != null ? nsBindingsOverride.clone() : that.namespaceBindings.clone();
     if (varBindingsOverride == null) {
       that.bindings = new HashMap<QName, Object>(that.bindings);
     } else {
       that.bindings = new HashMap<QName, Object>();
       for (Map.Entry<QName, ?> entry : varBindingsOverride.entrySet()) {
         that.let(entry.getKey(), entry.getValue());
       }
     }
     that.moduleMap = new TreeMap<String, Document>(moduleMap);
     return that;
   } catch (CloneNotSupportedException e) {
     throw new RuntimeException("unexpected exception", e);
   }
 }