Source Code Cross Referenced for DelegatingRequestProcessor.java in  » J2EE » spring-framework-2.0.6 » org » springframework » web » struts » 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.struts 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2002-2007 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.struts;
018:
019:        import java.io.IOException;
020:
021:        import javax.servlet.ServletException;
022:        import javax.servlet.http.HttpServletRequest;
023:        import javax.servlet.http.HttpServletResponse;
024:
025:        import org.apache.struts.action.Action;
026:        import org.apache.struts.action.ActionMapping;
027:        import org.apache.struts.action.ActionServlet;
028:        import org.apache.struts.action.RequestProcessor;
029:        import org.apache.struts.config.ModuleConfig;
030:
031:        import org.springframework.beans.BeansException;
032:        import org.springframework.web.context.WebApplicationContext;
033:
034:        /**
035:         * Subclass of Struts's default {@link RequestProcessor} that looks up
036:         * Spring-managed Struts {@link Action Actions} defined in
037:         * {@link ContextLoaderPlugIn ContextLoaderPlugIn's} {@link WebApplicationContext}
038:         * (or, as a fallback, in the root <code>WebApplicationContext</code>).
039:         *
040:         * <p>In the Struts config file, you can either specify the original
041:         * <code>Action</code> class (as when generated by XDoclet), or no
042:         * <code>Action</code> class at all. In any case, Struts will delegate to an
043:         * <code>Action</code> bean in the <code>ContextLoaderPlugIn</code> context.
044:         *
045:         * <pre class="code">&lt;action path="/login" type="myapp.MyAction"/&gt;</pre>
046:         *
047:         * or
048:         *
049:         * <pre class="code">&lt;action path="/login"/&gt;</pre>
050:         *
051:         * The name of the <code>Action</code> bean in the
052:         * <code>WebApplicationContext</code> will be determined from the mapping path
053:         * and module prefix. This can be customized by overriding the
054:         * {@link #determineActionBeanName} method.
055:         *
056:         * <p>Example:
057:         * <ul>
058:         * <li>mapping path "/login" -> bean name "/login"<br>
059:         * <li>mapping path "/login", module prefix "/mymodule" ->
060:         * bean name "/mymodule/login"
061:         * </ul>
062:         *
063:         * <p>A corresponding bean definition in the <code>ContextLoaderPlugin</code>
064:         * context would look as follows; notice that the <code>Action</code> is now
065:         * able to leverage fully Spring's configuration facilities:
066:         *
067:         * <pre class="code">
068:         * &lt;bean name="/login" class="myapp.MyAction"&gt;
069:         *   &lt;property name="..."&gt;...&lt;/property&gt;
070:         * &lt;/bean&gt;</pre>
071:         *
072:         * Note that you can use a single <code>ContextLoaderPlugIn</code> for all
073:         * Struts modules. That context can in turn be loaded from multiple XML files,
074:         * for example split according to Struts modules. Alternatively, define one
075:         * <code>ContextLoaderPlugIn</code> per Struts module, specifying appropriate
076:         * "contextConfigLocation" parameters. In both cases, the Spring bean name has
077:         * to include the module prefix.
078:         *
079:         * <p>If you also need the Tiles setup functionality of the original
080:         * <code>TilesRequestProcessor</code>, use
081:         * <code>DelegatingTilesRequestProcessor</code>. As there is just a
082:         * single central class to customize in Struts, we have to provide another
083:         * subclass here, covering both the Tiles and the Spring delegation aspect.
084:         *
085:         * <p>If this <code>RequestProcessor</code> conflicts with the need for a
086:         * different <code>RequestProcessor</code> subclass (other than
087:         * <code>TilesRequestProcessor</code>), consider using
088:         * {@link DelegatingActionProxy} as the Struts <code>Action</code> type in
089:         * your struts-config file.
090:         *
091:         * <p>The default implementation delegates to the
092:         * <code>DelegatingActionUtils</code> class as much as possible, to reuse as
093:         * much code as possible despite the need to provide two
094:         * <code>RequestProcessor</code> subclasses. If you need to subclass yet
095:         * another <code>RequestProcessor</code>, take this class as a template,
096:         * delegating to <code>DelegatingActionUtils</code> just like it.
097:         *
098:         * @author Juergen Hoeller
099:         * @since 1.0.2
100:         * @see #determineActionBeanName
101:         * @see DelegatingTilesRequestProcessor
102:         * @see DelegatingActionProxy
103:         * @see DelegatingActionUtils
104:         * @see ContextLoaderPlugIn
105:         */
106:        public class DelegatingRequestProcessor extends RequestProcessor {
107:
108:            private WebApplicationContext webApplicationContext;
109:
110:            public void init(ActionServlet actionServlet,
111:                    ModuleConfig moduleConfig) throws ServletException {
112:                super .init(actionServlet, moduleConfig);
113:                if (actionServlet != null) {
114:                    this .webApplicationContext = initWebApplicationContext(
115:                            actionServlet, moduleConfig);
116:                }
117:            }
118:
119:            /**
120:             * Fetch ContextLoaderPlugIn's {@link WebApplicationContext} from the
121:             * <code>ServletContext</code>, falling back to the root
122:             * <code>WebApplicationContext</code>.
123:             * <p>This context is supposed to contain the Struts <code>Action</code>
124:             * beans to delegate to.
125:             * @param actionServlet the associated <code>ActionServlet</code>
126:             * @param moduleConfig the associated <code>ModuleConfig</code>
127:             * @return the <code>WebApplicationContext</code>
128:             * @throws IllegalStateException if no <code>WebApplicationContext</code> could be found
129:             * @see DelegatingActionUtils#findRequiredWebApplicationContext
130:             * @see ContextLoaderPlugIn#SERVLET_CONTEXT_PREFIX
131:             */
132:            protected WebApplicationContext initWebApplicationContext(
133:                    ActionServlet actionServlet, ModuleConfig moduleConfig)
134:                    throws IllegalStateException {
135:
136:                return DelegatingActionUtils.findRequiredWebApplicationContext(
137:                        actionServlet, moduleConfig);
138:            }
139:
140:            /**
141:             * Return the <code>WebApplicationContext</code> that this processor
142:             * delegates to.
143:             */
144:            protected final WebApplicationContext getWebApplicationContext() {
145:                return this .webApplicationContext;
146:            }
147:
148:            /**
149:             * Override the base class method to return the delegate action.
150:             * @see #getDelegateAction
151:             */
152:            protected Action processActionCreate(HttpServletRequest request,
153:                    HttpServletResponse response, ActionMapping mapping)
154:                    throws IOException {
155:
156:                Action action = getDelegateAction(mapping);
157:                if (action != null) {
158:                    return action;
159:                }
160:                return super .processActionCreate(request, response, mapping);
161:            }
162:
163:            /**
164:             * Return the delegate <code>Action</code> for the given mapping.
165:             * <p>The default implementation determines a bean name from the
166:             * given <code>ActionMapping</code> and looks up the corresponding
167:             * bean in the <code>WebApplicationContext</code>.
168:             * @param mapping the Struts <code>ActionMapping</code>
169:             * @return the delegate <code>Action</code>, or <code>null</code> if none found
170:             * @throws BeansException if thrown by <code>WebApplicationContext</code> methods
171:             * @see #determineActionBeanName
172:             */
173:            protected Action getDelegateAction(ActionMapping mapping)
174:                    throws BeansException {
175:                String beanName = determineActionBeanName(mapping);
176:                if (!getWebApplicationContext().containsBean(beanName)) {
177:                    return null;
178:                }
179:                return (Action) getWebApplicationContext().getBean(beanName,
180:                        Action.class);
181:            }
182:
183:            /**
184:             * Determine the name of the <code>Action</code> bean, to be looked up in
185:             * the <code>WebApplicationContext</code>.
186:             * <p>The default implementation takes the
187:             * {@link org.apache.struts.action.ActionMapping#getPath mapping path} and
188:             * prepends the
189:             * {@link org.apache.struts.config.ModuleConfig#getPrefix module prefix},
190:             * if any.
191:             * @param mapping the Struts <code>ActionMapping</code>
192:             * @return the name of the Action bean
193:             * @see DelegatingActionUtils#determineActionBeanName
194:             * @see org.apache.struts.action.ActionMapping#getPath
195:             * @see org.apache.struts.config.ModuleConfig#getPrefix
196:             */
197:            protected String determineActionBeanName(ActionMapping mapping) {
198:                return DelegatingActionUtils.determineActionBeanName(mapping);
199:            }
200:
201:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.