Revision 24064
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/ToolsLocator.java | ||
---|---|---|
52 | 52 |
|
53 | 53 |
/** |
54 | 54 |
* Registers the Class implementing the PersistenceManager interface. |
55 |
*
|
|
55 |
* |
|
56 | 56 |
* @param clazz |
57 | 57 |
* implementing the PersistenceManager interface |
58 | 58 |
*/ |
... | ... | |
62 | 62 |
clazz); |
63 | 63 |
} |
64 | 64 |
|
65 |
public static void registerDefaultPersistenceManager(Class clazz) { |
|
66 |
getInstance().registerDefault(PERSISTENCE_MANAGER_NAME, |
|
67 |
PERSISTENCE_MANAGER_DESCRIPTION, clazz); |
|
68 |
} |
|
69 |
|
|
65 | 70 |
/** |
66 | 71 |
* Return a reference to OperationManager. |
67 |
*
|
|
72 |
* |
|
68 | 73 |
* @return a reference to OperationManager |
69 | 74 |
* @throws LocatorException |
70 | 75 |
* if there is no access to the class or the class cannot be |
... | ... | |
78 | 83 |
|
79 | 84 |
/** |
80 | 85 |
* Registers the Class implementing the OperationManager interface. |
81 |
*
|
|
86 |
* |
|
82 | 87 |
* @param clazz |
83 | 88 |
* implementing the OperationManager interface |
84 | 89 |
*/ |
... | ... | |
87 | 92 |
OPERATION_MANAGER_DESCRIPTION, clazz); |
88 | 93 |
} |
89 | 94 |
|
95 |
public static void registerDefaultOperationManager(Class clazz) { |
|
96 |
getInstance().registerDefault(OPERATION_MANAGER_NAME, |
|
97 |
OPERATION_MANAGER_DESCRIPTION, clazz); |
|
98 |
} |
|
99 |
|
|
90 | 100 |
} |
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/ToolsLibrary.java | ||
---|---|---|
33 | 33 |
public class ToolsLibrary implements Library { |
34 | 34 |
|
35 | 35 |
public void initialize() throws ReferenceNotRegisteredException { |
36 |
|
|
36 |
ToolsLocator.registerDefaultOperationManager(DefaultOperationManager); |
|
37 | 37 |
} |
38 | 38 |
|
39 | 39 |
public void postInitialize() throws ReferenceNotRegisteredException { |
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/attributes/Attributes.java | ||
---|---|---|
4 | 4 |
|
5 | 5 |
public interface Attributes { |
6 | 6 |
|
7 |
public boolean allowAnonimousAttributes(); |
|
8 |
|
|
7 | 9 |
/** |
8 | 10 |
* Returns the value of an attribute. |
9 | 11 |
* |
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/attributes/DefaultAttributes.java | ||
---|---|---|
14 | 14 |
|
15 | 15 |
private Map params; |
16 | 16 |
private Map alias; |
17 |
private boolean allowAnonimousAttributes; |
|
17 | 18 |
|
18 | 19 |
public DefaultAttributes() { |
19 | 20 |
this.params = new HashMap(); |
20 | 21 |
this.alias = new HashMap(); |
22 |
this.allowAnonimousAttributes = false; |
|
21 | 23 |
} |
22 | 24 |
|
25 |
public DefaultAttributes(boolean allowAnonimousAttributes) { |
|
26 |
this.params = new HashMap(); |
|
27 |
this.alias = new HashMap(); |
|
28 |
this.allowAnonimousAttributes = allowAnonimousAttributes; |
|
29 |
} |
|
30 |
|
|
31 |
final protected void setAllowAnonimousAttributes( |
|
32 |
boolean allowAnonimousAttributes) { |
|
33 |
this.allowAnonimousAttributes = allowAnonimousAttributes; |
|
34 |
} |
|
35 |
|
|
36 |
public boolean allowAnonimousAttributes() { |
|
37 |
return this.allowAnonimousAttributes; |
|
38 |
} |
|
39 |
|
|
23 | 40 |
public AttributeDescriptor addAttribute(String name, int dataType, |
24 | 41 |
String description, Object defaultValue) { |
25 | 42 |
AttributeDescriptor attr = new DefaultAttributeDescriptor(name, |
... | ... | |
69 | 86 |
} |
70 | 87 |
|
71 | 88 |
public void loadState(PersistentState state) throws PersistenceException { |
89 |
state.set("Attributes.allowAnonimousAttributes", |
|
90 |
allowAnonimousAttributes); |
|
72 | 91 |
Iterator it = params.values().iterator(); |
73 | 92 |
while (it.hasNext()) { |
74 | 93 |
DefaultAttributeDescriptor p = ((DefaultAttributeDescriptor) it |
... | ... | |
81 | 100 |
Iterator it = state.getNames(); |
82 | 101 |
while (it.hasNext()) { |
83 | 102 |
String name = (String) it.next(); |
84 |
try { |
|
85 |
this.setAttribute(name, state.get(name)); |
|
86 |
} catch (PersistenceValueNotFoundException e) { |
|
87 |
// Ignore |
|
103 |
if (name.equals("Attributes.allowAnonimousAttributes")) { |
|
104 |
this.allowAnonimousAttributes = state.getBoolean(name); |
|
105 |
} else { |
|
106 |
try { |
|
107 |
this.setAttribute(name, state.get(name)); |
|
108 |
} catch (PersistenceValueNotFoundException e) { |
|
109 |
// Ignore |
|
110 |
} |
|
88 | 111 |
} |
89 | 112 |
} |
90 | 113 |
} |
branches/v2_0_0_prep/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 |
} |
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/exception/ExceptionTranslator.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 ExceptionTranslator { |
|
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 |
} |
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/exception/BaseException.java | ||
---|---|---|
2 | 2 |
* |
3 | 3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
4 | 4 |
* of the Valencian Gobernment (CIT) |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* This program is free software; you can redistribute it and/or |
7 | 7 |
* modify it under the terms of the GNU General Public License |
8 | 8 |
* as published by the Free Software Foundation; either version 2 |
9 | 9 |
* of the License, or (at your option) any later version. |
10 |
*
|
|
10 |
* |
|
11 | 11 |
* This program is distributed in the hope that it will be useful, |
12 | 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | 14 |
* GNU General Public License for more details. |
15 |
*
|
|
15 |
* |
|
16 | 16 |
* You should have received a copy of the GNU General Public License |
17 | 17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 | 19 |
* MA 02110-1301, USA. |
20 |
*
|
|
20 |
* |
|
21 | 21 |
*/ |
22 | 22 |
|
23 | 23 |
/* |
... | ... | |
30 | 30 |
import java.util.Map; |
31 | 31 |
|
32 | 32 |
/** |
33 |
*
|
|
33 |
* |
|
34 | 34 |
* Esta clase esta pensada para actuar como clase base para las excepciones que |
35 | 35 |
* se lanzan dentro del proyecto de gvSIG. |
36 |
*
|
|
36 |
* |
|
37 | 37 |
* A?ade la implementacion necesaria para disponer de mensajes de error |
38 | 38 |
* internacionalizables, a traves del metodo getLocalizedMessage, asi como una |
39 | 39 |
* serie de metodos que nos permiten obtener los mesanes de error de la cadena |
40 | 40 |
* de excepciones enlazadas a traves de su "causa", asi como utilidades que |
41 | 41 |
* permitan recorrer de forma comoda esta cadena de excepciones por medio de un |
42 | 42 |
* Iterador. |
43 |
*
|
|
43 |
* |
|
44 | 44 |
* @author Equipo de desarrollo de gvSIG. |
45 |
*
|
|
45 |
* |
|
46 | 46 |
*/ |
47 | 47 |
public abstract class BaseException extends Exception implements IBaseException { |
48 |
/** |
|
49 |
* |
|
50 |
*/ |
|
51 |
private static final long serialVersionUID = 6631799898764636572L; |
|
48 | 52 |
private final static String BLANKS =" "; |
49 |
private static IExceptionTranslator translator= null;
|
|
53 |
private static ExceptionTranslator translator = null;
|
|
50 | 54 |
|
51 | 55 |
protected String messageKey; |
52 | 56 |
|
... | ... | |
59 | 63 |
* Unique code of error. |
60 | 64 |
*/ |
61 | 65 |
protected long code; |
62 |
|
|
66 |
|
|
63 | 67 |
/** |
64 | 68 |
* Empty constructor, don't use it anymore. |
65 |
*
|
|
69 |
* |
|
66 | 70 |
* @deprecated |
67 | 71 |
*/ |
68 | 72 |
public BaseException() { |
... | ... | |
71 | 75 |
/** |
72 | 76 |
* Constructs a BaseException with a default message format, a key to find a |
73 | 77 |
* localized message format, and a unique code to identify the exception. |
74 |
*
|
|
78 |
* |
|
75 | 79 |
* @param message |
76 | 80 |
* the default messageFormat to describe the exception |
77 | 81 |
* @param key |
... | ... | |
89 | 93 |
/** |
90 | 94 |
* Constructs a BaseException with a default message format, a key to find a |
91 | 95 |
* localized message format, and a unique code to identify the exception. |
92 |
*
|
|
96 |
* |
|
93 | 97 |
* @param message |
94 | 98 |
* the default messageFormat to describe the exception |
95 | 99 |
* @param cause |
... | ... | |
109 | 113 |
/** |
110 | 114 |
* Returns the format string received in the parameter with its keys |
111 | 115 |
* replaced with the corresponding values of the map. |
112 |
*
|
|
116 |
* |
|
113 | 117 |
* @param formatString |
114 | 118 |
* @param values |
115 | 119 |
* map |
... | ... | |
136 | 140 |
// Return the original format message in any other case |
137 | 141 |
return formatString; |
138 | 142 |
} |
139 |
|
|
143 |
|
|
140 | 144 |
/** |
141 | 145 |
* Method to replace message variables, not using the new String.replaceAll |
142 | 146 |
* method for Java ME CDC Compatibility. |
... | ... | |
169 | 173 |
return getLocalizedMessage(translator,0); |
170 | 174 |
} |
171 | 175 |
|
172 |
public String getLocalizedMessage(IExceptionTranslator translator, int indent){
|
|
176 |
public String getLocalizedMessage(ExceptionTranslator translator, int indent) {
|
|
173 | 177 |
|
174 | 178 |
String fmt; |
175 | 179 |
if (translator == null){ |
... | ... | |
198 | 202 |
int i = 1; |
199 | 203 |
while (iter.hasNext()){ |
200 | 204 |
Exception ex = ((Exception) iter.next()); |
201 |
|
|
205 |
|
|
202 | 206 |
if (msgBuffer.length() > 0) { |
203 | 207 |
msgBuffer.append("\n"); |
204 | 208 |
} |
205 |
|
|
209 |
|
|
206 | 210 |
if ( ex instanceof BaseException ) { |
207 | 211 |
BaseException bex = (BaseException) ex; |
208 | 212 |
msgBuffer.append(bex.getMessage(indent * i)); |
... | ... | |
210 | 214 |
msgBuffer.append(insertBlanksAtStart(ex.getMessage(), indent |
211 | 215 |
* i)); |
212 | 216 |
} |
213 |
|
|
217 |
|
|
214 | 218 |
i++; |
215 | 219 |
} |
216 | 220 |
return msgBuffer.toString(); |
... | ... | |
221 | 225 |
return getLocalizedMessageStack(BaseException.translator,0); |
222 | 226 |
} |
223 | 227 |
|
224 |
public String getLocalizedMessageStack(IExceptionTranslator translator, int indent) { |
|
228 |
public String getLocalizedMessageStack(ExceptionTranslator translator, |
|
229 |
int indent) { |
|
225 | 230 |
Iterator iter = this.iterator(); |
226 | 231 |
StringBuffer msgBuffer = new StringBuffer(); |
227 | 232 |
Exception ex; |
... | ... | |
308 | 313 |
* @param translator It(He,She) is used to translate |
309 | 314 |
* the messages associated with the exceptions. |
310 | 315 |
*/ |
311 |
public static void setTranslator(IExceptionTranslator translator){
|
|
316 |
public static void setTranslator(ExceptionTranslator translator) {
|
|
312 | 317 |
BaseException.translator = translator; |
313 | 318 |
} |
314 | 319 |
|
... | ... | |
322 | 327 |
|
323 | 328 |
} |
324 | 329 |
|
325 |
class TranslatorWraper implements IExceptionTranslator {
|
|
330 |
class TranslatorWraper implements ExceptionTranslator { |
|
326 | 331 |
|
327 | 332 |
private Object translator = null; |
328 | 333 |
private Method method = null; |
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/exception/BaseRuntimeException.java | ||
---|---|---|
2 | 2 |
* |
3 | 3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
4 | 4 |
* of the Valencian Gobernment (CIT) |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* This program is free software; you can redistribute it and/or |
7 | 7 |
* modify it under the terms of the GNU General Public License |
8 | 8 |
* as published by the Free Software Foundation; either version 2 |
9 | 9 |
* of the License, or (at your option) any later version. |
10 |
*
|
|
10 |
* |
|
11 | 11 |
* This program is distributed in the hope that it will be useful, |
12 | 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | 14 |
* GNU General Public License for more details. |
15 |
*
|
|
15 |
* |
|
16 | 16 |
* You should have received a copy of the GNU General Public License |
17 | 17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 | 19 |
* MA 02110-1301, USA. |
20 |
*
|
|
20 |
* |
|
21 | 21 |
*/ |
22 | 22 |
|
23 | 23 |
/* |
... | ... | |
34 | 34 |
|
35 | 35 |
/** |
36 | 36 |
* Adds RuntimeException nature to the BaseException. |
37 |
*
|
|
37 |
* |
|
38 | 38 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a> |
39 | 39 |
*/ |
40 | 40 |
public abstract class BaseRuntimeException extends RuntimeException implements |
41 | 41 |
IBaseException { |
42 |
|
|
42 |
|
|
43 | 43 |
private static final long serialVersionUID = 4584809667815834006L; |
44 | 44 |
|
45 | 45 |
// Inner delegate exception |
... | ... | |
49 | 49 |
* Constructs a RuntimeBaseException with a default message format, a key to |
50 | 50 |
* find a localized message format, and a unique code to identify the |
51 | 51 |
* exception. |
52 |
*
|
|
52 |
* |
|
53 | 53 |
* @param message |
54 | 54 |
* the default messageFormat to describe the exception |
55 | 55 |
* @param key |
... | ... | |
64 | 64 |
/** |
65 | 65 |
* Constructs a BaseException with a default message format, a key to find a |
66 | 66 |
* localized message format, and a unique code to identify the exception. |
67 |
*
|
|
67 |
* |
|
68 | 68 |
* @param message |
69 | 69 |
* the default messageFormat to describe the exception |
70 | 70 |
* @param cause |
... | ... | |
99 | 99 |
return exception.getLocalizedMessage(); |
100 | 100 |
} |
101 | 101 |
|
102 |
public String getLocalizedMessage(IExceptionTranslator translator,
|
|
102 |
public String getLocalizedMessage(ExceptionTranslator translator, |
|
103 | 103 |
int indent) { |
104 | 104 |
return exception.getLocalizedMessage(translator, indent); |
105 | 105 |
} |
... | ... | |
108 | 108 |
return exception.getLocalizedMessageStack(); |
109 | 109 |
} |
110 | 110 |
|
111 |
public String getLocalizedMessageStack(IExceptionTranslator translator,
|
|
111 |
public String getLocalizedMessageStack(ExceptionTranslator translator, |
|
112 | 112 |
int indent) { |
113 | 113 |
return exception.getLocalizedMessageStack(translator, indent); |
114 | 114 |
} |
... | ... | |
184 | 184 |
/** |
185 | 185 |
* Used to return a map that serves to replace in the format string the keys |
186 | 186 |
* with the corresponding values. |
187 |
*
|
|
187 |
* |
|
188 | 188 |
* @return the message values |
189 | 189 |
*/ |
190 | 190 |
abstract protected Map values(); |
191 | 191 |
|
192 | 192 |
/** |
193 | 193 |
* Inner BaseException implementation to use as the inner exception. |
194 |
*
|
|
194 |
* |
|
195 | 195 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a> |
196 | 196 |
*/ |
197 | 197 |
public class DelegateBaseException extends BaseException { |
198 |
|
|
198 |
|
|
199 | 199 |
private static final long serialVersionUID = 1784643169215420315L; |
200 |
|
|
200 |
|
|
201 | 201 |
private BaseRuntimeException baseException; |
202 |
|
|
202 |
|
|
203 | 203 |
public DelegateBaseException(String message, String key, long code, |
204 | 204 |
BaseRuntimeException baseException) { |
205 | 205 |
super(message, key, code); |
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/exception/IBaseException.java | ||
---|---|---|
2 | 2 |
* |
3 | 3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
4 | 4 |
* of the Valencian Gobernment (CIT) |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* This program is free software; you can redistribute it and/or |
7 | 7 |
* modify it under the terms of the GNU General Public License |
8 | 8 |
* as published by the Free Software Foundation; either version 2 |
9 | 9 |
* of the License, or (at your option) any later version. |
10 |
*
|
|
10 |
* |
|
11 | 11 |
* This program is distributed in the hope that it will be useful, |
12 | 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | 14 |
* GNU General Public License for more details. |
15 |
*
|
|
15 |
* |
|
16 | 16 |
* You should have received a copy of the GNU General Public License |
17 | 17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 | 19 |
* MA 02110-1301, USA. |
20 |
*
|
|
20 |
* |
|
21 | 21 |
*/ |
22 | 22 |
|
23 | 23 |
/* |
... | ... | |
28 | 28 |
import java.util.Iterator; |
29 | 29 |
|
30 | 30 |
/** |
31 |
*
|
|
32 |
*
|
|
31 |
* |
|
32 |
* |
|
33 | 33 |
* @author Equipo de desarrollo de gvSIG |
34 | 34 |
* |
35 | 35 |
*/ |
36 | 36 |
public interface IBaseException { |
37 |
|
|
38 |
/**
|
|
37 |
|
|
38 |
/** |
|
39 | 39 |
* Returns the message that describes the exception. |
40 |
*
|
|
40 |
* |
|
41 | 41 |
* @return The message. |
42 | 42 |
*/ |
43 | 43 |
public String getMessage(); |
44 | 44 |
|
45 |
/**
|
|
45 |
/** |
|
46 | 46 |
* Returns the message that describes the exception, with indentation. |
47 |
*
|
|
47 |
* |
|
48 | 48 |
* @param indent Quantity of blanks to insert |
49 | 49 |
* at the start of the message. |
50 | 50 |
* @return The message with indentation. |
51 | 51 |
*/ |
52 | 52 |
public String getMessage(int indent); |
53 | 53 |
|
54 |
/**
|
|
54 |
/** |
|
55 | 55 |
* Returns the translated message that describes the exception. |
56 |
*
|
|
56 |
* |
|
57 | 57 |
* @return The translated message with indentation. |
58 | 58 |
*/ |
59 | 59 |
public String getLocalizedMessage(); |
60 |
|
|
61 |
/**
|
|
60 |
|
|
61 |
/** |
|
62 | 62 |
* Returns the translated message that |
63 | 63 |
* describes the exception with indentation. |
64 | 64 |
* |
... | ... | |
71 | 71 |
* at the start of the message. |
72 | 72 |
* @return The translated message with indentation. |
73 | 73 |
*/ |
74 |
public String getLocalizedMessage(IExceptionTranslator translator, int indent);
|
|
75 |
|
|
76 |
/**
|
|
74 |
public String getLocalizedMessage(ExceptionTranslator translator, int indent); |
|
75 |
|
|
76 |
/** |
|
77 | 77 |
* Crosses the exceptions chained through cause to conform |
78 | 78 |
* the message. |
79 |
*
|
|
79 |
* |
|
80 | 80 |
* @return The compound message with all the messages |
81 | 81 |
* of the stack of exceptions. |
82 | 82 |
*/ |
83 | 83 |
public String getMessageStack(); |
84 | 84 |
|
85 |
/**
|
|
85 |
/** |
|
86 | 86 |
* Crosses the exceptions chained through cause to conform |
87 | 87 |
* the compound message with indentation. |
88 |
*
|
|
88 |
* |
|
89 | 89 |
* @param indent Quantity of blanks to insert |
90 | 90 |
* at the start of the messages. |
91 | 91 |
* @return The compound message with all the messages |
... | ... | |
94 | 94 |
*/ |
95 | 95 |
public String getMessageStack(int indent); |
96 | 96 |
|
97 |
/**
|
|
97 |
/** |
|
98 | 98 |
* Crosses the exceptions chained through cause |
99 | 99 |
* to conform the compound message in the corresponding language. |
100 |
*
|
|
100 |
* |
|
101 | 101 |
* @return The translated compound message. |
102 |
*
|
|
102 |
* |
|
103 | 103 |
*/ |
104 | 104 |
public String getLocalizedMessageStack(); |
105 | 105 |
|
106 |
/**
|
|
106 |
/** |
|
107 | 107 |
* Crosses the exceptions chained through cause |
108 | 108 |
* to conform the compound message in the corresponding language. |
109 |
*
|
|
109 |
* |
|
110 | 110 |
* @param translator Instance of a class that fulfills |
111 | 111 |
* the IExceptionTranslator interface. |
112 | 112 |
* His method "getText" takes charge returning |
... | ... | |
115 | 115 |
* @param indent Quantity of blanks to insert |
116 | 116 |
* at the start of the messages. |
117 | 117 |
* @return The translated message with indentation. |
118 |
*
|
|
118 |
* |
|
119 | 119 |
*/ |
120 |
public String getLocalizedMessageStack(IExceptionTranslator translator, int indent); |
|
121 |
|
|
122 |
|
|
123 |
/** |
|
120 |
public String getLocalizedMessageStack(ExceptionTranslator translator, |
|
121 |
int indent); |
|
122 |
|
|
123 |
|
|
124 |
/** |
|
124 | 125 |
* @return The exception's code. |
125 | 126 |
*/ |
126 | 127 |
public long getCode(); |
127 |
|
|
128 |
/**
|
|
128 |
|
|
129 |
/** |
|
129 | 130 |
* @return The format string. |
130 | 131 |
*/ |
131 | 132 |
public String getFormatString(); |
132 |
|
|
133 |
/**
|
|
133 |
|
|
134 |
/** |
|
134 | 135 |
* @return The message key associated to the exception. |
135 | 136 |
*/ |
136 | 137 |
public String getMessageKey(); |
137 |
|
|
138 |
/**
|
|
138 |
|
|
139 |
/** |
|
139 | 140 |
* @return A iterator for the chained exceptions. |
140 | 141 |
*/ |
141 | 142 |
public Iterator iterator(); |
142 |
|
|
143 |
|
|
143 | 144 |
} |
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/exception/ListBaseException.java | ||
---|---|---|
2 | 2 |
* |
3 | 3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
4 | 4 |
* of the Valencian Gobernment (CIT) |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* This program is free software; you can redistribute it and/or |
7 | 7 |
* modify it under the terms of the GNU General Public License |
8 | 8 |
* as published by the Free Software Foundation; either version 2 |
9 | 9 |
* of the License, or (at your option) any later version. |
10 |
*
|
|
10 |
* |
|
11 | 11 |
* This program is distributed in the hope that it will be useful, |
12 | 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | 14 |
* GNU General Public License for more details. |
15 |
*
|
|
15 |
* |
|
16 | 16 |
* You should have received a copy of the GNU General Public License |
17 | 17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 | 19 |
* MA 02110-1301, USA. |
20 |
*
|
|
20 |
* |
|
21 | 21 |
*/ |
22 | 22 |
|
23 | 23 |
/* |
... | ... | |
37 | 37 |
*/ |
38 | 38 |
public abstract class ListBaseException extends BaseException implements List{ |
39 | 39 |
private List exceptions = new ArrayList(); |
40 |
|
|
40 |
|
|
41 | 41 |
/* (non-Javadoc) |
42 | 42 |
* @see java.util.Collection#size() |
43 | 43 |
*/ |
... | ... | |
202 | 202 |
public List subList(int arg0, int arg1) { |
203 | 203 |
return this.exceptions.subList(arg0, arg1); |
204 | 204 |
} |
205 |
|
|
205 |
|
|
206 | 206 |
/* (non-Javadoc) |
207 | 207 |
* @see java.lang.Throwable#getMessage() |
208 | 208 |
*/ |
... | ... | |
216 | 216 |
} |
217 | 217 |
return msg; |
218 | 218 |
} |
219 |
|
|
220 |
public String getLocalizedMessage(IExceptionTranslator exceptionTranslator, int indent) { |
|
219 |
|
|
220 |
public String getLocalizedMessage(ExceptionTranslator exceptionTranslator, |
|
221 |
int indent) { |
|
221 | 222 |
String msg = super.getLocalizedMessage(exceptionTranslator, indent); |
222 | 223 |
Exception bex; |
223 | 224 |
Iterator iter=this.exceptions.iterator(); |
224 | 225 |
while (iter.hasNext()) { |
225 | 226 |
bex = (Exception) iter.next(); |
226 | 227 |
if( bex instanceof BaseException ) { |
227 |
msg = msg + "\n " + ((BaseException)bex).getLocalizedMessage(exceptionTranslator, indent);
|
|
228 |
msg = msg + "\n " + ((BaseException)bex).getLocalizedMessage(exceptionTranslator, indent); |
|
228 | 229 |
} else { |
229 | 230 |
msg = msg + "\n " + bex.getLocalizedMessage(); |
230 | 231 |
} |
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/locator/Locator.java | ||
---|---|---|
2 | 2 |
* |
3 | 3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
4 | 4 |
* of the Valencian Gobernment (CIT) |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* This program is free software; you can redistribute it and/or |
7 | 7 |
* modify it under the terms of the GNU General Public License |
8 | 8 |
* as published by the Free Software Foundation; either version 2 |
9 | 9 |
* of the License, or (at your option) any later version. |
10 |
*
|
|
10 |
* |
|
11 | 11 |
* This program is distributed in the hope that it will be useful, |
12 | 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | 14 |
* GNU General Public License for more details. |
15 |
*
|
|
15 |
* |
|
16 | 16 |
* You should have received a copy of the GNU General Public License |
17 | 17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 | 19 |
* MA 02110-1301, USA. |
20 |
*
|
|
20 |
* |
|
21 | 21 |
*/ |
22 | 22 |
|
23 | 23 |
/* |
... | ... | |
28 | 28 |
|
29 | 29 |
/** |
30 | 30 |
* Manages references to the objects of a Library or module. |
31 |
*
|
|
31 |
* |
|
32 | 32 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a> |
33 | 33 |
*/ |
34 | 34 |
public interface Locator { |
35 | 35 |
|
36 | 36 |
/** |
37 | 37 |
* Returns a reference to the object with the given name. |
38 |
*
|
|
38 |
* |
|
39 | 39 |
* @param name |
40 | 40 |
* of the object to return |
41 | 41 |
* @return an instance of an object, or null if not found |
... | ... | |
48 | 48 |
/** |
49 | 49 |
* Returns the list of names of references available through this Locator. |
50 | 50 |
* Must return null if there are not any registered names. |
51 |
*
|
|
51 |
* |
|
52 | 52 |
* @return the list of names of references |
53 | 53 |
*/ |
54 | 54 |
String[] getNames(); |
... | ... | |
56 | 56 |
/** |
57 | 57 |
* Registers a class related to a name. The class is used to create an |
58 | 58 |
* instance of the object to return in the {@link #get(String)} method. |
59 |
*
|
|
59 |
* |
|
60 | 60 |
* @param name |
61 | 61 |
* of the object to register |
62 | 62 |
* @param clazz |
... | ... | |
64 | 64 |
*/ |
65 | 65 |
void register(String name, Class clazz); |
66 | 66 |
|
67 |
void registerDefault(String name, Class clazz); |
|
68 |
|
|
67 | 69 |
/** |
68 | 70 |
* Registers a class related to a name. The class is used to create an |
69 | 71 |
* instance of the object to return in the {@link #get(String)} method. |
70 |
*
|
|
72 |
* |
|
71 | 73 |
* @param name |
72 | 74 |
* of the object to register |
73 | 75 |
* @param description |
... | ... | |
77 | 79 |
*/ |
78 | 80 |
void register(String name, String description, Class clazz); |
79 | 81 |
|
82 |
void registerDefault(String name, String description, Class clazz); |
|
83 |
|
|
80 | 84 |
/** |
81 | 85 |
* Registers an object factory related to a name. The factory is used to |
82 | 86 |
* create an instance of the object to return in the {@link #get(String)} |
83 | 87 |
* method. |
84 |
*
|
|
88 |
* |
|
85 | 89 |
* @param name |
86 | 90 |
* of the object to register |
87 | 91 |
* @param factory |
... | ... | |
93 | 97 |
* Registers an object factory related to a name. The factory is used to |
94 | 98 |
* create an instance of the object to return in the {@link #get(String)} |
95 | 99 |
* method. |
96 |
*
|
|
100 |
* |
|
97 | 101 |
* @param name |
98 | 102 |
* of the object to register |
99 | 103 |
* @param description |
... | ... | |
102 | 106 |
* the factory of objects to register |
103 | 107 |
*/ |
104 | 108 |
void register(String name, String description, LocatorObjectFactory factory); |
105 |
|
|
109 |
|
|
106 | 110 |
/** |
107 | 111 |
* Returns the name of the Locator, for registration, logging, and other |
108 | 112 |
* uses. |
109 |
*
|
|
113 |
* |
|
110 | 114 |
* @return the name of the Locator |
111 | 115 |
*/ |
112 | 116 |
String getLocatorName(); |
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/locator/AbstractLocator.java | ||
---|---|---|
2 | 2 |
* |
3 | 3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
4 | 4 |
* of the Valencian Gobernment (CIT) |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* This program is free software; you can redistribute it and/or |
7 | 7 |
* modify it under the terms of the GNU General Public License |
8 | 8 |
* as published by the Free Software Foundation; either version 2 |
9 | 9 |
* of the License, or (at your option) any later version. |
10 |
*
|
|
10 |
* |
|
11 | 11 |
* This program is distributed in the hope that it will be useful, |
12 | 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | 14 |
* GNU General Public License for more details. |
15 |
*
|
|
15 |
* |
|
16 | 16 |
* You should have received a copy of the GNU General Public License |
17 | 17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 | 19 |
* MA 02110-1301, USA. |
20 |
*
|
|
20 |
* |
|
21 | 21 |
*/ |
22 | 22 |
|
23 | 23 |
/* |
... | ... | |
36 | 36 |
|
37 | 37 |
/** |
38 | 38 |
* Locator implementation based on the use of the ExtensionPoints. |
39 |
*
|
|
39 |
* |
|
40 | 40 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a> |
41 | 41 |
*/ |
42 | 42 |
public abstract class AbstractLocator implements Locator { |
... | ... | |
77 | 77 |
.add(getLocatorName(), name, clazz); |
78 | 78 |
} |
79 | 79 |
|
80 |
public void registerDefault(String name, Class clazz) { |
|
81 |
ExtensionPoint ep = getExtensionPoint(); |
|
82 |
if (ep.get(name) == null) { |
|
83 |
register(name, clazz); |
|
84 |
} |
|
85 |
} |
|
86 |
|
|
80 | 87 |
public void register(String name, String description, Class clazz) { |
81 | 88 |
ExtensionPointsSingleton.getInstance().add(getLocatorName(), name, |
82 | 89 |
description, clazz); |
83 | 90 |
} |
84 | 91 |
|
92 |
public void registerDefault(String name, String description, Class clazz) { |
|
93 |
ExtensionPoint ep = getExtensionPoint(); |
|
94 |
if( ep.get(name) == null ) { |
|
95 |
register(name,description, clazz); |
|
96 |
} |
|
97 |
} |
|
98 |
|
|
85 | 99 |
public void register(String name, LocatorObjectFactory factory) { |
86 | 100 |
ExtensionPointsSingleton.getInstance().add(getLocatorName(), name, |
87 | 101 |
factory); |
... | ... | |
92 | 106 |
ExtensionPointsSingleton.getInstance().add(getLocatorName(), name, |
93 | 107 |
description, factory); |
94 | 108 |
} |
95 |
|
|
109 |
|
|
96 | 110 |
public String toString() { |
97 | 111 |
return getLocatorName(); |
98 | 112 |
} |
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/operations/ExtendedOperations.java | ||
---|---|---|
1 |
package org.gvsig.tools.operations; |
|
2 |
|
|
3 |
|
|
4 |
public interface ExtendedOperations { |
|
5 |
|
|
6 |
public Object invokeOperation(int code, |
|
7 |
OperationContext context) |
|
8 |
throws OperationException, |
|
9 |
OperationNotSupportedException; |
|
10 |
|
|
11 |
public Object invokeOperation(String name, |
|
12 |
OperationContext context) |
|
13 |
throws OperationException, |
|
14 |
OperationNotSupportedException; |
|
15 |
|
|
16 |
|
|
17 |
public Object getOperation(int code) |
|
18 |
throws OperationException, |
|
19 |
OperationNotSupportedException; |
|
20 |
|
|
21 |
public Object getOperation(String name) |
|
22 |
throws OperationException, |
|
23 |
OperationNotSupportedException; |
|
24 |
|
|
25 |
|
|
26 |
public boolean implementsOperation(int code); |
|
27 |
|
|
28 |
public boolean implementsOperation(String name); |
|
29 |
|
|
30 |
} |
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/operations/OperationNotSupportedException.java | ||
---|---|---|
2 | 2 |
* |
3 | 3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
4 | 4 |
* of the Valencian Government (CIT) |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* This program is free software; you can redistribute it and/or |
7 | 7 |
* modify it under the terms of the GNU General Public License |
8 | 8 |
* as published by the Free Software Foundation; either version 2 |
9 | 9 |
* of the License, or (at your option) any later version. |
10 |
*
|
|
10 |
* |
|
11 | 11 |
* This program is distributed in the hope that it will be useful, |
12 | 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | 14 |
* GNU General Public License for more details. |
15 |
*
|
|
15 |
* |
|
16 | 16 |
* You should have received a copy of the GNU General Public License |
17 | 17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 | 19 |
* MA 02110-1301, USA. |
20 |
*
|
|
20 |
* |
|
21 | 21 |
*/ |
22 | 22 |
|
23 | 23 |
/* |
24 | 24 |
* AUTHORS (In addition to CIT): |
25 | 25 |
* 2008 IVER T.I. S.A. {{Task}} |
26 | 26 |
*/ |
27 |
|
|
27 |
|
|
28 | 28 |
package org.gvsig.tools.operations; |
29 | 29 |
|
30 |
import java.util.HashMap; |
|
31 |
import java.util.Map; |
|
32 | 30 |
|
33 |
import org.gvsig.tools.exception.BaseException;
|
|
31 |
public class OperationNotSupportedException extends OperationException {
|
|
34 | 32 |
|
35 |
public class OperationNotSupportedException extends BaseException { |
|
36 | 33 |
|
37 | 34 |
/** |
38 |
*
|
|
35 |
* |
|
39 | 36 |
*/ |
40 |
private static final long serialVersionUID = 1L; |
|
41 |
/** |
|
42 |
* Generated serial version UID |
|
43 |
*/ |
|
44 |
private static final String MESSAGE = "Operation Exception"; |
|
45 |
private static final String MESSAGE_KEY = "_Exception_executing_the_operation_XoperationNameX_with_code_XoperationCodeX"; |
|
46 |
private static final String FORMAT_STRING = |
|
47 |
"Operation %(operationName) with code %(operationCode) not supported."; |
|
48 |
|
|
49 |
private int operationCode = -1; |
|
50 |
private String operationName = "unknow"; |
|
37 |
private static final long serialVersionUID = -6662679326425178742L; |
|
38 |
private static final String MESSAGE_KEY = "_OperationNotSupportedException"; |
|
39 |
private static final String MESSAGE_FORMAT = "Operation %(operationName)s with code %(operationCode)s not supported in %(theClass)s."; |
|
51 | 40 |
|
52 |
public OperationNotSupportedException(int operationCode,String operationName) {
|
|
53 |
super(MESSAGE, MESSAGE_KEY, serialVersionUID);
|
|
54 |
this.formatString = FORMAT_STRING;
|
|
55 |
this.operationCode=operationCode;
|
|
56 |
this.operationName=operationName;
|
|
41 |
public OperationNotSupportedException(Class theClass, String operationName) {
|
|
42 |
super(MESSAGE_FORMAT, MESSAGE_KEY, serialVersionUID);
|
|
43 |
setValue("operationCode", new Integer(-1));
|
|
44 |
setValue("operationName", operationName);
|
|
45 |
setValue("theClass", theClass);
|
|
57 | 46 |
} |
58 |
|
|
59 |
public OperationNotSupportedException(int operationCode,String operationName,Throwable e) {
|
|
60 |
super(MESSAGE, e, MESSAGE_KEY, serialVersionUID);
|
|
61 |
this.formatString = FORMAT_STRING;
|
|
62 |
this.operationCode=operationCode;
|
|
63 |
this.operationName=operationName;
|
|
47 |
|
|
48 |
public OperationNotSupportedException(Class theClass, int code) {
|
|
49 |
super(MESSAGE_FORMAT, MESSAGE_KEY, serialVersionUID);
|
|
50 |
setValue("operationCode", new Integer(code));
|
|
51 |
setValue("operationName", "unknow");
|
|
52 |
setValue("theClass", theClass);
|
|
64 | 53 |
} |
65 |
|
|
66 |
protected Map values() { |
|
67 |
Map params = new HashMap(); |
|
68 |
params.put("operationCode",new Integer(this.operationCode)); |
|
69 |
params.put("operationName",this.operationName); |
|
70 |
return params; |
|
71 |
} |
|
72 | 54 |
|
73 | 55 |
} |
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/operations/OperationManager.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
public interface OperationManager { |
4 | 4 |
|
5 |
public Operation get(Object obj, String opname); |
|
5 |
public int getOperationCode(Class aClass, String name) |
|
6 |
throws OperationNotSupportedException; |
|
6 | 7 |
|
7 |
public Operation get(Object obj, int opcode); |
|
8 |
public Operation getOperation(Object obj, String name) |
|
9 |
throws OperationNotSupportedException; |
|
8 | 10 |
|
9 |
public Object invoke(Object obj, String opname, OperationContext context); |
|
11 |
public Operation getOperation(Object obj, int code) |
|
12 |
throws OperationNotSupportedException; |
|
10 | 13 |
|
11 |
public Object invoke(Object obj, int opcode, OperationContext context); |
|
14 |
public Operation getOperation(Class aClass, String name) |
|
15 |
throws OperationNotSupportedException; |
|
12 | 16 |
|
13 |
public boolean has(Object obj, String opname); |
|
17 |
public Operation getOperation(Class aClass, int code) |
|
18 |
throws OperationNotSupportedException; |
|
14 | 19 |
|
15 |
public boolean has(Object obj, int opcode); |
|
20 |
public Object invokeOperation(Object obj, String name, |
|
21 |
OperationContext context) throws OperationException; |
|
16 | 22 |
|
17 |
public int register(Object obj, String opname); |
|
23 |
public Object invokeOperation(Object obj, int code, OperationContext context) |
|
24 |
throws OperationException; |
|
25 |
|
|
26 |
public boolean hasOperation(Object obj, String name); |
|
27 |
|
|
28 |
public boolean hasOperation(Object obj, int code); |
|
29 |
|
|
30 |
public boolean hasOperation(Class aClass, String name); |
|
31 |
|
|
32 |
public boolean hasOperation(Class aClass, int code); |
|
33 |
|
|
34 |
public int registerOperation(Operation operation, Object obj); |
|
35 |
|
|
36 |
public int registerOperation(Operation operation, Class aClass); |
|
18 | 37 |
} |
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/operations/OperationException.java | ||
---|---|---|
2 | 2 |
* |
3 | 3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
4 | 4 |
* of the Valencian Government (CIT) |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* This program is free software; you can redistribute it and/or |
7 | 7 |
* modify it under the terms of the GNU General Public License |
8 | 8 |
* as published by the Free Software Foundation; either version 2 |
9 | 9 |
* of the License, or (at your option) any later version. |
10 |
*
|
|
10 |
* |
|
11 | 11 |
* This program is distributed in the hope that it will be useful, |
12 | 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | 14 |
* GNU General Public License for more details. |
15 |
*
|
|
15 |
* |
|
16 | 16 |
* You should have received a copy of the GNU General Public License |
17 | 17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 | 19 |
* MA 02110-1301, USA. |
20 |
*
|
|
20 |
* |
|
21 | 21 |
*/ |
22 | 22 |
|
23 | 23 |
/* |
24 | 24 |
* AUTHORS (In addition to CIT): |
25 | 25 |
* 2008 IVER T.I. S.A. {{Task}} |
26 | 26 |
*/ |
27 |
|
|
27 |
|
|
28 | 28 |
package org.gvsig.tools.operations; |
29 | 29 |
|
30 | 30 |
import java.util.HashMap; |
... | ... | |
33 | 33 |
import org.gvsig.tools.exception.BaseException; |
34 | 34 |
|
35 | 35 |
public class OperationException extends BaseException { |
36 |
|
|
37 | 36 |
/** |
38 |
* Generated serial version UID
|
|
37 |
* |
|
39 | 38 |
*/ |
40 |
private static final long serialVersionUID = -622721450600971933L; |
|
39 |
private static final long serialVersionUID = -2344772588507587265L; |
|
40 |
private final static String MESSAGE_FORMAT = "Error with operation."; |
|
41 |
private final static String MESSAGE_KEY = "_OperationException"; |
|
41 | 42 |
|
42 |
private static final String MESSAGE = "Operation Exception"; |
|
43 |
private static final String MESSAGE_KEY = "_Exception_executing_the_operation_XoperationNameX_with_code_XoperationCodeX"; |
|
44 |
private static final String FORMAT_STRING = |
|
45 |
"Exception executing the operation %(operationName) with code %(operationCode)."; |
|
46 |
|
|
47 |
private int operationCode = -1; |
|
48 |
private String operationName = "unknow"; |
|
43 |
protected Map values = new HashMap(); |
|
49 | 44 |
|
50 |
public OperationException(int operationCode,String operationName) { |
|
51 |
super(MESSAGE, MESSAGE_KEY, serialVersionUID); |
|
52 |
this.formatString = FORMAT_STRING; |
|
53 |
this.operationCode=operationCode; |
|
54 |
this.operationName=operationName; |
|
45 |
public OperationException(String messageFormat, Throwable cause, |
|
46 |
String messageKey, long code) { |
|
47 |
super(messageFormat, cause, messageKey, code); |
|
55 | 48 |
} |
56 |
|
|
57 |
public OperationException(int operationCode,String operationName,Throwable e) { |
|
58 |
super(MESSAGE, e, MESSAGE_KEY, serialVersionUID); |
|
59 |
this.formatString = FORMAT_STRING; |
|
60 |
this.operationCode=operationCode; |
|
61 |
this.operationName=operationName; |
|
49 |
|
|
50 |
public OperationException(String messageFormat, String messageKey, |
|
51 |
long code) { |
|
52 |
super(messageFormat, messageKey, code); |
|
62 | 53 |
} |
63 |
|
|
54 |
|
|
55 |
public OperationException(Throwable cause) { |
|
56 |
super(MESSAGE_FORMAT, cause, MESSAGE_KEY, serialVersionUID); |
|
57 |
} |
|
58 |
|
|
59 |
protected void setValue(String name, Object value) { |
|
60 |
this.values.put(name, value); |
|
61 |
} |
|
62 |
|
|
64 | 63 |
protected Map values() { |
65 |
Map params = new HashMap(); |
|
66 |
params.put("operationCode",new Integer(this.operationCode)); |
|
67 |
params.put("operationName",this.operationName); |
|
68 |
return params; |
|
64 |
return this.values; |
|
69 | 65 |
} |
70 | 66 |
|
71 | 67 |
} |
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/operations/DefaultOperationManager.java | ||
---|---|---|
1 |
package org.gvsig.tools.operations; |
|
2 |
|
|
3 |
import java.util.HashMap; |
|
4 |
import java.util.Map; |
|
5 |
|
|
6 |
public class DefaultOperationManager implements OperationManager { |
|
7 |
|
|
8 |
private class OperationInfo { |
|
9 |
Class theClass; |
|
10 |
int code; |
|
11 |
Operation operation; |
|
12 |
|
|
13 |
OperationInfo(Class theClass, int code, Operation operation) { |
|
14 |
this.theClass = theClass; |
|
15 |
this.code = code; |
|
16 |
this.operation = operation; |
|
17 |
} |
|
18 |
|
|
19 |
String getKey() { |
|
20 |
return theClass.getName() + ":" + operation.getName(); |
|
21 |
} |
|
22 |
} |
|
23 |
|
|
24 |
private Operation[] operations; |
|
25 |
private Map operationsInfoMap; |
|
26 |
private OperationInfo[] operationsInfo; |
|
27 |
|
|
28 |
public DefaultOperationManager() { |
|
29 |
operationsInfoMap = new HashMap(); |
|
30 |
operations = new Operation[1]; |
|
31 |
} |
|
32 |
|
|
33 |
public int registerOperation(Operation operation, Class theClass) { |
|
34 |
OperationInfo info = new OperationInfo(theClass, 0, operation); |
|
35 |
OperationInfo oldInfo = (OperationInfo) operationsInfoMap.get(info |
|
36 |
.getKey()); |
|
37 |
if (oldInfo != null) { |
|
38 |
// Update the operation |
|
39 |
oldInfo.theClass = theClass; |
|
40 |
oldInfo.operation = operation; |
|
41 |
return oldInfo.code; |
|
42 |
} |
|
43 |
if (operations == null) { |
|
44 |
operations = new Operation[1]; |
|
45 |
operationsInfo = new OperationInfo[1]; |
|
46 |
info.code = 0; |
|
47 |
} else { |
|
48 |
Operation[] temp1 = new Operation[operations.length + 1]; |
|
49 |
System.arraycopy(operations, 0, temp1, 0, operations.length); |
|
50 |
OperationInfo[] temp2 = new OperationInfo[operationsInfo.length + 1]; |
|
51 |
System |
|
52 |
.arraycopy(operationsInfo, 0, temp2, 0, |
|
53 |
operationsInfo.length); |
|
54 |
info.code = operations.length - 1; |
|
55 |
} |
|
56 |
operations[info.code] = info.operation; |
|
57 |
operationsInfo[info.code] = info; |
|
58 |
operationsInfoMap.put(info.getKey(), info); |
|
59 |
return info.code; |
|
60 |
} |
|
61 |
|
|
62 |
private String getKey(Object obj, String name) { |
|
63 |
return obj.getClass().getName() + ":" + name; |
|
64 |
} |
|
65 |
|
|
66 |
private String getKey(Class theClass, String name) { |
|
67 |
return theClass.getName() + ":" + name; |
|
68 |
} |
|
69 |
|
|
70 |
public Operation getOperation(Object obj, String name) |
|
71 |
throws OperationNotSupportedException { |
|
72 |
OperationInfo info = (OperationInfo) operationsInfoMap.get(getKey(obj, |
|
73 |
name)); |
|
74 |
if (info == null) { |
|
75 |
throw new OperationNotSupportedException(obj.getClass(), name); |
|
76 |
} |
|
77 |
return info.operation; |
|
78 |
} |
|
79 |
|
|
80 |
public Operation getOperation(Class theClass, String name) |
|
81 |
throws OperationNotSupportedException { |
|
82 |
OperationInfo info = (OperationInfo) operationsInfoMap.get(getKey( |
|
83 |
theClass, name)); |
|
84 |
if (info == null) { |
|
85 |
throw new OperationNotSupportedException(theClass, name); |
|
86 |
} |
|
87 |
return info.operation; |
|
88 |
} |
|
89 |
|
|
90 |
public Operation getOperation(Object obj, int code) |
|
91 |
throws OperationNotSupportedException { |
|
92 |
if (code >= operationsInfo.length) { |
|
93 |
throw new OperationNotSupportedException(obj.getClass(), code); |
|
94 |
} |
|
95 |
OperationInfo info = operationsInfo[code]; |
|
96 |
if (!info.theClass.isAssignableFrom(obj.getClass())) { |
|
97 |
throw new OperationNotSupportedException(obj.getClass(), code); |
|
98 |
} |
|
99 |
return info.operation; |
|
100 |
} |
|
101 |
|
|
102 |
public Operation getOperation(Class theClass, int code) |
|
103 |
throws OperationNotSupportedException { |
|
104 |
if (code >= operationsInfo.length) { |
|
105 |
throw new OperationNotSupportedException(theClass, code); |
|
106 |
} |
|
107 |
OperationInfo info = operationsInfo[code]; |
|
108 |
if (!info.theClass.isAssignableFrom(theClass)) { |
|
109 |
throw new OperationNotSupportedException(theClass, code); |
|
110 |
} |
|
111 |
return info.operation; |
|
112 |
} |
|
113 |
|
|
114 |
public boolean hasOperation(Object obj, String name) { |
|
115 |
try { |
|
116 |
Operation op = getOperation(obj, name); |
|
117 |
return op != null; |
|
118 |
} catch (OperationNotSupportedException e) { |
|
119 |
return false; |
|
120 |
} |
|
121 |
} |
|
122 |
|
|
123 |
public boolean hasOperation(Object obj, int code) { |
|
124 |
try { |
|
125 |
Operation op = getOperation(obj, code); |
|
126 |
return op != null; |
|
127 |
} catch (OperationNotSupportedException e) { |
|
128 |
return false; |
|
129 |
} |
|
130 |
} |
|
131 |
|
|
132 |
public boolean hasOperation(Class theClass, String name) { |
|
133 |
try { |
|
134 |
Operation op = getOperation(theClass, name); |
|
135 |
return op != null; |
|
136 |
} catch (OperationNotSupportedException e) { |
|
137 |
return false; |
|
138 |
} |
|
139 |
} |
|
140 |
|
|
141 |
public boolean hasOperation(Class theClass, int code) { |
|
142 |
try { |
|
143 |
Operation op = getOperation(theClass, code); |
|
144 |
return op != null; |
|
145 |
} catch (OperationNotSupportedException e) { |
|
146 |
return false; |
|
147 |
} |
|
148 |
} |
|
149 |
|
|
150 |
public Object invokeOperation(Object obj, String name, |
|
151 |
OperationContext context) throws OperationException { |
|
152 |
Operation op = getOperation(obj, name); |
|
153 |
return op.invoke(obj, context); |
|
154 |
} |
|
155 |
|
|
156 |
public Object invokeOperation(Object obj, int code, OperationContext context) |
|
157 |
throws OperationException { |
|
158 |
try { |
|
159 |
/* |
|
160 |
* Intentamos ejecutar la operacion, y si peta ya aremos las |
|
161 |
* comprobaciones oportunas para lanzar la excepcion que toque. |
|
162 |
* |
|
163 |
* Asi evitamos codigo de comprobacion para los casos que valla bien |
|
164 |
* que deberian ser la mayoria. |
|
165 |
*/ |
|
166 |
return operations[code].invoke(obj, context); |
|
167 |
} catch (RuntimeException e) { |
|
168 |
getOperation(obj, code); |
|
169 |
throw e; |
|
170 |
} catch (OperationException e) { |
|
171 |
getOperation(obj, code); |
|
172 |
throw e; |
|
173 |
} |
|
174 |
} |
|
175 |
|
|
176 |
public int getOperationCode(Class theClass, String name) |
|
177 |
throws OperationNotSupportedException { |
|
178 |
OperationInfo info = (OperationInfo) operationsInfoMap.get(getKey( |
|
179 |
theClass, name)); |
|
180 |
if (info == null) { |
|
181 |
throw new OperationNotSupportedException(theClass, name); |
|
182 |
} |
|
183 |
return info.code; |
|
184 |
} |
|
185 |
|
|
186 |
public int registerOperation(Operation operation, Object obj) { |
|
187 |
return registerOperation(operation, obj.getClass()); |
|
188 |
} |
|
189 |
|
|
190 |
|
|
191 |
} |
|
0 | 192 |
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/operations/Operation.java | ||
---|---|---|
1 | 1 |
package org.gvsig.tools.operations; |
2 | 2 |
|
3 |
public abstract class Operation { |
|
3 |
public interface Operation { |
|
4 |
public Object invoke(Object self, OperationContext context) |
|
5 |
throws OperationException; |
|
4 | 6 |
|
5 |
/** |
|
6 |
* Invokes this operation in context ctx |
|
7 |
* @param self the object to which apply this operation |
|
8 |
* @param ctx Parameter container |
|
9 |
* @return Place-holder object that may contain any specific return value. |
|
10 |
* @throws OperationException The implementation is responsible to throw this exception when needed. |
|
11 |
*/ |
|
12 |
public abstract Object invoke(Object self, OperationContext ctx) throws OperationException; |
|
7 |
public String getName(); |
|
13 | 8 |
|
14 |
/** |
|
15 |
* Returns the constant value that identifies this operation and that was obtained upon registering it. |
|
16 |
* @return operation unique index |
|
17 |
*/ |
|
18 |
public abstract int getOperationIndex(); |
|
19 |
|
|
9 |
public String getDescription(); |
|
10 |
|
|
11 |
public int getCode() throws OperationNotSupportedException; |
|
20 | 12 |
} |
21 | 13 |
branches/v2_0_0_prep/libraries/libTools/src/org/gvsig/tools/operations/Operations.java | ||
---|---|---|
1 |
package org.gvsig.tools.operations; |
|
2 |
|
|
3 |
|
|
4 |
public interface Operations { |
|
5 |
|
|
6 |
public Object invokeOperation(int code, OperationContext context) |
|
7 |
throws OperationException, OperationNotSupportedException; |
|
8 |
|
|
9 |
public Object invokeOperation(String name, OperationContext context) |
|
10 |
throws OperationException, OperationNotSupportedException; |
|
11 |
|
|
12 |
|
|
13 |
public Object getOperation(int code) |
Also available in: Unified diff