org.jboss.solder.reflection
Class AnnotationInspector

java.lang.Object
  extended by org.jboss.solder.reflection.AnnotationInspector

public class AnnotationInspector
extends Object

Inspect an AnnotatedElement or Annotated to obtain its meta-annotations and annotations, featuring support for Stereotype annotations as a transitive annotation provider.

Author:
Pete Muir, Dan Allen

Method Summary
static
<A extends Annotation>
A
getAnnotation(Annotated annotated, Class<A> annotationType, BeanManager beanManager)
          Inspect the Annotated and retrieve the specified annotation type, if present.
static
<A extends Annotation>
A
getAnnotation(AnnotatedElement element, Class<A> annotationType, BeanManager beanManager)
          Inspect the AnnotatedElement and retrieve the specified annotation type, if present.
static
<A extends Annotation>
A
getAnnotation(AnnotatedElement element, Class<A> annotationType, boolean transitive, BeanManager beanManager)
          Inspect the AnnotatedElement for a specific annotation type.
static
<A extends Annotation>
A
getAnnotationFromStereotype(Annotated annotated, Class<A> annotationType, BeanManager beanManager)
          Discover if the Annotated has been annotated with a @ Stereotype that provides the specified annotation type and return it.
static
<A extends Annotation>
A
getAnnotationFromStereotype(AnnotatedElement element, Class<A> annotationType, BeanManager beanManager)
          Discover if the AnnotatedElement has been annotated with a @ Stereotype that provides the annotation type and return it.
static Set<Annotation> getAnnotations(Annotated element, Class<? extends Annotation> metaAnnotationType)
          Inspects an annotated element for any annotations with the given meta annotation.
static
<A extends Annotation>
A
getMetaAnnotation(Annotated element, Class<A> annotationType)
          Inspects an annotated element for the given meta annotation.
static boolean isAnnotationPresent(Annotated annotated, Class<? extends Annotation> annotationType, BeanManager beanManager)
          Discover if the Annotated has been annotated with the specified annotation type.
static boolean isAnnotationPresent(AnnotatedElement element, Class<? extends Annotation> annotationType, BeanManager beanManager)
          Discover if the AnnotatedElement has been annotated with the specified annotation type.
static boolean isAnnotationPresent(AnnotatedElement element, Class<? extends Annotation> annotationType, boolean transitive, BeanManager beanManager)
          Discover if the AnnotatedElement has been annotated with the specified annotation type.
static boolean isAnnotationPresentOnStereotype(Annotated annotated, Class<? extends Annotation> annotationType, BeanManager beanManager)
          Discover if the Annotated has been annotated with a @ Stereotype that provides the specified annotation type.
static boolean isAnnotationPresentOnStereotype(AnnotatedElement element, Class<? extends Annotation> annotationType, BeanManager beanManager)
          Discover if the AnnotatedElement has been annotated with a @ Stereotype that provides the annotation type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isAnnotationPresent

public static boolean isAnnotationPresent(AnnotatedElement element,
                                          Class<? extends Annotation> annotationType,
                                          BeanManager beanManager)
Discover if the AnnotatedElement has been annotated with the specified annotation type. This method discovers annotations defined on the element as well as annotations inherited from a CDI @ Stereotype on the element.

Parameters:
element - The element to inspect
annotationType - The annotation type to expect
beanManager - The CDI BeanManager instance
Returns:
true if annotation is present either on the element itself or one of its stereotypes, false if the annotation is not present

isAnnotationPresent

public static boolean isAnnotationPresent(Annotated annotated,
                                          Class<? extends Annotation> annotationType,
                                          BeanManager beanManager)
Discover if the Annotated has been annotated with the specified annotation type. This method discovers annotations defined on the element as well as annotations inherited from a CDI @ Stereotype on the element.

Parameters:
element - The element to inspect
annotationType - The annotation type to expect
beanManager - The CDI BeanManager instance
Returns:
true if annotation is present either on the element itself or one of its stereotypes, false if the annotation is not present

isAnnotationPresent

public static boolean isAnnotationPresent(AnnotatedElement element,
                                          Class<? extends Annotation> annotationType,
                                          boolean transitive,
                                          BeanManager beanManager)
Discover if the AnnotatedElement has been annotated with the specified annotation type. If the transitive argument is true , this method also discovers annotations inherited from a CDI @ Stereotype on the element.

Parameters:
element - The element to inspect
annotationType - The annotation to expect
transitive - Whether annotations provided by stereotypes should be considered
beanManager - The CDI BeanManager instance
Returns:
true if annotation is present on the element itself or (if specified) one of its stereotypes, false if the annotation is not present

