public abstract class AnnotationUtils
extends java.lang.Object
Title: AnnotationUtils.java
Description: General utility methods for working with annotations, handling bridge methods (which the compiler generates for generic declarations) as well as super methods (for optional "annotation inheritance"). Note that none of this is provided by the JDK's introspection facilities themselves.
As a general rule for runtime-retained annotations (e.g. for transaction
control, authorization or service exposure), always use the lookup methods on
this class (e.g., findAnnotation(Method, Class),
getAnnotation(Method, Class), and getAnnotations(Method))
instead of the plain annotation lookup methods in the JDK. You can still
explicitly choose between lookup on the given class level only
(getAnnotation(Method, Class)) and lookup in the entire inheritance
hierarchy of the given method (findAnnotation(Method, Class)).
bboss workgroup
Copyright (c) 2008
| 构造器和说明 |
|---|
AnnotationUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static java.lang.String |
converDefaultValue(java.lang.String defaultValue) |
static <A extends java.lang.annotation.Annotation> |
findAnnotation(java.lang.Class<?> clazz,
java.lang.Class<A> annotationType)
Find a single
Annotation of annotationType from the
supplied Class, traversing its interfaces and super classes
if no annotation can be found on the given class itself. |
static <A extends java.lang.annotation.Annotation> |
findAnnotation(java.lang.reflect.Method method,
java.lang.Class<A> annotationType)
Get a single
Annotation of annotationType from the
supplied Method, traversing its super methods if no annotation
can be found on the given method itself. |
static java.lang.Class<?> |
findAnnotationDeclaringClass(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType,
java.lang.Class<?> clazz)
Find the first
Class in the inheritance hierarchy of the
specified clazz (including the specified
clazz itself) which declares an annotation for the
specified annotationType, or null if not
found. |
static <A extends java.lang.annotation.Annotation> |
getAnnotation(java.lang.reflect.Method method,
java.lang.Class<A> annotationType)
Get a single
Annotation of annotationType from the
supplied Method. |
static java.util.Map<java.lang.String,java.lang.Object> |
getAnnotationAttributes(java.lang.annotation.Annotation annotation)
Retrieve the given annotation's attributes as a Map.
|
static java.lang.annotation.Annotation[] |
getAnnotations(java.lang.reflect.Method method)
Get all
Annotations from the supplied Method. |
static java.lang.Object |
getDefaultValue(java.lang.annotation.Annotation annotation)
Retrieve the default value of the
"value" attribute of a single-element
Annotation, given an annotation instance. |
static java.lang.Object |
getDefaultValue(java.lang.annotation.Annotation annotation,
java.lang.String attributeName)
Retrieve the default value of a named Annotation attribute,
given an annotation instance.
|
static java.lang.Object |
getDefaultValue(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Retrieve the default value of the
"value" attribute of a single-element
Annotation, given the annotation type. |
static java.lang.Object |
getDefaultValue(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType,
java.lang.String attributeName)
Retrieve the default value of a named Annotation attribute,
given the
annotation type. |
static java.lang.Object |
getValue(java.lang.annotation.Annotation annotation)
Retrieve the value of the
"value"
attribute of a single-element Annotation, given an annotation instance. |
static java.lang.Object |
getValue(java.lang.annotation.Annotation annotation,
java.lang.String attributeName)
Retrieve the value of a named Annotation attribute, given an
annotation instance.
|
static boolean |
isAnnotationDeclaredLocally(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType,
java.lang.Class<?> clazz)
Determine whether an annotation for the specified
annotationType
is declared locally on the supplied clazz. |
static boolean |
isAnnotationInherited(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType,
java.lang.Class<?> clazz)
Determine whether an annotation for the specified
annotationType
is present on the supplied clazz and is
inherited
(i.e., not declared locally for the class). |
static java.util.List<java.lang.String> |
parserPathdata(java.lang.String path) |
static java.util.Map |
resolvePathDatas(MethodInfo method,
java.lang.String lookupPath)
获取restful路径中的变量的值
|
public static java.lang.annotation.Annotation[] getAnnotations(java.lang.reflect.Method method)
Annotations from the supplied Method.
Correctly handles bridge Methods generated by the compiler.
method - the method to look for annotations onpublic static <A extends java.lang.annotation.Annotation> A getAnnotation(java.lang.reflect.Method method,
java.lang.Class<A> annotationType)
Annotation of annotationType from the
supplied Method.
Correctly handles bridge Methods generated by the compiler.
method - the method to look for annotations onannotationType - the annotation class to look forpublic static <A extends java.lang.annotation.Annotation> A findAnnotation(java.lang.reflect.Method method,
java.lang.Class<A> annotationType)
Annotation of annotationType from the
supplied Method, traversing its super methods if no annotation
can be found on the given method itself.
Annotations on methods are not inherited by default, so we need to handle this explicitly. Tge
method - the method to look for annotations onannotationType - the annotation class to look fornull if none foundpublic static <A extends java.lang.annotation.Annotation> A findAnnotation(java.lang.Class<?> clazz,
java.lang.Class<A> annotationType)
Annotation of annotationType from the
supplied Class, traversing its interfaces and super classes
if no annotation can be found on the given class itself.
This method explicitly handles class-level annotations which are
not declared as inherited
as well as annotations on interfaces.
The algorithm operates as follows: Searches for an annotation on the given class and returns it if found. Else searches all interfaces that the given class declares, returning the annotation from the first matching candidate, if any. Else proceeds with introspection of the superclass of the given class, checking the superclass itself; if no annotation found there, proceeds with the interfaces that the superclass declares. Recursing up through the entire superclass hierarchy if no match is found.
clazz - the class to look for annotations onannotationType - the annotation class to look fornull if none foundpublic static java.lang.Class<?> findAnnotationDeclaringClass(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType,
java.lang.Class<?> clazz)
Class in the inheritance hierarchy of the
specified clazz (including the specified
clazz itself) which declares an annotation for the
specified annotationType, or null if not
found. If the supplied clazz is null,
null will be returned.
If the supplied clazz is an interface, only the interface
itself will be checked; the inheritance hierarchy for interfaces will not
be traversed.
The standard Class API does not provide a mechanism for
determining which class in an inheritance hierarchy actually declares an
Annotation, so we need to handle this explicitly.
annotationType - the Class object corresponding to the annotation typeclazz - the Class object corresponding to the class on which to
check for the annotation, or null.Class in the inheritance hierarchy of the
specified clazz which declares an annotation for the specified
annotationType, or null if not found.Class.isAnnotationPresent(Class),
Class.getDeclaredAnnotations()public static boolean isAnnotationDeclaredLocally(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType,
java.lang.Class<?> clazz)
annotationType
is declared locally on the supplied clazz.
The supplied Class object may represent any type.
Note: This method does not determine if the annotation
is inherited. For greater clarity
regarding inherited annotations, consider using
isAnnotationInherited(Class, Class) instead.
annotationType - the Class object corresponding to the annotation typeclazz - the Class object corresponding to the class on which to
check for the annotationtrue if an annotation for the specified
annotationType is declared locally on the supplied clazzClass.getDeclaredAnnotations(),
isAnnotationInherited(Class, Class)public static boolean isAnnotationInherited(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType,
java.lang.Class<?> clazz)
annotationType
is present on the supplied clazz and is
inherited
(i.e., not declared locally for the class).
If the supplied clazz is an interface, only the interface
itself will be checked. In accord with standard meta-annotation
semantics, the inheritance hierarchy for interfaces will not be
traversed. See the JavaDoc for the
@Inherited meta-annotation for further details regarding annotation
inheritance.
annotationType - the Class object corresponding to the annotation typeclazz - the Class object corresponding to the class on which to
check for the annotationtrue if an annotation for the specified
annotationType is present on the supplied clazz
and is inheritedClass.isAnnotationPresent(Class),
isAnnotationDeclaredLocally(Class, Class)public static java.util.Map<java.lang.String,java.lang.Object> getAnnotationAttributes(java.lang.annotation.Annotation annotation)
annotation - the annotation to retrieve the attributes forpublic static java.lang.Object getValue(java.lang.annotation.Annotation annotation)
"value"
attribute of a single-element Annotation, given an annotation instance.annotation - the annotation instance from which to retrieve the valuenull if not foundgetValue(Annotation, String)public static java.lang.Object getValue(java.lang.annotation.Annotation annotation,
java.lang.String attributeName)
annotation - the annotation instance from which to retrieve the valueattributeName - the name of the attribute value to retrievenull if not foundgetValue(Annotation)public static java.lang.Object getDefaultValue(java.lang.annotation.Annotation annotation)
"value" attribute of a single-element
Annotation, given an annotation instance.annotation - the annotation instance from which to retrieve
the default valuenull if not foundgetDefaultValue(Annotation, String)public static java.lang.Object getDefaultValue(java.lang.annotation.Annotation annotation,
java.lang.String attributeName)
annotation - the annotation instance from which to retrieve
the default valueattributeName - the name of the attribute value to retrievenull
if not found.getDefaultValue(Class, String)public static java.lang.Object getDefaultValue(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
"value" attribute of a single-element
Annotation, given the annotation type.annotationType - the annotation type for which the
default value should be retrievednull if not foundgetDefaultValue(Class, String)public static java.lang.Object getDefaultValue(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType,
java.lang.String attributeName)
annotation type.annotationType - the annotation type for which the
default value should be retrievedattributeName - the name of the attribute value to retrieve.null
if not foundgetDefaultValue(Annotation, String)public static java.util.List<java.lang.String> parserPathdata(java.lang.String path)
public static java.util.Map resolvePathDatas(MethodInfo method, java.lang.String lookupPath)
method - lookupPath - public static java.lang.String converDefaultValue(java.lang.String defaultValue)