Package org.restlet.engine.resource
Class AnnotationUtils
- java.lang.Object
-
- org.restlet.engine.resource.AnnotationUtils
-
- Direct Known Subclasses:
JaxRsAnnotationUtils
public class AnnotationUtils extends java.lang.ObjectUtilities to manipulate Restlet annotations.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.concurrent.ConcurrentMap<java.lang.Class<?>,java.util.List<AnnotationInfo>>cacheAnnotation info cache.private static AnnotationUtilsinstanceCurrent instance.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAnnotationUtils()Protected constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.util.List<AnnotationInfo>addAnnotations(java.util.List<AnnotationInfo> descriptors, java.lang.Class<?> clazz, java.lang.Class<?> initialClass)Computes the annotation descriptors for the given class or interface.private java.util.List<AnnotationInfo>addMethodAnnotationDescriptors(java.util.List<AnnotationInfo> descriptors, java.lang.Class<?> clazz, java.lang.Class<?> initialClass, java.lang.reflect.Method javaMethod)Computes the annotation descriptors for the given Java method.private java.util.List<AnnotationInfo>addThrowableAnnotationDescriptors(java.util.List<AnnotationInfo> descriptors, java.lang.Class<?> clazz, java.lang.Class<?> initialClass)Computes the annotation descriptors for the given Java method.voidclearCache()Clears the annotation descriptors cache.java.util.List<AnnotationInfo>getAnnotations(java.lang.Class<?> clazz)Returns the annotation descriptors for the given resource class.java.util.List<AnnotationInfo>getAnnotations(java.lang.Class<?> clazz, java.lang.reflect.Method javaMethod)Returns the annotation descriptors for the given resource class.static AnnotationUtilsgetInstance()Returns the current instance of AnnotationUtils.MethodAnnotationInfogetMethodAnnotation(java.util.List<AnnotationInfo> annotations, java.lang.reflect.Method javaMethod)Returns the first annotation descriptor matching the given Java method.MethodAnnotationInfogetMethodAnnotation(java.util.List<AnnotationInfo> annotations, Method restletMethod, Form query, Representation entity, MetadataService metadataService, ConverterService converterService)Returns the first annotation descriptor matching the given Restlet method.protected MethodgetRestletMethod(java.lang.annotation.Annotation annotation, java.lang.annotation.Annotation methodAnnotation)Returns an instance ofMethodaccording to the given annotations.ThrowableAnnotationInfogetThrowableAnnotationInfo(java.lang.Class<?> clazz)Returns the status annotation descriptor if present or null.ThrowableAnnotationInfogetThrowableAnnotationInfo(java.lang.reflect.Method javaMethod, int errorCode)Returns theThrowableclass matching the given error code if present or null.java.lang.Class<?>getThrowableClass(java.lang.reflect.Method javaMethod, int errorCode)Returns theThrowableclass matching the given error code if present or null.
-
-
-
Field Detail
-
cache
private static final java.util.concurrent.ConcurrentMap<java.lang.Class<?>,java.util.List<AnnotationInfo>> cache
Annotation info cache.
-
instance
private static AnnotationUtils instance
Current instance.
-
-
Method Detail
-
getInstance
public static AnnotationUtils getInstance()
Returns the current instance of AnnotationUtils.
-
addAnnotations
private java.util.List<AnnotationInfo> addAnnotations(java.util.List<AnnotationInfo> descriptors, java.lang.Class<?> clazz, java.lang.Class<?> initialClass)
Computes the annotation descriptors for the given class or interface.- Parameters:
descriptors- The annotation descriptors to update or null to create a new one.clazz- The class or interface to introspect.initialClass- The class or interface that runs the javaMethod.- Returns:
- The annotation descriptors.
-
addMethodAnnotationDescriptors
private java.util.List<AnnotationInfo> addMethodAnnotationDescriptors(java.util.List<AnnotationInfo> descriptors, java.lang.Class<?> clazz, java.lang.Class<?> initialClass, java.lang.reflect.Method javaMethod)
Computes the annotation descriptors for the given Java method.- Parameters:
descriptors- The annotation descriptors to update or null to create a new one.clazz- The class or interface that hosts the javaMethod.initialClass- The class or interface that runs the javaMethod.javaMethod- The Java method to inspect.- Returns:
- The annotation descriptors.
-
addThrowableAnnotationDescriptors
private java.util.List<AnnotationInfo> addThrowableAnnotationDescriptors(java.util.List<AnnotationInfo> descriptors, java.lang.Class<?> clazz, java.lang.Class<?> initialClass)
Computes the annotation descriptors for the given Java method.- Parameters:
descriptors- The annotation descriptors to update or null to create a new one.clazz- The class or interface that hosts the javaMethod.initialClass- The class or interface that runs the javaMethod.- Returns:
- The annotation descriptors.
-
clearCache
public void clearCache()
Clears the annotation descriptors cache.
-
getAnnotations
public java.util.List<AnnotationInfo> getAnnotations(java.lang.Class<?> clazz)
Returns the annotation descriptors for the given resource class.- Parameters:
clazz- The resource class to introspect.- Returns:
- The list of annotation descriptors.
-
getAnnotations
public java.util.List<AnnotationInfo> getAnnotations(java.lang.Class<?> clazz, java.lang.reflect.Method javaMethod)
Returns the annotation descriptors for the given resource class.- Parameters:
javaMethod- The Java method.- Returns:
- The list of annotation descriptors.
-
getMethodAnnotation
public MethodAnnotationInfo getMethodAnnotation(java.util.List<AnnotationInfo> annotations, java.lang.reflect.Method javaMethod)
Returns the first annotation descriptor matching the given Java method.- Parameters:
annotations- The list of annotations.javaMethod- The method to match.- Returns:
- The annotation descriptor.
-
getMethodAnnotation
public MethodAnnotationInfo getMethodAnnotation(java.util.List<AnnotationInfo> annotations, Method restletMethod, Form query, Representation entity, MetadataService metadataService, ConverterService converterService) throws java.io.IOException
Returns the first annotation descriptor matching the given Restlet method.- Parameters:
annotations- The list of annotations.restletMethod- The method to match.query- The query parameters.entity- The request entity to match or null if no entity is provided.metadataService- The metadata service to use.converterService- The converter service to use.- Returns:
- The annotation descriptor.
- Throws:
java.io.IOException
-
getRestletMethod
protected Method getRestletMethod(java.lang.annotation.Annotation annotation, java.lang.annotation.Annotation methodAnnotation)
Returns an instance ofMethodaccording to the given annotations.- Parameters:
annotation- Java annotation.methodAnnotation- Annotation that corresponds to a Restlet method.- Returns:
- An instance of
Methodaccording to the given annotations.
-
getThrowableAnnotationInfo
public ThrowableAnnotationInfo getThrowableAnnotationInfo(java.lang.Class<?> clazz)
Returns the status annotation descriptor if present or null.- Parameters:
clazz- The class with the status attached.- Returns:
- The status annotation descriptor if present or null.
-
getThrowableAnnotationInfo
public ThrowableAnnotationInfo getThrowableAnnotationInfo(java.lang.reflect.Method javaMethod, int errorCode)
Returns theThrowableclass matching the given error code if present or null.- Parameters:
javaMethod- The method that holdsThrowable.errorCode- The error code to match.- Returns:
- The
Throwableclass matching the given error code if present or null.
-
getThrowableClass
public java.lang.Class<?> getThrowableClass(java.lang.reflect.Method javaMethod, int errorCode)Returns theThrowableclass matching the given error code if present or null.- Parameters:
javaMethod- The method that holdsThrowable.errorCode- The error code to match.- Returns:
- The
Throwableclass matching the given error code if present or null.
-
-