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.pageflow.internal;
20:
21: import org.apache.beehive.netui.pageflow.handler.StorageHandler;
22: import org.apache.beehive.netui.pageflow.RequestContext;
23:
24: import javax.servlet.http.HttpServletRequest;
25: import javax.servlet.http.HttpSession;
26: import javax.servlet.ServletContext;
27: import java.util.Enumeration;
28: import java.util.Collections;
29:
30: /**
31: * This storage handler simply puts/gets attributes in the session. It does not do anything to support multiple
32: * concurrent forwarded requests that are simultaneously modifying session data.
33: *
34: * @see DeferredSessionStorageHandler
35: */
36: public class SimpleSessionStorageHandler extends DefaultHandler
37: implements StorageHandler {
38: public SimpleSessionStorageHandler(ServletContext servletContext) {
39: init(null, null, servletContext);
40: }
41:
42: public void setAttribute(RequestContext context,
43: String attributeName, Object value) {
44: ((HttpServletRequest) context.getRequest()).getSession()
45: .setAttribute(attributeName, value);
46: }
47:
48: public void removeAttribute(RequestContext context,
49: String attributeName) {
50: HttpSession session = ((HttpServletRequest) context
51: .getRequest()).getSession(false);
52: if (session != null)
53: session.removeAttribute(attributeName);
54: }
55:
56: public Object getAttribute(RequestContext context,
57: String attributeName) {
58: HttpSession session = ((HttpServletRequest) context
59: .getRequest()).getSession(false);
60: return session != null ? session.getAttribute(attributeName)
61: : null;
62: }
63:
64: public void ensureFailover(RequestContext context,
65: String attributeName, Object value) {
66: HttpServletRequest request = (HttpServletRequest) context
67: .getRequest();
68: AdapterManager.getServletContainerAdapter(getServletContext())
69: .ensureFailover(attributeName, value, request);
70: }
71:
72: public boolean allowBindingEvent(Object event) {
73: return true;
74: }
75:
76: public void applyChanges(RequestContext context) {
77: }
78:
79: public void dropChanges(RequestContext context) {
80: }
81:
82: public Enumeration getAttributeNames(RequestContext context) {
83: HttpSession session = ((HttpServletRequest) context
84: .getRequest()).getSession(false);
85: if (session != null) {
86: return session.getAttributeNames();
87: } else {
88: return Collections.enumeration(Collections.emptyList());
89: }
90: }
91: }
|