Class AnnotationHandler

java.lang.Object
org.simpleframework.xml.core.AnnotationHandler
All Implemented Interfaces:
InvocationHandler

class AnnotationHandler extends Object implements InvocationHandler
The AnnotationHandler object is used to handle all invocation made on a synthetic annotation. This is required so that annotations can be created without an implementation. The java.lang.reflect.Proxy object is used to wrap this invocation handler with the annotation interface.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final boolean
    This determines if a map should have a key attribute.
    private static final String
    This is used to determine if a key should be an attribute.
    private static final String
    This is the method used to acquire the associated type.
    private final Comparer
    This is used to perform a comparison of the annotations.
    private static final String
    This is used to perform a comparison of the annotations.
    private final boolean
    This is used to determine if the annotation is required.
    private static final String
    This is used to determine if annotations are optional.
    private static final String
    This is used to acquire a string value for the annotation.
    private final Class
    This is annotation type associated with this handler.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor for the AnnotationHandler object.
    AnnotationHandler(Class type, boolean required)
    Constructor for the AnnotationHandler object.
    AnnotationHandler(Class type, boolean required, boolean attribute)
    Constructor for the AnnotationHandler object.
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    This is used to build a string from the annotation.
    private boolean
    equals(Object proxy, Object[] list)
    This is used to determine if two annotations are equals based on the attributes of the annotation.
    invoke(Object proxy, Method method, Object[] list)
    This is used to handle all invocations on the wrapped annotation.
    private void
    This is used to build a string from the annotation.
    This is used to build a string from the annotation.
    private Object
    value(Method method)
    This is used to extract the default value used for the provided annotation attribute.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • CLASS

      private static final String CLASS
      This is the method used to acquire the associated type.
      See Also:
    • STRING

      private static final String STRING
      This is used to acquire a string value for the annotation.
      See Also:
    • REQUIRED

      private static final String REQUIRED
      This is used to determine if annotations are optional.
      See Also:
    • ATTRIBUTE

      private static final String ATTRIBUTE
      This is used to determine if a key should be an attribute.
      See Also:
    • EQUAL

      private static final String EQUAL
      This is used to perform a comparison of the annotations.
      See Also:
    • comparer

      private final Comparer comparer
      This is used to perform a comparison of the annotations.
    • type

      private final 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 Details

    • AnnotationHandler

      public AnnotationHandler(Class type)
      Constructor for the AnnotationHandler 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(Class type, boolean required)
      Constructor for the AnnotationHandler 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 wrapping
      required - this is used to determine if its required
    • AnnotationHandler

      public AnnotationHandler(Class type, boolean required, boolean attribute)
      Constructor for the AnnotationHandler 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 wrapping
      required - this is used to determine if its required
      attribute - determines if map keys are attributes
  • Method Details

    • invoke

      public Object invoke(Object proxy, Method method, Object[] list) throws 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 an equals or toString then this will be handled by an internal implementation.
      Specified by:
      invoke in interface InvocationHandler
      Parameters:
      proxy - this is the proxy object the invocation was made on
      method - this is the method that was invoked on the proxy
      list - this is the list of parameters to be used
      Returns:
      this is used to return the result of the invocation
      Throws:
      Throwable
    • equals

      private boolean equals(Object proxy, Object[] list) throws 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 on
      list - this is the parameters provided to the invocation
      Returns:
      this returns true if the annotations are equals
      Throws:
      Throwable
    • toString

      public 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 class Object
      Returns:
      returns a string representation of the annotation
    • name

      private void name(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(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 Object value(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