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;
20:
21: import org.apache.beehive.netui.pageflow.handler.StorageHandler;
22: import org.apache.beehive.netui.pageflow.handler.Handlers;
23: import org.apache.beehive.netui.pageflow.scoping.ScopedServletUtils;
24: import org.apache.beehive.netui.pageflow.internal.InternalConstants;
25:
26: import javax.servlet.http.HttpServletRequest;
27: import javax.servlet.ServletContext;
28:
29: public class PageFlowControlContainerFactory {
30: private static String PAGEFLOW_CONTROL_CONTAINER = InternalConstants.ATTR_PREFIX
31: + "PageFlowControlContainerInstance";
32:
33: /**
34: * This method will return the <code>PageFlowControlContainer</code> that is acting as the
35: * control container for the page flow runtime.
36: * @param request The current request
37: * @param servletContext The servlet context
38: * @return The <code>pageFLowControlContainer</code> acting as the control container.
39: */
40: public static synchronized PageFlowControlContainer getControlContainer(
41: HttpServletRequest request, ServletContext servletContext) {
42: PageFlowControlContainer pfcc = (PageFlowControlContainer) getSessionVar(
43: request, servletContext, PAGEFLOW_CONTROL_CONTAINER);
44: if (pfcc != null)
45: return pfcc;
46:
47: pfcc = new PageFlowControlContainerImpl();
48: setSessionVar(request, servletContext,
49: PAGEFLOW_CONTROL_CONTAINER, pfcc);
50: return pfcc;
51: }
52:
53: /**
54: * This is a generic routine that will retrieve a value from the Session through the
55: * StorageHandler.
56: * @param request
57: * @param servletContext
58: * @param name The name of the value to be retrieved
59: * @return The requested value from the session
60: */
61: private static Object getSessionVar(HttpServletRequest request,
62: ServletContext servletContext, String name) {
63: StorageHandler sh = Handlers.get(servletContext)
64: .getStorageHandler();
65:
66: HttpServletRequest unwrappedRequest = PageFlowUtils
67: .unwrapMultipart(request);
68: RequestContext rc = new RequestContext(unwrappedRequest, null);
69: String attrName = ScopedServletUtils.getScopedSessionAttrName(
70: name, unwrappedRequest);
71: return sh.getAttribute(rc, attrName);
72: }
73:
74: /**
75: * This is a generic routine that will store a value into the Session through the StorageHandler.
76: * @param request
77: * @param servletContext
78: * @param name The name of the variable to be stored
79: * @param value The value of the variable to be stored
80: */
81: private static void setSessionVar(HttpServletRequest request,
82: ServletContext servletContext, String name, Object value) {
83: StorageHandler sh = Handlers.get(servletContext)
84: .getStorageHandler();
85:
86: HttpServletRequest unwrappedRequest = PageFlowUtils
87: .unwrapMultipart(request);
88: RequestContext rc = new RequestContext(unwrappedRequest, null);
89: String attrName = ScopedServletUtils.getScopedSessionAttrName(
90: name, unwrappedRequest);
91: sh.setAttribute(rc, attrName, value);
92: }
93: }
|