Package org.exist.xquery.value

Examples of org.exist.xquery.value.IntegerValue


                    ((ValueSequence)resultSequence).keepUnOrdered(unordered);
                }
            }
            Sequence val = null;
            int p = 1;
            final IntegerValue atVal = new IntegerValue(1);
            if(positionalVariable != null)
                {at.setValue(atVal);}
            //Type.EMPTY is *not* a subtype of other types ;
            //the tests below would fail without this prior cardinality check
            if (in.isEmpty() && sequenceType != null &&
                    !Cardinality.checkCardinality(sequenceType.getCardinality(),
                    Cardinality.EMPTY)) {
                throw new XPathException(this, ErrorCodes.XPTY0004,
                    "Invalid cardinality for variable $" + varName +
                    ". Expected " + Cardinality.getDescription(sequenceType.getCardinality()) +
                    ", got " + Cardinality.getDescription(in.getCardinality()));
            }
            // Loop through each variable binding
            p = 0;
            for (final SequenceIterator i = in.iterate(); i.hasNext(); p++) {
                context.proceed(this);
                contextItem = i.nextItem();
                context.setContextSequencePosition(p, in);
                if (positionalVariable != null)
                    {at.setValue(new IntegerValue(p + 1));}
                contextSequence = contextItem.toSequence();
                // set variable value to current item
                var.setValue(contextSequence);
                if (sequenceType == null)
                    {var.checkType();} //because it makes some conversions !
                val = contextSequence;
                // check optional where clause
                if (whereExpr != null && (!fastExec)) {
                    if (contextItem instanceof NodeProxy)
                        {((NodeProxy)contextItem).addContextNode(getExpressionId(), (NodeProxy)contextItem);}
                    final Sequence bool = applyWhereExpression(null);
                    if (contextItem instanceof NodeProxy)
                        {((NodeProxy)contextItem).clearContext(getExpressionId());}
                    // if where returned false, continue
                    if (!bool.effectiveBooleanValue())
                        {continue;}
                } else {
                    val = contextItem.toSequence();
                }
                //Reset the context position
                context.setContextSequencePosition(0, null);
                if (groupedSequence==null) {
                    if (returnExpr instanceof BindingExpression) {
                        ((BindingExpression)returnExpr).eval(null, null, resultSequence, null);
                    // otherwise call the return expression and add results to resultSequence
                    } else {
                        val = returnExpr.eval(null);
                        resultSequence.addAll(val);
                    }
                } else {
                    /* bv : special processing for groupby :
                    if returnExpr is a Binding expression, pass the groupedSequence. 
                    Else, add item to groupedSequence and don't evaluate here ! 
                     */
                    if (returnExpr instanceof BindingExpression){
                        ((BindingExpression)returnExpr).eval(null, null, resultSequence, groupedSequence);
                    } else {
                        final Sequence toGroupSequence = context.resolveVariable(groupedSequence.getToGroupVarName()).getValue();
                        groupedSequence.addAll(toGroupSequence);
                    }
                }
                // free resources
                var.destroy(context, resultSequence);
            }
        } finally {
            // restore the local variable stack
            context.popLocalVariables(mark, resultSequence);
        }
        // bv : Special processing for groupBy : one return per group in groupedSequence
        if (groupSpecs!=null) {
            mark = context.markLocalVariables(false);
            context.declareVariableBinding(var);

            // Declare positional variable if required
            LocalVariable at = null;
            if (positionalVariable != null) {
                at = new LocalVariable(QName.parse(context, positionalVariable, null));
                at.setSequenceType(POSITIONAL_VAR_TYPE);
                context.declareVariableBinding(at);
            }
            final IntegerValue atVal = new IntegerValue(1);
            if(positionalVariable != null) {
                at.setValue(atVal);
            }

            int p = 0;
            for (final Iterator<String> it = groupedSequence.iterate(); it.hasNext(); ) {
                final GroupedValueSequence currentGroup = groupedSequence.get(it.next());
                context.proceed(this);
                // set binding variable to current group
                var.setValue(currentGroup);
                var.checkType();
                //set value of grouping keys for the current group
                for (int i=0; i< groupKeyVar.length ; i ++) {
                    groupKeyVar[i].setValue(currentGroup.getGroupKey().itemAt(i).toSequence());
                }
                if (positionalVariable != null) {
                    final ValueSequence ps = new ValueSequence();
                    for (int i = 0; i < currentGroup.getItemCount(); i++) {
                        ps.add(new IntegerValue(p + i + 1));
                    }
                    at.setValue(ps);
                }
                //evaluate real return expression
                final Sequence val = groupReturnExpr.eval(null);
View Full Code Here


       
        } else if(isCalledAs(qnHostname.getLocalName())) {
            result = new StringValue(request.getHostname());
       
        } else if(isCalledAs(qnPort.getLocalName())) {
            result = new IntegerValue(request.getPort());

        } else if(isCalledAs(qnPath.getLocalName())) {
            result = new StringValue(request.getPath());
           
        } else if(isCalledAs(qnQuery.getLocalName())) {
View Full Code Here

       
        } else if(isCalledAs(qnRemoteAddress.getLocalName())) {
            result = new StringValue(request.getRemoteAddress());

        } else if(isCalledAs(qnRemotePort.getLocalName())) {
            result = new IntegerValue(request.getRemotePort());
              
        } else {
            throw new XPathException(this, "Unknown function call: " + getSignature());
        }
       
View Full Code Here

        int j = 1;
        for (final SequenceIterator i = args[0].iterate(); i.hasNext(); j++) {
          final AtomicValue next = i.nextItem().atomize();
          try {
            if (ValueComparison.compareAtomic(collator, next, srch, Constants.TRUNC_NONE, Constants.EQ))
              {result.add(new IntegerValue(j));}
          } catch (final XPathException e) {
            //Ignore me : values can not be compared
          }
        }       
        }
