Package javax.xml.validation

Examples of javax.xml.validation.SchemaFactory


    }

   
    public void validateSchema(Element ele, String uri,
                               final OASISCatalogManager catalog) throws ToolException {
        SchemaFactory schemaFact = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        schemaFact.setResourceResolver(new LSResourceResolver() {
            public LSInput resolveResource(String type, 
                                           String namespaceURI,
                                           String publicId,
                                           String systemId,
                                           String baseURI) {
                String s = JAXBDataBinding.mapSchemaLocation(systemId, baseURI, catalog);
                return new LSInputSAXWrapper(new InputSource(s));
            }
        });
        DOMSource domSrc = new DOMSource(ele, uri);
        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


        wrapperAnnotation = method.getAnnotation(RequestWrapper.class);
       
        InputStream is =  getClass().getResourceAsStream("resources/StringStruct.xsd");
        StreamSource schemaSource = new StreamSource(is);
        assertNotNull(schemaSource);
        SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        schema = factory.newSchema(schemaSource);
        assertNotNull(schema);
    }
View Full Code Here

            return;
        }

        try {
            // Create SchemaFactory and configure for the default schema language - XMLSchema
            SchemaFactory factory = SchemaFactory.newInstance(DEFAULT_SCHEMA_LANGUAGE);
            factory.setErrorHandler(errorHandler);

            // set any features on/off as requested
            iter = properties.entrySet().iterator();
            while (iter.hasNext()) {
                Map.Entry entry = (Map.Entry) iter.next();
                String value = (String) entry.getValue();
                factory.setFeature(
                    (String) entry.getKey(), value != null && "true".equals(value));
            }

            Schema schema = null;

            StreamSource[] sources = new StreamSource[schemaKeys.size()];
            iter = schemaKeys.iterator();
            int i = 0;
            while (iter.hasNext()) {
                String propName = (String) iter.next();
                sources[i++] = Util.getStreamSource(
                    msgCtx.getConfiguration().getProperty(propName));
            }
            schema = factory.newSchema(sources);

            // Setup validator and input source
            // Features set for the SchemaFactory get propagated to Schema and Validator (JAXP 1.4)
            validator = schema.newValidator();
            validator.setErrorHandler(errorHandler);
View Full Code Here

        resolver = new DefaultModelResolver();
    }

    public void testValidateAssembly() throws Exception {
       
        SchemaFactory schemaFactory;
        try {
            schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        } catch (Error e) {
            // Some old JDKs don't support XMLSchema validation
            return;
        } catch (Exception e) {
            // Some old JDKs don't support XMLSchema validation
            return;
        }
        Schema schema = schemaFactory.newSchema(getClass().getClassLoader().getResource("tuscany-sca.xsd"));
        ValidatorHandler handler = schema.newValidatorHandler();
       
        SAXParserFactory parserFactory = SAXParserFactory.newInstance();
        URL url = getClass().getResource("Calculator.composite");
        XMLReader reader = parserFactory.newSAXParser().getXMLReader();
View Full Code Here

        assertNotNull(composite);
    }
       
    public void testValidateBinding() throws Exception {
       
        SchemaFactory schemaFactory;
        try {
            schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        } catch (Error e) {
            // Some old JDKs don't support XMLSchema validation
            return;
        } catch (Exception e) {
            // Some old JDKs don't support XMLSchema validation
            return;
        }
        Schema schema = schemaFactory.newSchema(getClass().getClassLoader().getResource("tuscany-sca.xsd"));
        ValidatorHandler handler = schema.newValidatorHandler();
       
        SAXParserFactory parserFactory = SAXParserFactory.newInstance();
        URL url = getClass().getResource("RMIBindingTest.composite");
        XMLReader reader = parserFactory.newSAXParser().getXMLReader();
View Full Code Here

        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

        return schema;
    }
   
    public static Schema createSchema(List<String> locations, String catalogLocation, final Bus bus) {
       
        SchemaFactory factory = SchemaFactory.newInstance(WSDLConstants.NS_SCHEMA_XSD);
        Schema s = null;
        try {
            List<Source> sources = new ArrayList<Source>();
            for (String loc : locations) {
                URL url = ResourceUtils.getResourceURL(loc, bus);
                if (url == null) {
                    throw new IllegalArgumentException("Cannot find XML schema location: " + loc);
                }
                Reader r = new BufferedReader(
                               new InputStreamReader(url.openStream(), "UTF-8"));
                StreamSource source = new StreamSource(r);
                source.setSystemId(url.toString());
                sources.add(source);
            }
            final OASISCatalogManager catalogResolver = OASISCatalogManager.getCatalogManager(bus);
            if (catalogResolver != null) {
                catalogLocation = catalogLocation == null
                    ? SchemaHandler.DEFAULT_CATALOG_LOCATION : catalogLocation;
                URL catalogURL = ResourceUtils.getResourceURL(catalogLocation, bus);
                if (catalogURL != null) {
                    try {
                        catalogResolver.loadCatalog(catalogURL);
                        factory.setResourceResolver(new LSResourceResolver() {
   
                            public LSInput resolveResource(String type, String namespaceURI, String publicId,
                                                           String systemId, String baseURI) {
                                try {
                                    String resolvedLocation  = catalogResolver.resolveSystem(systemId);
                                   
                                    if (resolvedLocation == null) {
                                        resolvedLocation = catalogResolver.resolveURI(namespaceURI);
                                    }
                                    if (resolvedLocation == null) {
                                        resolvedLocation = catalogResolver.resolvePublic(publicId, systemId);
                                    }
                                    if (resolvedLocation != null) {
                                        InputStream resourceStream =
                                            ResourceUtils.getResourceStream(resolvedLocation, bus);
                                        if (resourceStream != null) {
                                            return new LSInputImpl(publicId, systemId, resourceStream);
                                        }
                                    }
                                } catch (Exception ex) {
                                    // ignore
                                }
                                return null;
                            }
                           
                        });
                    } catch (IOException ex) {
                        throw new IllegalArgumentException("Catalog " + catalogLocation + " can not be loaded", ex);
                    }
                }
            }
            s = factory.newSchema(sources.toArray(new Source[sources.size()]));
        } catch (Exception ex) {
            throw new IllegalArgumentException("Failed to load XML schema : " + ex.getMessage(), ex);
        }
        return s;
       
View Full Code Here

    protected void init() throws JBIException {
        super.init();

        try {
            if (schema == null) {
                SchemaFactory factory = SchemaFactory.newInstance(schemaLanguage);

                if (schemaSource == null) {
                    if (schemaResource == null) {
                        throw new JBIException("You must specify a schema, schemaSource or schemaResource property");
                    }
                    if (schemaResource.getURL() == null) {
                        schemaSource = new StreamSource(schemaResource.getInputStream());
                    } else {
                        schemaSource = new StreamSource(schemaResource.getInputStream(), schemaResource.getURL().toExternalForm());
                    }
                }
                schema = factory.newSchema(schemaSource);
            }
        }
        catch (IOException e) {
            throw new JBIException("Failed to load schema: " + e, e);
        }
View Full Code Here

    // initialize a document from an input stream
    private static Document initializeDocument(InputStream in) throws IOException {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        try {
            // XML schema for validation
            SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
            URL xsdUrl = RegistrationDocument.class.getResource(REGISTRATION_DATA_SCHEMA);
            Schema schema = sf.newSchema(xsdUrl);
            Validator validator = schema.newValidator();

            DocumentBuilder builder = factory.newDocumentBuilder();
            Document doc = builder.parse(new InputSource(in));
            validator.validate(new DOMSource(doc));
View Full Code Here

            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

TOP

Related Classes of javax.xml.validation.SchemaFactory

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.