Package net.sf.saxon

Examples of net.sf.saxon.Configuration


     */
    protected synchronized void initialize(Exchange exchange) throws XPathException, IOException {
        // must use synchronized for concurrency issues and only let it initialize once
        if (!initialized.get()) {
            LOG.debug("Initializing XQueryBuilder {}", this);
            configuration = new Configuration();
            configuration.setHostLanguage(Configuration.XQUERY);
            configuration.setStripsWhiteSpace(isStripsAllWhiteSpace() ? Whitespace.ALL : Whitespace.IGNORABLE);

            staticQueryContext = new StaticQueryContext(getConfiguration());
            if (moduleURIResolver != null) {
View Full Code Here


                "' options='" + options + "' when='" + when + "'>");

        for (int f=0; f<tests.length; f++) {
            File file = new File(dir + tests[f]);

            Configuration config = (saproduct ? new EnterpriseConfiguration() : new Configuration());
            if (lazy) {
                config.setLazyConstructionMode(true);
            }
            if (satests) {
                config.setSchemaValidationMode(Validation.STRICT);
                config.addSchemaSource(new StreamSource(new File(dir + "schema.xsd")),
                        config.getErrorListener());
                config.setConfigurationProperty(FeatureKeys.USE_TYPED_VALUE_CACHE, "false");
            }
            if (val) {
                config.loadSchema(new File(dir + "sa\\schema.xsd").toURI().toString());
                config.setSchemaValidationMode(Validation.STRICT);
            }

            Source streamSource = new StreamSource(file);
            long pstart = System.currentTimeMillis();
            DocumentInfo doc = config.buildDocument(streamSource);
            long pend = System.currentTimeMillis();

            System.out.println("  <file name='" + tests[f] +
                    "' size='" + file.length() +
                    "' build-time='" + (pend-pstart) + "'>");
            Properties props = new Properties();
            props.setProperty("method", "xml");
            props.setProperty("indent", "yes");

            if (runCompiled) {
                for (int q=1; q<=20; q++) {
                    if (test != -1 && test != q) {
                        continue;
                    }
                    try {

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

            if (sa) {
                factory = new EnterpriseTransformerFactory();
            } else {
                factory = new TransformerFactoryImpl();
            }
            Configuration config = ((TransformerFactoryImpl)factory).getConfiguration();
            if (lazy) {
                config.setLazyConstructionMode(true);
            }

            Source streamSource = new StreamSource(file);
            long pstart = System.currentTimeMillis();
            DocumentInfo doc = config.buildDocument(streamSource);
            long pend = System.currentTimeMillis();

            System.out.println("  <file name='" + tests[f] +
                    "' size='" + file.length() +
                    "' schema-aware='" + config.isLicensedFeature(Configuration.LicenseFeature.SCHEMA_AWARE_XSLT) +
                    "' build-time='" + (pend-pstart) + "'>");

            for (int q=1; q<=20; q++) {
                //if (q==9) continue;
                File sheet = new File(dir + 'q' + q + ".xsl");
View Full Code Here

    public Expression preEvaluate(ExpressionVisitor visitor) throws XPathException {
        String lexicalQName = ((Literal)argument[0]).getValue().getStringValue();
        StaticContext env = visitor.getStaticContext();
        boolean b = false;
        Configuration config = visitor.getConfiguration();
        switch(operation) {
            case ELEMENT_AVAILABLE:
                b = ((XSLTStaticContext)env).isElementAvailable(lexicalQName);
                break;
            case FUNCTION_AVAILABLE:
                long arity = -1;
                if (argument.length == 2) {
                    arity = ((NumericValue)argument[1].evaluateItem(env.makeEarlyEvaluationContext())).longValue();
                }
                try {
                    String[] parts = config.getNameChecker().getQNameParts(lexicalQName);
                    String prefix = parts[0];
                    String uri;
                    if (prefix.length() == 0) {
                        uri = env.getDefaultFunctionNamespace();
                    } else {
                        uri = env.getURIForPrefix(prefix);
                    }
                    StructuredQName functionName = new StructuredQName(prefix, uri, parts[1]);
                    b = (env.getFunctionLibrary().getFunctionSignature(functionName, (int)arity)) != null;
                } catch (QNameException e) {
                    XPathException err = new XPathException(e.getMessage());
                    err.setErrorCode("XTDE1400");
                    throw err;
                } catch (XPathException e2) {
                    if ("XTDE0290".equals(e2.getErrorCodeLocalPart())) {
                        e2.setErrorCode("XTDE1400");
                    }
                    throw e2;
                }
                break;
            case TYPE_AVAILABLE:
                try {
                    String[] parts = config.getNameChecker().getQNameParts(lexicalQName);
                    String prefix = parts[0];
                    String uri;
                    if (prefix.length() == 0) {
                        uri = env.getDefaultElementNamespace();
                    } else {
                        uri = env.getURIForPrefix(prefix);
                    }
                    if (uri.equals(NamespaceConstant.JAVA_TYPE)) {
                        try {
                            config.getClass(parts[1], false, null);
                            b = true;
                        } catch (XPathException err) {
                            b = false;
                        }
                    } else {
                        int fingerprint = config.getNamePool().allocate(prefix, uri, parts[1]) & 0xfffff;
                        SchemaType type = config.getSchemaType(fingerprint);
                        if (type instanceof BuiltInAtomicType) {
                            b = env.isAllowedBuiltInType((BuiltInAtomicType)type);
                        } else if (type instanceof BuiltInListType) {
                            b = visitor.getExecutable().isSchemaAware();
                        } else {
View Full Code Here

        // Note: this requires the compile-time classes to be available at run-time; it will need
        // changing if we ever want to build a run-time JAR file.

        try {
            if (styleNodeFactory==null) {
                Configuration config = context.getConfiguration();
                styleNodeFactory = config.getStyleNodeFactory();
            }
            return styleNodeFactory.isElementAvailable(uri, localname);
        } catch (Exception err) {
            //err.printStackTrace();
            return false;
View Full Code Here

     * @param args Takes one argument, the XPath expression to be analyzed
     * @throws Exception
     */

    public static void main(String[] args) throws Exception {
        Configuration config = new Configuration();
        Expression exp;
        if (args[0].equals("xpath")) {
            XPathEvaluator xpath = new XPathEvaluator(config);
            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");
View Full Code Here

     */

    public static void main(String[] args) throws Exception {
        for (int i=0; i<1; i++) {
            long startTime = System.currentTimeMillis();
            PipelineConfiguration pipe = new Configuration().makePipelineConfiguration();
            StaxBridge puller = new StaxBridge();
            File f = new File(args[0]);
            puller.setInputStream(f.toURI().toString(), new FileInputStream(f));
            XMLEmitter emitter = new XMLEmitter();
            emitter.setPipelineConfiguration(pipe);
View Full Code Here

    public ItemType getItemType(TypeHierarchy th) {
        if (typeLabel.equals(BuiltInAtomicType.ANY_ATOMIC)) {
            if (th == null) {
                throw new NullPointerException("No TypeHierarchy supplied");
            } else {
                Configuration config = th.getConfiguration();
                typeLabel = new ExternalObjectType(value.getClass(), config);
            }
        }
        return typeLabel;
    }
View Full Code Here

    private void applySchemaImport(Import sImport) throws XPathException {

        // Do the importing

        Configuration config = env.getConfiguration();
        if (!config.isSchemaAvailable(sImport.namespaceURI)) {
            if (!sImport.locationURIs.isEmpty()) {
                try {
                    PipelineConfiguration pipe = config.makePipelineConfiguration();
                    config.readMultipleSchemas(pipe, env.getBaseURI(), sImport.locationURIs, sImport.namespaceURI);
                    namespacesToBeSealed.add(sImport.namespaceURI);
                } catch (TransformerConfigurationException err) {
                    grumble("Error in schema. " + err.getMessage(), "XQST0059");
                }
            } else {
View Full Code Here

    public XMLStreamReader getSequenceAsStream() throws XQException {
        checkNotClosed();
        checkOnlyReadOnce();
        EventIterator ei = new EventIteratorOverSequence(iterator);
        ei = new BracketedDocumentIterator(ei);
        Configuration config = getConfiguration();
        PipelineConfiguration pipe = config.makePipelineConfiguration();
        pipe.setHostLanguage(Configuration.XQUERY);
        ei = new Decomposer(ei, pipe);
        return new EventToStaxBridge(ei, pipe);
    }
View Full Code Here

TOP

Related Classes of net.sf.saxon.Configuration

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.