Class IntrospectUtil


  • public class IntrospectUtil
    extends Object
    Provides miscelaneous routines to query classes/objects properties using reflection mechanisms. Additionally, this class exposes some static members that contain useful information about SCIM resources that is collected upon class loading.
    • Field Detail

      • defaultCoreAttrs

        public static Map<Class<? extends BaseScimResource>,​Map<String,​List<Method>>> defaultCoreAttrs
        An unmodifiable map that provides access to the sequence of getter methods that allow to get the actual value(s) for every possible attribute (or sub-atribute) of a SCIM resource when its returnability is "default"
      • requestCoreAttrs

        public static Map<Class<? extends BaseScimResource>,​Map<String,​List<Method>>> requestCoreAttrs
        An unmodifiable map that provides access to the sequence of getter methods that allow to get the actual value(s) for every possible attribute (or sub-atribute) of a SCIM resource when its returnability is "request"
      • alwaysCoreAttrs

        public static Map<Class<? extends BaseScimResource>,​Map<String,​List<Method>>> alwaysCoreAttrs
        An unmodifiable map that provides access to the sequence of getter methods that allow to get the actual value(s) for every possible attribute (or sub-atribute) of a SCIM resource when its returnability is "always"
      • neverCoreAttrs

        public static Map<Class<? extends BaseScimResource>,​Map<String,​List<Method>>> neverCoreAttrs
        An unmodifiable map that provides access to the sequence of getter methods that allow to get the actual value(s) for every possible attribute (or sub-atribute) of a SCIM resource when its returnability is "never"
      • requiredCoreAttrs

        public static Map<Class<? extends BaseScimResource>,​Map<String,​List<Method>>> requiredCoreAttrs
        An unmodifiable map that provides access to the sequence of getter methods that allow to get the actual value(s) for every possible attribute (or sub-atribute) of a SCIM resource when the attribute is annotated as "required" in the resource
      • validableCoreAttrs

        public static Map<Class<? extends BaseScimResource>,​Map<String,​List<Method>>> validableCoreAttrs
        An unmodifiable map that provides access to the sequence of getter methods that allow to get the actual value(s) for every possible attribute (or sub-atribute) of a SCIM resource when the attribute is annotated with some validation
      • canonicalCoreAttrs

        public static Map<Class<? extends BaseScimResource>,​Map<String,​List<Method>>> canonicalCoreAttrs
        An unmodifiable map that provides access to the sequence of getter methods that allow to get the actual value(s) for every possible attribute (or sub-atribute) of a SCIM resource when the attribute has canonical values associated
      • allAttrs

        public static Map<Class<? extends BaseScimResource>,​SortedSet<String>> allAttrs
        An unmodifiable map that stores for every possible subclass of BaseScimResource a SortedSet with the paths that lead to every single attribute/subattribute part of that resource.

        As an example, a set for the UserResource includes elements such as schemas, id, name, name.givenName, emails, emails.value, emails.type, ...

      • storeRefs

        public static Map<Class<? extends BaseScimResource>,​Map<String,​String>> storeRefs
        An unmodifiable map that stores for every possible subclass of BaseScimResource a Map that stores paths (as stored in allAttrs) vs. LDAP attribute names corresponding to such paths.

        As an example, for UserResource this map will contain pairs like (userName, uid); (displayName, displayName); (meta.created, jsCreationTimestamp); (addresses, excludeAddres); (addresses.value, excludeAddres)...

    • Method Detail

      • findFieldFromPath

        public static Field findFieldFromPath​(Class<?> initcls,
                                              String path)
        Inspects a class to search for a field that corresponds to the path passed using dot notation. Every piece of the path (separated by the a dot '.') is expected to have a field with the same name in the class inspected. When such a field is found, the remainder of the path is processed using the class associated to the field, until the path is fully consumed.

        This method starts from an initial class and visits ascendingly the class hierarchy with a route determined by the components found in the path parameter.

        Parameters:
        initcls - Class to start the search from
        path - A string denoting a path to a target attribute. Examples of valid paths can be: displayName, name.givenName, addresses.locality
        Returns:
        A Field that represents the terminal portion of the path, for instance "locality" field for "addresses.locality". If no such field is found (because at some point, there was no route to go), null is returned.
      • strObjMap

        public static Map<String,​Object> strObjMap​(Object obj)
        Takes an opaque object and casts it to a Map<String, Object>. Call this only if you are sure the object being passed is actually an instance of Map<String, Object>.
        Parameters:
        obj - Object to be cast
        Returns:
        A map instance
      • getFieldAnnotation

        public static <T extends Annotation> T getFieldAnnotation​(String path,
                                                                  Class resourceClass,
                                                                  Class<T> annotationClass)
        Searches for a Field that corresponds to the path passed (using findFieldFromPath) and tries to find an annotation attached to such field that matches the annotationClass parameter.
        Type Parameters:
        T - Type parameter for annotationClass
        Parameters:
        path - A string denoting a path to a target attribute. Examples of valid paths can be: displayName, name.givenName, addresses.locality when UserResource class is used for resourceClass.
        resourceClass - Class to start the search from
        annotationClass - Class annotation to be inspected for the field
        Returns:
        An object of type T, or null if no annotation was found or the field itself couldn't be found
      • getAttributeValues

        public static List<Object> getAttributeValues​(BaseScimResource bean,
                                                      List<Method> getters)
        Traverses the contents of a SCIM resource and applies a set of getter methods to collect a list of values. For example, if passing a UserResource object and list of getters such as [getAdresses(), getStreetAddress()], it will return a list with all "street addresses" that can be found inside user object.
        Parameters:
        bean - A SCIM resource object
        getters - A list of getters methods
        Returns:
        List of values. They are collected by scanning the getter list from beginning to end. If no values could be collected at all, an empty list is returned
      • getSetter

        public static Method getSetter​(String fieldName,
                                       Class clazz)
                                throws Exception
        Inspects a class that represents a Java Bean and tries to find the setter Method associated to the class field whose name is passed as parameter.
        Parameters:
        fieldName - The name of the field whose setter needs to be found
        clazz - The Class to introspect
        Returns:
        A Method object, null if the lookup is not successful
        Throws:
        Exception - Upon introspection error
      • getGetter

        public static Method getGetter​(String fieldName,
                                       Class clazz)
                                throws Exception
        Inspects a class that represents a Java Bean and tries to find the getter Method associated to the class field whose name is passed as parameter.
        Parameters:
        fieldName - The name of the field whose getter needs to be found
        clazz - The Class to introspect
        Returns:
        A Method object, null if the lookup is not successful
        Throws:
        Exception - Upon introspection error
      • isCollection

        public static boolean isCollection​(Class clazz)
        Determines if the class passed implements the Collection interface.
        Parameters:
        clazz - Class to analyze
        Returns:
        true if the class is a Collection, false otherwise.
      • getPathsInExtension

        public static List<String> getPathsInExtension​(Extension extension)
        Returns a list with the names of the attributes that belong to an extension, so that every name is prefixed with the urn of the extension, like this: urn:attribute_name
        Parameters:
        extension - An Extension object
        Returns:
        A list of prefixed names