Package xbird.xquery.dm.value

Examples of xbird.xquery.dm.value.Item


            throws XQueryException {
        // If $arg is the empty sequence, the empty sequence is returned.
        if(argv.isEmpty()) {
            return ValueSequence.EMPTY_SEQUENCE;
        }
        Item arg = argv.getItem(0);
        Iterator<? extends Item> argItor = arg.iterator();
        Item firstItem = argItor.next();
        if(firstItem instanceof UntypedAtomicValue) {
            // If $arg contains values of type xdt:untypedAtomic they are cast to xs:double.
            firstItem = ((UntypedAtomicValue) firstItem).castAs(DoubleType.DOUBLE, dynEnv);
        }
        if(!argItor.hasNext()) {
            return firstItem;
        }
        if(firstItem instanceof XNumber) {
            XNumber sum = (XNumber) firstItem;
            int size;
            for(size = 1; argItor.hasNext(); size++) {
                Item toadd = argItor.next();
                if(toadd instanceof UntypedAtomicValue) {
                    toadd = ((UntypedAtomicValue) toadd).castAs(DoubleType.DOUBLE, dynEnv);
                } else if(!(toadd instanceof XNumber)) {
                    throw new DynamicError("err:FORG0006", "fs:plus(" + sum.getType() + ", "
                            + toadd.getType() + ") is not defined.");
                }
                final PlusOp op = new PlusOp();
                op.staticAnalysis(dynEnv.getStaticContext(), sum, toadd);
                sum = (XNumber) op.eval(dynEnv, sum, toadd);
            }
            final DivOp op = new DivOp();
            final XInteger divby = XInteger.valueOf(size);
            op.staticAnalysis(dynEnv.getStaticContext(), sum, divby);
            return op.eval(dynEnv, sum, divby);
        } else if(firstItem instanceof DurationValue) {
            // Duration values must either all be xdt:yearMonthDuration values
            // or must all be xdt:dayTimeDuration values.
            DurationValue sum = (DurationValue) firstItem;
            Type firstType = firstItem.getType();
            assert (firstType != null);
            int size;
            for(size = 1; argItor.hasNext(); size++) {
                Item toadd = argItor.next();
                if(toadd instanceof DurationValue) {
                    throw new DynamicError("err:FORG0006", "Duration values must all be `"
                            + firstType + "`, but found `" + toadd.getType() + "`");
                }
                final PlusOp op = new PlusOp();
                op.staticAnalysis(dynEnv.getStaticContext(), sum, toadd);
                sum = (DurationValue) op.eval(dynEnv, sum, toadd);
            }
View Full Code Here


                        final Sequence<? extends Item> pkv = key.eval(it, dynEnv);
                        final Iterator<? extends Item> pkvItor = pkv.iterator();
                        if(!pkvItor.hasNext()) {
                            continue outer;
                        }
                        final Item fpv = pkvItor.next();
                        if(pkvItor.hasNext()) {
                            persistKeys[i] = new SingleCollection(pkv, dynEnv);
                        } else if(_isNodeComp || fpv instanceof AtomicValue) {
                            persistKeys[i] = fpv;
                        } else {
                            if(counter == 0) {
                                _keyTypes.set(i, StringType.STRING);
                            }
                            persistKeys[i] = new XString(fpv.stringValue());
                        }
                    }
                    joinTable.put(persistKeys, it);
                }
                counter++;
