1 7 package com.inversoft.verge.mvc.controller; 8 9 10 import java.lang.reflect.Method ; 11 12 import com.inversoft.beans.BeanException; 13 import com.inversoft.beans.JavaBeanTools; 14 import com.inversoft.util.ReflectionException; 15 import com.inversoft.util.ReflectionTools; 16 17 18 30 public class BeanHandle { 31 32 String handleName; 33 Class beanClass; 34 Class [] paramTypes; 35 Method method; 36 37 38 46 public BeanHandle(String handleName, Class beanClass, Class [] paramTypes) 47 throws BeanException { 48 this.handleName = handleName; 49 this.beanClass = beanClass; 50 this.paramTypes = paramTypes; 51 52 initialize(); 53 } 54 55 56 61 protected void initialize() throws BeanException { 62 String handleMethodName = JavaBeanTools.makeHandle(handleName); 63 method = ReflectionTools.findMethod(beanClass, handleMethodName, 64 paramTypes, 0); 65 if (method == null) { 66 throw new BeanException("Invalid handle method: " + handleMethodName); 67 } 68 } 69 70 75 protected Class [] getParamTypes() { 76 return paramTypes; 77 } 78 79 84 public Method getHandleMethod() { 85 return method; 86 } 87 88 93 public String getHandleName() { 94 return handleName; 95 } 96 97 108 public Object invokeHandle(Object bean, Object [] params) throws BeanException { 109 110 try { 111 return ReflectionTools.invokeMethod(method, bean, params); 112 } catch (ReflectionException re) { 113 114 Throwable target = re.getTarget(); 115 if (target == null) { 116 throw new BeanException(re.getMessage()); 117 } else if (target instanceof RuntimeException ) { 118 throw (RuntimeException ) target; 119 } else if (target instanceof Error ) { 120 throw (Error ) target; 121 } else { 122 throw new BeanException(target); 123 } 124 } 125 } 126 } | Popular Tags |