Search in sources :

Example 1 with JaxbCfgEventListenerType

use of org.hibernate.boot.jaxb.cfg.spi.JaxbCfgEventListenerType in project hibernate-orm by hibernate.

the class LoadedConfig method consume.

/**
 * Consumes the JAXB representation of a {@code cfg.xml} file and builds the
 * LoadedConfig representation.
 *
 * @param jaxbCfg The JAXB representation of a {@code cfg.xml} file
 *
 * @return The parsed representation
 */
public static LoadedConfig consume(JaxbCfgHibernateConfiguration jaxbCfg) {
    final LoadedConfig cfg = new LoadedConfig(jaxbCfg.getSessionFactory().getName());
    for (JaxbCfgConfigPropertyType jaxbProperty : jaxbCfg.getSessionFactory().getProperty()) {
        cfg.addConfigurationValue(jaxbProperty.getName(), jaxbProperty.getValue());
    }
    for (JaxbCfgMappingReferenceType jaxbMapping : jaxbCfg.getSessionFactory().getMapping()) {
        cfg.addMappingReference(MappingReference.consume(jaxbMapping));
    }
    for (Object cacheDeclaration : jaxbCfg.getSessionFactory().getClassCacheOrCollectionCache()) {
        cfg.addCacheRegionDefinition(parseCacheRegionDefinition(cacheDeclaration));
    }
    if (jaxbCfg.getSecurity() != null) {
        for (JaxbCfgHibernateConfiguration.JaxbCfgSecurity.JaxbCfgGrant grant : jaxbCfg.getSecurity().getGrant()) {
            final JaccPermissionDeclarations jaccPermissions = cfg.getOrCreateJaccPermissions(jaxbCfg.getSecurity().getContext());
            jaccPermissions.addPermissionDeclaration(new GrantedPermission(grant.getRole(), grant.getEntityName(), grant.getActions()));
        }
    }
    if (!jaxbCfg.getSessionFactory().getListener().isEmpty()) {
        for (JaxbCfgEventListenerType listener : jaxbCfg.getSessionFactory().getListener()) {
            final EventType eventType = EventType.resolveEventTypeByName(listener.getType().value());
            cfg.addEventListener(eventType, listener.getClazz());
        }
    }
    if (!jaxbCfg.getSessionFactory().getEvent().isEmpty()) {
        for (JaxbCfgEventListenerGroupType listenerGroup : jaxbCfg.getSessionFactory().getEvent()) {
            if (listenerGroup.getListener().isEmpty()) {
                continue;
            }
            final String eventTypeName = listenerGroup.getType().value();
            final EventType eventType = EventType.resolveEventTypeByName(eventTypeName);
            for (JaxbCfgEventListenerType listener : listenerGroup.getListener()) {
                if (listener.getType() != null) {
                    log.debugf("Listener [%s] defined as part of a group also defined event type", listener.getClazz());
                }
                cfg.addEventListener(eventType, listener.getClazz());
            }
        }
    }
    return cfg;
}
Also used : JaxbCfgEventListenerType(org.hibernate.boot.jaxb.cfg.spi.JaxbCfgEventListenerType) JaccPermissionDeclarations(org.hibernate.secure.spi.JaccPermissionDeclarations) EventType(org.hibernate.event.spi.EventType) JaxbCfgConfigPropertyType(org.hibernate.boot.jaxb.cfg.spi.JaxbCfgConfigPropertyType) GrantedPermission(org.hibernate.secure.spi.GrantedPermission) JaxbCfgMappingReferenceType(org.hibernate.boot.jaxb.cfg.spi.JaxbCfgMappingReferenceType) JaxbCfgEventListenerGroupType(org.hibernate.boot.jaxb.cfg.spi.JaxbCfgEventListenerGroupType)

Aggregations

JaxbCfgConfigPropertyType (org.hibernate.boot.jaxb.cfg.spi.JaxbCfgConfigPropertyType)1 JaxbCfgEventListenerGroupType (org.hibernate.boot.jaxb.cfg.spi.JaxbCfgEventListenerGroupType)1 JaxbCfgEventListenerType (org.hibernate.boot.jaxb.cfg.spi.JaxbCfgEventListenerType)1 JaxbCfgMappingReferenceType (org.hibernate.boot.jaxb.cfg.spi.JaxbCfgMappingReferenceType)1 EventType (org.hibernate.event.spi.EventType)1 GrantedPermission (org.hibernate.secure.spi.GrantedPermission)1 JaccPermissionDeclarations (org.hibernate.secure.spi.JaccPermissionDeclarations)1