Source Code Cross Referenced for DelegatingActionUtils.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-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.struts;
018:
019:        import org.apache.commons.logging.Log;
020:        import org.apache.commons.logging.LogFactory;
021:        import org.apache.struts.action.ActionMapping;
022:        import org.apache.struts.action.ActionServlet;
023:        import org.apache.struts.config.ModuleConfig;
024:
025:        import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
026:        import org.springframework.web.context.WebApplicationContext;
027:        import org.springframework.web.context.support.WebApplicationContextUtils;
028:
029:        /**
030:         * Common methods for letting Struts Actions work with a
031:         * Spring WebApplicationContext.
032:         *
033:         * <p>As everything in Struts is based on concrete inheritance,
034:         * we have to provide an Action subclass (DelegatingActionProxy) and
035:         * two RequestProcessor subclasses (DelegatingRequestProcessor and
036:         * DelegatingTilesRequestProcessor). The only way to share common
037:         * functionality is a utility class like this one.
038:         *
039:         * @author Juergen Hoeller
040:         * @since 1.0.2
041:         * @see DelegatingActionProxy
042:         * @see DelegatingRequestProcessor
043:         * @see DelegatingTilesRequestProcessor
044:         */
045:        public abstract class DelegatingActionUtils {
046:
047:            /**
048:             * The name of the autowire init-param specified on the Struts ActionServlet:
049:             * "spring.autowire"
050:             */
051:            public static final String PARAM_AUTOWIRE = "spring.autowire";
052:
053:            /**
054:             * The name of the dependency check init-param specified on the Struts ActionServlet:
055:             * "spring.dependencyCheck"
056:             */
057:            public static final String PARAM_DEPENDENCY_CHECK = "spring.dependencyCheck";
058:
059:            /**
060:             * Value of the autowire init-param that indicates autowiring by name:
061:             * "byName"
062:             */
063:            public static final String AUTOWIRE_BY_NAME = "byName";
064:
065:            /**
066:             * Value of the autowire init-param that indicates autowiring by type:
067:             * "byType"
068:             */
069:            public static final String AUTOWIRE_BY_TYPE = "byType";
070:
071:            private static final Log logger = LogFactory
072:                    .getLog(DelegatingActionUtils.class);
073:
074:            /**
075:             * Fetch ContextLoaderPlugIn's WebApplicationContext from the ServletContext.
076:             * <p>Checks for a module-specific context first, falling back to the
077:             * context for the default module else.
078:             * @param actionServlet the associated ActionServlet
079:             * @param moduleConfig the associated ModuleConfig (can be <code>null</code>)
080:             * @return the WebApplicationContext, or <code>null</code> if none
081:             * @see ContextLoaderPlugIn#SERVLET_CONTEXT_PREFIX
082:             */
083:            public static WebApplicationContext getWebApplicationContext(
084:                    ActionServlet actionServlet, ModuleConfig moduleConfig) {
085:
086:                WebApplicationContext wac = null;
087:                String modulePrefix = null;
088:
089:                // Try module-specific attribute.
090:                if (moduleConfig != null) {
091:                    modulePrefix = moduleConfig.getPrefix();
092:                    wac = (WebApplicationContext) actionServlet
093:                            .getServletContext().getAttribute(
094:                                    ContextLoaderPlugIn.SERVLET_CONTEXT_PREFIX
095:                                            + modulePrefix);
096:                }
097:
098:                // If not found, try attribute for default module.
099:                if (wac == null && !"".equals(modulePrefix)) {
100:                    wac = (WebApplicationContext) actionServlet
101:                            .getServletContext().getAttribute(
102:                                    ContextLoaderPlugIn.SERVLET_CONTEXT_PREFIX);
103:                }
104:
105:                return wac;
106:            }
107:
108:            /**
109:             * Fetch ContextLoaderPlugIn's WebApplicationContext from the ServletContext.
110:             * <p>Checks for a module-specific context first, falling back to the
111:             * context for the default module else.
112:             * @param actionServlet the associated ActionServlet
113:             * @param moduleConfig the associated ModuleConfig (can be <code>null</code>)
114:             * @return the WebApplicationContext
115:             * @throws IllegalStateException if no WebApplicationContext could be found
116:             * @see ContextLoaderPlugIn#SERVLET_CONTEXT_PREFIX
117:             */
118:            public static WebApplicationContext getRequiredWebApplicationContext(
119:                    ActionServlet actionServlet, ModuleConfig moduleConfig)
120:                    throws IllegalStateException {
121:
122:                WebApplicationContext wac = getWebApplicationContext(
123:                        actionServlet, moduleConfig);
124:                // If no Struts-specific context found, throw an exception.
125:                if (wac == null) {
126:                    throw new IllegalStateException(
127:                            "Could not find ContextLoaderPlugIn's WebApplicationContext as ServletContext attribute ["
128:                                    + ContextLoaderPlugIn.SERVLET_CONTEXT_PREFIX
129:                                    + "]: Did you register ["
130:                                    + ContextLoaderPlugIn.class.getName()
131:                                    + "]?");
132:                }
133:                return wac;
134:            }
135:
136:            /**
137:             * Find most specific context available: check ContextLoaderPlugIn's
138:             * WebApplicationContext first, fall back to root WebApplicationContext else.
139:             * <p>When checking the ContextLoaderPlugIn context: checks for a module-specific
140:             * context first, falling back to the context for the default module else.
141:             * @param actionServlet the associated ActionServlet
142:             * @param moduleConfig the associated ModuleConfig (can be <code>null</code>)
143:             * @return the WebApplicationContext
144:             * @throws IllegalStateException if no WebApplicationContext could be found
145:             * @see #getWebApplicationContext
146:             * @see org.springframework.web.context.support.WebApplicationContextUtils#getRequiredWebApplicationContext
147:             */
148:            public static WebApplicationContext findRequiredWebApplicationContext(
149:                    ActionServlet actionServlet, ModuleConfig moduleConfig)
150:                    throws IllegalStateException {
151:
152:                WebApplicationContext wac = getWebApplicationContext(
153:                        actionServlet, moduleConfig);
154:                // If no Struts-specific context found, fall back to root context.
155:                if (wac == null) {
156:                    wac = WebApplicationContextUtils
157:                            .getRequiredWebApplicationContext(actionServlet
158:                                    .getServletContext());
159:                }
160:                return wac;
161:            }
162:
163:            /**
164:             * Default implementation of Action bean determination, taking
165:             * the mapping path and prepending the module prefix, if any.
166:             * @param mapping the Struts ActionMapping
167:             * @return the name of the Action bean
168:             * @see org.apache.struts.action.ActionMapping#getPath
169:             * @see org.apache.struts.config.ModuleConfig#getPrefix
170:             */
171:            public static String determineActionBeanName(ActionMapping mapping) {
172:                String prefix = mapping.getModuleConfig().getPrefix();
173:                String path = mapping.getPath();
174:                String beanName = prefix + path;
175:                if (logger.isDebugEnabled()) {
176:                    logger.debug("DelegatingActionProxy with mapping path '"
177:                            + path + "' and module prefix '" + prefix
178:                            + "' delegating to Spring bean with name ["
179:                            + beanName + "]");
180:                }
181:                return beanName;
182:            }
183:
184:            /**
185:             * Determine the autowire mode from the "autowire" init-param of the
186:             * Struts ActionServlet, falling back to "AUTOWIRE_BY_TYPE" as default.
187:             * @param actionServlet the Struts ActionServlet
188:             * @return the autowire mode to use
189:             * @see #PARAM_AUTOWIRE
190:             * @see #AUTOWIRE_BY_NAME
191:             * @see #AUTOWIRE_BY_TYPE
192:             * @see org.springframework.beans.factory.config.AutowireCapableBeanFactory#autowireBeanProperties
193:             * @see org.springframework.beans.factory.config.AutowireCapableBeanFactory#AUTOWIRE_BY_TYPE
194:             * @see org.springframework.beans.factory.config.AutowireCapableBeanFactory#AUTOWIRE_BY_NAME
195:             */
196:            public static int getAutowireMode(ActionServlet actionServlet) {
197:                String autowire = actionServlet
198:                        .getInitParameter(PARAM_AUTOWIRE);
199:                if (autowire != null) {
200:                    if (AUTOWIRE_BY_NAME.equals(autowire)) {
201:                        return AutowireCapableBeanFactory.AUTOWIRE_BY_NAME;
202:                    } else if (!AUTOWIRE_BY_TYPE.equals(autowire)) {
203:                        throw new IllegalArgumentException(
204:                                "ActionServlet 'autowire' parameter must be 'byName' or 'byType'");
205:                    }
206:                }
207:                return AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE;
208:            }
209:
210:            /**
211:             * Determine the dependency check to use from the "dependencyCheck" init-param
212:             * of the Struts ActionServlet, falling back to no dependency check as default.
213:             * @param actionServlet the Struts ActionServlet
214:             * @return whether to enforce a dependency check or not
215:             * @see #PARAM_DEPENDENCY_CHECK
216:             * @see org.springframework.beans.factory.config.AutowireCapableBeanFactory#autowireBeanProperties
217:             */
218:            public static boolean getDependencyCheck(ActionServlet actionServlet) {
219:                String dependencyCheck = actionServlet
220:                        .getInitParameter(PARAM_DEPENDENCY_CHECK);
221:                return Boolean.valueOf(dependencyCheck).booleanValue();
222:            }
223:
224:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.