View Full Code Here

            while(true) {
                if(!srcItor.hasNext()) {
                    srcItor.closeQuietly();
                    return BooleanValue.TRUE;
                } else {
                    final Item curitem = srcItor.next();
                    bindingVar.allocateResult(curitem, dynEnv);
                    final Sequence v = condExpr.eval(contextSeq, dynEnv);
                    if(!FnBoolean.effectiveBooleanValue(v)) {
                        srcItor.closeQuietly();
                        return BooleanValue.FALSE;
                    }
                }
            }
        } else {//some
            while(true) {
                if(!srcItor.hasNext()) {
                    srcItor.closeQuietly();
                    return BooleanValue.FALSE;
                } else {
                    final Item curitem = srcItor.next();
                    bindingVar.allocateResult(curitem, dynEnv);
                    final Sequence v = condExpr.eval(contextSeq, dynEnv);
                    if(FnBoolean.effectiveBooleanValue(v)) {
                        srcItor.closeQuietly();
                        return BooleanValue.TRUE;
View Full Code Here

    }

    public Sequence eval(Sequence<? extends Item> contextSeq, ValueSequence argv, DynamicContext dynEnv)
            throws XQueryException {
        assert (argv != null);
        Item firstItem = argv.getItem(0);
        if(firstItem.isEmpty()) {
            return ValueSequence.EMPTY_SEQUENCE;
        }
        Item secondItem = argv.getItem(1);
        if(secondItem.isEmpty()) {
            return ValueSequence.EMPTY_SEQUENCE;
        }
        String comparand1 = firstItem.stringValue();
        String comparand2 = secondItem.stringValue();
        final int cmp;
        final int arglen = argv.size();
        assert (arglen == 2 || arglen == 3);
        if(arglen == 3) {
            Item thirdItem = argv.getItem(2);
            String collation = thirdItem.stringValue();
            Collator collator = CollationUtils.resolve(collation, dynEnv.getStaticContext());
            cmp = collator.compare(comparand1, comparand2);
        } else {
            cmp = comparand1.compareTo(comparand2);
        }
View Full Code Here

            return delegate.hasNext();
        }

        public Item next() {
            final Comparable[] tuple = delegate.next();
            final Item it = (Item) tuple[0];
            final int keylen = orderSpecs.size();
            for(int i = 1; i <= keylen; i++) {
                tuple[i] = null; // hack: save memory space
            }
            return it;
View Full Code Here

    }

    public Sequence eval(Sequence<? extends Item> contextSeq, ValueSequence argv, DynamicContext dynEnv)
            throws XQueryException {
        assert (argv != null && argv.size() == 1);
        Item firstItem = argv.getItem(0);
        if(firstItem.isEmpty()) {
            return ValueSequence.EMPTY_SEQUENCE;
        }
        assert (firstItem instanceof XString);
        String viewloc = firstItem.stringValue();
        Reader reader = readQuery(viewloc, dynEnv.getStaticContext());
        Sequence res = Eval.evaluateQuery(reader, dynEnv);
        return res;
    }
View Full Code Here

    }

    public Sequence eval(Sequence<? extends Item> contextSeq, ValueSequence argv, DynamicContext dynEnv)
            throws XQueryException {
        assert (argv != null && argv.size() == 2);
        final Item target = argv.getItem(0);
        if(target.isEmpty()) {
            return ValueSequence.EMPTY_SEQUENCE;
        }
        Item secondItem = argv.getItem(1);
        assert (secondItem instanceof XInteger);
        final int pos = (int) ((XInteger) secondItem).getValue();
        return pos > 0 ? new RemoveEmuration(target, pos, dynEnv) : target;
    }
View Full Code Here

        public boolean next(IFocus focus) throws XQueryException {
            final int cpos = focus.getContextPosition();
            Iterator<? extends Item> itor = focus.getBaseFocus();
            boolean removed = false;
            while(itor.hasNext()) {
                Item next = itor.next();
                if(!removed && cpos == _removePos - 1) {
                    removed = true;
                    continue;
                }
                focus.setContextItem(next);
View Full Code Here

            final IFocus<? extends Item> inputItor = (IFocus<? extends Item>) actFocus.getBaseFocus();
            IFocus<? extends Item> actionItor = actFocus.getActionItor();
            for(int i = 0;; i++) {
                final int pos = actFocus.getContextPosition();
                if((i != 0 || pos > 0) && actionItor.hasNext()) {
                    Item actionItem = actionItor.next();
                    actFocus.setContextItem(actionItem);
                    return true;
                }
                if(!inputItor.hasNext()) {
                    break;
                }
                final Item nextit = inputItor.next();
                // iterate on action in the outer loop.
                final Sequence<? extends Item> action = _actionExpr.eval(nextit, _dynEnv);
                actionItor = action.iterator();
                actFocus.setActionItor(actionItor);
            }
View Full Code Here

        }

        public boolean next(IFocus focus) throws XQueryException {
            final IFocus<? extends Item> inputItor = (IFocus<? extends Item>) focus.getBaseFocus();
            if(inputItor.hasNext()) {
                Item nextit = inputItor.next();
                // invoke let action in the outer loop.
                _actionExpr.eval(nextit, _dynEnv);
                focus.setContextItem(nextit);
                return true;
            }
View Full Code Here

TOP

Related Classes of xbird.xquery.dm.value.Item

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.