Package org.ehcache.sizeof.annotations
Class AnnotationProxyFactory
java.lang.Object
org.ehcache.sizeof.annotations.AnnotationProxyFactory
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
Invocation handler implementing an invoke method that redirects every method call to the custom annotation method when possible; if not returns the reference annotation method default value -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Annotation>
TgetAnnotationProxy
(Annotation customAnnotation, Class<T> referenceAnnotation) Returns a proxy on the customAnnotation, having the same type than the referenceAnnotation
-
Constructor Details
-
AnnotationProxyFactory
private AnnotationProxyFactory()
-
-
Method Details
-
getAnnotationProxy
public static <T extends Annotation> T getAnnotationProxy(Annotation customAnnotation, Class<T> referenceAnnotation) Returns a proxy on the customAnnotation, having the same type than the referenceAnnotation- Parameters:
customAnnotation
- annotation proxiedreferenceAnnotation
- type of the returned annotation- Returns:
- proxied customAnnotation with the type of referenceAnnotation
-