Top Fields Constructors Methods
jnr.ffi.util

public final Class AnnotationProxy<A extends Annotation>

extends Object
implements Annotation, InvocationHandler
Class Inheritance
All Implemented Interfaces
java.lang.reflect.InvocationHandler, java.lang.annotation.Annotation
Type Parameters
<A>
The annotation type has to be proxed.
Imports
java.lang.annotation.Annotation, java.lang.reflect.AccessibleObject, .InvocationHandler, .InvocationTargetException, .Method, .Proxy, java.security.AccessController, .PrivilegedAction, java.util.LinkedHashMap, .Map, .Map.Entry

Version
$Id$

Field Summary

Modifier and TypeField and Description
private final Class<A>
annotationType

The annotation type class has to be proxed.

private static final int
MEMBER_NAME_MULTIPLICATOR

The multiplicator required in the hash code calculation.

private final Map<String, AnnotationProperty>
properties

The annotation properties registry.

private final A
proxedAnnotation

The proxed annotation.

Constructor Summary

AccessConstructor and Description
private
AnnotationProxy(Class<A>
the annotation type class has to be proxed.
annotationType
)

Build a new proxy annotation given the annotation type.

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.
public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Implements java.lang.annotation.Annotation.equals.

Returns true if the specified object represents an annotation that is logically equivalent to this one.
private static AnnotationProxy<?>

Returns:

the annotation proxy, if any, given the annotation.
getAnnotationProxy
(Object
the annotation.
obj
)

Retrieves the annotation proxy, if any, given the annotation.

private static <
the annotation type.
A extends Annotation
>
Method[]

Returns:

the declared methods of an annotation, given the type.
getDeclaredMethods
(final Class<A>
the annotation type class.
annotationType
)

Access to the declared methods of an annotation, given the type.

public Object

Returns:

the property value, given the name, if present.
getProperty
(String
the property name.
name
)

Returns the property value, given the name, if present.

public A

Returns:

the proxed annotation.
getProxedAnnotation
()

Returns the proxed annotation.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Implements java.lang.annotation.Annotation.hashCode.

Returns the hash code of this annotation.
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.
public static <
the annotation type has to be proxed.
A extends Annotation
>
AnnotationProxy<A>

Returns:

a new annotation proxy.
newProxy
(Class<A>
the annotation type class has to be proxed.
annotationType
)

Creates a new annotation proxy.

public void
setProperty(String
the property name.
name
,
Object
the property value.
value
)

Set a property value.

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:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

annotationTypeback to summary
private final Class<A> annotationType

The annotation type class has to be proxed.

MEMBER_NAME_MULTIPLICATORback to summary
private static final int MEMBER_NAME_MULTIPLICATOR

The multiplicator required in the hash code calculation.

propertiesback to summary
private final Map<String, AnnotationProperty> properties

The annotation properties registry.

proxedAnnotationback to summary
private final A proxedAnnotation

The proxed annotation.

Constructor Detail

AnnotationProxyback to summary
private AnnotationProxy(Class<A> annotationType)

Build a new proxy annotation given the annotation type.

Parameters
annotationType:Class<A>

the annotation type class has to be proxed.

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

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Implements java.lang.annotation.Annotation.equals.

Doc from java.lang.annotation.Annotation.equals.

Returns true if the specified object represents an annotation that is logically equivalent to this one. In other words, returns true if the specified object is an instance of the same annotation interface as this instance, all of whose members are equal to the corresponding member of this annotation, as defined below:

  • Two corresponding primitive typed members whose values are x and y are considered equal if x == y, unless their type is float or double.
  • Two corresponding float members whose values are x and y are considered equal if Float.valueOf(x).equals(Float.valueOf(y)). (Unlike the == operator, NaN is considered equal to itself, and 0.0f unequal to -0.0f.)
  • Two corresponding double members whose values are x and y are considered equal if Double.valueOf(x).equals(Double.valueOf(y)). (Unlike the == operator, NaN is considered equal to itself, and 0.0 unequal to -0.0.)
  • Two corresponding String, Class, enum, or annotation typed members whose values are x and y are considered equal if x.equals(y). (Note that this definition is recursive for annotation typed members.)
  • Two corresponding array typed members x and y are considered equal if Arrays.equals(x, y), for the appropriate overloading of Arrays.equals.
Parameters
obj:Object

Doc from java.lang.Object.equals.

the reference object with which to compare.

Returns:boolean

true if the specified object represents an annotation that is logically equivalent to this one, otherwise false

Annotations
@Override
getAnnotationProxyback to summary
private static AnnotationProxy<?> getAnnotationProxy(Object obj)

Retrieves the annotation proxy, if any, given the annotation.

Parameters
obj:Object

the annotation.

Returns:AnnotationProxy<?>

the annotation proxy, if any, given the annotation.

getDeclaredMethodsback to summary
private static <A extends Annotation> Method[] getDeclaredMethods(final Class<A> annotationType)

Access to the declared methods of an annotation, given the type.

Parameters
<A>
the annotation type.
annotationType:Class<A>

the annotation type class.

Returns:Method[]

the declared methods of an annotation, given the type.

getPropertyback to summary
public Object getProperty(String name)

Returns the property value, given the name, if present.

Parameters
name:String

the property name.

Returns:Object

the property value, given the name, if present.

getProxedAnnotationback to summary
public A getProxedAnnotation()

Returns the proxed annotation.

Returns:A

the proxed annotation.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Implements java.lang.annotation.Annotation.hashCode.

Doc from java.lang.annotation.Annotation.hashCode.

Returns the hash code of this annotation.

The hash code of an annotation is the sum of the hash codes of its members (including those with default values). The hash code of an annotation member is (127 times the hash code of the member-name as computed by String#hashCode()) XOR the hash code of the member-value. The hash code of a member-value depends on its type as defined below:

  • The hash code of a primitive value v is equal to WrapperType.valueOf(v).hashCode(), where WrapperType is the wrapper type corresponding to the primitive type of v (Byte, Character, Double, Float, Integer, Long, Short, or Boolean).
  • The hash code of a string, enum, class, or annotation member-value v is computed as by calling v.hashCode(). (In the case of annotation member values, this is a recursive definition.)
  • The hash code of an array member-value is computed by calling the appropriate overloading of Arrays.hashCode on the value. (There is one overloading for each primitive type, and one for object reference types.)
Returns:int

the hash code of this annotation

Annotations
@Override
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.
newProxyback to summary
public static <A extends Annotation> AnnotationProxy<A> newProxy(Class<A> annotationType)

Creates a new annotation proxy.

Parameters
<A>
the annotation type has to be proxed.
annotationType:Class<A>

the annotation type class has to be proxed.

Returns:AnnotationProxy<A>

a new annotation proxy.

setPropertyback to summary
public void setProperty(String name, Object value)

Set a property value.

Parameters
name:String

the property name.

value:Object

the property value.

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

Annotations
@Override