1 16 17 package org.springframework.aop.framework.autoproxy; 18 19 import java.util.ArrayList ; 20 import java.util.Iterator ; 21 import java.util.List ; 22 23 import org.springframework.aop.TargetSource; 24 import org.springframework.beans.factory.BeanFactory; 25 import org.springframework.beans.factory.FactoryBean; 26 import org.springframework.util.Assert; 27 import org.springframework.util.PatternMatchUtils; 28 import org.springframework.util.StringUtils; 29 30 46 public class BeanNameAutoProxyCreator extends AbstractAutoProxyCreator { 47 48 private List beanNames; 49 50 51 63 public void setBeanNames(String [] beanNames) { 64 Assert.notEmpty(beanNames, "'beanNames' must not be empty"); 65 this.beanNames = new ArrayList (beanNames.length); 66 for (int i = 0; i < beanNames.length; i++) { 67 this.beanNames.add(StringUtils.trimWhitespace(beanNames[i])); 68 } 69 } 70 71 72 75 protected Object [] getAdvicesAndAdvisorsForBean(Class beanClass, String beanName, TargetSource targetSource) { 76 if (this.beanNames != null) { 77 for (Iterator it = this.beanNames.iterator(); it.hasNext();) { 78 String mappedName = (String ) it.next(); 79 if (FactoryBean.class.isAssignableFrom(beanClass)) { 80 if (!mappedName.startsWith(BeanFactory.FACTORY_BEAN_PREFIX)) { 81 continue; 82 } 83 mappedName = mappedName.substring(BeanFactory.FACTORY_BEAN_PREFIX.length()); 84 } 85 if (isMatch(beanName, mappedName)) { 86 return PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS; 87 } 88 } 89 } 90 return DO_NOT_PROXY; 91 } 92 93 102 protected boolean isMatch(String beanName, String mappedName) { 103 return PatternMatchUtils.simpleMatch(mappedName, beanName); 104 } 105 106 } 107 | Popular Tags |