org.springframework.aop.aspectj.annotation
Class AspectJProxyFactory

java.lang.Object
  extended by org.springframework.aop.framework.ProxyConfig
      extended by org.springframework.aop.framework.AdvisedSupport
          extended by org.springframework.aop.framework.ProxyCreatorSupport
              extended by org.springframework.aop.aspectj.annotation.AspectJProxyFactory
All Implemented Interfaces:
java.io.Serializable, Advised, TargetClassAware

public class AspectJProxyFactory
extends ProxyCreatorSupport

AspectJ-based proxy factory, allowing for programmatic building of proxies which include AspectJ aspects (code style as well Java 5 annotation style).

Since:
2.0
Author:
Rob Harrop, Juergen Hoeller, Ramnivas Laddad
See Also:
addAspect(Object), addAspect(Class), getProxy(), getProxy(ClassLoader), ProxyFactory, Serialized Form

Field Summary
private static java.util.Map<java.lang.Class,java.lang.Object> aspectCache
          Cache for singleton aspect instances
private  AspectJAdvisorFactory aspectFactory
           
 
Fields inherited from class org.springframework.aop.framework.AdvisedSupport
EMPTY_TARGET_SOURCE
 
Constructor Summary
AspectJProxyFactory()
          Create a new AspectJProxyFactory.
AspectJProxyFactory(java.lang.Class[] interfaces)
          Create a new AspectJProxyFactory.
AspectJProxyFactory(java.lang.Object target)
          Create a new AspectJProxyFactory.
 
Method Summary
private  void addAdvisorsFromAspectInstanceFactory(MetadataAwareAspectInstanceFactory instanceFactory)
          Add all Advisors from the supplied MetadataAwareAspectInstanceFactory to the current chain.
 void addAspect(java.lang.Class aspectClass)
          Add an aspect of the supplied type to the end of the advice chain.
 void addAspect(java.lang.Object aspectInstance)
          Add the supplied aspect instance to the chain.
private  MetadataAwareAspectInstanceFactory createAspectInstanceFactory(AspectMetadata am, java.lang.Class aspectClass, java.lang.String aspectName)
          Create a MetadataAwareAspectInstanceFactory for the supplied aspect type.
private  AspectMetadata createAspectMetadata(java.lang.Class aspectClass, java.lang.String aspectName)
          Create an AspectMetadata instance for the supplied aspect type.
<T> T
getProxy()
          Create a new proxy according to the settings in this factory.
<T> T
getProxy(java.lang.ClassLoader classLoader)
          Create a new proxy according to the settings in this factory.
private  java.lang.Object getSingletonAspectInstance(java.lang.Class aspectClass)
          Get the singleton aspect instance for the supplied aspect type.
 
Methods inherited from class org.springframework.aop.framework.ProxyCreatorSupport
addListener, adviceChanged, createAopProxy, getAopProxyFactory, isActive, removeListener, setAopProxyFactory
 
Methods inherited from class org.springframework.aop.framework.AdvisedSupport
addAdvice, addAdvice, addAdvisor, addAdvisor, addAdvisors, addAdvisors, addAllAdvisors, addInterface, adviceIncluded, copyConfigurationFrom, copyConfigurationFrom, countAdvicesOfType, getAdvisorChainFactory, getAdvisors, getAdvisorsInternal, getInterceptorsAndDynamicInterceptionAdvice, getProxiedInterfaces, getTargetClass, getTargetSource, indexOf, indexOf, isInterfaceProxied, isPreFiltered, removeAdvice, removeAdvisor, removeAdvisor, removeInterface, replaceAdvisor, setAdvisorChainFactory, setInterfaces, setPreFiltered, setTarget, setTargetClass, setTargetSource, toProxyConfigString, toString, updateAdvisorArray
 
Methods inherited from class org.springframework.aop.framework.ProxyConfig
copyFrom, isExposeProxy, isFrozen, isOpaque, isOptimize, isProxyTargetClass, setExposeProxy, setFrozen, setOpaque, setOptimize, setProxyTargetClass
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.springframework.aop.framework.Advised
isExposeProxy, isFrozen, isProxyTargetClass, setExposeProxy
 

Field Detail

aspectCache

private static final java.util.Map<java.lang.Class,java.lang.Object> aspectCache
Cache for singleton aspect instances


aspectFactory

private final AspectJAdvisorFactory aspectFactory
Constructor Detail

AspectJProxyFactory

public AspectJProxyFactory()
Create a new AspectJProxyFactory.


AspectJProxyFactory

public AspectJProxyFactory(java.lang.Object target)
Create a new AspectJProxyFactory.

Will proxy all interfaces that the given target implements.

Parameters:
target - the target object to be proxied

AspectJProxyFactory

public AspectJProxyFactory(java.lang.Class[] interfaces)
Create a new AspectJProxyFactory. No target, only interfaces. Must add interceptors.

Method Detail

addAspect

public void addAspect(java.lang.Object aspectInstance)
Add the supplied aspect instance to the chain. The type of the aspect instance supplied must be a singleton aspect. True singleton lifecycle is not honoured when using this method - the caller is responsible for managing the lifecycle of any aspects added in this way.

Parameters:
aspectInstance - the AspectJ aspect instance

addAspect

public void addAspect(java.lang.Class aspectClass)
Add an aspect of the supplied type to the end of the advice chain.

Parameters:
aspectClass - the AspectJ aspect class

addAdvisorsFromAspectInstanceFactory

private void addAdvisorsFromAspectInstanceFactory(MetadataAwareAspectInstanceFactory instanceFactory)
Add all Advisors from the supplied MetadataAwareAspectInstanceFactory to the current chain. Exposes any special purpose Advisors if needed.

See Also:
#makeAdvisorChainAspectJCapableIfNecessary()

createAspectMetadata

private AspectMetadata createAspectMetadata(java.lang.Class aspectClass,
                                            java.lang.String aspectName)
Create an AspectMetadata instance for the supplied aspect type.


createAspectInstanceFactory

private MetadataAwareAspectInstanceFactory createAspectInstanceFactory(AspectMetadata am,
                                                                       java.lang.Class aspectClass,
                                                                       java.lang.String aspectName)
Create a MetadataAwareAspectInstanceFactory for the supplied aspect type. If the aspect type has no per clause, then a SingletonMetadataAwareAspectInstanceFactory is returned, otherwise a PrototypeAspectInstanceFactory is returned.


getSingletonAspectInstance

private java.lang.Object getSingletonAspectInstance(java.lang.Class aspectClass)
Get the singleton aspect instance for the supplied aspect type. An instance is created if one cannot be found in the instance cache.


getProxy

public <T> T getProxy()
Create a new proxy according to the settings in this factory.

Can be called repeatedly. Effect will vary if we've added or removed interfaces. Can add and remove interceptors.

Uses a default class loader: Usually, the thread context class loader (if necessary for proxy creation).

Returns:
the new proxy

getProxy

public <T> T getProxy(java.lang.ClassLoader classLoader)
Create a new proxy according to the settings in this factory.

Can be called repeatedly. Effect will vary if we've added or removed interfaces. Can add and remove interceptors.

Uses the given class loader (if necessary for proxy creation).

Parameters:
classLoader - the class loader to create the proxy with
Returns:
the new proxy