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.Iterator;
19:
20: import javax.servlet.ServletContext;
21:
22: import org.springframework.binding.collection.SharedMap;
23: import org.springframework.binding.collection.StringKeyedMapAdapter;
24: import org.springframework.webflow.core.collection.CollectionUtils;
25:
26: /**
27: * Map backed by the Servlet context for accessing application scoped
28: * attributes.
29: *
30: * @author Keith Donald
31: */
32: public class HttpServletContextMap extends StringKeyedMapAdapter
33: implements SharedMap {
34:
35: /**
36: * The wrapped servlet context.
37: */
38: private ServletContext context;
39:
40: /**
41: * Create a map wrapping given servlet context.
42: */
43: public HttpServletContextMap(ServletContext context) {
44: this .context = context;
45: }
46:
47: protected Object getAttribute(String key) {
48: return context.getAttribute(key);
49: }
50:
51: protected void setAttribute(String key, Object value) {
52: context.setAttribute(key, value);
53: }
54:
55: protected void removeAttribute(String key) {
56: context.removeAttribute(key);
57: }
58:
59: protected Iterator getAttributeNames() {
60: return CollectionUtils.toIterator(context.getAttributeNames());
61: }
62:
63: public Object getMutex() {
64: return context;
65: }
66: }
|