Source Code Cross Referenced for DefaultExceptionHandlerConfig.java in  » Testing » mockrunner-0.4 » com » mockrunner » 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 » Testing » mockrunner 0.4 » com.mockrunner.struts 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.mockrunner.struts;
002:
003:        import javax.servlet.ServletException;
004:        import javax.servlet.http.HttpServletRequest;
005:        import javax.servlet.http.HttpServletResponse;
006:
007:        import org.apache.struts.action.ActionForm;
008:        import org.apache.struts.action.ActionMapping;
009:        import org.apache.struts.action.ExceptionHandler;
010:        import org.apache.struts.config.ExceptionConfig;
011:
012:        import com.mockrunner.base.NestedApplicationException;
013:
014:        /**
015:         * The default implementation of {@link ExceptionHandlerConfig}. It uses the Struts
016:         * exception handling mechanism. Use the various constructors to provide your subclass
017:         * of <code>ExceptionHandler</code> or to configure exception handling using an
018:         * instance of <code>ExceptionConfig</code>. The <code>ExceptionConfig</code> class
019:         * allows you to set the handler class an exception type.
020:         * Use {@link ActionTestModule#addExceptionHandler} to register an exception handler.
021:         */
022:        public class DefaultExceptionHandlerConfig implements 
023:                ExceptionHandlerConfig {
024:            private ExceptionConfig exceptionConfig;
025:            private ExceptionHandler exceptionHandler;
026:            private Class exceptionClass;
027:
028:            public DefaultExceptionHandlerConfig(ExceptionConfig exceptionConfig) {
029:                this .exceptionConfig = exceptionConfig;
030:                try {
031:                    Class handlerClass = exceptionConfig.getClass()
032:                            .getClassLoader().loadClass(
033:                                    exceptionConfig.getHandler());
034:                    exceptionHandler = (ExceptionHandler) handlerClass
035:                            .newInstance();
036:                    exceptionClass = exceptionConfig.getClass()
037:                            .getClassLoader().loadClass(
038:                                    exceptionConfig.getType());
039:                } catch (Exception exc) {
040:                    throw new NestedApplicationException(exc);
041:                }
042:            }
043:
044:            public DefaultExceptionHandlerConfig(
045:                    ExceptionHandler exceptionHandler,
046:                    ExceptionConfig exceptionConfig) {
047:                this .exceptionHandler = exceptionHandler;
048:                this .exceptionConfig = exceptionConfig;
049:                this .exceptionConfig.setHandler(exceptionHandler.getClass()
050:                        .getName());
051:                try {
052:                    exceptionClass = exceptionConfig.getClass()
053:                            .getClassLoader().loadClass(
054:                                    exceptionConfig.getType());
055:                } catch (Exception exc) {
056:                    throw new NestedApplicationException(exc);
057:                }
058:            }
059:
060:            public DefaultExceptionHandlerConfig(
061:                    ExceptionHandler exceptionHandler, Class exceptionClass) {
062:                this .exceptionHandler = exceptionHandler;
063:                this .exceptionClass = exceptionClass;
064:                this .exceptionConfig = new ExceptionConfig();
065:                this .exceptionConfig.setHandler(exceptionHandler.getClass()
066:                        .getName());
067:                this .exceptionConfig.setType(exceptionClass.getName());
068:            }
069:
070:            public DefaultExceptionHandlerConfig(Class exceptionClass) {
071:                this .exceptionHandler = new ExceptionHandler();
072:                this .exceptionClass = exceptionClass;
073:                this .exceptionConfig = new ExceptionConfig();
074:                this .exceptionConfig.setHandler(ExceptionHandler.class
075:                        .getName());
076:                this .exceptionConfig.setType(exceptionClass.getName());
077:            }
078:
079:            public boolean canHandle(Exception exception) {
080:                return exceptionClass.isInstance(exception);
081:            }
082:
083:            public Object handle(Exception exception, ActionMapping mapping,
084:                    ActionForm form, HttpServletRequest request,
085:                    HttpServletResponse response) throws ServletException {
086:                if (!canHandle(exception))
087:                    return null;
088:                if (null == exceptionHandler)
089:                    return null;
090:                return exceptionHandler.execute((Exception) exception,
091:                        exceptionConfig, mapping, form, request, response);
092:            }
093:
094:            /**
095:             * Get the underlying <code>ExceptionConfig</code>. If you did not provide
096:             * an instance of <code>ExceptionConfig</code>, this class will create one
097:             * internally.
098:             * @return the <code>ExceptionConfig</code>
099:             */
100:            public ExceptionConfig getExceptionConfig() {
101:                return exceptionConfig;
102:            }
103:
104:            /**
105:             * Get the underlying <code>ExceptionHandler</code>.
106:             * @return the <code>ExceptionHandler</code>
107:             */
108:            public ExceptionHandler getExceptionHandler() {
109:                return exceptionHandler;
110:            }
111:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.