Package net.sf.saxon.query

Examples of net.sf.saxon.query.XQueryExpression


        Configuration config = null;
        Properties props = new Properties();
        props.setProperty(OutputKeys.METHOD, "xml");
        props.setProperty(OutputKeys.INDENT, "yes");

        XQueryExpression exp = implementation.getCompiledExpressionsCache().get(xqExpression);
        if (exp == null) {
            config = new Configuration();
            StaticQueryContext sqc = new StaticQueryContext(config);
            exp = sqc.compileQuery(xqExpression);
            implementation.getCompiledExpressionsCache().put(xqExpression, exp);
        } else {
            config = exp.getStaticContext().getConfiguration();
        }

        Object[] params = prepareParameters(payload, config, props);

        DynamicQueryContext dynamicContext = new DynamicQueryContext(config);

        // Setting the parameters for function invokation
        String methodName = theMethod.getName();
        for (int i = 0; i < params.length; i++) {
            dynamicContext.setParameter(methodName + "_" + i, params[i]);
        }

        // Setting references
        for (Map.Entry<String, Object> entry : referenceProxies.entrySet()) {
            dynamicContext.setParameter(entry.getKey(), entry.getValue());
        }

        // Setting properties
        for (Map.Entry<String, Object> entry : properties.entrySet()) {
            dynamicContext.setParameter(entry.getKey(), transformProperty(entry.getValue(), config));
        }

        SequenceIterator iterator = null;
        Configuration oldConfigValue = SaxonDataBindingHelper.CURR_EXECUTING_CONFIG;
        SaxonDataBindingHelper.CURR_EXECUTING_CONFIG = config;
        try {
            iterator = exp.iterator(dynamicContext);
        } finally {
            SaxonDataBindingHelper.CURR_EXECUTING_CONFIG = oldConfigValue;
        }
        Item item = iterator.next();
        if (item == null) {
View Full Code Here


    public Node evaluateAsDOM(Exchange exchange) throws Exception {
        initialize(exchange);

        DOMResult result = new DOMResult();
        DynamicQueryContext context = createDynamicContext(exchange);
        XQueryExpression expression = getExpression();
        expression.pull(context, result, properties);
        return result.getNode();
    }
View Full Code Here

        Configuration config = null;
        Properties props = new Properties();
        props.setProperty(OutputKeys.METHOD, "xml");
        props.setProperty(OutputKeys.INDENT, "yes");

        XQueryExpression exp = implementation.getCompiledExpressionsCache().get(xqExpression);
        if (exp == null) {
            config = new Configuration();
            StaticQueryContext sqc = new StaticQueryContext(config);
            exp = sqc.compileQuery(xqExpression);
            implementation.getCompiledExpressionsCache().put(xqExpression, exp);
        } else {
            config = exp.getStaticContext().getConfiguration();
        }

        Object[] params = prepareParameters(payload, config, props);

        DynamicQueryContext dynamicContext = new DynamicQueryContext(config);

        // Setting the parameters for function invocation
        String methodName = theMethod.getName();
        for (int i = 0; i < params.length; i++) {
            dynamicContext.setParameter(methodName + "_" + i, params[i]);
        }

        // Setting references
        for (Map.Entry<String, Object> entry : referenceProxies.entrySet()) {
            dynamicContext.setParameter(entry.getKey(), entry.getValue());
        }

        // Setting properties
        for (Map.Entry<String, Object> entry : properties.entrySet()) {
            dynamicContext.setParameter(entry.getKey(), transformProperty(entry.getValue(), config));
        }

        SequenceIterator iterator = null;
        Configuration oldConfigValue = SaxonDataBindingHelper.CURR_EXECUTING_CONFIG;
        SaxonDataBindingHelper.CURR_EXECUTING_CONFIG = config;
        try {
            iterator = exp.iterator(dynamicContext);
        } finally {
            SaxonDataBindingHelper.CURR_EXECUTING_CONFIG = oldConfigValue;
        }
       
        ItemList list = new ItemList();
View Full Code Here

        xqExpression += "\r\n<dummy></dummy>";

        Configuration config = new Configuration();
        StaticQueryContext sqc = new StaticQueryContext(config);
        XQueryExpression exp = null;
        try {
            exp = sqc.compileQuery(xqExpression);
        } catch (XPathException e) {
            throw new ContributionResolveException(e);
        }
View Full Code Here

    public Node evaluateAsDOM(Exchange exchange) throws Exception {
        initialize(exchange);

        DOMResult result = new DOMResult();
        DynamicQueryContext context = createDynamicContext(exchange);
        XQueryExpression expression = getExpression();
        expression.pull(context, result, properties);
        return result.getNode();
    }
View Full Code Here

    public Node evaluateAsDOM(Exchange exchange) throws Exception {
        initialize(exchange);

        DOMResult result = new DOMResult();
        DynamicQueryContext context = createDynamicContext(exchange);
        XQueryExpression expression = getExpression();
        expression.pull(context, result, properties);
        return result.getNode();
    }
View Full Code Here

                    } else {
                        StaticQueryContext env = saConfig.newStaticQueryContext();
                        env.setModuleURIResolver(new XQTSModuleURIResolver(testCase));
                        env.setBaseURI(new File(absQueryName).toURI().toString());
                        env.setLanguageVersion(languageVersion);
                        XQueryExpression xqe;

                        try {
                            xqe = env.compileQuery(new FileInputStream(absQueryName), "UTF-8");
                        } catch (XPathException err) {
                            processError(err, testCase, testName, filePath + queryName + ".xq", expectedErrorNT, specVersionAtt);
                            continue;
                        }

                        NodeInfo optElement = getChildElement(testCase, optimizationNT);
                        if (optElement != null) {
                            String explain = optElement.getAttributeValue(explainAtt);
                            if ("true".equals(explain) || "1".equals(explain)) {
                                ExpressionPresenter presenter = new ExpressionPresenter(saConfig);
                                xqe.explain(presenter);
                                presenter.close();
                            }
                            String assertion = optElement.getAttributeValue(assertAtt);
                            if (assertion != null) {
                                TinyBuilder builder = new TinyBuilder();
                                builder.setPipelineConfiguration(saConfig.makePipelineConfiguration());
                                ExpressionPresenter presenter = new ExpressionPresenter(saConfig, builder);
                                xqe.explain(presenter);
                                presenter.close();
                                NodeInfo expressionTree = builder.getCurrentRoot();
                                XPathEvaluator xpe = new XPathEvaluator(saConfig);
                                XPathExpression exp = xpe.createExpression(assertion);
                                try {
                                    Boolean bv = (Boolean)exp.evaluateSingle(expressionTree);
                                    if (bv == null || !bv.booleanValue()) {
                                        log.println("** Optimization assertion failed");
                                        optimizationOK = false;
                                    }
                                } catch (Exception e) {
                                    log.println("** Optimization assertion result is not a boolean: " + assertion +
                                            "(" + e.getMessage() + ")");

                                }
                            }
                        }

                        DynamicQueryContext dqc = new DynamicQueryContext(saConfig);

                        NodeInfo contextItemElement = getChildElement(testCase, contextItemNT);
                        if (contextItemElement != null) {
                            DocumentInfo contextNode = loadDocument(contextItemElement.getStringValue());
                            dqc.setContextItem(contextNode);
                        }

                        processInputQueries(testCase, inputQueryNT, variableAtt, nameAtt, filePath, dqc);

                        processInputDocuments(testCase, inputFileNT, variableAtt, dqc);

                        setQueryParameters(catalog, testCase, dqc, inputUriNT, variableAtt, collectionNT, idAtt);

                        NodeInfo defaultCollection = getChildElement(testCase, defaultCollectionNT);
                        if (defaultCollection != null) {
                            String docName = defaultCollection.getStringValue();
                            NodeInfo collectionElement = getCollectionElement(catalog, docName, collectionNT, idAtt);
                            CollectionURIResolver r =
                                            new XQTSCollectionURIResolver(catalog, collectionElement, true);
                            saConfig.setCollectionURIResolver(r);
                        }


                        // Run the query

                        String outputDir = saxonDir + "/results/" + filePath;
                        if (outputDir.endsWith("/")) {
                            outputDir = outputDir.substring(0, outputDir.length()-1);
                        }
                        new File(outputDir).mkdirs();
                        outputFile = outputDir + "/" + testName + ".out";
                        File outputFileF = new File(outputFile);
                        outputFileF.createNewFile();
                        StreamResult result = new StreamResult(outputFileF);
                        try {
                            if (usePull) {
                                xqe.pull(dqc, result, outputProps);
                            } else {
                                xqe.run(dqc, result, outputProps);
                            }
                        } catch (XPathException err) {
                            processError(err, testCase, testName, filePath + queryName + ".xq", expectedErrorNT, specVersionAtt);
                            continue;
                        }
View Full Code Here

            variableName = toClarkName(variableName);
            if (variableName != null) {
                String preQueryName = inputQuery.getAttributeValue(nameAtt);
                String subQueryFile = testSuiteDir + "/Queries/XQuery/" + filePath + preQueryName + ".xq";
                StaticQueryContext sqc2 = saConfig.newStaticQueryContext();
                XQueryExpression subQuery = sqc2.compileQuery(new FileReader(subQueryFile));
                SequenceIterator subQueryResult = subQuery.iterator(new DynamicQueryContext(saConfig));
                dqc.setParameterValue(variableName, SequenceExtent.makeSequenceExtent(subQueryResult));
            }
        }
    }
