Class Enhancer
- java.lang.Object
-
- net.sf.cglib.core.AbstractClassGenerator
-
- net.sf.cglib.proxy.Enhancer
-
- All Implemented Interfaces:
ClassGenerator
public class Enhancer extends AbstractClassGenerator
Generates dynamic subclasses to enable method interception. This class started as a substitute for the standard Dynamic Proxy support included with JDK 1.3, but one that allowed the proxies to extend a concrete base class, in addition to implementing interfaces. The dynamically generated subclasses override the non-final methods of the superclass and have hooks which callback to user-defined interceptor implementations.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
MethodInterceptoris generic enough to meet any interception need, it is often overkill. For simplicity and performance, additional specialized callback types, such asLazyLoaderare 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 aCallbackFilter.The most common uses of this class are embodied in the static helper methods. For advanced needs, such as customizing the
ClassLoaderto use, you should create a new instance ofEnhancer. Other classes within CGLIB follow a similar pattern.All enhanced objects implement the
Factoryinterface, unlesssetUseFactory(boolean)is used to explicitly disable this feature. TheFactoryinterface 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 theProxyclass.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classEnhancer.EnhancerFactoryDataThe idea of the class is to cache relevant java.lang.reflect instances so proxy-class can be instantiated faster that when usingReflectUtils.newInstance(Class, Class[], Object[])andsetThreadCallbacks(Class, Callback[])static interfaceEnhancer.EnhancerKeyInternal interface, only public due to ClassLoader issues.-
Nested classes/interfaces inherited from class net.sf.cglib.core.AbstractClassGenerator
AbstractClassGenerator.ClassLoaderData, AbstractClassGenerator.Source
-
-
Field Summary
Fields Modifier and Type Field Description private static CallbackFilterALL_ZEROprivate java.lang.Object[]argumentsprivate java.lang.Class[]argumentTypesprivate static SignatureBIND_CALLBACKSprivate static java.lang.StringBOUND_FIELDprivate static org.objectweb.asm.TypeCALLBACKprivate static org.objectweb.asm.TypeCALLBACK_ARRAYprivate static java.lang.StringCALLBACK_FILTER_FIELDAbstractClassGenerator.ClassLoaderData.generatedClassesrequires to keep cache key in a good shape (the keys should be up and running if the proxy class is alive), and one of the cache keys isCallbackFilter.private Callback[]callbacksprivate org.objectweb.asm.Type[]callbackTypesprivate booleanclassOnlyprivate static java.lang.StringCONSTRUCTED_FIELDprivate static SignatureCSTRUCT_NULLprivate Enhancer.EnhancerFactoryDatacurrentDataprivate java.lang.ObjectcurrentKeyprivate static org.objectweb.asm.TypeFACTORYprivate static java.lang.StringFACTORY_DATA_FIELDprivate CallbackFilterfilterprivate static SignatureGET_CALLBACKprivate static SignatureGET_CALLBACKSprivate static org.objectweb.asm.TypeILLEGAL_ARGUMENT_EXCEPTIONprivate static org.objectweb.asm.TypeILLEGAL_STATE_EXCEPTIONprivate booleaninterceptDuringConstructionprivate java.lang.Class[]interfacesprivate static Enhancer.EnhancerKeyKEY_FACTORYprivate static SignatureMULTIARG_NEW_INSTANCEprivate static SignatureNEW_INSTANCEprivate static org.objectweb.asm.TypeOBJECT_TYPEprivate java.lang.LongserialVersionUIDprivate static SignatureSET_CALLBACKprivate static SignatureSET_CALLBACKSprivate static SignatureSET_STATIC_CALLBACKSprivate static java.lang.StringSET_STATIC_CALLBACKS_NAMEprivate static SignatureSET_THREAD_CALLBACKSprivate static java.lang.StringSET_THREAD_CALLBACKS_NAMEprivate static SignatureSINGLE_NEW_INSTANCEprivate static AbstractClassGenerator.SourceSOURCEprivate static java.lang.StringSTATIC_CALLBACKS_FIELDprivate java.lang.Classsuperclassprivate static java.lang.StringTHREAD_CALLBACKS_FIELDprivate static org.objectweb.asm.TypeTHREAD_LOCALprivate static SignatureTHREAD_LOCAL_GETprivate static SignatureTHREAD_LOCAL_SETprivate booleanuseFactoryprivate booleanvalidateCallbackTypes
-
Constructor Summary
Constructors Constructor Description Enhancer()Create a newEnhancer.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectcreate()Generate a new class if necessary and uses the specified callbacks (if any) to create a new object instance.java.lang.Objectcreate(java.lang.Class[] argumentTypes, java.lang.Object[] arguments)Generate a new class if necessary and uses the specified callbacks (if any) to create a new object instance.static java.lang.Objectcreate(java.lang.Class superclass, java.lang.Class[] interfaces, Callback callback)Helper method to create an intercepted object.static java.lang.Objectcreate(java.lang.Class superclass, java.lang.Class[] interfaces, CallbackFilter filter, Callback[] callbacks)Helper method to create an intercepted object.static java.lang.Objectcreate(java.lang.Class type, Callback callback)Helper method to create an intercepted object.java.lang.ClasscreateClass()Generate a new class if necessary and return it without creating a new instance.private java.lang.ObjectcreateHelper()private java.lang.ObjectcreateUsingReflection(java.lang.Class type)Instantiates a proxy instance and assigns callback values.private voidemitBindCallbacks(ClassEmitter ce)private voidemitCommonNewInstance(CodeEmitter e)private voidemitConstructors(ClassEmitter ce, java.util.List constructors)private voidemitCurrentCallback(CodeEmitter e, int index)private voidemitDefaultConstructor(ClassEmitter ce)private voidemitGetCallback(ClassEmitter ce, int[] keys)private voidemitGetCallbacks(ClassEmitter ce)private voidemitMethods(ClassEmitter ce, java.util.List methods, java.util.List actualMethods)private voidemitNewInstanceCallback(ClassEmitter ce)private voidemitNewInstanceCallbacks(ClassEmitter ce)private voidemitNewInstanceMultiarg(ClassEmitter ce, java.util.List constructors)private voidemitSetCallback(ClassEmitter ce, int[] keys)private voidemitSetCallbacks(ClassEmitter ce)private voidemitSetStaticCallbacks(ClassEmitter ce)private voidemitSetThreadCallbacks(ClassEmitter ce)protected voidfilterConstructors(java.lang.Class sc, java.util.List constructors)Filter the list of constructors from the superclass.protected java.lang.ObjectfirstInstance(java.lang.Class type)This method should not be called in regular flow.protected java.lang.Classgenerate(AbstractClassGenerator.ClassLoaderData data)voidgenerateClass(org.objectweb.asm.ClassVisitor v)private static java.lang.StringgetCallbackField(int index)private int[]getCallbackKeys()private static java.lang.reflect.MethodgetCallbacksSetter(java.lang.Class type, java.lang.String methodName)protected java.lang.ClassLoadergetDefaultClassLoader()static voidgetMethods(java.lang.Class superclass, java.lang.Class[] interfaces, java.util.List methods)Finds all of the methods that will be extended by an Enhancer-generated class using the specified superclass and interfaces.private static voidgetMethods(java.lang.Class superclass, java.lang.Class[] interfaces, java.util.List methods, java.util.List interfaceMethods, java.util.Set forcePublic)protected java.security.ProtectionDomaingetProtectionDomain()Returns the protection domain to use when defining the class.private org.objectweb.asm.TypegetThisType(CodeEmitter e)static booleanisEnhanced(java.lang.Class type)Determine if a class was generated usingEnhancer.protected java.lang.ObjectnextInstance(java.lang.Object instance)private voidpreValidate()static voidregisterCallbacks(java.lang.Class generatedClass, Callback[] callbacks)Call this method to register theCallbackarray to use before creating a new instance of the generated class via reflection.static voidregisterStaticCallbacks(java.lang.Class generatedClass, Callback[] callbacks)Similar toregisterCallbacks(java.lang.Class, net.sf.cglib.proxy.Callback[]), but suitable for use when multiple threads will be creating instances of the generated class.private Signaturerename(Signature sig, int index)voidsetCallback(Callback callback)Set the singleCallbackto use.voidsetCallbackFilter(CallbackFilter filter)Set theCallbackFilterused to map the generated class' methods to a particular callback index.voidsetCallbacks(Callback[] callbacks)Set the array of callbacks to use.private static voidsetCallbacksHelper(java.lang.Class type, Callback[] callbacks, java.lang.String methodName)voidsetCallbackType(java.lang.Class callbackType)Set the single type ofCallbackto use.voidsetCallbackTypes(java.lang.Class[] callbackTypes)Set the array of callback types to use.voidsetInterceptDuringConstruction(boolean interceptDuringConstruction)Set whether methods called from within the proxy's constructer will be intercepted.voidsetInterfaces(java.lang.Class[] interfaces)Set the interfaces to implement.voidsetSerialVersionUID(java.lang.Long sUID)Insert a static serialVersionUID field into the generated class.voidsetSuperclass(java.lang.Class superclass)Set the class which the generated class will extend.private static voidsetThreadCallbacks(java.lang.Class type, Callback[] callbacks)voidsetUseFactory(boolean useFactory)Set whether the enhanced object instances should implement theFactoryinterface.protected java.lang.ObjectunwrapCachedValue(java.lang.Object cached)private voidvalidate()protected java.lang.ObjectwrapCachedClass(java.lang.Class klass)-
Methods inherited from class net.sf.cglib.core.AbstractClassGenerator
create, getAttemptLoad, getClassLoader, getClassName, getCurrent, getNamingPolicy, getStrategy, getUseCache, setAttemptLoad, setClassLoader, setNamePrefix, setNamingPolicy, setStrategy, setUseCache
-
-
-
-
Field Detail
-
ALL_ZERO
private static final CallbackFilter ALL_ZERO
-
SOURCE
private static final AbstractClassGenerator.Source SOURCE
-
KEY_FACTORY
private static final Enhancer.EnhancerKey KEY_FACTORY
-
BOUND_FIELD
private static final java.lang.String BOUND_FIELD
- See Also:
- Constant Field Values
-
FACTORY_DATA_FIELD
private static final java.lang.String FACTORY_DATA_FIELD
- See Also:
- Constant Field Values
-
THREAD_CALLBACKS_FIELD
private static final java.lang.String THREAD_CALLBACKS_FIELD
- See Also:
- Constant Field Values
-
STATIC_CALLBACKS_FIELD
private static final java.lang.String STATIC_CALLBACKS_FIELD
- See Also:
- Constant Field Values
-
SET_THREAD_CALLBACKS_NAME
private static final java.lang.String SET_THREAD_CALLBACKS_NAME
- See Also:
- Constant Field Values
-
SET_STATIC_CALLBACKS_NAME
private static final java.lang.String SET_STATIC_CALLBACKS_NAME
- See Also:
- Constant Field Values
-
CONSTRUCTED_FIELD
private static final java.lang.String CONSTRUCTED_FIELD
- See Also:
- Constant Field Values
-
CALLBACK_FILTER_FIELD
private static final java.lang.String CALLBACK_FILTER_FIELD
AbstractClassGenerator.ClassLoaderData.generatedClassesrequires to keep cache key in a good shape (the keys should be up and running if the proxy class is alive), and one of the cache keys isCallbackFilter. That is why the generated class contains static field that keeps strong reference to thefilter.This dance achieves two goals: ensures generated class is reusable and available through generatedClasses cache, and it enables to unload classloader and the related
CallbackFilterin case user does not need that- See Also:
- Constant Field Values
-
OBJECT_TYPE
private static final org.objectweb.asm.Type OBJECT_TYPE
-
FACTORY
private static final org.objectweb.asm.Type FACTORY
-
ILLEGAL_STATE_EXCEPTION
private static final org.objectweb.asm.Type ILLEGAL_STATE_EXCEPTION
-
ILLEGAL_ARGUMENT_EXCEPTION
private static final org.objectweb.asm.Type ILLEGAL_ARGUMENT_EXCEPTION
-
THREAD_LOCAL
private static final org.objectweb.asm.Type THREAD_LOCAL
-
CALLBACK
private static final org.objectweb.asm.Type CALLBACK
-
CALLBACK_ARRAY
private static final org.objectweb.asm.Type CALLBACK_ARRAY
-
CSTRUCT_NULL
private static final Signature CSTRUCT_NULL
-
SET_THREAD_CALLBACKS
private static final Signature SET_THREAD_CALLBACKS
-
SET_STATIC_CALLBACKS
private static final Signature SET_STATIC_CALLBACKS
-
NEW_INSTANCE
private static final Signature NEW_INSTANCE
-
MULTIARG_NEW_INSTANCE
private static final Signature MULTIARG_NEW_INSTANCE
-
SINGLE_NEW_INSTANCE
private static final Signature SINGLE_NEW_INSTANCE
-
SET_CALLBACK
private static final Signature SET_CALLBACK
-
GET_CALLBACK
private static final Signature GET_CALLBACK
-
SET_CALLBACKS
private static final Signature SET_CALLBACKS
-
GET_CALLBACKS
private static final Signature GET_CALLBACKS
-
THREAD_LOCAL_GET
private static final Signature THREAD_LOCAL_GET
-
THREAD_LOCAL_SET
private static final Signature THREAD_LOCAL_SET
-
BIND_CALLBACKS
private static final Signature BIND_CALLBACKS
-
currentData
private Enhancer.EnhancerFactoryData currentData
-
currentKey
private java.lang.Object currentKey
-
interfaces
private java.lang.Class[] interfaces
-
filter
private CallbackFilter filter
-
callbacks
private Callback[] callbacks
-
callbackTypes
private org.objectweb.asm.Type[] callbackTypes
-
validateCallbackTypes
private boolean validateCallbackTypes
-
classOnly
private boolean classOnly
-
superclass
private java.lang.Class superclass
-
argumentTypes
private java.lang.Class[] argumentTypes
-
arguments
private java.lang.Object[] arguments
-
useFactory
private boolean useFactory
-
serialVersionUID
private java.lang.Long serialVersionUID
-
interceptDuringConstruction
private boolean interceptDuringConstruction
-
-
Constructor Detail
-
Enhancer
public Enhancer()
Create a newEnhancer. A newEnhancerobject should be used for each generated object, and should not be shared across threads. To create additional instances of a generated class, use theFactoryinterface.- See Also:
Factory
-
-
Method Detail
-
setSuperclass
public void setSuperclass(java.lang.Class superclass)
Set the class which the generated class will extend. As a convenience, if the supplied superclass is actually an interface,setInterfaceswill be called with the appropriate argument instead. A non-interface argument must not be declared as final, and must have an accessible constructor.- Parameters:
superclass- class to extend or interface to implement- See Also:
setInterfaces(Class[])
-
setInterfaces
public void setInterfaces(java.lang.Class[] interfaces)
Set the interfaces to implement. TheFactoryinterface will always be implemented regardless of what is specified here.- Parameters:
interfaces- array of interfaces to implement, or null- See Also:
Factory
-
setCallbackFilter
public void setCallbackFilter(CallbackFilter filter)
Set theCallbackFilterused to map the generated class' methods to a particular callback index. New object instances will always use the same mapping, but may use different actual callback objects.- Parameters:
filter- the callback filter to use when generating a new class- See Also:
setCallbacks(net.sf.cglib.proxy.Callback[])
-
setCallback
public void setCallback(Callback callback)
Set the singleCallbackto use. Ignored if you usecreateClass().- Parameters:
callback- the callback to use for all methods- See Also:
setCallbacks(net.sf.cglib.proxy.Callback[])
-
setCallbacks
public void setCallbacks(Callback[] callbacks)
Set the array of callbacks to use. Ignored if you usecreateClass(). You must use aCallbackFilterto specify the index into this array for each method in the proxied class.- Parameters:
callbacks- the callback array- See Also:
setCallbackFilter(net.sf.cglib.proxy.CallbackFilter),setCallback(net.sf.cglib.proxy.Callback)
-
setUseFactory
public void setUseFactory(boolean useFactory)
Set whether the enhanced object instances should implement theFactoryinterface. This was added for tools that need for proxies to be more indistinguishable from their targets. Also, in some cases it may be necessary to disable theFactoryinterface to prevent code from changing the underlying callbacks.- Parameters:
useFactory- whether to implementFactory; default istrue
-
setInterceptDuringConstruction
public void setInterceptDuringConstruction(boolean interceptDuringConstruction)
Set whether methods called from within the proxy's constructer will be intercepted. The default value is true. Unintercepted methods will call the method of the proxy's base class, if it exists.- Parameters:
interceptDuringConstruction- whether to intercept methods called from the constructor
-
setCallbackType
public void setCallbackType(java.lang.Class callbackType)
Set the single type ofCallbackto use. This may be used instead ofsetCallback(net.sf.cglib.proxy.Callback)when callingcreateClass(), since it may not be possible to have an array of actual callback instances.- Parameters:
callbackType- the type of callback to use for all methods- See Also:
setCallbackTypes(java.lang.Class[])
-
setCallbackTypes
public void setCallbackTypes(java.lang.Class[] callbackTypes)
Set the array of callback types to use. This may be used instead ofsetCallbacks(net.sf.cglib.proxy.Callback[])when callingcreateClass(), since it may not be possible to have an array of actual callback instances. You must use aCallbackFilterto specify the index into this array for each method in the proxied class.- Parameters:
callbackTypes- the array of callback types
-
create
public java.lang.Object create()
Generate a new class if necessary and uses the specified callbacks (if any) to create a new object instance. Uses the no-arg constructor of the superclass.- Returns:
- a new instance
-
create
public java.lang.Object create(java.lang.Class[] argumentTypes, java.lang.Object[] arguments)Generate a new class if necessary and uses the specified callbacks (if any) to create a new object instance. Uses the constructor of the superclass matching theargumentTypesparameter, with the given arguments.- Parameters:
argumentTypes- constructor signaturearguments- compatible wrapped arguments to pass to constructor- Returns:
- a new instance
-
createClass
public java.lang.Class createClass()
Generate a new class if necessary and return it without creating a new instance. This ignores any callbacks that have been set. To create a new instance you will have to use reflection, and methods called during the constructor will not be intercepted. To avoid this problem, use the multi-argcreatemethod.- See Also:
create(Class[], Object[])
-
setSerialVersionUID
public void setSerialVersionUID(java.lang.Long sUID)
Insert a static serialVersionUID field into the generated class.- Parameters:
sUID- the field value, or null to avoid generating field.
-
preValidate
private void preValidate()
-
validate
private void validate()
-
createHelper
private java.lang.Object createHelper()
-
generate
protected java.lang.Class generate(AbstractClassGenerator.ClassLoaderData data)
- Overrides:
generatein classAbstractClassGenerator
-
getDefaultClassLoader
protected java.lang.ClassLoader getDefaultClassLoader()
- Specified by:
getDefaultClassLoaderin classAbstractClassGenerator
-
getProtectionDomain
protected java.security.ProtectionDomain getProtectionDomain()
Description copied from class:AbstractClassGeneratorReturns the protection domain to use when defining the class.Default implementation returns
nullfor using a default protection domain. Sub-classes may override to use a more specific protection domain.- Overrides:
getProtectionDomainin classAbstractClassGenerator- Returns:
- the protection domain (
nullfor using a default)
-
getMethods
public static void getMethods(java.lang.Class superclass, java.lang.Class[] interfaces, java.util.List methods)Finds all of the methods that will be extended by an Enhancer-generated class using the specified superclass and interfaces. This can be useful in building a list of Callback objects. The methods are added to the end of the given list. Due to the subclassing nature of the classes generated by Enhancer, the methods are guaranteed to be non-static, non-final, and non-private. Each method signature will only occur once, even if it occurs in multiple classes.- Parameters:
superclass- the class that will be extended, or nullinterfaces- the list of interfaces that will be implemented, or nullmethods- the list into which to copy the applicable methods
-
getMethods
private static void getMethods(java.lang.Class superclass, java.lang.Class[] interfaces, java.util.List methods, java.util.List interfaceMethods, java.util.Set forcePublic)
-
generateClass
public void generateClass(org.objectweb.asm.ClassVisitor v) throws java.lang.Exception- Throws:
java.lang.Exception
-
filterConstructors
protected void filterConstructors(java.lang.Class sc, java.util.List constructors)Filter the list of constructors from the superclass. The constructors which remain will be included in the generated class. The default implementation is to filter out all private constructors, but subclasses may extend Enhancer to override this behavior.- Parameters:
sc- the superclassconstructors- the list of all declared constructors from the superclass- Throws:
java.lang.IllegalArgumentException- if there are no non-private constructors
-
firstInstance
protected java.lang.Object firstInstance(java.lang.Class type) throws java.lang.ExceptionThis method should not be called in regular flow. Technically speakingwrapCachedClass(Class)usesEnhancer.EnhancerFactoryDataas a cache value, and the latter enables faster instantiation than plain old reflection lookup and invoke. This method is left intact for backward compatibility reasons: just in case it was ever used.- Specified by:
firstInstancein classAbstractClassGenerator- Parameters:
type- class to instantiate- Returns:
- newly created proxy instance
- Throws:
java.lang.Exception- if something goes wrong
-
nextInstance
protected java.lang.Object nextInstance(java.lang.Object instance)
- Specified by:
nextInstancein classAbstractClassGenerator
-
wrapCachedClass
protected java.lang.Object wrapCachedClass(java.lang.Class klass)
- Overrides:
wrapCachedClassin classAbstractClassGenerator
-
unwrapCachedValue
protected java.lang.Object unwrapCachedValue(java.lang.Object cached)
- Overrides:
unwrapCachedValuein classAbstractClassGenerator
-
registerCallbacks
public static void registerCallbacks(java.lang.Class generatedClass, Callback[] callbacks)Call this method to register theCallbackarray to use before creating a new instance of the generated class via reflection. If you are using an instance ofEnhanceror theFactoryinterface to create new instances, this method is unnecessary. Its primary use is for when you want to cache and reuse a generated class yourself, and the generated class does not implement theFactoryinterface.Note that this method only registers the callbacks on the current thread. If you want to register callbacks for instances created by multiple threads, use
registerStaticCallbacks(java.lang.Class, net.sf.cglib.proxy.Callback[]).The registered callbacks are overwritten and subsequently cleared when calling any of the
createmethods (such ascreate()), or anyFactorynewInstancemethod. Otherwise they are not cleared, and you should be careful to set them back tonullafter creating new instances via reflection if memory leakage is a concern.- Parameters:
generatedClass- a class previously created byEnhancercallbacks- the array of callbacks to use when instances of the generated class are created- See Also:
setUseFactory(boolean)
-
registerStaticCallbacks
public static void registerStaticCallbacks(java.lang.Class generatedClass, Callback[] callbacks)Similar toregisterCallbacks(java.lang.Class, net.sf.cglib.proxy.Callback[]), but suitable for use when multiple threads will be creating instances of the generated class. The thread-level callbacks will always override the static callbacks. Static callbacks are never cleared.- Parameters:
generatedClass- a class previously created byEnhancercallbacks- the array of callbacks to use when instances of the generated class are created
-
isEnhanced
public static boolean isEnhanced(java.lang.Class type)
Determine if a class was generated usingEnhancer.- Parameters:
type- any class- Returns:
- whether the class was generated using
Enhancer
-
setThreadCallbacks
private static void setThreadCallbacks(java.lang.Class type, Callback[] callbacks)
-
setCallbacksHelper
private static void setCallbacksHelper(java.lang.Class type, Callback[] callbacks, java.lang.String methodName)
-
getCallbacksSetter
private static java.lang.reflect.Method getCallbacksSetter(java.lang.Class type, java.lang.String methodName) throws java.lang.NoSuchMethodException- Throws:
java.lang.NoSuchMethodException
-
createUsingReflection
private java.lang.Object createUsingReflection(java.lang.Class type)
Instantiates a proxy instance and assigns callback values. Implementation detail: java.lang.reflect instances are not cached, so this method should not be used on a hot path. This method is used whenAbstractClassGenerator.setUseCache(boolean)is set tofalse.- Parameters:
type- class to instantiate- Returns:
- newly created instance
-
create
public static java.lang.Object create(java.lang.Class type, Callback callback)Helper method to create an intercepted object. For finer control over the generated instance, use a new instance ofEnhancerinstead of this static method.- Parameters:
type- class to extend or interface to implementcallback- the callback to use for all methods
-
create
public static java.lang.Object create(java.lang.Class superclass, java.lang.Class[] interfaces, Callback callback)Helper method to create an intercepted object. For finer control over the generated instance, use a new instance ofEnhancerinstead of this static method.- Parameters:
superclass- class to extend or interface to implementinterfaces- array of interfaces to implement, or nullcallback- the callback to use for all methods
-
create
public static java.lang.Object create(java.lang.Class superclass, java.lang.Class[] interfaces, CallbackFilter filter, Callback[] callbacks)Helper method to create an intercepted object. For finer control over the generated instance, use a new instance ofEnhancerinstead of this static method.- Parameters:
superclass- class to extend or interface to implementinterfaces- array of interfaces to implement, or nullfilter- the callback filter to use when generating a new classcallbacks- callback implementations to use for the enhanced object
-
emitDefaultConstructor
private void emitDefaultConstructor(ClassEmitter ce)
-
emitConstructors
private void emitConstructors(ClassEmitter ce, java.util.List constructors)
-
getCallbackKeys
private int[] getCallbackKeys()
-
emitGetCallback
private void emitGetCallback(ClassEmitter ce, int[] keys)
-
emitSetCallback
private void emitSetCallback(ClassEmitter ce, int[] keys)
-
emitSetCallbacks
private void emitSetCallbacks(ClassEmitter ce)
-
emitGetCallbacks
private void emitGetCallbacks(ClassEmitter ce)
-
emitNewInstanceCallbacks
private void emitNewInstanceCallbacks(ClassEmitter ce)
-
getThisType
private org.objectweb.asm.Type getThisType(CodeEmitter e)
-
emitCommonNewInstance
private void emitCommonNewInstance(CodeEmitter e)
-
emitNewInstanceCallback
private void emitNewInstanceCallback(ClassEmitter ce)
-
emitNewInstanceMultiarg
private void emitNewInstanceMultiarg(ClassEmitter ce, java.util.List constructors)
-
emitMethods
private void emitMethods(ClassEmitter ce, java.util.List methods, java.util.List actualMethods)
-
emitSetThreadCallbacks
private void emitSetThreadCallbacks(ClassEmitter ce)
-
emitSetStaticCallbacks
private void emitSetStaticCallbacks(ClassEmitter ce)
-
emitCurrentCallback
private void emitCurrentCallback(CodeEmitter e, int index)
-
emitBindCallbacks
private void emitBindCallbacks(ClassEmitter ce)
-
getCallbackField
private static java.lang.String getCallbackField(int index)
-
-