class CglibAopProxy extends java.lang.Object implements AopProxy, java.io.Serializable
AopProxy
implementation for the Spring AOP framework.
Objects of this type should be obtained through proxy factories,
configured by an AdvisedSupport
object. This class is internal
to Spring's AOP framework and need not be used directly by client code.
DefaultAopProxyFactory
will automatically create CGLIB-based
proxies if necessary, for example in case of proxying a target class
(see the attendant javadoc
for details).
Proxies created using this class are thread-safe if the underlying (target) class is thread-safe.
Enhancer
,
ProxyConfig.setProxyTargetClass(boolean)
,
DefaultAopProxyFactory
Modifier and Type | Class and Description |
---|---|
private static class |
CglibAopProxy.AdvisedDispatcher
Dispatcher for any methods declared on the Advised class.
|
private static class |
CglibAopProxy.CglibMethodInvocation
Implementation of AOP Alliance MethodInvocation used by this AOP proxy.
|
private static class |
CglibAopProxy.ClassLoaderAwareUndeclaredThrowableStrategy
CGLIB GeneratorStrategy variant which exposes the application ClassLoader
as thread context ClassLoader for the time of class generation
(in order for ASM to pick it up when doing common superclass resolution).
|
private static class |
CglibAopProxy.DynamicAdvisedInterceptor
General purpose AOP callback.
|
private static class |
CglibAopProxy.DynamicUnadvisedExposedInterceptor
Interceptor for unadvised dynamic targets when the proxy needs exposing.
|
private static class |
CglibAopProxy.DynamicUnadvisedInterceptor
Interceptor used to invoke a dynamic target without creating a method
invocation or evaluating an advice chain.
|
private static class |
CglibAopProxy.EqualsInterceptor
Dispatcher for the
equals method. |
private static class |
CglibAopProxy.FixedChainStaticTargetInterceptor
Interceptor used specifically for advised methods on a frozen, static proxy.
|
private static class |
CglibAopProxy.HashCodeInterceptor
Dispatcher for the
hashCode method. |
private static class |
CglibAopProxy.ProxyCallbackFilter
CallbackFilter to assign Callbacks to methods.
|
static class |
CglibAopProxy.SerializableNoOp
Serializable replacement for CGLIB's NoOp interface.
|
private static class |
CglibAopProxy.StaticDispatcher
Dispatcher for a static target.
|
private static class |
CglibAopProxy.StaticUnadvisedExposedInterceptor
Method interceptor used for static targets with no advice chain, when the
proxy is to be exposed.
|
private static class |
CglibAopProxy.StaticUnadvisedInterceptor
Method interceptor used for static targets with no advice chain.
|
Modifier and Type | Field and Description |
---|---|
protected AdvisedSupport |
advised
The configuration used to configure this proxy.
|
private CglibAopProxy.AdvisedDispatcher |
advisedDispatcher
Dispatcher used for methods on Advised.
|
private static int |
AOP_PROXY |
protected java.lang.Object[] |
constructorArgs |
protected java.lang.Class<?>[] |
constructorArgTypes |
private static int |
DISPATCH_ADVISED |
private static int |
DISPATCH_TARGET |
private java.util.Map<java.lang.reflect.Method,java.lang.Integer> |
fixedInterceptorMap |
private int |
fixedInterceptorOffset |
private static int |
INVOKE_EQUALS |
private static int |
INVOKE_HASHCODE |
private static int |
INVOKE_TARGET |
protected static Log |
logger
Logger available to subclasses; static to optimize serialization.
|
private static int |
NO_OVERRIDE |
private static java.util.Map<java.lang.Class<?>,java.lang.Boolean> |
validatedClasses
Keeps track of the Classes that we have validated for final methods.
|
Constructor and Description |
---|
CglibAopProxy(AdvisedSupport config)
Create a new CglibAopProxy for the given AOP configuration.
|
Modifier and Type | Method and Description |
---|---|
protected Enhancer |
createEnhancer()
Creates the CGLIB
Enhancer . |
protected java.lang.Object |
createProxyClassAndInstance(Enhancer enhancer,
Callback[] callbacks) |
private void |
doValidateClass(java.lang.Class<?> proxySuperClass,
java.lang.ClassLoader proxyClassLoader,
java.util.Set<java.lang.Class<?>> ifcs)
Checks for final methods on the given
Class , as well as package-visible
methods across ClassLoaders, and writes warnings to the log for each one found. |
boolean |
equals(java.lang.Object other) |
private Callback[] |
getCallbacks(java.lang.Class<?> rootClass) |
java.lang.Object |
getProxy()
Create a new proxy object.
|
java.lang.Object |
getProxy(java.lang.ClassLoader classLoader)
Create a new proxy object.
|
int |
hashCode() |
private static boolean |
implementsInterface(java.lang.reflect.Method method,
java.util.Set<java.lang.Class<?>> ifcs)
Check whether the given method is declared on any of the given interfaces.
|
private static java.lang.Object |
processReturnType(java.lang.Object proxy,
java.lang.Object target,
java.lang.reflect.Method method,
java.lang.Object returnValue)
Process a return value.
|
void |
setConstructorArguments(java.lang.Object[] constructorArgs,
java.lang.Class<?>[] constructorArgTypes)
Set constructor arguments to use for creating the proxy.
|
private void |
validateClassIfNecessary(java.lang.Class<?> proxySuperClass,
java.lang.ClassLoader proxyClassLoader)
Checks to see whether the supplied
Class has already been validated and
validates it if not. |
private static final int AOP_PROXY
private static final int INVOKE_TARGET
private static final int NO_OVERRIDE
private static final int DISPATCH_TARGET
private static final int DISPATCH_ADVISED
private static final int INVOKE_EQUALS
private static final int INVOKE_HASHCODE
protected static final Log logger
private static final java.util.Map<java.lang.Class<?>,java.lang.Boolean> validatedClasses
protected final AdvisedSupport advised
@Nullable protected java.lang.Object[] constructorArgs
@Nullable protected java.lang.Class<?>[] constructorArgTypes
private final transient CglibAopProxy.AdvisedDispatcher advisedDispatcher
private transient java.util.Map<java.lang.reflect.Method,java.lang.Integer> fixedInterceptorMap
private transient int fixedInterceptorOffset
public CglibAopProxy(AdvisedSupport config) throws AopConfigException
config
- the AOP configuration as AdvisedSupport objectAopConfigException
- if the config is invalid. We try to throw an informative
exception in this case, rather than let a mysterious failure happen later.public void setConstructorArguments(@Nullable java.lang.Object[] constructorArgs, @Nullable java.lang.Class<?>[] constructorArgTypes)
constructorArgs
- the constructor argument valuesconstructorArgTypes
- the constructor argument typespublic java.lang.Object getProxy()
AopProxy
Uses the AopProxy's default class loader (if necessary for proxy creation): usually, the thread context class loader.
public java.lang.Object getProxy(@Nullable java.lang.ClassLoader classLoader)
AopProxy
Uses the given class loader (if necessary for proxy creation).
null
will simply be passed down and thus lead to the low-level
proxy facility's default, which is usually different from the default chosen
by the AopProxy implementation's AopProxy.getProxy()
method.
protected java.lang.Object createProxyClassAndInstance(Enhancer enhancer, Callback[] callbacks)
protected Enhancer createEnhancer()
private void validateClassIfNecessary(java.lang.Class<?> proxySuperClass, @Nullable java.lang.ClassLoader proxyClassLoader)
Class
has already been validated and
validates it if not.private void doValidateClass(java.lang.Class<?> proxySuperClass, @Nullable java.lang.ClassLoader proxyClassLoader, java.util.Set<java.lang.Class<?>> ifcs)
Class
, as well as package-visible
methods across ClassLoaders, and writes warnings to the log for each one found.private Callback[] getCallbacks(java.lang.Class<?> rootClass) throws java.lang.Exception
java.lang.Exception
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
private static boolean implementsInterface(java.lang.reflect.Method method, java.util.Set<java.lang.Class<?>> ifcs)
@Nullable private static java.lang.Object processReturnType(java.lang.Object proxy, @Nullable java.lang.Object target, java.lang.reflect.Method method, @Nullable java.lang.Object returnValue)
this
if necessary to be the
proxy
and also verifies that null
is not returned as a primitive.