Top Description Fields Constructors Methods
org.hibernate.annotations.common.annotationfactory

public final Class AnnotationProxy

extends Object
implements Annotation, InvocationHandler
Class Inheritance
All Implemented Interfaces
java.lang.reflect.InvocationHandler, java.lang.annotation.Annotation
Imports
java.lang.annotation.Annotation, java.lang.reflect.InvocationHandler, .Method, java.util.Collections, .Comparator, .HashMap, .Map, .SortedSet, .TreeSet

A concrete implementation of Annotation that pretends it is a "real" source code annotation. It's also an InvocationHandler.

When you create an AnnotationProxy, you must initialize it with an AnnotationDescriptor. The adapter checks that the provided elements are the same elements defined in the annotation interface. However, it does not check that their values are the right type. If you omit an element, the adapter will use the default value for that element from the annotation interface, if it exists. If no default exists, it will throw an exception.

Warning

this class does not implement hashCode() and equals() - it just uses the ones it inherits from Object. This means that an AnnotationProxy does not follow the recommendations of the Annotation javadoc about these two methods. That's why you should never mix AnnotationProxies with "real" annotations. For example, don't put them into the same Collection.

Authors
Paolo Perrotta, Davide Marchignoli
See Also
java.lang.annotation.Annotation

Field Summary

Modifier and TypeField and Description
private final Class<? extends Annotation>
private final Map<Method, Object>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Class<? extends Annotation>
annotationType()

Implements java.lang.annotation.Annotation.annotationType.

Returns the annotation interface of this annotation.
private static Map<Method, Object>
getAnnotationValues(Class<? extends Annotation> annotationType, AnnotationDescriptor descriptor)

private SortedSet<Method>
public Object
invoke(Object
the proxy instance that the method was invoked on
proxy
,
Method
the Method instance corresponding to the interface method invoked on the proxy instance. The declaring class of the Method object will be the interface that the method was declared in, which may be a superinterface of the proxy interface that the proxy class inherits the method through.
method
,
Object[]
an array of objects containing the values of the arguments passed in the method invocation on the proxy instance, or null if interface method takes no arguments. Arguments of primitive types are wrapped in instances of the appropriate primitive wrapper class, such as java.lang.Integer or java.lang.Boolean.
args
)

Implements java.lang.reflect.InvocationHandler.invoke.

Processes a method invocation on a proxy instance and returns the result.
pack-priv static <K, V> Map<K, V>
toSmallMap(Map<K, V> map)

public String
toString()

Overrides java.lang.Object.toString.

Implements java.lang.annotation.Annotation.toString.

Returns a string representation of this annotation.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

annotationTypeback to summary
private final Class<? extends Annotation> annotationType
valuesback to summary
private final Map<Method, Object> values

Constructor Detail

AnnotationProxyback to summary
public AnnotationProxy(AnnotationDescriptor descriptor)

Method Detail

annotationTypeback to summary
public Class<? extends Annotation> annotationType()

Implements java.lang.annotation.Annotation.annotationType.

Doc from java.lang.annotation.Annotation.annotationType.

Returns the annotation interface of this annotation.

Returns:Class<? extends Annotation>

the annotation interface of this annotation

getAnnotationValuesback to summary
private static Map<Method, Object> getAnnotationValues(Class<? extends Annotation> annotationType, AnnotationDescriptor descriptor)
getRegisteredMethodsInAlphabeticalOrderback to summary
private SortedSet<Method> getRegisteredMethodsInAlphabeticalOrder()
invokeback to summary
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable

Implements java.lang.reflect.InvocationHandler.invoke.

Doc from java.lang.reflect.InvocationHandler.invoke.

Processes a method invocation on a proxy instance and returns the result. This method will be invoked on an invocation handler when a method is invoked on a proxy instance that it is associated with.

Parameters
proxy:Object

the proxy instance that the method was invoked on

method:Method

the Method instance corresponding to the interface method invoked on the proxy instance. The declaring class of the Method object will be the interface that the method was declared in, which may be a superinterface of the proxy interface that the proxy class inherits the method through.

args:Object[]

an array of objects containing the values of the arguments passed in the method invocation on the proxy instance, or null if interface method takes no arguments. Arguments of primitive types are wrapped in instances of the appropriate primitive wrapper class, such as java.lang.Integer or java.lang.Boolean.

Returns:Object

the value to return from the method invocation on the proxy instance. If the declared return type of the interface method is a primitive type, then the value returned by this method must be an instance of the corresponding primitive wrapper class; otherwise, it must be a type assignable to the declared return type. If the value returned by this method is null and the interface method's return type is primitive, then a NullPointerException will be thrown by the method invocation on the proxy instance. If the value returned by this method is otherwise not compatible with the interface method's declared return type as described above, a ClassCastException will be thrown by the method invocation on the proxy instance.

Exceptions
Throwable:
the exception to throw from the method invocation on the proxy instance. The exception's type must be assignable either to any of the exception types declared in the throws clause of the interface method or to the unchecked exception types java.lang.RuntimeException or java.lang.Error. If a checked exception is thrown by this method that is not assignable to any of the exception types declared in the throws clause of the interface method, then an UndeclaredThrowableException containing the exception that was thrown by this method will be thrown by the method invocation on the proxy instance.
toSmallMapback to summary
pack-priv static <K, V> Map<K, V> toSmallMap(Map<K, V> map)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Implements java.lang.annotation.Annotation.toString.

Doc from java.lang.annotation.Annotation.toString.

Returns a string representation of this annotation. The details of the representation are implementation-dependent, but the following may be regarded as typical:

  @com.example.Name(first="Duke", middle="of", last="Java")
Returns:String

a string representation of this annotation