org.springframework.binding.support
Class ReflectionAnnotationTranslator
java.lang.Object
org.springframework.binding.support.ReflectionAnnotationTranslator
- All Implemented Interfaces:
- AnnotationTranslator
public class ReflectionAnnotationTranslator
- extends Object
- implements AnnotationTranslator
Uses reflection to translate annotations into property level user metadata.
This implementation will translate annotations in the following manner:
- The Annotation instance itself will be placed into a key in the form of
the '@' character followed by the annotation class name. For example:
import com.mypkg.SomeAnnotation;
...
@SomeAnnotation("This is a test")
public String getMyProperty()
...
Will store the "SomeAnnotation" instance in the key
@com.mypkg.SomeAnnotation
.
This allows 1.5 code easier access to annotation data.
- If the Annotation does not define any value or properties, then
Boolean.TRUE
will be stored against the fully qualified
classname of the Annotation as the key. For example:
import com.mypkg.MyAnnotation;
...
@MyAnnotation
public String getMyProperty()
...
Will store Boolean.TRUE
in the key
com.mypkg.MyAnnotation
.
- If the Annotation defines a single "value", then the annotation value
will be stored using the fully qualified classname of the Annotation as the
key and single value of the annotation as the key's value. For example:
import com.mypkg.SomeAnnotation;
...
@SomeAnnotation("Hello, World!")
public String getMyProperty()
...
Will store the value "Hello, World!"
in the key
com.mypkg.SomeAnnotation
.
- If the Annotation has multiple values, then
Boolean.TRUE
will be stored against the fully qualified annotation class name and each
value will be stored using the fully qualified classname of the Annotation
with a "." and the property name of the annotation as the key value. For
example:
import com.mypkg.OtherAnnotation;
...
@OtherAnnotation(aprop1="Something", aprop2=100)
public String getMyProperty()
...
Will create three key + value pairs:
Key | | Value |
com.mypkg.OtherAnnotation | = | Boolean.TRUE |
com.mypkg.OtherAnnotation.aprop1 | = | "Something" |
com.mypkg.OtherAnnotation.aprop2 | = | 100 |
- Since:
- May 8, 2006 4:08:53 PM
- Author:
- andy
Method Summary |
void |
translate(Annotation annotation,
Map<String,Object> result)
Translates annotation into its constituent (or
equivalent) key + value pairs and places the resulting pairs into
the result map. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SINGLE_VALUE_METHOD_NAME
public static final String SINGLE_VALUE_METHOD_NAME
- See Also:
- Constant Field Values
ReflectionAnnotationTranslator
public ReflectionAnnotationTranslator()
translate
public void translate(Annotation annotation,
Map<String,Object> result)
- Description copied from interface:
AnnotationTranslator
- Translates
annotation
into its constituent (or
equivalent) key + value pairs and places the resulting pairs into
the result
map.
- Specified by:
translate
in interface AnnotationTranslator
- Parameters:
annotation
- the annotation to be translatedresult
- container to hold the result of this translation
Copyright © 2004-2009 The Spring Framework. All Rights Reserved.