Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libExceptions / src / org / gvsig / exceptions / BaseRuntimeException.java @ 23150

History | View | Annotate | Download (6.2 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.exceptions;
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
 * @deprecated @see org.gvsig.tools.exception.BaseRuntimeException
39
 */
40
public abstract class BaseRuntimeException extends RuntimeException implements
41
        IBaseException {
42
    
43
    // Inner delegate exception
44
    private BaseException exception;
45

    
46
    /**
47
     * Constructs a RuntimeBaseException with a default message format, a key to
48
     * find a localized message format, and a unique code to identify the
49
     * exception.
50
     * 
51
     * @param message
52
     *            the default messageFormat to describe the exception
53
     * @param key
54
     *            the key to use to search a localized messageFormnata
55
     * @param code
56
     *            the unique code to identify the exception
57
     */
58
    public BaseRuntimeException(String message, String key, long code) {
59
        exception = new DelegateBaseException(message, key, code, this);
60
    }
61

    
62
    /**
63
     * Constructs a BaseException with a default message format, a key to find a
64
     * localized message format, and a unique code to identify the exception.
65
     * 
66
     * @param message
67
     *            the default messageFormat to describe the exception
68
     * @param cause
69
     *            the original cause of the exception
70
     * @param key
71
     *            the key to use to search a localized messageFormnata
72
     * @param code
73
     *            the unique code to identify the exception
74
     */
75
    public BaseRuntimeException(String message, Throwable cause, String key,
76
            long code) {
77
        exception = new DelegateBaseException(message, cause, key, code, this);
78
    }
79

    
80
    public boolean equals(Object obj) {
81
        return exception.equals(obj);
82
    }
83

    
84
    public Throwable getCause() {
85
        return exception.getCause();
86
    }
87

    
88
    public long getCode() {
89
        return exception.getCode();
90
    }
91

    
92
    public String getFormatString() {
93
        return exception.getFormatString();
94
    }
95

    
96
    public String getLocalizedMessage() {
97
        return exception.getLocalizedMessage();
98
    }
99

    
100
    public String getLocalizedMessage(IExceptionTranslator translator,
101
            int indent) {
102
        return exception.getLocalizedMessage(translator, indent);
103
    }
104

    
105
    public String getLocalizedMessageStack() {
106
        return exception.getLocalizedMessageStack();
107
    }
108

    
109
    public String getLocalizedMessageStack(IExceptionTranslator translator,
110
            int indent) {
111
        return exception.getLocalizedMessageStack(translator, indent);
112
    }
113

    
114
    public String getMessage() {
115
        return exception.getMessage();
116
    }
117

    
118
    public String getMessage(int indent) {
119
        return exception.getMessage(indent);
120
    }
121

    
122
    public String getMessageKey() {
123
        return exception.getMessageKey();
124
    }
125

    
126
    public String getMessageStack() {
127
        return exception.getMessageStack();
128
    }
129

    
130
    public String getMessageStack(int indent) {
131
        return exception.getMessageStack(indent);
132
    }
133

    
134
    public StackTraceElement[] getStackTrace() {
135
        return exception.getStackTrace();
136
    }
137

    
138
    public int hashCode() {
139
        return exception.hashCode();
140
    }
141

    
142
    public Throwable initCause(Throwable cause) {
143
        return exception.initCause(cause);
144
    }
145

    
146
    public Iterator iterator() {
147
        return exception.iterator();
148
    }
149

    
150
    public void printStackTrace() {
151
        exception.printStackTrace();
152
    }
153

    
154
    public void printStackTrace(PrintStream s) {
155
        exception.printStackTrace(s);
156
    }
157

    
158
    public void printStackTrace(PrintWriter s) {
159
        exception.printStackTrace(s);
160
    }
161

    
162
    public void setCode(long code) {
163
        exception.setCode(code);
164
    }
165

    
166
    public void setFormatString(String formatString) {
167
        exception.setFormatString(formatString);
168
    }
169

    
170
    public void setMessageKey(String messageKey) {
171
        exception.setMessageKey(messageKey);
172
    }
173

    
174
    public void setStackTrace(StackTraceElement[] stackTrace) {
175
        exception.setStackTrace(stackTrace);
176
    }
177

    
178
    public String toString() {
179
        return exception.toString();
180
    }
181

    
182
    /**
183
     * Used to return a map that serves to replace in the format string the keys
184
     * with the corresponding values.
185
     * 
186
     * @return the message values
187
     */
188
    abstract protected Map values();
189

    
190
    /**
191
     * Inner BaseException implementation to use as the inner exception.
192
     * 
193
     * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
194
     */
195
    public class DelegateBaseException extends BaseException {
196
        
197
        private BaseRuntimeException baseException;
198
        
199
        public DelegateBaseException(String message, String key, long code,
200
                BaseRuntimeException baseException) {
201
            super(message, key, code);
202
            this.baseException = baseException;
203
        }
204

    
205
        public DelegateBaseException(String message, Throwable cause,
206
                String key, long code, BaseRuntimeException baseException) {
207
            super(message, cause, key, code);
208
            this.baseException = baseException;
209
        }
210

    
211
        protected Map values() {
212
            return baseException.values();
213
        }
214
    }
215
}