source: SRUServer/trunk/src/main/java/eu/clarin/sru/server/SRUDiagnostic.java @ 6816

Last change on this file since 6816 was 6816, checked in by Oliver Schonefeld, 9 years ago
  • first step towards SRU 2.0 argument parsing and response serialization
  • Property svn:eol-style set to native
File size: 15.1 KB
Line 
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 */
17package eu.clarin.sru.server;
18
19/**
20 * Class to hold a SRU diagnostic.
21 *
22 * @see SRUConstants
23 * @see SRUDiagnosticList
24 * @see <a href="http://www.loc.gov/standards/sru/specs/diagnostics.html">SRU
25 *      Diagnostics</a>
26 * @see <a href="http://www.loc.gov/standards/sru/resources/diagnostics-list.html">SRU
27 *      Diagnostics List</a>
28 */
29public final class SRUDiagnostic {
30    private final String uri;
31    private final String details;
32    private final String message;
33
34
35    /**
36     * Constructor.
37     *
38     * @param uri
39     *            the diagnostic's identifying URI
40     * @param details
41     *            supplementary information available, often in a format
42     *            specified by the diagnostic or <code>null</code>
43     * @param message
44     *            human readable message to display to the end user or
45     *            <code>null</code>
46     * @throws NullPointerException
47     *             if uri is <code>null</code>
48     * @throws IllegalArgumentException
49     *             if uri is empty string
50     */
51    public SRUDiagnostic(String uri, String details, String message) {
52        if (uri == null) {
53            throw new NullPointerException("uri == null");
54        }
55        uri = uri.trim();
56        if (uri.isEmpty()) {
57            throw new IllegalArgumentException("uri is empty");
58        }
59        this.uri     = uri;
60        if (details != null) {
61            details = details.trim();
62            if (details.isEmpty()) {
63                details = null;
64            }
65        }
66        this.details = details;
67        if (message != null) {
68            message = message.trim();
69            if (message.isEmpty()) {
70                message = null;
71            }
72        }
73        this.message = message;
74    }
75
76
77    /**
78     * Constructor.
79     *
80     * @param uri
81     *            the diagnostic's identifying URI
82     * @param details
83     *            supplementary information available, often in a format
84     *            specified by the diagnostic or <code>null</code>
85     */
86    public SRUDiagnostic(String uri, String details) {
87        this(uri, details, null);
88    }
89
90
91    /**
92     * Constructor.
93     *
94     * @param uri
95     *            the diagnostic's identifying URI
96     */
97    public SRUDiagnostic(String uri) {
98        this(uri, null, null);
99    }
100
101
102    /**
103     * Get code for this diagnostic.
104     *
105     * @return diagnostic code
106     * @see SRUConstants
107     */
108    public String getURI() {
109        return uri;
110    }
111
112
113    /**
114     * Get supplementary information for this diagnostic. The format for this
115     * value is often specified by the diagnostic code.
116     *
117     * @return supplementary information
118     */
119    public String getDetails() {
120        return details;
121    }
122
123
124    /**
125     * Get human readable message.
126     *
127     * @return human readable message
128     */
129    public String getMessage() {
130        return message != null ? message : getDefaultErrorMessage(uri);
131    }
132
133
134    private static String getDefaultErrorMessage(final String uri) {
135        /*
136         * Ugly, but can't do better unless we drop JDK 1.6 compatibility.
137         * (JDK 1.7+ has switch on String)
138         */
139        if (uri.equals(SRUConstants.SRU_GENERAL_SYSTEM_ERROR)) {
140            return "General system error";
141        } else if (uri.equals(SRUConstants.SRU_SYSTEM_TEMPORARILY_UNAVAILABLE)) {
142            return "System temporarily unavailable";
143        } else if (uri.equals(SRUConstants.SRU_AUTHENTICATION_ERROR)) {
144            return "Authentication error";
145        } else if (uri.equals(SRUConstants.SRU_UNSUPPORTED_OPERATION)) {
146            return "Unsupported operation";
147        } else if (uri.equals(SRUConstants.SRU_UNSUPPORTED_VERSION)) {
148            return "Unsupported version";
149        } else if (uri.equals(SRUConstants.SRU_UNSUPPORTED_PARAMETER_VALUE)) {
150            return "Unsupported parameter value";
151        } else if (uri.equals(SRUConstants.SRU_MANDATORY_PARAMETER_NOT_SUPPLIED)) {
152            return "Mandatory parameter not supplied";
153        } else if (uri.equals(SRUConstants.SRU_UNSUPPORTED_PARAMETER)) {
154            return "Unsupported Parameter";
155        } else if (uri.equals(SRUConstants.SRU_QUERY_SYNTAX_ERROR)) {
156            return "Query syntax error";
157        } else if (uri.equals(SRUConstants.SRU_TOO_MANY_CHARACTERS_IN_QUERY)) {
158            return "Too many characters in query";
159        } else if (uri.equals(SRUConstants.SRU_INVALID_OR_UNSUPPORTED_USE_OF_PARENTHESES)) {
160            return "Invalid or unsupported use of parentheses";
161        } else if (uri.equals(SRUConstants.SRU_INVALID_OR_UNSUPPORTED_USE_OF_QUOTES)) {
162            return "Invalid or unsupported use of quotes";
163        } else if (uri.equals(SRUConstants.SRU_UNSUPPORTED_CONTEXT_SET)) {
164            return "Unsupported context set";
165        } else if (uri.equals(SRUConstants.SRU_UNSUPPORTED_INDEX)) {
166            return "Unsupported index";
167        } else if (uri.equals(SRUConstants.SRU_UNSUPPORTED_COMBINATION_OF_INDEXES)) {
168            return "Unsupported combination of indexes";
169        } else if (uri.equals(SRUConstants.SRU_UNSUPPORTED_RELATION)) {
170            return "Unsupported relation";
171        } else if (uri.equals(SRUConstants.SRU_UNSUPPORTED_RELATION_MODIFIER)) {
172            return "Unsupported relation modifier";
173        } else if (uri.equals(SRUConstants.SRU_UNSUPPORTED_COMBINATION_OF_RELATION_MODIFERS)) {
174            return "Unsupported combination of relation modifers";
175        } else if (uri.equals(SRUConstants.SRU_UNSUPPORTED_COMBINATION_OF_RELATION_AND_INDEX)) {
176            return "Unsupported combination of relation and index";
177        } else if (uri.equals(SRUConstants.SRU_TOO_MANY_CHARACTERS_IN_TERM)) {
178            return "Too many characters in term";
179        } else if (uri.equals(SRUConstants.SRU_UNSUPPORTED_COMBINATION_OF_RELATION_AND_TERM)) {
180            return "Unsupported combination of relation and term";
181        } else if (uri.equals(SRUConstants.SRU_NON_SPECIAL_CHARACTER_ESCAPED_IN_TERM)) {
182            return "Non special character escaped in term";
183        } else if (uri.equals(SRUConstants.SRU_EMPTY_TERM_UNSUPPORTED)) {
184            return "Empty term unsupported";
185        } else if (uri.equals(SRUConstants.SRU_MASKING_CHARACTER_NOT_SUPPORTED)) {
186            return "Masking character not supported";
187        } else if (uri.equals(SRUConstants.SRU_MASKED_WORDS_TOO_SHORT)) {
188            return "Masked words too short";
189        } else if (uri.equals(SRUConstants.SRU_TOO_MANY_MASKING_CHARACTERS_IN_TERM)) {
190            return "Too many masking characters in term";
191        } else if (uri.equals(SRUConstants.SRU_ANCHORING_CHARACTER_NOT_SUPPORTED)) {
192            return "Anchoring character not supported";
193        } else if (uri.equals(SRUConstants.SRU_ANCHORING_CHARACTER_IN_UNSUPPORTED_POSITION)) {
194            return "Anchoring character in unsupported position";
195        } else if (uri.equals(SRUConstants.SRU_COMBINATION_OF_PROXIMITY_ADJACENCY_AND_MASKING_CHARACTERS_NOT_SUPPORTED)) {
196            return "Combination of proximity adjacency and masking characters not supported";
197        } else if (uri.equals(SRUConstants.SRU_COMBINATION_OF_PROXIMITY_ADJACENCY_AND_ANCHORING_CHARACTERS_NOT_SUPPORTED)) {
198            return "Combination of proximity adjacency and anchoring characters not supported";
199        } else if (uri.equals(SRUConstants.SRU_TERM_CONTAINS_ONLY_STOPWORDS)) {
200            return "Term contains only stopwords";
201        } else if (uri.equals(SRUConstants.SRU_TERM_IN_INVALID_FORMAT_FOR_INDEX_OR_RELATION)) {
202            return "Term in invalid format for index or relation";
203        } else if (uri.equals(SRUConstants.SRU_UNSUPPORTED_BOOLEAN_OPERATOR)) {
204            return "Unsupported boolean operator";
205        } else if (uri.equals(SRUConstants.SRU_TOO_MANY_BOOLEAN_OPERATORS_IN_QUERY)) {
206            return "Too many boolean operators in query";
207        } else if (uri.equals(SRUConstants.SRU_PROXIMITY_NOT_SUPPORTED)) {
208            return "Proximity not supported";
209        } else if (uri.equals(SRUConstants.SRU_UNSUPPORTED_PROXIMITY_RELATION)) {
210            return "Unsupported proximity relation";
211        } else if (uri.equals(SRUConstants.SRU_UNSUPPORTED_PROXIMITY_DISTANCE)) {
212            return "Unsupported proximity distance";
213        } else if (uri.equals(SRUConstants.SRU_UNSUPPORTED_PROXIMITY_UNIT)) {
214            return "Unsupported proximity unit";
215        } else if (uri.equals(SRUConstants.SRU_UNSUPPORTED_PROXIMITY_ORDERING)) {
216            return "Unsupported proximity ordering";
217        } else if (uri.equals(SRUConstants.SRU_UNSUPPORTED_COMBINATION_OF_PROXIMITY_MODIFIERS)) {
218            return "Unsupported combination of proximity modifiers";
219        } else if (uri.equals(SRUConstants.SRU_UNSUPPORTED_BOOLEAN_MODIFIER)) {
220            return "Unsupported boolean modifier";
221        } else if (uri.equals(SRUConstants.SRU_CANNOT_PROCESS_QUERY_REASON_UNKNOWN)) {
222            return "Cannot process query; reason unknown";
223        } else if (uri.equals(SRUConstants.SRU_QUERY_FEATURE_UNSUPPORTED)) {
224            return "Query feature unsupported";
225        } else if (uri.equals(SRUConstants.SRU_MASKING_CHARACTER_IN_UNSUPPORTED_POSITION)) {
226            return "Masking character in unsupported position";
227        } else if (uri.equals(SRUConstants.SRU_RESULT_SETS_NOT_SUPPORTED)) {
228            return "Result sets not supported";
229        } else if (uri.equals(SRUConstants.SRU_RESULT_SET_DOES_NOT_EXIST)) {
230            return "Result set does not exist";
231        } else if (uri.equals(SRUConstants.SRU_RESULT_SET_TEMPORARILY_UNAVAILABLE)) {
232            return "Result set temporarily unavailable";
233        } else if (uri.equals(SRUConstants.SRU_RESULT_SETS_ONLY_SUPPORTED_FOR_RETRIEVAL)) {
234            return "Result sets only supported for retrieval";
235        } else if (uri.equals(SRUConstants.SRU_COMBINATION_OF_RESULT_SETS_WITH_SEARCH_TERMS_NOT_SUPPORTED)) {
236            return "Combination of result sets with search terms not supported";
237        } else if (uri.equals(SRUConstants.SRU_RESULT_SET_CREATED_WITH_UNPREDICTABLE_PARTIAL_RESULTS_AVAILABLE)) {
238            return "Result set created with unpredictable partial results available";
239        } else if (uri.equals(SRUConstants.SRU_RESULT_SET_CREATED_WITH_VALID_PARTIAL_RESULTS_AVAILABLE)) {
240            return "Result set created with valid partial results available";
241        } else if (uri.equals(SRUConstants.SRU_RESULT_SET_NOT_CREATED_TOO_MANY_MATCHING_RECORDS)) {
242            return "Result set not created)) { too many matching records";
243        } else if (uri.equals(SRUConstants.SRU_FIRST_RECORD_POSITION_OUT_OF_RANGE)) {
244            return "First record position out of range";
245        } else if (uri.equals(SRUConstants.SRU_RECORD_TEMPORARILY_UNAVAILABLE)) {
246            return "Record temporarily unavailable";
247        } else if (uri.equals(SRUConstants.SRU_RECORD_DOES_NOT_EXIST)) {
248            return "Record does not exist";
249        } else if (uri.equals(SRUConstants.SRU_UNKNOWN_SCHEMA_FOR_RETRIEVAL)) {
250            return "Unknown schema for retrieval";
251        } else if (uri.equals(SRUConstants.SRU_RECORD_NOT_AVAILABLE_IN_THIS_SCHEMA)) {
252            return "Record not available in this schema";
253        } else if (uri.equals(SRUConstants.SRU_NOT_AUTHORISED_TO_SEND_RECORD)) {
254            return "Not authorised to send record";
255        } else if (uri.equals(SRUConstants.SRU_NOT_AUTHORISED_TO_SEND_RECORD_IN_THIS_SCHEMA)) {
256            return "Not authorised to send record in this schema";
257        } else if (uri.equals(SRUConstants.SRU_RECORD_TOO_LARGE_TO_SEND)) {
258            return "Record too large to send";
259        } else if (uri.equals(SRUConstants.SRU_UNSUPPORTED_XML_ESCAPING_VALUE)) {
260            return "Unsupported record packing";
261        } else if (uri.equals(SRUConstants.SRU_XPATH_RETRIEVAL_UNSUPPORTED)) {
262            return "XPath retrieval unsupported";
263        } else if (uri.equals(SRUConstants.SRU_XPATH_EXPRESSION_CONTAINS_UNSUPPORTED_FEATURE)) {
264            return "XPath expression contains unsupported feature";
265        } else if (uri.equals(SRUConstants.SRU_UNABLE_TO_EVALUATE_XPATH_EXPRESSION)) {
266            return "Unable to evaluate XPath expression";
267        } else if (uri.equals(SRUConstants.SRU_SORT_NOT_SUPPORTED)) {
268            return "Sort not supported";
269        } else if (uri.equals(SRUConstants.SRU_UNSUPPORTED_SORT_SEQUENCE)) {
270            return "Unsupported sort sequence";
271        } else if (uri.equals(SRUConstants.SRU_TOO_MANY_RECORDS_TO_SORT)) {
272            return "Too many records to sort";
273        } else if (uri.equals(SRUConstants.SRU_TOO_MANY_SORT_KEYS_TO_SORT)) {
274            return "Too many sort keys to sort";
275        } else if (uri.equals(SRUConstants.SRU_CANNOT_SORT_INCOMPATIBLE_RECORD_FORMATS)) {
276            return "Cannot sort incompatible record formats";
277        } else if (uri.equals(SRUConstants.SRU_UNSUPPORTED_SCHEMA_FOR_SORT)) {
278            return "Unsupported schema for sort";
279        } else if (uri.equals(SRUConstants.SRU_UNSUPPORTED_PATH_FOR_SORT)) {
280            return "Unsupported path for sort";
281        } else if (uri.equals(SRUConstants.SRU_PATH_UNSUPPORTED_FOR_SCHEMA)) {
282            return "Path unsupported for schema";
283        } else if (uri.equals(SRUConstants.SRU_UNSUPPORTED_DIRECTION)) {
284            return "Unsupported direction";
285        } else if (uri.equals(SRUConstants.SRU_UNSUPPORTED_CASE)) {
286            return "Unsupported } else if (uri.equals(";
287        } else if (uri.equals(SRUConstants.SRU_UNSUPPORTED_MISSING_VALUE_ACTION)) {
288            return "Unsupported missing value action";
289        } else if (uri.equals(SRUConstants.SRU_SORT_ENDED_DUE_TO_MISSING_VALUE)) {
290            return "Sort ended due to missing value";
291        } else if (uri.equals(SRUConstants.SRU_SORT_SPEC_INCLUDED_BOTH_IN_QUERY_AND_PROTOCOL_QUERY_PREVAILS)) {
292            return "Sort spec included both in query and protocol query prevails";
293        } else if (uri.equals(SRUConstants.SRU_SORT_SPEC_INCLUDED_BOTH_IN_QUERY_AND_PROTOCOL_PROTOCOL_PREVAILS)) {
294            return "Sort spec included both in query and protocol protocol prevails";
295        } else if (uri.equals(SRUConstants.SRU_SORT_SPEC_INCLUDED_BOTH_IN_QUERY_AND_PROTOCOL_ERROR)) {
296            return "Sort spec included both in query and protocol error";
297        } else if (uri.equals(SRUConstants.SRU_STYLESHEETS_NOT_SUPPORTED)) {
298            return "Stylesheets not supported";
299        } else if (uri.equals(SRUConstants.SRU_UNSUPPORTED_STYLESHEET)) {
300            return "Unsupported stylesheet";
301        } else if (uri.equals(SRUConstants.SRU_RESPONSE_POSITION_OUT_OF_RANGE)) {
302            return "Response position out of range";
303        } else if (uri.equals(SRUConstants.SRU_TOO_MANY_TERMS_REQUESTED)) {
304            return "Too many terms requested";
305        } else {
306            return null;
307        }
308    }
309
310} // class SRUDiagnostic
Note: See TracBrowser for help on using the repository browser.