Package cz.cvut.kbss.jsonld.common
Class BeanAnnotationProcessor
java.lang.Object
cz.cvut.kbss.jsonld.common.BeanAnnotationProcessor
Utilities for mapping-related tasks.
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
expandIriIfNecessary
(String iri, Class<?> declaringClass) Attempts to expand the specified IRI in case it is compacted (seeIdentifierUtil.isCompactIri(String)
) using JOPA namespace declarations.getAncestors
(Class<?> cls) Resolves ancestors of the specified class, up toObject
.static String
getAttributeIdentifier
(Field field) Resolves JSON-LD attribute identifier of the specified field.static String[]
getAttributeOrder
(Class<?> cls) Retrieves an array of attribute names specifying (partial) order in which they should be (de)serialized.getIdentifierField
(Class<?> cls) Gets the identifier field of the specified class.getInstanceIdentifier
(Object instance) Resolves value of the identifier attribute (i.e. annotated withId
) of the specified instance.getMarshallableFields
(Class<?> cls) Gets all fields which can be serialized or deserialized from the specified class (or its supertypes).static String
getOwlClass
(Class<?> cls) Gets IRI of the OWL class represented by the specified Java class.getOwlClasses
(Class<?> cls) Resolves a transitive closure of ontological types of the specified class, as specified by theOWLClass
annotation.getOwlClasses
(Object object) Resolves ontological types of the specified object, as specified by theOWLClass
annotation.static Field
getPropertiesField
(Class<?> cls) Retrieves a field representingProperties
in the specified class.getSerializableFields
(Object object) Returns all fields of the class of the specified object and its superclasses, which can be serialized into JSON-LD.getTypesField
(Class<?> cls) Extracts types field from the specified class or any of its ancestors.static boolean
hasPropertiesField
(Class<?> cls) Checks whether the specified class contains aProperties
field.static boolean
hasTypesField
(Class<?> cls) Checks whether the specified class contains aTypes
field.static boolean
isAnnotationProperty
(Field field) Checks whether the specified field is mapped to an OWL annotation property.static boolean
isInstanceIdentifier
(Field field) Checks whether the specified field is an identifier field.static boolean
isObjectProperty
(Field field) Checks whether the specified field is mapped to an OWL object property.static boolean
isOwlClassEntity
(Class<?> cls) Checks whether the specified class is annotated with theOWLClass
annotation.static boolean
isPropertiesField
(Field field) Checks whether the specified field is aProperties
field.static boolean
isTypesField
(Field field) Checks whether the specified field is aTypes
field.static boolean
isWriteable
(Field field) Checks whether deserialization can write into the specified field.mapFieldsForDeserialization
(Class<?> cls) Creates a map of JSON-LD serializable fields, where the keys are IRIs of properties mapped by the fields.static void
Sets property access resolver, overriding the default one.
-
Method Details
-
setPropertyAccessResolver
Sets property access resolver, overriding the default one.- Parameters:
resolver
- Resolver to set
-
isOwlClassEntity
Checks whether the specified class is annotated with theOWLClass
annotation.- Parameters:
cls
- The class to examine- Returns:
- Whether it is annotated with
OWLClass
-
getOwlClass
Gets IRI of the OWL class represented by the specified Java class.- Parameters:
cls
- Java class to examine- Returns:
- Represented ontological class
- Throws:
IllegalArgumentException
- If the specified class is not mapped byOWLClass
-
expandIriIfNecessary
Attempts to expand the specified IRI in case it is compacted (seeIdentifierUtil.isCompactIri(String)
) using JOPA namespace declarations.If the IRI is not compact or no matching namespace is found, the original IRI is returned.
- Parameters:
iri
- IRI to expand (if necessary and possible)declaringClass
- Class in/on which the IRI is declared. It is used as base for namespace search- Returns:
- Expanded IRI if it was possible to expand it, original argument if not
- See Also:
-
IdentifierUtil.isCompactIri(String)
Namespaces
Namespace
-
getOwlClasses
Resolves ontological types of the specified object, as specified by theOWLClass
annotation.- Parameters:
object
- The object to resolve- Returns:
- Resolved OWL types or an empty set if the object's class is not annotated with
OWLClass
- See Also:
-
getOwlClasses
Resolves a transitive closure of ontological types of the specified class, as specified by theOWLClass
annotation.I.e. the result contains also types mapped by the class's ancestors.
- Parameters:
cls
- The class to process- Returns:
- Set of mapped ontological classes (possibly empty)
-
getAncestors
Resolves ancestors of the specified class, up toObject
.Ancestors are resolved using the
Class.getSuperclass()
method.- Parameters:
cls
- Class whose ancestors to resolve- Returns:
- List of ancestors, including the specified class
-
getSerializableFields
Returns all fields of the class of the specified object and its superclasses, which can be serialized into JSON-LD.For a field to be serializable, it has to be:
- Non-static
- Annotated with one of the following annotations:
Id
,OWLAnnotationProperty
,OWLDataProperty
,OWLObjectProperty
- Not configured with
JsonLdProperty.Access.WRITE_ONLY
access
- Parameters:
object
- Object whose fields should be discovered- Returns:
- List of discovered fields
-
getMarshallableFields
Gets all fields which can be serialized or deserialized from the specified class (or its supertypes).is does not take into account property access configuration, just the fact that a field is:
- Non-static
- Annotated with one of the following annotations:
Id
,OWLAnnotationProperty
,OWLDataProperty
,OWLObjectProperty
- Parameters:
cls
- Class to check- Returns:
- List of marshallable fields
-
mapFieldsForDeserialization
Creates a map of JSON-LD serializable fields, where the keys are IRIs of properties mapped by the fields.Identifier field is mapped to the
JsonLd.ID
property identifier. Ancestors of the specified class are also scanned.- Parameters:
cls
- Class for which the mapping should be determined- Returns:
- Mapping of OWL properties to fields
-
isPropertiesField
Checks whether the specified field is aProperties
field.- Parameters:
field
- The field to examine- Returns:
- Whether the field has the
Properties
annotation
-
hasPropertiesField
Checks whether the specified class contains aProperties
field.- Parameters:
cls
- The class to examine- Returns:
- Whether the class has properties field
-
getPropertiesField
Retrieves a field representingProperties
in the specified class.- Parameters:
cls
- The class to get properties field from- Returns:
- Properties field
- Throws:
IllegalArgumentException
- When the specified class does not have aProperties
field
-
getTypesField
Extracts types field from the specified class or any of its ancestors.This method assumes there is at most one types field in the class hierarchy.
- Parameters:
cls
- The class to scan- Returns:
- Types field
-
hasTypesField
Checks whether the specified class contains aTypes
field.- Parameters:
cls
- The class to examine- Returns:
- Whether the class has types field
-
isObjectProperty
Checks whether the specified field is mapped to an OWL object property.- Parameters:
field
- The field to examine- Returns:
- Whether field has a
OWLObjectProperty
annotation
-
isAnnotationProperty
Checks whether the specified field is mapped to an OWL annotation property.- Parameters:
field
- The field to examine- Returns:
- Whether field has a
OWLAnnotationProperty
annotation
-
isInstanceIdentifier
Checks whether the specified field is an identifier field.- Parameters:
field
- The field to examine- Returns:
- Whether the field has a
Id
annotation
-
isTypesField
Checks whether the specified field is aTypes
field.- Parameters:
field
- The field to examine- Returns:
- Whether the field has a
Types
annotation
-
isWriteable
Checks whether deserialization can write into the specified field.- Parameters:
field
- The field to examine- Returns:
- Write access status
-
getAttributeIdentifier
Resolves JSON-LD attribute identifier of the specified field.For OWL properties, this will be their IRI. For id fields it will be the
JsonLd.ID
string.- Parameters:
field
- The field to resolve- Returns:
- JSON-LD attribute identifier
-
getIdentifierField
Gets the identifier field of the specified class.That is, gets the field annotated with
Id
, even inherited.- Parameters:
cls
- Class whose identifier field to retrieve- Returns:
- Matching field, optionally empty
-
getInstanceIdentifier
Resolves value of the identifier attribute (i.e. annotated withId
) of the specified instance.- Parameters:
instance
- Instance to get identifier value from- Returns:
- Identifier value
-
getAttributeOrder
Retrieves an array of attribute names specifying (partial) order in which they should be (de)serialized.- Parameters:
cls
- Class whose attribute order should be retrieved- Returns:
- Array declaring attribute order, possibly empty
-