Package xbird.xquery

Examples of xbird.xquery.DynamicError


            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);
            }
            final DivOp op = new DivOp();
            final XInteger divby = XInteger.valueOf(size);
            op.staticAnalysis(dynEnv.getStaticContext(), sum, divby);
            return op.eval(dynEnv, sum, divby);
        } else {
            throw new DynamicError("err:FORG0006", "Invalid argument type: " + firstItem.getType());
        }
    }
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
        final XQNode root = node.getRoot();
        if(root.nodeKind() != NodeKind.DOCUMENT) {
            throw new DynamicError("err:FODC0001", "root node was not document-node.");
        }
        final IFocus<Item> firstItemItor = argv.getItem(0).iterator();
        final NodeSequence<XQNode> nodes = new NodeSequence<XQNode>(dynEnv);
        for(Item it : firstItemItor) {
            assert (it instanceof XString);
View Full Code Here

        URI resolved = ResolveUri.resolveURI(viewloc, staticEnv);
        final URL queryUrl;
        try {
            queryUrl = resolved.toURL();
        } catch (MalformedURLException e) {
            throw new DynamicError("Invalid URL form: " + viewloc);
        }
        final InputStream is;
        try {
            is = queryUrl.openStream();
        } catch (IOException e) {
            throw new DynamicError("failed to open stream for " + queryUrl);
        }
        Reader reader = new InputStreamReader(is);
        return reader;
    }
View Full Code Here

        }
        final Pattern compiled;
        try {
            compiled = Pattern.compile(pattern, flags);
        } catch (PatternSyntaxException pse) {
            throw new DynamicError("err:FORX0002", "Invalid pattern: " + pattern);
        }
        if(compiled.matcher("").matches()) {
            // If the supplied $pattern matches a zero-length string, that is,
            // if fn:matches("", $pattern, $flags) returns true, then an error is raised.           
            throw new DynamicError("err:FORX0003", "Specified pattern is illegally matched to zero-length string: "
                    + pattern);
        }
        return new TokenizerEmuration(input, compiled, dynEnv);
    }
View Full Code Here

        }
        final Pattern compiled;
        try {
            compiled = Pattern.compile(pattern, flags);
        } catch (PatternSyntaxException pse) {
            throw new DynamicError("err:FORX0002", "Invalid pattern: " + pattern);
        }
        Matcher matcher = compiled.matcher(input);
        final boolean match = matcher.matches();
        return match ? BooleanValue.TRUE : BooleanValue.FALSE;
    }
View Full Code Here

                    break;
                case 'x':
                    ret |= Pattern.COMMENTS;
                    break;
                default:
                    throw new DynamicError("err:FORX0001", "Unsupported flag: `" + c + '`');
            }
        }
        return ret;
    }
View Full Code Here

        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");
            }
            arg = contextItem.stringValue();
        } else {
            // If the value of $arg is the empty sequence, returns the zero-length string.
            Item first = argv.getItem(0);
View Full Code Here

                case '\r':
                case '\t':
                    break;
                default:
                    if(DOMAIN.indexOf(c) == -1) {
                        throw new DynamicError("err:FORG0001", "Illegal representation as xs:base64Binary: "
                                + data);
                    }
                    trimed[bytesCopied++] = c;
            }
        }
View Full Code Here

                URI resolved = baseUri.resolve(unescapedArg);
                final URL colurl;
                try {
                    colurl = resolved.toURL();
                } catch (MalformedURLException e) {
                    throw new DynamicError("Invalid uri: " + argStr);
                }
                DocumentManager docmgr = dynEnv.getDocumentManager();
                DTMDocument doc = docmgr.loadDocument(colurl, dynEnv);
                catalog = resolveCatalog(doc, dynEnv);
            } else if(unescapedArg.startsWith("/")) {
View Full Code Here

            } else {
                // c. otherwise returns $actual cast to the type of $expected.
                try {
                    return actual.castAs((AtomicType) expectedType, dynEnv);
                } catch (XQueryException e) {
                    throw new DynamicError("err:FORG0001", e);
                }
            }
        }
        return actual;
    }
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.