KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > webflow > context > servlet > HttpSessionMapBindingListener


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
19
20 import javax.servlet.http.HttpSessionBindingEvent JavaDoc;
21 import javax.servlet.http.HttpSessionBindingListener JavaDoc;
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 HttpSessionBindingListener JavaDoc {
35
36     private AttributeMapBindingListener listener;
37
38     private Map JavaDoc sessionMap;
39
40     /**
41      * Create a new wrapper for given listener.
42      * @param listener the listener to wrap
43      * @param sessionMap the session map containing the listener
44      */

45     public HttpSessionMapBindingListener(AttributeMapBindingListener listener, Map JavaDoc sessionMap) {
46         this.listener = listener;
47         this.sessionMap = sessionMap;
48     }
49
50     /**
51      * Returns the wrapped listener.
52      */

53     public AttributeMapBindingListener getListener() {
54         return listener;
55     }
56
57     /**
58      * Returns the session map containing the listener.
59      */

60     public Map JavaDoc getSessionMap() {
61         return sessionMap;
62     }
63
64     public void valueBound(HttpSessionBindingEvent JavaDoc event) {
65         listener.valueBound(getContextBindingEvent(event));
66     }
67
68     public void valueUnbound(HttpSessionBindingEvent JavaDoc event) {
69         listener.valueUnbound(getContextBindingEvent(event));
70     }
71
72     /**
73      * Create a attribute map binding event for given HTTP session binding
74      * event.
75      */

76     private AttributeMapBindingEvent getContextBindingEvent(HttpSessionBindingEvent JavaDoc event) {
77         return new AttributeMapBindingEvent(new LocalAttributeMap(sessionMap), event.getName(), listener);
78     }
79 }
Popular Tags