Package xbird.xquery

Examples of xbird.xquery.DynamicError


        public XDouble eval(DynamicContext dynEnv, Item v1, Item v2) throws XQueryException {
            double d1 = asDouble(v1, dynEnv);
            double d2 = asDouble(v2, dynEnv);
            final double res = d1 + d2;
            if(res == Double.POSITIVE_INFINITY) {
                throw new DynamicError("err:FOAR0002", "result overflow");
            }
            if(res == Double.NEGATIVE_INFINITY) {
                throw new DynamicError("err:FOAR0002", "result underflow");
            }
            return XDouble.valueOf(res);
        }
View Full Code Here


            case TypeTable.NUMERIC_TID:
                v = this;
                break;
            case TypeTable.INTEGER_TID:
                if(Double.isNaN(value)) {
                    throw new DynamicError("err:FOCA0002", "Can't convert xs:double(" + toString()
                            + ") to xs:integer");
                }
                if(Double.isInfinite(value)) {
                    throw new DynamicError("err:FOCA0002", "Can't convert xs:double(" + toString()
                            + ") to xs:integer");
                }
                v = XInteger.valueOf(asLong());
                break;
            case TypeTable.FLOAT_TID:
                if(Double.isNaN(value)) {
                    v = XFloat.valueOf(Float.NaN);
                } else if(value == Double.POSITIVE_INFINITY) {
                    v = XFloat.valueOf(Float.POSITIVE_INFINITY);
                } else if(value == Double.NEGATIVE_INFINITY) {
                    v = XFloat.valueOf(Float.NEGATIVE_INFINITY);
                } else {
                    v = XFloat.valueOf((float) value);
                }
                break;
            case TypeTable.DECIMAL_TID:
                if(Double.isNaN(value)) {
                    throw new DynamicError("err:FORG0001", "Can't convert xs:double(" + toString()
                            + ") to xs:decimal");
                }
                if(Double.isInfinite(value)) {
                    throw new DynamicError("err:FOCA0002", "Can't convert xs:double(" + toString()
                            + ") to xs:decimal");
                }
                v = XDecimal.valueOf(asDecimal());
                break;
            default:
View Full Code Here

    public XDouble createInstance(String literal, AtomicType srcType, DynamicContext dynEnv)
            throws XQueryException {
        try {
            return new XDouble(literal);
        } catch (NumberFormatException e) {
            throw new DynamicError("err:FORG0001", e);
        }
    }
View Full Code Here

        final XQNode node;
        if (argv == null) {
            // If the argument is omitted, it defaults to the context node.
            Item contextItem = dynEnv.contextItem();
            if (contextItem == null) {
                throw new DynamicError("err:XPDY0002", "ContextItem is not set");
            }
            if (!(contextItem instanceof XQNode)) {
                throw new DynamicError("err:XPTY0004", "context item is expected to be a node, but was "
                        + contextItem.getType());
            }
            node = (XQNode) contextItem;
        } else {
            assert (argv.size() == 1);
View Full Code Here

    public AtomicValue createInstance(String literal, AtomicType srcType, DynamicContext dynEnv)
            throws XQueryException {
        try {
            return new XFloat(literal);
        } catch (NumberFormatException e) {
            throw new DynamicError("err:FORG0001", e);
        }
    }
View Full Code Here

        final XQNode node;
        if (argv == null) {
            // If the argument is omitted, it defaults to the context node.
            Item contextItem = dynEnv.contextItem();
            if (contextItem == null) {
                throw new DynamicError("err:XPDY0002", "ContextItem is not set");
            }
            if (!(contextItem instanceof XQNode)) {
                throw new DynamicError("err:XPTY0004", "context item is expected to be a node, but was "
                        + contextItem.getType());
            }
            node = (XQNode) contextItem;
        } else {
            assert (argv.size() == 1);
View Full Code Here

            XQNode element = (XQNode) secondItem;
            nsuri = NamespaceUriForPrefix.resolveNamespaceUri(element, prefix);
            if(nsuri == null) {
                // If the $qname has a prefix and if there is no namespace binding for $element
                // that matches this prefix, then an error is raised [err:FONS0004].
                throw new DynamicError("err:FONS0004", "Namespace for the prefix `" + qnameStr
                        + "` not found");
            }
        }
        final QualifiedName resolved;
        try {
            resolved = QNameUtil.parse(qnameStr, nsuri);
        } catch (IllegalArgumentException e) {
            // If $qname does not have the correct lexical form for xs:QName an error
            // is raised [err:FOCA0002].
            throw new DynamicError("err:FOCA0002", "Illegal qname form: " + qnameStr);
        }
        return new QNameValue(resolved);
    }
View Full Code Here

            throws XQueryException {
        final long lv;
        try {
            lv = Long.parseLong(literal);
        } catch (NumberFormatException pe) {
            throw new DynamicError("err:FORG0001", "failed to cast as '" + SYMBOL + "': " + literal);
        }
        if(lv < lowerBound() || lv > upperBound()) {
            throw new DynamicError("err:FORG0001", "Illegal value for '" + SYMBOL + "': " + literal);
        }
        return new XInteger(lv, this);
    }
View Full Code Here

        final QualifiedName nodeName;
        if (argv == null) {
            // If the argument is omitted, it defaults to the context node.
            Item contextItem = dynEnv.contextItem();
            if (contextItem == null) {
                throw new DynamicError("err:XPDY0002", "ContextItem is not set");
            }
            if (!(contextItem instanceof XQNode)) {
                throw new DynamicError("err:XPTY0004", "context item is expected to be a node, but was "
                        + contextItem.getType());
            } else {
                nodeName = ((XQNode) contextItem).nodeName();
            }
        } else {
View Full Code Here

    public Sequence eval(Sequence<? extends Item> contextSeq, ValueSequence argv, DynamicContext dynEnv)
            throws XQueryException {
        final Item contextItem = dynEnv.contextItem();
        if(argv == null) {
            if(contextItem == null) {
                throw new DynamicError("err:XPDY0002", "ContextItem is not set");
            } else {
                // If no argument is supplied, this function returns the string value
                // of the context item (.).
                final String sv = contextItem.stringValue();
                return XString.valueOf(sv);
            }
        }
        // If $arg is the empty sequence, the zero-length string is returned.
        if(argv.isEmpty()) {
            return XString.valueOf("");
        }
        final Item arg = argv.getItem(0);
        final IFocus<? extends Item> argItor = arg.iterator();
        if(argItor.hasNext()) {
            final Item firstItem = argItor.next();
            final Sequence ret;
            if(firstItem instanceof XQNode) {
                // If $arg is a node, the function returns the string-value of the node.
                final String sv = ((XQNode) firstItem).stringValue();
                ret = XString.valueOf(sv);
            } else if(firstItem instanceof AtomicValue) {
                // If $arg is an atomic value, then the function returns the same string as
                // is returned by the expression "$arg cast as xs:string".
                final XString sv = ((AtomicValue) firstItem).<XString> castAs(StringType.STRING, dynEnv);
                ret = sv;
            } else {
                argItor.closeQuietly();
                throw new IllegalStateException("Illegal argument type: "
                        + arg.getClass().getName());
            }
            if(argItor.hasNext()) {
                argItor.closeQuietly();
                throw new DynamicError("argument should have zero or one element.");
            }
            argItor.closeQuietly();
            return ret;
        } else {
            argItor.closeQuietly();
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.