Revision 30092

View differences:

tags/tmp_build/libraries/libTools/src/org/gvsig/tools/exception/IBaseException.java
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
 */
26
package org.gvsig.tools.exception;
27

  
28
import java.util.Iterator;
29

  
30
/**
31
 * 
32
 * 
33
 * @author Equipo de desarrollo de gvSIG
34
 *
35
 */
36
public interface IBaseException {
37
	
38
	/** 
39
	 *  Returns the message that describes the exception.
40
	 *  
41
	 *  @return The message.
42
	 */
43
	public String getMessage();
44

  
45
	/** 
46
	 *  Returns the message that describes the exception, with indentation.
47
	 *  
48
	 *  @param indent Quantity of blanks to insert
49
	 *         at the start of the message.
50
	 *  @return The message with indentation.
51
	 */
52
	public String getMessage(int indent);
53

  
54
	/** 
55
	 *  Returns the translated message that describes the exception.
56
	 *  
57
	 *  @return The translated message with indentation.
58
	 */
59
	public String getLocalizedMessage();
60
	
61
	/** 
62
	 *  Returns the translated message that
63
	 *  describes the exception with indentation.
64
	 *
65
	 *  @param translator Instance of a class that fulfills
66
	 *         the IExceptionTranslator interface.
67
	 *         His method "getText" takes charge returning
68
	 *         the expression, correspondent to the key that
69
	 *         delivers him, translated into the configured language.
70
	 *  @param indent Quantity of blanks to insert
71
	 *         at the start of the message.
72
	 *  @return The translated message with indentation.
73
	 */
74
	public String getLocalizedMessage(IExceptionTranslator translator, int indent);
75
	
76
	/** 
77
	 *  Crosses the exceptions chained through cause to conform
78
	 *  the message.
79
	 *  
80
	 *  @return The compound message with all the messages
81
	 *          of the stack of exceptions.
82
	 */
83
	public String getMessageStack();
84

  
85
	/** 
86
	 *  Crosses the exceptions chained through cause to conform
87
	 *  the compound message with indentation.
88
	 *  
89
	 *  @param indent Quantity of blanks to insert
90
	 *         at the start of the messages.
91
	 *  @return The compound message with all the messages
92
	 *          of the stack of exceptions.
93

  
94
	 */
95
	public String getMessageStack(int indent);
96

  
97
	/** 
98
	 *  Crosses the exceptions chained through cause
99
	 *  to conform the compound message in the corresponding language.
100
	 *  
101
	 *  @return The translated compound message.
102
	 *    
103
	 */
104
	public String getLocalizedMessageStack();
105

  
106
	/** 
107
	 *  Crosses the exceptions chained through cause
108
	 *  to conform the compound message in the corresponding language.
109
	 *  
110
	 *  @param translator Instance of a class that fulfills
111
	 *         the IExceptionTranslator interface.
112
	 *         His method "getText" takes charge returning
113
	 *         the expression, correspondent to the key that
114
	 *         delivers him, translated into the configured language.
115
	 *  @param indent Quantity of blanks to insert
116
	 *         at the start of the messages.
117
	 *  @return The translated message with indentation.
118
	 *  
119
	 */
120
	public String getLocalizedMessageStack(IExceptionTranslator translator, int indent);
121
	
122
	
123
	/** 
124
	 *  @return The exception's code.
125
	 */
126
	public long getCode();
127
	
128
	/** 
129
	 *  @return The format string.
130
	 */
131
	public String getFormatString();
132
	
133
	/** 
134
	 *  @return The message key associated to the exception.
135
	 */
136
	public String getMessageKey();
137
	
138
	/** 
139
	 *  @return A iterator for the chained exceptions.
140
	 */
141
	public Iterator iterator();
142
	
143
}
tags/tmp_build/libraries/libTools/src/org/gvsig/tools/exception/BaseExceptionIterator.java
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
 */
