01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.simulator.app;
05:
06: import java.io.PrintStream;
07: import java.io.PrintWriter;
08: import java.io.StringWriter;
09:
10: public class ErrorContext {
11: private final String message;
12: private final Thread thread;
13: private Throwable throwable;
14:
15: public ErrorContext(String message) {
16: this .message = message;
17: this .thread = Thread.currentThread();
18: }
19:
20: public ErrorContext(String message, Throwable throwable) {
21: this (message);
22: this .throwable = throwable;
23: }
24:
25: public ErrorContext(Throwable t) {
26: this ("", t);
27: }
28:
29: public String getMessage() {
30: return message;
31: }
32:
33: public Thread getThread() {
34: return thread;
35: }
36:
37: public Throwable getThrowable() {
38: return throwable;
39: }
40:
41: public String toString() {
42:
43: StringWriter sw = new StringWriter();
44: PrintWriter pw = new PrintWriter(sw);
45: dump(pw);
46: pw.flush();
47: return sw.getBuffer().toString();
48: }
49:
50: // Ok. It's totally retarted to have these two dump methods, but I can't for the life of me figure out
51: // how collapse the two methods together. The java.io package has me stumped at the moment
52: // --Orion
53:
54: public void dump(PrintWriter out) {
55: out.println(getClass().getName() + " [" + message
56: + ", thread: " + thread + "]");
57: if (throwable != null) {
58: throwable.printStackTrace(out);
59: }
60: }
61:
62: public void dump(PrintStream out) {
63: out.println(getClass().getName() + " [" + message
64: + ", thread: " + thread + "]");
65: if (throwable != null) {
66: throwable.printStackTrace(out);
67: }
68: }
69: }
|