View Full Code Here

                        StaticQueryContext qenv = config.newStaticQueryContext();
                        qenv.setBaseURI(query.toURI().toString());
                        if (val) {
                            qenv.getExecutable().setSchemaAware(true);
                        }
                        XQueryExpression exp = qenv.compileQuery(new FileReader(query));
                        int runs = 0;
                        long totalTime = 0;
                        long min = Integer.MAX_VALUE;
                        long max = 0;
                        for (int t=0; t<1000; t++) {
                            final DynamicQueryContext context = new DynamicQueryContext(config);
                            context.setContextItem(doc);
                            Result result = new Sink();
                            long start, end;
                            if (pull) {
                                start = System.currentTimeMillis();
                                exp.pull(context, result, props);
                                end = System.currentTimeMillis();
                            } else {
                                start = System.currentTimeMillis();
                                exp.run(context, result, props);
                                end = System.currentTimeMillis();
                            }
                            runs++;
                            long time = (end - start);
                            if (time < min) min = time;
View Full Code Here

            XPathExpression xpexp = xpath.createExpression(args[1]);
            exp = xpexp.getInternalExpression();
        } else if (args[0].equals("xquery")) {
            StaticQueryContext sqc = config.newStaticQueryContext();
            sqc.setBaseURI(new File(args[1]).toURI().toString());
            XQueryExpression xqe = sqc.compileQuery(new FileReader(args[1]));
            exp = xqe.getExpression();
        } else {
            throw new IllegalArgumentException("first argument must be xpath or xquery");
        }
        exp.explain(System.err);
        PathMap initialPath = new PathMap(exp);
View Full Code Here

TOP

Related Classes of net.sf.saxon.query.XQueryExpression

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.