26
package org.gvsig.tools.exception;
27

  
28
import java.util.Iterator;
29

  
30
class BaseExceptionIterator implements Iterator {
31
	
32
	Exception exception;
33
	
34
	BaseExceptionIterator(BaseException exception){
35
		this.exception = exception;
36
	}
37
	/** 
38
	 *  @return true if the iteration has more elements.
39
	 */
40
	public boolean hasNext() {
41
		return this.exception != null;
42
	}
43
	
44
	/** 
45
	 *  @return The next element in the iteration.
46
	 */
47
	public Object next() {
48
		Exception exception;
49
		exception = this.exception;
50
		this.exception = (Exception) exception.getCause();
51
		return exception;
52
	}
53
	
54
	/** 
55
	 *  @throws "UnsupportedOperationException" because
56
	 *  the remove operation will not be supported
57
	 *  by this Iterator.
58
	 */
59
	public void remove() {
60
		throw new UnsupportedOperationException();
61
	}
62
}
tags/tmp_build/libraries/libTools/src/org/gvsig/tools/exception/ListBaseException.java
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
 */
26
package org.gvsig.tools.exception;
27

  
28
import java.util.ArrayList;
29
import java.util.Collection;
30
import java.util.Iterator;
31
import java.util.List;
32
import java.util.ListIterator;
33

  
34
/**
35
 * @author Equipo de desarrollo de gvSIG
36
 *
37
 */
