KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > container > SessionContainer


1 /**
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved.
3  * Please look at license.txt in info directory for more license detail.
4  **/

5 package org.exoplatform.container;
6
7 import java.util.List JavaDoc;
8 import org.exoplatform.container.monitor.SessionMonitor;
9 import org.exoplatform.container.monitor.SessionMonitorListenerStack;
10 /**
11  * Created by The eXo Platform SARL
12  * Author : Tuan Nguyen
13  * tuan08@users.sourceforge.net
14  * Date: Jul 18, 2004
15  * Time: 12:15:28 AM
16  */

17 public class SessionContainer extends ExoContainer {
18   private static ThreadLocal JavaDoc threadLocal_ = new ThreadLocal JavaDoc() ;
19   
20   private String JavaDoc portalName_ ;
21   private SessionMonitor monitor_ ;
22   private String JavaDoc id_ ;
23   
24   public SessionContainer(PortalContainer parent, String JavaDoc id, String JavaDoc 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 JavaDoc 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 JavaDoc getId() { return id_ ; }
41   
42   public String JavaDoc getOwner() { return monitor_.getSessionOwner() ; }
43   
44   public SessionMonitor getMonitor() { return monitor_ ; }
45   
46   public String JavaDoc getPortalName() { return portalName_ ; }
47   public void setPortalName(String JavaDoc 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 JavaDoc getComponent(Class JavaDoc key) {
73     SessionContainer scontainer = (SessionContainer)threadLocal_.get() ;
74     return scontainer.getComponentInstanceOfType(key) ;
75   }
76 }
Popular Tags