01: /*
02: * Copyright 2004-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package org.springframework.webflow.context.servlet;
17:
18: import java.util.Map;
19:
20: import javax.servlet.http.HttpSessionBindingEvent;
21: import javax.servlet.http.HttpSessionBindingListener;
22:
23: import org.springframework.webflow.core.collection.AttributeMapBindingEvent;
24: import org.springframework.webflow.core.collection.AttributeMapBindingListener;
25: import org.springframework.webflow.core.collection.LocalAttributeMap;
26:
27: /**
28: * Helper class that adapts a generic {@link AttributeMapBindingListener} to a
29: * HTTP specific {@link HttpSessionBindingListener}. Calls will be forwarded to
30: * the wrapped listener.
31: *
32: * @author Keith Donald
33: */
34: public class HttpSessionMapBindingListener implements
35: HttpSessionBindingListener {
36:
37: private AttributeMapBindingListener listener;
38:
39: private Map sessionMap;
40:
41: /**
42: * Create a new wrapper for given listener.
43: * @param listener the listener to wrap
44: * @param sessionMap the session map containing the listener
45: */
46: public HttpSessionMapBindingListener(
47: AttributeMapBindingListener listener, Map sessionMap) {
48: this .listener = listener;
49: this .sessionMap = sessionMap;
50: }
51:
52: /**
53: * Returns the wrapped listener.
54: */
55: public AttributeMapBindingListener getListener() {
56: return listener;
57: }
58:
59: /**
60: * Returns the session map containing the listener.
61: */
62: public Map getSessionMap() {
63: return sessionMap;
64: }
65:
66: public void valueBound(HttpSessionBindingEvent event) {
67: listener.valueBound(getContextBindingEvent(event));
68: }
69:
70: public void valueUnbound(HttpSessionBindingEvent event) {
71: listener.valueUnbound(getContextBindingEvent(event));
72: }
73:
74: /**
75: * Create a attribute map binding event for given HTTP session binding
76: * event.
77: */
78: private AttributeMapBindingEvent getContextBindingEvent(
79: HttpSessionBindingEvent event) {
80: return new AttributeMapBindingEvent(new LocalAttributeMap(
81: sessionMap), event.getName(), listener);
82: }
83: }
|