Class ReflectionCache

java.lang.Object
com.atlan.cache.ReflectionCache

public class ReflectionCache extends Object
Lazily-loaded cache for Java reflection-based operations across the Atlan data model.
  • Constructor Details

    • ReflectionCache

      public ReflectionCache()
  • Method Details

    • getFieldNames

      public static Set<String> getFieldNames(Class<?> b)
      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

      public static Class<?> getFieldType(Class<?> b, String fieldName)
      Retrieve the type of the specified field.
      Parameters:
      b - class of the asset type
      fieldName - name of the field
      Returns:
      the type of that field
    • isAttribute

      public static boolean isAttribute(Class<?> b, String fieldName)
      Check whether the provided field name is annotated as an attribute (true) or not (false).
      Parameters:
      b - class of the asset type
      fieldName - name of the field
      Returns:
      true if the field should be attributes-nested, false otherwise
    • isDate

      public static boolean isDate(Class<?> b, String fieldName)
      Check whether the provided field name is annotated as a date (true) or not (false).
      Parameters:
      b - class of the asset type
      fieldName - name of the field
      Returns:
      true if the field should be treated as a date, false otherwise
    • getGetter

      public static Method getGetter(Class<?> b, String fieldName)
      Retrieve the getter method for the specified field.
      Parameters:
      b - class of the asset type
      fieldName - name of the field
      Returns:
      getter method that can be invoked to retrieve the value of the field
    • getValue

      public static Object getValue(Asset a, String fieldName) throws IOException
      Retrieve the value for a specified field from the provided asset.
      Parameters:
      a - asset from which to retrieve the value
      fieldName - 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

      public static Method getSetter(Class<?> b, String fieldName)
      Retrieve the setter method for the specified field.
      Parameters:
      b - class of the asset type
      fieldName - 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, InvocationTargetException
      Set the value of a field on a specific asset (via its mutable builder).
      Parameters:
      builder - for the asset through which to set the property
      fieldName - name of the property to set
      value - 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 field
      IllegalAccessException - if the setter cannot be accessed to set this field
      InvocationTargetException - if the provided builder cannot be used
    • setValue

      Set the value of a field on a specific asset (via its mutable builder).
      Parameters:
      builder - for the asset through which to set the property
      fieldName - name of the property to set
      value - value to set on the property
      Throws:
      NoSuchMethodException - if there is no setter on the builder to set this field
      IllegalAccessException - if the setter cannot be accessed to set this field
      InvocationTargetException - if the provided builder cannot be used
    • getSerializedName

      public static String getSerializedName(Class<?> b, String fieldName)
      Retrieve the name that should be used for this field for serialization purposes.
      Parameters:
      b - class of the asset type
      fieldName - name of the field
      Returns:
      the name of the field to use when serializing into JSON
    • getDeserializedName

      public static String getDeserializedName(Class<?> b, String fieldName)
      Retrieve the name that should be used for this field for deserialization purposes.
      Parameters:
      b - class of the asset type
      fieldName - name of the field
      Returns:
      the name of the field to use when deserializing into an object
    • getParameterOfMethod

      public static Class<?> getParameterOfMethod(Method method)
      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

      public static Type getParameterizedTypeOfMethod(Method method)
      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

      public static Class<?> getClassOfParameterizedType(Type parameterizedType)
      Retrieve the class (type) within the parameterized type provided. For example, if the parameterized type is List<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