source: SRUServer/trunk/src/main/java/eu/clarin/sru/server/SRUScanResultSet.java @ 1881

Last change on this file since 1881 was 1881, checked in by oschonef, 12 years ago
  • import of sru server endpoint
  • Property svn:eol-style set to native
File size: 4.3 KB
Line 
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 */
17package eu.clarin.sru.server;
18
19import java.util.NoSuchElementException;
20
21import javax.xml.stream.XMLStreamException;
22import javax.xml.stream.XMLStreamWriter;
23
24
25/**
26 * A result set of a <em>scan</em> operation. It allows to iterate over the term
27 * set and provides a method to serialize the terms. <br />
28 *
29 * <p>This class needs to be implemented for the target data source.</p>
30 *
31 * @see <a href="http://www.loc.gov/standards/sru/specs/scan.html">
32 *      SRU Scan Operation</a>
33 */
34public abstract class SRUScanResultSet extends SRUAbstractResult {
35    /**
36     * A flag to indicate the position of the term within the complete term
37     * list.
38     */
39    public enum WhereInList {
40        /**
41         * The first term (<em>first</em>)
42         */
43        FIRST,
44
45        /**
46         * The last term (<em>last</em>)
47         */
48        LAST,
49
50        /**
51         * The only term (<em>only</em>)
52         */
53        ONLY,
54
55        /**
56         * Any other term (<em>inner</em>)
57         */
58        INNER;
59    };
60
61
62    /**
63     * Constructor.
64     *
65     * @param diagnostics
66     *            an instance of a SRUDiagnosticList.
67     * @see SRUDiagnosticList
68     */
69    protected SRUScanResultSet(SRUDiagnosticList diagnostics) {
70        super(diagnostics);
71    }
72
73
74    /**
75     * Returns true if the term set has more terms. (In other words, returns
76     * <code>true</code> if <code>nextTerm()</code> would move the internal
77     * result pointer to a new term instead of throwing an exception.)
78     *
79     * @return <code>true</code> if the term set has more terms,
80     *         <code>false</code> otherwise
81     */
82    public abstract boolean hasMoreTerms();
83
84
85    /**
86     * Move to the next term.
87     *
88     * @throws NoSuchElementException
89     *             term set has no more terms
90     */
91    public abstract void nextTerm();
92
93
94    /**
95     * Get the current term exactly as it appears in the index.
96     *
97     * @return current term
98     */
99    public abstract String getValue();
100
101
102    /**
103     * Get the number of records for the current term which would be matched if
104     * the index in the request's <em>scanClause</em> was searched with the term
105     * in the <em>value</em> field.
106     *
107     * @return a non-negative number of records
108     */
109    public abstract int getNumberOfRecords();
110
111
112    /**
113     * Get the string for the current term to display to the end user in place
114     * of the term itself.
115     *
116     * @return display string or <code>null</code>
117     */
118    public abstract String getDisplayTerm();
119
120
121    /**
122     * Get the flag to indicate the position of the term within the complete
123     * term list.
124     *
125     * @return position within term list or <code>null</code>
126     */
127    public abstract WhereInList getWhereInList();
128
129
130    /**
131     * Check, if extra term data should be serialized for the current term. A
132     * default implementation is provided for convince and always returns
133     * <code>false</code>.
134     *
135     * @return <code>true</code> if the term has extra term data
136     * @throws NoSuchElementException
137     *             term set is already advanced past all past terms
138     * @see #writeExtraTermData(XMLStreamWriter)
139     */
140    public boolean hasExtraTermData() {
141        return false;
142    }
143
144
145    /**
146     * Serialize extra term data for the current term. A no-op default
147     * implementation is provided for convince.
148     *
149     * @param writer
150     *            the {@link XMLStreamException} instance to be used
151     * @throws XMLStreamException
152     *             an error occurred while serializing the term extra data
153     * @throws NoSuchElementException
154     *             result set already advanced past all terms
155     * @see #hasExtraTermData()
156     */
157    public void writeExtraTermData(XMLStreamWriter writer)
158            throws XMLStreamException {
159    }
160
161} // abstract class SRUScanResult
Note: See TracBrowser for help on using the repository browser.