Package org.simpleframework.xml.core
Class AnnotationHandler
- java.lang.Object
-
- org.simpleframework.xml.core.AnnotationHandler
-
- All Implemented Interfaces:
java.lang.reflect.InvocationHandler
class AnnotationHandler extends java.lang.Object implements java.lang.reflect.InvocationHandler
TheAnnotationHandler
object is used to handle all invocation made on a synthetic annotation. This is required so that annotations can be created without an implementation. Thejava.lang.reflect.Proxy
object is used to wrap this invocation handler with the annotation interface.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
attribute
This determines if a map should have a key attribute.private static java.lang.String
ATTRIBUTE
This is used to determine if a key should be an attribute.private static java.lang.String
CLASS
This is the method used to acquire the associated type.private Comparer
comparer
This is used to perform a comparison of the annotations.private static java.lang.String
EQUAL
This is used to perform a comparison of the annotations.private boolean
required
This is used to determine if the annotation is required.private static java.lang.String
REQUIRED
This is used to determine if annotations are optional.private static java.lang.String
STRING
This is used to acquire a string value for the annotation.private java.lang.Class
type
This is annotation type associated with this handler.
-
Constructor Summary
Constructors Constructor Description AnnotationHandler(java.lang.Class type)
Constructor for theAnnotationHandler
object.AnnotationHandler(java.lang.Class type, boolean required)
Constructor for theAnnotationHandler
object.AnnotationHandler(java.lang.Class type, boolean required, boolean attribute)
Constructor for theAnnotationHandler
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
attributes(java.lang.StringBuilder builder)
This is used to build a string from the annotation.private boolean
equals(java.lang.Object proxy, java.lang.Object[] list)
This is used to determine if two annotations are equals based on the attributes of the annotation.java.lang.Object
invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] list)
This is used to handle all invocations on the wrapped annotation.private void
name(java.lang.StringBuilder builder)
This is used to build a string from the annotation.java.lang.String
toString()
This is used to build a string from the annotation.private java.lang.Object
value(java.lang.reflect.Method method)
This is used to extract the default value used for the provided annotation attribute.
-
-
-
Field Detail
-
CLASS
private static final java.lang.String CLASS
This is the method used to acquire the associated type.- See Also:
- Constant Field Values
-
STRING
private static final java.lang.String STRING
This is used to acquire a string value for the annotation.- See Also:
- Constant Field Values
-
REQUIRED
private static final java.lang.String REQUIRED
This is used to determine if annotations are optional.- See Also:
- Constant Field Values
-
ATTRIBUTE
private static final java.lang.String ATTRIBUTE
This is used to determine if a key should be an attribute.- See Also:
- Constant Field Values
-
EQUAL
private static final java.lang.String EQUAL
This is used to perform a comparison of the annotations.- See Also:
- Constant Field Values
-
comparer
private final Comparer comparer
This is used to perform a comparison of the annotations.
-
type
private final java.lang.Class type
This is annotation type associated with this handler.
-
attribute
private final boolean attribute
This determines if a map should have a key attribute.
-
required
private final boolean required
This is used to determine if the annotation is required.
-
-
Constructor Detail
-
AnnotationHandler
public AnnotationHandler(java.lang.Class type)
Constructor for theAnnotationHandler
object. This is used to create a handler for invocations on a synthetic annotation. The annotation type wrapped must be provided. By default the requirement of the annotations is true.- Parameters:
type
- this is the annotation type that this is wrapping
-
AnnotationHandler
public AnnotationHandler(java.lang.Class type, boolean required)
Constructor for theAnnotationHandler
object. This is used to create a handler for invocations on a synthetic annotation. The annotation type wrapped must be provided.- Parameters:
type
- this is the annotation type that this is wrappingrequired
- this is used to determine if its required
-
AnnotationHandler
public AnnotationHandler(java.lang.Class type, boolean required, boolean attribute)
Constructor for theAnnotationHandler
object. This is used to create a handler for invocations on a synthetic annotation. The annotation type wrapped must be provided.- Parameters:
type
- this is the annotation type that this is wrappingrequired
- this is used to determine if its requiredattribute
- determines if map keys are attributes
-
-
Method Detail
-
invoke
public java.lang.Object invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] list) throws java.lang.Throwable
This is used to handle all invocations on the wrapped annotation. Typically the response to an invocation will result in the default value of the annotation attribute being returned. If the method is anequals
ortoString
then this will be handled by an internal implementation.- Specified by:
invoke
in interfacejava.lang.reflect.InvocationHandler
- Parameters:
proxy
- this is the proxy object the invocation was made onmethod
- this is the method that was invoked on the proxylist
- this is the list of parameters to be used- Returns:
- this is used to return the result of the invocation
- Throws:
java.lang.Throwable
-
equals
private boolean equals(java.lang.Object proxy, java.lang.Object[] list) throws java.lang.Throwable
This is used to determine if two annotations are equals based on the attributes of the annotation. The comparison done can ignore specific attributes, for instance the name attribute.- Parameters:
proxy
- this is the annotation the invocation was made onlist
- this is the parameters provided to the invocation- Returns:
- this returns true if the annotations are equals
- Throws:
java.lang.Throwable
-
toString
public java.lang.String toString()
This is used to build a string from the annotation. The string produces adheres to the typical string representation of a normal annotation. This ensures that an exceptions that are thrown with a string representation of the annotation are identical to those thrown with a normal annotation.- Overrides:
toString
in classjava.lang.Object
- Returns:
- returns a string representation of the annotation
-
name
private void name(java.lang.StringBuilder builder)
This is used to build a string from the annotation. The string produces adheres to the typical string representation of a normal annotation. This ensures that an exceptions that are thrown with a string representation of the annotation are identical to those thrown with a normal annotation.- Parameters:
builder
- this is the builder used to compose the text
-
attributes
private void attributes(java.lang.StringBuilder builder)
This is used to build a string from the annotation. The string produces adheres to the typical string representation of a normal annotation. This ensures that an exceptions that are thrown with a string representation of the annotation are identical to those thrown with a normal annotation.- Parameters:
builder
- this is the builder used to compose the text
-
value
private java.lang.Object value(java.lang.reflect.Method method)
This is used to extract the default value used for the provided annotation attribute. This will return the default value for all attributes except that it makes the requirement optional. Making the requirement optional provides better functionality.- Parameters:
method
- this is the annotation representing the attribute- Returns:
- this returns the default value for the attribute
-
-