edu.utah.further.core.util.aop
Class SelectiveAspectJAutoProxyCreator

java.lang.Object
  extended by org.springframework.aop.framework.ProxyConfig
      extended by org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator
          extended by org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator
              extended by org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator
                  extended by org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator
                      extended by edu.utah.further.core.util.aop.SelectiveAspectJAutoProxyCreator
All Implemented Interfaces:
Serializable, org.springframework.aop.framework.AopInfrastructureBean, org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.config.BeanPostProcessor, org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor, org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor, org.springframework.core.Ordered, org.springframework.core.PriorityOrdered

public class SelectiveAspectJAutoProxyCreator
extends org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator
implements org.springframework.core.PriorityOrdered

An extension of AnnotationAwareAspectJAutoProxyCreator, the aspect behind the <aop:aspectj-autoproxy> element that scans and advises beans whose names match any number of specified regular expressions wired to this creator.

That is, while <aop:include> allows specifying which aspects are used by AnnotationAwareAspectJAutoProxyCreator, this bean also also allows specifying a subset of the beans in the application context to be auto-proxied. This is done using the analogous elements <core:include-bean> within the <core:aspectj-autoproxy> that hides SelectiveAspectJAutoProxyCreator's bean definition. For example, to only proxy beans under the edu.utah.further package, use

      <core:aspectj-autoproxy>
         </core:include-bean value="edu\.utah\.further\..+" />
      </core:aspectj-autoproxy>
 

Additionally, this aspect prevents any dynamic CGLIB proxies from being auto-proxied because they will always trigger the error below when an AspectJ class-level annotation matching pattern such as @within(edu.utah.further.SomeAnnotationType) is used in a point-cut.

This is not only faster, but especially useful in an OSGi setting, because some OSGi services like pooledConnectionFactory are dynamic proxies, and crash AnnotationAwareAspectJAutoProxyCreator on the error

 Caused by: org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException: warning can't determine annotations of missing type com.springsource.kernel.dmfragment.internal.KernelMBeanExporter
  [Xlint:cantFindType]
 

This class was built for extension. -----------------------------------------------------------------------------------
(c) 2008-2011 FURTHeR Project, Health Sciences IT, University of Utah
Contact: Dr. Scott Narus <scott.narus@hsc.utah.edu>
Biomedical Informatics, 26 South 2000 East
Room 5775 HSEB, Salt Lake City, UT 84112
Day Phone: 1-801-213-3288
-----------------------------------------------------------------------------------

Version:
May 28, 2010
Author:
Oren E. Livne <oren.livne@utah.edu>
See Also:
https://jira.chpc.utah.edu/browse/FUR-900, http://forum.springsource.org/showthread.php?t=85396, https://issuetracker.springsource.com/browse/DMS-2390, 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 interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
 
Constructor Summary
SelectiveAspectJAutoProxyCreator()
           
 
Method Summary
protected  List<?> findAdvisorsThatCanApply(List candidateAdvisors, Class beanClass, String beanName)
          Search the given candidate Advisors to find all Advisors that can apply to the specified bean.
protected  List<?> findCandidateAdvisors()
          Find all candidate Advisors to use in auto-proxying.
protected  Object[] getAdvicesAndAdvisorsForBean(Class beanClass, String beanName, org.springframework.aop.TargetSource targetSource)
           
protected  boolean isBeanADynamicProxy(String beanClassName)
          Is this class name of a dynamic proxy bean generated by CGLIB.
protected  boolean isBeanProxied(String beanClassName)
          Is bean eligible for auto-proxying.
protected  boolean isEligibleAspectBean(String beanName)
           
protected  boolean isEligibleBeanForProxying(String beanClassName)
          Check whether the given application context bean is eligible for auto-proxying based on inclusion patterns.
 void setIncludeBeanPatterns(List<String> patterns)
          Set a list of regular expression patterns, matching eligible spring fully-qualified bean names in the application context.
 
