sun.reflect.annotation
Class AnnotationInvocationHandler

java.lang.Object
  extended by sun.reflect.annotation.AnnotationInvocationHandler
All Implemented Interfaces:
Serializable, InvocationHandler

public final class AnnotationInvocationHandler
extends Object
implements InvocationHandler, Serializable

This class exists for serialization compatibility with the JDK. VMs can choose to implement annotations by constructing proxies with this invocation handler, but that is not required. If a different strategy for proxy objects is chosen, they can have a writeReplace method to substitute a Proxy based on this invocation handler is used for serialization.

See Also:
Serialized Form

Constructor Summary
AnnotationInvocationHandler(Class type, Map memberValues)
          Construct a new invocation handler for an annotation proxy.
 
Method Summary
static Annotation create(Class type, Map memberValues)
           
static boolean equals(Class type, Map memberValues, Object other)
          Compare an instance of AnnotationInvocationHandler with another object.
static int hashCode(Class type, Map memberValues)
          Compute the hashCode for an annotation.
 Object invoke(Object proxy, Method method, Object[] args)
          When a method is invoked on a proxy instance, it is wrapped and this method is called instead, so that you may decide at runtime how the original method should behave.
static String toString(Class type, Map memberValues)
          This method is public for use by other parts of the VM.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AnnotationInvocationHandler

public AnnotationInvocationHandler(Class type,
                                   Map memberValues)
Construct a new invocation handler for an annotation proxy. Note that the VM is responsible for filling the memberValues map with the default values of all the annotation members.

Method Detail

create

public static Annotation create(Class type,
                                Map memberValues)

equals

public static boolean equals(Class type,
                             Map memberValues,
                             Object other)
Compare an instance of AnnotationInvocationHandler with another object. Note that the other object does not have to be an AnnotationInvocationHandler, any implementation of the annotation interface is allowed to be compared for equality. Note that this makes the equals method asymmetric, but this behavior is specified by Annotation.equals and identical to the JDK. This method is public for use by other parts of the VM. Some VMs (can) use different representations of annotations that reuse this method.


hashCode

public static int hashCode(Class type,
                           Map memberValues)
Compute the hashCode for an annotation. Note that the algorithm is specified by Annotation.hashCode. This method is public for use by other parts of the VM. Some VMs (can) use different representations of annotations that reuse this method.


toString

public static String toString(Class type,
                              Map memberValues)
This method is public for use by other parts of the VM. Some VMs (can) use different representations of annotations that reuse this method.


invoke

public Object invoke(Object proxy,
                     Method method,
                     Object[] args)
              throws Throwable
Description copied from interface: InvocationHandler
When a method is invoked on a proxy instance, it is wrapped and this method is called instead, so that you may decide at runtime how the original method should behave.

Specified by:
invoke in interface InvocationHandler
Parameters:
proxy - the instance that the wrapped method should be invoked on. When this method is called by a Proxy object, `proxy' will be an instance of Proxy, and oddly enough, Proxy.getInvocationHandler(proxy) will return this!
method - the reflected method to invoke on the proxy. When this method is called by a Proxy object, 'method' will be the reflection object owned by the declaring class or interface, which may be a supertype of the interfaces the proxy directly implements.
args - the arguments passed to the original method, or null if the method takes no arguments. (But also be prepared to handle a 0-length array). Arguments of primitive type, such as boolean or int, are wrapped in the appropriate class such as Boolean or Integer.
Returns:
whatever is necessary to return from the wrapped method. If the wrapped method is void, the proxy instance will ignore it. If the wrapped method returns a primitive, this must be the correct wrapper type whose value is exactly assignable to the appropriate type (no widening will be performed); a null object in this case causes a NullPointerException. In all remaining cases, if the returned object is not assignment compatible to the declared type of the original method, the proxy instance will generate a ClassCastException.
Throws:
Throwable - this interface is listed as throwing anything, but the implementation should only throw unchecked exceptions and exceptions listed in the throws clause of all methods being overridden by the proxy instance. If something is thrown that is not compatible with the throws clause of all overridden methods, the proxy instance will wrap the exception in an UndeclaredThrowableException. Note that an exception listed in the throws clause of the `method' parameter might not be declared in additional interfaces also implemented by the proxy object.
See Also:
Proxy, UndeclaredThrowableException