KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > pageflow > internal > PageFlowServiceProvider


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * $Header:$
17  */

18 package org.apache.beehive.netui.pageflow.internal;
19
20 import org.apache.beehive.netui.pageflow.PageFlowUtils;
21 import org.apache.beehive.netui.pageflow.PageFlowController;
22
23 import javax.servlet.http.HttpServletRequest JavaDoc;
24 import javax.servlet.ServletRequest JavaDoc;
25 import java.beans.beancontext.BeanContextServiceProvider JavaDoc;
26 import java.beans.beancontext.BeanContextServices JavaDoc;
27 import java.util.Iterator JavaDoc;
28
29
30 /**
31  * Service provider that offers initialization for PageFlowController and SharedFlowControler members in a Control.
32  */

33 public class PageFlowServiceProvider implements BeanContextServiceProvider JavaDoc
34 {
35     private static final PageFlowServiceProvider _provider = new PageFlowServiceProvider();
36
37     public static final PageFlowServiceProvider getProvider() { return _provider; }
38
39     private PageFlowServiceProvider()
40     {
41     }
42
43     public static interface HasServletRequest
44     {
45         ServletRequest JavaDoc getServletRequest();
46     }
47     
48     public Object JavaDoc getService( BeanContextServices JavaDoc bcs, Object JavaDoc requestor, Class JavaDoc serviceClass,
49                               Object JavaDoc serviceSelector )
50     {
51         //
52
// These services are only available to controls running within the scope of a PageFlowBeanContext
53
//
54
if ( ! ( bcs instanceof HasServletRequest ) ) return null;
55
56         if ( PageFlowController.class.equals( serviceClass ) )
57         {
58             ServletRequest JavaDoc request = ( ( HasServletRequest ) bcs ).getServletRequest();
59             if ( ! ( request instanceof HttpServletRequest JavaDoc ) ) return null;
60             return PageFlowUtils.getCurrentPageFlow( ( HttpServletRequest JavaDoc ) request );
61         }
62
63         return null;
64     }
65
66     public void releaseService( BeanContextServices JavaDoc bcs, Object JavaDoc requestor, Object JavaDoc service )
67     {
68     }
69
70     public Iterator JavaDoc getCurrentServiceSelectors( BeanContextServices JavaDoc bcs, Class JavaDoc serviceClass )
71     {
72         return null;
73     }
74 }
75
Popular Tags