1 15 16 package com.jdon.container.visitor; 17 18 import java.util.HashMap ; 19 import java.util.Map ; 20 21 import javax.servlet.http.HttpSessionBindingEvent ; 22 import javax.servlet.http.HttpSessionBindingListener ; 23 24 import com.jdon.container.ContainerWrapper; 25 import com.jdon.container.access.TargetMetaRequest; 26 import com.jdon.container.finder.ComponentKeys; 27 import com.jdon.container.visitor.data.SessionContext; 28 import com.jdon.util.Debug; 29 30 49 public class HttpSessionProxyVisitor implements ComponentVisitor, HttpSessionBindingListener { 50 private final static String module = HttpSessionProxyVisitor.class.getName(); 51 52 66 private Map componentsboxs = new HashMap (); 67 68 private ComponentVisitor componentVisitor; 69 70 public HttpSessionProxyVisitor(ComponentVisitor componentVisitor) { 71 this.componentVisitor = componentVisitor; 72 } 73 74 public ContainerWrapper getContainerWrapper() { 75 return componentVisitor.getContainerWrapper(); 76 } 77 78 public void valueBound(HttpSessionBindingEvent event) { 79 Debug.logVerbose("[JdonFramework] valueBound active, sessionId :" + event.getSession().getId(), module); 80 componentsboxs.clear(); 81 82 } 83 84 87 public void valueUnbound(HttpSessionBindingEvent event) { 88 String sessionId = event.getSession().getId(); 89 Debug.logVerbose("[JdonFramework] unvalueBound active, sessionId :" + sessionId, module); 90 Debug.logVerbose("[JdonFramework] unvalueUnbound active, componentsboxs size" + componentsboxs.size(), module); 91 componentsboxs.clear(); 93 } 94 95 104 public Object visit(TargetMetaRequest targetMetaRequest) { 105 Object o = null; 106 try { 107 StringBuffer sb = new StringBuffer (targetMetaRequest.getTargetMetaDef().getCacheKey()); 108 sb.append(targetMetaRequest.getVisitableName()); 109 Debug.logVerbose("[JdonFramework] get the optimized instance for the key " + sb.toString(), module); 110 o = componentsboxs.get(sb.toString()); 111 if (o == null) { 112 Debug.logVerbose("[JdonFramework] first time visit: " + targetMetaRequest.getTargetMetaDef().getClassName(), module); 113 o = componentVisitor.visit(targetMetaRequest); 114 componentsboxs.put(sb.toString(), o); 115 } 116 } catch (Exception e) { 117 Debug.logError("[JdonFramework]visit error: " + e); 118 } 119 return o; 120 } 121 122 public SessionContext visitSessionContext(TargetMetaRequest targetMetaRequest){ 123 Object sessionContext = componentsboxs.get(SessionContext.NAME); 124 if (sessionContext == null) { 125 Debug.logVerbose("[JdonFramework] first time visit sessionContext: " + targetMetaRequest.getVisitableName(), module); 126 sessionContext = componentVisitor.visit(targetMetaRequest); 127 componentsboxs.put(SessionContext.NAME, sessionContext); 128 } 129 return (SessionContext)sessionContext; 130 } 131 132 135 public void removeObjects() { 136 144 145 } 146 147 157 } 158 | Popular Tags |