1 | /** |
---|
2 | * This software is copyright (c) 2011-2012 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.client; |
---|
18 | |
---|
19 | import java.util.Collections; |
---|
20 | import java.util.List; |
---|
21 | |
---|
22 | import org.w3c.dom.Document; |
---|
23 | |
---|
24 | |
---|
25 | |
---|
26 | /** |
---|
27 | * Abstract base class for SRU responses. |
---|
28 | * |
---|
29 | * @see SRUExplainResponse |
---|
30 | * @see SRUScanResponse |
---|
31 | * @see SRUSearchRetrieveResponse |
---|
32 | */ |
---|
33 | class SRUAbstractResponse<T> { |
---|
34 | private final T request; |
---|
35 | private final List<SRUDiagnostic> diagnostics; |
---|
36 | private final Document extraResponseData; |
---|
37 | |
---|
38 | |
---|
39 | /** |
---|
40 | * Constructor. |
---|
41 | * |
---|
42 | * @param diagnostics |
---|
43 | * a list of diagnostics associated to this result or |
---|
44 | * <code>null</code> if none. |
---|
45 | * @param extraResponseData |
---|
46 | * extra response data for this result or <code>null</code> if |
---|
47 | * none. |
---|
48 | */ |
---|
49 | protected SRUAbstractResponse(T request, List<SRUDiagnostic> diagnostics, |
---|
50 | Document extraResponseData) { |
---|
51 | this.request = request; |
---|
52 | this.diagnostics = ((diagnostics != null) && !diagnostics.isEmpty()) |
---|
53 | ? Collections.unmodifiableList(diagnostics) : null; |
---|
54 | this.extraResponseData = extraResponseData; |
---|
55 | } |
---|
56 | |
---|
57 | |
---|
58 | /** |
---|
59 | * Get the request that produced this response. |
---|
60 | * |
---|
61 | * @return the request |
---|
62 | */ |
---|
63 | public T getRequest() { |
---|
64 | return request; |
---|
65 | } |
---|
66 | |
---|
67 | |
---|
68 | /** |
---|
69 | * Get the diagnostics for this response. |
---|
70 | * |
---|
71 | * @return diagnostics for this response or <code>null</code> if none |
---|
72 | */ |
---|
73 | public List<SRUDiagnostic> getDiagnostics() { |
---|
74 | return diagnostics; |
---|
75 | } |
---|
76 | |
---|
77 | |
---|
78 | /** |
---|
79 | * Check, if the response contains any diagnostics. |
---|
80 | * |
---|
81 | * <p> |
---|
82 | * NB: Surrogate diagnostics are not covered by this. |
---|
83 | * </p> |
---|
84 | * |
---|
85 | * @return <code>true</code> if response contains any diagnostic, |
---|
86 | * <code>false</code> otherwise |
---|
87 | */ |
---|
88 | public boolean hasDiagnostics() { |
---|
89 | return diagnostics != null; |
---|
90 | } |
---|
91 | |
---|
92 | |
---|
93 | /** |
---|
94 | * Get the extra response data for this result. |
---|
95 | * |
---|
96 | * @return a {@link Document} node for the extra response data or |
---|
97 | * <code>null</code> if none |
---|
98 | */ |
---|
99 | public Document getExtraResponseData() { |
---|
100 | return extraResponseData; |
---|
101 | } |
---|
102 | |
---|
103 | } // class SRUAbstractResponse |
---|