Source Code Cross Referenced for ExceptionHandler.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » apt » ui » internal » util » 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 » IDE Eclipse » jdt » org.eclipse.jdt.apt.ui.internal.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2007 IBM Corporation, BEA Systems, Inc., and others
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *   wharley@bea.com - based on org.eclipse.jdt.internal.ui.util.ExceptionHandler
010:         *******************************************************************************/package org.eclipse.jdt.apt.ui.internal.util;
011:
012:        import java.io.StringWriter;
013:        import java.lang.reflect.InvocationTargetException;
014:
015:        import org.eclipse.core.runtime.CoreException;
016:        import org.eclipse.core.runtime.IStatus;
017:        import org.eclipse.core.runtime.Status;
018:        import org.eclipse.jdt.apt.ui.internal.AptUIPlugin;
019:        import org.eclipse.jface.dialogs.ErrorDialog;
020:        import org.eclipse.jface.dialogs.MessageDialog;
021:        import org.eclipse.swt.widgets.Shell;
022:
023:        /**
024:         * This code is 
025:         * The default exception handler shows an error dialog when one of its handle methods
026:         * is called. If the passed exception is a <code>CoreException</code> an error dialog
027:         * pops up showing the exception's status information. For a <code>InvocationTargetException</code>
028:         * a normal message dialog pops up showing the exception's message. Additionally the exception
029:         * is written to the platform log.
030:         */
031:        public class ExceptionHandler {
032:
033:            private static ExceptionHandler fgInstance = new ExceptionHandler();
034:
035:            /**
036:             * Logs the given exception using the platform's logging mechanism. The exception is
037:             * logged as an error with the error code <code>AptUIPlugin.INTERNAL_ERROR</code>.
038:             */
039:            public static void log(Throwable t, String message) {
040:                AptUIPlugin.log(new Status(IStatus.ERROR,
041:                        AptUIPlugin.PLUGIN_ID, AptUIPlugin.INTERNAL_ERROR,
042:                        message, t));
043:            }
044:
045:            /**
046:             * Handles the given <code>CoreException</code>. The workbench shell is used as a parent
047:             * for the dialog window.
048:             * 
049:             * @param e the <code>CoreException</code> to be handled
050:             * @param title the dialog window's window title
051:             * @param message message to be displayed by the dialog window
052:             */
053:            public static void handle(CoreException e, String title,
054:                    String message) {
055:                handle(e, AptUIPlugin.getActiveWorkbenchShell(), title, message);
056:            }
057:
058:            /**
059:             * Handles the given <code>CoreException</code>. 
060:             * 
061:             * @param e the <code>CoreException</code> to be handled
062:             * @param parent the dialog window's parent shell
063:             * @param title the dialog window's window title
064:             * @param message message to be displayed by the dialog window
065:             */
066:            public static void handle(CoreException e, Shell parent,
067:                    String title, String message) {
068:                fgInstance.perform(e, parent, title, message);
069:            }
070:
071:            /**
072:             * Handles the given <code>InvocationTargetException</code>. The workbench shell is used 
073:             * as a parent for the dialog window.
074:             * 
075:             * @param e the <code>InvocationTargetException</code> to be handled
076:             * @param title the dialog window's window title
077:             * @param message message to be displayed by the dialog window
078:             */
079:            public static void handle(InvocationTargetException e,
080:                    String title, String message) {
081:                handle(e, AptUIPlugin.getActiveWorkbenchShell(), title, message);
082:            }
083:
084:            /**
085:             * Handles the given <code>InvocationTargetException</code>. 
086:             * 
087:             * @param e the <code>InvocationTargetException</code> to be handled
088:             * @param parent the dialog window's parent shell
089:             * @param title the dialog window's window title
090:             * @param message message to be displayed by the dialog window
091:             */
092:            public static void handle(InvocationTargetException e,
093:                    Shell parent, String title, String message) {
094:                fgInstance.perform(e, parent, title, message);
095:            }
096:
097:            //---- Hooks for subclasses to control exception handling ------------------------------------
098:
099:            protected void perform(CoreException e, Shell shell, String title,
100:                    String message) {
101:                AptUIPlugin.log(e);
102:                IStatus status = e.getStatus();
103:                if (status != null) {
104:                    ErrorDialog.openError(shell, title, message, status);
105:                } else {
106:                    displayMessageDialog(e, e.getMessage(), shell, title,
107:                            message);
108:                }
109:            }
110:
111:            protected void perform(InvocationTargetException e, Shell shell,
112:                    String title, String message) {
113:                Throwable target = e.getTargetException();
114:                if (target instanceof  CoreException) {
115:                    perform((CoreException) target, shell, title, message);
116:                } else {
117:                    AptUIPlugin.log(e);
118:                    if (e.getMessage() != null && e.getMessage().length() > 0) {
119:                        displayMessageDialog(e, e.getMessage(), shell, title,
120:                                message);
121:                    } else {
122:                        displayMessageDialog(e, target.getMessage(), shell,
123:                                title, message);
124:                    }
125:                }
126:            }
127:
128:            //---- Helper methods -----------------------------------------------------------------------
129:
130:            private void displayMessageDialog(Throwable t,
131:                    String exceptionMessage, Shell shell, String title,
132:                    String message) {
133:                StringWriter msg = new StringWriter();
134:                if (message != null) {
135:                    msg.write(message);
136:                    msg.write("\n\n"); //$NON-NLS-1$
137:                }
138:                if (exceptionMessage == null || exceptionMessage.length() == 0)
139:                    msg.write(Messages.ExceptionHandler_seeErrorLog);
140:                else
141:                    msg.write(exceptionMessage);
142:                MessageDialog.openError(shell, title, msg.toString());
143:            }
144:        }
ww__w__.___j__a__v___a___2___s_.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.