1 16 package com.jdon.aop.interceptor; 17 18 import java.util.ArrayList ; 19 import java.util.List ; 20 21 import org.aopalliance.intercept.MethodInterceptor; 22 import org.aopalliance.intercept.MethodInvocation; 23 24 import com.jdon.aop.reflection.ProxyMethodInvocation; 25 import com.jdon.bussinessproxy.TargetMetaDef; 26 import com.jdon.container.ContainerWrapper; 27 import com.jdon.container.access.TargetMetaRequest; 28 import com.jdon.container.finder.ComponentKeys; 29 import com.jdon.container.finder.ContainerCallback; 30 import com.jdon.container.visitor.ComponentVisitor; 31 import com.jdon.controller.service.Stateful; 32 import com.jdon.util.Debug; 33 34 48 public class StatefulInterceptor implements MethodInterceptor { 49 private final static String module = StatefulInterceptor.class.getName(); 50 51 private List isStatefulCache = new ArrayList (); 52 53 private List unStatefulCache = new ArrayList (); 54 55 private ContainerCallback containerCallback; 56 57 58 61 public StatefulInterceptor(ContainerCallback containerCallback) { 62 super(); 63 this.containerCallback = containerCallback; 64 } 65 66 72 public Object invoke(MethodInvocation invocation) throws Throwable { 73 ProxyMethodInvocation pmi = (ProxyMethodInvocation)invocation; 74 TargetMetaRequest targetMetaRequest = pmi.getTargetMetaRequest(); 75 TargetMetaDef targetMetaDef = targetMetaRequest.getTargetMetaDef(); 76 if (targetMetaDef.isEJB()) 77 return invocation.proceed(); 78 79 if (!isStateful(targetMetaDef)){ 80 return invocation.proceed(); 83 } 84 Debug.logVerbose("[JdonFramework] enter StatefulInterceptor", module); 85 Object result = null; 86 try { 87 ComponentVisitor cm = targetMetaRequest.getComponentVisitor(); 88 targetMetaRequest.setVisitableName(ComponentKeys.TARGETSERVICE_FACTORY); 89 Debug.logVerbose(ComponentKeys.TARGETSERVICE_FACTORY 90 + " in action (Stateful)", module); 91 Object targetObjRef = cm.visit(targetMetaRequest); 92 pmi.setThis(targetObjRef); 93 result = invocation.proceed(); 94 }catch(Exception ex){ 95 Debug.logError("[JdonFramework]StatefulInterceptor error: " + ex, module); 96 } 97 return result; 98 } 99 100 public boolean isStateful(TargetMetaDef targetMetaDef) { 101 boolean found = false; 102 if (isStatefulCache.contains(targetMetaDef.getName())) { 103 found = true; 104 }else if(!unStatefulCache.contains(targetMetaDef.getName())){ 105 Debug.logVerbose("[JdonFramework] check if it is a isStateful", module); 106 ContainerWrapper containerWrapper = containerCallback.getContainerWrapper(); 107 Class thisCLass = containerWrapper.getComponentClass(targetMetaDef.getName()); 108 if (Stateful.class.isAssignableFrom(thisCLass)) { 109 found = true; 110 isStatefulCache.add(targetMetaDef.getName()); 111 }else{ 112 unStatefulCache.add(targetMetaDef.getName()); 113 } 114 } 115 return found; 116 } 117 118 119 } 120 | Popular Tags |