KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.servlet.ServletContext JavaDoc;
21
22 import org.apache.beehive.controls.api.context.ControlContainerContext;
23 import org.apache.beehive.controls.api.context.ControlThreadContext;
24
25 /**
26  * This class is the contextual service implementation for javax.servlet.ServletContext. It
27  * acts as an intermediary between the client and the ServletContext instance held by the
28  * associated ServletBeanContext. It validates that attempt to access the ServletContext
29  * only occur during the servlet request processing lifecycle, then delegates to the underlying
30  * ServletContext instance for actual services.
31  */

32 /* package */ class ServletContextService implements ServletContext JavaDoc
33 {
34     
35     /* package */ ServletContextService(ServletBeanContext beanContext)
36     {
37         _beanContext = beanContext;
38     }
39
40     /**
41      * This method retrieves the current ServletBeanContext for the service. It is capable
42      * of reassociating with the current active context, if the service instance has been
43      * serialized/deserialized.
44      */

45     final protected ServletBeanContext getServletBeanContext()
46     {
47         if (_beanContext == null)
48         {
49             ControlContainerContext ccc = ControlThreadContext.getContext();
50             if (! (ccc instanceof ServletBeanContext))
51                 throw new IllegalStateException JavaDoc("No ServletBeanContext available");
52
53             _beanContext = (ServletBeanContext)ccc;
54         }
55         return _beanContext;
56     }
57
58     final protected ServletContext JavaDoc getServletContext()
59     {
60         ServletContext JavaDoc servletContext = getServletBeanContext().getServletContext();
61         if (servletContext == null)
62             throw new IllegalStateException JavaDoc("No access to ServletContext outside request processing");
63         return servletContext;
64     }
65
66     public java.lang.Object JavaDoc getAttribute(java.lang.String JavaDoc name)
67     {
68         return getServletContext().getAttribute(name);
69     }
70
71     public java.util.Enumeration JavaDoc getAttributeNames()
72     {
73         return getServletContext().getAttributeNames();
74     }
75
76     public ServletContext JavaDoc getContext(java.lang.String JavaDoc uripath)
77     {
78         return getServletContext().getContext(uripath);
79     }
80
81     public java.lang.String JavaDoc getInitParameter(java.lang.String JavaDoc name)
82     {
83         return getServletContext().getInitParameter(name);
84     }
85
86     public java.util.Enumeration JavaDoc getInitParameterNames()
87     {
88         return getServletContext().getInitParameterNames();
89     }
90
91     public int getMajorVersion()
92     {
93         return getServletContext().getMajorVersion();
94     }
95
96     public java.lang.String JavaDoc getMimeType(java.lang.String JavaDoc file)
97     {
98         return getServletContext().getMimeType(file);
99     }
100
101     public int getMinorVersion()
102     {
103         return getServletContext().getMinorVersion();
104     }
105
106     public javax.servlet.RequestDispatcher JavaDoc getNamedDispatcher(java.lang.String JavaDoc name)
107     {
108         return getServletContext().getNamedDispatcher(name);
109     }
110
111     public java.lang.String JavaDoc getRealPath(java.lang.String JavaDoc path)
112     {
113         return getServletContext().getRealPath(path);
114     }
115
116     public javax.servlet.RequestDispatcher JavaDoc getRequestDispatcher(java.lang.String JavaDoc path)
117     {
118         return getServletContext().getRequestDispatcher(path);
119     }
120
121     public java.net.URL JavaDoc getResource(java.lang.String JavaDoc path) throws java.net.MalformedURLException JavaDoc
122     {
123         return getServletContext().getResource(path);
124     }
125
126     public java.io.InputStream JavaDoc getResourceAsStream(java.lang.String JavaDoc path)
127     {
128         return getServletContext().getResourceAsStream(path);
129     }
130
131     public java.util.Set JavaDoc getResourcePaths(java.lang.String JavaDoc path)
132     {
133         return getServletContext().getResourcePaths(path);
134     }
135
136     public java.lang.String JavaDoc getServerInfo()
137     {
138         return getServletContext().getServerInfo();
139     }
140
141     public javax.servlet.Servlet JavaDoc getServlet(java.lang.String JavaDoc name) throws javax.servlet.ServletException JavaDoc
142     {
143         return getServletContext().getServlet(name);
144     }
145
146     public java.lang.String JavaDoc getServletContextName()
147     {
148         return getServletContext().getServletContextName();
149     }
150
151     public java.util.Enumeration JavaDoc getServletNames()
152     {
153         return getServletContext().getServletNames();
154     }
155
156     public java.util.Enumeration JavaDoc getServlets()
157     {
158         return getServletContext().getServlets();
159     }
160
161     public void log(java.lang.String JavaDoc msg)
162     {
163         getServletContext().log(msg);
164     }
165
166     public void log(java.lang.Exception JavaDoc exception, java.lang.String JavaDoc msg)
167     {
168         getServletContext().log(exception, msg);
169     }
170
171     public void log(java.lang.String JavaDoc message, java.lang.Throwable JavaDoc throwable)
172     {
173         getServletContext().log(message, throwable);
174     }
175
176     public void removeAttribute(java.lang.String JavaDoc name)
177     {
178         getServletContext().removeAttribute(name);
179     }
180
181     public void setAttribute(java.lang.String JavaDoc name, java.lang.Object JavaDoc object)
182     {
183         getServletContext().setAttribute(name, object);
184     }
185
186     transient private ServletBeanContext _beanContext; // never access directly
187
}
188
Popular Tags