source: FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/ResourceInfo.java @ 5546

Last change on this file since 5546 was 5546, checked in by Oliver Schonefeld, 10 years ago
  • support new FCS specification (with some backwards compatibility for old spec)

HEADS UP: not yet ready for release; needs more testing

  • Property svn:eol-style set to native
File size: 5.8 KB
Line 
1package eu.clarin.sru.server.fcs;
2
3import java.util.Collections;
4import java.util.List;
5import java.util.Map;
6
7
8/**
9 * This class implements a resource info record, which provides supplementary
10 * information about a resource that is available at the endpoint.
11 *
12 * @see EndpointDescription
13 */
14public class ResourceInfo {
15    private final String pid;
16    private final Map<String, String> title;
17    private final Map<String, String> description;
18    private final String landingPageURI;
19    private final List<String> languages;
20    private final List<DataView> availableDataViews;
21    private final List<ResourceInfo> subResources;
22
23
24    /**
25     * Constructor.
26     *
27     * @param pid
28     *            the persistent identifier of the resource
29     * @param title
30     *            the title of the resource represented as a map with pairs of
31     *            language code and title
32     * @param description
33     *            the description of the resource represented as a map with
34     *            pairs of language code and description or <code>null</code> if
35     *            not applicable
36     * @param landingPageURI
37     *            a URI to the landing page of the resource or <code>null</code>
38     *            if not applicable
39     * @param languages
40     *            the languages represented within this resource represented as
41     *            a list of ISO-632-3 three letter language codes
42     * @param availableDataViews
43     *            the list of available data views for this resource
44     * @param subResources
45     *            a list of resource sub-ordinate to this resource or
46     *            <code>null</code> if not applicable
47     */
48    public ResourceInfo(String pid, Map<String, String> title,
49            Map<String, String> description, String landingPageURI,
50            List<String> languages, List<DataView> availableDataViews,
51            List<ResourceInfo> subResources) {
52        if (pid == null) {
53            throw new NullPointerException("pid == null");
54        }
55        this.pid = pid;
56
57        if (title == null) {
58            throw new NullPointerException("title == null");
59        }
60        if (title.isEmpty()) {
61            throw new IllegalArgumentException("title is empty");
62        }
63        this.title = Collections.unmodifiableMap(title);
64        if ((description != null) && !description.isEmpty()) {
65            this.description = Collections.unmodifiableMap(description);
66        } else {
67            this.description = null;
68        }
69
70        this.landingPageURI = landingPageURI;
71        if (languages == null) {
72            throw new NullPointerException("languages == null");
73        }
74        if (languages.isEmpty()) {
75            throw new IllegalArgumentException("languages is empty");
76        }
77        this.languages = languages;
78
79        if (availableDataViews == null) {
80            throw new IllegalArgumentException("availableDataViews == null");
81        }
82        this.availableDataViews =
83                Collections.unmodifiableList(availableDataViews);
84
85        if ((subResources != null) && !subResources.isEmpty()) {
86            this.subResources = Collections.unmodifiableList(subResources);
87        } else {
88            this.subResources = null;
89        }
90    }
91
92
93    /**
94     * Get the persistent identifier of this resource.
95     *
96     * @return a string representing the persistent identifier of this resource
97     */
98    public String getPid() {
99        return pid;
100    }
101
102
103    /**
104     * Determine, if this resource has sub-resources.
105     *
106     * @return <code>true</code> if the resource has sub-resources,
107     *         <code>false</code> otherwise
108     */
109    public boolean hasSubResources() {
110        return subResources != null;
111    }
112
113
114    /**
115     * Get the title of this resource.
116     *
117     * @return a Map of titles keyed by language code
118     */
119    public Map<String, String> getTitle() {
120        return title;
121    }
122
123
124    /**
125     * Get the title of the resource for a specific language code.
126     *
127     * @param language
128     *            the language code
129     * @return the title for the language code or <code>null</code> if no title
130     *         for this language code exists
131     */
132    public String getTitle(String language) {
133        return title.get(language);
134    }
135
136
137    /**
138     * Get the description of this resource.
139     *
140     * @return a Map of descriptions keyed by language code
141     */
142    public Map<String, String> getDescription() {
143        return description;
144    }
145
146
147    /**
148     * Get the description of the resource for a specific language code.
149     *
150     * @param language
151     *            the language code
152     * @return the description for the language code or <code>null</code> if no
153     *         title for this language code exists
154     */
155    public String getDescription(String language) {
156        return (description != null) ? description.get(language) : null;
157    }
158
159
160    /**
161     * Get the landing page of this resource.
162     *
163     * @return the landing page of this resource or <code>null</code> if not
164     *         applicable
165     */
166    public String getLandingPageURI() {
167        return landingPageURI;
168    }
169
170
171    /**
172     * Get the list of languages in this resource represented as ISO-632-3 three
173     * letter language code.
174     *
175     * @return the list of languages in this resource as a list of ISO-632-3
176     *         three letter language codes.
177     */
178    public List<String> getLanguages() {
179        return languages;
180    }
181
182
183    /**
184     * Get the direct sub-ordinate resources of this resource.
185     *
186     * @return a list of resources or <code>null</code> if this resource has no
187     *         sub-ordinate resources
188     */
189    public List<ResourceInfo> getSubResources() {
190        return subResources;
191    }
192
193
194        public List<DataView> getAvailableDataViews() {
195                return availableDataViews;
196        }
197
198} // class ResourceInfo
Note: See TracBrowser for help on using the repository browser.