org.springframework.aop.framework
Class Cglib2AopProxy

java.lang.Object
  extended by org.springframework.aop.framework.Cglib2AopProxy
All Implemented Interfaces:
java.io.Serializable, AopProxy

final class Cglib2AopProxy
extends java.lang.Object
implements AopProxy, java.io.Serializable

CGLIB2-based AopProxy implementation for the Spring AOP framework.

Requires CGLIB 2.1+ on the classpath.. As of Spring 2.0, earlier CGLIB versions are not supported anymore.

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 CGLIB2-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.

Author:
Rod Johnson, Rob Harrop, Juergen Hoeller, Ramnivas Laddad
See Also:
net.sf.cglib.proxy.Enhancer, ProxyConfig.setProxyTargetClass(boolean), DefaultAopProxyFactory

Nested Class Summary
private static class Cglib2AopProxy.AdvisedDispatcher
          Dispatcher for any methods declared on the Advised class.
private static class Cglib2AopProxy.CglibMethodInvocation
          Implementation of AOP Alliance MethodInvocation used by this AOP proxy.
private static class Cglib2AopProxy.DynamicAdvisedInterceptor
          General purpose AOP callback.
private static class Cglib2AopProxy.DynamicUnadvisedExposedInterceptor
          Interceptor for unadvised dynamic targets when the proxy needs exposing.
private static class Cglib2AopProxy.DynamicUnadvisedInterceptor
          Interceptor used to invoke a dynamic target without creating a method invocation or evaluating an advice chain.
private static class Cglib2AopProxy.EqualsInterceptor
          Dispatcher for the equals method.
private static class Cglib2AopProxy.FixedChainStaticTargetInterceptor
          Interceptor used specifically for advised methods on a frozen, static proxy.
private static class Cglib2AopProxy.HashCodeInterceptor
          Dispatcher for the hashCode method.
private static class Cglib2AopProxy.ProxyCallbackFilter
          CallbackFilter to assign Callbacks to methods.
static class Cglib2AopProxy.SerializableNoOp
          Serializable replacement for CGLIB's NoOp interface.
private static class Cglib2AopProxy.StaticDispatcher
          Dispatcher for a static target.
private static class Cglib2AopProxy.StaticUnadvisedExposedInterceptor
          Method interceptor used for static targets with no advice chain, when the proxy is to be exposed.
private static class Cglib2AopProxy.StaticUnadvisedInterceptor
          Method interceptor used for static targets with no advice chain.
 
Field Summary
protected  AdvisedSupport advised
          The configuration used to configure this proxy
private  Cglib2AopProxy.AdvisedDispatcher advisedDispatcher
          Dispatcher used for methods on Advised
private static int AOP_PROXY
           
private  java.lang.Object[] constructorArgs
           
private  java.lang.Class[] constructorArgTypes
           
private static int DISPATCH_ADVISED
           
private static int DISPATCH_TARGET
           
private  java.util.Map<java.lang.String,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 Summary
Cglib2AopProxy(AdvisedSupport config)
          Create a new Cglib2AopProxy for the given AOP configuration.
 
Method Summary
protected  Enhancer createEnhancer()
          Creates the CGLIB Enhancer.
private  void doValidateClass(java.lang.Class proxySuperClass)
          Checks for final methods on the Class 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 java.lang.Object massageReturnTypeIfNecessary(java.lang.Object proxy, java.lang.Object target, java.lang.reflect.Method method, java.lang.Object retVal)
          Wrap a return of this if necessary to be the proxy
 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)
          Checks to see whether the supplied Class has already been validated and validates it if not.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AOP_PROXY

private static final int AOP_PROXY
See Also:
Constant Field Values

INVOKE_TARGET

private static final int INVOKE_TARGET
See Also:
Constant Field Values

NO_OVERRIDE

private static final int NO_OVERRIDE
See Also:
Constant Field Values

DISPATCH_TARGET

private static final int DISPATCH_TARGET
See Also:
Constant Field Values

DISPATCH_ADVISED

private static final int DISPATCH_ADVISED
See Also:
Constant Field Values

INVOKE_EQUALS

private static final int INVOKE_EQUALS
See Also:
Constant Field Values

INVOKE_HASHCODE

private static final int INVOKE_HASHCODE
See Also:
Constant Field Values

logger

protected static final Log logger
Logger available to subclasses; static to optimize serialization


validatedClasses

private static final java.util.Map<java.lang.Class,java.lang.Boolean> validatedClasses
Keeps track of the Classes that we have validated for final methods


advised

protected final AdvisedSupport advised
The configuration used to configure this proxy


constructorArgs

private java.lang.Object[] constructorArgs

constructorArgTypes

private java.lang.Class[] constructorArgTypes

advisedDispatcher

private final transient Cglib2AopProxy.AdvisedDispatcher advisedDispatcher
Dispatcher used for methods on Advised


fixedInterceptorMap

private transient java.util.Map<java.lang.String,java.lang.Integer> fixedInterceptorMap

fixedInterceptorOffset

private transient int fixedInterceptorOffset
Constructor Detail

Cglib2AopProxy

public Cglib2AopProxy(AdvisedSupport config)
               throws AopConfigException
Create a new Cglib2AopProxy for the given AOP configuration.

Parameters:
config - the AOP configuration as AdvisedSupport object
Throws:
AopConfigException - if the config is invalid. We try to throw an informative exception in this case, rather than let a mysterious failure happen later.
Method Detail

setConstructorArguments

public void setConstructorArguments(java.lang.Object[] constructorArgs,
                                    java.lang.Class[] constructorArgTypes)
Set constructor arguments to use for creating the proxy.

Parameters:
constructorArgs - the constructor argument values
constructorArgTypes - the constructor argument types

getProxy

public java.lang.Object getProxy()
Description copied from interface: AopProxy
Create a new proxy object.

Uses the AopProxy's default class loader (if necessary for proxy creation): usually, the thread context class loader.

Specified by:
getProxy in interface AopProxy
Returns:
the new proxy object (never null)
See Also:
Thread.getContextClassLoader()

getProxy

public java.lang.Object getProxy(java.lang.ClassLoader classLoader)
Description copied from interface: AopProxy
Create a new proxy object.

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.

Specified by:
getProxy in interface AopProxy
Parameters:
classLoader - the class loader to create the proxy with (or null for the low-level proxy facility's default)
Returns:
the new proxy object (never null)

createEnhancer

protected Enhancer createEnhancer()
Creates the CGLIB Enhancer. Subclasses may wish to override this to return a custom Enhancer implementation.


validateClassIfNecessary

private void validateClassIfNecessary(java.lang.Class proxySuperClass)
Checks to see whether the supplied Class has already been validated and validates it if not.


doValidateClass

private void doValidateClass(java.lang.Class proxySuperClass)
Checks for final methods on the Class and writes warnings to the log for each one found.


getCallbacks

private Callback[] getCallbacks(java.lang.Class rootClass)
                         throws java.lang.Exception
Throws:
java.lang.Exception

massageReturnTypeIfNecessary

private static java.lang.Object massageReturnTypeIfNecessary(java.lang.Object proxy,
                                                             java.lang.Object target,
                                                             java.lang.reflect.Method method,
                                                             java.lang.Object retVal)
Wrap a return of this if necessary to be the proxy


equals

public boolean equals(java.lang.Object other)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object