de.dfki.util.xmlrpc.annotation
Class AnnotationUtils

java.lang.Object
  extended by de.dfki.util.xmlrpc.annotation.AnnotationUtils

public class AnnotationUtils
extends java.lang.Object

Convenience methods for getting annotations from classes, objects, methods, ... (they are not always located were we expect them to be)

Author:
lauer

Constructor Summary
AnnotationUtils()
           
 
Method Summary
static
<T extends java.lang.annotation.Annotation>
T
getAnnotation(java.lang.annotation.Annotation[] annos, java.lang.Class<T> annoClass)
          Get annotation of specific type out of an array of annotations.
static
<T extends java.lang.annotation.Annotation>
T
getAnnotationForClass(java.lang.Class<?> sourceClass, java.lang.Class<T> annotationClass)
          Gets annotations for a class.
static
<T extends java.lang.annotation.Annotation>
T
getAnnotationForObject(java.lang.Object source, java.lang.Class<T> annotationClass)
          Gets annotations for an object.
static
<T extends java.lang.annotation.Annotation>
T
getAnnotationFromMethod(java.lang.reflect.Method m, java.lang.Class<T> annoClass)
           
static java.lang.annotation.Annotation[] getAnnotationFromMethodParameter(java.lang.reflect.Method m, int pos)
          Gets a parameter annotation.
static java.lang.annotation.Annotation[] getAnnotationsFrom(java.lang.reflect.Method m)
          Get annotations from a method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AnnotationUtils

public AnnotationUtils()
Method Detail

getAnnotationForObject

public static final <T extends java.lang.annotation.Annotation> T getAnnotationForObject(java.lang.Object source,
                                                                                         java.lang.Class<T> annotationClass)
Gets annotations for an object. Calls getAnnotationForClass(Class, Class).


getAnnotationForClass

public static final <T extends java.lang.annotation.Annotation> T getAnnotationForClass(java.lang.Class<?> sourceClass,
                                                                                        java.lang.Class<T> annotationClass)
Gets annotations for a class. Also looks for annotations of interfaces the class implements (which is not done automatically by the java reflection api).


getAnnotation

public static <T extends java.lang.annotation.Annotation> T getAnnotation(java.lang.annotation.Annotation[] annos,
                                                                          java.lang.Class<T> annoClass)
Get annotation of specific type out of an array of annotations.

Returns:
null, if array is null or annotation is not contained in array, the annotation otherwise.

getAnnotationsFrom

public static java.lang.annotation.Annotation[] getAnnotationsFrom(java.lang.reflect.Method m)
Get annotations from a method. If the given method is located in a class implementing an interface and the implemented method has annotations, then this annotation is returned.


getAnnotationFromMethod

public static <T extends java.lang.annotation.Annotation> T getAnnotationFromMethod(java.lang.reflect.Method m,
                                                                                    java.lang.Class<T> annoClass)

getAnnotationFromMethodParameter

public static java.lang.annotation.Annotation[] getAnnotationFromMethodParameter(java.lang.reflect.Method m,
                                                                                 int pos)
Gets a parameter annotation. If method is declared in an interface implementation, annotations of the interface is not inherited. Thus, the correct interface has to be found.

Returns:
Array of zero or more annotations for parameter a position pos.


Copyright © 2012. All Rights Reserved.