38
public abstract class ListBaseException extends BaseException implements List{
39
	private List exceptions = new ArrayList();
40
	
41
	/* (non-Javadoc)
42
	 * @see java.util.Collection#size()
43
	 */
44
	public int size() {
45
		return this.exceptions.size();
46
	}
47

  
48
	/* (non-Javadoc)
49
	 * @see java.util.Collection#isEmpty()
50
	 */
51
	public boolean isEmpty() {
52
		return this.exceptions.isEmpty();
53
	}
54

  
55
	/* (non-Javadoc)
56
	 * @see java.util.Collection#contains(java.lang.Object)
57
	 */
58
	public boolean contains(Object arg0) {
59
		return this.exceptions.contains(arg0);
60
	}
61

  
62
	/* (non-Javadoc)
63
	 * @see java.util.Collection#toArray()
64
	 */
65
	public Object[] toArray() {
66
		return this.exceptions.toArray();
67
	}
68

  
69
	/**
70
	 * @param arg0
71
	 * @return
72
	 */
73
	public Object[] toArray(Object[] arg0) {
74
		return this.exceptions.toArray(arg0);
75
	}
76

  
77
	/**
78
	 * @param arg0
79
	 * @return
80
	 */
81
	public boolean add(Object arg0) {
82
		return this.exceptions.add(arg0);
83
	}
84

  
85
	/* (non-Javadoc)
86
	 * @see java.util.Collection#remove(java.lang.Object)
87
	 */
88
	public boolean remove(Object arg0) {
89
		return this.exceptions.remove(arg0);
90
	}
91

  
92
	/**
93
	 * @param arg0
94
	 * @return
95
	 */
96
	public boolean containsAll(Collection arg0) {
97
		return this.exceptions.contains(arg0);
98
	}
99

  
100
	/**
101
	 * @param arg0
102
	 * @return
103
	 */
104
	public boolean addAll(Collection arg0) {
105
		return this.exceptions.addAll(arg0);
106
	}
107

  
108
	/**
109
	 * @param arg0
110
	 * @param arg1
111
	 * @return
112
	 */
113
	public boolean addAll(int arg0, Collection arg1) {
114
		return this.exceptions.addAll(arg0, arg1);
115
	}
116

  
117
	/**
118
	 * @param arg0
119
	 * @return
120
	 */
121
	public boolean removeAll(Collection arg0) {
122
		return this.exceptions.removeAll(arg0);
123
	}
124

  
125
	/**
126
	 * @param arg0
127
	 * @return
128
	 */
129
	public boolean retainAll(Collection arg0) {
130
		return this.exceptions.retainAll(arg0);
131
	}
132

  
133
	/* (non-Javadoc)
134
	 * @see java.util.Collection#clear()
135
	 */
136
	public void clear() {
137
		this.exceptions.clear();
138
	}
139

  
140
	/* (non-Javadoc)
141
	 * @see java.util.List#get(int)
142
	 */
143
	public Object get(int arg0) {
144
		return this.exceptions.get(arg0);
145
	}
146

  
147
	/**
148
	 * @param arg0
149
	 * @param arg1
150
	 * @return
151
	 */
152
	public Object set(int arg0, Object arg1) {
153
		return this.exceptions.set(arg0, arg1);
154
	}
155

  
156
	/**
157
	 * @param arg0
158
	 * @param arg1
159
	 */
160
	public void add(int arg0, Object arg1) {
161
		this.exceptions.add(arg0, arg1);
162
	}
163

  
164
	/* (non-Javadoc)
165
	 * @see java.util.List#remove(int)
166
	 */
167
	public Object remove(int arg0) {
168
		return this.exceptions.remove(arg0);
169
	}
170

  
171
	/* (non-Javadoc)
172
	 * @see java.util.List#indexOf(java.lang.Object)
173
	 */
174
	public int indexOf(Object arg0) {
175
		return this.exceptions.indexOf(arg0);
176
	}
177

  
178
	/* (non-Javadoc)
179
	 * @see java.util.List#lastIndexOf(java.lang.Object)
180
	 */
181
	public int lastIndexOf(Object arg0) {
182
		return this.exceptions.lastIndexOf(arg0);
183
	}
184

  
185
	/* (non-Javadoc)
186
	 * @see java.util.List#listIterator()
187
	 */
188
	public ListIterator listIterator() {
189
		return this.exceptions.listIterator();
190
	}
191

  
192
	/* (non-Javadoc)
193
	 * @see java.util.List#listIterator(int)
194
	 */
195
	public ListIterator listIterator(int arg0) {
196
		return this.exceptions.listIterator(arg0);
197
	}
198

  
199
	/* (non-Javadoc)
200
	 * @see java.util.List#subList(int, int)
201
	 */
202
	public List subList(int arg0, int arg1) {
203
		return this.exceptions.subList(arg0, arg1);
204
	}
205
	
206
	/* (non-Javadoc)
207
	 * @see java.lang.Throwable#getMessage()
208
	 */
209
	public String getMessage() {
210
		String msg = super.getMessage();
211
		Exception bex;
212
		Iterator iter=this.exceptions.iterator();
213
		while (iter.hasNext()) {
214
			bex = (Exception) iter.next();
215
			msg = msg + "\n  " + bex.getMessage();
216
		}
217
		return msg;
218
	}
219
	
220
	public String getLocalizedMessage(IExceptionTranslator exceptionTranslator, int indent) {
221
		String msg = super.getLocalizedMessage(exceptionTranslator, indent);
222
		Exception bex;
223
		Iterator iter=this.exceptions.iterator();
224
		while (iter.hasNext()) {
225
			bex = (Exception) iter.next();
226
			if( bex instanceof BaseException ) {
227
				msg = msg + "\n  " + ((BaseException)bex).getLocalizedMessage(exceptionTranslator, indent);				
228
			} else {
229
				msg = msg + "\n  " + bex.getLocalizedMessage();
230
			}
231
		}
232
		return BaseException.insertBlanksAtStart(msg,indent);
233
	}
234

  
235
}
tags/tmp_build/libraries/libTools/src/org/gvsig/tools/exception/NotYetImplemented.java
1
package org.gvsig.tools.exception;
2

  
3
import java.util.HashMap;
4
import java.util.Map;
5

  
6
public class NotYetImplemented extends BaseRuntimeException {
7
	/**
8
	 *
9
	 */
10
	private static final long serialVersionUID = -4448165879403648365L;
11
	private final static String MESSAGE_FORMAT = "Operation %(operation)s not yet implemented.";
12
	private final static String MESSAGE_KEY = "_NotYetImplemented";
13
	private String operation = "";
14

  
15
	public NotYetImplemented() {
16
		super(MESSAGE_FORMAT, MESSAGE_KEY, serialVersionUID);
17
	}
18

  
19
	public NotYetImplemented(String operation) {
20
		super(MESSAGE_FORMAT, MESSAGE_KEY, serialVersionUID);
21
		this.operation = "'" + operation + "'";
22
	}
23

  
24
	protected Map values() {
25
		Map values = new HashMap();
26
		values.put("operation", this.operation);
27
		return values;
28
	}
29

  
30
}
0 31

  
tags/tmp_build/libraries/libTools/src/org/gvsig/tools/exception/BaseException.java
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
 */
