source: SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUExplainRecordData.java @ 2986

Last change on this file since 2986 was 2986, checked in by oschonef, 11 years ago
  • add support for parsing indexInfo within ZeeRex? (explain) record data
  • Property svn:eol-style set to native
File size: 12.3 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
19import java.util.Collections;
20import java.util.List;
21import java.util.Set;
22
23/**
24 * A record data implementation for SRU explain record data conforming to the
25 * ZeeRex schema.
26 *
27 * @see <a href="http://zeerex.z3950.org/dtd/">ZeeRex DTD</a>
28 */
29public class SRUExplainRecordData implements SRURecordData {
30    public static final String RECORD_SCHEMA =
31            "http://explain.z3950.org/dtd/2.0/";
32
33    public static class ServerInfo {
34        private final String host;
35        private final int port;
36        private final String database;
37        private final SRUVersion version;
38        private final Set<String> transport;
39
40        ServerInfo(String host, int port, String database,
41                String protocol, SRUVersion version, Set<String> transport) {
42            if (host == null) {
43                throw new NullPointerException("host == null");
44            }
45            if (host.isEmpty()) {
46                throw new IllegalArgumentException("host is empty");
47            }
48            if ((port < 0) || (port > 65535)) {
49                throw new IllegalArgumentException("port < 0 || port > 65535");
50            }
51            if (database == null) {
52                throw new NullPointerException("database == null");
53            }
54            if (database.isEmpty()) {
55                throw new IllegalArgumentException("database is empty");
56            }
57            if (version == null) {
58                throw new NullPointerException("version == null");
59            }
60            if (transport == null) {
61                throw new NullPointerException("transport == null");
62            }
63            this.host      = host;
64            this.port      = port;
65            this.database  = database;
66            this.version   = version;
67            this.transport = Collections.unmodifiableSet(transport);
68        }
69
70
71        public String getHost() {
72            return host;
73        }
74
75
76        public int getPort() {
77            return port;
78        }
79
80
81        public String getDatabase() {
82            return database;
83        }
84
85
86        public SRUVersion getVersion() {
87            return version;
88        }
89
90
91        public Set<String> getTransport() {
92            return transport;
93        }
94    } // class ServerInfo
95
96    public static final class LocalizedString {
97        private final boolean primary;
98        private final String lang;
99        private final String value;
100
101
102        LocalizedString(String value, String lang, boolean primary) {
103            this.value = value;
104            this.lang = lang;
105            this.primary = primary;
106        }
107
108
109        public boolean isPrimary() {
110            return primary;
111        }
112
113
114        public String getLang() {
115            return lang;
116        }
117
118
119        public String getValue() {
120            return value;
121        }
122    } // class LocalizedString
123
124    public static final class DatabaseInfo {
125        private final List<LocalizedString> title;
126        private final List<LocalizedString> description;
127        private final List<LocalizedString> author;
128        private final List<LocalizedString> contact;
129        private final List<LocalizedString> extent;
130        private final List<LocalizedString> history;
131        private final List<LocalizedString> langUsage;
132        private final List<LocalizedString> restrictions;
133        private final List<LocalizedString> subjects;
134        private final List<LocalizedString> links;
135        private final List<LocalizedString> implementation;
136
137
138        DatabaseInfo(List<LocalizedString> title,
139                List<LocalizedString> description,
140                List<LocalizedString> author, List<LocalizedString> contact,
141                List<LocalizedString> extent, List<LocalizedString> history,
142                List<LocalizedString> langUsage,
143                List<LocalizedString> restrictions,
144                List<LocalizedString> subjects, List<LocalizedString> links,
145                List<LocalizedString> implementation) {
146            if ((title != null) && !title.isEmpty()) {
147                this.title = Collections.unmodifiableList(title);
148            } else {
149                this.title = null;
150            }
151            if ((description != null) && !description.isEmpty()) {
152                this.description = Collections.unmodifiableList(description);
153            } else {
154                this.description = null;
155            }
156            if ((author != null) && !author.isEmpty()) {
157                this.author = Collections.unmodifiableList(author);
158            } else {
159                this.author = null;
160            }
161            if ((contact != null) && !contact.isEmpty()) {
162                this.contact = Collections.unmodifiableList(contact);
163            } else {
164                this.contact = null;
165            }
166            if ((extent != null) && !extent.isEmpty()) {
167                this.extent = Collections.unmodifiableList(extent);
168            } else {
169                this.extent = null;
170            }
171            if ((history != null) && !history.isEmpty()) {
172                this.history = Collections.unmodifiableList(history);
173            } else {
174                this.history = null;
175            }
176            if ((langUsage != null) && !langUsage.isEmpty()) {
177                this.langUsage = Collections.unmodifiableList(langUsage);
178            } else {
179                this.langUsage = null;
180            }
181            if ((restrictions != null) && !restrictions.isEmpty()) {
182                this.restrictions = Collections.unmodifiableList(restrictions);
183            } else {
184                this.restrictions = null;
185            }
186            if ((subjects != null) && !subjects.isEmpty()) {
187                this.subjects = Collections.unmodifiableList(subjects);
188            } else {
189                this.subjects = null;
190            }
191            if ((links != null) && !links.isEmpty()) {
192                this.links = Collections.unmodifiableList(links);
193            } else {
194                this.links = null;
195            }
196            if ((implementation != null) && !implementation.isEmpty()) {
197                this.implementation = Collections
198                        .unmodifiableList(implementation);
199            } else {
200                this.implementation = null;
201            }
202        }
203
204
205        public List<LocalizedString> getTitle() {
206            return title;
207        }
208
209
210        public List<LocalizedString> getDescription() {
211            return description;
212        }
213
214
215        public List<LocalizedString> getAuthor() {
216            return author;
217        }
218
219
220        public List<LocalizedString> getContact() {
221            return contact;
222        }
223
224
225        public List<LocalizedString> getExtend() {
226            return extent;
227        }
228
229
230        public List<LocalizedString> getHistory() {
231            return history;
232        }
233
234
235        public List<LocalizedString> getLangUsage() {
236            return langUsage;
237        }
238
239
240        public List<LocalizedString> getRestrictions() {
241            return restrictions;
242        }
243
244
245        public List<LocalizedString> getSubjects() {
246            return subjects;
247        }
248
249
250        public List<LocalizedString> getLinks() {
251            return links;
252        }
253
254
255        public List<LocalizedString> getImplementation() {
256            return implementation;
257        }
258    } // class DatabaseInfo
259
260    public static final class IndexInfo {
261        public static class Set {
262            private final String identifier;
263            private final String name;
264            private final List<LocalizedString> title;
265
266
267            Set(String identifier, String name, List<LocalizedString> title) {
268                this.identifier = identifier;
269                this.name = name;
270                if ((title != null) && !title.isEmpty()) {
271                    this.title = Collections.unmodifiableList(title);
272                } else {
273                    this.title = null;
274                }
275            }
276
277
278            public String getIdentifier() {
279                return identifier;
280            }
281
282
283            public String getName() {
284                return name;
285            }
286
287
288            public List<LocalizedString> getTitle() {
289                return title;
290            }
291        } // class IndexInfo.Set
292
293        public static class Index {
294            public static class Map {
295                private final boolean primary;
296                private final String set;
297                private final String name;
298
299
300                Map(boolean primary, String set, String name) {
301                    this.primary = primary;
302                    this.set     = set;
303                    this.name    = name;
304                }
305
306
307                public boolean isPrimary() {
308                    return primary;
309                }
310
311
312                public String getSet() {
313                    return set;
314                }
315
316
317                public String getName() {
318                    return name;
319                }
320            } // class IndexInfo.Index.Map
321
322            private final String id;
323            private final List<LocalizedString> title;
324            private final boolean can_search;
325            private final boolean can_scan;
326            private final boolean can_sort;
327            private final List<Index.Map> maps;
328
329
330            Index(String id, List<LocalizedString> title, boolean can_search,
331                    boolean can_scan, boolean can_sort, List<Map> maps) {
332                this.id = id;
333                if ((title != null) && !title.isEmpty()) {
334                    this.title = Collections.unmodifiableList(title);
335                } else {
336                    this.title = null;
337                }
338                this.can_search = can_search;
339                this.can_scan = can_scan;
340                this.can_sort = can_sort;
341                this.maps = maps;
342            }
343
344
345            public String getId() {
346                return id;
347            }
348
349
350            public List<LocalizedString> getTitle() {
351                return title;
352            }
353
354
355            public boolean canSearch() {
356                return can_search;
357            }
358
359
360            public boolean canScan() {
361                return can_scan;
362            }
363
364
365            public boolean canSort() {
366                return can_sort;
367            }
368
369
370            public List<Index.Map> getMaps() {
371                return maps;
372            }
373
374        } // class Index
375
376        private final List<IndexInfo.Set> sets;
377        private final List<IndexInfo.Index> indexes;
378
379
380        IndexInfo(List<IndexInfo.Set> sets, List<IndexInfo.Index> indexes) {
381            if ((sets != null) && !sets.isEmpty()) {
382                this.sets = Collections.unmodifiableList(sets);
383            } else {
384                this.sets = null;
385            }
386            if ((indexes != null) && !indexes.isEmpty()) {
387                this.indexes = Collections.unmodifiableList(indexes);
388            } else {
389                this.indexes = null;
390            }
391        }
392
393
394        public List<IndexInfo.Set> getSets() {
395            return sets;
396        }
397
398
399        public List<IndexInfo.Index> getIndexes() {
400            return indexes;
401        }
402    } // class IndexInfo
403
404    private final ServerInfo serverInfo;
405    private final DatabaseInfo databaseInfo;
406    private final IndexInfo indexInfo;
407
408
409    SRUExplainRecordData(ServerInfo serverInfo, DatabaseInfo databaseInfo,
410            IndexInfo indexInfo) {
411        this.serverInfo   = serverInfo;
412        this.databaseInfo = databaseInfo;
413        this.indexInfo    = indexInfo;
414    }
415
416
417    @Override
418    public boolean isTransient() {
419        return false;
420    }
421
422
423    @Override
424    public String getRecordSchema() {
425        return RECORD_SCHEMA;
426    }
427
428
429    public ServerInfo getServerInfo() {
430        return serverInfo;
431    }
432
433
434    public DatabaseInfo getDatabaseInfo() {
435        return databaseInfo;
436    }
437
438
439    public IndexInfo getIndexInfo() {
440        return indexInfo;
441    }
442
443} // class SRUExplainRecordData
Note: See TracBrowser for help on using the repository browser.