Class AnnotationMetadataProviderImpl
java.lang.Object
org.kuali.rice.krad.data.provider.impl.MetadataProviderBase
org.kuali.rice.krad.data.provider.annotation.impl.AnnotationMetadataProviderImpl
- All Implemented Interfaces:
MetadataProvider,Provider
Parses custom krad-data annotations for additional metadata to layer on top of that provided by the persistence
metadata provider which should have run before this one.
At the moment, it will only process classes which were previously identified by the JPA implementation.
TODO: Addition of a new Annotation which will need to be scanned for in order to process non-persistent classes as data objects.
- Author:
- Kuali Rice Team (rice.collab@kuali.org)
-
Field Summary
Fields inherited from class org.kuali.rice.krad.data.provider.impl.MetadataProviderBase
masterMetadataMap -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddDataObjectCollection(DataObjectMetadataImpl metadata, Field f, CollectionRelationship a) Adds a collection relationship for a field to the metadata object.protected voidaddDataObjectRelationship(DataObjectMetadataImpl metadata, Field f, Relationship a) Adds a relationship for a field to the metadata object.Gets theDataObjectService.protected StringUsed to find the property name from a getter method.protected Class<?> getTypeOfProperty(Class<?> clazz, String propertyName) Used to find the property type of a given attribute regardless of whether the attribute exists as a field or only as a getter method.protected voidinitializeMetadata(Collection<Class<?>> types) Performs the initialization of the provider with the given set of types.booleanGets whether initialization was attempted.protected booleanprocessAnnotationForAttribute(Annotation a, DataObjectAttributeImpl attr, DataObjectMetadataImpl metadata) Helper method to process the annotations which can be present on attributes.protected booleanHelper method to process the annotations which can be present on attributes or classes.protected booleanprocessClassLevelAnnotations(Class<?> clazz, DataObjectMetadataImpl metadata) Handle annotations made at the class level and add their data to the given metadata object.protected booleanprocessFieldLevelAnnotations(Class<?> clazz, DataObjectMetadataImpl metadata) Handle annotations made at the field level and add their data to the given metadata object.protected booleanprocessInheritedAttributes(Class<?> clazz, DataObjectMetadataImpl metadata) Handle inherited properties and add their data to the given metadata object.protected booleanprocessMethodLevelAnnotations(Class<?> clazz, DataObjectMetadataImpl metadata) Handle annotations made at the method level and add their data to the given metadata object.booleanFlag which allows the service to indicate that it requires knowledge of previously discovered persistable entities.voidsetDataObjectService(DataObjectService dataObjectService) Setter for the theDataObjectService.Methods inherited from class org.kuali.rice.krad.data.provider.impl.MetadataProviderBase
getMetadataForType, getSupportedTypes, handles, isClassPersistable, provideMetadata, provideMetadataForTypes
-
Constructor Details
-
AnnotationMetadataProviderImpl
public AnnotationMetadataProviderImpl()
-
-
Method Details
-
initializeMetadata
Performs the initialization of the provider with the given set of types.If the list is null or empty, the provider is expected to discover the types via other means, or do nothing if the types cannot be discovered.
- Specified by:
initializeMetadatain classMetadataProviderBase
-
processClassLevelAnnotations
Handle annotations made at the class level and add their data to the given metadata object.- Parameters:
clazz- the class to process.metadata- the metadata for the class.- Returns:
- true if any annotations are found.
-
processFieldLevelAnnotations
Handle annotations made at the field level and add their data to the given metadata object.- Parameters:
clazz- the class to process.metadata- the metadata for the class.- Returns:
- true if any annotations are found.
-
processAnnotationsforCommonMetadata
Helper method to process the annotations which can be present on attributes or classes.- Parameters:
a- the annotation to process.metadata- the metadata for the class.- Returns:
- true if a valid annotation is found
-
processAnnotationForAttribute
protected boolean processAnnotationForAttribute(Annotation a, DataObjectAttributeImpl attr, DataObjectMetadataImpl metadata) Helper method to process the annotations which can be present on attributes.Used to abstract the logic so it can be applied to both field and method-level annotations.
- Parameters:
a- the annotation to process.attr- the attribute for the field.metadata- the metadata for the class.- Returns:
- true if any annotations were processed, false if not
-
getPropertyNameFromGetterMethod
Used to find the property name from a getter method.(Not using PropertyUtils since it required an instance of the class.)
- Parameters:
m- the method from which to get the property name.- Returns:
- the property name.
-
processMethodLevelAnnotations
Handle annotations made at the method level and add their data to the given metadata object.- Parameters:
clazz- the class to process.metadata- the metadata for the class.- Returns:
- true if any annotations are found.
-
addDataObjectRelationship
Adds a relationship for a field to the metadata object.- Parameters:
metadata- the metadata for the class.f- the field to process.a- the relationship to add.
-
addDataObjectCollection
protected void addDataObjectCollection(DataObjectMetadataImpl metadata, Field f, CollectionRelationship a) Adds a collection relationship for a field to the metadata object.- Parameters:
metadata- the metadata for the class.f- the field to process.a- the collection relationship to add.
-
processInheritedAttributes
Handle inherited properties and add their data to the given metadata object.- Parameters:
clazz- the class to process.metadata- the metadata for the class.- Returns:
- true if any annotations are found.
-
getTypeOfProperty
Used to find the property type of a given attribute regardless of whether the attribute exists as a field or only as a getter method.(Not using PropertyUtils since it required an instance of the class.)
- Parameters:
clazz- the class that contains the property.propertyName- the name of the property.- Returns:
- the type of the property.
-
requiresListOfExistingTypes
public boolean requiresListOfExistingTypes()Flag which allows the service to indicate that it requires knowledge of previously discovered persistable entities.That is, the service is designed only to process existing objects and not to create new ones.
By default, providers are assumed to be able to pull the list of annotated types from somewhere. Returns true in this implementation. This tells the composite metadata provider to pass in all known metadata to the initializeMetadata method.- Specified by:
requiresListOfExistingTypesin interfaceMetadataProvider- Overrides:
requiresListOfExistingTypesin classMetadataProviderBase- Returns:
- true if this provider will fail when passed an empty list of entity types
-
isInitializationAttempted
public boolean isInitializationAttempted()Gets whether initialization was attempted.- Returns:
- whether initialization was attempted.
-
getDataObjectService
Gets theDataObjectService.- Returns:
- the
DataObjectService.
-
setDataObjectService
Setter for the theDataObjectService.- Parameters:
dataObjectService- the theDataObjectServiceto set.
-