isAnnotationPresentOnStereotype

public static boolean isAnnotationPresentOnStereotype(AnnotatedElement element,
                                                      Class<? extends Annotation> annotationType,
                                                      BeanManager beanManager)
Discover if the AnnotatedElement has been annotated with a @ Stereotype that provides the annotation type.

Parameters:
element - The element to inspect
annotationType - The annotation type to expect
beanManager - The CDI BeanManager instance
Returns:
true if annotation is provided by a stereotype on the element, false if the annotation is not present

isAnnotationPresentOnStereotype

public static boolean isAnnotationPresentOnStereotype(Annotated annotated,
                                                      Class<? extends Annotation> annotationType,
                                                      BeanManager beanManager)
Discover if the Annotated has been annotated with a @ Stereotype that provides the specified annotation type.

Parameters:
element - The element to inspect.
annotationType - The annotation type to expect
beanManager - The CDI BeanManager instance
Returns:
true if annotation is provided by a stereotype on the element, false if the annotation is not present

getAnnotation

public static <A extends Annotation> A getAnnotation(AnnotatedElement element,
                                                     Class<A> annotationType,
                                                     BeanManager beanManager)
Inspect the AnnotatedElement and retrieve the specified annotation type, if present. This method discovers annotations defined on the element as well as annotations inherited from a CDI @ Stereotype on the element.

Parameters:
element - The element to inspect
annotationType - The annotation type to expect
beanManager - The CDI BeanManager instance
Returns:
The annotation instance found on this element or null if no matching annotation was found.

getAnnotation

public static <A extends Annotation> A getAnnotation(Annotated annotated,
                                                     Class<A> annotationType,
                                                     BeanManager beanManager)
Inspect the Annotated and retrieve the specified annotation type, if present. This method discovers annotations defined on the element as well as annotations inherited from a CDI @ Stereotype on the element.

Parameters:
annotated - The element to inspect
annotationType - The annotation type to expect
beanManager - The CDI BeanManager instance
Returns:
The annotation instance found on this element or null if no matching annotation was found.

getAnnotation

public static <A extends Annotation> A getAnnotation(AnnotatedElement element,
                                                     Class<A> annotationType,
                                                     boolean transitive,
                                                     BeanManager beanManager)
Inspect the AnnotatedElement for a specific annotation type. If the transitive argument is true , this method also discovers annotations inherited from a CDI @ Stereotype on the element.

Parameters:
element - The element to inspect
annotationType - The annotation type to expect
transitive - Whether the annotation may be used as a meta-annotation or not
beanManager - The CDI BeanManager instance
Returns:
The annotation instance found on this element or null if no matching annotation was found.

getAnnotationFromStereotype

public static <A extends Annotation> A getAnnotationFromStereotype(AnnotatedElement element,
                                                                   Class<A> annotationType,
                                                                   BeanManager beanManager)
Discover if the AnnotatedElement has been annotated with a @ Stereotype that provides the annotation type and return it.

Parameters:
element - The element to inspect
annotationType - The annotation type to expect
beanManager - The CDI BeanManager instance
Returns:
The annotation instance found on this element or null if no matching annotation was found.

getAnnotationFromStereotype

public static <A extends Annotation> A getAnnotationFromStereotype(Annotated annotated,
                                                                   Class<A> annotationType,
                                                                   BeanManager beanManager)
Discover if the Annotated has been annotated with a @ Stereotype that provides the specified annotation type and return it.

Parameters:
element - The element to inspect.
annotationType - The annotation type to expect
beanManager - The CDI BeanManager instance
Returns:
The annotation instance found on this element or null if no matching annotation was found.

getMetaAnnotation

public static <A extends Annotation> A getMetaAnnotation(Annotated element,
                                                         Class<A> annotationType)
Inspects an annotated element for the given meta annotation. This should only be used for user defined meta annotations, where the annotation must be physically present.

Parameters:
element - The element to inspect
annotationType - The meta annotation to search for
Returns:
The annotation instance found on this element or null if no matching annotation was found.

getAnnotations

public static Set<Annotation> getAnnotations(Annotated element,
                                             Class<? extends Annotation> metaAnnotationType)
Inspects an annotated element for any annotations with the given meta annotation. This should only be used for user defined meta annotations, where the annotation must be physically present.

Parameters:
element - The element to inspect
annotationType - The meta annotation to search for
Returns:
The annotation instances found on this element or an empty set if no matching meta-annotation was found.


Copyright © 2011 Seam Framework. All Rights Reserved.