|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--org.codehaus.dimple.Implementor
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 = (Connection)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)
To create an Implementor class. |
|
| Method Summary | |
java.lang.reflect.InvocationHandler |
createInvocationHandler(java.lang.Object instance)
create an InvocationHandler object by calling instance if a method is implemented by the impl class. |
java.lang.reflect.InvocationHandler |
createInvocationHandler(java.lang.Object 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(java.lang.Object 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)
|
java.lang.Class |
getImplClass()
Get the impl class, which is the class whose public methods are used to implement target interface. |
int |
hashCode()
|
java.lang.Object |
implement(java.lang.Class asType,
java.lang.Object with)
create a dynamic proxy that implements asType by calling with if a method is implemented by the impl class. |
java.lang.Object |
implement(java.lang.Class asType,
java.lang.Object with,
java.lang.Object defaultDelegate)
create a dynamic proxy that implements asType by calling with if a method is implemented by the impl class. |
static java.lang.Class |
implementedBy(java.lang.Class asType,
java.lang.Class implClass)
To assert that all methods in implClass will properly implement some method in asType |
java.lang.Object |
implementWithDefaultHandler(java.lang.Class asType,
java.lang.Object 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. |
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 java.lang.Object |
newProxyInstance(java.lang.ClassLoader loader,
java.lang.Class 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,
java.lang.Object 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 java.lang.Object |
proxy(java.lang.Class asType,
java.lang.Object with)
Equivalent as new Implementor(with.getClass()).implement(asType) |
static java.lang.Object |
proxy(java.lang.Class asType,
java.lang.Object with,
java.lang.Object defaultDelegate)
Equivalent as new Implementor(with.getClass()).implement(asType, with, defaultDelegate) |
static java.lang.Object |
proxyWithDefaultHandler(java.lang.Class asType,
java.lang.Object with,
java.lang.reflect.InvocationHandler defaultHandler)
Equivalent as new Implementor(with.getClass()).implementWithDefaultHandler(itf, with, defaultHandler) |
java.lang.String |
toString()
|
static java.lang.Class |
willImplement(java.lang.Class implClass,
java.lang.Class asType)
To assert that all methods in implClass will properly implement some method in asType |
static java.lang.Class |
willImplement(java.lang.Class implClass,
java.lang.Class[] asTypes)
To assert that all methods in implClass will properly implement some method in any one of asTypes |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
public Implementor(java.lang.Class implClass)
implClass - the class used to implement.| Method Detail |
public static java.lang.Object proxyWithDefaultHandler(java.lang.Class asType,
java.lang.Object 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 java.lang.Object proxy(java.lang.Class asType,
java.lang.Object with,
java.lang.Object 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 java.lang.Object proxy(java.lang.Class asType,
java.lang.Object 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 java.lang.Object implement(java.lang.Class asType,
java.lang.Object with,
java.lang.Object 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 java.lang.Object implementWithDefaultHandler(java.lang.Class asType,
java.lang.Object 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 java.lang.Object implement(java.lang.Class asType,
java.lang.Object 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(java.lang.Object instance)
instance - the instance of the impl class.
public java.lang.reflect.InvocationHandler createInvocationHandlerWithDefaultHandler(java.lang.Object 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(java.lang.Object instance,
java.lang.Object defaultDelegate)
instance - the instance of the impl class.defaultDelegate - the default delegate. If null, UnsupportedOperationException is thrown.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 getImplClass()
public java.lang.reflect.Method lookupImplementingMethod(java.lang.reflect.Method implemented)
implemented - the method to be implemented.
public static java.lang.Object newProxyInstance(java.lang.ClassLoader loader,
java.lang.Class 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 static java.lang.Class implementedBy(java.lang.Class asType,
java.lang.Class implClass)
throws InvalidReturnTypeException,
UnusedMethodException
InvalidReturnTypeException - UnusedMethodException -
public static java.lang.Class willImplement(java.lang.Class implClass,
java.lang.Class asType)
throws InvalidReturnTypeException,
UnusedMethodException
InvalidReturnTypeException - UnusedMethodException -
public static java.lang.Class willImplement(java.lang.Class implClass,
java.lang.Class[] asTypes)
throws InvalidReturnTypeException,
UnusedMethodException
InvalidReturnTypeException - UnusedMethodException -
public final java.lang.Object override(java.lang.Object obj,
java.lang.Object overrider)
obj - the object to be overriden.overrider - the overrider.
public static final 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: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||