View Javadoc

1   /*
2    * Copyright (C) 2004 TiongHiang Lee
3    *
4    * This library is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Lesser General Public
6    * License as published by the Free Software Foundation; either
7    * version 2.1 of the License, or (at your option) any later version.
8    *
9    * This library is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   * Lesser General Public License for more details.
13   *
14   * You should have received a copy of the GNU Lesser General Public
15   * License along with this library; if not,  write to the Free Software
16   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17   *
18   * Email: thlee@onemindsoft.org
19   */
20  
21  package org.onemind.awtbridge.session;
22  
23  import java.util.*;
24  import org.onemind.awtbridge.BridgeContextSession;
25  import org.onemind.awtbridge.ComponentManager;
26  public class SimpleContextSession implements BridgeContextSession
27  {
28  
29      private final ComponentManager _manager;
30  
31      private Map _values = new HashMap();
32  
33      private final List _sessionListeners = new ArrayList();
34      
35      private boolean _closed = false;
36  
37      public SimpleContextSession()
38      {
39          this(new ComponentManager());
40      }
41  
42      public SimpleContextSession(ComponentManager manager)
43      {
44          _manager = manager;
45      }
46  
47      public ComponentManager getComponentManager()
48      {
49          // TODO Auto-generated method stub
50          return _manager;
51      }
52  
53      /*** 
54       * {@inheritDoc}
55       */
56      public void addListener(SessionLifecycleListener listener)
57      {
58          _sessionListeners.add(listener);
59      }
60  
61      /*** 
62       * {@inheritDoc}
63       */
64      public void removeListener(SessionLifecycleListener listener)
65      {
66          _sessionListeners.remove(listener);
67      }
68  
69      /***
70       * fire sessionEnded event to all listener
71       */
72      private void fireSessionEnded()
73      {
74          Iterator it = _sessionListeners.iterator();
75          while (it.hasNext())
76          {
77              ((SessionLifecycleListener) it.next()).sessionEnded(this);
78          }
79      }
80  
81      public Object getValue(Object key)
82      {
83          return _values.get(key);
84      }
85  
86      public void putValue(Object key, Object value)
87      {
88          _values.put(key, value);
89      }
90  
91      public void putAllValues(Map values)
92      {
93          _values.putAll(values);
94      }
95  
96      public Object removeValue(Object key)
97      {
98          return _values.remove(key);
99      }
100 
101     public void close()
102     {
103         if (!_closed){
104             _closed = true;
105             fireSessionEnded();
106         }
107     }
108     
109     public boolean isClosed(){
110         return _closed;
111     }
112 }