public abstract class AnnotationDataReader<A extends java.lang.annotation.Annotation,D extends AnnotationDataReader.AnnotationData<A>>
extends java.lang.Object
annotation data object
populated with annotation element values. Can be used to simulate annotation inheritance,
as such does not exist in Java.
There are 3 ways how this class can be used. First, it can be used on single annotation, but that does not make much sense.
Second way is with child and parent annotation. The parent annotation is default one, like a base class. Child annotation contains some predefined values different from parent. Note that child annotation does NOT have to specify all elements - all missing elements will be read from default parent annotation. So child annotation behaves like it is overriding the parent one.
Third way is similar, except the child annotation is also annotated with parent annotation! Besides overriding features and default values, this way we can finalize some element value and prevent it from being modified by user.
Modifier and Type | Class and Description |
---|---|
static class |
AnnotationDataReader.AnnotationData<N extends java.lang.annotation.Annotation>
Base class for annotation data, for holding annotation elements values.
|
Modifier and Type | Field and Description |
---|---|
protected java.lang.Class<A> |
annotationClass |
protected java.lang.annotation.Annotation |
defaultAnnotation |
Modifier | Constructor and Description |
---|---|
protected |
AnnotationDataReader(java.lang.Class<A> annotationClass,
java.lang.Class<? extends java.lang.annotation.Annotation> defaultAnnotationClass)
Creates new annotation data reader using annotation definition
from class generics.
|
Modifier and Type | Method and Description |
---|---|
protected abstract D |
createAnnotationData(A annotation)
Creates annotation data from given annotation.
|
java.lang.Class<A> |
getAnnotationClass()
Returns annotation class.
|
boolean |
hasAnnotation(java.lang.reflect.AccessibleObject accessibleObject)
Returns
true if annotation is present on
given accessible object. |
D |
readAnnotationData(java.lang.reflect.AccessibleObject accessibleObject)
Reads
annotation data on provided accessible object. |
D |
readAnnotationData(java.lang.Class<?> type)
Reads
annotation data on provided type. |
protected boolean |
readBoolean(A annotation,
java.lang.String name,
boolean defaultValue)
Reads boolean element from the annotation.
|
protected java.lang.Object |
readElement(A annotation,
java.lang.String name)
Reads annotation element as an object.
|
protected int |
readInt(A annotation,
java.lang.String name,
int defaultValue)
Reads int element from the annotation.
|
protected java.lang.String |
readString(A annotation,
java.lang.String name,
java.lang.String defaultValue)
Reads string element from the annotation.
|
protected java.lang.String |
readStringElement(A annotation,
java.lang.String name)
Reads non-empty, trimmed, annotation element value.
|
protected final java.lang.annotation.Annotation defaultAnnotation
protected final java.lang.Class<A extends java.lang.annotation.Annotation> annotationClass
protected AnnotationDataReader(java.lang.Class<A> annotationClass, java.lang.Class<? extends java.lang.annotation.Annotation> defaultAnnotationClass)
annotationClass
- annotation type to read fromdefaultAnnotationClass
- optional default annotation type, used to annotate the annotation class.public java.lang.Class<A> getAnnotationClass()
public boolean hasAnnotation(java.lang.reflect.AccessibleObject accessibleObject)
true
if annotation is present on
given accessible object.public D readAnnotationData(java.lang.reflect.AccessibleObject accessibleObject)
annotation data
on provided accessible object.
If annotation is not presented, null
is returned.public D readAnnotationData(java.lang.Class<?> type)
annotation data
on provided type.
If annotation is not presented, null
is returned.protected abstract D createAnnotationData(A annotation)
protected java.lang.String readStringElement(A annotation, java.lang.String name)
null
.protected java.lang.Object readElement(A annotation, java.lang.String name)
null
.protected java.lang.String readString(A annotation, java.lang.String name, java.lang.String defaultValue)
protected boolean readBoolean(A annotation, java.lang.String name, boolean defaultValue)
protected int readInt(A annotation, java.lang.String name, int defaultValue)
Copyright © 2003-2013 Jodd Team