KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > controls > runtime > servlet > ServletServiceProvider


1 package org.apache.beehive.controls.runtime.servlet;
2 /*
3  * Copyright 2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * 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
20 import java.beans.beancontext.BeanContextServices JavaDoc;
21 import java.beans.beancontext.BeanContextServiceProvider JavaDoc;
22 import java.util.Iterator JavaDoc;
23
24 import javax.servlet.ServletContext JavaDoc;
25 import javax.servlet.ServletRequest JavaDoc;
26 import javax.servlet.ServletRequestWrapper JavaDoc;
27 import javax.servlet.ServletResponse JavaDoc;
28 import javax.servlet.ServletResponseWrapper JavaDoc;
29 import javax.servlet.http.HttpServletRequest JavaDoc;
30 import javax.servlet.http.HttpServletRequestWrapper JavaDoc;
31 import javax.servlet.http.HttpServletResponse JavaDoc;
32 import javax.servlet.http.HttpServletResponseWrapper JavaDoc;
33
34 /**
35  * The ServletContextProvider helper class acts at the BeanContextServiceProvider provides
36  * instances of web tier services associated with a ServletBeanContext
37  */

38 class ServletServiceProvider implements BeanContextServiceProvider JavaDoc
39 {
40     static final private ServletServiceProvider _provider = new ServletServiceProvider();
41
42     static final ServletServiceProvider getProvider() { return _provider; }
43
44     /* package */ ServletServiceProvider() {}
45
46     public Object JavaDoc getService(BeanContextServices JavaDoc bcs, Object JavaDoc requestor, Class JavaDoc serviceClass,
47                              Object JavaDoc serviceSelector)
48     {
49         //
50
// These services are only available to controls running within the scope of a
51
// ServletBeanContext
52
//
53
if (! (bcs instanceof ServletBeanContext))
54             return null;
55
56         ServletBeanContext sbc = (ServletBeanContext)bcs;
57         if (serviceClass.equals(ServletContext JavaDoc.class))
58             return new ServletContextService(sbc);
59
60         if (serviceClass.equals(HttpServletRequest JavaDoc.class))
61         {
62             HttpRequestService requestService = new HttpRequestService(sbc);
63             if (sbc.useWrappers())
64                 return requestService.getHttpRequestWrapper();
65             return requestService;
66         }
67
68         if (serviceClass.equals(HttpServletResponse JavaDoc.class))
69         {
70             HttpResponseService responseService = new HttpResponseService(sbc);
71             if (sbc.useWrappers())
72                 return responseService.getHttpResponseWrapper();
73             return responseService;
74         }
75
76         if (serviceClass.equals(ServletRequest JavaDoc.class))
77         {
78             ServletRequestService requestService = new ServletRequestService(sbc);
79             if (sbc.useWrappers())
80                 return requestService.getRequestWrapper();
81             return requestService;
82         }
83
84         if (serviceClass.equals(ServletResponse JavaDoc.class))
85         {
86             ServletResponseService responseService = new ServletResponseService(sbc);
87             if (sbc.useWrappers())
88                 return responseService.getResponseWrapper();
89             return responseService;
90         }
91
92         return null;
93     }
94
95     public void releaseService(BeanContextServices JavaDoc bcs, Object JavaDoc requestor, Object JavaDoc service)
96     {
97         // noop, because the provider isn't tracking service instances.
98
}
99
100     public Iterator JavaDoc getCurrentServiceSelectors(BeanContextServices JavaDoc bcs, Class JavaDoc serviceClass)
101     {
102         return null; // no selectors
103
}
104 }
105
Popular Tags