net.sf.daileon.supported
Class DomainAnnotationsHelper<T>

java.lang.Object
  extended by net.sf.daileon.supported.DomainAnnotationsHelper<T>

public class DomainAnnotationsHelper<T>
extends Object

The AnnotationsHelper class provides static methods for dealing with domain annotations. Essentially, it provides methods that inform if domain annotations are annotated with known annotations of a particular framework, as well as retrieving all annotations that annotate a particular element.

Version:
1.0 02/12/2009
Author:
Roberto Perillo, Eduardo Guerra

Field Summary
private static Annotation[] EMPTY_ANNOTATIONS_ARRAY
          An empty array of Annotation, used by the getKnownAnnotation method
 
Constructor Summary
DomainAnnotationsHelper()
           
 
Method Summary
static
<T extends Annotation>
T
getAnnotation(AnnotatedElement element, Class<T> annotationClass)
          Gets a particular annotation that indirectly annotates an AnnotatedElement.
static Annotation[] getKnownAnnotations(AnnotatedElement element)
           Retrieves the known annotations of a given element.
static Annotation[] getKnownAnnotations(Annotation[] annotationsVerified)
           Retrieves the known annotations of an array of domain annotations.
static boolean isAnnotationPresent(AnnotatedElement element, Class<? extends Annotation> annotationClass)
          Informs whether an AnnotatedElement is annotated with a particular Annotation.
private static boolean isTemplateAnnotation(Class<? extends Annotation> annotationClass)
          Informs whether a particular Annotation is a template annotation, which can be ClassTemplate, FieldTemplate or MethodTemplate.
private static boolean isValidAnnotation(Class<? extends Annotation> annotationClass)
          Informs whether a particular Annotation is valid or not, which can be Documented, Retention, Target or DomainAnnotation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_ANNOTATIONS_ARRAY

private static final Annotation[] EMPTY_ANNOTATIONS_ARRAY
An empty array of Annotation, used by the getKnownAnnotation method

Constructor Detail

DomainAnnotationsHelper

public DomainAnnotationsHelper()
Method Detail

isAnnotationPresent

public static boolean isAnnotationPresent(AnnotatedElement element,
                                          Class<? extends Annotation> annotationClass)
Informs whether an AnnotatedElement is annotated with a particular Annotation. This Annotation is searched recursively in the given AnnotatedElement, which can be a Field, a Method or even a Class. Therefore, it is possible to verify if a class element, or even if a class, is annotated with a known annotation.

Parameters:
element - The AnnotatedElement (that is, the class element) to be verified.
annotationClass - The Annotation to be verified.
Returns:
A boolean value that can be:
  • true if the given AnnotatedElement is annotated with a particular Annotation;
  • false if the given AnnotatedElement is not annotated with a particular Annotation.

getKnownAnnotations

public static Annotation[] getKnownAnnotations(AnnotatedElement element)

Retrieves the known annotations of a given element. The known annotations are the annotations that annotate an AnnotatedElement that is also annotated with the DomainAnnotation annotation. For instance:

 @Retention(RetentionPolicy.RUNTIME)
 @Target(ElementType.METHOD)
 @FrameworkAnnotation1
 @FrameworkAnnotation2
 @DomainAnnotation
 public @interface ANewlyCreatedDomainAnnotation {}
 
 @ANewlyCreatedDomainAnnotation
 public void domainMethod() {
     // A business method
 }
 

In the example addressed above, @FrameworkAnnotation1 and @FrameworkAnnotation2 are the annotations of the framework or component that supports the creation of domain annotations; in other words, they are the known annotations, which will be returned.

Parameters:
element - An AnnotatedElement to be verified.
Returns:
All known annotations (which are the annotations that annotate a domain annotation). Returns null if the AnnotatedElement is not annotated with @DomainAnnotation.

getKnownAnnotations

public static Annotation[] getKnownAnnotations(Annotation[] annotationsVerified)

Retrieves the known annotations of an array of domain annotations. The known annotations are the annotations that annotate each Annotation that is annotated with the DomainAnnotation annotation.

Parameters:
annotationsVerified - An array of domain annotations.
Returns:
All known annotations (which are the annotations that annotate a domain annotation). Returns null if no annotations are found the AnnotatedElement is not annotated with @DomainAnnotation.

getAnnotation

public static <T extends Annotation> T getAnnotation(AnnotatedElement element,
                                                     Class<T> annotationClass)
Gets a particular annotation that indirectly annotates an AnnotatedElement. For instance if @FrameworkAnnotation annotates a domain annotation, and this domain annotation annotates a particular element, then this method is capable of retrieving @FrameworkAnnotation from the element annotated with the domain annotation. If the searched annotation does not indirectly annotates the element, then null is returned.

Parameters:
element - The AnnotatedElement, annotated with a domain annotation.
annotationClass - The Class of the annotation being searched.
Returns:
The Annotation that indirectly annotates the given element, or null if the annotation is not found in the element.

isValidAnnotation

private static boolean isValidAnnotation(Class<? extends Annotation> annotationClass)
Informs whether a particular Annotation is valid or not, which can be Documented, Retention, Target or DomainAnnotation.

Parameters:
annotationClass - The Class that represents the annotation to be verified.
Returns:
A boolean value that can be:
  • true if the given Annotation is valid;
  • false if the given Annotation is not valid.

isTemplateAnnotation

private static boolean isTemplateAnnotation(Class<? extends Annotation> annotationClass)
Informs whether a particular Annotation is a template annotation, which can be ClassTemplate, FieldTemplate or MethodTemplate.

Parameters:
annotationClass - The Class that represents the annotation to be verified.
Returns:
A boolean value that can be:
  • true if the given Annotation is a template annotation;
  • false if the given Annotation is not a template annotation.