1 15 16 package com.jdon.aop.reflection; 17 18 import java.lang.reflect.AccessibleObject ; 19 import java.lang.reflect.Method ; 20 import java.util.List ; 21 22 import org.aopalliance.intercept.MethodInterceptor; 23 import org.aopalliance.intercept.MethodInvocation; 24 25 import com.jdon.bussinessproxy.TargetMetaDef; 26 import com.jdon.bussinessproxy.target.TargetServiceFactory; 27 import com.jdon.container.access.TargetMetaRequest; 28 import com.jdon.util.Debug; 29 30 35 public class ProxyMethodInvocation implements MethodInvocation, 36 java.io.Serializable { 37 private final static String module = ProxyMethodInvocation.class.getName(); 38 39 protected TargetServiceFactory targetServiceFactory; 40 41 private TargetMetaRequest targetMetaRequest; 42 43 private Method method; 44 45 private Object [] args; 46 47 private Object target; 48 49 protected List interceptors; 50 51 protected MethodInvokerUtil mUtil; 52 53 protected int currentInterceptorInt = -1; 54 55 public ProxyMethodInvocation(List interceptors, 56 TargetMetaRequest targetMetaRequest, 57 TargetServiceFactory targetServiceFactory, Method method, 58 Object [] args) { 59 Debug.logVerbose("[JdonFramework] method.getName() :" + method.getName(), module); 60 this.targetMetaRequest = targetMetaRequest; 61 this.interceptors = interceptors; 62 this.targetServiceFactory = targetServiceFactory; 63 this.mUtil = new MethodInvokerUtil(); 64 this.method = method; 65 this.args = args; 66 } 67 68 71 public Object proceed() throws Throwable { 72 if (currentInterceptorInt == interceptors.size() - 1) { 75 Debug.logVerbose("[JdonFramework] finish call all inteceptors", module); 76 return methodInvoke(); 77 } 78 79 Object interceptor = interceptors.get(++currentInterceptorInt); 80 if (interceptor != null) { 81 MethodInterceptor methodInterceptor = (MethodInterceptor) interceptor; 82 return methodInterceptor.invoke(this); 85 } else { 86 Debug.logVerbose("[JdonFramework] null finish call all inteceptors", module); 87 return methodInvoke(); 88 } 89 } 90 91 private Object methodInvoke() throws Throwable { 92 Debug.logVerbose("[JdonFramework]enter method reflection ", module); 93 Object result = null; 94 try { 95 if (target == null){ Debug.logVerbose("[JdonFramework] all interceptors not set this target object, now create it", module); 97 target = mUtil.createTargetObject(targetServiceFactory, targetMetaRequest); 98 } 99 100 Debug.logVerbose("[JdonFramework] target:"+ target.getClass().getName() +" service's method:" 101 + method.getName()+ " running.. ", module); 102 103 if (targetMetaRequest.getTargetMetaDef().isEJB()) { 104 Debug.logVerbose("[JdonFramework] it is ejb target service", module); 105 result = mUtil.execute(method, target, mUtil.narrowArgs(args)); 106 } else { 107 Debug.logVerbose("[JdonFramework] it is pojo target service", module); 108 result = mUtil.execute(method, target, args); 109 } 110 } catch (Exception ex) { 111 Debug.logError("[JdonFramework]run error: " + ex, module); 112 throw new Throwable (ex); 113 } catch (Throwable tex) { 114 throw new Throwable (tex); 115 } 116 return result; 117 } 118 119 public TargetMetaDef getTargetMetaDef() { 120 return targetMetaRequest.getTargetMetaDef(); 121 } 122 123 124 public Object [] getArguments() { 125 return this.args; 126 } 127 128 public Object getThis() { 129 137 return target; 138 } 139 140 public void setThis(Object target) { 141 this.target = target; 142 } 143 144 public AccessibleObject getStaticPart() { 145 return null; 146 } 147 148 public Method getMethod() { 149 return method; 150 } 151 152 153 156 public TargetMetaRequest getTargetMetaRequest() { 157 return targetMetaRequest; 158 } 159 162 public void setTargetMetaRequest(TargetMetaRequest targetMetaRequest) { 163 this.targetMetaRequest = targetMetaRequest; 164 } 165 } 166 | Popular Tags |