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.ServletRequest;
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 ServletRequest}'s attribute map.
28: */
29: public class RequestAttributeMapFacade extends MapFacade implements
30: WrappedObject {
31:
32: private ServletRequest _request = null;
33:
34: public RequestAttributeMapFacade(ServletRequest request) {
35: _request = request;
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 _request;
46: }
47:
48: protected Object getValue(Object key) {
49: if (key == null)
50: return null;
51:
52: assert _request != null;
53: return _request.getAttribute(key.toString());
54: }
55:
56: protected Object putValue(Object key, Object value) {
57: assert key != null;
58: assert _request != null;
59:
60: String strKey = key.toString();
61: Object prev = _request.getAttribute(strKey);
62:
63: _request.setAttribute(strKey, value);
64:
65: return prev;
66: }
67:
68: protected Iterator getKeys() {
69: return new EnumerationIterator(_request.getAttributeNames());
70: }
71: }
|