root / branches / v2_0_0_prep / libraries / libTools / src / org / gvsig / tools / exception / BaseRuntimeException.java @ 24060
History | View | Annotate | Download (6.3 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Gobernment (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2008 {DiSiD Technologies} {Create a BaseException as a RuntimeException}
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.tools.exception; |
29 |
|
30 |
import java.io.PrintStream; |
31 |
import java.io.PrintWriter; |
32 |
import java.util.Iterator; |
33 |
import java.util.Map; |
34 |
|
35 |
/**
|
36 |
* Adds RuntimeException nature to the BaseException.
|
37 |
*
|
38 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
|
39 |
*/
|
40 |
public abstract class BaseRuntimeException extends RuntimeException implements |
41 |
IBaseException { |
42 |
|
43 |
private static final long serialVersionUID = 4584809667815834006L; |
44 |
|
45 |
// Inner delegate exception
|
46 |
private BaseException exception;
|
47 |
|
48 |
/**
|
49 |
* Constructs a RuntimeBaseException with a default message format, a key to
|
50 |
* find a localized message format, and a unique code to identify the
|
51 |
* exception.
|
52 |
*
|
53 |
* @param message
|
54 |
* the default messageFormat to describe the exception
|
55 |
* @param key
|
56 |
* the key to use to search a localized messageFormnata
|
57 |
* @param code
|
58 |
* the unique code to identify the exception
|
59 |
*/
|
60 |
public BaseRuntimeException(String message, String key, long code) { |
61 |
exception = new DelegateBaseException(message, key, code, this); |
62 |
} |
63 |
|
64 |
/**
|
65 |
* Constructs a BaseException with a default message format, a key to find a
|
66 |
* localized message format, and a unique code to identify the exception.
|
67 |
*
|
68 |
* @param message
|
69 |
* the default messageFormat to describe the exception
|
70 |
* @param cause
|
71 |
* the original cause of the exception
|
72 |
* @param key
|
73 |
* the key to use to search a localized messageFormnata
|
74 |
* @param code
|
75 |
* the unique code to identify the exception
|
76 |
*/
|
77 |
public BaseRuntimeException(String message, Throwable cause, String key, |
78 |
long code) {
|
79 |
exception = new DelegateBaseException(message, cause, key, code, this); |
80 |
} |
81 |
|
82 |
public boolean equals(Object obj) { |
83 |
return exception.equals(obj);
|
84 |
} |
85 |
|
86 |
public Throwable getCause() { |
87 |
return exception.getCause();
|
88 |
} |
89 |
|
90 |
public long getCode() { |
91 |
return exception.getCode();
|
92 |
} |
93 |
|
94 |
public String getFormatString() { |
95 |
return exception.getFormatString();
|
96 |
} |
97 |
|
98 |
public String getLocalizedMessage() { |
99 |
return exception.getLocalizedMessage();
|
100 |
} |
101 |
|
102 |
public String getLocalizedMessage(IExceptionTranslator translator, |
103 |
int indent) {
|
104 |
return exception.getLocalizedMessage(translator, indent);
|
105 |
} |
106 |
|
107 |
public String getLocalizedMessageStack() { |
108 |
return exception.getLocalizedMessageStack();
|
109 |
} |
110 |
|
111 |
public String getLocalizedMessageStack(IExceptionTranslator translator, |
112 |
int indent) {
|
113 |
return exception.getLocalizedMessageStack(translator, indent);
|
114 |
} |
115 |
|
116 |
public String getMessage() { |
117 |
return exception.getMessage();
|
118 |
} |
119 |
|
120 |
public String getMessage(int indent) { |
121 |
return exception.getMessage(indent);
|
122 |
} |
123 |
|
124 |
public String getMessageKey() { |
125 |
return exception.getMessageKey();
|
126 |
} |
127 |
|
128 |
public String getMessageStack() { |
129 |
return exception.getMessageStack();
|
130 |
} |
131 |
|
132 |
public String getMessageStack(int indent) { |
133 |
return exception.getMessageStack(indent);
|
134 |
} |
135 |
|
136 |
public StackTraceElement[] getStackTrace() { |
137 |
return exception.getStackTrace();
|
138 |
} |
139 |
|
140 |
public int hashCode() { |
141 |
return exception.hashCode();
|
142 |
} |
143 |
|
144 |
public Throwable initCause(Throwable cause) { |
145 |
return exception.initCause(cause);
|
146 |
} |
147 |
|
148 |
public Iterator iterator() { |
149 |
return exception.iterator();
|
150 |
} |
151 |
|
152 |
public void printStackTrace() { |
153 |
exception.printStackTrace(); |
154 |
} |
155 |
|
156 |
public void printStackTrace(PrintStream s) { |
157 |
exception.printStackTrace(s); |
158 |
} |
159 |
|
160 |
public void printStackTrace(PrintWriter s) { |
161 |
exception.printStackTrace(s); |
162 |
} |
163 |
|
164 |
public void setCode(long code) { |
165 |
exception.setCode(code); |
166 |
} |
167 |
|
168 |
public void setFormatString(String formatString) { |
169 |
exception.setFormatString(formatString); |
170 |
} |
171 |
|
172 |
public void setMessageKey(String messageKey) { |
173 |
exception.setMessageKey(messageKey); |
174 |
} |
175 |
|
176 |
public void setStackTrace(StackTraceElement[] stackTrace) { |
177 |
exception.setStackTrace(stackTrace); |
178 |
} |
179 |
|
180 |
public String toString() { |
181 |
return exception.toString();
|
182 |
} |
183 |
|
184 |
/**
|
185 |
* Used to return a map that serves to replace in the format string the keys
|
186 |
* with the corresponding values.
|
187 |
*
|
188 |
* @return the message values
|
189 |
*/
|
190 |
abstract protected Map values(); |
191 |
|
192 |
/**
|
193 |
* Inner BaseException implementation to use as the inner exception.
|
194 |
*
|
195 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
|
196 |
*/
|
197 |
public class DelegateBaseException extends BaseException { |
198 |
|
199 |
private static final long serialVersionUID = 1784643169215420315L; |
200 |
|
201 |
private BaseRuntimeException baseException;
|
202 |
|
203 |
public DelegateBaseException(String message, String key, long code, |
204 |
BaseRuntimeException baseException) { |
205 |
super(message, key, code);
|
206 |
this.baseException = baseException;
|
207 |
} |
208 |
|
209 |
public DelegateBaseException(String message, Throwable cause, |
210 |
String key, long code, BaseRuntimeException baseException) { |
211 |
super(message, cause, key, code);
|
212 |
this.baseException = baseException;
|
213 |
} |
214 |
|
215 |
protected Map values() { |
216 |
return baseException.values();
|
217 |
} |
218 |
} |
219 |
} |