Class AbstractAnnotationReader
- java.lang.Object
-
- org.datanucleus.metadata.annotations.AbstractAnnotationReader
-
- All Implemented Interfaces:
AnnotationReader
public abstract class AbstractAnnotationReader extends Object implements AnnotationReader
Abstract implementation of a metadata annotations reader. A metadata annotation reader takes in a class and converts its annotations into internal metadata. Any implementation has to implement the method "processClassAnnotations" which creates the ClassMetaData record for the class, and the method "processFieldAnnotations" which updates the ClassMetaData with its field definition.Each annotation reader supports a set of annotations. So it could support "JPA" annotations, or "JDO" annotations, or "DataNucleus" annotations or whatever.
-
-
Field Summary
Fields Modifier and Type Field Description protected MetaDataManager
mmgr
Manager for MetaData operationsprotected Set<String>
supportedDuplicateAnnotations
Supported annotations that can be duplicated (when used in meta-annotations).protected String[]
supportedPackages
Supported annotations packages.
-
Constructor Summary
Constructors Constructor Description AbstractAnnotationReader(MetaDataManager mgr)
Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addSupportedDuplicateAnnotations(String annot)
protected AnnotationObject[]
getAnnotationObjectsForAnnotations(String clsName, Annotation[] annotations)
Convenience method to convert an array of Annotation objects into an array of AnnotationObjects.protected AnnotationObject[]
getClassAnnotationsForClass(Class cls)
Method returning the annotations for the class.protected Collection<org.datanucleus.metadata.annotations.AnnotatedMember>
getFieldAnnotationsForClass(Class cls)
Method returning a Collection of the annotated fields for the specified class.protected Collection<org.datanucleus.metadata.annotations.AnnotatedMember>
getJavaBeanAccessorAnnotationsForClass(Class cls)
Method returning a Map containing an array of the annotations for each Java Bean accessor method of the passed class, keyed by the method name.AbstractClassMetaData
getMetaDataForClass(Class cls, PackageMetaData pmd, ClassLoaderResolver clr)
Accessor for the ClassMetaData for the specified class from its annotations.String[]
getSupportedAnnotationPackages()
Method to set the valid annotation packages to be supported when reading.boolean
isPersistenceContext()
Method to return whether this is reading in a persistence context.protected boolean
isSupportedAnnotation(String annotationClassName)
Convenience method to check whether an annotation class name is supported by this reader.protected abstract AbstractClassMetaData
processClassAnnotations(PackageMetaData pmd, Class cls, AnnotationObject[] annotations, ClassLoaderResolver clr)
Method to process the "class" level annotations and create the outline ClassMetaData object.protected abstract AbstractMemberMetaData
processMemberAnnotations(AbstractClassMetaData cmd, Member member, AnnotationObject[] annotations)
Method to take the passed in outline ClassMetaData and process the annotations for fields/properties adding any necessary FieldMetaData/PropertyMetaData to the ClassMetaData.protected abstract void
processMethodAnnotations(AbstractClassMetaData cmd, Method method)
Method to take the passed in outline ClassMetaData and process the annotations for method adding any necessary MetaData to the ClassMetaData.protected void
setSupportedAnnotationPackages(String[] packages)
Method to set the valid annotation packages to be supported when reading.
-
-
-
Field Detail
-
mmgr
protected MetaDataManager mmgr
Manager for MetaData operations
-
supportedPackages
protected String[] supportedPackages
Supported annotations packages.
-
-
Constructor Detail
-
AbstractAnnotationReader
public AbstractAnnotationReader(MetaDataManager mgr)
Constructor.- Parameters:
mgr
- MetaData manager
-
-
Method Detail
-
isPersistenceContext
public boolean isPersistenceContext()
Description copied from interface:AnnotationReader
Method to return whether this is reading in a persistence context.- Specified by:
isPersistenceContext
in interfaceAnnotationReader
- Returns:
- Whether this is a persistence context
-
getSupportedAnnotationPackages
public String[] getSupportedAnnotationPackages()
Method to set the valid annotation packages to be supported when reading.- Specified by:
getSupportedAnnotationPackages
in interfaceAnnotationReader
- Returns:
- The supported packages.
-
setSupportedAnnotationPackages
protected void setSupportedAnnotationPackages(String[] packages)
Method to set the valid annotation packages to be supported when reading.- Parameters:
packages
- The supported packages.
-
addSupportedDuplicateAnnotations
protected void addSupportedDuplicateAnnotations(String annot)
-
isSupportedAnnotation
protected boolean isSupportedAnnotation(String annotationClassName)
Convenience method to check whether an annotation class name is supported by this reader.- Parameters:
annotationClassName
- Name of the annotation class- Returns:
- Whether it is supported.
-
getMetaDataForClass
public AbstractClassMetaData getMetaDataForClass(Class cls, PackageMetaData pmd, ClassLoaderResolver clr)
Accessor for the ClassMetaData for the specified class from its annotations. The returned ClassMetaData will be unpopulated and uninitialised.- Specified by:
getMetaDataForClass
in interfaceAnnotationReader
- Parameters:
cls
- The classpmd
- MetaData for the owning packageclr
- ClassLoader resolver- Returns:
- The ClassMetaData
-
processClassAnnotations
protected abstract AbstractClassMetaData processClassAnnotations(PackageMetaData pmd, Class cls, AnnotationObject[] annotations, ClassLoaderResolver clr)
Method to process the "class" level annotations and create the outline ClassMetaData object.- Parameters:
pmd
- Parent PackageMetaDatacls
- The classannotations
- Annotations for the classclr
- ClassLoader resolver- Returns:
- The ClassMetaData (or null if no annotations)
-
processMemberAnnotations
protected abstract AbstractMemberMetaData processMemberAnnotations(AbstractClassMetaData cmd, Member member, AnnotationObject[] annotations)
Method to take the passed in outline ClassMetaData and process the annotations for fields/properties adding any necessary FieldMetaData/PropertyMetaData to the ClassMetaData.- Parameters:
cmd
- The ClassMetaData (to be updated)member
- The field/property being processedannotations
- The annotations for this field/property- Returns:
- The FieldMetaData/PropertyMetaData that was added (if any)
-
processMethodAnnotations
protected abstract void processMethodAnnotations(AbstractClassMetaData cmd, Method method)
Method to take the passed in outline ClassMetaData and process the annotations for method adding any necessary MetaData to the ClassMetaData. Called for all methods and is intended for processing of any methods other than persistence specifications (for example listener methods). Methods for persistence specification are processed via "processMemberAnnotations".- Parameters:
cmd
- The ClassMetaData (to be updated)method
- The method
-
getClassAnnotationsForClass
protected AnnotationObject[] getClassAnnotationsForClass(Class cls)
Method returning the annotations for the class.- Parameters:
cls
- The class- Returns:
- Class annotations
-
getJavaBeanAccessorAnnotationsForClass
protected Collection<org.datanucleus.metadata.annotations.AnnotatedMember> getJavaBeanAccessorAnnotationsForClass(Class cls)
Method returning a Map containing an array of the annotations for each Java Bean accessor method of the passed class, keyed by the method name.- Parameters:
cls
- The class- Returns:
- Collection of the annotated methods (with supported annotations)
-
getFieldAnnotationsForClass
protected Collection<org.datanucleus.metadata.annotations.AnnotatedMember> getFieldAnnotationsForClass(Class cls)
Method returning a Collection of the annotated fields for the specified class.- Parameters:
cls
- The class- Returns:
- Collection of the annotated fields (with supported annotations)
-
getAnnotationObjectsForAnnotations
protected AnnotationObject[] getAnnotationObjectsForAnnotations(String clsName, Annotation[] annotations)
Convenience method to convert an array of Annotation objects into an array of AnnotationObjects.- Parameters:
clsName
- Name of the classannotations
- The annotations- Returns:
- The annotation objects
-
-