Package org.exist.xquery

Examples of org.exist.xquery.Expression


    processAll();
  }
 
  private void processAll() throws XPathException {
    for(int i = 0; i < orderSpecs.length; i++) {
      final Expression expr = orderSpecs[i].getSortExpression();
      final NodeSet result = expr.eval(null).toNodeSet();
      for(final Iterator j = result.iterator(); j.hasNext(); ) {
        final NodeProxy p = (NodeProxy)j.next();
        ContextItem context = p.getContext();
        //TODO : review to consider transverse context
        while(context != null) {
View Full Code Here


  /* (non-Javadoc)
   * @see org.exist.xquery.Function#setArguments(java.util.List)
   */
  public void setArguments(List<Expression> arguments) throws XPathException {
        Expression arg = arguments.get(0);
        arg = new DynamicCardinalityCheck(context, Cardinality.ZERO_OR_ONE, arg,
                new Error(Error.FUNC_PARAM_CARDINALITY, "1", mySignature));   
        if(!Type.subTypeOf(arg.returnsType(), Type.ATOMIC))
            {arg = new Atomize(context, arg);}
        steps.add(arg);
       
        arg = arguments.get(1);
        arg = new DynamicCardinalityCheck(context, Cardinality.EXACTLY_ONE, arg,
                new Error(Error.FUNC_PARAM_CARDINALITY, "2", mySignature));
        if(!Type.subTypeOf(arg.returnsType(), Type.ATOMIC))
            {arg = new Atomize(context, arg);}
        steps.add(arg);
       
        arg = arguments.get(2);
        arg = new DynamicCardinalityCheck(context, Cardinality.EXACTLY_ONE, arg,
                new Error(Error.FUNC_PARAM_CARDINALITY, "3", mySignature));
        if(!Type.subTypeOf(arg.returnsType(), Type.ATOMIC))
            {arg = new Atomize(context, arg);}
        steps.add(arg);
       
        if (arguments.size() == 4) {
            arg = arguments.get(3);
            arg = new DynamicCardinalityCheck(context, Cardinality.EXACTLY_ONE, arg,
                    new Error(Error.FUNC_PARAM_CARDINALITY, "4", mySignature));
            if(!Type.subTypeOf(arg.returnsType(), Type.ATOMIC))
                {arg = new Atomize(context, arg);}
            steps.add(arg);           
        }
  }
View Full Code Here

        if(contextItem != null)
      {contextSequence = contextItem.toSequence();}

        Sequence result;
        boolean processInMem = false;
        final Expression arg = getArgument(0);
    final Sequence idval = arg.eval(contextSequence);
   
    if(idval.isEmpty() || (getArgumentCount() == 1 && contextSequence != null && contextSequence.isEmpty()))
            {result = Sequence.EMPTY_SEQUENCE;}
        else {
        String nextId;
View Full Code Here

          
    if(contextItem != null)
      {contextSequence = contextItem.toSequence();}
   
        Sequence result;
        final Expression arg = getArgument(0);   
    // case 1: if the argument expression returns a node set,
    // subtract the set from the context node set and return
    // the remaining set
    if (Type.subTypeOf(arg.returnsType(), Type.NODE) &&
            (contextSequence == null || contextSequence.isPersistentSet()) &&
            !Dependency.dependsOn(arg, Dependency.CONTEXT_ITEM)) {
      if (contextSequence == null || contextSequence.isEmpty()) {
        // TODO: special treatment if the context sequence is empty:
        // within a predicate, we just return the empty sequence
        // otherwise evaluate the argument and return a boolean result         
//        if (inPredicate && !inWhereClause)
//                    result = Sequence.EMPTY_SEQUENCE;
//        else
                    result = evalBoolean(contextSequence, contextItem, arg);
      } else {
          result = contextSequence.toNodeSet().copy();

          if (inPredicate) {
            for (final SequenceIterator i = result.iterate(); i.hasNext();) {
              final NodeProxy item = (NodeProxy) i.nextItem();
//              item.addContextNode(getExpressionId(), item);
              if (contextId != Expression.NO_CONTEXT_ID)
                            {item.addContextNode(contextId, item);}
              else
                {item.addContextNode(getExpressionId(), item);}
            }
          }

          // evaluate argument expression
          final Sequence argSeq = arg.eval(result);
          NodeSet argSet;
          if (contextId != Expression.NO_CONTEXT_ID) {
            argSet = argSeq.toNodeSet().getContextNodes(contextId);
          } else {
            argSet = argSeq.toNodeSet().getContextNodes(getExpressionId());
View Full Code Here

            if (contextItem != null)
                {context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT ITEM", contextItem.toSequence());}
        } 
       
    //get arguments
        final Expression argSourceString = getArgument(0);
    final Expression argStartingLoc = getArgument(1);
    Expression argLength = null;
   
    //get the context sequence
    if(contextItem != null)
      {contextSequence = contextItem.toSequence();}
        Sequence result;
    final Sequence seqSourceString = argSourceString.eval(contextSequence);
   
    //If the value of $sourceString is the empty sequence return EMPTY_STRING, there must be a string to operate on!
    if(seqSourceString.isEmpty()) {
      result = StringValue.EMPTY_STRING;
    } else {
      //get the string to substring
          final String sourceString = seqSourceString.getStringValue();
       
          //check for a valid start position for the substring
          final NumericValue startingLoc = ((NumericValue)(argStartingLoc.eval(contextSequence).itemAt(0).convertTo(Type.NUMBER))).round();
          if(!validStartPosition(startingLoc, sourceString.length())) {
            //invalid start position
            result = StringValue.EMPTY_STRING;
          } else {
        //are there 2 or 3 arguments to this function?
        if(getArgumentCount() > 2) {
          argLength = getArgument(2);
                    NumericValue length = new IntegerValue(sourceString.length());
                    length = ((NumericValue)(argLength.eval(contextSequence).itemAt(0).convertTo(Type.NUMBER))).round();

                    // Relocate length to position according to spec:
                    // fn:round($startingLoc) <=
                    // $p
                    // < fn:round($startingLoc) + fn:round($length)
View Full Code Here

        final List<LocationStep> steps = BasicExpressionVisitor.findLocationSteps(getArgument(0));
        if (!steps.isEmpty()) {
            LocationStep firstStep = steps.get(0);
            LocationStep lastStep = steps.get(steps.size() - 1);
            if (firstStep != null && steps.size() == 1 && firstStep.getAxis() == Constants.SELF_AXIS) {
                final Expression outerExpr = contextInfo.getContextStep();
                if (outerExpr != null && outerExpr instanceof LocationStep) {
                    final LocationStep outerStep = (LocationStep) outerExpr;
                    final NodeTest test = outerStep.getTest();
                    if (!test.isWildcardTest() && test.getName() != null) {
                        contextQName = new QName(test.getName());
View Full Code Here

          {return Sequence.EMPTY_SEQUENCE;}
       
        if (preselectResult == null && !checkForQNameIndex(contextSequence))
            {contextQName = null;}

        final Expression path = getArgument(0);
        NodeSet result;
    // if the expression does not depend on the current context item,
    // we can evaluate it in one single step
    if (path == null || !Dependency.dependsOn(path, Dependency.CONTEXT_ITEM)) {
      final boolean canCache =
                (getTermDependencies() & Dependency.CONTEXT_ITEM) == Dependency.NO_DEPENDENCY;
            ifcanCache && cached != null && cached.isValid(contextSequence, contextItem)) {
        return cached.getResult();
      }
            // do we optimize this expression?
            if (contextStep == null || preselectResult == null) {
                // no optimization: process the whole expression
                final NodeSet nodes =
                    path == null
                        ? contextSequence.toNodeSet()
                        : path.eval(contextSequence).toNodeSet();
                final List<String> terms = getSearchTerms(contextSequence);
                result = evalQuery(nodes, terms).toNodeSet();
            } else {
                contextStep.setPreloadedData(contextSequence.getDocumentSet(), preselectResult);
                result = path.eval(contextSequence).toNodeSet();
            }
            if(canCache && contextSequence.isCacheable())
        {cached = new CachedResult(contextSequence, contextItem, result);}

    // otherwise we have to walk through each item in the context
    } else {
      Item current;
      final @SuppressWarnings("unused")
      String arg;
      NodeSet nodes;
      result = new ExtArrayNodeSet();
      Sequence temp;
      for (final SequenceIterator i = contextSequence.iterate(); i.hasNext();) {
        current = i.nextItem();
        final List<String> terms = getSearchTerms(contextSequence);
        nodes =
          path == null
          ? contextSequence.toNodeSet()
              : path
              .eval(current.toSequence()).toNodeSet();
        temp = evalQuery(nodes, terms);
        result.addAll(temp);
      }
    }
View Full Code Here

    protected List<String> getSearchTerms(Sequence contextSequence) throws XPathException {
    if(getArgumentCount() < 2)
      {throw new XPathException(this, "function requires at least 2 arguments");}
    final List<String> terms = new ArrayList<String>();
    Expression next;
    Sequence seq;
    for(int i = 1; i < getLength(); i++) {
      next = getArgument(i);
      seq = next.eval(contextSequence);
      if(seq.hasOne())
          {terms.add(translateRegexp(seq.itemAt(0).getStringValue()));}
      else {
        for(final SequenceIterator it = seq.iterate(); it.hasNext(); ) {
            terms.add(translateRegexp(it.nextItem().getStringValue()));
View Full Code Here

        }
    }

    public void validate() throws XPathException {
        for (int pos = 0; pos < this.getLength(); pos++) {
            Expression expr = this.getExpression(pos);
            if (expr instanceof ValueOf) {
                ValueOf valueOf = (ValueOf) expr;
                valueOf.validate();
                valueOf.sequenceItSelf = true;
            } else if (expr instanceof ApplyTemplates) {
View Full Code Here

           
            //TODO this is a workaround?
            declareVariables(xqueryContext);
           
            //START workaround: evaluate global variables in modules, as they are reset by XQueryContext.reset()
            final Expression rootExpr = xqueryContext.getRootExpression();
            for(int i = 0; i < rootExpr.getSubExpressionCount(); i++) {
                final Expression subExpr = rootExpr.getSubExpression(i);
                if(subExpr instanceof VariableDeclaration) {
                    subExpr.eval(null);
                }
            }
            //END workaround
           
            //setup monitoring
View Full Code Here

TOP

Related Classes of org.exist.xquery.Expression

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.