Ejemplo n.º 1
0
  @SuppressWarnings("unchecked")
  private void putEntityListeners(AnnotationInfo ai, EntityListeners entityListeners) {
    Class[] entityListenerClasses = entityListeners.value();
    if (entityListenerClasses == null) return;

    Map<Class, List<ClassMethodEntry>> listeners = ai.getEntityListeners();

    List<Class<? extends Annotation>> annotations =
        Arrays.asList(
            PrePersist.class,
            PreUpdate.class,
            PreRemove.class,
            PostLoad.class,
            PostPersist.class,
            PostUpdate.class,
            PostRemove.class);
    // TODO: More than one listener per event cannot be handled like this...

    for (Class clazz : entityListenerClasses) {
      //            System.out.println("class=" + clazz);
      for (Method method : clazz.getMethods()) {
        //                System.out.println("method=" + method.getName());
        for (Class<? extends Annotation> annotationClass : annotations) {
          Annotation annotation = method.getAnnotation(annotationClass);
          addListener(listeners, clazz, method, annotation, annotationClass);
        }
      }
    }
  }