1 17 package org.apache.servicemix.beanflow.support; 18 19 import java.lang.reflect.InvocationTargetException ; 20 import java.lang.reflect.Method ; 21 import java.util.concurrent.Callable ; 22 23 28 public class MethodReflector<T> implements Callable <T> { 29 30 protected static final Object [] NO_ARGUMENTS = {}; 31 32 private final Object source; 33 private final Method method; 34 private final Object [] arguments; 35 36 public MethodReflector(Object source, Method method) { 37 this(source, method, NO_ARGUMENTS); 38 } 39 40 public MethodReflector(Object source, Method method, Object [] arguments) { 41 this.source = source; 42 this.method = method; 43 this.arguments = arguments; 44 } 45 46 @SuppressWarnings ("unchecked") 47 public T call() throws Exception { 48 try { 49 return (T) method.invoke(source, arguments); 50 } 51 catch (InvocationTargetException e) { 52 Throwable targetException = e.getTargetException(); 53 if (targetException instanceof Exception ) { 54 throw (Exception ) targetException; 55 } 56 else { 57 throw e; 58 } 59 } 60 } 61 } 62 | Popular Tags |