Package org.exist.xquery.value

Examples of org.exist.xquery.value.Sequence


                    "CONTEXT SEQUENCE", contextSequence);}
            if (contextItem != null)
                {context.getProfiler().message(this, Profiler.START_SEQUENCES,
                    "CONTEXT ITEM", contextItem.toSequence());}
        }
        final Sequence lseq = getLeft().eval(contextSequence, contextItem);
        final Sequence rseq = getRight().eval(contextSequence, contextItem);
        if (lseq.hasMany())
            {throw new XPathException(this, ErrorCodes.XPTY0004,
                "Too many operands at the left of " + Constants.OPS[operator]);}
        if (rseq.hasMany())
            {throw new XPathException(this, ErrorCodes.XPTY0004,
                "Too many operands at the right of " + Constants.OPS[operator]);}
        Sequence result;
        if (rseq.isEmpty())
            {result = Sequence.EMPTY_SEQUENCE;}
        else if (lseq.isEmpty())
            {result = Sequence.EMPTY_SEQUENCE;}
        else {
            Item lvalue = lseq.itemAt(0);
            Item rvalue = rseq.itemAt(0);
            try {
                if (lvalue.getType() == Type.UNTYPED_ATOMIC || lvalue.getType() == Type.ATOMIC)
                    {lvalue = lvalue.convertTo(Type.NUMBER);}
                if (rvalue.getType() == Type.UNTYPED_ATOMIC || rvalue.getType() == Type.ATOMIC)
                    {rvalue = rvalue.convertTo(Type.NUMBER);}
                if (!(lvalue instanceof ComputableValue))
                    {throw new XPathException(this, ErrorCodes.XPTY0004, "'" +
                        Type.getTypeName(lvalue.getType()) + "(" + lvalue + ")' can not be an operand for " +
                        Constants.OPS[operator]);}
                if (!(rvalue instanceof ComputableValue))
                    {throw new XPathException(this, ErrorCodes.XPTY0004, "'" +
                        Type.getTypeName(rvalue.getType()) + "(" + rvalue + ")' can not be an operand for " +
                        Constants.OPS[operator]);}
                //TODO : move to implementations
                if (operator == Constants.IDIV) {
                    if (!Type.subTypeOf(lvalue.getType(), Type.NUMBER))
                        {throw new XPathException(this, ErrorCodes.XPTY0004, "'" +
                            Type.getTypeName(lvalue.getType()) + "(" + lvalue + ")' can not be an operand for " + Constants.OPS[operator]);}
                    if (!Type.subTypeOf(rvalue.getType(), Type.NUMBER))
                        {throw new XPathException(this, ErrorCodes.XPTY0004, "'" +
                            Type.getTypeName(rvalue.getType()) + "(" + rvalue + ")' can not be an operand for " + Constants.OPS[operator]);}
                    //If the divisor is (positive or negative) zero, then an error is raised [err:FOAR0001]
                    if (((NumericValue)rvalue).isZero())
                        {throw new XPathException(this, ErrorCodes.FOAR0001, "Division by zero");}
                    //If either operand is NaN then an error is raised [err:FOAR0002].
                    if (((NumericValue)lvalue).isNaN())
                        {throw new XPathException(this, ErrorCodes.FOAR0002, "Division of " +
                            Type.getTypeName(lvalue.getType()) + "(" + lvalue + ")'");}
                    //If either operand is NaN then an error is raised [err:FOAR0002].
                    if (((NumericValue)rvalue).isNaN())
                        {throw new XPathException(this, ErrorCodes.FOAR0002, "Division of " +
                            Type.getTypeName(rvalue.getType()) + "(" + rvalue + ")'");}
                    //If $arg1 is INF or -INF then an error is raised [err:FOAR0002].
                    if (((NumericValue)lvalue).isInfinite())
                        {throw new XPathException(this, ErrorCodes.FOAR0002, "Division of " +
                            Type.getTypeName(lvalue.getType()) + "(" + lvalue + ")'");}
                    result = ((NumericValue) lvalue).idiv((NumericValue) rvalue);
                } else {
                    result = applyOperator((ComputableValue) lvalue, (ComputableValue) rvalue);
                }
                //TODO : type-checks on MOD operator : maybe the same ones than above -pb
            } catch (final XPathException e) {
                e.setLocation(line, column);
                throw e;
            }
        }
        if (context.getProfiler().isEnabled())
            {context.getProfiler().end(this, "", result);}
        //Sets the return type if not already set
        if (returnType == Type.ATOMIC)
            //TODO : refine previously set type ? -pb
            {returnType = result.getItemType();}
        return result;
    }
View Full Code Here


                {context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);}
            if (contextItem != null)
                {context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT ITEM", contextItem.toSequence());}
        }       
   
        final Sequence result = atomize(expression.eval(contextSequence, contextItem));

        if (context.getProfiler().isEnabled())          
            {context.getProfiler().end(this, "", result);}  
    
        return result;
