Class AnnotationUtils

  • Direct Known Subclasses:
    JaxRsAnnotationUtils

    public class AnnotationUtils
    extends java.lang.Object
    Utilities to manipulate Restlet annotations.
    • Field Detail

      • cache

        private static final java.util.concurrent.ConcurrentMap<java.lang.Class<?>,​java.util.List<AnnotationInfo>> cache
        Annotation info cache.
    • Constructor Detail

      • AnnotationUtils

        protected AnnotationUtils()
        Protected constructor.
    • 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 of Method according to the given annotations.
        Parameters:
        annotation - Java annotation.
        methodAnnotation - Annotation that corresponds to a Restlet method.
        Returns:
        An instance of Method according 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 the Throwable class matching the given error code if present or null.
        Parameters:
        javaMethod - The method that holds Throwable.
        errorCode - The error code to match.
        Returns:
        The Throwable class matching the given error code if present or null.
      • getThrowableClass

        public java.lang.Class<?> getThrowableClass​(java.lang.reflect.Method javaMethod,
                                                    int errorCode)
        Returns the Throwable class matching the given error code if present or null.
        Parameters:
        javaMethod - The method that holds Throwable.
        errorCode - The error code to match.
        Returns:
        The Throwable class matching the given error code if present or null.