Class AnnotationProxy

java.lang.Object
org.eclipse.persistence.jaxb.javamodel.AnnotationProxy
All Implemented Interfaces:
InvocationHandler

public class AnnotationProxy extends Object implements InvocationHandler

Purpose:The purpose of this class is to act as a dynamic proxy that allows JDK Annotation method calls to be made on a non Annotation object.

Responsibilities:

  • Create and return a dynamic proxy instance based on an Annotation class and a Map of components (method name to value pairs)
  • Allow JDK Annotation method calls to be invoked on the proxy object

This class provides a means to invoke JDK Annotation method calls on a non Annotation instance.

See Also:
  • Method Details

    • getProxy

      public static <A extends Annotation> A getProxy(Map<String,Object> components, Class<A> annoClass, ClassLoader cl, org.eclipse.persistence.internal.helper.ConversionManager conversionMgr)
      This is the preferred way to obtain an instance of a dynamic proxy. The method takes a ClassLoader (which is used to load the target Annotation), a Class (which indicates the target Annotation, i.e. jakarta.xml.bind.annotation.XmlElement.class), and a Map of method name to value pairs, which represent the method names on the Annotation and the values that are to be returned from each method call. For example, if this proxy is to be used for an @XmlElement, the Map should contain the following keys:
      • defaultValue
      • name
      • namespace
      • nillable
      • required
      • type
      Following are example key/value pairs :
      • "defaultValue", "##default"
      • "name", "employee"
      • "namespace", "www.example.org"
      • "nillable", false
      • "required", false
      • "type", jakarta.xml.bind.annotation.XmlElement.DEFAULT.class
      Parameters:
      components - Map of method name/value pairs for this proxy instance
      annoClass - The interface for the proxy class to implement
      cl - The ClassLoader to define the proxy class
      conversionMgr - ConversionManager instance for converting to the correct return type in the invoke method
      Returns:
      A dynamic proxy instance based on a Java model JavaAnnotation
    • getComponents

      public Map<String,Object> getComponents()
      Return the Map of method name/value pairs for this proxy instance.
      Returns:
      Map of method name/value pairs for this proxy instance
    • invoke

      public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
      Invoke a given Method on this proxy. The component Map will be accessed using the given Method's name, and if an entry exists, the associated value is returned.
      Specified by:
      invoke in interface InvocationHandler
      Parameters:
      proxy - Satisfy the InvocationHandler interface - not used
      method - The Method instance corresponding to the interface method invoked on the proxy instance
      args - Satisfy the InvocationHandler interface - not used
      Returns:
      The value from the method invocation on the proxy instance
      Throws:
      Throwable