KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > pageflow > DefaultServletContainerAdapter


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;
19
20 import org.apache.beehive.netui.pageflow.adapter.AdapterContext;
21 import org.apache.beehive.netui.pageflow.internal.PageFlowBeanContext;
22 import org.apache.beehive.netui.util.logging.Logger;
23
24 import javax.security.auth.login.LoginException JavaDoc;
25 import javax.servlet.ServletContext JavaDoc;
26 import javax.servlet.http.HttpServletRequest JavaDoc;
27 import javax.servlet.http.HttpServletResponse JavaDoc;
28
29
30 /**
31  * Default implementation of a Servlet container adapter.
32  */

33 public abstract class DefaultServletContainerAdapter
34         implements ServletContainerAdapter
35 {
36     private static boolean _productionMode = true;
37     
38     private ServletContext JavaDoc _servletContext;
39     private PageFlowEventReporter _eventReporter;
40     
41     static
42     {
43         String JavaDoc productionModeFlag = System.getProperty( "beehive.productionmode" );
44         
45         if ( productionModeFlag != null )
46         {
47             _productionMode = Boolean.valueOf( productionModeFlag ).booleanValue();
48         }
49         else
50         {
51             //
52
// This is our default definition of "production mode": when asserts are disabled (the following statement
53
// sets _productionMode to false when asserts are enabled).
54
//
55
assert ( _productionMode = false ) || true;
56         }
57     }
58
59     protected DefaultServletContainerAdapter()
60     {
61     }
62     
63     /**
64      * Tell whether the system is in production mode.
65      *
66      * @return <code>true</code> if the system property "beehive.productionmode" is set to "true", or if asserts are
67      * disabled for this class in the case where the system property has no value; <code>false</code> if the
68      * system property is set to "false", or if asserts are enabled for this class in the case where the
69      * system property has no value.
70      */

71     public boolean isInProductionMode()
72     {
73         return _productionMode;
74     }
75
76     /**
77      * Tell whether a web application resource requires a secure transport protocol. This default implementation
78      * simply returns {@link SecurityProtocol#UNSPECIFIED} for all paths.
79      *
80      * @param path a webapp-relative path for a resource.
81      * @param request the current HttpServletRequest.
82      * @return {@link SecurityProtocol#UNSPECIFIED}.
83      */

84     public SecurityProtocol getSecurityProtocol( String JavaDoc path, HttpServletRequest JavaDoc request )
85     {
86         // TODO: implement this based on parsing of web.xml
87
return SecurityProtocol.UNSPECIFIED;
88     }
89
90     /**
91      * Cause the server to do a security check for the given path. This default implementation does nothing.
92      * @return <code>false</code>
93      */

94     public boolean doSecurityRedirect( String JavaDoc path, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response )
95     {
96         return false;
97     }
98
99     /**
100      * Get the port on which the server is listening for unsecure connections. This default implementation always
101      * returns <code>-1</code>.
102      * @param request the current HttpServletRequest.
103      * @return <code>-1</code>.
104      */

105     public int getListenPort( HttpServletRequest JavaDoc request )
106     {
107         // TODO: have a configuration in netui-config.xml to specify this; an alternative to having to have an adapter.
108
return -1;
109     }
110
111     /**
112      * Get the port on which the server is listening for secure connections. This default implementation always
113      * returns <code>-1</code>.
114      * @param request the current HttpServletRequest.
115      * @return <code>-1</code>.
116      */

117     public int getSecureListenPort( HttpServletRequest JavaDoc request )
118     {
119         // TODO: have a configuration in netui-config.xml to specify this; an alternative to having to have an adapter.
120
return -1;
121     }
122
123     /**
124      * Log in the user, using "weak" username/password authentication. This default implementation always throws
125      * {@link UnsupportedOperationException}.
126      *
127      * @throws UnsupportedOperationException in all cases.
128      */

129     public void login( String JavaDoc username, String JavaDoc password, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response )
130             throws LoginException JavaDoc
131     {
132         throw new UnsupportedOperationException JavaDoc( "login is not supported by "
133                                                  + DefaultServletContainerAdapter.class.getName() );
134     }
135
136     /**
137      * Log out the user. This default implementation always throws {@link UnsupportedOperationException}.
138      *
139      * @throws UnsupportedOperationException in all cases.
140      */

141     public void logout( boolean invalidateSessions, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response )
142     {
143         throw new UnsupportedOperationException JavaDoc( "logout is not supported by "
144                                                  + DefaultServletContainerAdapter.class.getName() );
145     }
146     
147     /**
148      * Return the webapp context path for the given request. This can differ from HttpServletRequest.getContextPath()
149      * only in that it will return a valid value even if the request is for the default webapp. This default
150      * implementation always returns the value of <code>getContextPath()</code> on the request.
151      *
152      * @param request the current HttpServletRequest.
153      * @return the value of <code>getContextPath()</code> on the current request.
154      */

155     public String JavaDoc getFullContextPath( HttpServletRequest JavaDoc request )
156     {
157         return request.getContextPath();
158     }
159
160     /**
161      * Ensure that the given session attribute is replicated in a cluster for session failover.
162      * This method does not need to be implemented for servers that do not support clustering and
163      * session failover. The default implementation does nothing.
164      *
165      * @param attrName the name of the session attribute for which failover should be ensured.
166      * @param attrVal the value of the given session attribute.
167      * @param request the current HttpServletRequest.
168      */

169     public void ensureFailover( String JavaDoc attrName, Object JavaDoc attrVal, HttpServletRequest JavaDoc request )
170     {
171     }
172
173     /**
174      * Called at the beginning of each processed request. This default implementation does nothing.
175      *
176      * @param request the current HttpServletRequest.
177      * @param response the current HttpServletResponse.
178      */

179     public void beginRequest( HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response )
180     {
181     }
182
183     /**
184      * Called at the end of each processed request. This default implementation does nothing.
185      *
186      * @param request the current HttpServletRequest.
187      * @param response the current HttpServletResponse.
188      */

189     public void endRequest( HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response )
190     {
191     }
192
193     /**
194      * Get a context object to support Beehive Controls. This default implementation returns an instance of
195      * {@link PageFlowBeanContext}.
196      *
197      * @param request the current HttpServletRequest.
198      * @param response the current HttpServletResponse.
199      * @return a new ControlBeanContext.
200      */

201     public Object JavaDoc createControlBeanContext( HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response )
202     {
203         return new PageFlowBeanContext();
204     }
205
206     /**
207      * Get the current ServletContext.
208      * @return the current ServletContext.
209      */

210     protected ServletContext JavaDoc getServletContext()
211     {
212         return _servletContext;
213     }
214     
215     /**
216      * Set the AdapterContext.
217      * @param context the AdapterContext to set.
218      */

219     public void setContext( AdapterContext context )
220     {
221         Object JavaDoc servletContext = context.getExternalContext();
222         assert servletContext instanceof ServletContext JavaDoc : servletContext;
223         _servletContext = ( ServletContext JavaDoc ) servletContext;
224         _eventReporter = new DefaultPageFlowEventReporter( _servletContext );
225     }
226     
227     /**
228      * Get the name of the platform, which may be used to find platform-specific configuration files. This default
229      * implementation returns "generic".
230      *
231      * @return the name of the platform ("generic" in this default implementation).
232      */

233     public String JavaDoc getPlatformName()
234     {
235         return "generic";
236     }
237
238     /**
239      * Get an event reporter, which will be notified of events like "page flow created", "action raised", etc.
240      * This default implementation returns an instance of {@link DefaultPageFlowEventReporter}.
241      *
242      * @return a {@link PageFlowEventReporter}.
243      */

244     public PageFlowEventReporter getEventReporter()
245     {
246         return _eventReporter;
247     }
248 }
249
Popular Tags