1 | /** |
---|
2 | * This software is copyright (c) 2011-2013 by |
---|
3 | * - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de) |
---|
4 | * This is free software. You can redistribute it |
---|
5 | * and/or modify it under the terms described in |
---|
6 | * the GNU General Public License v3 of which you |
---|
7 | * should have received a copy. Otherwise you can download |
---|
8 | * it from |
---|
9 | * |
---|
10 | * http://www.gnu.org/licenses/gpl-3.0.txt |
---|
11 | * |
---|
12 | * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de) |
---|
13 | * |
---|
14 | * @license http://www.gnu.org/licenses/gpl-3.0.txt |
---|
15 | * GNU General Public License v3 |
---|
16 | */ |
---|
17 | package eu.clarin.sru.server; |
---|
18 | |
---|
19 | /** |
---|
20 | * An exception raised if something went wrong processing the request. For |
---|
21 | * diagnostic codes, see constants in {@link SRUConstants}. |
---|
22 | * |
---|
23 | * @see SRUConstants |
---|
24 | */ |
---|
25 | @SuppressWarnings("serial") |
---|
26 | public class SRUException extends Exception { |
---|
27 | private final int code; |
---|
28 | private final String details; |
---|
29 | |
---|
30 | |
---|
31 | /** |
---|
32 | * Constructor. |
---|
33 | * |
---|
34 | * @param code |
---|
35 | * the diagnostic code |
---|
36 | * @param details |
---|
37 | * diagnostic details or <code>null</code> |
---|
38 | * @param message |
---|
39 | * diagnostic message or <code>null</code> |
---|
40 | * @param cause |
---|
41 | * the cause of the error or <code>null</code> |
---|
42 | */ |
---|
43 | public SRUException(int code, String details, String message, |
---|
44 | Throwable cause) { |
---|
45 | super(message, cause); |
---|
46 | this.code = code; |
---|
47 | this.details = details; |
---|
48 | } |
---|
49 | |
---|
50 | |
---|
51 | /** |
---|
52 | * Constructor. |
---|
53 | * |
---|
54 | * @param code |
---|
55 | * the diagnostic code |
---|
56 | * @param details |
---|
57 | * diagnostic details or <code>null</code> |
---|
58 | * @param message |
---|
59 | * diagnostic message or <code>null</code> |
---|
60 | */ |
---|
61 | public SRUException(int code, String details, String message) { |
---|
62 | this(code, details, message, null); |
---|
63 | } |
---|
64 | |
---|
65 | |
---|
66 | /** |
---|
67 | * Constructor. |
---|
68 | * |
---|
69 | * @param code |
---|
70 | * the diagnostic code |
---|
71 | * @param message |
---|
72 | * diagnostic message or <code>null</code> |
---|
73 | * @param cause |
---|
74 | * the cause of the error or <code>null</code> |
---|
75 | */ |
---|
76 | public SRUException(int code, String message, Throwable cause) { |
---|
77 | this(code, null, message, cause); |
---|
78 | } |
---|
79 | |
---|
80 | |
---|
81 | /** |
---|
82 | * Constructor. |
---|
83 | * |
---|
84 | * @param code |
---|
85 | * the diagnostic code |
---|
86 | * @param message |
---|
87 | * diagnostic message or <code>null</code> |
---|
88 | */ |
---|
89 | public SRUException(int code, String message) { |
---|
90 | this(code, null, message, null); |
---|
91 | } |
---|
92 | |
---|
93 | |
---|
94 | /** |
---|
95 | * Constructor. |
---|
96 | * |
---|
97 | * @param code |
---|
98 | * the diagnostic code |
---|
99 | * @param cause |
---|
100 | * the cause of the error or <code>null</code> |
---|
101 | */ |
---|
102 | public SRUException(int code, Throwable cause) { |
---|
103 | this(code, null, null, cause); |
---|
104 | } |
---|
105 | |
---|
106 | |
---|
107 | /** |
---|
108 | * Constructor. |
---|
109 | * |
---|
110 | * @param code |
---|
111 | * the diagnostic code |
---|
112 | */ |
---|
113 | public SRUException(int code) { |
---|
114 | this(code, null, null, null); |
---|
115 | } |
---|
116 | |
---|
117 | |
---|
118 | /** |
---|
119 | * Create a SRU diagnostic from this exception. |
---|
120 | * |
---|
121 | * @return a {@link SRUDiagnostic} instance |
---|
122 | */ |
---|
123 | public SRUDiagnostic getDiagnostic() { |
---|
124 | return new SRUDiagnostic(code, details, this.getMessage()); |
---|
125 | } |
---|
126 | |
---|
127 | } // class SRUException |
---|