Package com.atlan.cache
Class ReflectionCache
java.lang.Object
com.atlan.cache.ReflectionCache
Lazily-loaded cache for Java reflection-based operations across the Atlan data model.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Class<?>
getClassOfParameterizedType
(Type parameterizedType) Retrieve the class (type) within the parameterized type provided.static String
getDeserializedName
(Class<?> b, String fieldName) Retrieve the name that should be used for this field for deserialization purposes.getFieldNames
(Class<?> b) Retrieve all the field names for the provided asset type's class.static Class<?>
getFieldType
(Class<?> b, String fieldName) Retrieve the type of the specified field.static Method
Retrieve the getter method for the specified field.static Type
getParameterizedTypeOfMethod
(Method method) Retrieve the parameterized class (type) of the first parameter of the provided method.static Class<?>
getParameterOfMethod
(Method method) Retrieve the class (type) of the first parameter of the provided method.static String
getSerializedName
(Class<?> b, String fieldName) Retrieve the name that should be used for this field for serialization purposes.static Method
Retrieve the setter method for the specified field.static Object
Retrieve the value for a specified field from the provided asset.static boolean
isAttribute
(Class<?> b, String fieldName) Check whether the provided field name is annotated as an attribute (true) or not (false).static boolean
Check whether the provided field name is annotated as a date (true) or not (false).static boolean
setValue
(Asset.AssetBuilder<?, ?> builder, String fieldName, Object value) Set the value of a field on a specific asset (via its mutable builder).static void
setValue
(RelationshipAttributes.RelationshipAttributesBuilder<?, ?> builder, String fieldName, Object value) Set the value of a field on a specific asset (via its mutable builder).
-
Constructor Details
-
ReflectionCache
public ReflectionCache()
-
-
Method Details
-
getFieldNames
Retrieve all the field names for the provided asset type's class.- Parameters:
b
- class of the asset type- Returns:
- collection of all field names for that asset type
-
getFieldType
Retrieve the type of the specified field.- Parameters:
b
- class of the asset typefieldName
- name of the field- Returns:
- the type of that field
-
isAttribute
Check whether the provided field name is annotated as an attribute (true) or not (false).- Parameters:
b
- class of the asset typefieldName
- name of the field- Returns:
- true if the field should be attributes-nested, false otherwise
-
isDate
Check whether the provided field name is annotated as a date (true) or not (false).- Parameters:
b
- class of the asset typefieldName
- name of the field- Returns:
- true if the field should be treated as a date, false otherwise
-
getGetter
Retrieve the getter method for the specified field.- Parameters:
b
- class of the asset typefieldName
- name of the field- Returns:
- getter method that can be invoked to retrieve the value of the field
-
getValue
Retrieve the value for a specified field from the provided asset.- Parameters:
a
- asset from which to retrieve the valuefieldName
- field on that asset from which to retrieve the value- Returns:
- value of the field on that asset
- Throws:
IOException
- if there is any error retrieving the value dynamically
-
getSetter
Retrieve the setter method for the specified field.- Parameters:
b
- class of the asset typefieldName
- name of the field- Returns:
- setter method that can be invoked to store the value of the field
-
setValue
public static boolean setValue(Asset.AssetBuilder<?, ?> builder, String fieldName, Object value) throws NoSuchMethodException, IllegalAccessException, InvocationTargetExceptionSet the value of a field on a specific asset (via its mutable builder).- Parameters:
builder
- for the asset through which to set the propertyfieldName
- name of the property to setvalue
- value to set on the property- Returns:
- true if the property was set, otherwise false (for example if no such property appears to exist)
- Throws:
NoSuchMethodException
- if there is no setter on the builder to set this fieldIllegalAccessException
- if the setter cannot be accessed to set this fieldInvocationTargetException
- if the provided builder cannot be used
-
setValue
public static void setValue(RelationshipAttributes.RelationshipAttributesBuilder<?, ?> builder, String fieldName, Object value) throws NoSuchMethodException, IllegalAccessException, InvocationTargetExceptionSet the value of a field on a specific asset (via its mutable builder).- Parameters:
builder
- for the asset through which to set the propertyfieldName
- name of the property to setvalue
- value to set on the property- Throws:
NoSuchMethodException
- if there is no setter on the builder to set this fieldIllegalAccessException
- if the setter cannot be accessed to set this fieldInvocationTargetException
- if the provided builder cannot be used
-
getSerializedName
Retrieve the name that should be used for this field for serialization purposes.- Parameters:
b
- class of the asset typefieldName
- name of the field- Returns:
- the name of the field to use when serializing into JSON
-
getDeserializedName
Retrieve the name that should be used for this field for deserialization purposes.- Parameters:
b
- class of the asset typefieldName
- name of the field- Returns:
- the name of the field to use when deserializing into an object
-
getParameterOfMethod
Retrieve the class (type) of the first parameter of the provided method. (For setter methods, this should be the only parameter.)- Parameters:
method
- for which to determine the first parameter's type- Returns:
- the class of the first parameter
-
getParameterizedTypeOfMethod
Retrieve the parameterized class (type) of the first parameter of the provided method. (For setter methods, this should be the only parameter.)- Parameters:
method
- for which to determine the first parameter's parameterized type- Returns:
- the parameterized type of the first parameter
-
getClassOfParameterizedType
Retrieve the class (type) within the parameterized type provided. For example, if the parameterized type isList<String>
this will return the String class.- Parameters:
parameterizedType
- the parameterized type from which to determine the inner type- Returns:
- the class within the parameterized type
-