Package io.jans.scim.model.scim2.util
Class IntrospectUtil
java.lang.Object
io.jans.scim.model.scim2.util.IntrospectUtil
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
FieldsModifier and TypeFieldDescriptionstatic Map<Class<? extends BaseScimResource>,SortedSet<String>> An unmodifiable map that stores for every possible subclass ofBaseScimResourceaSortedSetwith the paths that lead to every single attribute/subattribute part of that resource.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"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 valuesassociatedAn 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"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"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"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 List<Class<? extends BaseScimResource>>An unmodifiable map that stores for every possible subclass ofBaseScimResourceaMapthat stores paths (as stored inallAttrs) vs.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
Modifier and TypeMethodDescriptionstatic FieldfindFieldFromPath(Class<?> initcls, String path) Inspects a class to search for a field that corresponds to the path passed using dot notation.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 aFieldthat corresponds to the path passed (usingfindFieldFromPath) and tries to find an annotation attached to such field that matches theannotationClassparameter.static MethodInspects a class that represents a Java Bean and tries to find the getterMethodassociated to the class field whose name is passed as parameter.getPathsInExtension(Extension extension) Returns a list with the names of the attributes that belong to an extension, so that every name is prefixed with theurnof the extension, like this:urn:attribute_namestatic MethodInspects a class that represents a Java Bean and tries to find the setterMethodassociated to the class field whose name is passed as parameter.static booleanisCollection(Class clazz) Determines if the class passed implements theCollectioninterface.Takes an opaque object and casts it to a Map<String, Object>.
-
Field Details
-
resourceClasses
-
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
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
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
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
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
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
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 valuesassociated -
allAttrs
An unmodifiable map that stores for every possible subclass ofBaseScimResourceaSortedSetwith the paths that lead to every single attribute/subattribute part of that resource.As an example, a set for the
UserResourceincludes elements such asschemas, id, name, name.givenName, emails, emails.value, emails.type, ... -
storeRefs
An unmodifiable map that stores for every possible subclass ofBaseScimResourceaMapthat stores paths (as stored inallAttrs) vs. LDAP attribute names corresponding to such paths.As an example, for
UserResourcethis map will contain pairs like(userName, uid); (displayName, displayName); (meta.created, jsCreationTimestamp); (addresses, excludeAddres); (addresses.value, excludeAddres)...
-
-
Method Details
-
findFieldFromPath
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
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 aFieldthat corresponds to the path passed (usingfindFieldFromPath) and tries to find an annotation attached to such field that matches theannotationClassparameter.- 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 whenUserResourceclass 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
Traverses the contents of a SCIM resource and applies a set of getter methods to collect a list of values. For example, if passing aUserResourceobject 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
Inspects a class that represents a Java Bean and tries to find the setterMethodassociated 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
Inspects a class that represents a Java Bean and tries to find the getterMethodassociated 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
Determines if the class passed implements theCollectioninterface.- Parameters:
clazz- Class to analyze- Returns:
- true if the class is a Collection, false otherwise.
-
getPathsInExtension
Returns a list with the names of the attributes that belong to an extension, so that every name is prefixed with theurnof the extension, like this:urn:attribute_name- Parameters:
extension- AnExtensionobject- Returns:
- A list of prefixed names
-