1 16 17 package org.springframework.aop.config; 18 19 import java.lang.reflect.Method ; 20 21 import org.springframework.beans.BeanUtils; 22 import org.springframework.beans.factory.BeanFactory; 23 import org.springframework.beans.factory.BeanFactoryAware; 24 import org.springframework.beans.factory.FactoryBean; 25 import org.springframework.util.StringUtils; 26 27 33 public class MethodLocatingFactoryBean implements FactoryBean, BeanFactoryAware { 34 35 private String targetBeanName; 36 37 private String methodName; 38 39 private Method method; 40 41 42 47 public void setTargetBeanName(String targetBeanName) { 48 this.targetBeanName = targetBeanName; 49 } 50 51 56 public void setMethodName(String methodName) { 57 this.methodName = methodName; 58 } 59 60 public void setBeanFactory(BeanFactory beanFactory) { 61 if (!StringUtils.hasText(this.targetBeanName)) { 62 throw new IllegalArgumentException ("Property 'targetBeanName' is required"); 63 } 64 if (!StringUtils.hasText(this.methodName)) { 65 throw new IllegalArgumentException ("Property 'methodName' is required"); 66 } 67 68 Class beanClass = beanFactory.getType(this.targetBeanName); 69 if (beanClass == null) { 70 throw new IllegalArgumentException ("Can't determine type of bean with name '" + this.targetBeanName + "'"); 71 } 72 this.method = BeanUtils.resolveSignature(this.methodName, beanClass); 73 74 if (this.method == null) { 75 throw new IllegalArgumentException ("Unable to locate method [" + this.methodName + 76 "] on bean [" + this.targetBeanName + "]"); 77 } 78 } 79 80 81 public Object getObject() throws Exception { 82 return this.method; 83 } 84 85 public Class getObjectType() { 86 return Method .class; 87 } 88 89 public boolean isSingleton() { 90 return true; 91 } 92 93 } 94 | Popular Tags |