Examples of DynamicError


Examples of xbird.xquery.DynamicError

        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

Examples of xbird.xquery.DynamicError

    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

Examples of xbird.xquery.DynamicError

        }
        final Pattern compiled;
        try {
            compiled = Pattern.compile(pattern, flags);
        } catch (PatternSyntaxException pse) {
            throw new DynamicError("err:FORX0002", "Invalid pattern: " + pattern);
        }
        if(compiled.matcher("").matches()) {
            // An error is raised [err:FORX0003] if the pattern matches a zero-length string,
            // that is, if the expression fn:matches("", $pattern, $flags) returns true.
            // It is not an error, however, if a captured substring is zero-length.
            throw new DynamicError("err:FORX0003", "Specified pattern is illegally matched to zero-length string: "
                    + pattern);
        }
        Matcher matcher = compiled.matcher(input);
        final String replaced = matcher.replaceAll(replacement);
        return XString.valueOf(replaced);
View Full Code Here

Examples of xbird.xquery.DynamicError

                    char next = replacement.charAt(i + 1);
                    if(Character.isDigit(next)) {
                        continue;
                    }
                }
                throw new DynamicError("err:FORX0004", "Invalid replacement expr: " + replacement);
            } else if(c == '\\') {
                if(len >= i + 1) {
                    char next = replacement.charAt(i + 1);
                    // An error is raised [err:FORX0004] if the value of $replacement contains
                    // a "\" character that is not part of a "\\" pair, unless it is immediately
                    // followed by a "$" character.
                    if(next == '\\' || next == '$') {
                        continue;
                    }
                }
                throw new DynamicError("err:FORX0004", "Invalid replacement expr: " + replacement);
            }
        }
    }
View Full Code Here

Examples of xbird.xquery.DynamicError

            // If $arg is not specified, returns the value of the base-uri property
            // of the context item (.)
            final Item contextItem = dynEnv.contextItem();
            if(argv == null) {
                if(contextItem == null) {
                    throw new DynamicError("err:XPDY0002", "Context Item is not set");
                } else {
                    if(!(contextItem instanceof XQNode)) {
                        throw new DynamicError("err:XPTY0004", "Context item is not a node: "
                                + contextItem.getClass().getName());
                    }
                }
            } else if(argv.isEmpty()) {// If $arg is the empty sequence, the empty sequence is returned.
                return ValueSequence.EMPTY_SEQUENCE;
            }
        }
        Item it = argv.getItem(0);
        if(it instanceof SingleCollection) {
            final Sequence<? extends Item> src = ((SingleCollection) it).getSource();
            final IFocus<? extends Item> itor = src.iterator();
            if(!itor.hasNext()) {
                itor.closeQuietly();
                return ValueSequence.EMPTY_SEQUENCE;
            }
            it = itor.next();
            if(itor.hasNext()) {
                itor.closeQuietly();
                throw new DynamicError("err:XPTY0004", "Context item is not a node: " + src);
            }
            itor.closeQuietly();
        }
        if(!(it instanceof XQNode)) {
            if(it.isEmpty()) {
                return ValueSequence.EMPTY_SEQUENCE;
            } else {
                throw new DynamicError("err:XPTY0004", "Item was not a node: "
                        + it.getClass().getName());
            }
        }
        final XQNode node = (XQNode) it;
        final byte nodekind = node.nodeKind();
View Full Code Here

Examples of xbird.xquery.DynamicError

                if(relative.isAbsolute()) {// If $relative is an absolute URI reference, it is returned unchanged.
                    return AnyURIValue.valueOf(relative);
                }
            }
        } catch (URISyntaxException e) {
            throw new DynamicError("err:FORG0002", "Invalid URI form: " + relativeStr);
        }
        final URI baseUri;
        final int arglen = argv.size();
        if(arglen == 2) {
            Item secondItem = argv.getItem(1);
            String baseStr = secondItem.stringValue();
            baseUri = URI.create(baseStr);
        } else {
            baseUri = dynEnv.getStaticContext().getBaseURI();
            if(baseUri == null) {
                throw new DynamicError("err:FONS0005", "BaseUri is not set in the static context.");
            }
        }
        if(relative == null) {// If $relative is the zero-length string, returns the value of the base-uri property.
            return AnyURIValue.valueOf(baseUri);
        }
View Full Code Here

Examples of xbird.xquery.DynamicError

        Item secondItem = argv.getItem(1);
        final String qname = ((XString) secondItem).getValue();
        final String paramUri;
        if(firstItem.isEmpty()) {
            if(qname.indexOf(':') != -1) {
                throw new DynamicError("err:FOCA0002", "Invalid qname: " + qname);
            }
            paramUri = XMLUtils.NULL_NS_URI;
        } else {
            paramUri = ((XString) firstItem).getValue();
        }
        final QualifiedName ret;
        try {
            ret = QNameUtil.parse(qname, paramUri);
        } catch (Throwable e) {
            throw new DynamicError("err:FOCA0002", "Incorrect lexical form for xs:QName: " + qname);
        }
        return new QNameValue(ret);
    }
View Full Code Here

Examples of xbird.xquery.DynamicError

    public static URI resolveURI(String relativeUri, StaticContext staticEnv)
            throws XQueryException {
        assert (relativeUri != null && staticEnv != null);
        URI baseUri = staticEnv.getBaseURI();
        if(baseUri == null) {
            throw new DynamicError("err:FONS0005", "BaseUri is not set in the static context.");
        }
        return resolveURI(relativeUri, baseUri);
    }
View Full Code Here

Examples of xbird.xquery.DynamicError

        if(argv == null) {
            // If no argument is supplied, $arg defaults to the string value of the context item (.).
            // If no argument is supplied and the context item is undefined an error is raised: [err:XPDY0002].
            Item contextItem = dynEnv.contextItem();
            if(contextItem == null) {
                throw new DynamicError("err:XPDY0002", "ContextItem is not set");
            }
            String sv = contextItem.stringValue();
            // If the value of $arg is the empty sequence, the xs:integer 0 is returned.
            return XInteger.valueOf(sv.length());
        }
View Full Code Here

Examples of xbird.xquery.DynamicError

            if(argItor.hasNext()) {
                final Item first = argItor.next();
                assert (first != null);
                if(argItor.hasNext()) {
                    // Returns $arg if it contains one or more items. Otherwise, raises an error [err:FORG0004].
                    throw new DynamicError("err:FORG0004", "Invalid result sequence type was detected, $arg contains one or more items: "
                            + arg.getType());
                }
            }
        }
        return arg;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.