Source Code Cross Referenced for ErrorHandler.java in  » Report » datavision-1.1.0 » jimm » datavision » 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 » Report » datavision 1.1.0 » jimm.datavision 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package jimm.datavision;
002:
003:        import jimm.util.StringUtils;
004:        import jimm.util.I18N;
005:        import java.sql.SQLException;
006:        import javax.swing.JOptionPane;
007:
008:        /**
009:         * This class provides static methods for displaying error messages.
010:         * It displays error messages to System.err. When the GUI is being used
011:         * it displays error messages in dialog boxes as well.
012:         * <p>
013:         * The only shortcoming is that you have to explicitly tell this class
014:         * whether to use the GUI or not.
015:         * <p>
016:         * This class is also used by other parts of the system to determine
017:         * if the report is being run with or without a GUI.
018:         *
019:         * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
020:         */
021:        public class ErrorHandler {
022:
023:            protected static final int MAX_MESSAGE_WIDTH = 66;
024:
025:            protected static boolean useGUI = false;
026:
027:            /**
028:             * Tells the error handler routines whether to display error messages
029:             * in dialog boxes or not.
030:             *
031:             * @param b if <code>true</code>, all error messages will be displayed
032:             * using a dialog box in addition to being printed on System.err
033:             */
034:            public static void useGUI(boolean b) {
035:                useGUI = b;
036:            }
037:
038:            /**
039:             * Returns <code>true</code> if we've been told to use the GUI.
040:             *
041:             * @return <code>true</code> if we've been told to use the GUI
042:             */
043:            public static boolean usingGUI() {
044:                return useGUI;
045:            }
046:
047:            /**
048:             * Displays an error message.
049:             *
050:             * @param message the error message; may be <code>null</code>,
051:             * but that would be rather silly
052:             */
053:            public static void error(String message) {
054:                error(message, null, null);
055:            }
056:
057:            /**
058:             * Displays an error message and an exception (actually a
059:             * <code>Throwable</code>) Both arguments are optionally <code>null</code>.
060:             *
061:             * @param message the error message; may be <code>null</code>
062:             * @param t a throwable; may be <code>null</code>
063:             */
064:            public static void error(String message, Throwable t) {
065:                error(message, t, null);
066:            }
067:
068:            /**
069:             * Displays an error message with the given window title. Both
070:             * arguments are optionally <code>null</code>.
071:             *
072:             * @param message the error message; may be <code>null</code>
073:             * @param windowTitle a string to use as the dialog title; may be
074:             * <code>null</code>
075:             */
076:            public static void error(String message, String windowTitle) {
077:                error(message, null, windowTitle);
078:            }
079:
080:            /**
081:             * Displays an exception (actually a <code>Throwable</code>). It may
082:             * be <code>null</code>, but that would be rather silly.
083:             *
084:             * @param t a throwable; may be <code>null</code>
085:             */
086:            public static void error(Throwable t) {
087:                error(null, t, null);
088:            }
089:
090:            /**
091:             * Displays an error message and an exception (actually a
092:             * <code>Throwable</code>) with the given window title. All three
093:             * arguments are optionally <code>null</code>.
094:             *
095:             * @param t a throwable; may be <code>null</code>
096:             * @param windowTitle a string to use as the dialog title; may be
097:             * <code>null</code>
098:             */
099:            public static void error(Throwable t, String windowTitle) {
100:                error(null, t, windowTitle);
101:            }
102:
103:            /**
104:             * Displays an error message and an exception (actually a
105:             * <code>Throwable</code>) with the given window title. All three
106:             * arguments are optionally <code>null</code>.
107:             *
108:             * @param message the error message; may be <code>null</code>
109:             * @param t a throwable; may be <code>null</code>
110:             * @param windowTitle a string to use as the dialog title; may be
111:             * <code>null</code>
112:             */
113:            public static void error(String message, Throwable t,
114:                    String windowTitle) {
115:                StringBuffer buf = new StringBuffer();
116:                if (message != null)
117:                    StringUtils.splitUp(buf, message, MAX_MESSAGE_WIDTH);
118:                if (t != null) {
119:                    if (message != null)
120:                        buf.append("\n");
121:                    StringUtils.splitUp(buf, t.toString(), MAX_MESSAGE_WIDTH);
122:                    if (t instanceof  SQLException) {
123:                        SQLException ex = (SQLException) t;
124:                        ex = ex.getNextException();
125:                        while (ex != null) {
126:                            buf.append("\n");
127:                            StringUtils.splitUp(buf, ex.toString(),
128:                                    MAX_MESSAGE_WIDTH);
129:                            ex = ex.getNextException();
130:                        }
131:                    }
132:                }
133:                String errorMessage = buf.toString();
134:
135:                System.err.println("DataVision v" + info.Version);
136:                if (windowTitle != null)
137:                    System.err.print(windowTitle + ": ");
138:                System.err.println(errorMessage);
139:
140:                if (t != null)
141:                    t.printStackTrace();
142:
143:                if (useGUI) {
144:                    if (windowTitle == null)
145:                        windowTitle = I18N
146:                                .get("ErrorHandler.default_win_title");
147:                    JOptionPane.showMessageDialog(null, errorMessage,
148:                            windowTitle, JOptionPane.ERROR_MESSAGE);
149:                }
150:            }
151:
152:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.