View Full Code Here

      result = Sequence.EMPTY_SEQUENCE;
    } else {
      final Sequence arg = args[0];
      final DurationValue duration = new DurationValue(((DurationValue) arg.itemAt(0)).getCanonicalDuration());
      if (isCalledAs("days-from-duration")) {
            result = new IntegerValue(duration.getPart(DurationValue.DAY));
      } else if (isCalledAs("hours-from-duration")) {
            result = new IntegerValue(duration.getPart(DurationValue.HOUR));
      } else if (isCalledAs("minutes-from-duration")) {
            result = new IntegerValue(duration.getPart(DurationValue.MINUTE));
      } else if (isCalledAs("seconds-from-duration")) {
        if (duration.getCanonicalDuration().getField(DatatypeConstants.SECONDS) == null)
          {result = new DecimalValue(0);}
        else
          {result = new DecimalValue((BigDecimal)duration.getCanonicalDuration().getField(DatatypeConstants.SECONDS));}
        if (duration.getCanonicalDuration().getSign() < 0)
          {result = ((DecimalValue)result).negate();}
      } else if (isCalledAs("months-from-duration")) {
            result = new IntegerValue(duration.getPart(DurationValue.MONTH));
      } else if (isCalledAs("years-from-duration")) {
            result = new IntegerValue(duration.getPart(DurationValue.YEAR));
      } else {
                logger.error("can't handle function " + mySignature.getName().getLocalName());
        throw new Error("can't handle function " + mySignature.getName().getLocalName());
      }
    }
View Full Code Here

            {contextSequence = contextItem.toSequence();}
        Sequence result;
        if (getArgumentCount() == 0)
            {result = IntegerValue.ZERO;}
        else
            {result = new IntegerValue(getArgument(0).eval(contextSequence).getItemCount());}
        if (context.getProfiler().isEnabled())
            {context.getProfiler().end(this, "", result);}
        return result;
    }
View Full Code Here

            if (contextItem != null)
                {context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT ITEM", contextItem.toSequence());}
        }              
       
        Sequence result;
    IntegerValue precision = null;
    final Sequence seq = getArgument(0).eval(contextSequence, contextItem);
    if (seq.isEmpty())
      {result = Sequence.EMPTY_SEQUENCE;}
        else {   
            if (contextItem != null)
View Full Code Here

            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)
                    NumericValue endingLoc;
                    if (!length.isInfinite()) {
                        endingLoc = (NumericValue) new IntegerValue(startingLoc.getInt() + length.getInt());
                    } else {
                        endingLoc = length;
                    }
          //check for a valid end position for the substring
          if(!validEndPosition(endingLoc, startingLoc)) {
View Full Code Here

            result = Sequence.EMPTY_SEQUENCE;
        } else {
            final Collator collator = getCollator(contextSequence, contextItem, 3);   
            final int comparison = Collations.compare(collator, seq1.getStringValue(), seq2.getStringValue());
            if (comparison == Constants.EQUAL)
                {result = new IntegerValue(Constants.EQUAL);}
            else if (comparison < 0)
                {result = new IntegerValue(Constants.INFERIOR);}
            else
                {result = new IntegerValue(Constants.SUPERIOR);}
        }
        if (context.getProfiler().isEnabled())
            {context.getProfiler().end(this, "", result);}
        return result;
  }
View Full Code Here

   
    Sequence result;
    if (inSequence.isEmpty())
            {result = Sequence.EMPTY_SEQUENCE;}
        else
            {result = new IntegerValue(context.getContextPosition() + 1);}
       
        if (context.getProfiler().isEnabled())
            {context.getProfiler().end(this, "", result);}
       
        return result;        
View Full Code Here

TOP

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

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.