The original and most general callback type is the MethodInterceptor, which
in AOP terms enables "around advice"--that is, you can invoke custom code both before
and after the invocation of the "super" method. In addition you can modify the
arguments before calling the super method, or not call it at all.
Although MethodInterceptor is generic enough to meet any
interception need, it is often overkill. For simplicity and performance, additional
specialized callback types, such as LazyLoader are also available.
Often a single callback will be used per enhanced class, but you can control
which callback is used on a per-method basis with a CallbackFilter.
The most common uses of this class are embodied in the static helper methods. For
advanced needs, such as customizing the ClassLoader to use, you should create
a new instance of Enhancer. Other classes within CGLIB follow a similar pattern.
All enhanced objects implement the Factory interface, unless setUseFactory is
used to explicitly disable this feature. The Factory interface provides an API
to change the callbacks of an existing object, as well as a faster and easier way to create
new instances of the same type.
For an almost drop-in replacement for
java.lang.reflect.Proxy, see the Proxy class.
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | Enhancer.
The idea of the class is to cache relevant java.lang.reflect instances so
proxy-class can be instantiated faster that when using |
| private static record |
| Modifier and Type | Field and Description |
|---|---|
| private static final CallbackFilter | |
| private Object[] | |
| private Class | |
| private static final Signature | |
| private static final String | |
| private static final Type | |
| private static final Type | |
| private static final String | CALLBACK_FILTER_FIELD
|
| private Callback[] | |
| private Type[] | |
| private boolean | |
| private static final String | |
| private static final Signature | |
| private Enhancer. | |
| private Object | |
| private static final Type | |
| private static final String | |
| private CallbackFilter | |
| private static final Signature | |
| private static final Signature | |
| private static final Type | |
| private static final Type | |
| private boolean | |
| private Class | |
| private static final Signature | |
| private static final Signature | |
| private static final Type | |
| private Long | |
| private static final Signature | |
| private static final Signature | |
| private static final Signature | |
| private static final String | |
| private static final Signature | |
| private static final String | |
| private static final Signature | |
| private static final AbstractClassGenerator. | |
| private static final String | |
| private Class | |
| private static final String | |
| private static final Type | |
| private static final Signature | |
| private static final Signature | |
| private boolean | |
| private boolean |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public Object | Returns: a new instanceGenerate a new class if necessary and uses the specified callbacks (if any) to create a new object instance. |
| public Object | |
| public static Object | |
| public static Object | |
| public static Object | create(Class<T>
class to extend or interface to implement superclass, Class<T>[] array of interfaces to implement, or null interfaces, CallbackFilter the callback filter to use when generating a new class filter, Callback[] callback implementations to use for the enhanced object callbacks)Helper method to create an intercepted object. |
| public Class | |
| private Object | |
| private Object | Returns: newly created instanceclass to instantiate type)Instantiates a proxy instance and assigns callback values. |
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| protected void | filterConstructors(Class<T>
the superclass sc, List<E> the list of all declared constructors from the superclass constructors)Filter the list of constructors from the superclass. |
| protected Object | Returns: newly created proxy instanceclass to instantiate type)Implements abstract org. This method should not be called in regular flow. |
| protected Class | |
| public void | |
| private static String | |
| private int[] | |
| private static Method | |
| protected ClassLoader | |
| public static void | getMethods(Class<T>
the class that will be extended, or null superclass, Class<T>[] the list of interfaces that will be implemented, or null interfaces, List<E> the list into which to copy the applicable methods methods)Finds all of the methods that will be extended by an Enhancer-generated class using the specified superclass and interfaces. |
| private static void | |
| protected ProtectionDomain | getProtectionDomain()
Overrides org. Returns the protection domain to use when defining the class. |
| private Type | |
| public static boolean | Returns: whether the class was generated usingEnhancerany class type)Determine if a class was generated using |
| protected Object | nextInstance(Object instance)
Implements abstract org.
|
| private void | |
| public static void | registerCallbacks(Class<T>
a class previously created by generatedClass, Callback[] Enhancerthe array of callbacks to use when instances of the generated
class are created callbacks)Call this method to register the |
| public static void | registerStaticCallbacks(Class<T>
a class previously created by generatedClass, Callback[] Enhancerthe array of callbacks to use when instances of the generated
class are created callbacks)Similar to |
| private Signature | |
| public void | setCallback(final Callback
the callback to use for all methods callback)Set the single |
| public void | setCallbackFilter(CallbackFilter
the callback filter to use when generating a new class filter)Set the |
| public void | |
| private static void | |
| public void | setCallbackType(Class<T>
the type of callback to use for all methods callbackType)Set the single type of |
| public void | setCallbackTypes(Class<T>[]
the array of callback types callbackTypes)Set the array of callback types to use. |
| public void | setInterceptDuringConstruction(boolean
whether to intercept methods called from the constructor interceptDuringConstruction)Set whether methods called from within the proxy's constructer will be intercepted. |
| public void | setInterfaces(Class<T>[]
array of interfaces to implement, or null interfaces)Set the interfaces to implement. |
| public void | setSerialVersionUID(Long
the field value, or null to avoid generating field. sUID)Insert a static serialVersionUID field into the generated class. |
| public void | setSuperclass(Class<T>
class to extend or interface to implement superclass)Set the class which the generated class will extend. |
| private static void | |
| public void | setUseFactory(boolean
whether to implement useFactory)Factory; default is trueSet whether the enhanced object instances should implement
the |
| protected Object | |
| private void | |
| protected Object |