Package org.exist.xquery.value

Examples of org.exist.xquery.value.FunctionReference


   
    final FunctionCall call = new FunctionCall(context, function);
    call.setLocation(function.getLine(), function.getColumn());
    function.setCaller(call);
    function.analyze(cachedContextInfo);
    return new FunctionReference(call);
  }
View Full Code Here


  }

  @Override
  public Sequence eval(Sequence contextSequence, Item contextItem)
      throws XPathException {
    return new FunctionReference(resolvedFunction);
  }
View Full Code Here

  }

  @Override
  public Sequence eval(Sequence contextSequence, Item contextItem)
      throws XPathException {
    final FunctionReference newRef = createPartial(contextSequence, contextItem, function);
    return newRef;
  }
View Full Code Here

   
    func.setFunctionBody(innerCall);
   
    final FunctionCall newCall = new FunctionCall(context, func);
    newCall.setLocation(staticCall.getLine(), staticCall.getColumn());
    return new FunctionReference(newCall);
  }
View Full Code Here

            /* binary content */
            BinaryValue binary = (BinaryValue) args[0].itemAt(0);

            /* callback function */
            FunctionReference ref = (FunctionReference) args[2].itemAt(0);

            Map<String, String> mappings = new HashMap<>();
            if (args[3].hasOne()) {
                NodeValue namespaces = (NodeValue) args[3].itemAt(0);
                parseMappings(namespaces, mappings);
View Full Code Here

    String jid = args[1].itemAt(0).getStringValue();
   
        if(!(args[2].itemAt(0) instanceof FunctionReference))
            throw new XPathException("No chat listener function provided.");
       
        FunctionReference chatListenerFunctionRef = (FunctionReference)args[2].itemAt(0);
       
        FunctionSignature chatListenerFunctionSig = chatListenerFunctionRef.getSignature();
        if(chatListenerFunctionSig.getArgumentCount() < 3)
            throw new XPathException("Chat listener function must take at least 3 arguments.");
        chatListenerFunctionRef.setContext(context.copyContext());
       
        Sequence listenerParam = args[3];
       
        long chatHandle = XMPPModule.getHandle();
   
View Full Code Here

    public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
        if (args[0].isEmpty())
            return Sequence.EMPTY_SEQUENCE;

        FunctionReference func = (FunctionReference) args[1].itemAt(0);

        NGramIndexWorker index = (NGramIndexWorker) context.getBroker().getIndexController().getWorkerByIndexId(NGramIndex.ID);
        MemTreeBuilder builder = context.getDocumentBuilder();
        DocumentBuilderReceiver docBuilder = new DocumentBuilderReceiver(builder);
        MatchCallback matchCb = new MatchCallback(func, docBuilder);
View Full Code Here

            processMonitor = broker.getBrokerPool().getProcessMonitor();
            xqueryContext.getProfiler().traceQueryStart();
            processMonitor.queryStarted(xqueryContext.getWatchDog());
           
            //create a function call
            final FunctionReference fnRef = new FunctionReference(new FunctionCall(xqueryContext, fn));
           
            //convert the arguments
            final org.exist.xquery.value.Sequence[] fnArgs = convertToExistFunctionArguments(xqueryContext, fn, arguments);
           
            //execute the function call
            fnRef.analyze(new AnalyzeContextInfo());
            final org.exist.xquery.value.Sequence result = fnRef.evalFunction(null, null, fnArgs);
           
            return new SequenceAdapter(result);
        } catch(final URISyntaxException use) {
            throw new RestXqServiceException(use.getMessage(), use);
        } catch(final PermissionDeniedException pde) {
View Full Code Here

  @Override
  public Sequence eval(Sequence[] args, Sequence contextSequence)
      throws XPathException {
        Sequence result = new ValueSequence();
        if (isCalledAs("map")) {
            final FunctionReference ref = (FunctionReference) args[0].itemAt(0);
            ref.analyze(cachedContextInfo);
            for (final SequenceIterator i = args[1].iterate(); i.hasNext(); ) {
                final Item item = i.nextItem();
                final Sequence r = ref.evalFunction(contextSequence, null, new Sequence[]{item.toSequence()});
                result.addAll(r);
            }
        } else if (isCalledAs("for-each")) {
            final FunctionReference ref = (FunctionReference) args[1].itemAt(0);
            ref.analyze(cachedContextInfo);
            for (final SequenceIterator i = args[0].iterate(); i.hasNext(); ) {
                final Item item = i.nextItem();
                final Sequence r = ref.evalFunction(contextSequence, null, new Sequence[]{item.toSequence()});
                result.addAll(r);
            }
        } else if (isCalledAs("filter")) {
            FunctionReference ref;
            Sequence seq;
            // Hack: switch parameters for backwards compatibility
            if (Type.subTypeOf(args[1].getItemType(), Type.FUNCTION_REFERENCE)) {
                ref = (FunctionReference) args[1].itemAt(0);
                seq = args[0];
            } else {
                ref = (FunctionReference) args[0].itemAt(0);
                seq = args[1];
            }

            ref.analyze(cachedContextInfo);
          for (final SequenceIterator i = seq.iterate(); i.hasNext(); ) {
            final Item item = i.nextItem();
            final Sequence r = ref.evalFunction(contextSequence, null, new Sequence[] { item.toSequence() });
            if (r.effectiveBooleanValue())
              {result.add(item);}
          }
        } else if (isCalledAs("fold-left")) {
            final FunctionReference ref = (FunctionReference) args[2].itemAt(0);
            ref.analyze(cachedContextInfo);
          Sequence zero = args[1];
          Sequence input = args[0];
          while (!input.isEmpty()) {
            final SequenceIterator i = input.iterate();
            zero = ref.evalFunction(contextSequence, null, new Sequence[] { zero, i.nextItem().toSequence() });
            ValueSequence tail = new ValueSequence();
            while (i.hasNext()) {
              tail.add(i.nextItem());
            }
            input = tail;
          }
          result = zero;
        } else if (isCalledAs("fold-right")) {
            final FunctionReference ref = (FunctionReference) args[2].itemAt(0);
            ref.analyze(cachedContextInfo);
          final Sequence zero = args[1];
          final Sequence input = args[0];
          result = foldRight(ref, zero, input, contextSequence);
        } else if (isCalledAs("map-pairs")) {
            final FunctionReference ref = (FunctionReference) args[0];
            ref.analyze(cachedContextInfo);
          final SequenceIterator i1 = args[1].iterate();
          final SequenceIterator i2 = args[2].iterate();
          while (i1.hasNext() && i2.hasNext()) {
            final Sequence r = ref.evalFunction(contextSequence, null,
                new Sequence[] { i1.nextItem().toSequence(), i2.nextItem().toSequence() });
            result.addAll(r);
          }
        } else if (isCalledAs("for-each-pair")) {
            final FunctionReference ref = (FunctionReference) args[2].itemAt(0);
            ref.analyze(cachedContextInfo);
            final SequenceIterator i1 = args[0].iterate();
            final SequenceIterator i2 = args[1].iterate();
            while (i1.hasNext() && i2.hasNext()) {
                final Sequence r = ref.evalFunction(contextSequence, null,
                        new Sequence[] { i1.nextItem().toSequence(), i2.nextItem().toSequence() });
                result.addAll(r);
            }
        }
    return result;
View Full Code Here

                        // return empty sequence for all "function not found" related errors
                        return Sequence.EMPTY_SEQUENCE;
                    }
                    throw e;
                }
          return call == null ? Sequence.EMPTY_SEQUENCE : new FunctionReference(call);
      } else if (isCalledAs("function-name")) {
        final FunctionReference ref = (FunctionReference) args[0].itemAt(0);
        final QName qname = ref.getSignature().getName();
        if (qname == null || qname == InlineFunction.INLINE_FUNCTION_QNAME)
          {return Sequence.EMPTY_SEQUENCE;}
        else
          {return new QNameValue(context, qname);}
      } else {
        // isCalledAs("function-arity")
        final FunctionReference ref = (FunctionReference) args[0].itemAt(0);
        return new IntegerValue(ref.getSignature().getArgumentCount());
      }
    } catch (final Exception e) {
      if (e instanceof XPathException)
        {throw (XPathException)e;}
      else
View Full Code Here

TOP

Related Classes of org.exist.xquery.value.FunctionReference

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.