1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.mycore.datamodel.metadata;
20
21 import java.util.Objects;
22
23 import org.jdom2.Element;
24 import org.mycore.common.MCRException;
25
26 import com.fasterxml.jackson.annotation.JsonClassDescription;
27 import com.fasterxml.jackson.annotation.JsonIgnore;
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 @JsonClassDescription("Links to other objects or derivates")
48 public class MCRMetaLinkID extends MCRMetaLink {
49
50
51
52 public MCRMetaLinkID() {
53 super();
54 }
55
56
57
58
59
60 public MCRMetaLinkID(String subtag, int inherted) {
61 super(subtag, inherted);
62 }
63
64
65
66
67
68
69
70 public MCRMetaLinkID(String subtag, MCRObjectID id, String label, String title) {
71 this(subtag, id, label, title, null);
72 }
73
74
75
76
77
78 public MCRMetaLinkID(String subtag, MCRObjectID id, String label, String title, String role) {
79 this(subtag, 0);
80 setReference(id, label, title);
81 setXLinkRole(role);
82 }
83
84
85
86
87
88
89
90
91
92
93
94
95
96 @Override
97 public final void setReference(String href, String label, String title) throws MCRException {
98 try {
99 MCRObjectID hrefid = MCRObjectID.getInstance(href);
100 super.setReference(hrefid.toString(), label, title);
101 } catch (Exception e) {
102 throw new MCRException("The href value is not a MCRObjectID: " + href, e);
103 }
104 }
105
106
107
108
109
110
111
112
113
114
115
116
117
118 public final void setReference(MCRObjectID href, String label, String title) throws MCRException {
119 if (href == null) {
120 throw new MCRException("The href value is null.");
121 }
122
123 super.setReference(href.toString(), label, title);
124 }
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139 @Override
140 public final void setBiLink(String from, String to, String title) throws MCRException {
141 try {
142 MCRObjectID fromid = MCRObjectID.getInstance(from);
143 MCRObjectID toid = MCRObjectID.getInstance(to);
144 super.setBiLink(fromid.toString(), toid.toString(), title);
145 } catch (Exception e) {
146 linktype = null;
147 throw new MCRException("The from/to value is not a MCRObjectID.");
148 }
149 }
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164 public final void setBiLink(MCRObjectID from, MCRObjectID to, String title) throws MCRException {
165 if (from == null || to == null) {
166 throw new MCRException("The from/to value is null.");
167 }
168
169 super.setBiLink(from.toString(), to.toString(), title);
170 }
171
172
173
174
175
176
177 @JsonIgnore
178 public final MCRObjectID getXLinkHrefID() {
179 return MCRObjectID.getInstance(href);
180 }
181
182
183
184
185
186
187 @JsonIgnore
188 public final MCRObjectID getXLinkFromID() {
189 return MCRObjectID.getInstance(from);
190 }
191
192
193
194
195
196
197 @JsonIgnore
198 public final MCRObjectID getXLinkToID() {
199 return MCRObjectID.getInstance(to);
200 }
201
202
203
204
205
206
207
208
209
210
211
212 @Override
213 public void setFromDOM(Element element) {
214 super.setFromDOM(element);
215
216 if (linktype.equals("locator")) {
217 try {
218 MCRObjectID hrefid = MCRObjectID.getInstance(href);
219 href = hrefid.toString();
220 } catch (Exception e) {
221 throw new MCRException("The xlink:href is not a MCRObjectID.");
222 }
223 } else {
224 try {
225 MCRObjectID fromid = MCRObjectID.getInstance(from);
226 from = fromid.toString();
227 } catch (Exception e) {
228 throw new MCRException("The xlink:from is not a MCRObjectID.");
229 }
230
231 try {
232 MCRObjectID toid = MCRObjectID.getInstance(to);
233 to = toid.toString();
234 } catch (Exception e) {
235 throw new MCRException("The xlink:to is not a MCRObjectID.");
236 }
237 }
238 }
239
240 @Override
241 public boolean equals(Object obj) {
242 if (!super.equals(obj)) {
243 return false;
244 }
245 MCRMetaLinkID other = (MCRMetaLinkID) obj;
246 if (!Objects.equals(from, other.from)) {
247 return false;
248 } else if (!Objects.equals(href, other.href)) {
249 return false;
250 } else if (!Objects.equals(label, other.label)) {
251 return false;
252 } else if (!Objects.equals(linktype, other.linktype)) {
253 return false;
254 } else if (!Objects.equals(role, other.role)) {
255 return false;
256 } else if (!Objects.equals(title, other.title)) {
257 return false;
258 } else {
259 return Objects.equals(to, other.to);
260 }
261 }
262
263 @Override
264 public MCRMetaLinkID clone() {
265 return (MCRMetaLinkID) super.clone();
266 }
267
268 @Override
269 public final String toString() {
270 return getXLinkHref();
271 }
272 }