1 | /** |
---|
2 | * This software is copyright (c) 2011-2016 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 String uri; |
---|
28 | private final String details; |
---|
29 | |
---|
30 | |
---|
31 | /** |
---|
32 | * Constructor. |
---|
33 | * |
---|
34 | * @param uri |
---|
35 | * the diagnostic's identifying URI |
---|
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(String uri, String details, String message, |
---|
44 | Throwable cause) { |
---|
45 | super(message, cause); |
---|
46 | if (uri == null) { |
---|
47 | throw new NullPointerException("uri == null"); |
---|
48 | } |
---|
49 | uri = uri.trim(); |
---|
50 | if (uri.isEmpty()) { |
---|
51 | throw new IllegalArgumentException("uri is empty"); |
---|
52 | } |
---|
53 | this.uri = uri; |
---|
54 | this.details = details; |
---|
55 | } |
---|
56 | |
---|
57 | |
---|
58 | /** |
---|
59 | * Constructor. |
---|
60 | * |
---|
61 | * @param uri |
---|
62 | * the diagnostic's identifying URI |
---|
63 | * @param details |
---|
64 | * diagnostic details or <code>null</code> |
---|
65 | * @param message |
---|
66 | * diagnostic message or <code>null</code> |
---|
67 | */ |
---|
68 | public SRUException(String uri, String details, String message) { |
---|
69 | this(uri, details, message, null); |
---|
70 | } |
---|
71 | |
---|
72 | |
---|
73 | /** |
---|
74 | * Constructor. |
---|
75 | * |
---|
76 | * @param uri |
---|
77 | * the diagnostic's identifying URI |
---|
78 | * @param message |
---|
79 | * diagnostic message or <code>null</code> |
---|
80 | * @param cause |
---|
81 | * the cause of the error or <code>null</code> |
---|
82 | */ |
---|
83 | public SRUException(String uri, String message, Throwable cause) { |
---|
84 | this(uri, null, message, cause); |
---|
85 | } |
---|
86 | |
---|
87 | |
---|
88 | /** |
---|
89 | * Constructor. |
---|
90 | * |
---|
91 | * @param uri |
---|
92 | * the diagnostic's identifying URI |
---|
93 | * @param message |
---|
94 | * diagnostic message or <code>null</code> |
---|
95 | */ |
---|
96 | public SRUException(String uri, String message) { |
---|
97 | this(uri, null, message, null); |
---|
98 | } |
---|
99 | |
---|
100 | |
---|
101 | /** |
---|
102 | * Constructor. |
---|
103 | * |
---|
104 | * @param uri |
---|
105 | * the diagnostic's identifying URI |
---|
106 | * @param cause |
---|
107 | * the cause of the error or <code>null</code> |
---|
108 | */ |
---|
109 | public SRUException(String uri, Throwable cause) { |
---|
110 | this(uri, null, null, cause); |
---|
111 | } |
---|
112 | |
---|
113 | |
---|
114 | /** |
---|
115 | * Constructor. |
---|
116 | * |
---|
117 | * @param uri |
---|
118 | * the diagnostic's identifying URI |
---|
119 | */ |
---|
120 | public SRUException(String uri) { |
---|
121 | this(uri, null, null, null); |
---|
122 | } |
---|
123 | |
---|
124 | |
---|
125 | /** |
---|
126 | * Create a SRU diagnostic from this exception. |
---|
127 | * |
---|
128 | * @return a {@link SRUDiagnostic} instance |
---|
129 | */ |
---|
130 | public SRUDiagnostic getDiagnostic() { |
---|
131 | return new SRUDiagnostic(uri, details, this.getMessage()); |
---|
132 | } |
---|
133 | |
---|
134 | } // class SRUException |
---|