Source Code Cross Referenced for AbstractController.java in  » J2EE » spring-framework-2.0.6 » org » springframework » web » servlet » mvc » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » spring framework 2.0.6 » org.springframework.web.servlet.mvc 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2002-2006 the original author or authors.
003:         * 
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         * 
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.springframework.web.servlet.mvc;
018:
019:        import javax.servlet.http.HttpServletRequest;
020:        import javax.servlet.http.HttpServletResponse;
021:        import javax.servlet.http.HttpSession;
022:
023:        import org.springframework.web.servlet.ModelAndView;
024:        import org.springframework.web.servlet.support.WebContentGenerator;
025:        import org.springframework.web.util.WebUtils;
026:
027:        /**
028:         * <p>Convenient superclass for controller implementations, using the Template
029:         * Method design pattern.</p>
030:         * 
031:         * <p>As stated in the {@link org.springframework.web.servlet.mvc.Controller Controller}
032:         * interface, a lot of functionality is already provided by certain abstract
033:         * base controllers. The AbstractController is one of the most important
034:         * abstract base controller providing basic features such as the generation
035:         * of caching headers and the enabling or disabling of
036:         * supported methods (GET/POST).</p>
037:         *
038:         * <p><b><a name="workflow">Workflow
039:         * (<a href="Controller.html#workflow">and that defined by interface</a>):</b><br>
040:         * <ol>
041:         *  <li>{@link #handleRequest(HttpServletRequest,HttpServletResponse) handleRequest()}
042:         *      will be called by the DispatcherServlet</li>
043:         *  <li>Inspection of supported methods (ServletException if request method
044:         *      is not support)</li>
045:         *  <li>If session is required, try to get it (ServletException if not found)</li>
046:         *  <li>Set caching headers if needed according to cacheSeconds propery</li>
047:         *  <li>Call abstract method {@link #handleRequestInternal(HttpServletRequest,HttpServletResponse) handleRequestInternal()}
048:         *      (optionally synchronizing around the call on the HttpSession),
049:         *      which should be implemented by extending classes to provide actual
050:         *      functionality to return {@link org.springframework.web.servlet.ModelAndView ModelAndView} objects.</li>
051:         * </ol>
052:         * </p>
053:         *
054:         * <p><b><a name="config">Exposed configuration properties</a>
055:         * (<a href="Controller.html#config">and those defined by interface</a>):</b><br>
056:         * <table border="1">
057:         *  <tr>
058:         *      <td><b>name</b></th>
059:         *      <td><b>default</b></td>
060:         *      <td><b>description</b></td>
061:         *  </tr>
062:         *  <tr>
063:         *      <td>supportedMethods</td>
064:         *      <td>GET,POST</td>
065:         *      <td>comma-separated (CSV) list of methods supported by this controller,
066:         *          such as GET, POST and PUT</td>
067:         *  </tr>
068:         *  <tr>
069:         *      <td>requireSession</td>
070:         *      <td>false</td>
071:         *      <td>whether a session should be required for requests to be able to
072:         *          be handled by this controller. This ensures that derived controller
073:         *          can - without fear of null pointers - call request.getSession() to
074:         *          retrieve a session. If no session can be found while processing
075:         *          the request, a ServletException will be thrown</td>
076:         *  </tr>
077:         *  <tr>
078:         *      <td>cacheSeconds</td>
079:         *      <td>-1</td>
080:         *      <td>indicates the amount of seconds to include in the cache header
081:         *          for the response following on this request. 0 (zero) will include
082:         *          headers for no caching at all, -1 (the default) will not generate
083:         *          <i>any headers</i> and any positive number will generate headers
084:         *          that state the amount indicated as seconds to cache the content</td>
085:         *  </tr>
086:         *  <tr>
087:         *      <td>synchronizeOnSession</td>
088:         *      <td>false</td>
089:         *      <td>whether the call to <code>handleRequestInternal</code> should be
090:         *          synchronized around the HttpSession, to serialize invocations
091:         *          from the same client. No effect if there is no HttpSession.
092:         *      </td>
093:         *  </tr>
094:         * </table>
095:         *
096:         * @author Rod Johnson
097:         * @author Juergen Hoeller
098:         * @see WebContentInterceptor
099:         */
100:        public abstract class AbstractController extends WebContentGenerator
101:                implements  Controller {
102:
103:            private boolean synchronizeOnSession = false;
104:
105:            /**
106:             * Set if controller execution should be synchronized on the session,
107:             * to serialize parallel invocations from the same client.
108:             * <p>More specifically, the execution of the <code>handleRequestInternal</code>
109:             * method will get synchronized if this flag is "true". The best available
110:             * session mutex will be used for the synchronization; ideally, this will
111:             * be a mutex exposed by HttpSessionMutexListener.
112:             * <p>The session mutex is guaranteed to be the same object during
113:             * the entire lifetime of the session, available under the key defined
114:             * by the <code>SESSION_MUTEX_ATTRIBUTE</code> constant. It serves as a
115:             * safe reference to synchronize on for locking on the current session.
116:             * <p>In many cases, the HttpSession reference itself is a safe mutex
117:             * as well, since it will always be the same object reference for the
118:             * same active logical session. However, this is not guaranteed across
119:             * different servlet containers; the only 100% safe way is a session mutex.
120:             * @see org.springframework.web.servlet.mvc.AbstractController#handleRequestInternal
121:             * @see org.springframework.web.util.HttpSessionMutexListener
122:             * @see org.springframework.web.util.WebUtils#getSessionMutex(javax.servlet.http.HttpSession)
123:             */
124:            public final void setSynchronizeOnSession(
125:                    boolean synchronizeOnSession) {
126:                this .synchronizeOnSession = synchronizeOnSession;
127:            }
128:
129:            /**
130:             * Return whether controller execution should be synchronized on the session.
131:             */
132:            public final boolean isSynchronizeOnSession() {
133:                return synchronizeOnSession;
134:            }
135:
136:            public final ModelAndView handleRequest(HttpServletRequest request,
137:                    HttpServletResponse response) throws Exception {
138:
139:                // Delegate to WebContentGenerator for checking and preparing.
140:                checkAndPrepare(request, response, this  instanceof  LastModified);
141:
142:                // Execute handleRequestInternal in synchronized block if required.
143:                if (this .synchronizeOnSession) {
144:                    HttpSession session = request.getSession(false);
145:                    if (session != null) {
146:                        Object mutex = WebUtils.getSessionMutex(session);
147:                        synchronized (mutex) {
148:                            return handleRequestInternal(request, response);
149:                        }
150:                    }
151:                }
152:
153:                return handleRequestInternal(request, response);
154:            }
155:
156:            /**
157:             * Template method. Subclasses must implement this.
158:             * The contract is the same as for <code>handleRequest</code>.
159:             * @see #handleRequest
160:             */
161:            protected abstract ModelAndView handleRequestInternal(
162:                    HttpServletRequest request, HttpServletResponse response)
163:                    throws Exception;
164:
165:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.