1 | package eu.clarin.sru.client.fcs; |
---|
2 | |
---|
3 | import java.io.Serializable; |
---|
4 | import java.net.URI; |
---|
5 | import java.util.Collections; |
---|
6 | import java.util.List; |
---|
7 | import java.util.Map; |
---|
8 | |
---|
9 | import javax.xml.namespace.QName; |
---|
10 | |
---|
11 | import eu.clarin.sru.client.SRUExtraResponseData; |
---|
12 | |
---|
13 | |
---|
14 | public class ClarinFCSEndpointDescription implements Serializable, |
---|
15 | SRUExtraResponseData { |
---|
16 | private static final long serialVersionUID = 9061228238942949036L; |
---|
17 | private static final QName ROOT_ELEMENT = |
---|
18 | new QName("http://clarin.eu/fcs/endpoint-description", |
---|
19 | "EndpointDescription"); |
---|
20 | private final int version; |
---|
21 | private final List<URI> capabilites; |
---|
22 | private final List<DataView> supportedDataViews; |
---|
23 | private final List<ResourceInfo> resources; |
---|
24 | |
---|
25 | |
---|
26 | ClarinFCSEndpointDescription(int version, List<URI> capabilites, |
---|
27 | List<DataView> supportedDataViews, List<ResourceInfo> resources) { |
---|
28 | this.version = version; |
---|
29 | if ((capabilites != null) && !capabilites.isEmpty()) { |
---|
30 | this.capabilites = Collections.unmodifiableList(capabilites); |
---|
31 | } else { |
---|
32 | this.capabilites = Collections.emptyList(); |
---|
33 | } |
---|
34 | if ((supportedDataViews != null) && !supportedDataViews.isEmpty()) { |
---|
35 | this.supportedDataViews = |
---|
36 | Collections.unmodifiableList(supportedDataViews); |
---|
37 | } else { |
---|
38 | this.supportedDataViews = Collections.emptyList(); |
---|
39 | } |
---|
40 | if ((resources != null) && !resources.isEmpty()) { |
---|
41 | this.resources = Collections.unmodifiableList(resources); |
---|
42 | } else { |
---|
43 | this.resources = Collections.emptyList(); |
---|
44 | } |
---|
45 | } |
---|
46 | |
---|
47 | |
---|
48 | @Override |
---|
49 | public QName getRootElement() { |
---|
50 | return ROOT_ELEMENT; |
---|
51 | } |
---|
52 | |
---|
53 | |
---|
54 | public int getVersion() { |
---|
55 | return version; |
---|
56 | } |
---|
57 | |
---|
58 | |
---|
59 | public List<URI> getCapabilities() { |
---|
60 | return capabilites; |
---|
61 | } |
---|
62 | |
---|
63 | |
---|
64 | public List<DataView> getSupportedDataViews() { |
---|
65 | return supportedDataViews; |
---|
66 | } |
---|
67 | |
---|
68 | |
---|
69 | public List<ResourceInfo> getResources() { |
---|
70 | return resources; |
---|
71 | } |
---|
72 | |
---|
73 | |
---|
74 | public static class DataView implements Serializable { |
---|
75 | private static final long serialVersionUID = -5628565233032672627L; |
---|
76 | |
---|
77 | |
---|
78 | /** |
---|
79 | * Enumeration to indicate the delivery policy of a data view. |
---|
80 | */ |
---|
81 | public enum DeliveryPolicy { |
---|
82 | /** |
---|
83 | * The data view is sent automatically by the endpoint. |
---|
84 | */ |
---|
85 | SEND_BY_DEFAULT, |
---|
86 | /** |
---|
87 | * A client must explicitly request the endpoint. |
---|
88 | */ |
---|
89 | NEED_TO_REQUEST; |
---|
90 | } // enum PayloadDelivery |
---|
91 | private final String identifier; |
---|
92 | private final String mimeType; |
---|
93 | private final DeliveryPolicy deliveryPolicy; |
---|
94 | |
---|
95 | |
---|
96 | DataView(String identifier, String mimeType, |
---|
97 | DeliveryPolicy deliveryPolicy) { |
---|
98 | if (identifier == null) { |
---|
99 | throw new NullPointerException("identifier == null"); |
---|
100 | } |
---|
101 | if (identifier.isEmpty()) { |
---|
102 | throw new IllegalArgumentException("identifier is empty"); |
---|
103 | } |
---|
104 | this.identifier = identifier; |
---|
105 | |
---|
106 | if (mimeType == null) { |
---|
107 | throw new NullPointerException("mimeType == null"); |
---|
108 | } |
---|
109 | if (mimeType.isEmpty()) { |
---|
110 | throw new IllegalArgumentException("mimeType is empty"); |
---|
111 | } |
---|
112 | this.mimeType = mimeType; |
---|
113 | |
---|
114 | if (deliveryPolicy == null) { |
---|
115 | throw new NullPointerException("deliveryPolicy == null"); |
---|
116 | } |
---|
117 | this.deliveryPolicy = deliveryPolicy; |
---|
118 | } |
---|
119 | |
---|
120 | |
---|
121 | /** |
---|
122 | * Get the identifier of this data view. |
---|
123 | * |
---|
124 | * @return the identifier of the data view |
---|
125 | */ |
---|
126 | public String getIdentifier() { |
---|
127 | return identifier; |
---|
128 | } |
---|
129 | |
---|
130 | |
---|
131 | /** |
---|
132 | * Get the MIME type of this data view. |
---|
133 | * |
---|
134 | * @return the MIME type of this data view |
---|
135 | */ |
---|
136 | public String getMimeType() { |
---|
137 | return mimeType; |
---|
138 | } |
---|
139 | |
---|
140 | |
---|
141 | /** |
---|
142 | * Get the delivery policy for this data view. |
---|
143 | * |
---|
144 | * @return the delivery policy of this data view |
---|
145 | * @see DeliveryPolicy |
---|
146 | */ |
---|
147 | public DeliveryPolicy getDeliveryPolicy() { |
---|
148 | return deliveryPolicy; |
---|
149 | } |
---|
150 | |
---|
151 | |
---|
152 | @Override |
---|
153 | public String toString() { |
---|
154 | StringBuilder sb = new StringBuilder(); |
---|
155 | sb.append(getClass().getSimpleName()); |
---|
156 | sb.append("["); |
---|
157 | sb.append("identifier=").append(identifier); |
---|
158 | sb.append(", mimeType=").append(mimeType); |
---|
159 | sb.append("]"); |
---|
160 | return sb.toString(); |
---|
161 | } |
---|
162 | |
---|
163 | } // class DataView |
---|
164 | |
---|
165 | |
---|
166 | public static class ResourceInfo implements Serializable { |
---|
167 | private static final long serialVersionUID = 1046130188435071544L; |
---|
168 | private final String pid; |
---|
169 | private final Map<String, String> title; |
---|
170 | private final Map<String, String> description; |
---|
171 | private final String landingPageURI; |
---|
172 | private final List<String> languages; |
---|
173 | private final List<DataView> availableDataViews; |
---|
174 | private final List<ResourceInfo> subResources; |
---|
175 | |
---|
176 | |
---|
177 | ResourceInfo(String pid, Map<String, String> title, |
---|
178 | Map<String, String> description, String landingPageURI, |
---|
179 | List<String> languages, List<DataView> availableDataViews, |
---|
180 | List<ResourceInfo> subResources) { |
---|
181 | if (pid == null) { |
---|
182 | throw new NullPointerException("pid == null"); |
---|
183 | } |
---|
184 | this.pid = pid; |
---|
185 | |
---|
186 | if (title == null) { |
---|
187 | throw new NullPointerException("title == null"); |
---|
188 | } |
---|
189 | if (title.isEmpty()) { |
---|
190 | throw new IllegalArgumentException("title is empty"); |
---|
191 | } |
---|
192 | this.title = Collections.unmodifiableMap(title); |
---|
193 | if ((description != null) && !description.isEmpty()) { |
---|
194 | this.description = Collections.unmodifiableMap(description); |
---|
195 | } else { |
---|
196 | this.description = null; |
---|
197 | } |
---|
198 | |
---|
199 | this.landingPageURI = landingPageURI; |
---|
200 | if (languages == null) { |
---|
201 | throw new NullPointerException("languages == null"); |
---|
202 | } |
---|
203 | if (languages.isEmpty()) { |
---|
204 | throw new IllegalArgumentException("languages is empty"); |
---|
205 | } |
---|
206 | this.languages = languages; |
---|
207 | |
---|
208 | if (availableDataViews == null) { |
---|
209 | throw new IllegalArgumentException("availableDataViews == null"); |
---|
210 | } |
---|
211 | this.availableDataViews = |
---|
212 | Collections.unmodifiableList(availableDataViews); |
---|
213 | |
---|
214 | if ((subResources != null) && !subResources.isEmpty()) { |
---|
215 | this.subResources = Collections.unmodifiableList(subResources); |
---|
216 | } else { |
---|
217 | this.subResources = null; |
---|
218 | } |
---|
219 | } |
---|
220 | |
---|
221 | |
---|
222 | /** |
---|
223 | * Get the persistent identifier of this resource. |
---|
224 | * |
---|
225 | * @return a string representing the persistent identifier of this resource |
---|
226 | */ |
---|
227 | public String getPid() { |
---|
228 | return pid; |
---|
229 | } |
---|
230 | |
---|
231 | |
---|
232 | /** |
---|
233 | * Determine, if this resource has sub-resources. |
---|
234 | * |
---|
235 | * @return <code>true</code> if the resource has sub-resources, |
---|
236 | * <code>false</code> otherwise |
---|
237 | */ |
---|
238 | public boolean hasSubResources() { |
---|
239 | return subResources != null; |
---|
240 | } |
---|
241 | |
---|
242 | |
---|
243 | /** |
---|
244 | * Get the title of this resource. |
---|
245 | * |
---|
246 | * @return a Map of titles keyed by language code |
---|
247 | */ |
---|
248 | public Map<String, String> getTitle() { |
---|
249 | return title; |
---|
250 | } |
---|
251 | |
---|
252 | |
---|
253 | /** |
---|
254 | * Get the title of the resource for a specific language code. |
---|
255 | * |
---|
256 | * @param language |
---|
257 | * the language code |
---|
258 | * @return the title for the language code or <code>null</code> if no title |
---|
259 | * for this language code exists |
---|
260 | */ |
---|
261 | public String getTitle(String language) { |
---|
262 | return title.get(language); |
---|
263 | } |
---|
264 | |
---|
265 | |
---|
266 | /** |
---|
267 | * Get the description of this resource. |
---|
268 | * |
---|
269 | * @return a Map of descriptions keyed by language code |
---|
270 | */ |
---|
271 | public Map<String, String> getDescription() { |
---|
272 | return description; |
---|
273 | } |
---|
274 | |
---|
275 | |
---|
276 | /** |
---|
277 | * Get the description of the resource for a specific language code. |
---|
278 | * |
---|
279 | * @param language |
---|
280 | * the language code |
---|
281 | * @return the description for the language code or <code>null</code> if no |
---|
282 | * title for this language code exists |
---|
283 | */ |
---|
284 | public String getDescription(String language) { |
---|
285 | return (description != null) ? description.get(language) : null; |
---|
286 | } |
---|
287 | |
---|
288 | |
---|
289 | /** |
---|
290 | * Get the landing page of this resource. |
---|
291 | * |
---|
292 | * @return the landing page of this resource or <code>null</code> if not |
---|
293 | * applicable |
---|
294 | */ |
---|
295 | public String getLandingPageURI() { |
---|
296 | return landingPageURI; |
---|
297 | } |
---|
298 | |
---|
299 | |
---|
300 | /** |
---|
301 | * Get the list of languages in this resource represented as ISO-632-3 three |
---|
302 | * letter language code. |
---|
303 | * |
---|
304 | * @return the list of languages in this resource as a list of ISO-632-3 |
---|
305 | * three letter language codes. |
---|
306 | */ |
---|
307 | public List<String> getLanguages() { |
---|
308 | return languages; |
---|
309 | } |
---|
310 | |
---|
311 | |
---|
312 | /** |
---|
313 | * Get the direct sub-ordinate resources of this resource. |
---|
314 | * |
---|
315 | * @return a list of resources or <code>null</code> if this resource has no |
---|
316 | * sub-ordinate resources |
---|
317 | */ |
---|
318 | public List<ResourceInfo> getSubResources() { |
---|
319 | return subResources; |
---|
320 | } |
---|
321 | |
---|
322 | |
---|
323 | public List<DataView> getAvailableDataViews() { |
---|
324 | return availableDataViews; |
---|
325 | } |
---|
326 | |
---|
327 | } // class ResourceInfo |
---|
328 | |
---|
329 | } // class ClarinFCSEndpointDescription |
---|