org.springframework.aop.framework
Class JdkDynamicAopProxy

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

final class JdkDynamicAopProxy
extends java.lang.Object
implements AopProxy, java.lang.reflect.InvocationHandler, java.io.Serializable

JDK-based AopProxy implementation for the Spring AOP framework, based on JDK dynamic proxies.

Creates a dynamic proxy, implementing the interfaces exposed by the AopProxy. Dynamic proxies cannot be used to proxy methods defined in classes, rather than interfaces.

Objects of this type should be obtained through proxy factories, configured by an AdvisedSupport class. This class is internal to Spring's AOP framework and need not be used directly by client code.

Proxies created using this class will be thread-safe if the underlying (target) class is thread-safe.

Proxies are serializable so long as all Advisors (including Advices and Pointcuts) and the TargetSource are serializable.

Author:
Rod Johnson, Juergen Hoeller, Rob Harrop
See Also:
Proxy, AdvisedSupport, ProxyFactory

Field Summary
private  AdvisedSupport advised
          Config used to configure this proxy
private  boolean equalsDefined
          Is the equals(java.lang.Object) method defined on the proxied interfaces?
private  boolean hashCodeDefined
          Is the hashCode() method defined on the proxied interfaces?
private static Log logger
          We use a static Log to avoid serialization issues
private static long serialVersionUID
          use serialVersionUID from Spring 1.2 for interoperability
 
Constructor Summary
JdkDynamicAopProxy(AdvisedSupport config)
          Construct a new JdkDynamicAopProxy for the given AOP configuration.
 
Method Summary
 boolean equals(java.lang.Object other)
          Equality means interfaces, advisors and TargetSource are equal.
private  void findDefinedEqualsAndHashCodeMethods(java.lang.Class[] proxiedInterfaces)
          Finds any equals(java.lang.Object) or hashCode() method that may be defined on the supplied set of interfaces.
 java.lang.Object getProxy()
          Create a new proxy object.
 java.lang.Object getProxy(java.lang.ClassLoader classLoader)
          Create a new proxy object.
 int hashCode()
          Proxy uses the hash code of the TargetSource.
 java.lang.Object invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)
          Implementation of InvocationHandler.invoke.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
use serialVersionUID from Spring 1.2 for interoperability

See Also:
Constant Field Values

logger

private static Log logger
We use a static Log to avoid serialization issues


advised

private final AdvisedSupport advised
Config used to configure this proxy


equalsDefined

private boolean equalsDefined
Is the equals(java.lang.Object) method defined on the proxied interfaces?


hashCodeDefined

private boolean hashCodeDefined
Is the hashCode() method defined on the proxied interfaces?

Constructor Detail

JdkDynamicAopProxy

public JdkDynamicAopProxy(AdvisedSupport config)
                   throws AopConfigException
Construct a new JdkDynamicAopProxy 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

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)

findDefinedEqualsAndHashCodeMethods

private void findDefinedEqualsAndHashCodeMethods(java.lang.Class[] proxiedInterfaces)
Finds any equals(java.lang.Object) or hashCode() method that may be defined on the supplied set of interfaces.

Parameters:
proxiedInterfaces - the interfaces to introspect

invoke

public java.lang.Object invoke(java.lang.Object proxy,
                               java.lang.reflect.Method method,
                               java.lang.Object[] args)
                        throws java.lang.Throwable
Implementation of InvocationHandler.invoke.

Callers will see exactly the exception thrown by the target, unless a hook method throws an exception.

Specified by:
invoke in interface java.lang.reflect.InvocationHandler
Throws:
java.lang.Throwable

equals

public boolean equals(java.lang.Object other)
Equality means interfaces, advisors and TargetSource are equal.

The compared object may be a JdkDynamicAopProxy instance itself or a dynamic proxy wrapping a JdkDynamicAopProxy instance.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Proxy uses the hash code of the TargetSource.

Overrides:
hashCode in class java.lang.Object