Examples of SchemaFactory


Examples of javax.xml.validation.SchemaFactory

        }
        return sources;
    }

    private SchemaFactory getOrCreateSchemaFactory() {
        SchemaFactory factory = SCHEMA_FACTORY_POOL.poll();
        if (factory == null) {
            factory = createSchemaFactory();
        }
        return factory;
    }
View Full Code Here

Examples of javax.xml.validation.SchemaFactory

    }

    private static synchronized Schema getSchema() {
        if (rmSchema == null) {
            try {
                SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
                javax.xml.transform.Source ad = new StreamSource(RMEndpoint.class
                                             .getResource("/schemas/wsdl/addressing.xsd")
                                             .openStream(),
                                             "http://schemas.xmlsoap.org/ws/2004/08/addressing");
                javax.xml.transform.Source rm = new StreamSource(RMEndpoint.class
                                                                 .getResource("/schemas/wsdl/wsrm.xsd")
                                                                 .openStream());
               
                javax.xml.transform.Source schemas[] = new javax.xml.transform.Source[] {ad, rm};
                rmSchema = factory.newSchema(schemas);
            } catch (Exception ex) {
                //ignore
            }
        }
        return rmSchema;
View Full Code Here

Examples of javax.xml.validation.SchemaFactory

                // See also: http://java.net/jira/browse/JAXB-537

                Unmarshaller unmarshaller = context.createUnmarshaller();

                String xsd = this.generateSchema(type);
                SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
                Schema schema = sf.newSchema(new StreamSource(new StringReader(xsd)));

                ValidationEventCollector eventHandler = new ValidationEventCollector();
                unmarshaller.setEventHandler(eventHandler);
                unmarshaller.setSchema(schema);
View Full Code Here

Examples of javax.xml.validation.SchemaFactory

        if (b == null) {
            b = BusFactory.getThreadDefaultBus(false);
        }
        Schema schema = serviceInfo.getProperty(Schema.class.getName(), Schema.class);
        if (schema == null) {
            SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
            Map<String, byte[]> schemaSourcesMap = new LinkedHashMap<String, byte[]>();
            Map<String, Source> schemaSourcesMap2 = new LinkedHashMap<String, Source>();

            try {
                for (SchemaInfo si : serviceInfo.getSchemas()) {
                    Element el = si.getElement();
                    String baseURI = null;
                    try {
                        baseURI = el.getBaseURI();
                    } catch (Exception ex) {
                        //ignore - not DOM level 3
                    }
                    if (baseURI == null) {
                        baseURI = si.getSystemId();
                    }
                    DOMSource ds = new DOMSource(el, baseURI);  
                    schemaSourcesMap2.put(si.getSystemId() + ":" + si.getNamespaceURI(), ds);
                    LoadingByteArrayOutputStream out = new LoadingByteArrayOutputStream();
                    XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(out);
                    StaxUtils.copy(el, writer);
                    writer.flush();
                    schemaSourcesMap.put(si.getSystemId() + ":" + si.getNamespaceURI(), out.toByteArray());
                }

               
                for (XmlSchema sch : serviceInfo.getXmlSchemaCollection().getXmlSchemas()) {
                    if (sch.getSourceURI() != null
                        && !schemaSourcesMap.containsKey(sch.getSourceURI() + ":"
                                                         + sch.getTargetNamespace())) {
                       
                        InputStream ins = null;
                        try {
                            URL url = new URL(sch.getSourceURI());
                            ins = url.openStream();
                        } catch (Exception e) {
                            //ignore, we'll just use what we have.  (though
                            //bugs in XmlSchema could make this less useful)
                        }
                       
                        LoadingByteArrayOutputStream out = new LoadingByteArrayOutputStream();
                        if (ins == null) {
                            sch.write(out);
                        } else {
                            IOUtils.copyAndCloseInput(ins, out);
                        }

                        schemaSourcesMap.put(sch.getSourceURI() + ":"
                                             + sch.getTargetNamespace(), out.toByteArray());
                       
                        Source source = new StreamSource(out.createInputStream(), sch.getSourceURI());
                        schemaSourcesMap2.put(sch.getSourceURI() + ":"
                                              + sch.getTargetNamespace(), source);
                    }
                }


                factory.setResourceResolver(new SchemaLSResourceResolver(schemaSourcesMap, b));
                schema = factory.newSchema(schemaSourcesMap2.values()
                                           .toArray(new Source[schemaSourcesMap2.size()]));
               
               
            } catch (Exception ex) {
                // Something not right with the schema from the wsdl.
View Full Code Here

Examples of javax.xml.validation.SchemaFactory

        throw new IllegalArgumentException("You must specify a schema, "
                                           + "schemaFile, schemaSource or schemaUrl property");
    }

    protected Schema createSchema() throws SAXException, IOException {
        SchemaFactory factory = getSchemaFactory();

        URL url = getSchemaUrl();
        if (url != null) {
            return factory.newSchema(url);
        }
        File file = getSchemaFile();
        if (file != null) {
            return factory.newSchema(file);
        }
        return factory.newSchema(getSchemaSource());
    }
View Full Code Here

Examples of javax.xml.validation.SchemaFactory

            for (int i = 0; i < urls.length; i++) {
                urls[i] = new URL(uris.get(i));
            }
            final Collection<? extends Source> sources = aggregate(urls);           

            final SchemaFactory schemaFactory = newSchemaFactory();
            DOMImplementation impl = null;
            try {
                impl = documentBuilderFactory.newDocumentBuilder().getDOMImplementation();
            } catch (ParserConfigurationException e) {
                // Ignore
            }
            if (impl instanceof DOMImplementationLS) {
                ls = (DOMImplementationLS)impl;
                schemaFactory.setResourceResolver(this);
            }
            // Allow privileged access to check files. Requires FilePermission
            // in security policy.
            try {
                aggregatedSchema = AccessController.doPrivileged(new PrivilegedExceptionAction<Schema>() {
                    public Schema run() throws SAXException {
                        return schemaFactory.newSchema(sources.toArray(new Source[sources.size()]));
                    }
                });
            } catch (PrivilegedActionException e) {
              warn(monitor, "PrivilegedActionException", schemaFactory, (SAXException)e.getException());
              hasSchemas = false;
View Full Code Here

Examples of javax.xml.validation.SchemaFactory

       
        // get the source
        SAXSource sourceForValidate = new SAXSource(xmlFilter, new InputSource(in));
       
        // get the schema
        SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
       
        JaxbJavaeeSchemaResourceResolver resourceResolver = new JaxbJavaeeSchemaResourceResolver()
        schemaFactory.setResourceResolver(resourceResolver)
       
        Schema schema = schemaFactory.newSchema(
                new Source[] {
                        new StreamSource(xmlSchemaURL.openStream()),
                        new StreamSource(javaeeSchemaURL.openStream())
                });
View Full Code Here

Examples of javax.xml.validation.SchemaFactory

        if (serviceInfo == null) {
            return null;
        }
        Schema schema = serviceInfo.getProperty(Schema.class.getName(), Schema.class);
        if (schema == null) {
            SchemaFactory factory = SchemaFactory.newInstance(
                XMLConstants.W3C_XML_SCHEMA_NS_URI);
            List<Source> schemaSources = new ArrayList<Source>();
            final XmlSchemaCollection sc = serviceInfo.getXmlSchemaCollection();
            for (SchemaInfo schemaInfo : serviceInfo.getSchemas()) {
                Source source = new DOMSource(schemaInfo.getElement());
                if (source != null) {
                    source.setSystemId(schemaInfo.getElement().getBaseURI());
                    schemaSources.add(source);
                }
            }
            try {
                factory.setResourceResolver(new LSResourceResolver() {
                    public LSInput resolveResource(String type, String namespaceURI, String publicId,
                                                   String systemId, String baseURI) {
                        for (XmlSchema sch : sc.getXmlSchemas()) {
                            if (namespaceURI.equals(sch.getTargetNamespace())) {
                                LSInputImpl impl = new LSInputImpl();
                                InputStream ins = null;
                                try {
                                    URL url = new URL(sch.getSourceURI());
                                    ins = url.openStream();
                                } catch (Exception e) {
                                    //ignore, we'll just use what we have.  (though
                                    //bugs in XmlSchema could make this less useful)
                                }
                               
                                if (ins == null) {
                                    LoadingByteArrayOutputStream out = new LoadingByteArrayOutputStream();
                                    sch.write(out);
                                    ins = out.createInputStream();
                                }
                                impl.setByteStream(ins);
                                return impl;
                            }
                        }
                        return null;
                    }
                   
                });
                schema = factory.newSchema(schemaSources.toArray(
                    new Source[schemaSources.size()]));
                if (schema != null) {
                    serviceInfo.setProperty(Schema.class.getName(), schema);
                    LOG.log(Level.FINE, "Obtained schema from ServiceInfo");
                }
View Full Code Here

Examples of javax.xml.validation.SchemaFactory

    // Implementation methods
    // -----------------------------------------------------------------------

    protected SchemaFactory createSchemaFactory() {
        SchemaFactory factory = SchemaFactory.newInstance(schemaLanguage);
        if (getResourceResolver() != null) {
            factory.setResourceResolver(getResourceResolver());
        }
        return factory;
    }
View Full Code Here

Examples of javax.xml.validation.SchemaFactory

    protected Source createSchemaSource() throws IOException {
        throw new IllegalArgumentException("You must specify either a schema, schemaFile, schemaSource or schemaUrl property");
    }

    protected Schema createSchema() throws SAXException, IOException {
        SchemaFactory factory = getSchemaFactory();

        URL url = getSchemaUrl();
        if (url != null) {
            return factory.newSchema(url);
        }

        File file = getSchemaFile();
        if (file != null) {
            return factory.newSchema(file);
        }

        byte[] bytes = getSchemaAsByteArray();
        if (bytes != null) {
            return factory.newSchema(new StreamSource(new ByteArrayInputStream(schemaAsByteArray)));
        }

        Source source = getSchemaSource();
        return factory.newSchema(source);
    }
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.