Search in sources :

Example 1 with EntityMappings

use of org.hibernate.jpamodelgen.xml.jaxb.EntityMappings 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 EntityMappings

use of org.hibernate.jpamodelgen.xml.jaxb.EntityMappings in project hibernate-orm by hibernate.

the class JpaDescriptorParser method determineAnnotationAccessTypes.

private void determineAnnotationAccessTypes() {
    for (EntityMappings mappings : entityMappings) {
        String fqcn;
        String packageName = mappings.getPackage();
        for (Entity entity : mappings.getEntity()) {
            String name = entity.getClazz();
            fqcn = StringUtil.determineFullyQualifiedClassName(packageName, name);
            TypeElement element = context.getTypeElementForFullyQualifiedName(fqcn);
            if (element != null) {
                TypeUtils.determineAccessTypeForHierarchy(element, context);
            }
        }
        for (org.hibernate.jpamodelgen.xml.jaxb.MappedSuperclass mappedSuperClass : mappings.getMappedSuperclass()) {
            String name = mappedSuperClass.getClazz();
            fqcn = StringUtil.determineFullyQualifiedClassName(packageName, name);
            TypeElement element = context.getTypeElementForFullyQualifiedName(fqcn);
            if (element != null) {
                TypeUtils.determineAccessTypeForHierarchy(element, context);
            }
        }
    }
}
Also used : Entity(org.hibernate.jpamodelgen.xml.jaxb.Entity) TypeElement(javax.lang.model.element.TypeElement) EntityMappings(org.hibernate.jpamodelgen.xml.jaxb.EntityMappings)

Example 3 with EntityMappings

use of org.hibernate.jpamodelgen.xml.jaxb.EntityMappings in project hibernate-orm by hibernate.

the class JpaDescriptorParser method determineXmlAccessTypes.

private void determineXmlAccessTypes() {
    for (EntityMappings mappings : entityMappings) {
        String fqcn;
        String packageName = mappings.getPackage();
        AccessType defaultAccessType = determineEntityAccessType(mappings);
        for (Entity entity : mappings.getEntity()) {
            String name = entity.getClazz();
            fqcn = StringUtil.determineFullyQualifiedClassName(packageName, name);
            AccessType explicitAccessType = null;
            org.hibernate.jpamodelgen.xml.jaxb.AccessType type = entity.getAccess();
            if (type != null) {
                explicitAccessType = mapXmlAccessTypeToJpaAccessType(type);
            }
            AccessTypeInformation accessInfo = new AccessTypeInformation(fqcn, explicitAccessType, defaultAccessType);
            context.addAccessTypeInformation(fqcn, accessInfo);
        }
        for (org.hibernate.jpamodelgen.xml.jaxb.MappedSuperclass mappedSuperClass : mappings.getMappedSuperclass()) {
            String name = mappedSuperClass.getClazz();
            fqcn = StringUtil.determineFullyQualifiedClassName(packageName, name);
            AccessType explicitAccessType = null;
            org.hibernate.jpamodelgen.xml.jaxb.AccessType type = mappedSuperClass.getAccess();
            if (type != null) {
                explicitAccessType = mapXmlAccessTypeToJpaAccessType(type);
            }
            AccessTypeInformation accessInfo = new AccessTypeInformation(fqcn, explicitAccessType, defaultAccessType);
            context.addAccessTypeInformation(fqcn, accessInfo);
        }
        for (org.hibernate.jpamodelgen.xml.jaxb.Embeddable embeddable : mappings.getEmbeddable()) {
            String name = embeddable.getClazz();
            fqcn = StringUtil.determineFullyQualifiedClassName(packageName, name);
            AccessType explicitAccessType = null;
            org.hibernate.jpamodelgen.xml.jaxb.AccessType type = embeddable.getAccess();
            if (type != null) {
                explicitAccessType = mapXmlAccessTypeToJpaAccessType(type);
            }
            AccessTypeInformation accessInfo = new AccessTypeInformation(fqcn, explicitAccessType, defaultAccessType);
            context.addAccessTypeInformation(fqcn, accessInfo);
        }
    }
}
Also used : Entity(org.hibernate.jpamodelgen.xml.jaxb.Entity) EntityMappings(org.hibernate.jpamodelgen.xml.jaxb.EntityMappings) AccessType(org.hibernate.jpamodelgen.util.AccessType) AccessTypeInformation(org.hibernate.jpamodelgen.util.AccessTypeInformation)

Example 4 with EntityMappings

use of org.hibernate.jpamodelgen.xml.jaxb.EntityMappings in project hibernate-orm by hibernate.

the class JpaDescriptorParser method parseXml.

public void parseXml() {
    Collection<String> mappingFileNames = determineMappingFileNames();
    if (context.doLazyXmlParsing() && mappingFilesUnchanged(mappingFileNames)) {
        return;
    }
    loadEntityMappings(mappingFileNames);
    determineDefaultAccessTypeAndMetaCompleteness();
    determineXmlAccessTypes();
    if (!context.isFullyXmlConfigured()) {
        // need to take annotations into consideration, since they can override xml settings
        // we have to at least determine whether any of the xml configured entities is influenced by annotations
        determineAnnotationAccessTypes();
    }
    for (EntityMappings mappings : entityMappings) {
        String defaultPackageName = mappings.getPackage();
        parseEntities(mappings.getEntity(), defaultPackageName);
        parseEmbeddable(mappings.getEmbeddable(), defaultPackageName);
        parseMappedSuperClass(mappings.getMappedSuperclass(), defaultPackageName);
    }
}
Also used : EntityMappings(org.hibernate.jpamodelgen.xml.jaxb.EntityMappings)

Aggregations

EntityMappings (org.hibernate.jpamodelgen.xml.jaxb.EntityMappings)4 Entity (org.hibernate.jpamodelgen.xml.jaxb.Entity)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 TypeElement (javax.lang.model.element.TypeElement)1 Schema (javax.xml.validation.Schema)1 AccessType (org.hibernate.jpamodelgen.util.AccessType)1 AccessTypeInformation (org.hibernate.jpamodelgen.util.AccessTypeInformation)1 XmlParsingException (org.hibernate.jpamodelgen.util.xml.XmlParsingException)1