org.omnaest.utils.proxy
Class StubCreator<E>

java.lang.Object
  extended by org.omnaest.utils.proxy.StubCreator<E>

public class StubCreator<E>
extends Object

Helper to create stubs easily based on CGLIB.

There are several static creation methods but the StubCreator can be instantiated also. If instantiated it will cache a prototype of a generated stub for the given type and its interfaces and creates any new instance based on this prototype instance which is much more faster.

Author:
Omnaest

Constructor Summary
StubCreator(Class<? extends E> type)
           
StubCreator(Class<? extends E> type, Class<?>[] interfaces)
           
StubCreator(Class<? extends E> type, Class<?>[] interfaces, ExceptionHandler exceptionHandler)
           
StubCreator(Class<? extends E> type, ExceptionHandler exceptionHandler)
           
 
Method Summary
protected static net.sf.cglib.proxy.MethodInterceptor adapter(MethodInvocationHandler methodInvocationHandler)
          Returns a adapter which acts as MethodInterceptor for a given MethodInvocationHandler
 E build(MethodInvocationHandler methodInvocationHandler)
           
static
<E> E
newStubInstance(Class<? extends E> clazz, Class<?>[] interfaces, net.sf.cglib.proxy.MethodInterceptor methodInterceptor)
          Returns a new proxy stub for the given class or interface but takes additional interfaces.
static
<E> E
newStubInstance(Class<? extends E> clazz, Class<?>[] interfaces, net.sf.cglib.proxy.MethodInterceptor methodInterceptor, ExceptionHandler exceptionHandler)
          Returns a new proxy stub for the given class or interface but takes additional interfaces.
static
<E> E
newStubInstance(Class<? extends E> clazz, Class<?>[] interfaces, MethodInvocationHandler methodInvocationHandler)
          Same as newStubInstance(Class, Class[], MethodInterceptor) but uses a MethodInvocationHandler instead.
static
<E> E
newStubInstance(Class<? extends E> clazz, Class<?>[] interfaces, MethodInvocationHandler methodInvocationHandler, ExceptionHandler exceptionHandler)
          Same as newStubInstance(Class, Class[], MethodInterceptor) but uses a MethodInvocationHandler instead.
static
<E> E
newStubInstance(Class<? extends E> clazz, net.sf.cglib.proxy.MethodInterceptor methodInterceptor)
           
static
<E> E
newStubInstance(Class<? extends E> clazz, MethodInvocationHandler methodInvocationHandler)
          Returns a new proxy stub for the given class or interface.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StubCreator

public StubCreator(Class<? extends E> type)
Parameters:
type -
See Also:
StubCreator

StubCreator

public StubCreator(Class<? extends E> type,
                   ExceptionHandler exceptionHandler)
Parameters:
type -
exceptionHandler -
See Also:
StubCreator

StubCreator

public StubCreator(Class<? extends E> type,
                   Class<?>[] interfaces)
Parameters:
type -
interfaces -
See Also:
StubCreator

StubCreator

public StubCreator(Class<? extends E> type,
                   Class<?>[] interfaces,
                   ExceptionHandler exceptionHandler)
Parameters:
type -
interfaces -
exceptionHandler - ExceptionHandler
See Also:
StubCreator
Method Detail

build

public E build(MethodInvocationHandler methodInvocationHandler)
Parameters:
methodInvocationHandler -
Returns:
See Also:
newStubInstance(Class, Class[], MethodInvocationHandler)

newStubInstance

public static <E> E newStubInstance(Class<? extends E> clazz,
                                    MethodInvocationHandler methodInvocationHandler)
Returns a new proxy stub for the given class or interface.

Type Parameters:
E -
Parameters:
clazz -
methodInvocationHandler -
Returns:

newStubInstance

public static <E> E newStubInstance(Class<? extends E> clazz,
                                    net.sf.cglib.proxy.MethodInterceptor methodInterceptor)
Parameters:
clazz -
methodInterceptor -
Returns:

newStubInstance

public static <E> E newStubInstance(Class<? extends E> clazz,
                                    Class<?>[] interfaces,
                                    MethodInvocationHandler methodInvocationHandler)
Same as newStubInstance(Class, Class[], MethodInterceptor) but uses a MethodInvocationHandler instead.

Type Parameters:
E -
Parameters:
clazz -
interfaces -
methodInvocationHandler -
Returns:

newStubInstance

public static <E> E newStubInstance(Class<? extends E> clazz,
                                    Class<?>[] interfaces,
                                    MethodInvocationHandler methodInvocationHandler,
                                    ExceptionHandler exceptionHandler)
Same as newStubInstance(Class, Class[], MethodInterceptor) but uses a MethodInvocationHandler instead.

Type Parameters:
E -
Parameters:
clazz -
interfaces -
methodInvocationHandler -
exceptionHandler -
Returns:

adapter

protected static net.sf.cglib.proxy.MethodInterceptor adapter(MethodInvocationHandler methodInvocationHandler)
Returns a adapter which acts as MethodInterceptor for a given MethodInvocationHandler

Parameters:
methodInvocationHandler -
Returns:

newStubInstance

public static <E> E newStubInstance(Class<? extends E> clazz,
                                    Class<?>[] interfaces,
                                    net.sf.cglib.proxy.MethodInterceptor methodInterceptor)
Returns a new proxy stub for the given class or interface but takes additional interfaces.

Type Parameters:
E -
Parameters:
clazz -
interfaces -
methodInterceptor -
Returns:

newStubInstance

public static <E> E newStubInstance(Class<? extends E> clazz,
                                    Class<?>[] interfaces,
                                    net.sf.cglib.proxy.MethodInterceptor methodInterceptor,
                                    ExceptionHandler exceptionHandler)
Returns a new proxy stub for the given class or interface but takes additional interfaces.

Type Parameters:
E -
Parameters:
clazz -
interfaces -
methodInterceptor -
exceptionHandler -
Returns:


Copyright © 2013. All Rights Reserved.