1 | /** |
---|
2 | * This software is copyright (c) 2011 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 | import java.util.NoSuchElementException; |
---|
20 | |
---|
21 | import javax.xml.stream.XMLStreamException; |
---|
22 | import javax.xml.stream.XMLStreamWriter; |
---|
23 | |
---|
24 | |
---|
25 | /** |
---|
26 | * A result set of a <em>searchRetrieve</em> operation. It it used to iterate |
---|
27 | * over the result set and provides a method to serialize the record in the |
---|
28 | * requested format. |
---|
29 | * <p> |
---|
30 | * A <code>SRUSearchResultSet</code> object maintains a cursor pointing to its |
---|
31 | * current record. Initially the cursor is positioned before the first record. |
---|
32 | * The <code>next</code> method moves the cursor to the next record, and because |
---|
33 | * it returns <code>false</code> when there are no more records in the |
---|
34 | * <code>SRUSearchResultSet</code> object, it can be used in a |
---|
35 | * <code>while</code> loop to iterate through the result set. |
---|
36 | * </p> |
---|
37 | * <p> |
---|
38 | * This class needs to be implemented for the target search engine. |
---|
39 | * </p> |
---|
40 | * |
---|
41 | * @see <a href="http://www.loc.gov/standards/sru/specs/search-retrieve.html"> |
---|
42 | * SRU Search Retrieve Operation</a> |
---|
43 | */ |
---|
44 | public abstract class SRUSearchResultSet extends SRUAbstractResult { |
---|
45 | |
---|
46 | /** |
---|
47 | * Constructor. |
---|
48 | * |
---|
49 | * @param diagnostics |
---|
50 | * an instance of a SRUDiagnosticList |
---|
51 | * @see SRUDiagnosticList |
---|
52 | */ |
---|
53 | protected SRUSearchResultSet(SRUDiagnosticList diagnostics) { |
---|
54 | super(diagnostics); |
---|
55 | } |
---|
56 | |
---|
57 | |
---|
58 | /** |
---|
59 | * The number of records matched by the query. If the query fails this must |
---|
60 | * be 0. |
---|
61 | * |
---|
62 | * @return the total number of results or 0 if the query failed |
---|
63 | */ |
---|
64 | public abstract int getTotalRecordCount(); |
---|
65 | |
---|
66 | |
---|
67 | /** |
---|
68 | * The number of records matched by the query but at most as the number of |
---|
69 | * records requested to be returned (maximumRecords parameter). If the query |
---|
70 | * fails this must be 0. |
---|
71 | * |
---|
72 | * @return the number of results or 0 if the query failed |
---|
73 | */ |
---|
74 | public abstract int getRecordCount(); |
---|
75 | |
---|
76 | |
---|
77 | /** |
---|
78 | * The result set id of this result. the default implementation returns |
---|
79 | * <code>null</code>. |
---|
80 | * |
---|
81 | * @return the result set id or <code>null</code> if not applicable for this |
---|
82 | * result |
---|
83 | */ |
---|
84 | public String getResultSetId() { |
---|
85 | return null; |
---|
86 | } |
---|
87 | |
---|
88 | |
---|
89 | /** |
---|
90 | * The idle time for this result. The default implementation returns |
---|
91 | * <code>-1</code>. |
---|
92 | * |
---|
93 | * @return the result set idle time or <code>-1</code> if not applicable for |
---|
94 | * this result |
---|
95 | */ |
---|
96 | public int getResultSetIdleTime() { |
---|
97 | return -1; |
---|
98 | } |
---|
99 | |
---|
100 | |
---|
101 | /** |
---|
102 | * The record schema identifier in which the records are returned |
---|
103 | * (recordSchema parameter). |
---|
104 | * |
---|
105 | * @return the record schema identifier |
---|
106 | */ |
---|
107 | public abstract String getRecordSchemaIdentifier(); |
---|
108 | |
---|
109 | |
---|
110 | /** |
---|
111 | * Moves the cursor forward one record from its current position. A |
---|
112 | * <code>SRUSearchResultSet</code> cursor is initially positioned before the |
---|
113 | * first record; the first call to the method <code>next</code> makes the |
---|
114 | * first record the current record; the second call makes the second record |
---|
115 | * the current record, and so on. |
---|
116 | * <p> |
---|
117 | * When a call to the <code>next</code> method returns <code>false</code>, |
---|
118 | * the cursor is positioned after the last record. |
---|
119 | * </p> |
---|
120 | * |
---|
121 | * @return <code>true</code> if the new current record is valid; |
---|
122 | * <code>false</code> if there are no more records |
---|
123 | */ |
---|
124 | public abstract boolean nextRecord(); |
---|
125 | |
---|
126 | |
---|
127 | /** |
---|
128 | * An identifier for the current record by which it can unambiguously be |
---|
129 | * retrieved in a subsequent operation. |
---|
130 | * |
---|
131 | * @return identifier for the record or <code>null</code> of none is |
---|
132 | * available |
---|
133 | * @throws NoSuchElementException |
---|
134 | * result set is past all records |
---|
135 | */ |
---|
136 | public abstract String getRecordIdentifier(); |
---|
137 | |
---|
138 | |
---|
139 | /** |
---|
140 | * Get surrogate diagnostic for current record. If this method returns a |
---|
141 | * diagnostic, the writeRecord method will not be called. The default |
---|
142 | * implementation returns <code>null</code>. |
---|
143 | * |
---|
144 | * @return a surrogate diagnostic or <code>null</code> |
---|
145 | */ |
---|
146 | public SRUDiagnostic getSurrogateDiagnostic() { |
---|
147 | return null; |
---|
148 | } |
---|
149 | |
---|
150 | |
---|
151 | /** |
---|
152 | * Serialize the current record in the requested format. |
---|
153 | * |
---|
154 | * @param writer |
---|
155 | * the {@link XMLStreamException} instance to be used |
---|
156 | * @throws XMLStreamException |
---|
157 | * an error occurred while serializing the result |
---|
158 | * @throws NoSuchElementException |
---|
159 | * result set past all records |
---|
160 | * @see #getRecordSchemaIdentifier() |
---|
161 | */ |
---|
162 | public abstract void writeRecord(XMLStreamWriter writer) |
---|
163 | throws XMLStreamException; |
---|
164 | |
---|
165 | |
---|
166 | /** |
---|
167 | * Check, if extra record data should be serialized for the current record. |
---|
168 | * The default implementation returns <code>false</code>. |
---|
169 | * |
---|
170 | * @return <code>true</code> if the record has extra record data |
---|
171 | * @throws NoSuchElementException |
---|
172 | * result set is already advanced past all records |
---|
173 | * @see #writeExtraResponseData(XMLStreamWriter) |
---|
174 | */ |
---|
175 | public boolean hasExtraRecordData() { |
---|
176 | return false; |
---|
177 | } |
---|
178 | |
---|
179 | |
---|
180 | /** |
---|
181 | * Serialize extra record data for the current record. A no-op default |
---|
182 | * implementation is provided for convince. |
---|
183 | * |
---|
184 | * @param writer |
---|
185 | * the {@link XMLStreamException} instance to be used |
---|
186 | * @throws XMLStreamException |
---|
187 | * an error occurred while serializing the result extra data |
---|
188 | * @throws NoSuchElementException |
---|
189 | * result set past already advanced past all records |
---|
190 | * @see #hasExtraRecordData() |
---|
191 | */ |
---|
192 | public void writeExtraRecordData(XMLStreamWriter writer) |
---|
193 | throws XMLStreamException { |
---|
194 | } |
---|
195 | |
---|
196 | } // class SRUSearchResultSet |
---|