org.springframework.aop.framework.autoproxy
Class AbstractAdvisorAutoProxyCreator

java.lang.Object
  extended byorg.springframework.aop.framework.ProxyConfig
      extended byorg.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator
          extended byorg.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator
All Implemented Interfaces:
BeanFactoryAware, BeanPostProcessor, Ordered, Serializable
Direct Known Subclasses:
DefaultAdvisorAutoProxyCreator

public abstract class AbstractAdvisorAutoProxyCreator
extends AbstractAutoProxyCreator

Abstract BeanPostProcessor implementation that creates AOP proxies. This class is completely generic; it contains no special code to handle any particular aspects, such as pooling aspects.

Subclasses must implement the abstract findCandidateAdvisors() method to return a list of Advisors applying to any object. Subclasses can also override the inherited shouldSkip() method to exclude certain objects from autoproxying, but they must be careful to invoke the shouldSkip() method of this class, which tries to avoid circular reference problems and infinite loops.

Advisors or advices requiring ordering should implement the Ordered interface. This class sorts advisors by Ordered order value. Advisors that don't implement the Ordered interface will be considered to be unordered, and will appear at the end of the advisor chain in undefined order.

Author:
Rod Johnson
See Also:
findCandidateAdvisors(), Serialized Form

Field Summary
 
Fields inherited from class org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator
DO_NOT_PROXY, logger, PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS
 
Fields inherited from class org.springframework.aop.framework.ProxyConfig
exposeProxy
 
Constructor Summary
AbstractAdvisorAutoProxyCreator()
           
 
Method Summary
protected abstract  List findCandidateAdvisors()
          Find all candidate advisors to use in auto-proxying.
protected  List findEligibleAdvisors(Class clazz)
          Find all eligible advices and for autoproxying this class.
protected  Object[] getAdvicesAndAdvisorsForBean(Object bean, String name, TargetSource targetSource)
          Return whether the given bean is to be proxied, what additional advices (e.g.
 void setBeanFactory(BeanFactory beanFactory)
          We override this method to ensure that all candidate advisors are materialized under a stack trace including this bean.
protected  boolean shouldSkip(Object bean, String name)
          We override this to ensure that we don't get into circular reference hell when our own infrastructure (such as this class) depends on advisors that depend on beans...
protected  List sortAdvisors(List advisors)
          Sort advisors based on ordering.
 
Methods inherited from class org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator
customizeProxyFactory, getBeanFactory, getCustomTargetSource, getOrder, isInfrastructureClass, postProcessAfterInitialization, postProcessBeforeInitialization, setAdvisorAdapterRegistry, setApplyCommonInterceptorsFirst, setCustomTargetSourceCreators, setInterceptorNames, setOrder
 
Methods inherited from class org.springframework.aop.framework.ProxyConfig
copyFrom, getAopProxyFactory, getExposeProxy, getOpaque, getOptimize, getProxyTargetClass, isExposeProxy, isFrozen, isOpaque, isOptimize, isProxyTargetClass, setAopProxyFactory, setExposeProxy, setFrozen, setOpaque, setOptimize, setProxyTargetClass, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractAdvisorAutoProxyCreator

public AbstractAdvisorAutoProxyCreator()
Method Detail

setBeanFactory

public void setBeanFactory(BeanFactory beanFactory)
We override this method to ensure that all candidate advisors are materialized under a stack trace including this bean. Otherwise, the dependencies won't be apparent to the circular-reference prevention strategy in AbstractBeanFactory.

Specified by:
setBeanFactory in interface BeanFactoryAware
Overrides:
setBeanFactory in class AbstractAutoProxyCreator

getAdvicesAndAdvisorsForBean

protected Object[] getAdvicesAndAdvisorsForBean(Object bean,
                                                String name,
                                                TargetSource targetSource)
Description copied from class: AbstractAutoProxyCreator
Return whether the given bean is to be proxied, what additional advices (e.g. AOP Alliance interceptors) and advisors to apply.

The previous name of this method was "getInterceptorAndAdvisorForBean". It has been renamed in the course of general terminology clarification in Spring 1.1. An AOP Alliance Interceptor is just a special form of Advice, so the generic Advice term is preferred now.

The third parameter, customTargetSource, is new in Spring 1.1; add it to existing implementations of this method.

Specified by:
getAdvicesAndAdvisorsForBean in class AbstractAutoProxyCreator
Parameters:
bean - the new bean instance
name - the name of the bean
targetSource - targetSource returned by getTargetSource() method: may be ignored. Will be null unless a custom target source is in use.
Returns:
an array of additional interceptors for the particular bean; or an empty array if no additional interceptors but just the common ones; or null if no proxy at all, not even with the common interceptors. See constants DO_NOT_PROXY and PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS.
See Also:
AbstractAutoProxyCreator.postProcessAfterInitialization(java.lang.Object, java.lang.String), AbstractAutoProxyCreator.DO_NOT_PROXY, AbstractAutoProxyCreator.PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS

findEligibleAdvisors

protected List findEligibleAdvisors(Class clazz)
Find all eligible advices and for autoproxying this class.

Returns:
the empty list, not null, if there are no pointcuts or interceptors
See Also:
findCandidateAdvisors()

sortAdvisors

protected List sortAdvisors(List advisors)
Sort advisors based on ordering.

See Also:
Ordered, OrderComparator

shouldSkip

protected boolean shouldSkip(Object bean,
                             String name)
We override this to ensure that we don't get into circular reference hell when our own infrastructure (such as this class) depends on advisors that depend on beans... We use a ControlFlow object to check that we didn't arrived at this call via this classes findCandidateAdvisors() method.

Overrides:
shouldSkip in class AbstractAutoProxyCreator
Parameters:
bean - the new bean instance
name - the name of the bean
See Also:
ControlFlow

findCandidateAdvisors

protected abstract List findCandidateAdvisors()
Find all candidate advisors to use in auto-proxying.

Returns:
list of Advisors


Copyright (C) 2003-2004 The Spring Framework Project.