1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
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 }