org.springframework.aop.framework
Class ProxyFactoryBean

org.springframework.aop.framework.ProxyConfig
  |
  +--org.springframework.aop.framework.AdvisedSupport
        |
        +--org.springframework.aop.framework.ProxyFactoryBean

public class ProxyFactoryBean
extends AdvisedSupport
implements AdvisedSupportListener, BeanFactoryAware, FactoryBean

FactoryBean implementation for use to source AOP proxies from a Spring BeanFactory.

Interceptors and Advisors are identified by a list of bean names in the current bean factory. These beans should be of type Interceptor or an Advisor subtype (presently InterceptionAroundAdvisor or InterceptionIntroductionAdvisor). The last entry in the list can be the name of any bean in the factory. If it's neither an Interceptor or a MethodPointcut, a new InvokerInterceptor is added to wrap it.

Global interceptors and advisors can be added at the factory level. The specified ones are expanded in an interceptor list where an "xxx*" entry is included in the list, matching the given prefix with the bean names (e.g. "global*" would match both "globalBean1" and "globalBean2", "*" all defined interceptors). The matching interceptors get applied according to their returned order value, if they implement the Ordered interface. An interceptor name list may not conclude with a global "xxx*" pattern, as global interceptors cannot invoke targets.

Creates a J2SE proxy when proxy interfaces are given, a CGLIB proxy for the actual target class if not. Note that the latter will only work if the target class does not have final methods, as a dynamic subclass will be created at runtime.

It's possible to cast a proxy obtained from this factory to Advisor, or to obtain the ProxyFactoryBean reference and programmatically manipulate it. This won't work for existing prototype references, which are independent. However, it will work for prototypes subsequently obtained from the factory. Changes to interception will work immediately on singletons (including existing references). However, to change interfaces or target it's necessary to obtain a new instance from the factory. This means that singleton instances obtained from the factory do not have the same object identity. However, they do have the same interceptors and target, and changing any reference will change all objects.

Author:
Rod Johnson, Juergen Hoeller
Version: $Id: ProxyFactoryBean.java,v 1.20 2004/02/11 17:18:16 jhoeller Exp $
See Also: setInterceptorNames(java.lang.String[]), setProxyInterfaces(java.lang.String[]), org.aopalliance.intercept.MethodInterceptor, InterceptionAroundAdvisor, InterceptionIntroductionAdvisor

Field Summary
 final static StringGLOBAL_SUFFIX
          This suffix in a value in an interceptor list indicates to expand globals.

Fields inherited from class org.springframework.aop.framework.AdvisedSupport
EMPTY_TARGET_SOURCE

Method Summary
 voidactivated(AdvisedSupport advisedSupport)
           
 voidadviceChanged(AdvisedSupport advisedSupport)
          Blow away and recache singleton to allow for advice changes.
 ObjectgetObject()
          Return a proxy.
 ClassgetObjectType()
           
 booleanisSingleton()
           
 voidsetBeanFactory(BeanFactory beanFactory)
           
 voidsetInterceptorNames(String[] interceptorNames)
          Set the list of Interceptor/Advisor bean names.
 voidsetProxyInterfaces(String[] interfaceNames)
          Set the names of the interfaces we're proxying.
 voidsetSingleton(boolean singleton)
          Set the value of the singleton property.

Methods inherited from class org.springframework.aop.framework.AdvisedSupport
addAdvisor, addAdvisor, addAdvisor, addBeforeAdvice, addInterceptor, addInterceptor, addInterface, addListener, addThrowsAdvice, countInterceptorsOfType, getAdvisorChainFactory, getAdvisors, getMethodInvocationFactory, getProxiedInterfaces, getTargetSource, indexOf, indexOf, interceptorIncluded, isInterfaceProxied, removeAdvisor, removeAdvisor, removeInterceptor, removeInterface, removeListener, replaceAdvisor, setAdvisorChainFactory, setInterfaces, setMethodInvocationFactory, setTarget, setTargetSource, toProxyConfigString, toString

Methods inherited from class org.springframework.aop.framework.ProxyConfig
copyFrom, getExposeProxy, getOptimize, getProxyTargetClass, setExposeProxy, setOptimize, setProxyTargetClass

Field Detail

GLOBAL_SUFFIX

public final static String GLOBAL_SUFFIX
This suffix in a value in an interceptor list indicates to expand globals.
Method Detail

activated

public void activated(AdvisedSupport advisedSupport)
See Also:
AdvisedSupportListener.activated(org.springframework.aop.framework.AdvisedSupport)

adviceChanged

public void adviceChanged(AdvisedSupport advisedSupport)
Blow away and recache singleton to allow for advice changes.
See Also:
AdvisedSupportListener.adviceChanged(org.springframework.aop.framework.AdvisedSupport)

getObject

public Object getObject()
throws org.springframework.beans.BeansException
Return a proxy. Invoked when clients obtain beans from this factory bean. Create an instance of the AOP proxy to be returned by this factory. The instance will be cached for a singleton, and create on each call to getObject() for a proxy.
Returns: Object a fresh AOP proxy reflecting the current state of this factory
See Also:
org.springframework.beans.factory.FactoryBean.getObject()

getObjectType

public Class getObjectType()
See Also:
org.springframework.beans.factory.FactoryBean.getObjectType()

isSingleton

public boolean isSingleton()
See Also:
org.springframework.beans.factory.FactoryBean.isSingleton()

setBeanFactory

public void setBeanFactory(BeanFactory beanFactory)
throws org.springframework.beans.BeansException

setInterceptorNames

public void setInterceptorNames(String[] interceptorNames)
Set the list of Interceptor/Advisor bean names. This must always be set to use this factory bean in a bean factory.

setProxyInterfaces

public void setProxyInterfaces(String[] interfaceNames)
throws AspectException,
java.lang.ClassNotFoundException
Set the names of the interfaces we're proxying. If no interface is given, a CGLIB for the actual class will be created.

setSingleton

public void setSingleton(boolean singleton)
Set the value of the singleton property. Governs whether this factory should always return the same proxy instance (which implies the same target) or whether it should return a new prototype instance, which implies that the target and interceptors may be new instances also, if they are obtained from prototype bean definitions. This allows for fine control of independence/uniqueness in the object graph.
Parameters:
singleton

Association Links

to Class java.lang.String

This suffix in a value in an interceptor list indicates to expand globals.

to Class org.springframework.beans.factory.BeanFactory

Owning bean factory, which cannot be changed after this object is initialized.

to Class java.util.Map

Map from PointCut or interceptor to bean name or null, depending on where it was sourced from. If it's sourced from a bean name, it will need to be refreshed each time a new prototype instance is created.

to Class java.lang.String

Names of interceptor and pointcut beans in the factory. Default is for globals expansion only.

to Class java.lang.String