org.kuali.rice.krad.data.provider.annotation.impl
Class AnnotationMetadataProviderImpl

java.lang.Object
  extended by org.kuali.rice.krad.data.provider.impl.MetadataProviderBase
      extended by org.kuali.rice.krad.data.provider.annotation.impl.AnnotationMetadataProviderImpl
All Implemented Interfaces:
MetadataProvider, Provider

public class AnnotationMetadataProviderImpl
extends MetadataProviderBase

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
AnnotationMetadataProviderImpl()
           
 
Method Summary
protected  void addDataObjectCollection(DataObjectMetadataImpl metadata, Field f, CollectionRelationship a)
          Adds a collection relationship for a field to the metadata object.
protected  void addDataObjectRelationship(DataObjectMetadataImpl metadata, Field f, Relationship a)
          Adds a relationship for a field to the metadata object.
 DataObjectService getDataObjectService()
          Gets the DataObjectService.
protected  String getPropertyNameFromGetterMethod(Method m)
          Used 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  void initializeMetadata(Collection<Class<?>> types)
          Performs the initialization of the provider with the given set of types.
 boolean isInitializationAttempted()
          Gets whether initialization was attempted.
protected  boolean processAnnotationForAttribute(Annotation a, DataObjectAttributeImpl attr, DataObjectMetadataImpl metadata)
          Helper method to process the annotations which can be present on attributes.
protected  boolean processAnnotationsforCommonMetadata(Annotation a, MetadataCommonBase metadata)
          Helper method to process the annotations which can be present on attributes or classes.
protected  boolean processClassLevelAnnotations(Class<?> clazz, DataObjectMetadataImpl metadata)
          Handle annotations made at the class level and add their data to the given metadata object.
protected  boolean processFieldLevelAnnotations(Class<?> clazz, DataObjectMetadataImpl metadata)
          Handle annotations made at the field level and add their data to the given metadata object.
protected  boolean processInheritedAttributes(Class<?> clazz, DataObjectMetadataImpl metadata)
          Handle inherited properties and add their data to the given metadata object.
protected  boolean processMethodLevelAnnotations(Class<?> clazz, DataObjectMetadataImpl metadata)
          Handle annotations made at the method level and add their data to the given metadata object.
 boolean requiresListOfExistingTypes()
          Flag which allows the service to indicate that it requires knowledge of previously discovered persistable entities.
 void setDataObjectService(DataObjectService dataObjectService)
          Setter for the the DataObjectService.
 
Methods inherited from class org.kuali.rice.krad.data.provider.impl.MetadataProviderBase
getMetadataForType, getSupportedTypes, handles, isClassPersistable, provideMetadata, provideMetadataForTypes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AnnotationMetadataProviderImpl

public AnnotationMetadataProviderImpl()
Method Detail

initializeMetadata

protected void initializeMetadata(Collection<Class<?>> types)
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:
initializeMetadata in class MetadataProviderBase

processClassLevelAnnotations

protected boolean processClassLevelAnnotations(Class<?> clazz,
                                               DataObjectMetadataImpl metadata)
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

protected boolean processFieldLevelAnnotations(Class<?> clazz,
                                               DataObjectMetadataImpl metadata)
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

protected boolean processAnnotationsforCommonMetadata(Annotation a,
                                                      MetadataCommonBase metadata)
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

protected String getPropertyNameFromGetterMethod(Method m)
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

protected boolean processMethodLevelAnnotations(Class<?> clazz,
                                                DataObjectMetadataImpl metadata)
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

protected void addDataObjectRelationship(DataObjectMetadataImpl metadata,
                                         Field f,
                                         Relationship a)
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

protected boolean processInheritedAttributes(Class<?> clazz,
                                             DataObjectMetadataImpl metadata)
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

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.

(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:
requiresListOfExistingTypes in interface MetadataProvider
Overrides:
requiresListOfExistingTypes in class MetadataProviderBase
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

public DataObjectService getDataObjectService()
Gets the DataObjectService.

Returns:
the DataObjectService.

setDataObjectService

public void setDataObjectService(DataObjectService dataObjectService)
Setter for the the DataObjectService.

Parameters:
dataObjectService - the the DataObjectService to set.


Copyright © 2005–2014 The Kuali Foundation. All rights reserved.