Examples of DynamicQueryContext


Examples of net.sf.saxon.query.DynamicQueryContext

            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;
View Full Code Here

Examples of net.sf.saxon.query.DynamicQueryContext

    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

Examples of net.sf.saxon.query.DynamicQueryContext

    /**
     * Creates a dynamic context for the given exchange
     */
    protected DynamicQueryContext createDynamicContext(Exchange exchange) throws Exception {
        Configuration config = getConfiguration();
        DynamicQueryContext dynamicQueryContext = new DynamicQueryContext(config);

        Message in = exchange.getIn();

        Item item = in.getBody(Item.class);
        if (item != null) {
            dynamicQueryContext.setContextItem(item);
        } else {
            Source source = in.getBody(Source.class);
            if (source == null) {
                source = converter.toSource(converter.createDocument());
            }
            DocumentInfo doc = getStaticQueryContext().buildDocument(source);
            dynamicQueryContext.setContextItem(doc);
        }
       
        configureQuery(dynamicQueryContext, exchange);
        // call the reset if the in message body is StreamCache
        MessageHelper.resetStreamCache(exchange.getIn());
View Full Code Here

Examples of net.sf.saxon.query.DynamicQueryContext

    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

Examples of net.sf.saxon.query.DynamicQueryContext

    /**
     * Creates a dynamic context for the given exchange
     */
    protected DynamicQueryContext createDynamicContext(Exchange exchange) throws Exception {
        Configuration config = getConfiguration();
        DynamicQueryContext dynamicQueryContext = new DynamicQueryContext(config);

        Message in = exchange.getIn();

        Item item = in.getBody(Item.class);
        if (item != null) {
            dynamicQueryContext.setContextItem(item);
        } else {
            Object body = in.getBody();

            // the underlying input stream, which we need to close to avoid locking files or other resources
            InputStream is = null;
            try {
                Source source;
                // only convert to input stream if really needed
                if (isInputStreamNeeded(exchange)) {
                    is = exchange.getIn().getBody(InputStream.class);
                    source = getSource(exchange, is);
                } else {
                    source = getSource(exchange, body);
                }

                // special for bean invocation
                if (source == null) {
                    if (body instanceof BeanInvocation) {
                        // if its a null bean invocation then handle that
                        BeanInvocation bi = exchange.getContext().getTypeConverter().convertTo(BeanInvocation.class, body);
                        if (bi.getArgs() != null && bi.getArgs().length == 1 && bi.getArgs()[0] == null) {
                            // its a null argument from the bean invocation so use null as answer
                            source = null;
                        }
                    }
                }

                if (source == null) {
                    // indicate it was not possible to convert to a Source type
                    throw new NoTypeConversionAvailableException(body, Source.class);
                }

                DocumentInfo doc = getStaticQueryContext().buildDocument(source);
                dynamicQueryContext.setContextItem(doc);
            } finally {
                // can deal if is is null
                IOHelper.close(is);
            }
        }
View Full Code Here

Examples of net.sf.saxon.query.DynamicQueryContext

                        qc.setClassName(makeClassName(groupName, queryName));
                        File dir = new File(saxonDir + "/java/");
                        dir.mkdir();
                        qc.setOutputDirectory(dir);

                        DynamicQueryContext dqc = new DynamicQueryContext(saConfig);
                        dqc.setParameterValue("zlsJJ", StringValue.EMPTY_STRING);
                        NodeInfo contextItemElement = getChildElement(testCase, contextItemNT);
                        if (contextItemElement != null) {
                            DocumentInfo contextNode = loadDocument(contextItemElement.getStringValue());
                            dqc.setContextItem(contextNode);
                        }

                        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);
                        }

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

                        String outputDir = saxonDir + "/results/" + filePath;
                        new File(outputDir).mkdirs();
                        outputFile = outputDir + "/" + testName + ".out";
                        File outputFileF = new File(outputFile);
                        outputFileF.createNewFile();
                        StreamResult result = new StreamResult(outputFileF);
                        try {
                            qc.runQuery(dqc, result, outputProps);
                        } catch (XPathException err) {
                            if (!err.hasBeenReported()) {
                                log.println(err.getMessage());
                            }
                            processError(err, testCase, testName, filePath + queryName + ".xq", expectedErrorNT, specVersionAtt);
                            continue;
                        } catch (ClassNotFoundException err) {
                            // means the query had a static error
                            continue;
                        } catch (Exception err2) {
                            err2.printStackTrace();
                            continue;
                        }
                    } 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);
