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.PageFlowUtils;
22: import org.apache.beehive.netui.pageflow.PageFlowController;
23:
24: import javax.servlet.http.HttpServletRequest;
25: import javax.servlet.ServletRequest;
26: import java.beans.beancontext.BeanContextServiceProvider;
27: import java.beans.beancontext.BeanContextServices;
28: import java.util.Iterator;
29:
30: /**
31: * Service provider that offers initialization for PageFlowController and SharedFlowControler members in a Control.
32: */
33: public class PageFlowServiceProvider implements
34: BeanContextServiceProvider {
35: private static final PageFlowServiceProvider _provider = new PageFlowServiceProvider();
36:
37: public static PageFlowServiceProvider getProvider() {
38: return _provider;
39: }
40:
41: private PageFlowServiceProvider() {
42: }
43:
44: public static interface HasServletRequest {
45: ServletRequest getServletRequest();
46: }
47:
48: public Object getService(BeanContextServices bcs, Object requestor,
49: Class serviceClass, Object serviceSelector) {
50: //
51: // These services are only available to controls running within the scope of a PageFlowBeanContext
52: //
53: if (!(bcs instanceof HasServletRequest))
54: return null;
55:
56: if (PageFlowController.class.equals(serviceClass)) {
57: ServletRequest request = ((HasServletRequest) bcs)
58: .getServletRequest();
59:
60: if (!(request instanceof HttpServletRequest))
61: return null;
62: else
63: return PageFlowUtils
64: .getCurrentPageFlow((HttpServletRequest) request);
65: }
66:
67: return null;
68: }
69:
70: public void releaseService(BeanContextServices bcs,
71: Object requestor, Object service) {
72: }
73:
74: public Iterator getCurrentServiceSelectors(BeanContextServices bcs,
75: Class serviceClass) {
76: return null;
77: }
78: }
|