1 15 16 package com.jdon.aop; 17 18 import java.lang.reflect.Method ; 19 import java.util.List ; 20 21 import org.aopalliance.intercept.MethodInvocation; 22 23 import com.jdon.aop.joinpoint.AdvisorChainFactory; 24 import com.jdon.aop.reflection.MethodConstructor; 25 import com.jdon.aop.reflection.ProxyMethodInvocation; 26 import com.jdon.bussinessproxy.meta.MethodMetaArgs; 27 import com.jdon.bussinessproxy.target.TargetServiceFactory; 28 import com.jdon.container.access.TargetMetaRequest; 29 import com.jdon.util.Debug; 30 31 36 public class AopClient { 37 38 private final static String module = AopClient.class.getName(); 39 40 private AdvisorChainFactory advisorChainFactory; 41 42 private TargetServiceFactory targetServiceFactory; 43 44 private MethodConstructor methodConstructor; 45 46 public AopClient(AdvisorChainFactory advisorChainFactory, 47 48 TargetServiceFactory targetServiceFactory) { 49 this.advisorChainFactory = advisorChainFactory; 50 this.targetServiceFactory = targetServiceFactory; 51 this.methodConstructor = new MethodConstructor(); 52 } 53 54 60 public Object invoke(TargetMetaRequest targetMetaRequest) throws 61 Throwable { 62 Debug.logVerbose("[JdonFramework] enter AOP invoker for:" +targetMetaRequest.getTargetMetaDef().getClassName() 63 +" method:" + targetMetaRequest.getMethodMetaArgs().getMethodName(), module); 64 65 Object result = null; 66 MethodInvocation methodInvocation = null; 67 try { 68 List chain = advisorChainFactory.create(targetMetaRequest.getTargetMetaDef()); 69 Object [] args = targetMetaRequest.getMethodMetaArgs().getArgs(); 70 Method method = methodConstructor.createMethod(targetServiceFactory, targetMetaRequest); 71 methodInvocation = new ProxyMethodInvocation(chain, targetMetaRequest, targetServiceFactory, method, args); 72 Debug.logVerbose("[JdonFramework] MethodInvocation will proceed ... ", module); 73 result = methodInvocation.proceed(); 74 } catch (Exception ex) { 75 Debug.logError(ex, module); 76 throw new Exception (ex); 77 } catch (Throwable ex) { 78 throw new Throwable (ex); 79 } 80 return result; 81 } 82 83 public Object invoke(TargetMetaRequest targetMetaRequest, 84 Method method, Object [] args) throws Throwable { 85 Debug.logVerbose("[JdonFramework] enter AOP invoker2 for:" +targetMetaRequest.getTargetMetaDef().getClassName() 86 +" method:" + method.getName(), module); 87 88 89 Object result = null; 90 MethodInvocation methodInvocation = null; 91 try { 92 List chain = advisorChainFactory.create(targetMetaRequest.getTargetMetaDef()); 93 methodInvocation = new ProxyMethodInvocation(chain, targetMetaRequest, targetServiceFactory, method, args); 94 Debug.logVerbose("[JdonFramework] MethodInvocation will proceed ... ", module); 95 result = methodInvocation.proceed(); 96 } catch (Exception ex) { 97 Debug.logError(ex, module); 98 throw new Exception (ex); 99 } catch (Throwable ex) { 100 throw new Throwable (ex); 101 } 102 return result; 103 104 } 105 106 } 107 | Popular Tags |