Holger's
Java API

com.antelmann.util
Class InterfaceWrapper

java.lang.Object
  extended by com.antelmann.util.InterfaceWrapper

public class InterfaceWrapper
extends Object

provides methods to generate special proxy objects that observe calls to specified interfaces

Since:
06/21/06
Author:
Holger Antelmann
See Also:
InterfaceMonitor, PerformanceMonitor, Proxy

Method Summary
static
<T> T
wrap(ClassLoader cl, Object object, T implementation, Class<T> type)
          the returned object additionally implements the Wrapped interface
static
<T> T
wrap(Object object, T implementation, Class<T> type)
           
static Object wrapObject(ClassLoader cl, Object object, InterfaceMonitor monitor, boolean wrapReturnValues, Class<?>... interfacesToObserve)
          returns an object that - apart from implementing the given interfaces - monitors each call to the object through the interfaces.
static Object wrapObject(ClassLoader cl, Object object, InterfaceMonitor monitor, Class<?>... interfacesToObserve)
           
static Object wrapObject(ClassLoader cl, Object object, InterfaceMonitor monitor, Filter<? super Method> wrapReturnValuesFilter, Class<?>... interfacesToObserve)
          returns an object that - apart from implementing the given interfaces - monitors each call to the object through the interfaces.
static Object wrapObject(Object obj, InterfaceMonitor mon, boolean wrapReturnValues, Class<?>... interfacesToObserve)
          uses the ClassLoader from the given object (first parameter)
static Object wrapObject(Object obj, InterfaceMonitor mon, Class<?>... interfacesToObserve)
          calls wrapObject(ClassLoader, Object, InterfaceMonitor, boolean, Class...) with false
static Object wrapObject(Object obj, InterfaceMonitor mon, Filter<? super Method> wrapReturnValuesFilter, Class<?>... interfacesToObserve)
          uses the ClassLoader from the given object (first parameter)
static
<T> T
wrapObject(T obj, InterfaceMonitor mon, boolean wrapReturnValues, Class<T> interfaceToObserve)
          convenience method
static
<T> T
wrapObject(T obj, InterfaceMonitor mon, Class<T> interfaceToObserve)
          convenience method
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

wrapObject

public static <T> T wrapObject(T obj,
                               InterfaceMonitor mon,
                               Class<T> interfaceToObserve)
convenience method


wrapObject

public static <T> T wrapObject(T obj,
                               InterfaceMonitor mon,
                               boolean wrapReturnValues,
                               Class<T> interfaceToObserve)
convenience method


wrapObject

public static Object wrapObject(Object obj,
                                InterfaceMonitor mon,
                                Class<?>... interfacesToObserve)
                         throws IllegalArgumentException
calls wrapObject(ClassLoader, Object, InterfaceMonitor, boolean, Class...) with false

Throws:
IllegalArgumentException

wrapObject

public static Object wrapObject(Object obj,
                                InterfaceMonitor mon,
                                boolean wrapReturnValues,
                                Class<?>... interfacesToObserve)
                         throws IllegalArgumentException
uses the ClassLoader from the given object (first parameter)

Throws:
IllegalArgumentException
See Also:
wrapObject(ClassLoader, Object, InterfaceMonitor, Class...)

wrapObject

public static Object wrapObject(Object obj,
                                InterfaceMonitor mon,
                                Filter<? super Method> wrapReturnValuesFilter,
                                Class<?>... interfacesToObserve)
                         throws IllegalArgumentException
uses the ClassLoader from the given object (first parameter)

Throws:
IllegalArgumentException
See Also:
wrapObject(ClassLoader, Object, InterfaceMonitor, Class...)

wrapObject

public static Object wrapObject(ClassLoader cl,
                                Object object,
                                InterfaceMonitor monitor,
                                Class<?>... interfacesToObserve)
                         throws IllegalArgumentException
Throws:
IllegalArgumentException
See Also:
wrapObject(ClassLoader, Object, InterfaceMonitor, boolean, Class...)

wrapObject

public static Object wrapObject(ClassLoader cl,
                                Object object,
                                InterfaceMonitor monitor,
                                boolean wrapReturnValues,
                                Class<?>... interfacesToObserve)
                         throws IllegalArgumentException
returns an object that - apart from implementing the given interfaces - monitors each call to the object through the interfaces. The given object must implement all interfaces that are to be observed. The return value can then savely be casted to one of the given interfaces.

Parameters:
wrapReturnValues - if true, return values of methods with an interface as a return type are also recursively wrapped
Returns:
a proxy object that monitors all calls to the given interface through the given monitor. The returned proxy can savely be casted to any of the given interfaces to be observed.
Throws:
IllegalArgumentException

wrapObject

public static Object wrapObject(ClassLoader cl,
                                Object object,
                                InterfaceMonitor monitor,
                                Filter<? super Method> wrapReturnValuesFilter,
                                Class<?>... interfacesToObserve)
                         throws IllegalArgumentException
returns an object that - apart from implementing the given interfaces - monitors each call to the object through the interfaces. The given object must implement all interfaces that are to be observed. The return value can then savely be casted to one of the given interfaces.

Parameters:
wrapReturnValuesFilter - determines whether return values of methods with an interface as a return type are also recursively wrapped
Returns:
a proxy object that monitors all calls to the given interface through the given monitor. The returned proxy can savely be casted to any of the given interfaces to be observed.
Throws:
IllegalArgumentException

wrap

public static <T> T wrap(Object object,
                         T implementation,
                         Class<T> type)
See Also:
wrap(ClassLoader, Object, Object, Class)

wrap

public static <T> T wrap(ClassLoader cl,
                         Object object,
                         T implementation,
                         Class<T> type)
              throws IllegalArgumentException
the returned object additionally implements the Wrapped interface

Throws:
IllegalArgumentException
See Also:
Misc.unwrap(Object, Class)


(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads