Source Code Cross Referenced for WebApplication.java in  » Development » jodd » jodd » madvoc » 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 » Development » jodd » jodd.madvoc 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
002:
003:        package jodd.madvoc;
004:
005:        import jodd.madvoc.result.ActionResult;
006:        import jodd.madvoc.result.ServletDispatcherResult;
007:        import jodd.madvoc.interceptor.ActionInterceptor;
008:        import jodd.madvoc.interceptor.ServletConfigInterceptor;
009:        import jodd.madvoc.interceptor.RenderViewInterceptor;
010:        import jodd.servlet.DispatcherUtil;
011:        import jodd.servlet.upload.FileUploadFactory;
012:        import jodd.servlet.upload.impl.AdaptiveFileUpload;
013:
014:        import javax.servlet.ServletContext;
015:        import javax.servlet.http.HttpServletRequest;
016:        import javax.servlet.http.HttpServletResponse;
017:        import java.util.Map;
018:        import java.util.HashMap;
019:
020:        /**
021:         * Contains all configurations and definitions for single web application.
022:         * <p>
023:         * Custom implementations may override this class to enhance several different
024:         * functionalities. Of course, it would be more modular to have separate
025:         * interface for each functionality, but this will lead to too-many
026:         * interfaces and classes. Anyhow, if needed, one abstract modular
027:         * web application may be created as a subclass.
028:         */
029:        public class WebApplication {
030:
031:            @SuppressWarnings({"unchecked"})
032:            public WebApplication(ServletContext servletContext) {
033:                configs = new HashMap<String, ActionConfig>();
034:                results = new HashMap<String, ActionResult>();
035:                resultsAliases = new HashMap<String, String>();
036:                this .servletContext = servletContext;
037:                defaultActionResultName = ServletDispatcherResult.NAME;
038:                encoding = "UTF-8";
039:                fileUploadFactory = new AdaptiveFileUpload.Factory();
040:                defaultInterceptors = new Class[] {
041:                        RenderViewInterceptor.class,
042:                        ServletConfigInterceptor.class };
043:            }
044:
045:            // ---------------------------------------------------------------- encoding
046:
047:            protected String encoding;
048:
049:            /**
050:             * Returns character encoding.
051:             */
052:            public String getEncoding() {
053:                return this .encoding;
054:            }
055:
056:            /**
057:             * Sets web application encoding.
058:             */
059:            public void setEncoding(String encoding) {
060:                this .encoding = encoding;
061:            }
062:
063:            // ---------------------------------------------------------------- file upload factory
064:
065:            protected FileUploadFactory fileUploadFactory;
066:
067:            /**
068:             * Returns current file upload factory.
069:             */
070:            public FileUploadFactory getFileUploadFactory() {
071:                return fileUploadFactory;
072:            }
073:
074:            /**
075:             * Sets file upload factory.
076:             */
077:            public void setFileUploadFactory(FileUploadFactory fileUploadFactory) {
078:                this .fileUploadFactory = fileUploadFactory;
079:            }
080:
081:            // ---------------------------------------------------------------- app ctx
082:
083:            protected final ServletContext servletContext;
084:
085:            /**
086:             * Returns application {@link javax.servlet.ServletContext}.
087:             */
088:            public ServletContext getServletContext() {
089:                return servletContext;
090:            }
091:
092:            // ---------------------------------------------------------------- action configs
093:
094:            protected final Map<String, ActionConfig> configs;
095:
096:            /**
097:             * Returns all registered action configurations. Should be used with care and
098:             * usually only during configuration.
099:             */
100:            public Map<String, ActionConfig> getAllActionConfigs() {
101:                return configs;
102:            }
103:
104:            /**
105:             * Registers new action config.
106:             */
107:            public void register(ActionConfig actionConfig) {
108:                configs.put(actionConfig.actionPath, actionConfig);
109:            }
110:
111:            /**
112:             * Returns action config assigned to provided actionPath.
113:             */
114:            public ActionConfig lookupActionConfig(String actionPath) {
115:                return configs.get(actionPath);
116:            }
117:
118:            /**
119:             * Builds action request for current servlet request. Returns <code>null</code> if
120:             * servlet path is not registeres as action path.
121:             * <p>
122:             * Custom implementations may include different logic for converting request path to action path.
123:             */
124:            public ActionRequest buildActionRequest(HttpServletRequest request,
125:                    HttpServletResponse response) {
126:                String requestPath = DispatcherUtil.getServletPath(request);
127:                ActionConfig config = configs.get(requestPath);
128:                if (config == null) {
129:                    return null;
130:                }
131:                return buildActionRequest(config, request, response);
132:            }
133:
134:            // ---------------------------------------------------------------- default interceptors
135:
136:            protected Class<? extends ActionInterceptor>[] defaultInterceptors;
137:
138:            /**
139:             * Returns default intercetors.
140:             */
141:            public Class<? extends ActionInterceptor>[] getDefaultInterceptors() {
142:                return defaultInterceptors;
143:            }
144:
145:            /**
146:             * Set default interceptors.
147:             */
148:            public void setDefaultInterceptors(
149:                    Class<? extends ActionInterceptor>[] defaultInterceptors) {
150:                this .defaultInterceptors = defaultInterceptors;
151:            }
152:
153:            // ---------------------------------------------------------------- result handlers
154:
155:            protected final Map<String, ActionResult> results;
156:
157:            /**
158:             * Registes new action result.
159:             */
160:            public void register(ActionResult actionResult) {
161:                results.put(actionResult.getName(), actionResult);
162:            }
163:
164:            /**
165:             * Returns action result for specified result name.
166:             */
167:            public ActionResult lookupActionResult(String resultName) {
168:                return results.get(resultName);
169:            }
170:
171:            protected String defaultActionResultName;
172:
173:            /**
174:             * Specifes default result name. Result must be already
175:             * registered before setting it to default.
176:             * @see #register(jodd.madvoc.result.ActionResult) 
177:             */
178:            public void setDefaultActionResultName(String name) {
179:                defaultActionResultName = name;
180:            }
181:
182:            /**
183:             * Returns default action result name.
184:             */
185:            public String getDefaultActionResultName() {
186:                return defaultActionResultName;
187:            }
188:
189:            // ---------------------------------------------------------------- result aliases
190:
191:            protected Map<String, String> resultsAliases;
192:
193:            /**
194:             * Sets alias value.
195:             */
196:            public void setResultAlias(String alias, String target) {
197:                if (alias.startsWith("/") == false) {
198:                    alias = '/' + alias;
199:                }
200:                resultsAliases.put(alias, target);
201:            }
202:
203:            /**
204:             * Returns result alias or its value result if no alias is defined. 
205:             */
206:            public String getResultAlias(String alias) {
207:                String value = resultsAliases.get(alias);
208:                if (value != null) {
209:                    return value;
210:                }
211:                return alias;
212:            }
213:
214:            // ---------------------------------------------------------------- object factory
215:
216:            /**
217:             * Creates new {@link ActionRequest},.
218:             */
219:            protected ActionRequest buildActionRequest(ActionConfig config,
220:                    HttpServletRequest request, HttpServletResponse response) {
221:                return new ActionRequest(this , config, request, response);
222:            }
223:
224:            /**
225:             * Creates new {@link jodd.madvoc.interceptor.ActionInterceptor}.
226:             */
227:            public ActionInterceptor buildInterceptor(
228:                    Class<? extends ActionInterceptor> actionInterceptorClass) {
229:                ActionInterceptor interceptor;
230:                try {
231:                    interceptor = actionInterceptorClass.newInstance();
232:                    //interceptor.init(this); toask add intreceptor initialization if needed
233:                } catch (InstantiationException iex) {
234:                    throw new MadvocException(
235:                            "Unable to create Madvoc action interceptor '"
236:                                    + actionInterceptorClass + "'.", iex);
237:                } catch (IllegalAccessException iaex) {
238:                    throw new MadvocException(
239:                            "Not enough rights to create Madvoc action interceptor '"
240:                                    + actionInterceptorClass + "'.", iaex);
241:                }
242:                return interceptor;
243:            }
244:
245:            /**
246:             * Creates a new action object from {@link ActionConfig}.
247:             */
248:            public Object buildAction(ActionConfig actionConfig) {
249:                Object action;
250:                try {
251:                    action = actionConfig.actionClass.newInstance();
252:                } catch (InstantiationException iex) {
253:                    throw new MadvocException(
254:                            "Unable to create Madvoc action.", iex);
255:                } catch (IllegalAccessException iaex) {
256:                    throw new MadvocException(
257:                            "Not enough rights to create Madvoc action.", iaex);
258:                }
259:                return action;
260:            }
261:
262:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.