org.datanucleus.metadata.annotations
Class AbstractAnnotationReader

java.lang.Object
  extended by org.datanucleus.metadata.annotations.AbstractAnnotationReader
All Implemented Interfaces:
AnnotationReader
Direct Known Subclasses:
JDOAnnotationReader, JPAAnnotationReader

public abstract class AbstractAnnotationReader
extends java.lang.Object
implements AnnotationReader

Abstract implementation of a metadata annotations reader for JDK 1.5. A metadata annotation reader takes in a class and converts its annotations into JPOX 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 "JPOX" annotations or whatever.

Version:
$Revision: 1.1 $

Field Summary
protected static org.datanucleus.util.Localiser LOCALISER
          Localiser for messages
protected  org.datanucleus.metadata.MetaDataManager mgr
          Manager for MetaData operations
protected  java.lang.String[] supportedPackages
          Supported annotations packages.
 
Constructor Summary
AbstractAnnotationReader(org.datanucleus.metadata.MetaDataManager mgr)
          Constructor.
 
Method Summary
protected  AnnotationObject[] getAnnotationObjectsForAnnotations(java.lang.String clsName, java.lang.annotation.Annotation[] annotations)
          Convenience method to convert an array of Annotation objects into an array of AnnotationObjects.
protected  AnnotationObject[] getClassAnnotationsForClass(java.lang.Class cls)
          Method returning the annotations for the class.
protected  java.util.Collection<org.datanucleus.metadata.annotations.AnnotatedMember> getFieldAnnotationsForClass(java.lang.Class cls)
          Method returning a Map containing an array of the annotations for each field of the passed class, keyed by the field name.
protected  java.util.Collection<org.datanucleus.metadata.annotations.AnnotatedMember> getJavaBeanAccessorAnnotationsForClass(java.lang.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.
 org.datanucleus.metadata.AbstractClassMetaData getMetaDataForClass(java.lang.Class cls, org.datanucleus.metadata.PackageMetaData pmd, org.datanucleus.ClassLoaderResolver clr)
          Accessor for the ClassMetaData for the specified class from its annotations.
protected  java.util.Collection<java.lang.annotation.Annotation[]> getMethodAnnotationsForClass(java.lang.Class cls)
          Method returning a Map containing an array of the annotations for each method of the passed class, keyed by the method name.
 java.lang.String[] getSupportedAnnotationPackages()
          Method to set the valid annotation packages to be supported when reading.
protected  boolean isSupportedAnnotation(java.lang.String annotationClassName)
          Convenience method to check whether an annotation class name is supported by this reader.
protected abstract  org.datanucleus.metadata.AbstractClassMetaData processClassAnnotations(org.datanucleus.metadata.PackageMetaData pmd, java.lang.Class cls, AnnotationObject[] annotations, org.datanucleus.ClassLoaderResolver clr)
          Method to process the "class" level annotations and create the outline ClassMetaData object.
protected abstract  org.datanucleus.metadata.AbstractMemberMetaData processMemberAnnotations(org.datanucleus.metadata.AbstractClassMetaData cmd, Member member, AnnotationObject[] annotations, boolean propertyAccessor)
          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(org.datanucleus.metadata.AbstractClassMetaData cmd, java.lang.reflect.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(java.lang.String[] packages)
          Method to set the valid annotation packages to be supported when reading.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCALISER

protected static org.datanucleus.util.Localiser LOCALISER
Localiser for messages


mgr

protected org.datanucleus.metadata.MetaDataManager mgr
Manager for MetaData operations


supportedPackages

protected java.lang.String[] supportedPackages
Supported annotations packages.

Constructor Detail

AbstractAnnotationReader

public AbstractAnnotationReader(org.datanucleus.metadata.MetaDataManager mgr)
Constructor.

Parameters:
mgr - MetaData manager
Method Detail

getSupportedAnnotationPackages

public java.lang.String[] getSupportedAnnotationPackages()
Method to set the valid annotation packages to be supported when reading.

Specified by:
getSupportedAnnotationPackages in interface AnnotationReader
Returns:
The supported packages.

setSupportedAnnotationPackages

protected void setSupportedAnnotationPackages(java.lang.String[] packages)
Method to set the valid annotation packages to be supported when reading.

Parameters:
packages - The supported packages.

isSupportedAnnotation

protected boolean isSupportedAnnotation(java.lang.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 org.datanucleus.metadata.AbstractClassMetaData getMetaDataForClass(java.lang.Class cls,
                                                                          org.datanucleus.metadata.PackageMetaData pmd,
                                                                          org.datanucleus.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 interface AnnotationReader
Parameters:
cls - The class
pmd - MetaData for the owning package
clr - ClassLoader resolver
Returns:
The ClassMetaData

processClassAnnotations

protected abstract org.datanucleus.metadata.AbstractClassMetaData processClassAnnotations(org.datanucleus.metadata.PackageMetaData pmd,
                                                                                          java.lang.Class cls,
                                                                                          AnnotationObject[] annotations,
                                                                                          org.datanucleus.ClassLoaderResolver clr)
Method to process the "class" level annotations and create the outline ClassMetaData object.

Parameters:
pmd - Parent PackageMetaData
cls - The class
annotations - Annotations for the class
clr - ClassLoader resolver
Returns:
The ClassMetaData (or null if no annotations)

processMemberAnnotations

protected abstract org.datanucleus.metadata.AbstractMemberMetaData processMemberAnnotations(org.datanucleus.metadata.AbstractClassMetaData cmd,
                                                                                            Member member,
                                                                                            AnnotationObject[] annotations,
                                                                                            boolean propertyAccessor)
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 processed
annotations - The annotations for this field/property
propertyAccessor - if has persistent properties
Returns:
The FieldMetaData/PropertyMetaData that was added (if any)

processMethodAnnotations

protected abstract void processMethodAnnotations(org.datanucleus.metadata.AbstractClassMetaData cmd,
                                                 java.lang.reflect.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(java.lang.Class cls)
Method returning the annotations for the class.

Parameters:
cls - The class
Returns:
Class annotations

getJavaBeanAccessorAnnotationsForClass

protected java.util.Collection<org.datanucleus.metadata.annotations.AnnotatedMember> getJavaBeanAccessorAnnotationsForClass(java.lang.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

getMethodAnnotationsForClass

protected java.util.Collection<java.lang.annotation.Annotation[]> getMethodAnnotationsForClass(java.lang.Class cls)
Method returning a Map containing an array of the annotations for each method of the passed class, keyed by the method name.

Parameters:
cls - The class
Returns:
Collection of the annotated methods

getFieldAnnotationsForClass

protected java.util.Collection<org.datanucleus.metadata.annotations.AnnotatedMember> getFieldAnnotationsForClass(java.lang.Class cls)
Method returning a Map containing an array of the annotations for each field of the passed class, keyed by the field name.

Parameters:
cls - The class
Returns:
Collection of the annotated fields

getAnnotationObjectsForAnnotations

protected AnnotationObject[] getAnnotationObjectsForAnnotations(java.lang.String clsName,
                                                                java.lang.annotation.Annotation[] annotations)
Convenience method to convert an array of Annotation objects into an array of AnnotationObjects.

Parameters:
clsName - Name of the class
annotations - The annotations
Returns:
The annotation objects


Copyright © 2009. All Rights Reserved.