Package cz.cvut.kbss.jsonld.common
Class BeanAnnotationProcessor
java.lang.Object
cz.cvut.kbss.jsonld.common.BeanAnnotationProcessor
Utilities for mapping-related tasks.
- 
Method SummaryModifier and TypeMethodDescriptionstatic StringexpandIriIfNecessary(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 StringgetAttributeIdentifier(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 StringgetOwlClass(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 theOWLClassannotation.getOwlClasses(Object object) Resolves ontological types of the specified object, as specified by theOWLClassannotation.static FieldgetPropertiesField(Class<?> cls) Retrieves a field representingPropertiesin 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 booleanhasPropertiesField(Class<?> cls) Checks whether the specified class contains aPropertiesfield.static booleanhasTypesField(Class<?> cls) Checks whether the specified class contains aTypesfield.static booleanisAnnotationProperty(Field field) Checks whether the specified field is mapped to an OWL annotation property.static booleanisInstanceIdentifier(Field field) Checks whether the specified field is an identifier field.static booleanisObjectProperty(Field field) Checks whether the specified field is mapped to an OWL object property.static booleanisOwlClassEntity(Class<?> cls) Checks whether the specified class is annotated with theOWLClassannotation.static booleanisPropertiesField(Field field) Checks whether the specified field is aPropertiesfield.static booleanisTypesField(Field field) Checks whether the specified field is aTypesfield.static booleanisWriteable(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 voidSets property access resolver, overriding the default one.
- 
Method Details- 
setPropertyAccessResolverSets property access resolver, overriding the default one.- Parameters:
- resolver- Resolver to set
 
- 
isOwlClassEntityChecks whether the specified class is annotated with theOWLClassannotation.- Parameters:
- cls- The class to examine
- Returns:
- Whether it is annotated with OWLClass
 
- 
getOwlClassGets 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 by- OWLClass
 
- 
expandIriIfNecessaryAttempts 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
 
 
- 
getOwlClassesResolves ontological types of the specified object, as specified by theOWLClassannotation.- 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:
 
- 
getOwlClassesResolves a transitive closure of ontological types of the specified class, as specified by theOWLClassannotation.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)
 
- 
getAncestorsResolves 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
 
- 
getSerializableFieldsReturns 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_ONLYaccess
 - Parameters:
- object- Object whose fields should be discovered
- Returns:
- List of discovered fields
 
- 
getMarshallableFieldsGets 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
 
- 
mapFieldsForDeserializationCreates 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.IDproperty 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
 
- 
isPropertiesFieldChecks whether the specified field is aPropertiesfield.- Parameters:
- field- The field to examine
- Returns:
- Whether the field has the Propertiesannotation
 
- 
hasPropertiesFieldChecks whether the specified class contains aPropertiesfield.- Parameters:
- cls- The class to examine
- Returns:
- Whether the class has properties field
 
- 
getPropertiesFieldRetrieves a field representingPropertiesin the specified class.- Parameters:
- cls- The class to get properties field from
- Returns:
- Properties field
- Throws:
- IllegalArgumentException- When the specified class does not have a- Propertiesfield
 
- 
getTypesFieldExtracts 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
 
- 
hasTypesFieldChecks whether the specified class contains aTypesfield.- Parameters:
- cls- The class to examine
- Returns:
- Whether the class has types field
 
- 
isObjectPropertyChecks whether the specified field is mapped to an OWL object property.- Parameters:
- field- The field to examine
- Returns:
- Whether field has a OWLObjectPropertyannotation
 
- 
isAnnotationPropertyChecks whether the specified field is mapped to an OWL annotation property.- Parameters:
- field- The field to examine
- Returns:
- Whether field has a OWLAnnotationPropertyannotation
 
- 
isInstanceIdentifierChecks whether the specified field is an identifier field.- Parameters:
- field- The field to examine
- Returns:
- Whether the field has a Idannotation
 
- 
isTypesFieldChecks whether the specified field is aTypesfield.- Parameters:
- field- The field to examine
- Returns:
- Whether the field has a Typesannotation
 
- 
isWriteableChecks whether deserialization can write into the specified field.- Parameters:
- field- The field to examine
- Returns:
- Write access status
 
- 
getAttributeIdentifierResolves JSON-LD attribute identifier of the specified field.For OWL properties, this will be their IRI. For id fields it will be the JsonLd.IDstring.- Parameters:
- field- The field to resolve
- Returns:
- JSON-LD attribute identifier
 
- 
getIdentifierFieldGets 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
 
- 
getInstanceIdentifierResolves value of the identifier attribute (i.e. annotated withId) of the specified instance.- Parameters:
- instance- Instance to get identifier value from
- Returns:
- Identifier value
 
- 
getAttributeOrderRetrieves 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
 
 
-