1 16 17 package org.springframework.scheduling.support; 18 19 import java.lang.reflect.InvocationTargetException ; 20 21 import org.apache.commons.logging.Log; 22 import org.apache.commons.logging.LogFactory; 23 24 import org.springframework.beans.factory.BeanClassLoaderAware; 25 import org.springframework.beans.factory.InitializingBean; 26 import org.springframework.beans.support.ArgumentConvertingMethodInvoker; 27 import org.springframework.util.ClassUtils; 28 29 56 public class MethodInvokingRunnable extends ArgumentConvertingMethodInvoker 57 implements Runnable , BeanClassLoaderAware, InitializingBean { 58 59 protected final Log logger = LogFactory.getLog(getClass()); 60 61 private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); 62 63 64 public void setBeanClassLoader(ClassLoader classLoader) { 65 this.beanClassLoader = classLoader; 66 } 67 68 protected Class resolveClassName(String className) throws ClassNotFoundException { 69 return ClassUtils.forName(className, this.beanClassLoader); 70 } 71 72 public void afterPropertiesSet() throws ClassNotFoundException , NoSuchMethodException { 73 prepare(); 74 } 75 76 77 public void run() { 78 try { 79 invoke(); 80 } 81 catch (InvocationTargetException ex) { 82 logger.error(getInvocationFailureMessage(), ex); 83 } 85 catch (Throwable ex) { 86 logger.error(getInvocationFailureMessage(), ex); 87 } 89 } 90 91 protected String getInvocationFailureMessage() { 92 return "Invocation of method '" + getTargetMethod() + 93 "' on target object [" + getTargetObject() + "] failed"; 94 } 95 96 } 97 | Popular Tags |