1
2
3
4
5
6
7
8
9
10
11
12
13 package org.abstracthorizon.danube.webflow;
14
15 import java.util.Collections;
16 import java.util.Enumeration;
17 import java.util.HashMap;
18 import java.util.Iterator;
19 import java.util.List;
20
21 import org.abstracthorizon.danube.http.HTTPConnection;
22 import org.abstracthorizon.danube.http.session.Session;
23 import org.springframework.binding.collection.SharedMap;
24 import org.springframework.binding.collection.SharedMapDecorator;
25 import org.springframework.binding.collection.StringKeyedMapAdapter;
26 import org.springframework.webflow.context.ExternalContext;
27 import org.springframework.webflow.core.collection.LocalParameterMap;
28 import org.springframework.webflow.core.collection.LocalSharedAttributeMap;
29 import org.springframework.webflow.core.collection.MutableAttributeMap;
30 import org.springframework.webflow.core.collection.ParameterMap;
31 import org.springframework.webflow.core.collection.SharedAttributeMap;
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 public class DanubeExternalContext implements ExternalContext {
48
49
50 protected HTTPConnection connection;
51
52
53 protected DanubeFlowController controller;
54
55
56
57
58
59
60 public DanubeExternalContext(DanubeFlowController controller, HTTPConnection connection) {
61 this.controller = controller;
62 this.connection = connection;
63 }
64
65
66
67
68
69 public String getContextPath() {
70 return connection.getContextPath();
71 }
72
73
74
75
76
77 public String getDispatcherPath() {
78 return connection.getComponentPath();
79 }
80
81
82
83
84
85 public String getRequestPathInfo() {
86 return connection.getComponentResourcePath();
87 }
88
89
90
91
92
93 public ParameterMap getRequestParameterMap() {
94 return new LocalParameterMap(connection.getRequestParameters().getAsMap());
95 }
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124 public class SessionMap extends StringKeyedMapAdapter implements SharedMap {
125
126
127
128
129
130 public SessionMap() {
131 }
132
133
134
135
136
137 protected Session getSession() {
138 return (Session)controller.getSessionManager().findSession(connection, false);
139 }
140
141
142
143
144
145 protected Object getAttribute(String key) {
146 Session session = getSession();
147 if (session == null) {
148 return null;
149 } else {
150 return session.getAttributes().get(key);
151 }
152 }
153
154
155
156
157
158
159 protected void setAttribute(String key, Object value) {
160 Session session = (Session)controller.getSessionManager().findSession(connection, true);
161 session.getAttributes().put(key, value);
162 }
163
164
165
166
167
168 protected void removeAttribute(String key) {
169 Session session = getSession();
170 if (session != null) {
171 session.getAttributes().remove(key);
172 }
173 }
174
175
176
177
178
179 protected Iterator<String> getAttributeNames() {
180 Session session = getSession();
181 if (session != null) {
182 return session.getAttributes().keySet().iterator();
183 } else {
184 List<String> list = Collections.emptyList();
185 return list.iterator();
186 }
187 }
188
189
190
191
192
193
194 public Object getMutex() {
195 Session session = (Session)controller.getSessionManager().findSession(connection, true);
196 return session;
197 }
198 }
199
200
201
202
203 public static class EnumerationIteratorAdapter<T> implements Enumeration<T> {
204
205
206 protected Iterator<T> iterator;
207
208
209
210
211
212 public EnumerationIteratorAdapter(Iterator<T> iterator) {
213 this.iterator = iterator;
214 }
215
216
217
218
219
220 public boolean hasMoreElements() {
221 return iterator.hasNext();
222 }
223
224
225
226
227
228 public T nextElement() {
229 return iterator.next();
230 }
231 }
232
233 public SharedAttributeMap getApplicationMap() {
234
235 return new LocalSharedAttributeMap(new SharedMapDecorator(new HashMap<Object, Object>()));
236 }
237
238 public SharedAttributeMap getGlobalSessionMap() {
239
240 return new LocalSharedAttributeMap(new SharedMapDecorator(new HashMap<Object, Object>()));
241 }
242
243 public MutableAttributeMap getRequestMap() {
244
245 return new LocalSharedAttributeMap(new SharedMapDecorator(new HashMap<Object, Object>()));
246 }
247
248 public SharedAttributeMap getSessionMap() {
249
250 return new LocalSharedAttributeMap(new SharedMapDecorator(new HashMap<Object, Object>()));
251 }
252
253 }