1 | package eu.clarin.cmdi.virtualcollectionregistry.model; |
---|
2 | |
---|
3 | import java.net.URI; |
---|
4 | import java.util.ArrayList; |
---|
5 | import java.util.Date; |
---|
6 | import java.util.List; |
---|
7 | |
---|
8 | import javax.xml.bind.annotation.XmlAccessType; |
---|
9 | import javax.xml.bind.annotation.XmlAccessorType; |
---|
10 | import javax.xml.bind.annotation.XmlAttribute; |
---|
11 | import javax.xml.bind.annotation.XmlElement; |
---|
12 | import javax.xml.bind.annotation.XmlElementWrapper; |
---|
13 | import javax.xml.bind.annotation.XmlElements; |
---|
14 | import javax.xml.bind.annotation.XmlRootElement; |
---|
15 | import javax.xml.bind.annotation.XmlType; |
---|
16 | import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; |
---|
17 | |
---|
18 | import eu.clarin.cmdi.virtualcollectionregistry.model.mapper.DateAdapter; |
---|
19 | |
---|
20 | @XmlAccessorType(XmlAccessType.NONE) |
---|
21 | @XmlType(namespace = "urn:x-vcr:clarin-virtualcollection", |
---|
22 | propOrder = { "header", "resources", "components" }) |
---|
23 | @XmlRootElement(name = "CMD") |
---|
24 | public class ClarinVirtualCollection { |
---|
25 | @XmlAccessorType(XmlAccessType.NONE) |
---|
26 | @XmlType(namespace = "urn:x-vcr:clarin-virtualcollection:header", |
---|
27 | propOrder = { "creator", "creationDate", "selfLink", "profile" }) |
---|
28 | public static class Header { |
---|
29 | private ClarinVirtualCollection cvc; |
---|
30 | |
---|
31 | private Header() { |
---|
32 | } |
---|
33 | |
---|
34 | private Header(ClarinVirtualCollection cvc) { |
---|
35 | this.cvc = cvc; |
---|
36 | } |
---|
37 | |
---|
38 | @XmlElement(name = "MdCreator") |
---|
39 | public String getCreator() { |
---|
40 | return cvc.getVirtualCollection().getOwner().getName(); |
---|
41 | } |
---|
42 | |
---|
43 | @XmlElement(name = "MdCreationDate") |
---|
44 | @XmlJavaTypeAdapter(DateAdapter.class) |
---|
45 | public Date getCreationDate() { |
---|
46 | return cvc.getVirtualCollection().getCreatedDate(); |
---|
47 | } |
---|
48 | |
---|
49 | @XmlElement(name = "MdSelfLink") |
---|
50 | public URI getSelfLink() { |
---|
51 | return cvc.getVirtualCollection() |
---|
52 | .getPersistentIdentifier() |
---|
53 | .createURI(); |
---|
54 | } |
---|
55 | |
---|
56 | @XmlElement(name = "MdProfile") |
---|
57 | public String getProfile() { |
---|
58 | return "http://url/to/mdprofile"; |
---|
59 | } |
---|
60 | } // inner class Header |
---|
61 | |
---|
62 | @XmlAccessorType(XmlAccessType.NONE) |
---|
63 | @XmlType(namespace = "urn:x-vcr:clarin-virtualcollection:resources") |
---|
64 | public static class Resources { |
---|
65 | @XmlAccessorType(XmlAccessType.NONE) |
---|
66 | @XmlType(namespace = "urn:x-vcr:clarin-virtualcollection:resources:proxy", |
---|
67 | propOrder = { "type", "ref" }) |
---|
68 | public static class Proxy { |
---|
69 | private Resource resource; |
---|
70 | |
---|
71 | private Proxy() { |
---|
72 | } |
---|
73 | |
---|
74 | private Proxy(Resource resource) { |
---|
75 | this.resource = resource; |
---|
76 | } |
---|
77 | |
---|
78 | @XmlAttribute(name = "id") |
---|
79 | public String getId() { |
---|
80 | return resource.getIdForXml(); |
---|
81 | } |
---|
82 | |
---|
83 | @XmlElement(name = "ResourceType") |
---|
84 | public ResourceType getType() { |
---|
85 | return resource.getType(); |
---|
86 | } |
---|
87 | |
---|
88 | @XmlElement(name = "ResourceRef") |
---|
89 | public String getRef() { |
---|
90 | return resource.getRef(); |
---|
91 | } |
---|
92 | } // inner class Proxy |
---|
93 | private List<Proxy> proxies = new ArrayList<Proxy>(); |
---|
94 | |
---|
95 | private Resources() { |
---|
96 | } |
---|
97 | |
---|
98 | private Resources(ClarinVirtualCollection cvc) { |
---|
99 | for (Resource r : cvc.getVirtualCollection().getResources()) { |
---|
100 | proxies.add(new Proxy(r)); |
---|
101 | } |
---|
102 | } |
---|
103 | |
---|
104 | @XmlElementWrapper(name = "ResourceProxyList") |
---|
105 | @XmlElements( { @XmlElement(name = "ResourceProxy") }) |
---|
106 | public List<Proxy> getResourceProxyList() { |
---|
107 | return proxies; |
---|
108 | } |
---|
109 | } // inner class Resources |
---|
110 | |
---|
111 | @XmlAccessorType(XmlAccessType.NONE) |
---|
112 | @XmlType(namespace = "urn:x-vcr:clarin-virtualcollection:components") |
---|
113 | public static class Components { |
---|
114 | @XmlAccessorType(XmlAccessType.NONE) |
---|
115 | @XmlType(namespace = "urn:x-vcr:clarin-virtualcollection:components:vc", |
---|
116 | propOrder = { "name", "description", "creationDate", "visibility", "origin", "creator" }) |
---|
117 | public static class VC { |
---|
118 | private VirtualCollection vc; |
---|
119 | |
---|
120 | private void init(VirtualCollection vc) { |
---|
121 | this.vc = vc; |
---|
122 | } |
---|
123 | |
---|
124 | @XmlElement(name = "Name") |
---|
125 | public String getName() { |
---|
126 | return vc.getName(); |
---|
127 | } |
---|
128 | |
---|
129 | @XmlElement(name = "Description") |
---|
130 | public String getDescription() { |
---|
131 | return vc.getDescription(); |
---|
132 | } |
---|
133 | |
---|
134 | @XmlElement(name = "CreationDate") |
---|
135 | @XmlJavaTypeAdapter(DateAdapter.class) |
---|
136 | public Date getCreationDate() { |
---|
137 | return vc.getCreationDate(); |
---|
138 | } |
---|
139 | |
---|
140 | @XmlElement(name = "Visibility") |
---|
141 | public VirtualCollection.Visibility getVisibility() { |
---|
142 | return vc.getVisibility(); |
---|
143 | } |
---|
144 | |
---|
145 | @XmlElement(name = "Origin") |
---|
146 | public String getOrigin() { |
---|
147 | return vc.getOrigin(); |
---|
148 | } |
---|
149 | |
---|
150 | @XmlElement(name = "Creator") |
---|
151 | public Creator getCreator() { |
---|
152 | return vc.getCreator(); |
---|
153 | } |
---|
154 | } |
---|
155 | private ClarinVirtualCollection cvc; |
---|
156 | private VC vc = new VC(); |
---|
157 | |
---|
158 | private Components() { |
---|
159 | } |
---|
160 | |
---|
161 | private Components(ClarinVirtualCollection cvc) { |
---|
162 | this.cvc = cvc; |
---|
163 | this.vc.init(this.cvc.getVirtualCollection()); |
---|
164 | } |
---|
165 | |
---|
166 | @XmlElement(name = "VirtualCollection") |
---|
167 | public VC getVirtualCollection() { |
---|
168 | return vc; |
---|
169 | } |
---|
170 | } |
---|
171 | |
---|
172 | private VirtualCollection vc; |
---|
173 | private Header header; |
---|
174 | private Resources resources; |
---|
175 | private Components components; |
---|
176 | |
---|
177 | @SuppressWarnings("unused") |
---|
178 | private ClarinVirtualCollection() { |
---|
179 | super(); |
---|
180 | } |
---|
181 | |
---|
182 | public ClarinVirtualCollection(VirtualCollection vc) { |
---|
183 | if (vc == null) { |
---|
184 | throw new NullPointerException("vc == null"); |
---|
185 | } |
---|
186 | this.vc = vc; |
---|
187 | this.header = new Header(this); |
---|
188 | this.resources = new Resources(this); |
---|
189 | this.components = new Components(this); |
---|
190 | } |
---|
191 | |
---|
192 | VirtualCollection getVirtualCollection() { |
---|
193 | return vc; |
---|
194 | } |
---|
195 | |
---|
196 | @XmlElement(name = "Header") |
---|
197 | public Header getHeader() { |
---|
198 | return header; |
---|
199 | } |
---|
200 | |
---|
201 | @XmlElement(name = "Resources") |
---|
202 | public Resources getResources() { |
---|
203 | return resources; |
---|
204 | } |
---|
205 | |
---|
206 | @XmlElement(name = "Components") |
---|
207 | public Components getComponents() { |
---|
208 | return components; |
---|
209 | } |
---|
210 | } |
---|