1 package org.csc.phynixx.common.exceptions;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 import java.io.PrintStream;
25 import java.io.PrintWriter;
26
27 public class DelegatedRuntimeException extends RuntimeException implements IDelegated {
28
29
30 public DelegatedRuntimeException() {
31 super();
32 }
33
34 public DelegatedRuntimeException(String message, Throwable cause) {
35 super(message, cause);
36 }
37
38 public DelegatedRuntimeException(String message) {
39 super(message);
40 }
41
42 public DelegatedRuntimeException(Throwable cause) {
43 super(cause);
44 }
45
46
47
48
49
50
51
52
53 public Throwable getRootCause() {
54 Throwable throwable = super.getCause();
55
56 if (throwable instanceof IDelegated) {
57 return ((IDelegated) throwable).getRootCause();
58 }
59 if (throwable == null) {
60 return new Exception("");
61 } else {
62 return throwable;
63 }
64 }
65
66
67
68
69 public String getDecoratingMessage() {
70 String decoratingMessage = super.getMessage();
71 if (decoratingMessage == null) {
72 return "";
73 } else {
74 return decoratingMessage;
75 }
76 }
77
78
79
80
81
82
83
84 public String getMessage() {
85 String message = super.getMessage();
86 if (this.getCause() != null) {
87 return message + " :: " + this.getCause().getMessage();
88 } else {
89 return super.getMessage() + " DelegatedSystemExeption :: No RootCause defined";
90 }
91 }
92
93
94
95
96
97
98
99
100
101 public void printStackTrace(PrintStream stream) {
102 if (getRootCause() != null) {
103 stream.println(this.getMessage());
104 getRootCause().printStackTrace(stream);
105 } else {
106 this.printStackTrace(stream);
107 }
108 }
109
110
111
112
113
114
115
116
117 public void printStackTrace(PrintWriter writer) {
118 if (getRootCause() != null) {
119 writer.write(getMessage());
120 getRootCause().printStackTrace(writer);
121 } else {
122 this.printStackTrace(writer);
123 }
124 }
125
126
127 }