1 14 15 package com.jdon.aop.reflection; 16 17 import java.lang.reflect.Method ; 18 19 import com.jdon.bussinessproxy.TargetMetaDef; 20 import com.jdon.bussinessproxy.meta.MethodMetaArgs; 21 import com.jdon.bussinessproxy.target.TargetServiceFactory; 22 import com.jdon.container.ContainerWrapper; 23 import com.jdon.container.access.TargetMetaRequest; 24 import com.jdon.container.visitor.ComponentVisitor; 25 import com.jdon.util.Debug; 26 27 public class MethodConstructor { 28 29 private final static String module = MethodConstructor.class.getName(); 30 31 private MethodInvokerUtil methodInvokerUtil = new MethodInvokerUtil(); 32 33 34 35 38 public MethodInvokerUtil getMethodInvokerUtil() { 39 return methodInvokerUtil; 40 } 41 42 51 public Method createMethod(TargetServiceFactory targetServiceFactory, 52 TargetMetaRequest targetMetaRequest) { 53 Method method = null; 54 Debug.logVerbose("[JdonFramework] enter create the Method " , module); 55 try { 56 if (targetMetaRequest.getTargetMetaDef().isEJB()) { 57 Object obj= methodInvokerUtil.createTargetObject(targetServiceFactory, targetMetaRequest); 58 method = createObjectMethod(obj, targetMetaRequest.getMethodMetaArgs()); 59 }else{ 60 method = createPojoMethod(targetMetaRequest); 61 } 62 } catch (Exception ex) { 63 Debug.logError("[JdonFramework] createMethod error: " + ex, module); 64 } 65 66 return method; 67 68 } 69 70 71 77 public Method createPojoMethod(TargetMetaRequest targetMetaRequest) { 78 Method method = null; 79 TargetMetaDef targetMetaDef = targetMetaRequest.getTargetMetaDef(); 80 MethodMetaArgs methodMetaArgs = targetMetaRequest.getMethodMetaArgs(); 81 Debug.logVerbose("[JdonFramework] createPOJO Method :" + methodMetaArgs.getMethodName() + " for target service: " + targetMetaDef.getName(), module); 82 try { 83 ComponentVisitor cm = targetMetaRequest.getComponentVisitor(); 84 Class thisCLass = cm.getContainerWrapper().getComponentClass(targetMetaDef.getName()); 85 if (thisCLass == null) return null; 86 method = thisCLass.getMethod(methodMetaArgs.getMethodName(), 87 methodMetaArgs.getParamTypes()); 88 } catch (NoSuchMethodException ne) { 89 Debug.logError("[JdonFramework] method name:" 90 + methodMetaArgs.getMethodName() + " or method parameters type don't match with your service's method", module); 91 Object types[] = methodMetaArgs.getParamTypes(); 92 for(int i = 0; i<types.length; i ++){ 93 Debug.logError("[JdonFramework]service's method parameter type must be:" + types[i] + "; ", module); 94 } 95 } catch (Exception ex) { 96 Debug.logError("[JdonFramework] createPojoMethod error: " + ex, module); 97 } 98 99 return method; 100 101 } 102 103 109 public Method createObjectMethod(Object ownerClass, MethodMetaArgs methodMetaArgs) { 110 Method m = null; 111 try { 112 m = ownerClass.getClass().getMethod(methodMetaArgs.getMethodName(), 113 methodMetaArgs.getParamTypes()); 114 } catch (NoSuchMethodException nsme) { 115 String errS = " NoSuchMethod:" + methodMetaArgs.getMethodName() + " in MethodMetaArgs of className:" 116 + ownerClass.getClass().getName(); 117 Debug.logError(errS, module); 118 } catch (Exception ex) { 119 Debug.logError("[JdonFramework] createMethod error:" + ex, module); 120 } 121 return m; 122 } 123 124 131 public Method createObjectMethod(Object ownerClass, String methodName, 132 Class [] paramTypes) { 133 Method m = null; 134 try { 135 m = ownerClass.getClass().getMethod(methodName, paramTypes); 136 } catch (NoSuchMethodException nsme) { 137 String errS = " NoSuchMethod:" + methodName + " in className:" 138 + ownerClass.getClass().getName() + " or method's args type error"; 139 Debug.logError(errS, module); 140 } catch (Exception ex) { 141 Debug.logError("[JdonFramework] createMethod error:" + ex, module); 142 } 143 return m; 144 } 145 146 } 147 | Popular Tags |