Class BeanClassProcessor

java.lang.Object
cz.cvut.kbss.jsonld.common.BeanClassProcessor

public class BeanClassProcessor extends Object
Reflection-related utilities.
  • Method Details

    • getFieldValue

      public static Object getFieldValue(Field field, Object instance)
      Extracts value of the specified field, from the specified instance.
      Parameters:
      field - The field to extract value from
      instance - Instance containing the field
      Returns:
      Field value, possibly null
    • setFieldValue

      public static void setFieldValue(Field field, Object instance, Object value)
      Sets value of the specified field.
      Parameters:
      field - The field to set
      instance - Instance on which the field will be set
      value - The value to use
    • createInstance

      public static <T> T createInstance(Class<T> cls)
      Creates new instance of the specified class.
      Type Parameters:
      T - The type of the created object
      Parameters:
      cls - The class to instantiate
      Returns:
      New instance
      Throws:
      BeanProcessingException - If the class is missing a public no-arg constructor
    • createCollection

      public static Collection<?> createCollection(CollectionType type)
      Creates collection of the specified type.
      Parameters:
      type - Collection type
      Returns:
      New collection instance
    • createCollection

      public static Collection<?> createCollection(Field field)
      Creates a collection to fill the specified field.

      I.e. the type of the collection is determined from the declared type of the field.

      Parameters:
      field - The field to create collection for
      Returns:
      New collection instance
    • createCollection

      public static Collection<?> createCollection(Class<?> collectionType)
      Creates an instance of the specified collection type.

      Lists and sets are supported.

      Parameters:
      collectionType - Type of the collection
      Returns:
      New collection instance
    • getCollectionItemType

      public static Class<?> getCollectionItemType(Field field)
      Determines the declared element type of collection represented by the specified field.
      Parameters:
      field - Field whose type is a collection
      Returns:
      Declared element type of the collection
    • getMapKeyType

      public static Class<?> getMapKeyType(Field field)
      Determines the declared type of keys of the map represented by the specified field.
      Parameters:
      field - Map field
      Returns:
      Declared type of values
    • getMapValueType

      public static Class<?> getMapValueType(Field field)
      Gets the declared type of values of the map represented by the specified field.
      Parameters:
      field - Map field
      Returns:
      Declared type of values
    • getMapGenericValueType

      public static Class<?> getMapGenericValueType(Field field)
      In case the map represent by the specified field has as value another generic type, this method retrieves this generic type's actual first argument.

      This implementation is supposed to determine value type of Properties fields with the following declaration Map<String, Collection<?>>, where the collection can be replaced by a more specific type (List, Set) and the map key type can be also different.

      Parameters:
      field - Map field
      Returns:
      Value type if present, null otherwise
    • isCollection

      public static boolean isCollection(Field field)
      Checks whether the specified field represents a collection.
      Parameters:
      field - The field to examine
      Returns:
      Whether the field is a collection or not
    • verifyPropertiesFieldType

      public static void verifyPropertiesFieldType(Field field)
      Checks that the properties field is a Map.
      Parameters:
      field - The field to check
      Throws:
      TargetTypeException - When the field is not a Map
    • isIndividualType

      public static boolean isIndividualType(Class<?> cls)
      Checks whether the specified class represents an individual reference and not a complex object.

      Individual references are identifiers or enum constants mapped to individuals.

      Parameters:
      cls - Class to check
      Returns:
      true when the type represents an individual, false otherwise
      See Also:
    • isIdentifierType

      public static boolean isIdentifierType(Class<?> cls)
      Checks whether the specified type is a valid identifier type.
      Parameters:
      cls - Class to check
      Returns:
      true if the specified class can be used as identifier field type, false otherwise
      See Also:
      • PersistenceProperties.IDENTIFIER_TYPES