1 16 17 package org.springframework.aop.config; 18 19 import org.springframework.aop.aspectj.AspectInstanceFactory; 20 import org.springframework.beans.factory.BeanFactory; 21 import org.springframework.beans.factory.BeanFactoryAware; 22 import org.springframework.core.Ordered; 23 import org.springframework.util.StringUtils; 24 25 33 public class SimpleBeanFactoryAwareAspectInstanceFactory implements AspectInstanceFactory, BeanFactoryAware { 34 35 private String aspectBeanName; 36 37 private BeanFactory beanFactory; 38 39 40 44 public void setAspectBeanName(String aspectBeanName) { 45 this.aspectBeanName = aspectBeanName; 46 } 47 48 public void setBeanFactory(BeanFactory beanFactory) { 49 this.beanFactory = beanFactory; 50 if (!StringUtils.hasText(this.aspectBeanName)) { 51 throw new IllegalArgumentException ("aspectBeanName is required"); 52 } 53 } 54 55 56 60 public Object getAspectInstance() { 61 return this.beanFactory.getBean(this.aspectBeanName); 62 } 63 64 public int getOrder() { 65 if (this.beanFactory.isSingleton(this.aspectBeanName) && 66 this.beanFactory.isTypeMatch(this.aspectBeanName, Ordered.class)) { 67 return ((Ordered) this.beanFactory.getBean(this.aspectBeanName)).getOrder(); 68 } 69 return Ordered.LOWEST_PRECEDENCE; 70 } 71 72 } 73 | Popular Tags |