1 | /** |
---|
2 | * This software is copyright (c) 2012-2022 by |
---|
3 | * - Leibniz-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 Leibniz-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 org.w3c.dom.DocumentFragment; |
---|
20 | |
---|
21 | |
---|
22 | /** |
---|
23 | * Class for holding a single record from a result set. |
---|
24 | * |
---|
25 | * @see SRUSearchRetrieveResponse |
---|
26 | */ |
---|
27 | public final class SRURecord { |
---|
28 | private final SRURecordData recordData; |
---|
29 | private final String recordIdentifier; |
---|
30 | private final int recordPosition; |
---|
31 | private DocumentFragment extraRecordData = null; |
---|
32 | |
---|
33 | |
---|
34 | SRURecord(SRURecordData recordData, String recordIdentifier, |
---|
35 | int recordPosition) { |
---|
36 | if (recordData == null) { |
---|
37 | throw new NullPointerException("recordData == null"); |
---|
38 | } |
---|
39 | this.recordData = recordData; |
---|
40 | this.recordIdentifier = recordIdentifier; |
---|
41 | this.recordPosition = recordPosition; |
---|
42 | } |
---|
43 | |
---|
44 | |
---|
45 | /** |
---|
46 | * The record schema for this record. |
---|
47 | * |
---|
48 | * @return the record schema for this record |
---|
49 | */ |
---|
50 | public String getRecordSchema() { |
---|
51 | return recordData.getRecordSchema(); |
---|
52 | } |
---|
53 | |
---|
54 | |
---|
55 | /** |
---|
56 | * Check if this record is in a certain record schema. |
---|
57 | * |
---|
58 | * @param recordSchema |
---|
59 | * the record schema to test against |
---|
60 | * @return <code>true</code> if the record is in the supplied record schema, |
---|
61 | * <code>false</code> otherwise |
---|
62 | * @throws NullPointerException |
---|
63 | * if any required arguments are not supplied |
---|
64 | */ |
---|
65 | public boolean isRecordSchema(String recordSchema) { |
---|
66 | if (recordSchema == null) { |
---|
67 | throw new NullPointerException("recordSchema == null"); |
---|
68 | } |
---|
69 | return recordData.getRecordSchema().equals(recordSchema); |
---|
70 | } |
---|
71 | |
---|
72 | |
---|
73 | /** |
---|
74 | * Get the record. |
---|
75 | * |
---|
76 | * @return the record |
---|
77 | */ |
---|
78 | public SRURecordData getRecordData() { |
---|
79 | return recordData; |
---|
80 | } |
---|
81 | |
---|
82 | |
---|
83 | /** |
---|
84 | * Get the record identifier (only SRU version 1.2). |
---|
85 | * |
---|
86 | * @return the record identifier or <code>null</code> if not available |
---|
87 | */ |
---|
88 | public String getRecordIdentifier() { |
---|
89 | return recordIdentifier; |
---|
90 | } |
---|
91 | |
---|
92 | |
---|
93 | /** |
---|
94 | * Get the record position in the result set. |
---|
95 | * |
---|
96 | * @return position of the record in the result set or <code>-1</code> if |
---|
97 | * not available |
---|
98 | */ |
---|
99 | public int getRecordPosition() { |
---|
100 | return recordPosition; |
---|
101 | } |
---|
102 | |
---|
103 | |
---|
104 | /** |
---|
105 | * Get extra record data attached to this record. |
---|
106 | * |
---|
107 | * @return get an instance of {@link DocumentFragment} containing the XML |
---|
108 | * fragment for the extra record data from the SRU response or |
---|
109 | * <code>null</code> if none are available |
---|
110 | */ |
---|
111 | public DocumentFragment getExtraRecordData() { |
---|
112 | return extraRecordData; |
---|
113 | } |
---|
114 | |
---|
115 | |
---|
116 | /** |
---|
117 | * Check, if this record has extra record data attached to it. |
---|
118 | * |
---|
119 | * @return <code>true</code> if extra record data is attached, |
---|
120 | * <code>false</code> otherwise |
---|
121 | */ |
---|
122 | public boolean hasExtraRecordData() { |
---|
123 | return extraRecordData != null; |
---|
124 | } |
---|
125 | |
---|
126 | |
---|
127 | void setExtraRecordData(DocumentFragment extraRecordData) { |
---|
128 | this.extraRecordData = extraRecordData; |
---|
129 | } |
---|
130 | |
---|
131 | } // class SRURecord |
---|