1 16 17 package org.springframework.aop.support; 18 19 import org.aopalliance.aop.Advice; 20 21 import org.springframework.beans.factory.BeanFactory; 22 import org.springframework.beans.factory.BeanFactoryAware; 23 import org.springframework.util.Assert; 24 25 38 public abstract class AbstractBeanFactoryPointcutAdvisor extends AbstractPointcutAdvisor implements BeanFactoryAware { 39 40 private String adviceBeanName; 41 42 private BeanFactory beanFactory; 43 44 private Advice advice; 45 46 private final Object adviceMonitor = new Object (); 47 48 49 57 public void setAdviceBeanName(String adviceBeanName) { 58 this.adviceBeanName = adviceBeanName; 59 } 60 61 64 public String getAdviceBeanName() { 65 return this.adviceBeanName; 66 } 67 68 public void setBeanFactory(BeanFactory beanFactory) { 69 this.beanFactory = beanFactory; 70 } 71 72 73 public Advice getAdvice() { 74 synchronized (this.adviceMonitor) { 75 if (this.advice == null && this.adviceBeanName != null) { 76 Assert.state(this.beanFactory != null, "BeanFactory must be set to resolve 'adviceBeanName'"); 77 this.advice = (Advice) this.beanFactory.getBean(this.adviceBeanName, Advice.class); 78 } 79 return this.advice; 80 } 81 } 82 83 public String toString() { 84 return getClass().getName() + ": advice bean '" + getAdviceBeanName() + "'"; 85 } 86 87 } 88 | Popular Tags |