26
package org.gvsig.tools.exception;
27

  
28
import java.lang.reflect.Method;
29
import java.util.Iterator;
30
import java.util.Map;
31

  
32
/**
33
 * 
34
 * Esta clase esta pensada para actuar como clase base para las excepciones que
35
 * se lanzan dentro del proyecto de gvSIG.
36
 * 
37
 * A?ade la implementacion necesaria para disponer de mensajes de error
38
 * internacionalizables, a traves del metodo getLocalizedMessage, asi como una
39
 * serie de metodos que nos permiten obtener los mesanes de error de la cadena
40
 * de excepciones enlazadas a traves de su "causa", asi como utilidades que
41
 * permitan recorrer de forma comoda esta cadena de excepciones por medio de un
42
 * Iterador.
43
 * 
44
 * @author Equipo de desarrollo de gvSIG.
45
 * 
46
 */
47
public abstract class BaseException extends Exception implements IBaseException {
48
	private final static String BLANKS ="                                                                                                     ";
49
	private static IExceptionTranslator translator= null;
50

  
51
	protected String messageKey;
52

  
53
	/**
54
     * TODO: remove the variable, use the Exception get/setMessage() instead.
55
     */
56
	protected String formatString;
57

  
58
	/**
59
	 * Unique code of error.
60
	 */
61
	protected long code;
62
	
63
    /**
64
     * Empty constructor, don't use it anymore.
65
     * 
66
     * @deprecated
67
     */
68
    public BaseException() {
69
    }
70

  
71
    /**
72
     * Constructs a BaseException with a default message format, a key to find a
73
     * localized message format, and a unique code to identify the exception.
74
     * 
75
     * @param message
76
     *            the default messageFormat to describe the exception
77
     * @param key
78
     *            the key to use to search a localized messageFormnata
79
     * @param code
80
     *            the unique code to identify the exception
81
     */
82
    public BaseException(String message, String key, long code) {
83
        super(message);
84
        this.formatString = message;
85
        this.messageKey = key;
86
        this.code = code;
87
    }
88

  
89
    /**
90
     * Constructs a BaseException with a default message format, a key to find a
91
     * localized message format, and a unique code to identify the exception.
92
     * 
93
     * @param message
94
     *            the default messageFormat to describe the exception
95
     * @param cause
96
     *            the original cause of the exception
97
     * @param key
98
     *            the key to use to search a localized messageFormnata
99
     * @param code
100
     *            the unique code to identify the exception
101
     */
102
    public BaseException(String message, Throwable cause, String key, long code) {
103
        super(message, cause);
104
        this.formatString = message;
105
        this.messageKey = key;
106
        this.code = code;
107
    }
108

  
109
	/**
110
     * Returns the format string received in the parameter with its keys
111
     * replaced with the corresponding values of the map.
112
     * 
113
     * @param formatString
114
     * @param values
115
     *            map
116
     * @return string formatted
117
     */
118
    private String format(String formatString, Map values) {
119
        if (values != null) {
120

  
121
            // If there is no message format, create a text with the values.
122
            if (formatString == null) {
123
                return "values = ".concat(values.toString());
124
            } else {
125
                // Replace the keys as variables with the values in the Map
126
                Iterator keys = values.keySet().iterator();
127
                String message = formatString;
128
                while (keys.hasNext()) {
129
                    String key = (String) keys.next();
130
                    String varName = "%\\(".concat(key).concat("\\)");
131
                    message = message.replaceAll(varName, (String) values
132
                            .get(key));
133
                }
134
                return message;
135
            }
136
        }
137
        // Return the original format message in any other case
138
        return formatString;
139
    }
140

  
141
	/* (non-Javadoc)
142
	 * @see java.lang.Throwable#getMessage()
143
	 */
144
	public String getMessage() {
145
		return format(this.formatString, values());
146
	}
147

  
148
	public String getMessage(int indent) {
149
		return insertBlanksAtStart(format(formatString, values()),indent);
150
	}
151

  
152
	public String getLocalizedMessage() {
153
		return getLocalizedMessage(translator,0);
154
	}
155

  
156
	public String getLocalizedMessage(IExceptionTranslator translator, int indent){
157

  
158
		String fmt;
159
		if (translator == null){
160
			translator = BaseException.translator;
161
		}
162
		if (translator == null){
163
			fmt = getFormatString();
164
		} else {
165
			fmt = getMessageKey();
166
			if (fmt == null){
167
				fmt = getFormatString();
168
			} else {
169
				fmt = translator.getText(fmt);
170
			}
171
		}
172
		return insertBlanksAtStart(format(fmt,values()),indent);
173
	}
174

  
175
	public String getMessageStack() {
176
		return getMessageStack(0);
177
	}
178

  
179
	public String getMessageStack(int indent) {
180
		Iterator iter = this.iterator();
181
		StringBuffer msgBuffer = new StringBuffer();
182
		int i = 1;
183
		while (iter.hasNext()){
184
		    Exception ex = ((Exception) iter.next());
185
			
186
            if (msgBuffer.length() > 0) {
187
                msgBuffer.append("\n");
188
            }
189
			
190
			if ( ex instanceof BaseException ) {
191
				BaseException bex = (BaseException) ex;
192
				msgBuffer.append(bex.getMessage(indent * i));
193
			} else {
194
			    msgBuffer.append(insertBlanksAtStart(ex.getMessage(), indent
195
                        * i));
196
			}
197
			
198
			i++;
199
		}
200
		return msgBuffer.toString();
201
	}
202

  
203

  
204
	public String getLocalizedMessageStack() {
205
		return getLocalizedMessageStack(BaseException.translator,0);
206
	}
207

  
208
	public String getLocalizedMessageStack(IExceptionTranslator translator, int indent) {
209
		Iterator iter = this.iterator();
210
        StringBuffer msgBuffer = new StringBuffer();
211
        Exception ex;
212
        while (iter.hasNext()) {
213
            ex = ((Exception) iter.next());
214
            if (msgBuffer.length() > 0) {
215
                msgBuffer.append("\n");
216
            }
217

  
218
            if (ex instanceof BaseException) {
219
                BaseException bex = (BaseException) ex;
220
                msgBuffer.append(bex.getLocalizedMessage(translator, indent));
221
            } else {
222
                msgBuffer.append(ex.getLocalizedMessage());
223
            }
224
        }
225
        return msgBuffer.toString();
226
	}
227

  
228
	/**
229
	 * Inserts blanks at the start of a string.
230
	 *
231
	 * @param str A string.
232
	 * @param len Quantity of blanks to insert at the start of str.
233
	 * @return A string compund by the quantity of blanks that
234
	 *         len indicates and str.
235
	 */
236
	static String insertBlanksAtStart(String str, int len){
237
        int blanksLen = len > BLANKS.length() ? BLANKS.length() : (len < 0 ? 0
238
                : len);
239

  
240
        return BLANKS.substring(0, blanksLen) + str;
241
	}
242

  
243
	public long getCode() {
244
		return this.code;
245
	}
246

  
247
	/**
248
	 * Sets the exception's code.
249
	 */
250
	public void setCode(long code) {
251
		this.code = code;
252
	}
253

  
254
	public String getFormatString() {
255
		return this.formatString;
256
	}
257

  
258
	/**
259
	 * Sets the format string.
260
	 *
261
	 * @param formatString
262
	 */
263
	public void setFormatString(String formatString) {
264
		this.formatString = formatString;
265
	}
266

  
267
	public String getMessageKey() {
268
		return this.messageKey;
269
	}
270

  
271
	/**
272
	 * Sets the property messageKey.
273
	 *
274
	 * @param messageKey
275
	 */
276
	public void setMessageKey(String messageKey) {
277
		this.messageKey = messageKey;
278
	}
279

  
280
	public Iterator iterator() {
281
		return new BaseExceptionIterator(this);
282
	}
283

  
284
	/**
285
	 * @return A map that serves to replace in the format string
286
	 * the keys with the corresponding values.
287
	 */
288
	abstract protected Map values();
289

  
290
	/**
291
	 * Sets the property translator.
292
	 * @param translator It(He,She) is used to translate
293
	 *        the messages associated with the exceptions.
294
	 */
295
	public static void setTranslator(IExceptionTranslator translator){
296
		BaseException.translator = translator;
297
	}
298

  
299
	public static void setTranslator(Object translator){
300
		BaseException.translator = new TranslatorWraper(translator);
301
	}
302

  
303
	public String toString(){
304
		return format(this.formatString, values());
305
	}
306

  
307
}
308

  
309
class TranslatorWraper implements IExceptionTranslator {
310

  
311
	private Object translator = null;
312
	private Method method = null;
313

  
314
	public TranslatorWraper(Object translator) {
315
		Class theClass = translator.getClass();
316
		String s = "";
317

  
318
		this.translator = translator;
319
		try {
320
			method = theClass.getMethod("getText",new Class[] { s.getClass() });
321
		} catch (Exception e) {
322
			throw new RuntimeException("El objeto translator suministrado no tiene el metodo getText apropiado.", e);
323
		}
324

  
325
	}
326

  
327
	public String getText(String key) {
328
		try {
329
			return (String)(method.invoke(translator,new String[] { key }));
330
		} catch (Exception e) {
331
			return key;
332
		}
333
	}
334

  
335
}
tags/tmp_build/libraries/libTools/src/org/gvsig/tools/exception/BaseRuntimeException.java
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
    // 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
}
tags/tmp_build/libraries/libTools/src/org/gvsig/tools/exception/IExceptionTranslator.java
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
 */
