Package cz.cvut.kbss.jsonld.common
Class BeanClassProcessor
java.lang.Object
cz.cvut.kbss.jsonld.common.BeanClassProcessor
Reflection-related utilities.
-
Method Summary
Modifier and TypeMethodDescriptionstatic Collection<?>
Creates collection of the specified type.static Collection<?>
createCollection
(Class<?> collectionType) Creates an instance of the specified collection type.static Collection<?>
createCollection
(Field field) Creates a collection to fill the specified field.static <T> T
createInstance
(Class<T> cls) Creates new instance of the specified class.static Class<?>
getCollectionItemType
(Field field) Determines the declared element type of collection represented by the specified field.static Object
getFieldValue
(Field field, Object instance) Extracts value of the specified field, from the specified instance.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.static Class<?>
getMapKeyType
(Field field) Determines the declared type of keys of the map represented by the specified field.static Class<?>
getMapValueType
(Field field) Gets the declared type of values of the map represented by the specified field.static boolean
isCollection
(Field field) Checks whether the specified field represents a collection.static boolean
isIdentifierType
(Class<?> cls) Checks whether the specified type is a valid identifier type.static boolean
isIndividualType
(Class<?> cls) Checks whether the specified class represents an individual reference and not a complex object.static void
setFieldValue
(Field field, Object instance, Object value) Sets value of the specified field.static void
verifyPropertiesFieldType
(Field field) Checks that the properties field is aMap
.
-
Method Details
-
getFieldValue
Extracts value of the specified field, from the specified instance.- Parameters:
field
- The field to extract value frominstance
- Instance containing the field- Returns:
- Field value, possibly
null
-
setFieldValue
Sets value of the specified field.- Parameters:
field
- The field to setinstance
- Instance on which the field will be setvalue
- The value to use
-
createInstance
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
Creates collection of the specified type.- Parameters:
type
- Collection type- Returns:
- New collection instance
-
createCollection
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
Creates an instance of the specified collection type.Lists and sets are supported.
- Parameters:
collectionType
- Type of the collection- Returns:
- New collection instance
-
getCollectionItemType
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
Determines the declared type of keys of the map represented by the specified field.- Parameters:
field
- Map field- Returns:
- Declared type of values
-
getMapValueType
Gets the declared type of values of the map represented by the specified field.- Parameters:
field
- Map field- Returns:
- Declared type of values
-
getMapGenericValueType
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 declarationMap<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
Checks whether the specified field represents a collection.- Parameters:
field
- The field to examine- Returns:
- Whether the field is a collection or not
-
verifyPropertiesFieldType
Checks that the properties field is aMap
.- Parameters:
field
- The field to check- Throws:
TargetTypeException
- When the field is not a Map
-
isIndividualType
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
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
-