Class AnnotationProxyFactory


  • public final class AnnotationProxyFactory
    extends java.lang.Object

    Allows you to transform the type of your custom annotation to a reference annotation type.
    It can come handy when you want to allow the consumers of your library not to depend on your API because of the annotations, still allowing them to use the original annotation methods.

    Example :

    getting a custom annotation from a class
    my.Annotation customAnnotation = klazz.getAnnotation(my.Annotation.class);
    if this annotation is "similar" (duck-typing, same methods) to the reference one, I can get a proxy to it, whose type is the reference annotation
    ehcache.Annotation annotation = AnnotationProxyFactory.getAnnotationProxy(customAnnotation, ehcache.Annotation.class);

    so my library can apply the behavior when the default annotation is used
    @ehcache.Annotation(action="true") public class UserClass {}

    or when a custom one is used, since all calls to action() will be caught and redirected to the custom annotation action method, if it exists, or fall back to the reference action method
    @my.Annotation(action="true") public class UserClass {}

    Author:
    Anthony Dahanne
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T extends java.lang.annotation.Annotation>
      T
      getAnnotationProxy​(java.lang.annotation.Annotation customAnnotation, java.lang.Class<T> referenceAnnotation)
      Returns a proxy on the customAnnotation, having the same type than the referenceAnnotation
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getAnnotationProxy

        public static <T extends java.lang.annotation.Annotation> T getAnnotationProxy​(java.lang.annotation.Annotation customAnnotation,
                                                                                       java.lang.Class<T> referenceAnnotation)
        Returns a proxy on the customAnnotation, having the same type than the referenceAnnotation
        Parameters:
        customAnnotation -
        referenceAnnotation -
        Returns:
        proxied customAnnotation with the type of referenceAnnotation