View Full Code Here

  }

  protected Sequence genericCompare(Sequence contextSequence, Item contextItem) throws XPathException {
        if (context.getProfiler().isEnabled())
            {context.getProfiler().message(this, Profiler.OPTIMIZATION_FLAGS, "OPTIMIZATION CHOICE", "genericCompare");
    final Sequence ls = getLeft().eval(contextSequence, contextItem);
    final Sequence rs = getRight().eval(contextSequence, contextItem);
    if(ls.isEmpty() || rs.isEmpty())
      {return Sequence.EMPTY_SEQUENCE;}
    if (ls.hasOne() && rs.hasOne()) {
            AtomicValue lv, rv;
      lv = ls.itemAt(0).atomize();
      rv = rs.itemAt(0).atomize();
            final Collator collator = getCollator(contextSequence);
      return BooleanValue.valueOf(compareAtomic(collator, lv, rv, Constants.TRUNC_NONE, relation));
    }
        throw new XPathException(this, "Type error: sequence with more than one item is not allowed here");
  }
View Full Code Here

                if (context==null) {
                   throw new XPathException(this,"Context is missing for node set comparison");
                }
                do {
                    final AtomicValue lv = current.atomize();
                    final Sequence rs = getRight().eval(context.getNode().toSequence());                   
                    if (!rs.hasOne())
                        {throw new XPathException(this,
                                "Type error: sequence with less or more than one item is not allowed here");}                   
                    if (compareAtomic(collator, lv, rs.itemAt(0).atomize(), Constants.TRUNC_NONE, relation))
                        {result.add(current);}
                } while ((context = context.getNextDirect()) != null);
            }
        } else {
            final Sequence rs = getRight().eval(null);
            if (!rs.hasOne())
                {throw new XPathException(this,
                        "Type error: sequence with less or more than one item is not allowed here");}
            final AtomicValue rv = rs.itemAt(0).atomize();
            for (final Iterator<NodeProxy> i = nodes.iterator(); i.hasNext();) {
                final NodeProxy current = i.next();
                final AtomicValue lv = current.atomize();
                if (compareAtomic(collator, lv, rv, Constants.TRUNC_NONE, Constants.EQ))
                    {result.add(current);}
View Full Code Here

                "CONTEXT SEQUENCE", contextSequence);}
            if (contextItem != null)
                {context.getProfiler().message(this, Profiler.START_SEQUENCES,
                "CONTEXT ITEM", contextItem.toSequence());}
        }
        Sequence lval = left.eval(contextSequence, contextItem);
        final Sequence rval = right.eval(contextSequence, contextItem);
        lval.removeDuplicates();
        rval.removeDuplicates();
        Sequence result;
        if (lval.isEmpty()) {
            result = Sequence.EMPTY_SEQUENCE;
        } else if (rval.isEmpty()) {
            if (!Type.subTypeOf(lval.getItemType(), Type.NODE))
                {throw new XPathException(this, ErrorCodes.XPTY0004, "Operand is not a node sequence");}
            result = lval;
        } else {
            if (!(Type.subTypeOf(lval.getItemType(), Type.NODE) && Type.subTypeOf(rval.getItemType(), Type.NODE)))
                {throw new XPathException(this, ErrorCodes.XPTY0004, "Operand is not a node sequence");}
            if (lval.isPersistentSet() && rval.isPersistentSet())
                {result = lval.toNodeSet().except(rval.toNodeSet());}
            else {
                result = new ValueSequence();
                final Set<Item> set = new TreeSet<Item>();
                for (final SequenceIterator i = rval.unorderedIterator(); i.hasNext(); )
                    set.add(i.nextItem());
                for (final SequenceIterator i = lval.unorderedIterator(); i.hasNext(); ) {
                    final Item next = i.nextItem();
                    if (!set.contains(next))
                        {result.add(next);}
                }
                result.removeDuplicates();
            }
        }
        if (context.getProfiler().isEnabled())
            {context.getProfiler().end(this, "", result);}
        return result;
View Full Code Here

       
    final Module myModule = context.getRootModule(qn.getNamespaceURI());   
        context.pushDocumentContext();
        context.prologEnter(this);
    // declare the variable
    final Sequence seq = expression.eval(null, null);
        Variable var;
    if(myModule != null) {
      var = myModule.declareVariable(qn, seq);
            var.setSequenceType(sequenceType);
            var.checkType();
View Full Code Here

        super(context, signature);
    }
   
    @Override
    public Sequence eval(final Sequence[] args, final HttpRequest request) throws XPathException {
        final Sequence result;
       
        if(isCalledAs(qnScheme.getLocalName())) {
            result = new StringValue(request.getScheme());
       
        } else if(isCalledAs(qnHostname.getLocalName())) {
View Full Code Here

        super(context, signature);
    }
   
    @Override
    public Sequence eval(final Sequence[] args, final HttpRequest request) throws XPathException {
        final Sequence result;
       
        if(isCalledAs(qnAddress.getLocalName())) {
            result = new StringValue(request.getAddress());
       
        } else if(isCalledAs(qnRemoteHostname.getLocalName())) {
View Full Code Here

        super(context, signature);
    }
   
    @Override
    public Sequence eval(final Sequence[] args, final HttpRequest request) throws XPathException {
        final Sequence result;
       
        if(isCalledAs(qnHeaderNames.getLocalName())) {
            result = new ValueSequence();
            for(final String parameterName : request.getHeaderNames()) {
                result.add(new StringValue(parameterName));
            }
        } else if(isCalledAs(qnHeader.getLocalName())) {
            final String headerName = args[0].getStringValue();
           
            if(getSignature().getArgumentCount() == 1) {
                result = getHeader(request, headerName, null);
            } else if(getSignature().getArgumentCount() == 2) {
                final Sequence defaultValues = args[1];
                result = getHeader(request, headerName, defaultValues);
            } else {
                throw new XPathException(this, "Unknown function call: " + getSignature());
            }  
        } else {
View Full Code Here

       
        return result;
    }
   
    private Sequence getHeader(final HttpRequest request, final String headerName, final Sequence defaultValues) throws XPathException {
        final Sequence result;
        final String headerValue = request.getHeader(headerName);
        if(headerValue == null) {
            if(defaultValues != null) {
                result = defaultValues;
            } else {
View Full Code Here

TOP

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

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.