Class ModelHelper


  • public final class ModelHelper
    extends Object
    Common model helper methods.
    • Method Detail

      • getAnnotatedResourceClass

        public static Class<?> getAnnotatedResourceClass​(Class<?> resourceClass,
                                                         Class<? extends Annotation> annotation)
        Get the class in the provided resource class ancestor hierarchy that is actually annotated with the specified annotation.

        If the annotation is not present in the class hierarchy the resource class is returned.

        Parameters:
        resourceClass - resource class
        annotation - the annotation to look for
        Returns:
        resource class or it's ancestor that is annotated with the specified annotation.
      • getDeclaredMethodsPA

        public static PrivilegedAction<Collection<? extends Method>> getDeclaredMethodsPA​(Class<?> clazz)
        Get privileged action to obtain methods declared on given class. If run using security manager, the returned privileged action must be invoked within a doPrivileged block.
        Parameters:
        clazz - class for which to get the declared methods.
        Returns:
        privileged action to obtain methods declared on the clazz class.
        See Also:
        AccessController.doPrivileged(java.security.PrivilegedAction)
      • findMethodOnClassPA

        public static PrivilegedAction<Method> findMethodOnClassPA​(Class<?> cls,
                                                                   Method m)
        Get privileged action to find a method on a class given an existing method. If run using security manager, the returned privileged action must be invoked within a doPrivileged block.

        If there exists a public method on the class that has the same name and parameters as the existing method then that public method is returned from the action.

        Otherwise, if there exists a public method on the class that has the same name and the same number of parameters as the existing method, and each generic parameter type, in order, of the public method is equal to the generic parameter type, in the same order, of the existing method or is an instance of TypeVariable then that public method is returned from the action.

        Parameters:
        cls - the class to search for a public method
        m - the method to find
        Returns:
        privileged action to return public method found.
        See Also:
        AccessController.doPrivileged(java.security.PrivilegedAction)
      • getArrayComponentType

        public static Type getArrayComponentType​(Type type)
        Gets the component type of the array.
        Parameters:
        type - must be an array.
        Returns:
        array component type.
        Throws:
        IllegalArgumentException - in case the type is not an array type.
      • getArrayForComponentType

        public static Class<?> getArrayForComponentType​(Class<?> c)
        Get Array class of component type.
        Parameters:
        c - the component class of the array
        Returns:
        the array class.
      • getGenericType

        public static Class<?> getGenericType​(Type type)
        Obtain the generic type for a Type.
        Parameters:
        type - the type to obtain the generic type of
        Returns:
        the generic type