1 16 package com.jdon.aop.reflection; 17 18 import java.lang.reflect.InvocationTargetException ; 19 import java.lang.reflect.Method ; 20 import java.rmi.Remote ; 21 22 import javax.ejb.EJBObject ; 23 import javax.rmi.PortableRemoteObject ; 24 25 import com.jdon.bussinessproxy.target.TargetServiceFactory; 26 import com.jdon.container.access.TargetMetaRequest; 27 import com.jdon.container.finder.ComponentKeys; 28 import com.jdon.container.visitor.ComponentVisitor; 29 import com.jdon.util.Debug; 30 31 36 public class MethodInvokerUtil { 37 private final static String module = MethodInvokerUtil.class.getName(); 38 39 48 public Object execute(Method method, Object targetObj, Object [] p_args) throws Throwable { 49 try { 50 if ((method == null) || (targetObj == null)) 51 Debug.logError("[JdonFramework] no method or target, please check your configure", module); 52 if (p_args == null) p_args = new Object [0]; 53 Debug.logVerbose("[JdonFramework] method invoke: " + targetObj.getClass().getName() + " method=" + method.getName(), module); 54 Object result = method.invoke(targetObj, p_args); 55 Debug.logVerbose("[JdonFramework] method invoke successfully ", module); 56 return result; 57 } catch (IllegalArgumentException iex) { 58 String errorInfo = "Errors happened in your method:["+ targetObj.getClass().getName() + "." + method.getName() +"]"; 59 Debug.logError(errorInfo, module); 60 errorInfo = "[JdonFramework] method invoke IllegalArgumentException: " + iex 61 + " method argument type :["+ method.getParameterTypes() +"], but method arguments value p_args type:"+ p_args.getClass().getName() ; 62 Debug.logError(errorInfo, module); 63 throw new Throwable (errorInfo, iex); 64 } catch (InvocationTargetException ex) { 65 String errorInfo = "Errors happened in your method:["+ targetObj.getClass().getName() + "." + method.getName() +"]"; 66 Debug.logError(errorInfo, module); 67 throw new Throwable (errorInfo); 68 } catch (IllegalAccessException ex) { 69 String errorInfo = "Errors happened in your method:["+ targetObj.getClass().getName() + "." + method.getName() +"]"; 70 Debug.logError(errorInfo, module); 71 Debug.logError("[JdonFramework] method invoke IllegalAccessException: " + ex, module); 72 throw new Throwable ("access method:" + method + " " + ex, ex); 73 } catch (Exception ex) { 74 String errorInfo = "Errors happened in your method:["+ targetObj.getClass().getName() + "." + method.getName() +"]"; 75 Debug.logError(errorInfo, module); 76 Debug.logError("[JdonFramework] method invoke error: " + ex, module); 77 throw new Throwable (" method invoke error: " + ex); 78 } 79 80 } 81 82 91 public Object createTargetObject(TargetServiceFactory targetServiceFactory, TargetMetaRequest targetMetaRequest) { 92 Debug.logVerbose("[JdonFramework] now getTargetObject by visitor ", module); 93 Object targetObjRef = null; 94 try { 95 if (targetMetaRequest.getTargetMetaDef().isEJB()) { ComponentVisitor cm = targetMetaRequest.getComponentVisitor(); 97 targetMetaRequest.setVisitableName(ComponentKeys.TARGETSERVICE_FACTORY); 98 Debug.logVerbose(ComponentKeys.TARGETSERVICE_FACTORY + " in action (cache)", module); 99 targetObjRef = cm.visit(targetMetaRequest); 100 } else { 101 Debug.logVerbose("[JdonFramework] not active targer service instance cache !!!!", module); 102 targetObjRef = targetServiceFactory.create(targetMetaRequest.getTargetMetaDef()); 103 } 104 } catch (Exception e) { 105 Debug.logError("[JdonFramework]createTargetObject error: " + e, module); 106 } 107 return targetObjRef; 108 } 109 110 114 public Object [] narrowArgs(Object [] p_args) { 115 if (p_args == null) 116 return null; 117 int length = p_args.length; 118 Object [] result = new Object [length]; 119 for (int i = 0; i < length; i++) { 120 if (p_args[i] instanceof Remote ) 121 result[i] = PortableRemoteObject.narrow(p_args[i], EJBObject .class); 122 else 123 result[i] = p_args[i]; 124 } 125 return result; 126 } 127 128 } 129 | Popular Tags |