Methods inherited from class org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator
initBeanFactory, isInfrastructureClass, setAspectJAdvisorFactory, setIncludePatterns
 
Methods inherited from class org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator
extendAdvisors, shouldSkip, sortAdvisors
 
Methods inherited from class org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator
advisorsPreFiltered, findEligibleAdvisors, isEligibleAdvisorBean, setBeanFactory
 
Methods inherited from class org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator
buildAdvisors, createProxy, customizeProxyFactory, determineCandidateConstructors, getBeanFactory, getCacheKey, getCustomTargetSource, getEarlyBeanReference, getOrder, isFrozen, isInfrastructureClass, postProcessAfterInitialization, postProcessAfterInstantiation, postProcessBeforeInitialization, postProcessBeforeInstantiation, postProcessPropertyValues, predictBeanType, setAdvisorAdapterRegistry, setApplyCommonInterceptorsFirst, setBeanClassLoader, setCustomTargetSourceCreators, setFrozen, setInterceptorNames, setOrder, setProxyClassLoader, shouldProxyTargetClass, wrapIfNecessary
 
Methods inherited from class org.springframework.aop.framework.ProxyConfig
copyFrom, isExposeProxy, isOpaque, isOptimize, isProxyTargetClass, setExposeProxy, setOpaque, setOptimize, setProxyTargetClass, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.springframework.core.Ordered
getOrder
 

Constructor Detail

SelectiveAspectJAutoProxyCreator

public SelectiveAspectJAutoProxyCreator()
Method Detail

getAdvicesAndAdvisorsForBean

protected Object[] getAdvicesAndAdvisorsForBean(Class beanClass,
                                                String beanName,
                                                org.springframework.aop.TargetSource targetSource)
Overrides:
getAdvicesAndAdvisorsForBean in class org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator

setIncludeBeanPatterns

public void setIncludeBeanPatterns(List<String> patterns)
Set a list of regular expression patterns, matching eligible spring fully-qualified bean names in the application context.

Default is to consider all beans as eligible for advice.

Parameters:
patterns - list of bean inclusion patterns

isBeanProxied

protected boolean isBeanProxied(String beanClassName)
Is bean eligible for auto-proxying.

Parameters:
beanClassName - fully-qualified class name of prospective bean to be advised
Returns:
is bean to be proxied

isBeanADynamicProxy

protected boolean isBeanADynamicProxy(String beanClassName)
Is this class name of a dynamic proxy bean generated by CGLIB.

Parameters:
beanClassName - fully-qualified class name
Returns:
true if and only if the class is thought to be a dynamic CGLIB proxy

isEligibleBeanForProxying

protected boolean isEligibleBeanForProxying(String beanClassName)
Check whether the given application context bean is eligible for auto-proxying based on inclusion patterns.

If no <core:include-bean> elements were used, then includeBeanPatterns will be null and all beans are included. If "includePatterns" is non-null, then one of the patterns must match.

Parameters:
beanClassName - fully-qualified class name of prospective bean to be advised
Returns:
is bean to be proxied

isEligibleAspectBean

protected boolean isEligibleAspectBean(String beanName)
Overrides:
isEligibleAspectBean in class org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator

findCandidateAdvisors

protected List<?> findCandidateAdvisors()
Find all candidate Advisors to use in auto-proxying.

Overrides:
findCandidateAdvisors in class org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator
Returns:
the List of candidate Advisors

findAdvisorsThatCanApply

protected List<?> findAdvisorsThatCanApply(List candidateAdvisors,
                                           Class beanClass,
                                           String beanName)
Search the given candidate Advisors to find all Advisors that can apply to the specified bean.

Overrides:
findAdvisorsThatCanApply in class org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator
Parameters:
candidateAdvisors - the candidate Advisors
beanClass - the target's bean class
beanName - the target's bean name
Returns:
the List of applicable Advisors
See Also:
ProxyCreationContext.getCurrentProxiedBeanName()


Copyright © 2011 Office of the AVP for Health Sci. IT. All Rights Reserved.