26
package org.gvsig.tools.exception;
27

  
28
/**
29
 * 
30
 * @author Equipo de desarrollo de gvSIG
31
 *
32
 */
33
public interface IExceptionTranslator {
34
	
35
	/** 
36
	 *  @param key The key of the message error.
37
	 *  @return The translated error message
38
	 *  corresponding to the key that it
39
	 *  obtains as parameter.
40
	 */
41
	public String getText(String key);
42
}
tags/tmp_build/libraries/libTools/src/org/gvsig/tools/visitor/NotSupportedOperationException.java
1
package org.gvsig.tools.visitor;
2

  
3
import java.util.HashMap;
4
import java.util.Map;
5

  
6
import org.gvsig.tools.exception.BaseException;
7

  
8
/* gvSIG. Geographic Information System of the Valencian Government
9
 *
10
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
11
 * of the Valencian Government (CIT)
12
 *
13
 * This program is free software; you can redistribute it and/or
14
 * modify it under the terms of the GNU General Public License
15
 * as published by the Free Software Foundation; either version 2
16
 * of the License, or (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with this program; if not, write to the Free Software
25
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26
 * MA  02110-1301, USA.
27
 *
28
 */
29

  
30
/*
31
 * AUTHORS (In addition to CIT):
32
 * 2008 IVER T.I. S.A.   {{Task}}
33
 */
