01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: * $Header:$
18: */
19: package org.apache.beehive.netui.script.el.util;
20:
21: import java.util.Iterator;
22: import javax.servlet.http.HttpSession;
23:
24: import org.apache.beehive.netui.util.iterator.EnumerationIterator;
25:
26: /**
27: * Class that puts a {@link java.util.Map} facade atop a {@link HttpSession}'s attribute map.
28: */
29: public class SessionAttributeMapFacade extends MapFacade implements
30: WrappedObject {
31:
32: private HttpSession _session = null;
33:
34: public SessionAttributeMapFacade(HttpSession session) {
35: _session = session;
36: }
37:
38: /**
39: * Implementation of the {@link WrappedObject} API that allows the caller to discover the
40: * backing object.
41: *
42: * @return the backing object
43: */
44: public Object unwrap() {
45: return _session;
46: }
47:
48: protected Object getValue(Object key) {
49: if (key == null)
50: return null;
51:
52: assert _session != null;
53: return _session.getAttribute(key.toString());
54: }
55:
56: protected Object putValue(Object key, Object value) {
57: String strKey = key.toString();
58: Object prev = _session.getAttribute(strKey);
59:
60: _session.setAttribute(strKey, value);
61:
62: return prev;
63: }
64:
65: protected Iterator getKeys() {
66: return new EnumerationIterator(_session.getAttributeNames());
67: }
68: }
|