source: SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUScanRequest.java @ 2466

Last change on this file since 2466 was 2466, checked in by oschonef, 11 years ago
  • update copyright (2/2)
  • Property svn:eol-style set to native
File size: 6.0 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.client;
18
19/**
20 * An object for performing a <em>explain</em> operation.
21 * <p>The following argument arguments are mandatory:</p>
22 * <ul>
23 *   <li><em>scanClause</em></li>
24 * </ul>
25 *
26 * @see SRUScanHandler
27 * @see <a href="http://www.loc.gov/standards/sru/specs/scan.html">SRU Scan
28 *      Operation</a>
29 */
30public final class SRUScanRequest extends SRUAbstractRequest {
31    /** for end-point conformance testing only. never use in production. */
32    public static final String X_MALFORMED_SCAN_CLAUSE =
33            "x-malformed-scanClause";
34    /** for end-point conformance testing only. never use in production. */
35    public static final String X_MALFORMED_RESPONSE_POSITION =
36            "x-malformed-responsePosition";
37    /** for end-point conformance testing only. never use in production. */
38    public static final String X_MALFORMED_MAXIMUM_TERMS =
39            "x-malformed-maximumTerms";
40    private String scanClause;
41    private int responsePosition = -1;
42    private int maximumTerms = -1;
43
44
45    /**
46     * Constructor.
47     *
48     * @param baseURI
49     *            the baseURI of the endpoint
50     */
51    public SRUScanRequest(String baseURI) {
52        super(baseURI);
53    }
54
55
56    /**
57     * Get the value of the <em>scanClause</em> argument for this request.
58     *
59     * @return the value for the <em>scanClause</em> argument or
60     *         <code>null</code> of none was set
61     */
62    public String getScanClause() {
63        return scanClause;
64    }
65
66
67    /**
68     * Set the value of the <em>scanClause</em> argument for this request.
69     *
70     * @param scanClause
71     *            the value for the <em>scanClause</em> argument
72     * @throws NullPointerException
73     *             if any required argument is <code>null</code>
74     * @throws IllegalArgumentException
75     *             if any argument is invalid
76     */
77    public void setScanClause(String scanClause) {
78        if (scanClause == null) {
79            throw new NullPointerException("scanClause == null");
80        }
81        if (scanClause.isEmpty()) {
82            throw new IllegalArgumentException("scanClause is an empty string");
83        }
84        this.scanClause = scanClause;
85    }
86
87
88    /**
89     * Get the value of the <em>responsePosition</em> argument for this request.
90     *
91     * @return the value for the <em>responsePosition</em> argument
92     */
93    public int getResponsePosition() {
94        return responsePosition;
95    }
96
97
98    /**
99     * Set the value of the <em>responsePosition</em> argument for this request.
100     *
101     * @param responsePosition
102     *            the value for the <em>responsePosition</em> argument
103     * @throws IllegalArgumentException
104     *             if any argument is invalid
105     */
106    public void setResponsePosition(int responsePosition) {
107        if (responsePosition < 0) {
108            throw new IllegalArgumentException("responsePosition < 0");
109        }
110        this.responsePosition = responsePosition;
111    }
112
113
114    /**
115     * Get the value of the <em>maximumTerms</em> argument for this request.
116     *
117     * @return the value for the <em>maximumTerms</em> argument
118     */
119    public int getMaximumTerms() {
120        return maximumTerms;
121    }
122
123
124    /**
125     * Set the value of the <em>maximumTerms</em> argument for this request.
126     *
127     * @param maximumTerms
128     *            the value for the <em>maximumTerms</em> argument
129     * @throws IllegalArgumentException
130     *             if any argument is invalid
131     */
132    public void setMaximumTerms(int maximumTerms) {
133        if (maximumTerms < 0) {
134            throw new IllegalArgumentException("maximumTerms < 0");
135        }
136        this.maximumTerms = maximumTerms;
137    }
138
139
140    @Override
141    SRUOperation getOperation() {
142        return SRUOperation.SCAN;
143    }
144
145
146    @Override
147    void addParametersToURI(URIBuilder uriBuilder) throws SRUClientException {
148        // scanClause
149        final String malformedScan =
150                getExtraRequestData(X_MALFORMED_SCAN_CLAUSE);
151        if (malformedScan == null) {
152            if ((scanClause == null) || scanClause.isEmpty()) {
153                throw new SRUClientException(
154                        "mandatory argument 'scanClause' not set or empty");
155            }
156            uriBuilder.append(PARAM_SCAN_CLAUSE, scanClause);
157        } else {
158            if (!malformedScan.equalsIgnoreCase(MALFORMED_OMIT)) {
159                uriBuilder.append(PARAM_VERSION, malformedScan);
160            }
161        }
162
163        // responsePosition
164        final String malformedResponsePosition =
165                getExtraRequestData(X_MALFORMED_RESPONSE_POSITION);
166        if (malformedResponsePosition == null) {
167            if (responsePosition > -1) {
168                uriBuilder.append(PARAM_RESPONSE_POSITION, responsePosition);
169            }
170        } else {
171            if (!malformedResponsePosition.equalsIgnoreCase(MALFORMED_OMIT)) {
172                uriBuilder.append(PARAM_RESPONSE_POSITION,
173                        malformedResponsePosition);
174            }
175        }
176
177        // maximumTerms
178        final String malformedMaximumTerms =
179                getExtraRequestData(X_MALFORMED_MAXIMUM_TERMS);
180        if (malformedMaximumTerms == null) {
181            if (maximumTerms > -1) {
182                uriBuilder.append(PARAM_MAXIMUM_TERMS, maximumTerms);
183            }
184        } else {
185            if (!malformedMaximumTerms.equalsIgnoreCase(MALFORMED_OMIT)) {
186                uriBuilder.append(PARAM_MAXIMUM_TERMS, malformedMaximumTerms);
187            }
188        }
189    }
190
191} // class SRUScanRequest
Note: See TracBrowser for help on using the repository browser.