source: SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUSearchRetrieveRequest.java @ 2047

Last change on this file since 2047 was 2047, checked in by oschonef, 12 years ago
  • ensure mandatory arguments have been set before commencing request
  • fix typo
  • Property svn:eol-style set to native
File size: 3.5 KB
Line 
1package eu.clarin.sru.client;
2
3public final class SRUSearchRetrieveRequest extends SRUAbstractRequest {
4    private String query;
5    private int startRecord = -1;
6    private int maximumRecords = -1;
7    private SRURecordPacking recordPacking;
8    private String recordSchema;
9    private int resultSetTTL = -1;
10
11
12    protected SRUSearchRetrieveRequest(String baseURI) {
13        super(baseURI);
14    }
15
16
17    public String getQuery() {
18        return query;
19    }
20
21
22    public void setQuery(String query) {
23        if (query == null) {
24            throw new NullPointerException("query == null");
25        }
26        if (query.isEmpty()) {
27            throw new IllegalArgumentException("query is an empty string");
28        }
29        this.query = query;
30    }
31
32
33    public int getStartRecord() {
34        return startRecord;
35    }
36
37
38    public void setStartRecord(int startRecord) {
39        if (startRecord < 1) {
40            throw new IllegalArgumentException("startRecord < 1");
41        }
42        this.startRecord = startRecord;
43    }
44
45
46    public int getMaximumRecords() {
47        return maximumRecords;
48    }
49
50
51    public void setMaximumRecords(int maximumRecords) {
52        if (maximumRecords < 0) {
53            throw new IllegalArgumentException("maximumRecords < 0");
54        }
55        this.maximumRecords = maximumRecords;
56    }
57
58
59    public String getRecordSchema() {
60        return recordSchema;
61    }
62
63
64    public void setRecordSchema(String recordSchema) {
65        this.recordSchema = recordSchema;
66    }
67
68
69    public void setRecordPacking(SRURecordPacking recordPacking) {
70        if (recordPacking == null) {
71            throw new NullPointerException("recordPacking == null");
72        }
73        this.recordPacking = recordPacking;
74    }
75
76
77    public SRURecordPacking getRecordPacking() {
78        return recordPacking;
79    }
80
81
82    public int getResultSetTTL() {
83        return resultSetTTL;
84    }
85
86
87    public void setResultSetTTL(int resultSetTTL) {
88        this.resultSetTTL = resultSetTTL;
89    }
90
91
92    @Override
93    protected SRUOperation getOperation() {
94        return SRUOperation.SEARCH_RETRIEVE;
95    }
96
97
98    @Override
99    protected void addParametersToURI(URIBuilder uriBuilder)
100            throws SRUClientException {
101        // query
102        if ((query == null) || query.isEmpty()) {
103            throw new SRUClientException(
104                    "mandatory argument 'query' not set or empty");
105        }
106        uriBuilder.append(PARAM_QUERY, query);
107
108        // startRecord
109        if (startRecord > 0) {
110            uriBuilder.append(PARAM_START_RECORD, startRecord);
111        }
112
113        // maximumRecords
114        if (maximumRecords > -1) {
115            uriBuilder.append(PARAM_MAXIMUM_RECORDS, maximumRecords);
116        }
117
118        // recordPacking
119        if (recordPacking != null) {
120            switch (recordPacking) {
121            case XML:
122                uriBuilder.append(PARAM_RECORD_PACKING, RECORD_PACKING_XML);
123                break;
124            case STRING:
125                uriBuilder.append(PARAM_RECORD_PACKING, RECORD_PACKING_STRING);
126                break;
127            default:
128                throw new SRUClientException("unsupported record packing: " +
129                        recordPacking);
130            } // switch
131        }
132
133        // recordSchema
134        if (recordSchema != null) {
135            uriBuilder.append(PARAM_RECORD_SCHEMA, recordSchema);
136        }
137
138        // resultSetTTL
139        if (resultSetTTL > -1) {
140            uriBuilder.append(PARAM_RESULT_SET_TTL, resultSetTTL);
141        }
142    }
143
144} // class SRUSearchRetrieveRequest
Note: See TracBrowser for help on using the repository browser.