Search in sources :

Example 1 with XsdException

use of org.hibernate.internal.util.xml.XsdException in project hibernate-orm by hibernate.

the class PersistenceXmlParser method resolveLocalSchema.

private Schema resolveLocalSchema(String schemaName) {
    // These XSD resources should be available on the Hibernate ClassLoader
    final URL url = classLoaderService.locateResource(schemaName);
    if (url == null) {
        throw new XsdException("Unable to locate schema [" + schemaName + "] via classpath", schemaName);
    }
    try {
        InputStream schemaStream = url.openStream();
        try {
            StreamSource source = new StreamSource(url.openStream());
            SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
            return schemaFactory.newSchema(source);
        } catch (SAXException e) {
            throw new XsdException("Unable to load schema [" + schemaName + "]", e, schemaName);
        } catch (IOException e) {
            throw new XsdException("Unable to load schema [" + schemaName + "]", e, schemaName);
        } finally {
            try {
                schemaStream.close();
            } catch (IOException e) {
                LOG.debugf("Problem closing schema stream [%s]", e.toString());
            }
        }
    } catch (IOException e) {
        throw new XsdException("Stream error handling schema url [" + url.toExternalForm() + "]", schemaName);
    }
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) XsdException(org.hibernate.internal.util.xml.XsdException) IOException(java.io.IOException) URL(java.net.URL) SAXException(org.xml.sax.SAXException)

Example 2 with XsdException

use of org.hibernate.internal.util.xml.XsdException in project hibernate-orm by hibernate.

the class JaxbCfgProcessor method resolveLocalSchema.

private Schema resolveLocalSchema(String schemaName, String schemaLanguage) {
    URL url = classLoaderService.locateResource(schemaName);
    if (url == null) {
        throw new XsdException("Unable to locate schema [" + schemaName + "] via classpath", schemaName);
    }
    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) {
            throw new XsdException("Unable to load schema [" + schemaName + "]", e, schemaName);
        } finally {
            try {
                schemaStream.close();
            } catch (IOException e) {
                log.debugf("Problem closing schema stream [%s]", e.toString());
            }
        }
    } catch (IOException e) {
        throw new XsdException("Stream error handling schema url [" + url.toExternalForm() + "]", schemaName);
    }
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) XsdException(org.hibernate.internal.util.xml.XsdException) IOException(java.io.IOException) URL(java.net.URL) SAXException(org.xml.sax.SAXException)

Aggregations

IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 URL (java.net.URL)2 StreamSource (javax.xml.transform.stream.StreamSource)2 SchemaFactory (javax.xml.validation.SchemaFactory)2 XsdException (org.hibernate.internal.util.xml.XsdException)2 SAXException (org.xml.sax.SAXException)2