34
/**
35
 * @author Jorge Piera Llodr? (jorge.piera@iver.es)
36
 */
37
public class NotSupportedOperationException extends BaseException{
38
	private static final long serialVersionUID = 1L;
39
	private String visitorClassName = null;
40
	private String objectClassName = null;
41

  
42
	public NotSupportedOperationException(Visitor visitor, Object object){
43
		this.visitorClassName = visitor.getClass().getName();
44
		this.objectClassName = object.getClass().getName();
45
	}
46

  
47
	/**
48
	 * Initializes some values
49
	 */
50
	public void init() {
51
		messageKey="geometries_reader_not_exists";
52
		formatString="The visitor %(visitorClassName) doesn't implements any " +
53
			"operation for the object %(objectClassName)";
54
		code = serialVersionUID;
55
	}
56

  
57
	protected Map values() {
58
		HashMap map = new HashMap();
59
		map.put("visitorClassName", visitorClassName);
60
		map.put("objectClassName", objectClassName);
61
		return map;
62
	}
63

  
64
}
0 65

  
tags/tmp_build/libraries/libTools/src/org/gvsig/tools/visitor/Visitor.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (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 IVER T.I. S.A.   {{Task}}
26
 */
27
package org.gvsig.tools.visitor;
28

  
29
import org.gvsig.tools.exception.BaseException;
30

  
31
public interface Visitor {
32
	public void visit(Object obj) throws BaseException;
33
}
0 34

  
tags/tmp_build/libraries/libTools/src/org/gvsig/tools/visitor/Visitable.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (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 IVER T.I. S.A.   {{Task}}
26
 */
27
package org.gvsig.tools.visitor;
28

  
29
import org.gvsig.tools.exception.BaseException;
30

  
31
public interface Visitable {
32

  
33
	public void accept(Visitor visitor) throws BaseException;
34

  
35
}
0 36

  
tags/tmp_build/libraries/libTools/src/org/gvsig/tools/evaluator/EvaluatorData.java
1
package org.gvsig.tools.evaluator;
2

  
3
import java.util.Iterator;
4

  
5
public interface EvaluatorData {
6

  
7
	public Object getDataValue(String name);
8

  
9
	public Object getContextValue(String name);
10

  
11
	public Iterator getDataValues();
12

  
13
	public Iterator getDataNames();
14
}
0 15

  
tags/tmp_build/libraries/libTools/src/org/gvsig/tools/evaluator/Evaluator.java
1
package org.gvsig.tools.evaluator;
2

  
3
public interface Evaluator {
4

  
5
	/**
6
	 * Evalue with the data suministred as parameter.
7
	 *
8
	 * @param data
9
	 * @return the result of the evaluation.
10
	 */
11
	public Object evaluate(EvaluatorData data);
12

  
13
	/**
14
	 * Get the simbolic name of the evaluator.
15
	 *
16
	 * @return the name
17
	 */
18
	public String getName();
19

  
20
	/**
21
	 * Get a description of the action performed with the evaluator.
22
	 *
23
	 * @return the description
24
	 */
25
	public String getDescription();
26

  
27
	/**
28
	 * Get an CQL representation of the evaluator.
29
	 * 
30
	 * @return the CQL string or null if not supported.
31
	 */
32
	public String getCQL();
33

  
34
	/**
35
	 * Get an array of match values for the name in the evaluation.
36
	 *
37
	 * @param name
38
	 * @return An array of match values or null if not use name in the
39
	 *         evaluation or if not is supported this method.
40
	 */
41
	public EvaluatorFieldValue[] getFieldValues(String name);
42
}
0 43

  
tags/tmp_build/libraries/libTools/src/org/gvsig/tools/evaluator/EvaluatorFieldValue.java
1
package org.gvsig.tools.evaluator;
2

  
3
public class EvaluatorFieldValue {
4

  
5
	final public static int MATCH = 0;
6
	final public static int RANGE = 1;
7
	final public static int NEAREST = 2;
8

  
9
	private int type;
10
	private Object value1;
11
	private Object value2;
12
	private int count;
13
	private int tolerance;
14
	private String fieldName;
15

  
16
	public EvaluatorFieldValue(String fieldName, Object value) {
17
		this.fieldName = fieldName;
18
		this.type = MATCH;
19
		this.value1 = value;
20
		this.value2 = null;
21
		this.count = -1;
22
		this.tolerance = -1;
23
	}
24

  
25
	public EvaluatorFieldValue(String fieldName, Object value1, Object value2) {
26
		this.fieldName = fieldName;
27
		this.type = RANGE;
28
		this.value1 = value1;
29
		this.value2 = value2;
30
		this.count = -1;
31
		this.tolerance = -1;
32
	}
33

  
34
	public EvaluatorFieldValue(String fieldName, int count, int tolerance,
35
			Object value) {
36
		this.fieldName = fieldName;
37
		this.type = NEAREST;
38
		this.count = count;
39
		this.tolerance = tolerance;
40
		this.value1 = value;
41
		this.value2 = null;
42
	}
43

  
44
	public EvaluatorFieldValue(String fieldName, int count, Object value) {
45
		this.fieldName = fieldName;
46
		this.type = NEAREST;
47
		this.count = count;
48
		this.tolerance = -1;
49
		this.value1 = value;
50
		this.value2 = null;
51
	}
52

  
53
	/**
54
	 * Get the type of operation realiced over the field.
55
	 * 
56
	 * The posibles values are: MATCH RANGE or NEAREST
57
	 * 
58
	 * @return an int with the type of operation
59
	 */
60
	public int getType() {
61
		return this.type;
62
	}
63

  
64
	/**
65
	 * Get the fieldName over the operation is realiced.
66
	 *
67
	 * @return String name of field.
68
	 */
69
	public String getFieldName() {
70
		return this.fieldName;
71
	}
72

  
73
	/**
74
	 * Get the count used in the nearest operation.
75
	 *
76
	 * @return the count or -1 if not aplicable.
77
	 */
78
	public int getCount() {
79
		return this.count;
80
	}
81

  
82
	/**
83
	 * Get the tolerance used in the nearest operation.
84
	 *
85
	 * @return the tolerance or -1 if not aplicable.
86
	 */
87
	public int getTolerance() {
88
		return this.tolerance;
89
	}
90

  
91
	/**
92
	 * Get the value used in the match or nearest operation.
93
	 *
94
	 * @return the match value or null if not aplicable.
95
	 */
96
	public Object getValue() {
97
		return this.value1;
98
	}
99

  
100
	/**
101
	 * Get the initial value used in the range operation.
102
	 *
103
	 * @return the first value or null if not aplicable.
104
	 */
105
	public Object getValue1() {
106
		return this.value1;
107
	}
108

  
109
	/**
110
	 * Get the final value used in the range operation.
111
	 *
112
	 * @return the final value or null if not aplicable.
113
	 */
114
	public Object getValue2() {
115
		return this.value2;
116
	}
117
}
0 118

  
tags/tmp_build/libraries/libTools/src/org/gvsig/tools/evaluator/AbstractEvaluator.java
1
package org.gvsig.tools.evaluator;
2

  
3

  
4
public abstract class AbstractEvaluator implements Evaluator {
5

  
6
	public String getDescription() {
7
		return "";
8
	}
9

  
10
	public String getCQL() {
11
		return null;
12
	}
13

  
14
	public EvaluatorFieldValue[] getFieldValues(String name) {
15
		return null;
16
	}
17
}
0 18

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff