|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectnet.sf.cglib.Enhancer
public class Enhancer
Provides methods to create dynamic proxies of any class, not just interfaces.
This code enhances a Vector object for tracing, by intercepting all methods:
java.util.Vector vector = (java.util.Vector)Enhancer.enhance(
java.util.Vector.class, // extend Vector
new Class[]{ java.util.List.class }, // implement List
new MethodInterceptor() {
public Object intercept(Object obj, java.lang.reflect.Method method,
Object[] args, MethodProxy proxy) throws Throwable {
System.out.println(method);
return proxy.invokeSuper(obj, args); // invoke original method
}
});
Enhancer is comparable to the standard Dynamic Proxy feature built into Java, but with some important differences, including:
All enhanced objects implement the Factory interface.
MethodInterceptor,
Factory| Nested Class Summary | |
|---|---|
static class |
Enhancer.InternalReplace
Class containing the default implementation of the writeReplace method. |
| Method Summary | |
|---|---|
static java.lang.Object |
enhance(java.lang.Class cls,
java.lang.Class[] interfaces,
MethodInterceptor ih)
Helper method, has same effect as |
static java.lang.Object |
enhance(java.lang.Class cls,
java.lang.Class[] interfaces,
MethodInterceptor ih,
java.lang.ClassLoader loader)
Helper method, has same effect as |
static java.lang.Object |
enhance(java.lang.Class cls,
java.lang.Class[] interfaces,
MethodInterceptor ih,
java.lang.ClassLoader loader,
java.lang.reflect.Method wreplace)
Helper method, has same effect as |
static java.lang.Object |
enhance(java.lang.Class cls,
java.lang.Class[] interfaces,
MethodInterceptor ih,
java.lang.ClassLoader loader,
java.lang.reflect.Method wreplace,
MethodFilter filter)
Enhances a public non-final class. |
static Factory |
enhance(java.lang.Class cls,
MethodInterceptor ih)
Overrides non-abstract methods and implements all abstract methods. |
static java.lang.Class |
enhanceClass(java.lang.Class cls,
java.lang.Class[] interfaces,
java.lang.ClassLoader loader,
MethodFilter filter)
This method can be used to enhance a class that does not have a no-args constructor. |
static MethodInterceptor |
getMethodInterceptor(java.lang.Object enhanced)
Helper method to get the current interceptor for an enhanced object. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static MethodInterceptor getMethodInterceptor(java.lang.Object enhanced)
java.lang.ClassCastException - If the object is not an enhanced object (i.e. does not implement Factory).Factory.interceptor()
public static Factory enhance(java.lang.Class cls,
MethodInterceptor ih)
cls - Class or interface to extend or implementih - interceptor used to handle implemented methods
public static java.lang.Object enhance(java.lang.Class cls,
java.lang.Class[] interfaces,
MethodInterceptor ih)
return enhance(cls, interfaces, ih, null, null, null);
enhance(Class, Class[], MethodInterceptor, ClassLoader, Method, MethodFilter)
public static java.lang.Object enhance(java.lang.Class cls,
java.lang.Class[] interfaces,
MethodInterceptor ih,
java.lang.ClassLoader loader)
return enhance(cls, interfaces, ih, loader, null, null);
enhance(Class, Class[], MethodInterceptor, ClassLoader, Method, MethodFilter)
public static java.lang.Object enhance(java.lang.Class cls,
java.lang.Class[] interfaces,
MethodInterceptor ih,
java.lang.ClassLoader loader,
java.lang.reflect.Method wreplace)
return enhance(cls, interfaces, ih, loader, wreplace, null);
enhance(Class, Class[], MethodInterceptor, ClassLoader, Method, MethodFilter)
public static java.lang.Object enhance(java.lang.Class cls,
java.lang.Class[] interfaces,
MethodInterceptor ih,
java.lang.ClassLoader loader,
java.lang.reflect.Method wreplace,
MethodFilter filter)
cls - class to extend, uses Object.class if nullinterfaces - interfaces to implement, can be null or emptyih - interceptor used to handle implemented methodsloader - ClassLoader for enhanced class, uses "current" if nullwreplace - static method to implement writeReplace, must have
a single Object type parameter (to replace) and return type of Object.
If null, a default implementation is used.filter - a filter to prevent certain methods from being intercepted, may be null to intercept all possible methods
Enhancer.InternalReplace.writeReplace(Object),
Factory
public static java.lang.Class enhanceClass(java.lang.Class cls,
java.lang.Class[] interfaces,
java.lang.ClassLoader loader,
MethodFilter filter)
cls - class to extend, uses Object.class if nullinterfaces - interfaces to implement, can be null or emptyloader - ClassLoader for enhanced class, uses "current" if nullfilter - a filter to prevent certain methods from being intercepted, may be null to intercept all possible methods
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||