View Full Code Here

Examples of net.sf.saxon.query.DynamicQueryContext

            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

Examples of net.sf.saxon.query.DynamicQueryContext

                        ClassLoader usercodeLoader = new URLClassLoader(
                                new URL[]{new URL("file:///e:/javalib/xMark/java/")});
                        Class userClass = usercodeLoader.loadClass("Q" + q);
                        CompiledUserQuery cuq = (CompiledUserQuery) userClass.newInstance();
                        cuq.setConfiguration(config);
                        final DynamicQueryContext dqc = new DynamicQueryContext(config);
                        cuq.setDynamicContext(dqc);

                        int runs = 0;
                        long totalTime = 0;
                        long min = Integer.MAX_VALUE;
                        long max = 0;
                        if (checkResults && f==0) {
                            dqc.setContextItem(doc);
                            File out = new File("e:/javalib/xmark/output/q" + q + ".out");
                            //out.mkdirs();
                            OutputStream os = new FileOutputStream(out);
                            Result result = new StreamResult(os);
                            cuq.run(result, props);
                            os.close();
                            compare(new File("e:/javalib/xmark/output/q" + q + ".out"),
                                    new File("e:/javalib/xmark/gold1m/q" + q + ".out"));
                        }
                        for (int t=0; t<1000; t++) {

                            dqc.setContextItem(doc);
                            Result result = new Sink();
                            long start, end;
                            start = System.currentTimeMillis();
                            cuq.run(result, props);
                            end = System.currentTimeMillis();

                            runs++;
                            long time = (end - start);
                            if (time < min) min = time;
                            if (time > max) max = time;
                            totalTime += time;
                            if (totalTime > 30000 && t>=2) break;
                        }
                        double avg = ((double)totalTime) / runs;
                        String avgs = format.format(avg);
                        System.out.println("    <query q='" + q +
                                    "' avg='" + avgs +
                                    "' runs='" + runs +
                                    "' min='" + min +
                                    "' max='" + max + "'/>");
                    } catch (XPathException err) {
                        System.err.println("Error in test " + q);
                        System.err.println(err.getMessageAndLocation());
                    }
                }
            } else {

                for (int q=1; q<=20; q++) {
                    if (test != -1 && test != q) {
                        continue;
                    }
                    try {
                        File query = new File(dir + 'q' + q + ".xq");
                        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);
View Full Code Here

Examples of net.sf.saxon.query.DynamicQueryContext

        checkNotClosed();
        try {
            SaxonXQStaticContext xqStaticContext = ((SaxonXQStaticContext)properties);
            StaticQueryContext sqc = xqStaticContext.getSaxonStaticQueryContext();
            XQueryExpression exp = sqc.compileQuery(xquery, null);
            DynamicQueryContext dqc = new DynamicQueryContext(config);
            return new SaxonXQPreparedExpression(this, exp, xqStaticContext, dqc);
        } catch (XPathException e) {
            throw newXQException(e);
        } catch (IOException e) {
            throw newXQException(e);
View Full Code Here

Examples of net.sf.saxon.query.DynamicQueryContext

        checkNotClosed();
        try {
            SaxonXQStaticContext xqStaticContext = ((SaxonXQStaticContext)properties);
            StaticQueryContext sqc = xqStaticContext.getSaxonStaticQueryContext();
            XQueryExpression exp = sqc.compileQuery(xquery);
            DynamicQueryContext dqc = new DynamicQueryContext(config);
            return new SaxonXQPreparedExpression(this, exp, xqStaticContext, dqc);
        } catch (XPathException e) {
            throw newXQException(e);
        } catch (IOException e) {
            throw newXQException(e);
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.