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 | */ |
---|
17 | package eu.clarin.sru.client; |
---|
18 | |
---|
19 | import java.util.Collections; |
---|
20 | import java.util.List; |
---|
21 | import java.util.Map; |
---|
22 | import java.util.Set; |
---|
23 | |
---|
24 | /** |
---|
25 | * A record data implementation for SRU explain record data conforming to the |
---|
26 | * ZeeRex schema. |
---|
27 | * |
---|
28 | * @see <a href="http://zeerex.z3950.org/dtd/">ZeeRex DTD</a> |
---|
29 | */ |
---|
30 | public class SRUExplainRecordData implements SRURecordData { |
---|
31 | public static final String RECORD_SCHEMA = |
---|
32 | "http://explain.z3950.org/dtd/2.0/"; |
---|
33 | |
---|
34 | public static class ServerInfo { |
---|
35 | private final String host; |
---|
36 | private final int port; |
---|
37 | private final String database; |
---|
38 | private final SRUVersion version; |
---|
39 | private final Set<String> transport; |
---|
40 | |
---|
41 | ServerInfo(String host, int port, String database, |
---|
42 | String protocol, SRUVersion version, Set<String> transport) { |
---|
43 | if (host == null) { |
---|
44 | throw new NullPointerException("host == null"); |
---|
45 | } |
---|
46 | if (host.isEmpty()) { |
---|
47 | throw new IllegalArgumentException("host is empty"); |
---|
48 | } |
---|
49 | if ((port < 0) || (port > 65535)) { |
---|
50 | throw new IllegalArgumentException("port < 0 || port > 65535"); |
---|
51 | } |
---|
52 | if (database == null) { |
---|
53 | throw new NullPointerException("database == null"); |
---|
54 | } |
---|
55 | if (database.isEmpty()) { |
---|
56 | throw new IllegalArgumentException("database is empty"); |
---|
57 | } |
---|
58 | if (version == null) { |
---|
59 | throw new NullPointerException("version == null"); |
---|
60 | } |
---|
61 | if (transport == null) { |
---|
62 | throw new NullPointerException("transport == null"); |
---|
63 | } |
---|
64 | this.host = host; |
---|
65 | this.port = port; |
---|
66 | this.database = database; |
---|
67 | this.version = version; |
---|
68 | this.transport = Collections.unmodifiableSet(transport); |
---|
69 | } |
---|
70 | |
---|
71 | |
---|
72 | public String getHost() { |
---|
73 | return host; |
---|
74 | } |
---|
75 | |
---|
76 | |
---|
77 | public int getPort() { |
---|
78 | return port; |
---|
79 | } |
---|
80 | |
---|
81 | |
---|
82 | public String getDatabase() { |
---|
83 | return database; |
---|
84 | } |
---|
85 | |
---|
86 | |
---|
87 | public SRUVersion getVersion() { |
---|
88 | return version; |
---|
89 | } |
---|
90 | |
---|
91 | |
---|
92 | public Set<String> getTransport() { |
---|
93 | return transport; |
---|
94 | } |
---|
95 | } // class ServerInfo |
---|
96 | |
---|
97 | public static final class LocalizedString { |
---|
98 | private final boolean primary; |
---|
99 | private final String lang; |
---|
100 | private final String value; |
---|
101 | |
---|
102 | |
---|
103 | LocalizedString(String value, String lang, boolean primary) { |
---|
104 | this.value = value; |
---|
105 | this.lang = lang; |
---|
106 | this.primary = primary; |
---|
107 | } |
---|
108 | |
---|
109 | |
---|
110 | public boolean isPrimary() { |
---|
111 | return primary; |
---|
112 | } |
---|
113 | |
---|
114 | |
---|
115 | public String getLang() { |
---|
116 | return lang; |
---|
117 | } |
---|
118 | |
---|
119 | |
---|
120 | public String getValue() { |
---|
121 | return value; |
---|
122 | } |
---|
123 | } // class LocalizedString |
---|
124 | |
---|
125 | public static final class DatabaseInfo { |
---|
126 | private final List<LocalizedString> title; |
---|
127 | private final List<LocalizedString> description; |
---|
128 | private final List<LocalizedString> author; |
---|
129 | private final List<LocalizedString> contact; |
---|
130 | private final List<LocalizedString> extent; |
---|
131 | private final List<LocalizedString> history; |
---|
132 | private final List<LocalizedString> langUsage; |
---|
133 | private final List<LocalizedString> restrictions; |
---|
134 | private final List<LocalizedString> subjects; |
---|
135 | private final List<LocalizedString> links; |
---|
136 | private final List<LocalizedString> implementation; |
---|
137 | |
---|
138 | |
---|
139 | DatabaseInfo(List<LocalizedString> title, |
---|
140 | List<LocalizedString> description, |
---|
141 | List<LocalizedString> author, List<LocalizedString> contact, |
---|
142 | List<LocalizedString> extent, List<LocalizedString> history, |
---|
143 | List<LocalizedString> langUsage, |
---|
144 | List<LocalizedString> restrictions, |
---|
145 | List<LocalizedString> subjects, List<LocalizedString> links, |
---|
146 | List<LocalizedString> implementation) { |
---|
147 | if ((title != null) && !title.isEmpty()) { |
---|
148 | this.title = Collections.unmodifiableList(title); |
---|
149 | } else { |
---|
150 | this.title = null; |
---|
151 | } |
---|
152 | if ((description != null) && !description.isEmpty()) { |
---|
153 | this.description = Collections.unmodifiableList(description); |
---|
154 | } else { |
---|
155 | this.description = null; |
---|
156 | } |
---|
157 | if ((author != null) && !author.isEmpty()) { |
---|
158 | this.author = Collections.unmodifiableList(author); |
---|
159 | } else { |
---|
160 | this.author = null; |
---|
161 | } |
---|
162 | if ((contact != null) && !contact.isEmpty()) { |
---|
163 | this.contact = Collections.unmodifiableList(contact); |
---|
164 | } else { |
---|
165 | this.contact = null; |
---|
166 | } |
---|
167 | if ((extent != null) && !extent.isEmpty()) { |
---|
168 | this.extent = Collections.unmodifiableList(extent); |
---|
169 | } else { |
---|
170 | this.extent = null; |
---|
171 | } |
---|
172 | if ((history != null) && !history.isEmpty()) { |
---|
173 | this.history = Collections.unmodifiableList(history); |
---|
174 | } else { |
---|
175 | this.history = null; |
---|
176 | } |
---|
177 | if ((langUsage != null) && !langUsage.isEmpty()) { |
---|
178 | this.langUsage = Collections.unmodifiableList(langUsage); |
---|
179 | } else { |
---|
180 | this.langUsage = null; |
---|
181 | } |
---|
182 | if ((restrictions != null) && !restrictions.isEmpty()) { |
---|
183 | this.restrictions = Collections.unmodifiableList(restrictions); |
---|
184 | } else { |
---|
185 | this.restrictions = null; |
---|
186 | } |
---|
187 | if ((subjects != null) && !subjects.isEmpty()) { |
---|
188 | this.subjects = Collections.unmodifiableList(subjects); |
---|
189 | } else { |
---|
190 | this.subjects = null; |
---|
191 | } |
---|
192 | if ((links != null) && !links.isEmpty()) { |
---|
193 | this.links = Collections.unmodifiableList(links); |
---|
194 | } else { |
---|
195 | this.links = null; |
---|
196 | } |
---|
197 | if ((implementation != null) && !implementation.isEmpty()) { |
---|
198 | this.implementation = Collections |
---|
199 | .unmodifiableList(implementation); |
---|
200 | } else { |
---|
201 | this.implementation = null; |
---|
202 | } |
---|
203 | } |
---|
204 | |
---|
205 | |
---|
206 | public List<LocalizedString> getTitle() { |
---|
207 | return title; |
---|
208 | } |
---|
209 | |
---|
210 | |
---|
211 | public List<LocalizedString> getDescription() { |
---|
212 | return description; |
---|
213 | } |
---|
214 | |
---|
215 | |
---|
216 | public List<LocalizedString> getAuthor() { |
---|
217 | return author; |
---|
218 | } |
---|
219 | |
---|
220 | |
---|
221 | public List<LocalizedString> getContact() { |
---|
222 | return contact; |
---|
223 | } |
---|
224 | |
---|
225 | |
---|
226 | public List<LocalizedString> getExtend() { |
---|
227 | return extent; |
---|
228 | } |
---|
229 | |
---|
230 | |
---|
231 | public List<LocalizedString> getHistory() { |
---|
232 | return history; |
---|
233 | } |
---|
234 | |
---|
235 | |
---|
236 | public List<LocalizedString> getLangUsage() { |
---|
237 | return langUsage; |
---|
238 | } |
---|
239 | |
---|
240 | |
---|
241 | public List<LocalizedString> getRestrictions() { |
---|
242 | return restrictions; |
---|
243 | } |
---|
244 | |
---|
245 | |
---|
246 | public List<LocalizedString> getSubjects() { |
---|
247 | return subjects; |
---|
248 | } |
---|
249 | |
---|
250 | |
---|
251 | public List<LocalizedString> getLinks() { |
---|
252 | return links; |
---|
253 | } |
---|
254 | |
---|
255 | |
---|
256 | public List<LocalizedString> getImplementation() { |
---|
257 | return implementation; |
---|
258 | } |
---|
259 | } // class DatabaseInfo |
---|
260 | |
---|
261 | public static final class IndexInfo { |
---|
262 | public static class Set { |
---|
263 | private final String identifier; |
---|
264 | private final String name; |
---|
265 | private final List<LocalizedString> title; |
---|
266 | |
---|
267 | |
---|
268 | Set(String identifier, String name, List<LocalizedString> title) { |
---|
269 | this.identifier = identifier; |
---|
270 | this.name = name; |
---|
271 | if ((title != null) && !title.isEmpty()) { |
---|
272 | this.title = Collections.unmodifiableList(title); |
---|
273 | } else { |
---|
274 | this.title = null; |
---|
275 | } |
---|
276 | } |
---|
277 | |
---|
278 | |
---|
279 | public String getIdentifier() { |
---|
280 | return identifier; |
---|
281 | } |
---|
282 | |
---|
283 | |
---|
284 | public String getName() { |
---|
285 | return name; |
---|
286 | } |
---|
287 | |
---|
288 | |
---|
289 | public List<LocalizedString> getTitle() { |
---|
290 | return title; |
---|
291 | } |
---|
292 | } // class IndexInfo.Set |
---|
293 | |
---|
294 | public static class Index { |
---|
295 | public static class Map { |
---|
296 | private final boolean primary; |
---|
297 | private final String set; |
---|
298 | private final String name; |
---|
299 | |
---|
300 | |
---|
301 | Map(boolean primary, String set, String name) { |
---|
302 | this.primary = primary; |
---|
303 | this.set = set; |
---|
304 | this.name = name; |
---|
305 | } |
---|
306 | |
---|
307 | |
---|
308 | public boolean isPrimary() { |
---|
309 | return primary; |
---|
310 | } |
---|
311 | |
---|
312 | |
---|
313 | public String getSet() { |
---|
314 | return set; |
---|
315 | } |
---|
316 | |
---|
317 | |
---|
318 | public String getName() { |
---|
319 | return name; |
---|
320 | } |
---|
321 | } // class IndexInfo.Index.Map |
---|
322 | |
---|
323 | private final String id; |
---|
324 | private final List<LocalizedString> title; |
---|
325 | private final boolean can_search; |
---|
326 | private final boolean can_scan; |
---|
327 | private final boolean can_sort; |
---|
328 | private final List<Index.Map> maps; |
---|
329 | |
---|
330 | |
---|
331 | Index(String id, List<LocalizedString> title, boolean can_search, |
---|
332 | boolean can_scan, boolean can_sort, List<Map> maps) { |
---|
333 | this.id = id; |
---|
334 | if ((title != null) && !title.isEmpty()) { |
---|
335 | this.title = Collections.unmodifiableList(title); |
---|
336 | } else { |
---|
337 | this.title = null; |
---|
338 | } |
---|
339 | this.can_search = can_search; |
---|
340 | this.can_scan = can_scan; |
---|
341 | this.can_sort = can_sort; |
---|
342 | this.maps = maps; |
---|
343 | } |
---|
344 | |
---|
345 | |
---|
346 | public String getId() { |
---|
347 | return id; |
---|
348 | } |
---|
349 | |
---|
350 | |
---|
351 | public List<LocalizedString> getTitle() { |
---|
352 | return title; |
---|
353 | } |
---|
354 | |
---|
355 | |
---|
356 | public boolean canSearch() { |
---|
357 | return can_search; |
---|
358 | } |
---|
359 | |
---|
360 | |
---|
361 | public boolean canScan() { |
---|
362 | return can_scan; |
---|
363 | } |
---|
364 | |
---|
365 | |
---|
366 | public boolean canSort() { |
---|
367 | return can_sort; |
---|
368 | } |
---|
369 | |
---|
370 | |
---|
371 | public List<Index.Map> getMaps() { |
---|
372 | return maps; |
---|
373 | } |
---|
374 | |
---|
375 | } // class Index |
---|
376 | |
---|
377 | private final List<IndexInfo.Set> sets; |
---|
378 | private final List<IndexInfo.Index> indexes; |
---|
379 | |
---|
380 | |
---|
381 | IndexInfo(List<IndexInfo.Set> sets, List<IndexInfo.Index> indexes) { |
---|
382 | if ((sets != null) && !sets.isEmpty()) { |
---|
383 | this.sets = Collections.unmodifiableList(sets); |
---|
384 | } else { |
---|
385 | this.sets = null; |
---|
386 | } |
---|
387 | if ((indexes != null) && !indexes.isEmpty()) { |
---|
388 | this.indexes = Collections.unmodifiableList(indexes); |
---|
389 | } else { |
---|
390 | this.indexes = null; |
---|
391 | } |
---|
392 | } |
---|
393 | |
---|
394 | |
---|
395 | public List<IndexInfo.Set> getSets() { |
---|
396 | return sets; |
---|
397 | } |
---|
398 | |
---|
399 | |
---|
400 | public List<IndexInfo.Index> getIndexes() { |
---|
401 | return indexes; |
---|
402 | } |
---|
403 | } // class IndexInfo |
---|
404 | |
---|
405 | public static class Schema { |
---|
406 | private final String identifier; |
---|
407 | private final String name; |
---|
408 | private final String location; |
---|
409 | private final boolean sort; |
---|
410 | private final boolean retrieve; |
---|
411 | private final List<LocalizedString> title; |
---|
412 | |
---|
413 | |
---|
414 | Schema(String identifier, String name, String location, boolean sort, |
---|
415 | boolean retrieve, List<LocalizedString> title) { |
---|
416 | this.identifier = identifier; |
---|
417 | this.name = name; |
---|
418 | this.location = location; |
---|
419 | this.sort = sort; |
---|
420 | this.retrieve = retrieve; |
---|
421 | if ((title != null) && !title.isEmpty()) { |
---|
422 | this.title = Collections.unmodifiableList(title); |
---|
423 | } else { |
---|
424 | this.title = null; |
---|
425 | } |
---|
426 | } |
---|
427 | |
---|
428 | |
---|
429 | public String getIdentifier() { |
---|
430 | return identifier; |
---|
431 | } |
---|
432 | |
---|
433 | |
---|
434 | public String getName() { |
---|
435 | return name; |
---|
436 | } |
---|
437 | |
---|
438 | |
---|
439 | public String getLocation() { |
---|
440 | return location; |
---|
441 | } |
---|
442 | |
---|
443 | |
---|
444 | public boolean getSort() { |
---|
445 | return sort; |
---|
446 | } |
---|
447 | |
---|
448 | |
---|
449 | public boolean getRetrieve() { |
---|
450 | return retrieve; |
---|
451 | } |
---|
452 | |
---|
453 | |
---|
454 | public List<LocalizedString> getTitle() { |
---|
455 | return title; |
---|
456 | } |
---|
457 | } // class SchemaInfo |
---|
458 | |
---|
459 | public static class ConfigInfo { |
---|
460 | private final Map<String, String> defaults; |
---|
461 | private final Map<String, String> settings; |
---|
462 | private final Map<String, String> supports; |
---|
463 | |
---|
464 | |
---|
465 | ConfigInfo(Map<String, String> defaults, Map<String, String> settings, |
---|
466 | Map<String, String> supports) { |
---|
467 | if ((defaults != null) && !defaults.isEmpty()) { |
---|
468 | this.defaults = Collections.unmodifiableMap(defaults); |
---|
469 | } else { |
---|
470 | this.defaults = Collections.emptyMap(); |
---|
471 | } |
---|
472 | if ((settings != null) && !settings.isEmpty()) { |
---|
473 | this.settings = Collections.unmodifiableMap(settings); |
---|
474 | } else { |
---|
475 | this.settings = Collections.emptyMap(); |
---|
476 | } |
---|
477 | if ((supports != null) && !supports.isEmpty()) { |
---|
478 | this.supports = Collections.unmodifiableMap(supports); |
---|
479 | } else { |
---|
480 | this.supports = Collections.emptyMap(); |
---|
481 | } |
---|
482 | } |
---|
483 | |
---|
484 | |
---|
485 | public Map<String, String> getDefaults() { |
---|
486 | return defaults; |
---|
487 | } |
---|
488 | |
---|
489 | |
---|
490 | public Map<String, String> getSettings() { |
---|
491 | return settings; |
---|
492 | } |
---|
493 | |
---|
494 | |
---|
495 | public Map<String, String> getSupports() { |
---|
496 | return supports; |
---|
497 | } |
---|
498 | } // class ConfigInfo |
---|
499 | |
---|
500 | private final ServerInfo serverInfo; |
---|
501 | private final DatabaseInfo databaseInfo; |
---|
502 | private final IndexInfo indexInfo; |
---|
503 | private final List<Schema> schemaInfo; |
---|
504 | private final ConfigInfo configInfo; |
---|
505 | |
---|
506 | |
---|
507 | SRUExplainRecordData(ServerInfo serverInfo, DatabaseInfo databaseInfo, |
---|
508 | IndexInfo indexInfo, List<Schema> schemaInfo, |
---|
509 | ConfigInfo configInfo) { |
---|
510 | this.serverInfo = serverInfo; |
---|
511 | this.databaseInfo = databaseInfo; |
---|
512 | this.indexInfo = indexInfo; |
---|
513 | if ((schemaInfo != null) && !schemaInfo.isEmpty()) { |
---|
514 | this.schemaInfo = Collections.unmodifiableList(schemaInfo); |
---|
515 | } else { |
---|
516 | this.schemaInfo = null; |
---|
517 | } |
---|
518 | this.configInfo = configInfo; |
---|
519 | } |
---|
520 | |
---|
521 | |
---|
522 | @Override |
---|
523 | public boolean isTransient() { |
---|
524 | return false; |
---|
525 | } |
---|
526 | |
---|
527 | |
---|
528 | @Override |
---|
529 | public String getRecordSchema() { |
---|
530 | return RECORD_SCHEMA; |
---|
531 | } |
---|
532 | |
---|
533 | |
---|
534 | public ServerInfo getServerInfo() { |
---|
535 | return serverInfo; |
---|
536 | } |
---|
537 | |
---|
538 | |
---|
539 | public DatabaseInfo getDatabaseInfo() { |
---|
540 | return databaseInfo; |
---|
541 | } |
---|
542 | |
---|
543 | |
---|
544 | public List<Schema> getSchemaInfo() { |
---|
545 | return schemaInfo; |
---|
546 | } |
---|
547 | |
---|
548 | |
---|
549 | public IndexInfo getIndexInfo() { |
---|
550 | return indexInfo; |
---|
551 | } |
---|
552 | |
---|
553 | |
---|
554 | public ConfigInfo getConfigInfo() { |
---|
555 | return configInfo; |
---|
556 | } |
---|
557 | |
---|
558 | } // class SRUExplainRecordData |
---|