Examples of XQueryModule


Examples of xbird.xquery.XQueryModule

        list.add(msg2);
        Assert.assertEquals(2, list.size());

        String query1 = "fn:collection('/" + COLLECTION_NAME + "/.*.xml')//author";
        XQueryProcessor proc = new XQueryProcessor();
        XQueryModule compiled1 = proc.parse(query1);
        Sequence<? extends Item> items = proc.execute(compiled1);
        INodeSequence<DTMElement> nodes = ProxyNodeSequence.wrap(items, DynamicContext.DUMMY);

        for(DTMElement node : nodes) {
            Object unmarshalled = xstream.unmarshal(new DTMReader(node));
View Full Code Here

Examples of xbird.xquery.XQueryModule

        if(query == null) {
            throw new IllegalStateException("query was null for: " + queryRequest);
        }

        // load shipped variables
        final XQueryModule module = new XQueryModule();
        final ShippedVariable[] vars = queryRequest.getShippedVariables();
        if(vars != null) {
            for(ShippedVariable var : vars) {
                try {
                    module.putVariable(var.getVarName(), var);
                } catch (XQueryException e) {
                    throw new RemoteException("failed to declare shipped variable: " + var, e);
                }
            }
        }

        final XQueryProcessor proccessor = new XQueryProcessor(module);
        try {
            proccessor.parse(query, queryRequest.getBaseUri());
        } catch (XQueryException e) {
            LOG.error("parse failed: \n" + query, e);
            rc.setFault(e);
            _resHandler.onResponse(rc);
            return;
        }
        final Sequence<? extends Item> resultSeq;
        _runningThreads.put(rc, Thread.currentThread());
        final DynamicContext dynEnv = new DynamicContext(proccessor.getStaticContext());
        try {
            resultSeq = proccessor.execute(module, dynEnv);
        } catch (Exception e) {
            LOG.error("execute failed: \n" + query, e);
            rc.setFault(e);
            _resHandler.onResponse(rc);
            return;
        } finally {
            _runningThreads.remove(rc);
        }
        final Serializable result = wrapResult(resultSeq, module.getExpression(), queryRequest, dynEnv);
        rc.setResult(result);

        try {
            _resHandler.onResponse(rc);
        } catch (RemoteException re) {
View Full Code Here

Examples of xbird.xquery.XQueryModule

    private int baseURIDeclCount = 0;

    public XQueryModule parse() throws XQueryException {
        if(currentModule == null) {
            this.currentModule = new XQueryModule();
        }
        final XQueryModule m;
        try {
            m = parseModule(); // returned m is same to currentModule
        } catch (XQueryException xqe) {
            throw xqe;
        } catch (TokenMgrError tme) {
View Full Code Here

Examples of xbird.xquery.XQueryModule

    private static String invokeQueryPushModeUsingSAX(String query) throws XQueryException,
            XMLStreamException, UnsupportedEncodingException {
        XQueryProcessor proc = new XQueryProcessor();
        InputStream input = new ByteArrayInputStream(query.getBytes("UTF-8"));
        XQueryModule module = proc.parse(input);
        StringWriter writer = new StringWriter(8192);
        SAXWriter saxwr = new SAXWriter(writer);
        Serializer ser = new SAXSerializer(saxwr, writer);
        //ser.setInterveBlanks(false);
        proc.execute(module, ser);
View Full Code Here

Examples of xbird.xquery.XQueryModule

    }

    private static void invokeQueryPullMode(InputStream input, URI baseUri) throws XQueryException {
        XQueryProcessor proc = new XQueryProcessor();
        // #1 parse a query
        XQueryModule module = proc.parse(input, baseUri);
        // #2 execute the compiled expression using ``pull'' mode
        Sequence<? extends Item> result = proc.execute(module);

        // prepare SAX result handler
        Writer writer = new NoopWriter();
View Full Code Here

Examples of xbird.xquery.XQueryModule

    private static void invokeQueryPushMode(InputStream input, URI baseUri) throws XQueryException,
            XMLStreamException {
        XQueryProcessor proc = new XQueryProcessor();
        // #1 parse a query
        XQueryModule module = proc.parse(input);

        // prepare a result handler (StAX)
        Writer writer = new StringWriter();
        XMLOutputFactory factory = XMLOutputFactory.newInstance();
        XMLStreamWriter streamWriter = factory.createXMLStreamWriter(writer);
View Full Code Here

Examples of xbird.xquery.XQueryModule

                final String testFilePath = xpath.evaluate("./@FilePath", testCase);
                final String queryFileName = xpath.evaluate("./*[local-name()='query']/@name", testCase);
                File queryFile = new File(xqtsQueryPath, testFilePath + queryFileName + ".xq");
                final URI baseUri = new File(xqtsQueryPath, testFilePath).toURI();

                XQueryModule xqmod = new XQueryModule();

                {// ((//*:test-group)//*:test-case)/*:module
                    NodeList moduleNodes = (NodeList) xpath.evaluate("./*[local-name()='module']", testCase, XPathConstants.NODESET);
                    final int modcount = moduleNodes.getLength();
                    if(modcount > 0) {
                        ModuleManager moduleManager = statEnv.getModuleManager();
                        SimpleModuleResolver modResolver = new SimpleModuleResolver();
                        moduleManager.setModuleResolver(modResolver);
                        for(int j = 0; j < modcount; j++) {
                            Node moduleNode = moduleNodes.item(j);
                            String moduleId = moduleNode.getTextContent();
                            String moduleFileStr = xpath.evaluate("/*[local-name()='test-suite']/*[local-name()='sources']/*[local-name()='module']/@FileName[../@ID='"
                                    + moduleId + "']", catalog);
                            File moduleFile = new File(xqtsDir, moduleFileStr + ".xq");
                            String physical = moduleFile.toURI().toString();
                            String logical = xpath.evaluate("./@namespace", moduleNode);
                            modResolver.addMappingRule(logical, physical);
                        }
                    }
                }
                {// ((//*:test-group)//*:test-case)/*:input-file
                    NodeList vars1 = (NodeList) xpath.evaluate("./*[local-name()='input-file']/@variable", testCase, XPathConstants.NODESET);
                    loadVariables(vars1, testCase, xqmod, statEnv, xpath, catalog, false);
                }
                { // ((//*:test-group)//*:test-case)/*:input-URI
                    NodeList vars2 = (NodeList) xpath.evaluate("./*[local-name()='input-URI']/@variable", testCase, XPathConstants.NODESET);
                    loadVariables(vars2, testCase, xqmod, statEnv, xpath, catalog, true);
                }
                {// ((//*:test-group)//*:test-case)/*:defaultCollection
                    String colId = xpath.evaluate("./*[local-name()='defaultCollection']/text()", testCase);
                    if(colId != null) {
                        NodeList list = (NodeList) xpath.evaluate("/*[local-name()='test-suite']/*[local-name()='sources']/*[local-name()='collection'][@ID='"
                                + colId + "']/*[local-name()='input-document']/text()", catalog, XPathConstants.NODESET);
                        final int listlen = list.getLength();
                        if(listlen > 0) {
                            final Map<String, DTMDocument> defaultCollectionMap = new HashMap<String, DTMDocument>(listlen);
                            for(int j = 0; j < listlen; j++) {
                                String name = list.item(j).getTextContent();
                                String docName = name + ".xml";
                                DTMDocument testDataDoc = _docCache.get(name);
                                if(testDataDoc == null) {
                                    File testDataFile = new File(xqtsDir, docName);
                                    DocumentTableModel dtm = new DocumentTableModel(false);
                                    dtm.loadDocument(new FileInputStream(testDataFile));
                                    testDataDoc = dtm.documentNode();
                                    _docCache.put(name, testDataDoc);
                                }
                                defaultCollectionMap.put(docName, testDataDoc);
                                // import namespace decl
                                Map<String, String> nsmap = testDataDoc.documentTable().getDeclaredNamespaces();
                                NamespaceBinder nsResolver = statEnv.getStaticalyKnownNamespaces();
                                nsResolver.declarePrefixs(nsmap);
                            }
                            statEnv.setDefaultCollection(defaultCollectionMap);
                        }
                    }
                }
                Sequence<? extends Item> contextItem = null;
                {// ((//*:test-group)//*:test-case)/*:contextItem
                    String contextItemRef = xpath.evaluate("./*[local-name()='contextItem']/text()", testCase);
                    if(contextItemRef != null && contextItemRef.length() > 0) {
                        String contextItemFileRef = xpath.evaluate("/*[local-name()='test-suite']/*[local-name()='sources']/*[local-name()='source']/@FileName[../@ID='"
                                + contextItemRef + "']", catalog);
                        DTMDocument contextItemDoc = _docCache.get(contextItemRef);
                        if(contextItemDoc == null) {
                            File contextItemFile = new File(xqtsDir, contextItemFileRef);
                            DocumentTableModel dtm = new DocumentTableModel(false);
                            dtm.loadDocument(new FileInputStream(contextItemFile));
                            contextItemDoc = dtm.documentNode();
                            _docCache.put(contextItemRef, contextItemDoc);
                        }
                        contextItem = contextItemDoc;
                    }
                }
                {// ((//*:test-group)//*:test-case)/*:input-query
                    String inputVarName = xpath.evaluate("./*[local-name()='input-query']/@variable", testCase);
                    if(inputVarName != null && inputVarName.length() > 0) {
                        String dateData = xpath.evaluate("./*[local-name()='input-query']/@date", testCase);
                        assert (dateData != null) : dateData;
                        QualifiedName varName = QNameTable.instantiate(XMLConstants.DEFAULT_NS_PREFIX, inputVarName);
                        Variable var = new Variable.GlobalVariable(varName, null);
                        var.setResult(new DateTimeValue(dateData, DateType.DATE));
                        xqmod.putVariable(varName, var);
                    }
                }

                // -----------------------------------------------------------
                // #1 execute
                final String resString;
                {
                    final String query = IOUtils.toString(new FileInputStream(queryFile), "UTF-8");
                    if(doPrint) {
                        println("Query: ");
                        println(query);
                    }
                    final NodeList expectedErrors = (NodeList) xpath.evaluate("./*[local-name()='expected-error']", testCase, XPathConstants.NODESET);
                    {
                        XQueryProcessor proc = new XQueryProcessor(xqmod);
                        proc.setStaticContext(statEnv);
                        if(contextItem != null) {
                            proc.setContextItem(contextItem);
                        }
                        final StringWriter res_sw = new StringWriter();
                        try {
                            XQueryModule mod = proc.parse(query, baseUri);
                            Sequence result = proc.execute(mod);
                            SAXWriter saxwriter = new SAXWriter(res_sw, SAXWriter.DEFAULT_ENCODING);
                            saxwriter.setXMLDeclaration(false);
                            Serializer ser = new SAXSerializer(saxwriter, res_sw);
                            ser.emit(result);
View Full Code Here

Examples of xbird.xquery.XQueryModule

    private int baseURIDeclCount = 0;

    public XQueryModule parse() throws XQueryException {
        if(currentModule == null) {
            this.currentModule = new XQueryModule();
        }
        final XQueryModule m;
        try {
            m = parseModule(); // returned m is same to currentModule
        } catch (XQueryException xqe) {
            throw xqe;
        } catch (TokenMgrError tme) {
View Full Code Here

Examples of xbird.xquery.XQueryModule

            return;
        } catch (CacheException e) {
            reportError("Caching failed: " + queryPath, e, out);
            return;
        }
        XQueryModule loadedModule = loaded.queryObject;
        XQExpression body = loadedModule.getExpression();
        if(body == null) {
            return;
        }
        // set parameters
        Enumeration<String> paramNames = req.getParameterNames();
        while(paramNames.hasMoreElements()) {
            String name = paramNames.nextElement();
            String value = req.getParameter(name);
            QualifiedName qname = QNameUtil.parse(name, XQSP_NSURI);
            Variable var = new GlobalVariable(qname, null);
            var.setResult(XString.valueOf(value));
            try {
                loadedModule.putVariable(qname, var);
            } catch (XQueryException e) {
                reportError("Setting parameter failed: " + qname, e, out);
                return;
            }
        }
View Full Code Here

Examples of xbird.xquery.XQueryModule

            // parse XQuery expression
            InputStream is = url.openStream();
            XQueryParser parser = new XQueryParser(is);
            StaticContext staticEnv = parser.getStaticContext();
            staticEnv.setBaseURI(path);
            XQueryModule module = parser.parse();
            _lock.readLock().unlock();
            _lock.writeLock().lock();
            // set query cache
            cached.queryObject = module;
            cached.staticEnv = staticEnv;
            cached.loadTimeStamp = System.currentTimeMillis();
            _caches.put(path, cached);
            _lock.writeLock().unlock();
            _lock.readLock().lock();
            // static analysis
            module.staticAnalysis(staticEnv);
        }
        _lock.readLock().unlock();
        return cached;
    }
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.