1 5 package org.exoplatform.container; 6 7 import java.util.List ; 8 import org.exoplatform.container.monitor.SessionMonitor; 9 import org.exoplatform.container.monitor.SessionMonitorListenerStack; 10 17 public class SessionContainer extends ExoContainer { 18 private static ThreadLocal threadLocal_ = new ThreadLocal () ; 19 20 private String portalName_ ; 21 private SessionMonitor monitor_ ; 22 private String id_ ; 23 24 public SessionContainer(PortalContainer parent, String id, String owner) { 25 super(new SimpleComponentAdapterFactory(), parent) ; 26 id_ = id ; 27 SessionMonitorListenerStack stack = 28 (SessionMonitorListenerStack)parent.getComponentInstanceOfType(SessionMonitorListenerStack.class); 29 monitor_ = new SessionMonitor(stack, owner); 30 registerComponentInstance(monitor_) ; 31 List factories = 32 parent.getComponentInstancesOfType(SessionContainerInitializer.class); 33 for(int i = 0; i < factories.size(); i++) { 34 SessionContainerInitializer initializer = 35 (SessionContainerInitializer) factories.get(i) ; 36 initializer.initialize(this) ; 37 } 38 } 39 40 public String getId() { return id_ ; } 41 42 public String getOwner() { return monitor_.getSessionOwner() ; } 43 44 public SessionMonitor getMonitor() { return monitor_ ; } 45 46 public String getPortalName() { return portalName_ ; } 47 public void setPortalName(String name) { portalName_ = name ; } 48 49 static public SessionContainer getInstance() { 50 return (SessionContainer)threadLocal_.get() ; 51 } 52 53 static public void setInstance(SessionContainer scontainer) { 54 threadLocal_.set(scontainer) ; 55 } 56 57 public void startActionLifcycle() { 58 threadLocal_.set(this) ; 59 } 60 61 public void endActionLifcycle() { 62 threadLocal_.set(null) ; 63 } 64 65 public void stop() { 66 if(monitor_ == null) return ; 67 monitor_.getListeners().onStop(monitor_) ; 68 monitor_ = null ; 69 super.stop() ; 70 } 71 72 public static Object getComponent(Class key) { 73 SessionContainer scontainer = (SessionContainer)threadLocal_.get() ; 74 return scontainer.getComponentInstanceOfType(key) ; 75 } 76 } | Popular Tags |