Package xbird.xquery

Examples of xbird.xquery.DynamicError


    public Sequence eval(Sequence<? extends Item> contextSeq, ValueSequence argv, DynamicContext dynEnv)
            throws XQueryException {
        IFocus focus = dynEnv.getFocus();
        if(focus == null) {
            throw new DynamicError("err:XPDY0002", "ContentPosition is not set");
        }
        final int pos = focus.getPosition();
        return XInteger.valueOf(pos);
    }
View Full Code Here


        assert (arglen == 1 || arglen == 2);
        final XQNode node;
        if (arglen == 2) {
            Item second = argv.getItem(1);
            if (!(second instanceof XQNode)) {
                throw new DynamicError("err:XPTY0004", "Second argument is expected to be a node, but was "
                        + second.getType());
            }
            node = (XQNode) second;
        } else {
            Item contextItem = dynEnv.contextItem();
            if (contextItem == null) {
                throw new DynamicError("err:XPDY0002", "ContextItem is not set");
            } else if (!(contextItem instanceof XQNode)) {
                throw new DynamicError("err:XPTY0004", "Context item is expected to be a node, but was "
                        + contextItem.getType());
            }
            node = (XQNode) contextItem;
        }
        // An error is raised if node's root is not a document node
        XQNode root = node.getRoot();
        if (root.nodeKind() != NodeKind.DOCUMENT) {
            throw new DynamicError("err:FODC0001", "root node was not document-node.");
        }
        Item firstItem = argv.getItem(0);
        NodeSequence<XQNode> nodes = new NodeSequence<XQNode>(dynEnv);
        for (Item it : firstItem) {
            assert (it instanceof XString);
View Full Code Here

        XMLGregorianCalendar timeValue = time.getValue();
        final int timeTz = timeValue.getTimezone();
        if(timeTz != DatatypeConstants.FIELD_UNDEFINED) {
            final int dateTz = newValue.getTimezone();
            if(dateTz != DatatypeConstants.FIELD_UNDEFINED && dateTz != timeTz) {
                throw new DynamicError("err:FORG0008", "fn:dateTime(" + date + ", " + time
                        + ") for `" + dateValue.getTimeZone(dateTz).getID() + " and `"
                        + timeValue.getTimeZone(timeTz).getID() + "` is not allowed.");
            }
            newValue.setTimezone(timeTz);
        }
View Full Code Here

    public Sequence eval(Sequence<? extends Item> contextSeq, ValueSequence argv, DynamicContext dynEnv)
            throws XQueryException {
        final IFocus focus = dynEnv.getFocus();
        if(focus == null) {
            throw new DynamicError("err:XPDY0002", "Focus of fileter is not set");
        }
        int last = focus.getLast();
        if(last != -1) {
            return new XInteger(last);
        }
        final Sequence<? extends Item> src = dynEnv.peekSequence();
        if(src == null) {
            throw new DynamicError("err:XPDY0002", "Source of fileter is not set");
        }
        last = 0;
        IFocus<? extends Item> srcItor = src.iterator();
        for(Item it : srcItor) {
            ++last;
View Full Code Here

            String collation = thirdItem.stringValue();
            Collator coll = CollationUtils.resolve(collation, dynEnv.getStaticContext());
            if(!(coll instanceof RuleBasedCollator)) {
                // If the specified collation does not support collation units an error
                // may be raised [err:FOCH0004].
                throw new DynamicError("err:FOCH0004", "Collator for the collation `" + collation
                        + "` is expected to be rule based collator, but was " + coll);
            }
            collator = (RuleBasedCollator) coll;
        } else {
            collator = null;
View Full Code Here

        Item arg = argv.getItem(0);
        final Type.Occurrence quantifier = arg.getType().quantifier();
        if(!Type.Occurrence.OCC_EXACTLY_ONE.accepts(quantifier.getAlignment())) {
            Iterator<? extends Item> argItor = arg.iterator();
            if(!argItor.hasNext()) {
                throw new DynamicError("err:FORG0005", "Item not found");
            }
            Item first = argItor.next();
            if(argItor.hasNext()) {
                // Returns $arg if it contains one or more items. Otherwise, raises an error [err:FORG0004].
                throw new DynamicError("err:FORG0005", "Sequence has more than one items");
            }
            return first;
        }
        return arg;
    }
View Full Code Here

            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);
            }
            return sum;
        } else {
            throw new DynamicError("err:FORG0006", "Invalid argument type: " + firstItem.getType());
        }

    }
