Source Code Cross Referenced for ErrorReporter.java in  » Scripting » groovy-1.0 » org » codehaus » groovy » tools » 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 » Scripting » groovy 1.0 » org.codehaus.groovy.tools 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         $Id: ErrorReporter.java 2255 2005-06-08 20:06:19Z glaforge $
003:
004:         Copyright 2004 (C) James Strachan and Bob Mcwhirter. All Rights Reserved.
005:
006:         Redistribution and use of this software and associated documentation
007:         ("Software"), with or without modification, are permitted provided
008:         that the following conditions are met:
009:
010:         1. Redistributions of source code must retain copyright
011:            statements and notices.  Redistributions must also contain a
012:            copy of this document.
013:
014:         2. Redistributions in binary form must reproduce the
015:            above copyright notice, this list of conditions and the
016:            following disclaimer in the documentation and/or other
017:            materials provided with the distribution.
018:
019:         3. The name "groovy" must not be used to endorse or promote
020:            products derived from this Software without prior written
021:            permission of The Codehaus.  For written permission,
022:            please contact info@codehaus.org.
023:
024:         4. Products derived from this Software may not be called "groovy"
025:            nor may "groovy" appear in their names without prior written
026:            permission of The Codehaus. "groovy" is a registered
027:            trademark of The Codehaus.
028:
029:         5. Due credit should be given to The Codehaus -
030:            http://groovy.codehaus.org/
031:
032:         THIS SOFTWARE IS PROVIDED BY THE CODEHAUS AND CONTRIBUTORS
033:         ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
034:         NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
035:         FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
036:         THE CODEHAUS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
037:         INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
038:         (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
039:         SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
040:         HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
041:         STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
042:         ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
043:         OF THE POSSIBILITY OF SUCH DAMAGE.
044:
045:         */
046:
047:        package org.codehaus.groovy.tools;
048:
049:        import java.io.PrintStream;
050:        import java.io.PrintWriter;
051:
052:        import org.codehaus.groovy.GroovyExceptionInterface;
053:        import org.codehaus.groovy.control.CompilationFailedException;
054:        import groovy.lang.GroovyRuntimeException;
055:
056:        /**
057:         *  Provides services for reporting compilation errors to the
058:         *  user.  Primary entry point is <code>write()</code>.
059:         *
060:         *  @author <a href="mailto:cpoirier%20AT%20tapestry_os%20DOT%20org">Chris Poirier</a>
061:         *  @version $Revision: 2255 $
062:         */
063:
064:        public class ErrorReporter {
065:            private Throwable base = null; // The exception on which to report
066:            private boolean debug = false; // If true, stack traces are always output
067:
068:            private Object output = null; // The stream/writer to which to output
069:
070:            /**
071:             *  Configures a new Reporter.  Default mode is not to report a stack trace unless
072:             *  the error was not of one of the supported types.
073:             *
074:             *  @param e  the exception on which to report
075:             */
076:
077:            public ErrorReporter(Throwable e) {
078:                this .base = e;
079:            }
080:
081:            /**
082:             *  Configures a new Reporter.  
083:             *
084:             *  @param e      the exception on which to report
085:             *  @param debug  if set, stack traces will be output for all reports
086:             */
087:
088:            public ErrorReporter(Throwable e, boolean debug) {
089:                this .base = e;
090:                this .debug = debug;
091:            }
092:
093:            /**
094:             *  Writes the error to the specified <code>PrintStream</code>.
095:             */
096:
097:            public void write(PrintStream stream) {
098:                this .output = stream;
099:                dispatch(base, false);
100:                stream.flush();
101:            }
102:
103:            /**
104:             *  Writes the error to the specified <code>PrintWriter</code>.
105:             */
106:
107:            public void write(PrintWriter writer) {
108:                this .output = writer;
109:                dispatch(base, false);
110:                writer.flush();
111:            }
112:
113:            /**
114:             *  Runs the report once all initialization is complete.
115:             */
116:
117:            protected void dispatch(Throwable object, boolean child) {
118:                if (object instanceof  CompilationFailedException) {
119:                    report((CompilationFailedException) object, child);
120:                } else if (object instanceof  GroovyExceptionInterface) {
121:                    report((GroovyExceptionInterface) object, child);
122:                } else if (object instanceof  GroovyRuntimeException) {
123:                    report((GroovyRuntimeException) object, child);
124:                } else if (object instanceof  Exception) {
125:                    report((Exception) object, child);
126:                } else {
127:                    report(object, child);
128:                }
129:
130:            }
131:
132:            //---------------------------------------------------------------------------
133:            // REPORTING ROUTINES
134:
135:            /**
136:             *  For CompilationFailedException.
137:             */
138:
139:            protected void report(CompilationFailedException e, boolean child) {
140:                println(e.toString());
141:                stacktrace(e, false);
142:            }
143:
144:            /**
145:             *  For GroovyException.
146:             */
147:
148:            protected void report(GroovyExceptionInterface e, boolean child) {
149:                println(((Exception) e).getMessage());
150:                stacktrace((Exception) e, false);
151:            }
152:
153:            /**
154:             *  For Exception.
155:             */
156:
157:            protected void report(Exception e, boolean child) {
158:                println(e.getMessage());
159:                stacktrace(e, false);
160:            }
161:
162:            /**
163:             *  For everything else.
164:             */
165:
166:            protected void report(Throwable e, boolean child) {
167:                println(">>> a serious error occurred: " + e.getMessage());
168:                stacktrace(e, true);
169:            }
170:
171:            //---------------------------------------------------------------------------
172:            // GENERAL SUPPORT ROUTINES
173:
174:            /**
175:             *  Prints a line to the underlying <code>PrintStream</code>
176:             */
177:
178:            protected void println(String line) {
179:                if (output instanceof  PrintStream) {
180:                    ((PrintStream) output).println(line);
181:                } else {
182:                    ((PrintWriter) output).println(line);
183:                }
184:            }
185:
186:            protected void println(StringBuffer line) {
187:                if (output instanceof  PrintStream) {
188:                    ((PrintStream) output).println(line);
189:                } else {
190:                    ((PrintWriter) output).println(line);
191:                }
192:            }
193:
194:            /**
195:             *  Displays an exception's stack trace, if <code>debug</code> or 
196:             *  <code>always</code>.
197:             */
198:
199:            protected void stacktrace(Throwable e, boolean always) {
200:                if (debug || always) {
201:                    println(">>> stacktrace:");
202:                    if (output instanceof  PrintStream) {
203:                        e.printStackTrace((PrintStream) output);
204:                    } else {
205:                        e.printStackTrace((PrintWriter) output);
206:                    }
207:                }
208:            }
209:
210:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.