source: SRUClient/tags/SRUClient-0.9.5/src/main/java/eu/clarin/sru/client/fcs/ClarinFCSEndpointDescription.java @ 6079

Last change on this file since 6079 was 6079, checked in by Oliver Schonefeld, 9 years ago
  • tag version 0.9.5
  • Property svn:eol-style set to native
File size: 11.5 KB
Line 
1package eu.clarin.sru.client.fcs;
2
3import java.io.Serializable;
4import java.net.URI;
5import java.util.Collections;
6import java.util.List;
7import java.util.Map;
8
9import javax.xml.namespace.QName;
10
11import eu.clarin.sru.client.SRUExtraResponseData;
12
13
14public 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    /**
55     * Get the version of this endpoint description.
56     *
57     * @return the version of the endpoint description
58     */
59    public int getVersion() {
60        return version;
61    }
62
63
64    /**
65     * Get the list of capabilities supported by this endpoint. The list
66     * contains the appropriate URIs defined by the CLARIN-FCS specification to
67     * indicate support for certain capabilities.
68     *
69     * @return the list of capabilities supported by this endpoint
70     */
71    public List<URI> getCapabilities() {
72        return capabilites;
73    }
74
75
76    /**
77     * Get the list of data views supported by this endpoint.
78     *
79     * @return the list of data views supported by this endpoint
80     */
81    public List<DataView> getSupportedDataViews() {
82        return supportedDataViews;
83    }
84
85
86    /**
87     * Get the list of top-level resources of this endpoint.
88     *
89     * @return the list of top-level resources of this endpoint
90     */
91    public List<ResourceInfo> getResources() {
92        return resources;
93    }
94
95
96    /**
97     * This class implements a description of a data view supported by the endpoint.
98     */
99    public static final class DataView implements Serializable {
100        private static final long serialVersionUID = -5628565233032672627L;
101
102
103        /**
104         * Enumeration to indicate the delivery policy of a data view.
105         */
106        public enum DeliveryPolicy {
107            /**
108             * The data view is sent automatically  by the endpoint.
109             */
110            SEND_BY_DEFAULT,
111            /**
112             * A client must explicitly request the endpoint.
113             */
114            NEED_TO_REQUEST;
115        } // enum PayloadDelivery
116        private final String identifier;
117        private final String mimeType;
118        private final DeliveryPolicy deliveryPolicy;
119
120
121        /**
122         * Constructor. <em>Internal use only!</em>
123         */
124        DataView(String identifier, String mimeType,
125                DeliveryPolicy deliveryPolicy) {
126            if (identifier == null) {
127                throw new NullPointerException("identifier == null");
128            }
129            if (identifier.isEmpty()) {
130                throw new IllegalArgumentException("identifier is empty");
131            }
132            this.identifier = identifier;
133
134            if (mimeType == null) {
135                throw new NullPointerException("mimeType == null");
136            }
137            if (mimeType.isEmpty()) {
138                throw new IllegalArgumentException("mimeType is empty");
139            }
140            this.mimeType = mimeType;
141
142            if (deliveryPolicy == null) {
143                throw new NullPointerException("deliveryPolicy == null");
144            }
145            this.deliveryPolicy = deliveryPolicy;
146        }
147
148
149        /**
150         * Get the identifier of this data view.
151         *
152         * @return the identifier of the data view
153         */
154        public String getIdentifier() {
155            return identifier;
156        }
157
158
159        /**
160         * Get the MIME type of this data view.
161         *
162         * @return the MIME type of this data view
163         */
164        public String getMimeType() {
165            return mimeType;
166        }
167
168
169        /**
170         * Get the delivery policy for this data view.
171         *
172         * @return the delivery policy of this data view
173         * @see DeliveryPolicy
174         */
175        public DeliveryPolicy getDeliveryPolicy() {
176            return deliveryPolicy;
177        }
178
179
180        @Override
181        public String toString() {
182            StringBuilder sb = new StringBuilder();
183            sb.append(getClass().getSimpleName());
184            sb.append("[");
185            sb.append("identifier=").append(identifier);
186            sb.append(", mimeType=").append(mimeType);
187            sb.append("]");
188            return sb.toString();
189        }
190
191    } // class DataView
192
193
194    /**
195     * This class implements a description of a resource available at an
196     * endpoint.
197     */
198    public static final class ResourceInfo implements Serializable {
199        private static final long serialVersionUID = 1046130188435071544L;
200        private final String pid;
201        private final Map<String, String> title;
202        private final Map<String, String> description;
203        private final String landingPageURI;
204        private final List<String> languages;
205        private final List<DataView> availableDataViews;
206        private final List<ResourceInfo> subResources;
207
208
209        /**
210         * Constructor. <em>Internal use only!</em>
211         */
212        ResourceInfo(String pid, Map<String, String> title,
213                Map<String, String> description, String landingPageURI,
214                List<String> languages, List<DataView> availableDataViews,
215                List<ResourceInfo> subResources) {
216            if (pid == null) {
217                throw new NullPointerException("pid == null");
218            }
219            this.pid = pid;
220
221            if (title == null) {
222                throw new NullPointerException("title == null");
223            }
224            if (title.isEmpty()) {
225                throw new IllegalArgumentException("title is empty");
226            }
227            this.title = Collections.unmodifiableMap(title);
228            if ((description != null) && !description.isEmpty()) {
229                this.description = Collections.unmodifiableMap(description);
230            } else {
231                this.description = null;
232            }
233
234            this.landingPageURI = landingPageURI;
235            if (languages == null) {
236                throw new NullPointerException("languages == null");
237            }
238            if (languages.isEmpty()) {
239                throw new IllegalArgumentException("languages is empty");
240            }
241            this.languages = languages;
242
243            if (availableDataViews == null) {
244                throw new IllegalArgumentException("availableDataViews == null");
245            }
246            this.availableDataViews =
247                    Collections.unmodifiableList(availableDataViews);
248
249            if ((subResources != null) && !subResources.isEmpty()) {
250                this.subResources = Collections.unmodifiableList(subResources);
251            } else {
252                this.subResources = null;
253            }
254        }
255
256
257        /**
258         * Get the persistent identifier of this resource.
259         *
260         * @return a string representing the persistent identifier of this resource
261         */
262        public String getPid() {
263            return pid;
264        }
265
266
267        /**
268         * Determine, if this resource has sub-resources.
269         *
270         * @return <code>true</code> if the resource has sub-resources,
271         *         <code>false</code> otherwise
272         */
273        public boolean hasSubResources() {
274            return subResources != null;
275        }
276
277
278        /**
279         * Get the title of this resource.
280         *
281         * @return a Map of titles keyed by language code
282         */
283        public Map<String, String> getTitle() {
284            return title;
285        }
286
287
288        /**
289         * Get the title of the resource for a specific language code.
290         *
291         * @param language
292         *            the language code
293         * @return the title for the language code or <code>null</code> if no title
294         *         for this language code exists
295         */
296        public String getTitle(String language) {
297            return title.get(language);
298        }
299
300
301        /**
302         * Get the description of this resource.
303         *
304         * @return a Map of descriptions keyed by language code
305         */
306        public Map<String, String> getDescription() {
307            return description;
308        }
309
310
311        /**
312         * Get the description of the resource for a specific language code.
313         *
314         * @param language
315         *            the language code
316         * @return the description for the language code or <code>null</code> if no
317         *         title for this language code exists
318         */
319        public String getDescription(String language) {
320            return (description != null) ? description.get(language) : null;
321        }
322
323
324        /**
325         * Get the landing page of this resource.
326         *
327         * @return the landing page of this resource or <code>null</code> if not
328         *         applicable
329         */
330        public String getLandingPageURI() {
331            return landingPageURI;
332        }
333
334
335        /**
336         * Get the list of languages in this resource represented as ISO-632-3 three
337         * letter language code.
338         *
339         * @return the list of languages in this resource as a list of ISO-632-3
340         *         three letter language codes.
341         */
342        public List<String> getLanguages() {
343            return languages;
344        }
345
346
347        /**
348         * Check, if this resource supports a certain language.
349         *
350         * @param language
351         *            a language encoded as a ISO-632-3 three letter language
352         *            code
353         * @return <code>true</code> if the language is supported by this
354         *         resource, <code>false</code> otherwise
355         */
356        public boolean supportsLanguage(String language) {
357            if (language == null) {
358                throw new NullPointerException("language == null");
359            }
360            for (String l : languages) {
361                if (language.equals(l)) {
362                    return true;
363                }
364            }
365            return false;
366        }
367
368
369        /**
370         * Get the direct sub-ordinate resources of this resource.
371         *
372         * @return a list of resources or <code>null</code> if this resource has
373         *         no sub-ordinate resources
374         */
375        public List<ResourceInfo> getSubResources() {
376            return subResources;
377        }
378
379
380        public List<DataView> getAvailableDataViews() {
381            return availableDataViews;
382        }
383
384    } // class ResourceInfo
385
386} // class ClarinFCSEndpointDescription
Note: See TracBrowser for help on using the repository browser.