View Full Code Here

            while(argItor.hasNext()) {
                Item it = argItor.next();
                if(it instanceof UntypedAtomicValue) {
                    it = ((UntypedAtomicValue) it).castAs(DoubleType.DOUBLE, dynEnv);
                } else if(!(it instanceof XNumber)) {
                    throw new DynamicError("err:FORG0006", "fs:plus(" + min.getType() + ", "
                            + it.getType() + ") is not defined.");
                }
                XNumber cmp = (XNumber) it;
                if(cmp.isNaN()) {
                    return cmp;
                }
                if(cmp.compareTo(min) < 0) {
                    min = cmp;
                }
            }
            return min;
        } else if(firstItem instanceof DurationValue) {
            // Duration values must either all be xdt:yearMonthDuration values
            // or must all be xdt:dayTimeDuration values.
            DurationValue min = (DurationValue) firstItem;
            assert (firstType != null);
            while(argItor.hasNext()) {
                Item it = argItor.next();
                if(it instanceof DurationValue) {
                    throw new DynamicError("err:FORG0006", "Duration values must all be `"
                            + firstType + "`, but found `" + it.getType() + "`");
                }
                DurationValue cmp = (DurationValue) it;
                if(cmp.compareTo(min) < 0) {
                    min = cmp;
                }
            }
            return min;
        } else if(TypeUtil.subtypeOf(firstType, StringType.STRING)) {
            AtomicValue min = (AtomicValue) firstItem;
            final int arglen = argv.size();
            final Collator collator;
            if(arglen == 2) {
                Item sec = argv.getItem(1);
                Type secType = sec.getType();
                if(!TypeUtil.subtypeOf(secType, StringType.STRING)) {
                    throw new DynamicError("err:FORG0006", "second argument is expected to be xs:string, but was "
                            + secType);
                }
                String uri = sec.stringValue();
                collator = CollationUtils.resolve(uri, dynEnv.getStaticContext());
            } else {
                collator = Collator.getInstance(); // compare in default locale
            }
            while(argItor.hasNext()) {
                Item it = argItor.next();
                Type cmpType = it.getType();
                if(!TypeUtil.subtypeOf(cmpType, StringType.STRING)) {
                    throw new DynamicError("err:FORG0006", "imcomparable xs:string and " + cmpType);
                }
                if(collator.compare(it, firstItem) < 0) {
                    min = (AtomicValue) it;
                }
            }
            return min;
        } else {
            throw new DynamicError("err:FORG0006", "Invalid argument type: " + firstItem.getType());
        }
    }
View Full Code Here

    }

    public Sequence<? extends Item> eval(Sequence<? extends Item> contextSeq, DynamicContext dynEnv)
            throws XQueryException {
        if(contextSeq == null) {
            throw new DynamicError("err:XPDY0002", "ContextItem is not set");
        }
        final INodeSequence<XQNode> src = ProxyNodeSequence.wrap(contextSeq, dynEnv);
        final IFocus<XQNode> srcitor = src.iterator();
        if(srcitor.hasNext()) {
            final XQNode n = srcitor.next();
View Full Code Here

            while(argItor.hasNext()) {
                Item it = argItor.next();
                if(it instanceof UntypedAtomicValue) {
                    it = ((UntypedAtomicValue) it).castAs(DoubleType.DOUBLE, dynEnv);
                } else if(!(it instanceof XNumber)) {
                    throw new DynamicError("err:FORG0006", "fs:plus(" + max.getType() + ", "
                            + it.getType() + ") is not defined");
                }
                XNumber cmp = (XNumber) it;
                if(cmp.isNaN()) {
                    return cmp;
                }
                if(cmp.compareTo(max) > 0) {
                    max = cmp;
                }
            }
            return max;
        } else if(firstItem instanceof DurationValue) {
            // Duration values must either all be xdt:yearMonthDuration values
            // or must all be xdt:dayTimeDuration values.
            DurationValue max = (DurationValue) firstItem;
            while(argItor.hasNext()) {
                Item it = argItor.next();
                if(it instanceof DurationValue) {
                    throw new DynamicError("err:FORG0006", "Duration values must all be `"
                            + firstType + "`, but found `" + it.getType() + "`");
                }
                DurationValue cmp = (DurationValue) it;
                if(cmp.compareTo(max) > 0) {
                    max = cmp;
                }
            }
            return max;
        } else if(TypeUtil.subtypeOf(firstType, StringType.STRING)) {
            AtomicValue max = (AtomicValue) firstItem;
            final int arglen = argv.size();
            final Collator collator;
            if(arglen == 2) {
                Item sec = argv.getItem(1);
                Type secType = sec.getType();
                if(!TypeUtil.subtypeOf(secType, StringType.STRING)) {
                    throw new DynamicError("err:FORG0006", "second argument is expected to be xs:string, but was "
                            + secType);
                }
                String uri = sec.stringValue();
                collator = CollationUtils.resolve(uri, dynEnv.getStaticContext());
            } else {
                collator = Collator.getInstance(); // compare in default locale
            }
            while(argItor.hasNext()) {
                Item it = argItor.next();
                Type cmpType = it.getType();
                if(!TypeUtil.subtypeOf(cmpType, StringType.STRING)) {
                    throw new DynamicError("err:FORG0006", "imcomparable xs:string and " + cmpType);
                }
                if(collator.compare(it, firstItem) > 0) {
                    max = (AtomicValue) it;
                }
            }
            return max;
        } else {
            throw new DynamicError("err:FORG0006", "Invalid argument type: " + firstItem.getType());
        }
    }
View Full Code Here

TOP

Related Classes of xbird.xquery.DynamicError

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.