1 5 package com.opensymphony.webwork.lifecycle; 6 7 import com.opensymphony.xwork.interceptor.component.ComponentConfiguration; 8 import com.opensymphony.xwork.interceptor.component.ComponentManager; 9 import com.opensymphony.xwork.interceptor.component.DefaultComponentManager; 10 import org.apache.commons.logging.Log; 11 import org.apache.commons.logging.LogFactory; 12 13 import javax.servlet.ServletContext ; 14 import javax.servlet.http.*; 15 import java.io.Serializable ; 16 17 18 25 public class SessionLifecycleListener implements HttpSessionListener, Serializable { 26 28 private static final Log log = LogFactory.getLog(SessionLifecycleListener.class); 29 30 32 37 public void sessionCreated(HttpSessionEvent event) { 38 if (log.isDebugEnabled()) { 39 log.debug("Session DefaultComponentManager : init"); 40 } 41 42 HttpSession session = event.getSession(); 43 ComponentManager container = createComponentManager(); 44 ServletContext application = getServletContext(session); 45 ComponentManager fallback = (ComponentManager) application.getAttribute(ComponentManager.COMPONENT_MANAGER_KEY); 46 if (fallback != null) { 47 container.setFallback(fallback); 48 } 49 50 ComponentConfiguration config = (ComponentConfiguration) application.getAttribute("ComponentConfiguration"); 51 if (config != null) { 52 config.configure(container, "session"); 53 session.setAttribute(ComponentManager.COMPONENT_MANAGER_KEY, container); 54 } 55 } 56 57 62 public void sessionDestroyed(HttpSessionEvent event) { 63 } 64 65 73 protected ServletContext getServletContext(HttpSession session) { 74 return session.getServletContext(); 75 } 76 77 83 protected DefaultComponentManager createComponentManager() { 84 return new SessionComponentManager(); 85 } 86 87 89 class SessionComponentManager extends DefaultComponentManager implements HttpSessionBindingListener { 90 public void valueBound(HttpSessionBindingEvent event) { 91 } 92 93 public void valueUnbound(HttpSessionBindingEvent event) { 94 if (log.isDebugEnabled()) { 95 log.debug("Session DefaultComponentManager : destroy"); 96 } 97 98 this.dispose(); 99 } 100 } 101 } 102 | Popular Tags |