Examples of SchemaFactory


Examples of javax.xml.validation.SchemaFactory

    }

    private Schema getSchema(InputStream is) {
        Source schemaFile = new StreamSource(is);

        SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = null;
        try {
            schema = factory.newSchema(schemaFile);
        } catch (SAXException ex) {
            throw new ConfigurationException(new Message("SCHEMA_CREATION_ERROR_EXC", LOG), ex);
        }
        return schema;
    }
View Full Code Here

Examples of javax.xml.validation.SchemaFactory

            }
        }
        Schema schema = schemaMap.get(definition);
        if (schema == null) {
            List<javax.wsdl.extensions.schema.Schema> schemas = getSchemas(definition);
            SchemaFactory factory = SchemaFactory.newInstance(
                XMLConstants.W3C_XML_SCHEMA_NS_URI);
            List<Source> schemaSources = new ArrayList<Source>();
            for (javax.wsdl.extensions.schema.Schema s : schemas) {
                Source source = new DOMSource(s.getElement());
                if (source != null) {
                    schemaSources.add(source);
                }
            }
            try {
                schema = factory.newSchema(schemaSources.toArray(
                    new Source[schemaSources.size()]));
                if (schema != null) {
                    synchronized (schemaMap) {
                        schemaMap.put(definition, schema);
                    }
View Full Code Here

Examples of javax.xml.validation.SchemaFactory

         {
            mapper = new XmlNamespacePrefixMapper(config.namespaces());
         }
         if (!"".equals(config.schema()))
         {
            SchemaFactory schemaFactory = SchemaFactory.newInstance(config.schemaType());
            try
            {
               InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(
                       config.schema());
               schema = schemaFactory.newSchema(new StreamSource(in));
            }
            catch (SAXException e)
            {
               throw new JAXBException("Error wil trying to load schema for " + config.schema(), e);
            }
View Full Code Here

Examples of javax.xml.validation.SchemaFactory

    return result;
  }

  private Schema loadSchema() {
    SchemaFactory sf = SchemaFactory
        .newInstance("http://www.w3.org/2001/XMLSchema"); //$NON-NLS-1$
    Schema s = null;
    try {
      s = sf.newSchema(getClass().getResource("/WEB-INF/schemas/po.xsd")); //$NON-NLS-1$
    } catch (SAXException e) {
      e.printStackTrace();
    }
    return s;
  }
View Full Code Here

Examples of javax.xml.validation.SchemaFactory

   
    private SyslogMessage test(String message) throws Exception {
        MessageContext msgContext = new MessageContext();
        ByteArrayInputStream in = new ByteArrayInputStream(message.getBytes("us-ascii"));
        OMElement element = new SyslogMessageBuilder().processDocument(in, null, msgContext);
        SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = factory.newSchema(new StreamSource(SyslogMessageBuilderTest.class.getResource("schema.xsd").toExternalForm()));
        Validator validator = schema.newValidator();
        validator.setErrorHandler(new ErrorHandler() {
            public void error(SAXParseException exception) throws SAXException {
                throw exception;
            }
View Full Code Here

Examples of javax.xml.validation.SchemaFactory

        return clone;
    }

   
    public void validateSchema(Element ele) throws ToolException {
        SchemaFactory schemaFact = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        DOMSource domSrc = new DOMSource(ele);
        try {
            schemaFact.newSchema(domSrc);
        } catch (SAXException e) {
            if (e.getLocalizedMessage().indexOf("src-resolve.4.2") > -1)  {
                //Ignore schema resolve error and do nothing
            } else {
                throw new ToolException("Schema Error : " + e.getLocalizedMessage(), e);
View Full Code Here

Examples of javax.xml.validation.SchemaFactory

    public static synchronized void init(URI uri, Class<?> callingClass) throws XMLSecurityException {
        if (initialized == null || uri != null && !uri.equals(initialized)) {
            try {
                JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
                final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
                SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
                Schema schema = schemaFactory.newSchema(
                        ClassLoaderUtils.getResource("schemas/security-config.xsd", Init.class));
                unmarshaller.setSchema(schema);
                final UnmarshallerHandler unmarshallerHandler = unmarshaller.getUnmarshallerHandler();

                SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
View Full Code Here

Examples of javax.xml.validation.SchemaFactory

   
   
    private static Schema createSchema(ServiceInfo serviceInfo) {
        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 = el.getBaseURI();
                    if (baseURI == null) {
                        baseURI = si.getSystemId();
                    }
                    DOMSource ds = new DOMSource(el, baseURI);  
                    schemaSourcesMap2.put(si.getSystemId() + ":" + si.getNamespaceURI(), ds);
                    LoadingByteArrayOutputStream out = new LoadingByteArrayOutputStream();
                    StaxUtils.copy(el, StaxUtils.createXMLStreamWriter(out));
                    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));
                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

        if (doc.getDocumentElement().getNamespaceURI() == null) {
            return;
        }

        SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        // root element has namespace - we can use schema validation
        Schema schema = factory.newSchema(new StreamSource(FeatureValidationUtil.class
            .getResourceAsStream("/org/apache/karaf/features/karaf-features-1.0.0.xsd")));

        // create schema by reading it from an XSD file:
        Validator validator = schema.newValidator();
View Full Code Here

Examples of javax.xml.validation.SchemaFactory

     * @param xsd
     * @return {@link Schema}
     */
    static Schema getSchema(String xsd) {
        ClassLoader loader = PrivilegedActions.getClassLoader(ValidationParser.class);
        SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        URL schemaUrl = loader.getResource(xsd);
        try {
            return sf.newSchema(schemaUrl);
        } catch (SAXException e) {
            log.warn("Unable to parse schema: " + xsd, e);
            return null;
        }
    }
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.