Top Description Methods
org.glassfish.jaxb.core.v2.model.annotation

public Interface AnnotationReader<T, C, F, M>

Known Direct Subinterfaces
org.glassfish.jaxb.runtime.v2.model.annotation.RuntimeAnnotationReader
Known Direct Implementers
org.glassfish.jaxb.runtime.v2.model.annotation.AbstractInlineAnnotationReaderImpl
Imports
java.lang.annotation.Annotation, java.lang.reflect.Field, .Method, com.sun.istack.Nullable, org.glassfish.jaxb.core.v2.model.core.ErrorHandler

Reads annotations for the given property.

This is the lowest abstraction that encapsulates the difference between reading inline annotations and external binding files.

Because the former operates on a Field and Method while the latter operates on a "property", the methods defined on this interface takes both, and the callee gets to choose which to use.

Most of the get method takes Locatable, which points to the place/context in which the annotation is read. The returned annotation also implements Locatable (so that it can point to the place where the annotation is placed), and its Locatable#getUpstream() will return the given Locatable.

Errors found during reading annotations are reported through the error handler. A valid ErrorHandler must be registered before the AnnotationReader is used.

Author
Kohsuke Kawaguchi ([email protected])

Method Summary

Modifier and TypeMethod and Description
public Annotation[]
getAllFieldAnnotations(F field, Locatable srcPos)

Gets all the annotations on a field.

public Annotation[]
getAllMethodAnnotations(M method, Locatable
the location from which this annotation is read.
srcPos
)

Gets all the annotations on a method.

public <A extends Annotation> A
getClassAnnotation(Class<A> annotation, C clazz, Locatable srcpos)

Reads an annotation on a class.

public T[]
getClassArrayValue(Annotation a, String name)

Similar to getClassValue(Annotation, String) method but obtains an array parameter.

public T
getClassValue(Annotation a, String
The name of the annotation parameter to be read.
name
)

Reads a value of an annotation that returns a Class object.

public <A extends Annotation> A
getFieldAnnotation(Class<A> annotation, F field, Locatable srcpos)

Reads an annotation on a property that consists of a field.

public <A extends Annotation> A
getMethodAnnotation(Class<A> annotation, M getter, M setter, Locatable srcpos)

Reads an annotation on a property that consists of a getter and a setter.

public <A extends Annotation> A
getMethodAnnotation(Class<A> annotation, M method, Locatable srcpos)

public <A extends Annotation> A

Returns:

null if the annotation was not found.
getMethodParameterAnnotation
(Class<A> annotation, M method, int paramIndex, Locatable srcPos)

Reads an annotation on a parameter of the method.

public <A extends Annotation> A
getPackageAnnotation(Class<A> annotation, C clazz, Locatable srcpos)

Reads an annotation on the package that the given class belongs to.

public boolean
hasClassAnnotation(C clazz, Class<? extends Annotation> annotationType)

Checks if a class has the annotation.

public boolean
hasFieldAnnotation(Class<? extends Annotation> annotationType, F field)

Checks if the given field has an annotation.

public boolean
hasMethodAnnotation(Class<? extends Annotation> annotation, String propertyName, M getter, M setter, Locatable srcPos)

Checks if the given method has an annotation.

public boolean
hasMethodAnnotation(Class<? extends Annotation> annotation, M method)

public void
setErrorHandler(ErrorHandler
must not be null.
errorHandler
)

Sets the error handler that receives errors found during reading annotations.

Method Detail

getAllFieldAnnotationsback to summary
public Annotation[] getAllFieldAnnotations(F field, Locatable srcPos)

Gets all the annotations on a field.

getAllMethodAnnotationsback to summary
public Annotation[] getAllMethodAnnotations(M method, Locatable srcPos)

Gets all the annotations on a method.

Parameters
srcPos:Locatable

the location from which this annotation is read.

getClassAnnotationback to summary
public <A extends Annotation> A getClassAnnotation(Class<A> annotation, C clazz, Locatable srcpos)

Reads an annotation on a class.

Annotations
@Nullable
getClassArrayValueback to summary
public T[] getClassArrayValue(Annotation a, String name)

Similar to getClassValue(Annotation, String) method but obtains an array parameter.

getClassValueback to summary
public T getClassValue(Annotation a, String name)

Reads a value of an annotation that returns a Class object.

Depending on the underlying reflection library, you can't always obtain the Class object directly (see the Annotation Processing MirrorTypeException for example), so use this method to avoid that.

Parameters
name:String

The name of the annotation parameter to be read.

getFieldAnnotationback to summary
public <A extends Annotation> A getFieldAnnotation(Class<A> annotation, F field, Locatable srcpos)

Reads an annotation on a property that consists of a field.

getMethodAnnotationback to summary
public <A extends Annotation> A getMethodAnnotation(Class<A> annotation, M getter, M setter, Locatable srcpos)

Reads an annotation on a property that consists of a getter and a setter.

getMethodAnnotationback to summary
public <A extends Annotation> A getMethodAnnotation(Class<A> annotation, M method, Locatable srcpos)
getMethodParameterAnnotationback to summary
public <A extends Annotation> A getMethodParameterAnnotation(Class<A> annotation, M method, int paramIndex, Locatable srcPos)

Reads an annotation on a parameter of the method.

Returns:A

null if the annotation was not found.

Annotations
@Nullable
getPackageAnnotationback to summary
public <A extends Annotation> A getPackageAnnotation(Class<A> annotation, C clazz, Locatable srcpos)

Reads an annotation on the package that the given class belongs to.

Annotations
@Nullable
hasClassAnnotationback to summary
public boolean hasClassAnnotation(C clazz, Class<? extends Annotation> annotationType)

Checks if a class has the annotation.

hasFieldAnnotationback to summary
public boolean hasFieldAnnotation(Class<? extends Annotation> annotationType, F field)

Checks if the given field has an annotation.

hasMethodAnnotationback to summary
public boolean hasMethodAnnotation(Class<? extends Annotation> annotation, String propertyName, M getter, M setter, Locatable srcPos)

Checks if the given method has an annotation.

hasMethodAnnotationback to summary
public boolean hasMethodAnnotation(Class<? extends Annotation> annotation, M method)
setErrorHandlerback to summary
public void setErrorHandler(ErrorHandler errorHandler)

Sets the error handler that receives errors found during reading annotations.

Parameters
errorHandler:ErrorHandler

must not be null.