root / branches / v2_0_0_prep / libraries / libTools / src / org / gvsig / tools / exception / BaseRuntimeException.java @ 23150
History | View | Annotate | Download (6.14 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 |
package org.gvsig.tools.exception; |
28 |
|
29 |
import java.io.PrintStream; |
30 |
import java.io.PrintWriter; |
31 |
import java.util.Iterator; |
32 |
import java.util.Map; |
33 |
|
34 |
/**
|
35 |
* Adds RuntimeException nature to the BaseException.
|
36 |
*
|
37 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
|
38 |
*/
|
39 |
public abstract class BaseRuntimeException extends RuntimeException implements |
40 |
IBaseException { |
41 |
|
42 |
// Inner delegate exception
|
43 |
private BaseException exception;
|
44 |
|
45 |
/**
|
46 |
* Constructs a RuntimeBaseException with a default message format, a key to
|
47 |
* find a localized message format, and a unique code to identify the
|
48 |
* exception.
|
49 |
*
|
50 |
* @param message
|
51 |
* the default messageFormat to describe the exception
|
52 |
* @param key
|
53 |
* the key to use to search a localized messageFormnata
|
54 |
* @param code
|
55 |
* the unique code to identify the exception
|
56 |
*/
|
57 |
public BaseRuntimeException(String message, String key, long code) { |
58 |
exception = new DelegateBaseException(message, key, code, this); |
59 |
} |
60 |
|
61 |
/**
|
62 |
* Constructs a BaseException with a default message format, a key to find a
|
63 |
* localized message format, and a unique code to identify the exception.
|
64 |
*
|
65 |
* @param message
|
66 |
* the default messageFormat to describe the exception
|
67 |
* @param cause
|
68 |
* the original cause of the exception
|
69 |
* @param key
|
70 |
* the key to use to search a localized messageFormnata
|
71 |
* @param code
|
72 |
* the unique code to identify the exception
|
73 |
*/
|
74 |
public BaseRuntimeException(String message, Throwable cause, String key, |
75 |
long code) {
|
76 |
exception = new DelegateBaseException(message, cause, key, code, this); |
77 |
} |
78 |
|
79 |
public boolean equals(Object obj) { |
80 |
return exception.equals(obj);
|
81 |
} |
82 |
|
83 |
public Throwable getCause() { |
84 |
return exception.getCause();
|
85 |
} |
86 |
|
87 |
public long getCode() { |
88 |
return exception.getCode();
|
89 |
} |
90 |
|
91 |
public String getFormatString() { |
92 |
return exception.getFormatString();
|
93 |
} |
94 |
|
95 |
public String getLocalizedMessage() { |
96 |
return exception.getLocalizedMessage();
|
97 |
} |
98 |
|
99 |
public String getLocalizedMessage(IExceptionTranslator translator, |
100 |
int indent) {
|
101 |
return exception.getLocalizedMessage(translator, indent);
|
102 |
} |
103 |
|
104 |
public String getLocalizedMessageStack() { |
105 |
return exception.getLocalizedMessageStack();
|
106 |
} |
107 |
|
108 |
public String getLocalizedMessageStack(IExceptionTranslator translator, |
109 |
int indent) {
|
110 |
return exception.getLocalizedMessageStack(translator, indent);
|
111 |
} |
112 |
|
113 |
public String getMessage() { |
114 |
return exception.getMessage();
|
115 |
} |
116 |
|
117 |
public String getMessage(int indent) { |
118 |
return exception.getMessage(indent);
|
119 |
} |
120 |
|
121 |
public String getMessageKey() { |
122 |
return exception.getMessageKey();
|
123 |
} |
124 |
|
125 |
public String getMessageStack() { |
126 |
return exception.getMessageStack();
|
127 |
} |
128 |
|
129 |
public String getMessageStack(int indent) { |
130 |
return exception.getMessageStack(indent);
|
131 |
} |
132 |
|
133 |
public StackTraceElement[] getStackTrace() { |
134 |
return exception.getStackTrace();
|
135 |
} |
136 |
|
137 |
public int hashCode() { |
138 |
return exception.hashCode();
|
139 |
} |
140 |
|
141 |
public Throwable initCause(Throwable cause) { |
142 |
return exception.initCause(cause);
|
143 |
} |
144 |
|
145 |
public Iterator iterator() { |
146 |
return exception.iterator();
|
147 |
} |
148 |
|
149 |
public void printStackTrace() { |
150 |
exception.printStackTrace(); |
151 |
} |
152 |
|
153 |
public void printStackTrace(PrintStream s) { |
154 |
exception.printStackTrace(s); |
155 |
} |
156 |
|
157 |
public void printStackTrace(PrintWriter s) { |
158 |
exception.printStackTrace(s); |
159 |
} |
160 |
|
161 |
public void setCode(long code) { |
162 |
exception.setCode(code); |
163 |
} |
164 |
|
165 |
public void setFormatString(String formatString) { |
166 |
exception.setFormatString(formatString); |
167 |
} |
168 |
|
169 |
public void setMessageKey(String messageKey) { |
170 |
exception.setMessageKey(messageKey); |
171 |
} |
172 |
|
173 |
public void setStackTrace(StackTraceElement[] stackTrace) { |
174 |
exception.setStackTrace(stackTrace); |
175 |
} |
176 |
|
177 |
public String toString() { |
178 |
return exception.toString();
|
179 |
} |
180 |
|
181 |
/**
|
182 |
* Used to return a map that serves to replace in the format string the keys
|
183 |
* with the corresponding values.
|
184 |
*
|
185 |
* @return the message values
|
186 |
*/
|
187 |
abstract protected Map values(); |
188 |
|
189 |
/**
|
190 |
* Inner BaseException implementation to use as the inner exception.
|
191 |
*
|
192 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
|
193 |
*/
|
194 |
public class DelegateBaseException extends BaseException { |
195 |
|
196 |
private BaseRuntimeException baseException;
|
197 |
|
198 |
public DelegateBaseException(String message, String key, long code, |
199 |
BaseRuntimeException baseException) { |
200 |
super(message, key, code);
|
201 |
this.baseException = baseException;
|
202 |
} |
203 |
|
204 |
public DelegateBaseException(String message, Throwable cause, |
205 |
String key, long code, BaseRuntimeException baseException) { |
206 |
super(message, cause, key, code);
|
207 |
this.baseException = baseException;
|
208 |
} |
209 |
|
210 |
protected Map values() { |
211 |
return baseException.values();
|
212 |
} |
213 |
} |
214 |
} |