|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.codehaus.dimple.Implementor<ImplClass>
public class Implementor<ImplClass>
This class is used to create implementation of interface(s) dynamically.
This class is ideal for creating stub or interceptor for interfaces where only a few methods are of interest while most other methods are either ignored or delegated.
For example:
Connection realConn = ...;
Connection nonCloseableConnection = Implementor.proxy(Connection.class, new Object(){
public void close() {
//we intercept close() call and do nothing.
}
}, realConn);
nonCloseableConnection.close();// no-op. realConn is not closed.
| Constructor Summary | |
|---|---|
Implementor(java.lang.Class<ImplClass> implClass)
To create an Implementor class. |
|
| Method Summary | ||
|---|---|---|
void |
checkImplementingMethods(java.lang.Class<?>... asTypes)
Makes sure that methods defined by ImplClass implement some method in any Class object in asTypes. |
|
void |
checkImplementingMethods(java.lang.Class<?> asType)
Makes sure that methods defined by ImplClass implement some method in asType. |
|
java.lang.reflect.InvocationHandler |
createInvocationHandler(ImplClass instance)
create an InvocationHandler object by calling instance if a method is implemented by the impl class. |
|
java.lang.reflect.InvocationHandler |
createInvocationHandler(ImplClass instance,
java.lang.Object defaultDelegate)
create an InvocationHandler object by calling instance if a method is implemented by the impl class. |
|
java.lang.reflect.InvocationHandler |
createInvocationHandlerWithDefaultHandler(ImplClass instance,
java.lang.reflect.InvocationHandler defaultHandler)
create an InvocationHandler object by calling instance if a method is implemented by the impl class. |
|
boolean |
equals(java.lang.Object obj)
|
|
|
generateInterceptor(java.lang.Class<T> interceptedType)
Generate byte code to create an interceptor that will intercept objects of interceptedType with objects of implClass. |
|
static
|
generateInterceptor(java.lang.Class<T> interceptedType,
java.lang.Class<Impl> implClass)
Generate byte code to create an interceptor that will intercept objects of interceptedType with objects of Impl. |
|
java.lang.Class<ImplClass> |
getImplClass()
Get the impl class, which is the class whose public methods are used to implement target interface. |
|
int |
hashCode()
|
|
|
implement(java.lang.Class<T> asType,
ImplClass with)
create a dynamic proxy that implements asType by calling with if a method is implemented by the impl class. |
|
|
implement(java.lang.Class<T> asType,
ImplClass with,
T defaultDelegate)
create a dynamic proxy that implements asType by calling with if a method is implemented by the impl class. |
|
static
|
implementedBy(java.lang.Class<T> asType,
java.lang.Class<?> implClass)
To assert that all methods in implClass will properly implement some method in asType |
|
|
implementWithDefaultHandler(java.lang.Class<T> asType,
ImplClass with,
java.lang.reflect.InvocationHandler defaultHandler)
create a dynamic proxy that implements asType by calling with if a method is implemented by the impl class. |
|
static
|
instance(java.lang.Class<ImplClass> implClass)
Convenience method to create an Implementor object. |
|
static
|
intercept(java.lang.Class<T> interceptedType,
T intercepted,
java.lang.Object with)
Convenience method to intercept an instance of an interface. |
|
java.lang.reflect.Method |
lookupImplementingMethod(java.lang.reflect.Method implemented)
To find a method in the impl class that can be used in place of the implemented method. |
|
static
|
newProxyInstance(java.lang.ClassLoader loader,
java.lang.Class<T> asType,
java.lang.reflect.InvocationHandler handler)
To create a proxy instance for a given interface or superclass. |
|
java.lang.Object |
override(java.lang.Object obj,
ImplClass overrider)
Overrides an object using methods defined in impl class and the overrider object bound to "this". |
|
static java.lang.Object |
overrideObject(java.lang.Object obj,
java.lang.Object overrider)
Overrides an object using the overrider object. |
|
static
|
proxy(java.lang.Class<T> asType,
ImplClass with)
Equivalent as new Implementor(with.getClass()).implement(asType) |
|
static
|
proxy(java.lang.Class<T> asType,
ImplClass with,
T defaultDelegate)
Equivalent as new Implementor(with.getClass()).implement(asType, with, defaultDelegate) |
|
static
|
proxyWithDefaultHandler(java.lang.Class<T> asType,
ImplClass with,
java.lang.reflect.InvocationHandler defaultHandler)
Equivalent as new Implementor(with.getClass()).implementWithDefaultHandler(itf, with, defaultHandler) |
|
static
|
stub(java.lang.Class<T> stubbedType,
java.lang.Object with)
Convenience method to stub an interface. |
|
java.lang.String |
toString()
|
|
static
|
willImplement(java.lang.Class<ImplClass> implClass,
java.lang.Class<?>... asTypes)
To assert that all methods in implClass will properly implement some method in any one of asTypes |
|
static
|
willImplement(java.lang.Class<ImplClass> implClass,
java.lang.Class<?> asType)
To assert that all methods in implClass will properly implement some method in asType |
|
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Implementor(java.lang.Class<ImplClass> implClass)
implClass - the class used to implement.| Method Detail |
|---|
public static <T,ImplClass> T proxyWithDefaultHandler(java.lang.Class<T> asType,
ImplClass with,
java.lang.reflect.InvocationHandler defaultHandler)
This method is a convenience shortcut. As the constructor of Implementor may be expensive, it is recommended to create an Implementor object once and then use it repeatedly.
public static <T,ImplClass> T proxy(java.lang.Class<T> asType,
ImplClass with,
T defaultDelegate)
This method is a convenience shortcut. As the constructor of Implementor may be expensive, it is recommended to create an Implementor object once and then use it repeatedly.
public static <T,ImplClass> T proxy(java.lang.Class<T> asType,
ImplClass with)
This method is a convenience shortcut. As the constructor of Implementor may be expensive, it is recommended to create an Implementor object once and then use it repeatedly.
public <T> T implement(java.lang.Class<T> asType,
ImplClass with,
T defaultDelegate)
asType - the interface to implement or super class to override (cglib is required in this case).with - the instance of the impl class.defaultDelegate - the default delegate.
public <T> T implementWithDefaultHandler(java.lang.Class<T> asType,
ImplClass with,
java.lang.reflect.InvocationHandler defaultHandler)
asType - the interface to implement or super class to override (cglib is required in this case).with - the instance of the impl class.defaultHandler - the default InvocationHandler.
public <T> T implement(java.lang.Class<T> asType,
ImplClass with)
asType - the interface to implement or super class to override (cglib is required in this case).with - the instance of the impl class.
public java.lang.reflect.InvocationHandler createInvocationHandler(ImplClass instance)
instance - the instance of the impl class.
public java.lang.reflect.InvocationHandler createInvocationHandlerWithDefaultHandler(ImplClass instance,
java.lang.reflect.InvocationHandler defaultHandler)
instance - the instance of the impl class.defaultHandler - the InvocationHandler object to provide default behavior.
If null, UnsupportedOperationException is thrown.
public java.lang.reflect.InvocationHandler createInvocationHandler(ImplClass instance,
java.lang.Object defaultDelegate)
instance - the instance of the impl class.defaultDelegate - the default delegate. If null, UnsupportedOperationException is thrown.
public static <ImplClass> Implementor<ImplClass> instance(java.lang.Class<ImplClass> implClass)
ImplClass - the impl class.implClass - the iml class object.
public boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.Class<ImplClass> getImplClass()
public <T> Interceptor<T,ImplClass> generateInterceptor(java.lang.Class<T> interceptedType)
interceptedType with objects of implClass.
asm and cglib jar files have to be in classpath to use this method.
T - the type of object to be intercepted.interceptedType - the intercepted type.
public static <T,Impl> Interceptor<T,Impl> generateInterceptor(java.lang.Class<T> interceptedType,
java.lang.Class<Impl> implClass)
interceptedType with objects of Impl.
asm and cglib jar files have to be in classpath to use this method.
T - the type of objects to be intercepted.Impl - the type of objects used to intercept.interceptedType - the intercepted type.implClass - the type used to intercept.
public static <T> T intercept(java.lang.Class<T> interceptedType,
T intercepted,
java.lang.Object with)
generateInterceptor(interceptedType, with.getClass()).intercept(intercepted, with);
asm and cglib jar files have to be in classpath to use this method.
T - the interface type to be intercepted.interceptedType - the intercepted type.intercepted - the object to be intercepted.with - the object used to intercept.
public static <T> T stub(java.lang.Class<T> stubbedType,
java.lang.Object with)
generateInterceptor(interceptedType, with.getClass()).stub(with);
asm and cglib jar files have to be in classpath to use this method.
T - the interface type to be stubbed.stubbedType - the type to be stubbed.with - the object used to stub.
public java.lang.reflect.Method lookupImplementingMethod(java.lang.reflect.Method implemented)
implemented - the method to be implemented.
public static <T> T newProxyInstance(java.lang.ClassLoader loader,
java.lang.Class<T> asType,
java.lang.reflect.InvocationHandler handler)
loader - the class loader.asType - the interface or super class (cglib is required in this case).handler - the InvocationHandler to handle calls.
public void checkImplementingMethods(java.lang.Class<?> asType)
throws InvalidReturnTypeException,
UnusedMethodException
asType - the interface to implement.
InvalidReturnTypeException
UnusedMethodException
public void checkImplementingMethods(java.lang.Class<?>... asTypes)
throws InvalidReturnTypeException,
UnusedMethodException
asTypes - the interfaces to implement.
InvalidReturnTypeException
UnusedMethodException
public static <T> java.lang.Class<T> implementedBy(java.lang.Class<T> asType,
java.lang.Class<?> implClass)
throws InvalidReturnTypeException,
UnusedMethodException
InvalidReturnTypeException
UnusedMethodException
public static <ImplClass> java.lang.Class<ImplClass> willImplement(java.lang.Class<ImplClass> implClass,
java.lang.Class<?> asType)
throws InvalidReturnTypeException,
UnusedMethodException
InvalidReturnTypeException
UnusedMethodException
public static <ImplClass> java.lang.Class<ImplClass> willImplement(java.lang.Class<ImplClass> implClass,
java.lang.Class<?>... asTypes)
throws InvalidReturnTypeException,
UnusedMethodException
InvalidReturnTypeException
UnusedMethodException
public final java.lang.Object override(java.lang.Object obj,
ImplClass overrider)
obj - the object to be overriden.overrider - the overrider.
public static java.lang.Object overrideObject(java.lang.Object obj,
java.lang.Object overrider)
obj - the object to be overriden.overrider - the overrider.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||