1 | /** |
---|
2 | * This software is copyright (c) 2012-2014 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.fcs; |
---|
18 | |
---|
19 | /** |
---|
20 | * Base class for Data View implementations according to the CLARIN-FCS record |
---|
21 | * schema. |
---|
22 | */ |
---|
23 | public abstract class DataView { |
---|
24 | private final String type; |
---|
25 | private final String pid; |
---|
26 | private final String ref; |
---|
27 | |
---|
28 | |
---|
29 | /** |
---|
30 | * Constructor. |
---|
31 | * |
---|
32 | * @param type |
---|
33 | * the MIME type of this DataView |
---|
34 | * @param pid |
---|
35 | * a persistent identifier or <code>null</code> |
---|
36 | * @param ref |
---|
37 | * a reference URI or <code>null</code> |
---|
38 | * @throws NullPointerException |
---|
39 | * if a mandatory argument was not supplied |
---|
40 | * |
---|
41 | */ |
---|
42 | protected DataView(String type, String pid, String ref) { |
---|
43 | if (type == null) { |
---|
44 | throw new NullPointerException("type == null"); |
---|
45 | } |
---|
46 | this.type = type; |
---|
47 | this.pid = ((pid != null) && !pid.isEmpty()) ? pid : null; |
---|
48 | this.ref = ((ref != null) && !ref.isEmpty()) ? ref : null; |
---|
49 | } |
---|
50 | |
---|
51 | |
---|
52 | /** |
---|
53 | * Get the MIME type of this DataView. |
---|
54 | * |
---|
55 | * @return the MIME type of this DataView |
---|
56 | */ |
---|
57 | public String getMimeType() { |
---|
58 | return type; |
---|
59 | } |
---|
60 | |
---|
61 | |
---|
62 | /** |
---|
63 | * Convenience method to check if this DataView is of a certain MIME type. |
---|
64 | * |
---|
65 | * @param type |
---|
66 | * the MIME type to test against |
---|
67 | * @return <code>true</code> if the DataView is in the supplied MIME type, |
---|
68 | * <code>false</code> otherwise |
---|
69 | * @throws NullPointerException |
---|
70 | * if any required arguments are not supplied |
---|
71 | */ |
---|
72 | public boolean isMimeType(String type) { |
---|
73 | if (type == null) { |
---|
74 | throw new NullPointerException("mimetype == null"); |
---|
75 | } |
---|
76 | return (this.type.equals(type)); |
---|
77 | } |
---|
78 | |
---|
79 | /** |
---|
80 | * Get the persistent identifier for this DataView. |
---|
81 | * |
---|
82 | * @return a persistent identifier or <code>null</code> of this DataView has |
---|
83 | * none |
---|
84 | */ |
---|
85 | public String getPid() { |
---|
86 | return pid; |
---|
87 | } |
---|
88 | |
---|
89 | |
---|
90 | /** |
---|
91 | * Get the reference URI for this DataView. |
---|
92 | * |
---|
93 | * @return a reference URI or <code>null</code> of this DataView has |
---|
94 | * none |
---|
95 | */ |
---|
96 | public String getRef() { |
---|
97 | return ref; |
---|
98 | } |
---|
99 | |
---|
100 | } // abstract class DataView |
---|