Source Code Cross Referenced for ExceptionHandler.java in  » Mail-Clients » columba-1.4 » org » columba » core » gui » exception » 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 » Mail Clients » columba 1.4 » org.columba.core.gui.exception 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // The contents of this file are subject to the Mozilla Public License Version
002:        // 1.1
003:        //(the "License"); you may not use this file except in compliance with the
004:        //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005:        //
006:        //Software distributed under the License is distributed on an "AS IS" basis,
007:        //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008:        //for the specific language governing rights and
009:        //limitations under the License.
010:        //
011:        //The Original Code is "The Columba Project"
012:        //
013:        //The Initial Developers of the Original Code are Frederik Dietz and Timo
014:        // Stich.
015:        //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016:        //
017:        //All Rights Reserved.
018:
019:        package org.columba.core.gui.exception;
020:
021:        import java.io.IOException;
022:        import java.io.PrintWriter;
023:        import java.io.StringWriter;
024:        import java.net.ConnectException;
025:        import java.net.NoRouteToHostException;
026:        import java.net.PortUnreachableException;
027:        import java.net.SocketException;
028:        import java.net.SocketTimeoutException;
029:        import java.net.UnknownHostException;
030:        import java.text.MessageFormat;
031:        import java.util.logging.Logger;
032:
033:        import org.columba.api.exception.IExceptionListener;
034:        import org.columba.core.connectionstate.ConnectionStateImpl;
035:        import org.columba.core.gui.dialog.ErrorDialog;
036:        import org.columba.core.resourceloader.GlobalResourceLoader;
037:        import org.columba.ristretto.imap.IMAPDisconnectedException;
038:        import org.columba.ristretto.imap.IMAPException;
039:        import org.columba.ristretto.io.ConnectionDroppedException;
040:
041:        import sun.net.ConnectionResetException;
042:
043:        /**
044:         * Handles all exceptions catched by Worker.construct(). Opens error dialogs.
045:         * 
046:         * @author fdietz
047:         */
048:        public class ExceptionHandler implements  IExceptionListener {
049:            private static final String RESOURCE_PATH = "org.columba.core.i18n.dialog";
050:
051:            /** JDK 1.4+ logging framework logger, used for logging. */
052:            private static final Logger LOG = Logger
053:                    .getLogger("org.columba.api.command");
054:
055:            /**
056:             * Handle all kinds of exceptions.
057:             * 
058:             * @param e
059:             *            exception to process
060:             */
061:            public void processException(Exception e) {
062:                // Print the stacktrace to our log file.
063:                StringWriter error = new StringWriter();
064:                e.printStackTrace(new PrintWriter(error));
065:                LOG.severe(error.toString());
066:
067:                if (e instanceof  SocketException) {
068:                    processSocketException((SocketException) e);
069:                    ConnectionStateImpl.getInstance().setOnline(false);
070:                } else if (e instanceof  IOException) {
071:                    processIOException((IOException) e);
072:                } else if (e instanceof  IMAPException) {
073:                    processIMAPExcpetion((IMAPException) e);
074:                } else {
075:                    // show error dialog, with exception message and stack-trace
076:                    // -> dialog also provides a button for the user to easily
077:                    // -> report a bug
078:                    showErrorDialog(e.getMessage(), e);
079:                }
080:            }
081:
082:            /**
083:             * @param exception
084:             */
085:            private void processIMAPExcpetion(IMAPException exception) {
086:                String errorMessage = "";
087:                String serverResponse = "";
088:
089:                if (exception.getResponse() != null) {
090:                    serverResponse = ": "
091:                            + exception.getResponse().getResponseMessage();
092:                }
093:
094:                if (exception instanceof  IMAPDisconnectedException) {
095:                    errorMessage = GlobalResourceLoader.getString(
096:                            RESOURCE_PATH, "error", "imap_disconnected_error");
097:                } else {
098:                    errorMessage = GlobalResourceLoader.getString(
099:                            RESOURCE_PATH, "error", "imap_error")
100:                            + serverResponse;
101:                }
102:
103:                showErrorDialog(errorMessage, exception);
104:            }
105:
106:            /**
107:             * Handle all java.net.SocketException
108:             * 
109:             * @param e
110:             *            a socket exception
111:             */
112:            private void processSocketException(SocketException e) {
113:                String errorMessage = "";
114:
115:                if (e instanceof  ConnectException) {
116:                    errorMessage = GlobalResourceLoader.getString(
117:                            RESOURCE_PATH, "error", "connect_error");
118:                } else if (e instanceof  NoRouteToHostException) {
119:                    errorMessage = GlobalResourceLoader.getString(
120:                            RESOURCE_PATH, "error", "no_route_to_host_error");
121:                } else if (e instanceof  PortUnreachableException) {
122:                    errorMessage = GlobalResourceLoader.getString(
123:                            RESOURCE_PATH, "error", "port_unreachable_error");
124:                } else if (e instanceof  ConnectionResetException) {
125:                    errorMessage = GlobalResourceLoader.getString(
126:                            RESOURCE_PATH, "error", "connection_reset");
127:                } else {
128:                    errorMessage = GlobalResourceLoader.getString(
129:                            RESOURCE_PATH, "error", "generic_socket_error");
130:                }
131:
132:                showErrorDialog(errorMessage, e);
133:            }
134:
135:            /**
136:             * Handle all java.io.IOExceptions
137:             * 
138:             * @param e
139:             *            io exception to process
140:             */
141:            private void processIOException(IOException e) {
142:                String errorMessage = e.getMessage();
143:
144:                if (e instanceof  SocketTimeoutException) {
145:                    errorMessage = GlobalResourceLoader.getString(
146:                            RESOURCE_PATH, "error", "socket_timeout_error");
147:                } else if (e instanceof  UnknownHostException) {
148:                    errorMessage = MessageFormat.format(GlobalResourceLoader
149:                            .getString(RESOURCE_PATH, "error",
150:                                    "unknown_host_error"), new Object[] { e
151:                            .getMessage() });
152:                } else if (e instanceof  ConnectionDroppedException) {
153:                    errorMessage = GlobalResourceLoader.getString(
154:                            RESOURCE_PATH, "error", "connection_dropped_error");
155:                } else {
156:                    errorMessage = GlobalResourceLoader.getString(
157:                            RESOURCE_PATH, "error", "generic_io_error");
158:                }
159:
160:                showErrorDialog(errorMessage, e);
161:            }
162:
163:            /**
164:             * Show error dialog.
165:             * 
166:             * @param errorMessage
167:             *            human-readable error message
168:             * @param e
169:             *            exception to process
170:             */
171:            private void showErrorDialog(String details, Exception e) {
172:
173:                if (details == null)
174:                    details = e.toString();
175:
176:                ErrorDialog.createDialog(details, e);
177:
178:            }
179:
180:            public void exceptionOccured(Exception e) {
181:                processException(e);
182:            }
183:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.