Search in sources :

Example 1 with XmlParsingException

use of org.hibernate.jpamodelgen.util.xml.XmlParsingException in project hibernate-orm by hibernate.

the class JpaDescriptorParser method loadEntityMappings.

private void loadEntityMappings(Collection<String> mappingFileNames) {
    for (String mappingFile : mappingFileNames) {
        InputStream stream = xmlParserHelper.getInputStreamForResource(mappingFile);
        if (stream == null) {
            continue;
        }
        EntityMappings mapping = null;
        try {
            Schema schema = xmlParserHelper.getSchema(ORM_SCHEMA);
            mapping = xmlParserHelper.getJaxbRoot(stream, EntityMappings.class, schema);
        } catch (XmlParsingException e) {
            context.logMessage(Diagnostic.Kind.WARNING, "Unable to parse " + mappingFile + ": " + e.getMessage());
        }
        if (mapping != null) {
            entityMappings.add(mapping);
        }
        try {
            stream.close();
        } catch (IOException e) {
        // eat it
        }
    }
}
Also used : ObjectInputStream(java.io.ObjectInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) XmlParsingException(org.hibernate.jpamodelgen.util.xml.XmlParsingException) Schema(javax.xml.validation.Schema) EntityMappings(org.hibernate.jpamodelgen.xml.jaxb.EntityMappings) IOException(java.io.IOException)

Example 2 with XmlParsingException

use of org.hibernate.jpamodelgen.util.xml.XmlParsingException in project hibernate-orm by hibernate.

the class JpaDescriptorParser method getPersistence.

private Persistence getPersistence() {
    Persistence persistence = null;
    String persistenceXmlLocation = context.getPersistenceXmlLocation();
    InputStream stream = xmlParserHelper.getInputStreamForResource(persistenceXmlLocation);
    if (stream == null) {
        return null;
    }
    try {
        Schema schema = xmlParserHelper.getSchema(PERSISTENCE_SCHEMA);
        persistence = xmlParserHelper.getJaxbRoot(stream, Persistence.class, schema);
    } catch (XmlParsingException e) {
        context.logMessage(Diagnostic.Kind.WARNING, "Unable to parse persistence.xml: " + e.getMessage());
    }
    try {
        stream.close();
    } catch (IOException e) {
    // eat it
    }
    return persistence;
}
Also used : Persistence(org.hibernate.jpamodelgen.xml.jaxb.Persistence) ObjectInputStream(java.io.ObjectInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) XmlParsingException(org.hibernate.jpamodelgen.util.xml.XmlParsingException) Schema(javax.xml.validation.Schema) IOException(java.io.IOException)

Aggregations

FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ObjectInputStream (java.io.ObjectInputStream)2 Schema (javax.xml.validation.Schema)2 XmlParsingException (org.hibernate.jpamodelgen.util.xml.XmlParsingException)2 EntityMappings (org.hibernate.jpamodelgen.xml.jaxb.EntityMappings)1 Persistence (org.hibernate.jpamodelgen.xml.jaxb.Persistence)1