1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| package org.apache.xindice.core; |
21 |
| |
22 |
| import org.xmldb.api.base.ErrorCodes; |
23 |
| import org.xmldb.api.base.XMLDBException; |
24 |
| |
25 |
| import java.util.HashMap; |
26 |
| import java.util.Map; |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| public abstract class FaultCodes { |
35 |
| |
36 |
| |
37 |
| |
38 |
| |
39 |
| public static final int MAX_CODE = 10000; |
40 |
| |
41 |
| private static final Map faultMessages = new HashMap(); |
42 |
| |
43 |
| private static final Map faultCodesToErrorCodesMap = new HashMap(); |
44 |
| |
45 |
| public static final int GEN = 0; |
46 |
| public static final int OBJ = 100; |
47 |
| public static final int COL = 200; |
48 |
| public static final int IDX = 300; |
49 |
| public static final int TRX = 400; |
50 |
| public static final int DBE = 500; |
51 |
| public static final int QRY = 600; |
52 |
| public static final int SEC = 700; |
53 |
| public static final int URI = 800; |
54 |
| public static final int JAVA = 2000; |
55 |
| |
56 |
| public static final int GEN_UNKNOWN = 0; |
57 |
| public static final int GEN_GENERAL_ERROR = 40; |
58 |
| public static final int GEN_CRITICAL_ERROR = 70; |
59 |
| public static final int GEN_FATAL_ERROR = 90; |
60 |
| |
61 |
| public static final int COL_COLLECTION_NOT_FOUND = 200; |
62 |
| public static final int COL_DOCUMENT_NOT_FOUND = 201; |
63 |
| public static final int COL_DUPLICATE_COLLECTION = 240; |
64 |
| public static final int COL_NULL_RESULT = 241; |
65 |
| public static final int COL_NO_FILER = 242; |
66 |
| public static final int COL_NO_INDEXMANAGER = 242; |
67 |
| public static final int COL_DOCUMENT_MALFORMED = 243; |
68 |
| public static final int COL_CANNOT_STORE = 244; |
69 |
| public static final int COL_CANNOT_RETRIEVE = 245; |
70 |
| public static final int COL_COLLECTION_READ_ONLY = 246; |
71 |
| public static final int COL_COLLECTION_CLOSED = 247; |
72 |
| public static final int COL_DUPLICATE_RESOURCE = 248; |
73 |
| public static final int COL_CANNOT_CREATE = 270; |
74 |
| public static final int COL_CANNOT_DROP = 271; |
75 |
| public static final int COL_INVALID_RESULT = 277; |
76 |
| |
77 |
| public static final int IDX_VALUE_NOT_FOUND = 300; |
78 |
| public static final int IDX_INDEX_NOT_FOUND = 301; |
79 |
| public static final int IDX_MATCHES_NOT_FOUND = 340; |
80 |
| public static final int IDX_DUPLICATE_INDEX = 341; |
81 |
| public static final int IDX_NOT_SUPPORTED = 370; |
82 |
| public static final int IDX_STYLE_NOT_FOUND = 371; |
83 |
| public static final int IDX_CORRUPTED = 372; |
84 |
| public static final int IDX_CANNOT_CREATE = 373; |
85 |
| |
86 |
| public static final int TRX_DOC_LOCKED = 400; |
87 |
| public static final int TRX_NO_CONTEXT = 440; |
88 |
| public static final int TRX_NOT_ACTIVE = 441; |
89 |
| public static final int TRX_NOT_SUPPORTED = 470; |
90 |
| |
91 |
| public static final int DBE_NO_PARENT = 500; |
92 |
| public static final int DBE_CANNOT_DROP = 570; |
93 |
| public static final int DBE_CANNOT_CREATE = 571; |
94 |
| public static final int DBE_CANNOT_READ = 572; |
95 |
| |
96 |
| public static final int QRY_NULL_RESULT = 600; |
97 |
| public static final int QRY_COMPILATION_ERROR = 640; |
98 |
| public static final int QRY_PROCESSING_ERROR = 641; |
99 |
| public static final int QRY_NOT_SUPPORTED = 670; |
100 |
| public static final int QRY_STYLE_NOT_FOUND = 671; |
101 |
| |
102 |
| public static final int SEC_INVALID_USER = 770; |
103 |
| public static final int SEC_INVALID_GROUP = 771; |
104 |
| public static final int SEC_INVALID_ACCESS = 772; |
105 |
| public static final int SEC_INVALID_CREDENTIALS = 773; |
106 |
| |
107 |
| public static final int URI_EMPTY = 800; |
108 |
| public static final int URI_NULL = 801; |
109 |
| public static final int URI_PARSE_ERROR = 820; |
110 |
| |
111 |
| public static final int JAVA_RUNTIME_ERROR = 2070; |
112 |
| |
113 |
| |
114 |
0
| private FaultCodes() {
|
115 |
| } |
116 |
| |
117 |
| static { |
118 |
| |
119 |
3
| putCodeMessage(GEN_UNKNOWN, "Unknown");
|
120 |
3
| putCodeMessage(GEN_GENERAL_ERROR, "General Error");
|
121 |
3
| putCodeMessage(GEN_CRITICAL_ERROR, "Critical Error");
|
122 |
3
| putCodeMessage(GEN_FATAL_ERROR, "Fatal Error");
|
123 |
| |
124 |
3
| addFaultCodeToErrorCodeMap(GEN_UNKNOWN, ErrorCodes.UNKNOWN_ERROR);
|
125 |
3
| addFaultCodeToErrorCodeMap(GEN_GENERAL_ERROR, ErrorCodes.UNKNOWN_ERROR);
|
126 |
3
| addFaultCodeToErrorCodeMap(GEN_CRITICAL_ERROR, ErrorCodes.UNKNOWN_ERROR);
|
127 |
3
| addFaultCodeToErrorCodeMap(GEN_FATAL_ERROR, ErrorCodes.UNKNOWN_ERROR);
|
128 |
| |
129 |
| |
130 |
3
| putCodeMessage(COL_COLLECTION_NOT_FOUND, "Collection Not Found");
|
131 |
3
| putCodeMessage(COL_DOCUMENT_NOT_FOUND, "Collection Document Not Found");
|
132 |
3
| putCodeMessage(COL_DUPLICATE_COLLECTION, "Collection Duplicated");
|
133 |
3
| putCodeMessage(COL_NULL_RESULT, "Collection Null Result");
|
134 |
3
| putCodeMessage(COL_NO_FILER, "Collection No Filer");
|
135 |
3
| putCodeMessage(COL_NO_INDEXMANAGER, "Collection No IndexManager");
|
136 |
3
| putCodeMessage(COL_DOCUMENT_MALFORMED, "Collection Document Malformed");
|
137 |
3
| putCodeMessage(COL_CANNOT_STORE, "Collection Cannot Store");
|
138 |
3
| putCodeMessage(COL_CANNOT_RETRIEVE, "Collection Cannot Retrieve");
|
139 |
3
| putCodeMessage(COL_COLLECTION_READ_ONLY, "Collection Read-only");
|
140 |
3
| putCodeMessage(COL_COLLECTION_CLOSED, "Collection Closed");
|
141 |
3
| putCodeMessage(COL_DUPLICATE_RESOURCE, "Resource Duplicated");
|
142 |
3
| putCodeMessage(COL_CANNOT_CREATE, "Collection Cannot Create");
|
143 |
3
| putCodeMessage(COL_CANNOT_DROP, "Collection Cannot Drop");
|
144 |
3
| putCodeMessage(COL_INVALID_RESULT, "Collection Invalid Result");
|
145 |
| |
146 |
3
| addFaultCodeToErrorCodeMap(COL_COLLECTION_NOT_FOUND, ErrorCodes.NO_SUCH_COLLECTION);
|
147 |
3
| addFaultCodeToErrorCodeMap(COL_DOCUMENT_NOT_FOUND, ErrorCodes.NO_SUCH_RESOURCE);
|
148 |
3
| addFaultCodeToErrorCodeMap(COL_DUPLICATE_COLLECTION, ErrorCodes.INVALID_COLLECTION);
|
149 |
3
| addFaultCodeToErrorCodeMap(COL_NULL_RESULT, ErrorCodes.INVALID_COLLECTION);
|
150 |
3
| addFaultCodeToErrorCodeMap(COL_NO_FILER, ErrorCodes.INVALID_COLLECTION);
|
151 |
3
| addFaultCodeToErrorCodeMap(COL_NO_INDEXMANAGER, ErrorCodes.INVALID_COLLECTION);
|
152 |
3
| addFaultCodeToErrorCodeMap(COL_DOCUMENT_MALFORMED, ErrorCodes.INVALID_RESOURCE);
|
153 |
3
| addFaultCodeToErrorCodeMap(COL_CANNOT_STORE, ErrorCodes.VENDOR_ERROR);
|
154 |
3
| addFaultCodeToErrorCodeMap(COL_CANNOT_RETRIEVE, ErrorCodes.VENDOR_ERROR);
|
155 |
3
| addFaultCodeToErrorCodeMap(COL_COLLECTION_READ_ONLY, ErrorCodes.VENDOR_ERROR);
|
156 |
3
| addFaultCodeToErrorCodeMap(COL_COLLECTION_CLOSED, ErrorCodes.COLLECTION_CLOSED);
|
157 |
3
| addFaultCodeToErrorCodeMap(COL_CANNOT_CREATE, ErrorCodes.VENDOR_ERROR);
|
158 |
3
| addFaultCodeToErrorCodeMap(COL_CANNOT_DROP, ErrorCodes.VENDOR_ERROR);
|
159 |
3
| addFaultCodeToErrorCodeMap(COL_INVALID_RESULT, ErrorCodes.VENDOR_ERROR);
|
160 |
| |
161 |
| |
162 |
3
| putCodeMessage(IDX_VALUE_NOT_FOUND, "Index Value Not Found");
|
163 |
3
| putCodeMessage(IDX_INDEX_NOT_FOUND, "Index Not Found");
|
164 |
3
| putCodeMessage(IDX_MATCHES_NOT_FOUND, "Index Matches Not Found");
|
165 |
3
| putCodeMessage(IDX_DUPLICATE_INDEX, "Index Duplicate Index");
|
166 |
3
| putCodeMessage(IDX_NOT_SUPPORTED, "Index Not Supported");
|
167 |
3
| putCodeMessage(IDX_STYLE_NOT_FOUND, "Index Style Not Found");
|
168 |
3
| putCodeMessage(IDX_CORRUPTED, "Index Corrupted");
|
169 |
3
| putCodeMessage(IDX_CANNOT_CREATE, "Index Cannot Create");
|
170 |
| |
171 |
3
| addFaultCodeToErrorCodeMap(IDX_VALUE_NOT_FOUND, ErrorCodes.INVALID_RESOURCE);
|
172 |
3
| addFaultCodeToErrorCodeMap(IDX_INDEX_NOT_FOUND, ErrorCodes.NO_SUCH_RESOURCE);
|
173 |
3
| addFaultCodeToErrorCodeMap(IDX_MATCHES_NOT_FOUND, ErrorCodes.VENDOR_ERROR);
|
174 |
3
| addFaultCodeToErrorCodeMap(IDX_DUPLICATE_INDEX, ErrorCodes.INVALID_RESOURCE);
|
175 |
3
| addFaultCodeToErrorCodeMap(IDX_NOT_SUPPORTED, ErrorCodes.NOT_IMPLEMENTED);
|
176 |
3
| addFaultCodeToErrorCodeMap(IDX_STYLE_NOT_FOUND, ErrorCodes.NO_SUCH_RESOURCE);
|
177 |
3
| addFaultCodeToErrorCodeMap(IDX_CORRUPTED, ErrorCodes.INVALID_RESOURCE);
|
178 |
3
| addFaultCodeToErrorCodeMap(IDX_CANNOT_CREATE, ErrorCodes.VENDOR_ERROR);
|
179 |
| |
180 |
| |
181 |
3
| putCodeMessage(TRX_DOC_LOCKED, "Transaction Document Locked");
|
182 |
3
| putCodeMessage(TRX_NO_CONTEXT, "Transaction No Context");
|
183 |
3
| putCodeMessage(TRX_NOT_ACTIVE, "Transaction Not Active");
|
184 |
3
| putCodeMessage(TRX_NOT_SUPPORTED, "Transaction Not Supported");
|
185 |
| |
186 |
3
| addFaultCodeToErrorCodeMap(TRX_DOC_LOCKED, ErrorCodes.VENDOR_ERROR);
|
187 |
3
| addFaultCodeToErrorCodeMap(TRX_NO_CONTEXT, ErrorCodes.INVALID_RESOURCE);
|
188 |
3
| addFaultCodeToErrorCodeMap(TRX_NOT_ACTIVE, ErrorCodes.VENDOR_ERROR);
|
189 |
3
| addFaultCodeToErrorCodeMap(TRX_NOT_SUPPORTED, ErrorCodes.VENDOR_ERROR);
|
190 |
| |
191 |
| |
192 |
3
| putCodeMessage(DBE_NO_PARENT, "Database No Parent");
|
193 |
3
| putCodeMessage(DBE_CANNOT_DROP, "Database Cannot Drop");
|
194 |
3
| putCodeMessage(DBE_CANNOT_CREATE, "Database Cannot Create");
|
195 |
3
| putCodeMessage(DBE_CANNOT_READ, "Database Cannot Read");
|
196 |
| |
197 |
3
| addFaultCodeToErrorCodeMap(DBE_NO_PARENT, ErrorCodes.INVALID_DATABASE);
|
198 |
3
| addFaultCodeToErrorCodeMap(DBE_CANNOT_DROP, ErrorCodes.VENDOR_ERROR);
|
199 |
3
| addFaultCodeToErrorCodeMap(DBE_CANNOT_CREATE, ErrorCodes.VENDOR_ERROR);
|
200 |
3
| addFaultCodeToErrorCodeMap(DBE_CANNOT_READ, ErrorCodes.VENDOR_ERROR);
|
201 |
| |
202 |
| |
203 |
3
| putCodeMessage(QRY_NULL_RESULT, "Query Null Result");
|
204 |
3
| putCodeMessage(QRY_COMPILATION_ERROR, "Query Compilation Error");
|
205 |
3
| putCodeMessage(QRY_PROCESSING_ERROR, "Query Processing Error");
|
206 |
3
| putCodeMessage(QRY_NOT_SUPPORTED, "Query Not Supported");
|
207 |
3
| putCodeMessage(QRY_STYLE_NOT_FOUND, "Query Style Not Found");
|
208 |
| |
209 |
3
| addFaultCodeToErrorCodeMap(QRY_NULL_RESULT, ErrorCodes.VENDOR_ERROR);
|
210 |
3
| addFaultCodeToErrorCodeMap(QRY_COMPILATION_ERROR, ErrorCodes.VENDOR_ERROR);
|
211 |
3
| addFaultCodeToErrorCodeMap(QRY_PROCESSING_ERROR, ErrorCodes.VENDOR_ERROR);
|
212 |
3
| addFaultCodeToErrorCodeMap(QRY_NOT_SUPPORTED, ErrorCodes.VENDOR_ERROR);
|
213 |
3
| addFaultCodeToErrorCodeMap(QRY_STYLE_NOT_FOUND, ErrorCodes.VENDOR_ERROR);
|
214 |
| |
215 |
| |
216 |
3
| putCodeMessage(SEC_INVALID_USER, "Security Invalid User");
|
217 |
3
| putCodeMessage(SEC_INVALID_GROUP, "Security Invalid Group");
|
218 |
3
| putCodeMessage(SEC_INVALID_ACCESS, "Security Invalid Access");
|
219 |
3
| putCodeMessage(SEC_INVALID_CREDENTIALS, "Security Invalid Credentials");
|
220 |
| |
221 |
3
| addFaultCodeToErrorCodeMap(SEC_INVALID_USER, ErrorCodes.PERMISSION_DENIED);
|
222 |
3
| addFaultCodeToErrorCodeMap(SEC_INVALID_GROUP, ErrorCodes.PERMISSION_DENIED);
|
223 |
3
| addFaultCodeToErrorCodeMap(SEC_INVALID_ACCESS, ErrorCodes.PERMISSION_DENIED);
|
224 |
3
| addFaultCodeToErrorCodeMap(SEC_INVALID_CREDENTIALS, ErrorCodes.PERMISSION_DENIED);
|
225 |
| |
226 |
| |
227 |
3
| putCodeMessage(URI_EMPTY, "URI Empty");
|
228 |
3
| putCodeMessage(URI_NULL, "URI Null");
|
229 |
3
| putCodeMessage(URI_PARSE_ERROR, "URI Parse Error");
|
230 |
| |
231 |
3
| addFaultCodeToErrorCodeMap(URI_EMPTY, ErrorCodes.INVALID_URI);
|
232 |
3
| addFaultCodeToErrorCodeMap(URI_NULL, ErrorCodes.INVALID_URI);
|
233 |
3
| addFaultCodeToErrorCodeMap(URI_PARSE_ERROR, ErrorCodes.INVALID_URI);
|
234 |
| |
235 |
| |
236 |
3
| putCodeMessage(JAVA_RUNTIME_ERROR, "Java Runtime Error");
|
237 |
| } |
238 |
| |
239 |
144
| private static void putCodeMessage(int code, String message) {
|
240 |
144
| faultMessages.put(new Integer(code), message);
|
241 |
| } |
242 |
| |
243 |
138
| private static void addFaultCodeToErrorCodeMap(int code, int errCode) {
|
244 |
138
| faultCodesToErrorCodesMap.put(new Integer(code), new Integer(errCode));
|
245 |
| } |
246 |
| |
247 |
| |
248 |
| |
249 |
| |
250 |
| |
251 |
| |
252 |
| |
253 |
| |
254 |
0
| public static int getErrorCode(int faultCode) {
|
255 |
0
| Object err = faultCodesToErrorCodesMap.get(new Integer(faultCode));
|
256 |
0
| if (err == null) {
|
257 |
0
| return ErrorCodes.UNKNOWN_ERROR;
|
258 |
| } else { |
259 |
0
| return ((Integer) err).intValue();
|
260 |
| } |
261 |
| } |
262 |
| |
263 |
| |
264 |
| |
265 |
| |
266 |
| |
267 |
| |
268 |
| |
269 |
0
| public static String getMessage(int code) {
|
270 |
0
| String msg = (String) faultMessages.get(new Integer(code));
|
271 |
0
| return msg != null ? msg : "";
|
272 |
| } |
273 |
| |
274 |
| |
275 |
| |
276 |
| |
277 |
| |
278 |
| |
279 |
| |
280 |
| |
281 |
| |
282 |
| |
283 |
42
| public static XMLDBException createXMLDBException(Exception e) {
|
284 |
42
| return createXMLDBException(null, e);
|
285 |
| } |
286 |
| |
287 |
| |
288 |
| |
289 |
| |
290 |
| |
291 |
| |
292 |
| |
293 |
| |
294 |
| |
295 |
| |
296 |
| |
297 |
42
| public static XMLDBException createXMLDBException(String message, Exception e) {
|
298 |
| |
299 |
42
| int faultCode = e instanceof RuntimeException ? JAVA_RUNTIME_ERROR : GEN_UNKNOWN;
|
300 |
42
| return createXMLDBException(faultCode, message, e);
|
301 |
| } |
302 |
| |
303 |
46
| public static XMLDBException createXMLDBException(int faultCode, String message, Exception e) {
|
304 |
46
| return createXMLDBException(ErrorCodes.VENDOR_ERROR, faultCode, message, e);
|
305 |
| } |
306 |
| |
307 |
| |
308 |
| |
309 |
| |
310 |
| |
311 |
| |
312 |
| |
313 |
| |
314 |
| |
315 |
| |
316 |
| |
317 |
| |
318 |
| |
319 |
| |
320 |
| |
321 |
| |
322 |
| |
323 |
| |
324 |
58
| public static XMLDBException createXMLDBException(int errorCode, int faultCode, String message, Exception e) {
|
325 |
58
| if (e instanceof XMLDBException) {
|
326 |
27
| return (XMLDBException) e;
|
327 |
| } |
328 |
| |
329 |
31
| if (e instanceof DBException) {
|
330 |
28
| faultCode = ((DBException) e).faultCode;
|
331 |
| } |
332 |
| |
333 |
31
| if (message == null) {
|
334 |
15
| message = e.getMessage();
|
335 |
| } else { |
336 |
16
| message += ": " + e.getMessage();
|
337 |
| } |
338 |
| |
339 |
| |
340 |
| |
341 |
31
| return new XMLDBException(errorCode, faultCode, message, e);
|
342 |
| } |
343 |
| |
344 |
| |
345 |
| |
346 |
| |
347 |
| |
348 |
| |
349 |
| |
350 |
| |
351 |
| |
352 |
| |
353 |
0
| public static int getFaultCodeType(Exception e) {
|
354 |
0
| int code = 0;
|
355 |
0
| if (e instanceof DBException) {
|
356 |
0
| code = ((DBException) e).faultCode;
|
357 |
| } |
358 |
| |
359 |
| |
360 |
0
| code = code % 100;
|
361 |
| |
362 |
0
| code = code - (code % 10);
|
363 |
0
| return code;
|
364 |
| } |
365 |
| |
366 |
| |
367 |
| |
368 |
| |
369 |
| |
370 |
| |
371 |
| |
372 |
| |
373 |
| |
374 |
| |
375 |
0
| public static int getFaultCodeSeries(Exception e) {
|
376 |
0
| int code = 0;
|
377 |
0
| if (e instanceof DBException) {
|
378 |
0
| code = ((DBException) e).faultCode;
|
379 |
| } |
380 |
| |
381 |
| |
382 |
0
| code = code - (code % 100);
|
383 |
0
| return code;
|
384 |
| } |
385 |
| |
386 |
| |
387 |
| |
388 |
| |
389 |
| |
390 |
| |
391 |
| |
392 |
| |
393 |
0
| public static int getFaultCode(Exception e) {
|
394 |
0
| if (e instanceof DBException) {
|
395 |
0
| return ((DBException) e).faultCode;
|
396 |
| } else { |
397 |
0
| return 0;
|
398 |
| } |
399 |
| } |
400 |
| |
401 |
| |
402 |
| |
403 |
| |
404 |
| |
405 |
| |
406 |
| |
407 |
| |
408 |
0
| public static String getFaultMessage(Exception e) {
|
409 |
0
| return getMessage(getFaultCode(e));
|
410 |
| } |
411 |
| } |