Package io.jans.scim.model.scim2.util
Class IntrospectUtil
- java.lang.Object
-
- io.jans.scim.model.scim2.util.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 Summary
Fields Modifier and Type Field Description static Map<Class<? extends BaseScimResource>,SortedSet<String>>
allAttrs
An unmodifiable map that stores for every possible subclass ofBaseScimResource
aSortedSet
with the paths that lead to every single attribute/subattribute part of that resource.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"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 hascanonical values
associatedstatic 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"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"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"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 resourcestatic Map<Class<? extends BaseScimResource>,Map<String,String>>
storeRefs
An unmodifiable map that stores for every possible subclass ofBaseScimResource
aMap
that stores paths (as stored inallAttrs
) vs.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 somevalidation
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Field
findFieldFromPath(Class<?> initcls, String path)
Inspects a class to search for a field that corresponds to the path passed using dot notation.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.static <T extends Annotation>
TgetFieldAnnotation(String path, Class resourceClass, Class<T> annotationClass)
Searches for aField
that corresponds to the path passed (usingfindFieldFromPath
) and tries to find an annotation attached to such field that matches theannotationClass
parameter.static Method
getGetter(String fieldName, Class clazz)
Inspects a class that represents a Java Bean and tries to find the getterMethod
associated to the class field whose name is passed as parameter.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 theurn
of the extension, like this:urn:attribute_name
static Method
getSetter(String fieldName, Class clazz)
Inspects a class that represents a Java Bean and tries to find the setterMethod
associated to the class field whose name is passed as parameter.static boolean
isCollection(Class clazz)
Determines if the class passed implements theCollection
interface.static Map<String,Object>
strObjMap(Object obj)
Takes an opaque object and casts it to a Map<String, Object>.
-
-
-
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 somevalidation
-
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 hascanonical values
associated
-
allAttrs
public static Map<Class<? extends BaseScimResource>,SortedSet<String>> allAttrs
An unmodifiable map that stores for every possible subclass ofBaseScimResource
aSortedSet
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 asschemas, 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 ofBaseScimResource
aMap
that stores paths (as stored inallAttrs
) 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 frompath
- 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 aField
that corresponds to the path passed (usingfindFieldFromPath
) and tries to find an annotation attached to such field that matches theannotationClass
parameter.- Type Parameters:
T
- Type parameter forannotationClass
- Parameters:
path
- A string denoting a path to a target attribute. Examples of valid paths can be: displayName, name.givenName, addresses.locality whenUserResource
class is used forresourceClass
.resourceClass
- Class to start the search fromannotationClass
- 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 aUserResource
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 objectgetters
- 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 setterMethod
associated to the class field whose name is passed as parameter.- Parameters:
fieldName
- The name of the field whose setter needs to be foundclazz
- 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 getterMethod
associated to the class field whose name is passed as parameter.- Parameters:
fieldName
- The name of the field whose getter needs to be foundclazz
- 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 theCollection
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 theurn
of the extension, like this:urn:attribute_name
- Parameters:
extension
- AnExtension
object- Returns:
- A list of prefixed names
-
-