Revision 9671 trunk/libraries/libExceptions/src/org/gvsig/exceptions/BaseException.java
BaseException.java | ||
---|---|---|
1 | 1 |
package org.gvsig.exceptions; |
2 | 2 |
|
3 |
import java.lang.reflect.Method; |
|
4 |
import java.util.Iterator; |
|
3 | 5 |
import java.util.Map; |
4 |
import java.util.Iterator; |
|
5 | 6 |
|
6 | 7 |
/** |
7 | 8 |
* @author Equipo de desarrollo de gvSIG. |
... | ... | |
9 | 10 |
*/ |
10 | 11 |
public abstract class BaseException extends Exception implements IBaseException { |
11 | 12 |
private final static String BLANKS =" "; |
12 |
static IExceptionTranslator translator= null; |
|
13 |
private static IExceptionTranslator translator= null;
|
|
13 | 14 |
|
14 | 15 |
protected String messageKey; |
15 | 16 |
|
... | ... | |
225 | 226 |
public static void setTranslator(IExceptionTranslator translator){ |
226 | 227 |
BaseException.translator = translator; |
227 | 228 |
} |
229 |
|
|
230 |
public static void setTranslator(Object translator){ |
|
231 |
BaseException.translator = new TranslatorWraper(translator); |
|
232 |
} |
|
233 |
|
|
234 |
} |
|
235 |
|
|
236 |
class TranslatorWraper implements IExceptionTranslator { |
|
237 |
|
|
238 |
private Object translator = null; |
|
239 |
private Method method = null; |
|
228 | 240 |
|
229 |
} |
|
241 |
public TranslatorWraper(Object translator) { |
|
242 |
Class theClass = translator.getClass(); |
|
243 |
String s = ""; |
|
244 |
|
|
245 |
this.translator = translator; |
|
246 |
try { |
|
247 |
method = theClass.getMethod("getText",new Class[] { s.getClass() }); |
|
248 |
} catch (Exception e) { |
|
249 |
throw new RuntimeException("El objeto translator suministrado no tiene el metodo getText apropiado.", e); |
|
250 |
} |
|
251 |
|
|
252 |
} |
|
253 |
|
|
254 |
public String getText(String key) { |
|
255 |
try { |
|
256 |
return (String)(method.invoke(translator,new String[] { key })); |
|
257 |
} catch (Exception e) { |
|
258 |
return key; |
|
259 |
} |
|
260 |
} |
|
261 |
|
|
262 |
} |
Also available in: Unified diff