Search in sources :

Example 1 with EntityListeners

use of javax.persistence.EntityListeners in project simplejpa by appoxy.

the class AnnotationManager method putEntityListeners.

private void putEntityListeners(AnnotationInfo ai, Class c) {
    EntityListeners listeners = (EntityListeners) c.getAnnotation(EntityListeners.class);
    if (listeners != null) {
        logger.fine("Found EntityListeners for " + c + " - " + listeners);
        putEntityListeners(ai, listeners);
    }
}
Also used : EntityListeners(javax.persistence.EntityListeners)

Example 2 with EntityListeners

use of javax.persistence.EntityListeners in project hibernate-orm by hibernate.

the class CallbackBuilderLegacyImpl method getListeners.

private static void getListeners(XClass currentClazz, List<Class> orderedListeners) {
    EntityListeners entityListeners = currentClazz.getAnnotation(EntityListeners.class);
    if (entityListeners != null) {
        Class[] classes = entityListeners.value();
        int size = classes.length;
        for (int index = size - 1; index >= 0; index--) {
            orderedListeners.add(classes[index]);
        }
    }
    if (useAnnotationAnnotatedByListener) {
        Annotation[] annotations = currentClazz.getAnnotations();
        for (Annotation annot : annotations) {
            entityListeners = annot.getClass().getAnnotation(EntityListeners.class);
            if (entityListeners != null) {
                Class[] classes = entityListeners.value();
                int size = classes.length;
                for (int index = size - 1; index >= 0; index--) {
                    orderedListeners.add(classes[index]);
                }
            }
        }
    }
}
Also used : XClass(org.hibernate.annotations.common.reflection.XClass) EntityListeners(javax.persistence.EntityListeners) Annotation(java.lang.annotation.Annotation)

Example 3 with EntityListeners

use of javax.persistence.EntityListeners in project hibernate-orm by hibernate.

the class JPAOverriddenAnnotationReader method getEntityListeners.

private EntityListeners getEntityListeners(Element tree, XMLContext.Default defaults) {
    Element element = tree != null ? tree.element("entity-listeners") : null;
    if (element != null) {
        List<Class> entityListenerClasses = new ArrayList<Class>();
        for (Element subelement : (List<Element>) element.elements("entity-listener")) {
            String className = subelement.attributeValue("class");
            try {
                entityListenerClasses.add(classLoaderAccess.classForName(XMLContext.buildSafeClassName(className, defaults)));
            } catch (ClassLoadingException e) {
                throw new AnnotationException("Unable to find " + element.getPath() + ".class: " + className, e);
            }
        }
        AnnotationDescriptor ad = new AnnotationDescriptor(EntityListeners.class);
        ad.setValue("value", entityListenerClasses.toArray(new Class[entityListenerClasses.size()]));
        return AnnotationFactory.create(ad);
    } else if (defaults.canUseJavaAnnotations()) {
        return getPhysicalAnnotation(EntityListeners.class);
    } else {
        return null;
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) AnnotationException(org.hibernate.AnnotationException) MapKeyClass(javax.persistence.MapKeyClass) IdClass(javax.persistence.IdClass) ArrayList(java.util.ArrayList) List(java.util.List) EntityListeners(javax.persistence.EntityListeners)

Aggregations

EntityListeners (javax.persistence.EntityListeners)3 Annotation (java.lang.annotation.Annotation)1 AnnotatedElement (java.lang.reflect.AnnotatedElement)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IdClass (javax.persistence.IdClass)1 MapKeyClass (javax.persistence.MapKeyClass)1 Element (org.dom4j.Element)1 AnnotationException (org.hibernate.AnnotationException)1 AnnotationDescriptor (org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor)1 XClass (org.hibernate.annotations.common.reflection.XClass)1 ClassLoadingException (org.hibernate.boot.registry.classloading.spi.ClassLoadingException)1