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.data.SessionContext; 31 import com.jdon.container.visitor.data.SessionContextAcceptable; 32 import com.jdon.util.Debug; 33 34 48 49 public class SessionContextInterceptor implements MethodInterceptor { 50 private final static String module = SessionContextInterceptor.class.getName(); 51 52 private List isSessionContextAcceptables = new ArrayList (); 53 54 private List unSessionContextAcceptables = new ArrayList (); 55 56 private ContainerCallback containerCallback; 57 58 public SessionContextInterceptor(ContainerCallback containerCallback) { 59 this.containerCallback = containerCallback; 60 } 61 62 66 public Object invoke(MethodInvocation invocation) throws Throwable { 67 ProxyMethodInvocation pmi = (ProxyMethodInvocation)invocation; 68 TargetMetaRequest targetMetaRequest = pmi.getTargetMetaRequest(); 69 TargetMetaDef targetMetaDef = targetMetaRequest.getTargetMetaDef(); 70 if (targetMetaDef.isEJB()) 71 return invocation.proceed(); 72 73 if (!isSessionContextAcceptable(targetMetaDef)){ 74 return invocation.proceed(); 77 } 78 Debug.logVerbose("[JdonFramework] enter SessionContextInterceptor", module); 79 80 Object result = null; 81 try { 82 Object targetObject = pmi.getThis(); 83 Debug.logVerbose("[JdonFramework] targetObject should be SessionContextAcceptable: " + targetObject.getClass().getName(), module); 84 SessionContextAcceptable myResult = (SessionContextAcceptable)targetObject; 85 targetMetaRequest.setVisitableName(ComponentKeys.SESSIONCONTEXT_FACTORY); 86 SessionContext sessionContext = targetMetaRequest.getComponentVisitor().visitSessionContext(targetMetaRequest); 87 myResult.setSessionContext(sessionContext); 88 89 result = invocation.proceed(); 90 91 }catch(Exception ex){ 92 Debug.logError("[JdonFramework]SessionContextInterceptor error: " + ex, module); 93 } 94 return result; 95 } 96 97 public boolean isSessionContextAcceptable(TargetMetaDef targetMetaDef) { 98 boolean found = false; 99 if (isSessionContextAcceptables.contains(targetMetaDef.getName())) { 100 found = true; 101 }else if(!unSessionContextAcceptables.contains(targetMetaDef.getName())){ 102 Debug.logVerbose("[JdonFramework] check if it is a isSessionContextAcceptable", module); 103 ContainerWrapper containerWrapper = containerCallback.getContainerWrapper(); 104 Class thisCLass = containerWrapper.getComponentClass(targetMetaDef.getName()); 105 if (SessionContextAcceptable.class.isAssignableFrom(thisCLass)) { 106 found = true; 107 isSessionContextAcceptables.add(targetMetaDef.getName()); 108 }else{ 109 unSessionContextAcceptables.add(targetMetaDef.getName()); 110 } 111 } 112 return found; 113 } 114 115 116 } 117 | Popular Tags |