1
16
17 package org.apache.wsrp4j.exception;
18
19
22 public class WSRPException extends Exception {
23
24
27 private int errCode = 0;
28
29 private Throwable nestedThrowable = null;
30
31 private static final int COMMON_EXCEPTION = 1;
33
34 private static final int CONSUMER_EXCEPTION = 2;
36
37 private static final int PRODUCER_EXCEPTION = 4;
39
40 private static final int PROVIDER_EXCEPTION = 8;
42
43 private int exceptionRange = 0;
45
46
50 public WSRPException() {
51 this(0, null);
52 }
53
54
58 public WSRPException(int errorCode) {
59 this(errorCode, null);
60 }
61
62
67 public WSRPException(int errorCode, Throwable t) {
68 super(Messages.get(errorCode));
70 errCode = errorCode;
71 nestedThrowable = t;
72 }
73
74
78 public int getErrorCode() {
79 return errCode;
80 }
81
82
86 public Throwable getNestedThrowable() {
87 return nestedThrowable;
88 }
89
90
93 public String toString() {
94 StringBuffer s = new StringBuffer(this.getClass().getName());
95 s.append(": ");
96 s.append(getMessage());
97 if (nestedThrowable != null) {
98 s.append("\n\nNested Throwable is:\n");
99 s.append(nestedThrowable.toString());
100 }
101 return s.toString();
102 }
103
104
110 public String toHTMLString() {
111
112 StringBuffer s = new StringBuffer();
113
114 s.append("<H2>Exception occured!</H2><br>");
115 s.append("<b>" + this.getClass().getName() + "</><br>");
116 s.append(" Message = " + getMessage() + "<br>");
117 s.append(" Type = " + getExceptionRange() + "<br>");
118
119 if (this.nestedThrowable != null) {
120
121 Throwable t = nestedThrowable;
122 s.append("<H3>Exception stack:</H3>");
123
124 while (t != null) {
125 s.append("<br><b>" + t.getClass().getName() + "</><br>");
126 if (t instanceof WSRPException) {
127 s.append(" Message = " + ((WSRPException) t).getMessage()
128 + "<br>");
129 s.append(" Type = "
130 + ((WSRPException) t).getExceptionRange() + "<br>");
131 t = ((WSRPException) t).getNestedThrowable();
132 }
133 else {
134 s.append(" Message = " + t.getMessage() + "<br>");
135 t = null;
136 }
137 }
138 }
139
140 return s.toString();
141 }
142
143
149 public int getExceptionRange() {
150
151 return exceptionRange;
152 }
153
154
157 public void setCommonExceptionRange() {
158
159 exceptionRange = COMMON_EXCEPTION;
160 }
161
162
165 public void setConsumerExceptionRange() {
166
167 exceptionRange = CONSUMER_EXCEPTION;
168 }
169
170
173 public void setProducerExceptionRange() {
174
175 exceptionRange = PRODUCER_EXCEPTION;
176 }
177
178
181 public void setProviderExceptionRange() {
182
183 exceptionRange = PROVIDER_EXCEPTION;
184 }
185 }