Package xbird.xquery.dm.value

Examples of xbird.xquery.dm.value.Item


    }

    public Sequence eval(Sequence<? extends Item> contextSeq, ValueSequence argv, DynamicContext dynEnv) throws XQueryException {
        assert (argv != null && argv.size() == 1);
        // If $uri-part is the empty sequence, returns the zero-length string.
        Item firstItem = argv.getItem(0);
        if(firstItem.isEmpty()) {
            return XString.valueOf("");
        }
        assert (firstItem instanceof XString);
        String uri = firstItem.stringValue();
        String escaped = XMLUtils.escapeHtmlUri(uri);
        return XString.valueOf(escaped);
    }
View Full Code Here


    }

    public boolean next(IFocus focus) throws XQueryException {
        final Iterator<? extends Item> itor = focus.getBaseFocus();
        if(itor.hasNext()) {
            Item it = itor.next();
            focus.setContextItem(it);
            return true;
        }
        return false;
    }
View Full Code Here

                        final Sequence<? extends Item> keyval = key.getKeyExpr().eval(contextSeq, dynEnv);
                        if(keyval.isEmpty()) {
                            tuple[i + 1] = null;
                        } else {
                            final Sequence<? extends Item> atomized = keyval.atomize(dynEnv);
                            final Item keyitem = SingleCollection.wrap(atomized, dynEnv);
                            if(keyitem instanceof AtomicValue) {
                                tuple[i + 1] = keyitem;
                            } else {//TODO typed value
                                tuple[i + 1] = keyitem.stringValue();
                            }
                        }
                    }
                    items.add(tuple);
                }
View Full Code Here

            return XString.valueOf("");
        }
        final StringBuilder buf = new StringBuilder(256);
        final int arglen = argv.size();
        for(int i = 0; i < arglen; i++) {
            Item arg = argv.getItem(i);
            String argStr = arg.stringValue();
            if(argStr.length() > 0) {
                buf.append(argStr);
            }
        }
        final String ret = buf.toString();
View Full Code Here

            assert (o1.length == o2.length);
            for(int i = 0; i < keylen; i++) {
                final int cmp;
                final int keyidx = i + 1;
                if(o1[keyidx] instanceof Item) {
                    final Item it1 = (Item) o1[keyidx];
                    final Item it2 = (Item) o2[keyidx];
                    final OrderSpec spec = orderSpecs.get(i);
                    cmp = spec.compare(it1, it2, dynEnv);
                } else {
                    final OrderSpec spec = orderSpecs.get(i);
                    cmp = spec.compare(o1[keyidx], o2[keyidx]);
View Full Code Here

            JoinTable joinTable = _joinTable;
            final ValueSequence vs = new ValueSequence(dynEnv);
            while(skvItor.hasNext()) {
                final Comparable searchKey;
                if(searchKeyLen == 1) {
                    final Item fsv = skvItor.next();
                    searchKey = mapArgument(fsv, 0, dynEnv);
                } else {
                    final Comparable[] searchKeys = new Comparable[searchKeyLen];
                    for(int i = 0; i < searchKeyLen; i++) {
                        Item fsv = skvItor.next();
                        searchKeys[i] = mapArgument(fsv, i, dynEnv);
                    }
                    searchKey = new JoinTable.Key(searchKeys, _opr);
                }
                final IFocus<Item> jsItor = joinTable.entrySequence(searchKey, dynEnv).iterator();
View Full Code Here

            }
            final ValueSequence vs = new ValueSequence(dynEnv);
            while(skvItor.hasNext()) {
                final Comparable searchKey;
                if(searchKeyLen == 1) {
                    final Item fsv = skvItor.next();
                    searchKey = mapArgument(fsv, 0, dynEnv);
                } else {
                    final Comparable[] searchKeys = new Comparable[searchKeyLen];
                    for(int i = 0; i < searchKeyLen; i++) {
                        Item fsv = skvItor.next();
                        searchKeys[i] = mapArgument(fsv, i, dynEnv);
                    }
                    searchKey = new JoinTable.Key(searchKeys, _opr);
                }
                if(_joinTable == null) {
View Full Code Here

    }

    public Sequence eval(Sequence<? extends Item> contextSeq, ValueSequence argv, DynamicContext dynEnv)
            throws XQueryException {
        final int arglen = argv.size();
        final Item zero;
        if(arglen == 2) {
            zero = argv.getItem(1);
        } else if(arglen == 1) {
            zero = XInteger.valueOf(0);
        } else {
            throw new IllegalStateException("Illefal args: " + arglen);
        }
        Item arg = argv.getItem(0);
        Iterator<? extends Item> argItor = arg.iterator();
        if(!argItor.hasNext()) {
            // If the converted sequence is empty, then the single-argument form
            // of the function returns the xs:integer value 0;
            // the two-argument form returns the value of the argument $zero.
            return zero;
        }
        Item firstItem = argItor.next();
        if(firstItem instanceof UntypedAtomicValue) {
            // Values of type xdt:untypedAtomic in $arg 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;
            while(argItor.hasNext()) {
                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.");
                }
                // TODO more efficient processing
                final PlusOp op = new PlusOp();
                op.staticAnalysis(dynEnv.getStaticContext(), sum, toadd);
                sum = (XNumber) op.eval(dynEnv, sum, toadd);
            }
            return sum;
        } 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);
            while(argItor.hasNext()) {
                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

            }

            public boolean next(IFocus focus) throws XQueryException {
                final Iterator<Item> itemItor = focus.getBaseFocus();
                if(itemItor.hasNext()) {
                    final Item curItem = itemItor.next();
                    focus.setContextItem(curItem);
                    return true;
                }
                return false;
            }
View Full Code Here

    public Sequence eval(final Sequence<? extends Item> contextSeq, final ValueSequence argv, final DynamicContext dynEnv)
            throws XQueryException {
        int count = 0;
        if(!argv.isEmpty()) {
            final Item arg = argv.getItem(0);
            if(arg instanceof IRandomAccessSequence) {
                count = ((IRandomAccessSequence) arg).size();
            } else {
                if(arg instanceof SingleCollection) {
                    final Sequence source = ((SingleCollection) arg).getSource();
                    if(source instanceof IRandomAccessSequence) {
                        count = ((IRandomAccessSequence) source).size();
                        return XInteger.valueOf(count);
                    } else if(source instanceof IndexMatchedSequence) {
                        count = ((IndexMatchedSequence) source).totalCount();
                        return XInteger.valueOf(count);
                    }
                }
                final IFocus<Item> argItor = arg.iterator();
                for(Item it : argItor) {
                    ++count;
                }
                argItor.closeQuietly();
            }
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.