org.springframework.aop.framework.autoproxy
Class AbstractAutoProxyCreator

org.springframework.aop.framework.ProxyConfig
  |
  +--org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator
Direct Known Subclasses:
AbstractAdvisorAutoProxyCreator, BeanNameAutoProxyCreator

public abstract class AbstractAutoProxyCreator
extends ProxyConfig
implements BeanFactoryAware, BeanPostProcessor, Ordered

BeanPostProcessor implementation that wraps a group of beans with AOP proxies that delegate to the given interceptors before invoking the bean itself.

This class distinguishes between "common" interceptors: shared for all proxies it creators, and "specific" interceptors: unique per bean instance. There need not be any common interceptors. If there are, they are set using the interceptorNames property. As with ProxyFactoryBean, interceptors names in the current factory are used rather than bean references to allow correct handling of prototype advisors and interceptors: for example, to support stateful mixins. Any advice type is supported for "interceptorNames" entries.

Such autoproxying is particularly useful if there's a large number of beans that need to be wrapped with similar proxies, i.e. delegating to the same interceptors. Instead of x repetitive proxy definitions for x target beans, you can register one single such post processor with the bean factory to achieve the same effect.

Subclasses can apply any strategy to decide if a bean is to be proxied, e.g. by type, by name, by definition details, etc. They can also return additional interceptors that should just be applied to the specific bean instance. The default concrete implementation is BeanNameAutoProxyCreator, identifying the beans to be proxied via a list of bean names.

Any number of TargetSourceCreator implementations can be used with any subclass, to create a custom target source--for example, to pool prototype objects. Autoproxying will occur even if there is no advice if a TargetSourceCreator specifies a custom TargetSource. If there are no TargetSourceCreators set, or if none matches, a SingletonTargetSource will be used by default to wrap the bean to be autoproxied.

Author:
Juergen Hoeller, Rod Johnson
Version: $Id: AbstractAutoProxyCreator.java,v 1.5 2004/01/14 07:35:50 jhoeller Exp $
Since: October 13, 2003
See Also: setInterceptorNames(java.lang.String[]), BeanNameAutoProxyCreator

Method Summary
 final intgetOrder()
           
 ObjectpostProcessAfterInitialization(Object bean, String name)
          Create a proxy with the configured interceptors if the bean is identified as one to proxy by the subclass.
 ObjectpostProcessBeforeInitialization(Object bean, String name)
           
 voidsetApplyCommonInterceptorsFirst(boolean applyCommonInterceptorsFirst)
          Set whether the common interceptors should be applied before bean-specific ones.
 voidsetBeanFactory(BeanFactory beanFactory)
           
 voidsetCustomTargetSourceCreators(List l)
          Set custom TargetSourceCreators to be applied in this order.
 voidsetInterceptorNames(String[] interceptorNames)
          Set the common interceptors.
 final voidsetOrder(int order)
          Set the ordering which will apply to this class's implementation of Ordered, used by bean post processors.

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

Method Detail

getOrder

public final int getOrder()

postProcessAfterInitialization

public Object postProcessAfterInitialization(Object bean, String name)
throws org.springframework.beans.BeansException
Create a proxy with the configured interceptors if the bean is identified as one to proxy by the subclass.
See Also:
getInterceptorsAndAdvisorsForBean(java.lang.Object,java.lang.String)

postProcessBeforeInitialization

public Object postProcessBeforeInitialization(Object bean, String name)

setApplyCommonInterceptorsFirst

public void setApplyCommonInterceptorsFirst(boolean applyCommonInterceptorsFirst)
Set whether the common interceptors should be applied before bean-specific ones. Default is true; else, bean-specific interceptors will get applied first.

setBeanFactory

public void setBeanFactory(BeanFactory beanFactory)
See Also:
org.springframework.beans.factory.BeanFactoryAware.setBeanFactory(org.springframework.beans.factory.BeanFactory)

setCustomTargetSourceCreators

public void setCustomTargetSourceCreators(List l)
Set custom TargetSourceCreators to be applied in this order. If the list is empty, or they all return null, a SingletonTargetSource will be created.
TargetSourceCreators can only be invoked if this post processor is used in a BeanFactory, and its BeanFactoryAware callback is used.
Parameters:
l - list of TargetSourceCreator. Ordering is significant: the TargetSource returned from the first matching TargetSourceCreator (that is, the first that returns non-null) will be used.

setInterceptorNames

public void setInterceptorNames(String[] interceptorNames)
Set the common interceptors. These must be bean names in the current factory. They can be of any advice or# advisor type Spring supports. If this property isn't set, there will be zero common interceptors. This is perfectly valid, if "specific" interceptors such as matching Advisors are all we want.

setOrder

public final void setOrder(int order)
Set the ordering which will apply to this class's implementation of Ordered, used by bean post processors. Default value is Integer.MAX_VALUE, meaning that it's non-ordered.
Parameters:
order - ordering value

Association Links

to Class java.lang.String

Names of common interceptors. We must use bean name rather than object references to handle prototype advisors/interceptors. Default is the empty array: no common interceptors.

to Class java.util.List

to Class org.springframework.beans.factory.BeanFactory