Examples of SchemaFactory


Examples of javax.xml.validation.SchemaFactory

    URL schemaUrl = this.getClass().getClassLoader().getResource( schemaName );
    if ( schemaUrl == null ) {
      return schema;
    }

    SchemaFactory sf = SchemaFactory.newInstance( javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI );
    try {
      schema = sf.newSchema( schemaUrl );
    }
    catch ( SAXException e ) {
      throw new XmlParsingException( "Unable to create schema for " + schemaName + ": " + e.getMessage(), e );
    }
    return schema;
View Full Code Here

Examples of javax.xml.validation.SchemaFactory

      }
   }

   public static void validate(final Node node, final String schemaFile) throws Exception
   {
      SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

      Schema schema = factory.newSchema(findResource(schemaFile));
      Validator validator = schema.newValidator();

      // validate the DOM tree
      try
      {
View Full Code Here

Examples of javax.xml.validation.SchemaFactory

    private static class KieModuleValidator {
        private static final Schema schema = loadSchema();

        private static Schema loadSchema() {
            SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
            try {
                URL url = KieModuleModel.class.getClassLoader().getResource("org/kie/api/kmodule.xsd");
                return factory.newSchema(url);
            } catch (SAXException ex ) {
                throw new RuntimeException( "Unable to load XSD", ex );
            }
        }
View Full Code Here

Examples of javax.xml.validation.SchemaFactory

      DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
      documentBuilderFactory.setNamespaceAware(true);
      DocumentBuilder parser = documentBuilderFactory.newDocumentBuilder();
      Document document = parser.parse(inputStreamXml);

      SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
      InputStream schemaStream = ResourceLoader.getResourceAsStream("nifty-1.3.xsd");
      try {
        Source schemaFile = new StreamSource(schemaStream);
        javax.xml.validation.Schema schema = factory.newSchema(schemaFile);
        javax.xml.validation.Validator validator = schema.newValidator();
        validator.validate(new DOMSource(document));
      } finally {
        schemaStream.close();
      }
View Full Code Here

Examples of javax.xml.validation.SchemaFactory

    private static class KieModuleValidator {
        private static final Schema schema = loadSchema();

        private static Schema loadSchema() {
            SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
            try {
                URL url = KieModuleModel.class.getClassLoader().getResource("org/kie/api/kmodule.xsd");
                return factory.newSchema(url);
            } catch (SAXException ex ) {
                throw new RuntimeException( "Unable to load XSD", ex );
            }
        }
View Full Code Here

Examples of javax.xml.validation.SchemaFactory

    }
    try {
      InputStream schemaStream = url.openStream();
      try {
        StreamSource source = new StreamSource( url.openStream() );
        SchemaFactory schemaFactory = SchemaFactory.newInstance( schemaLanguage );
        return schemaFactory.newSchema( source );
      }
      catch ( SAXException e ) {
        throw new XsdException( "Unable to load schema [" + schemaName + "]", e, schemaName );
      }
      catch ( IOException e ) {
View Full Code Here

Examples of javax.xml.validation.SchemaFactory

        xml = xml.replace(
            "<configuration>",
            "<configuration xmlns=\"" + Constants.NS_CODEGEN + "\">");

        try {
            SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
            javax.xml.validation.Schema schema = sf.newSchema(
                GenerationTool.class.getResource("/xsd/" + Constants.XSD_CODEGEN)
            );

            JAXBContext ctx = JAXBContext.newInstance(Configuration.class);
            Unmarshaller unmarshaller = ctx.createUnmarshaller();
View Full Code Here

Examples of javax.xml.validation.SchemaFactory

            } catch (Exception ex) {
                LOGGER.error("Unable to access schema " + schema);
            }
            if (is != null) {
                Source src = new StreamSource(is, LOG4J_XSD);
                SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
                Schema schema = null;
                try {
                    schema = factory.newSchema(src);
                } catch (SAXException ex) {
                    LOGGER.error("Error parsing Log4j schema", ex);
                }
                if (schema != null) {
                    validator = schema.newValidator();
View Full Code Here

Examples of javax.xml.validation.SchemaFactory

    }
   
    protected Unmarshaller createUnmarshaller() throws JAXBException, SAXException, FileNotFoundException, MalformedURLException {
        Unmarshaller unmarshaller = getContext().createUnmarshaller();
        if (schema != null) {
            SchemaFactory factory = getOrCreateSchemaFactory();
            try {
                Schema newSchema = factory.newSchema(getSources());
                unmarshaller.setSchema(newSchema);
                unmarshaller.setEventHandler(new ValidationEventHandler() {
                    public boolean handleEvent(ValidationEvent event) {
                        // stop unmarshalling if the event is an ERROR or FATAL ERROR
                        return event.getSeverity() == ValidationEvent.WARNING;
View Full Code Here

Examples of javax.xml.validation.SchemaFactory

    }

    protected Marshaller createMarshaller() throws JAXBException, SAXException, FileNotFoundException, MalformedURLException {
        Marshaller marshaller = getContext().createMarshaller();
        if (schema != null) {
            SchemaFactory factory = getOrCreateSchemaFactory();
            try {
                Schema newSchema = factory.newSchema(getSources());
                marshaller.setSchema(newSchema);
                marshaller.setEventHandler(new ValidationEventHandler() {
                    public boolean handleEvent(ValidationEvent event) {
                        // stop marshalling if the event is an ERROR or FATAL ERROR
                        return event.getSeverity() == ValidationEvent.WARNING;
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.