-
Notifications
You must be signed in to change notification settings - Fork 402
/
Registration.java
764 lines (655 loc) · 27.9 KB
/
Registration.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
/*******************************************************************************
* Copyright (c) 2013-2015 Sierra Wireless and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v20.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.html.
*
* Contributors:
* Sierra Wireless - initial API and implementation
* Achim Kraus (Bosch Software Innovations GmbH) - use Identity as destination
* Michał Wadowski (Orange) - Improved compliance with rfc6690
*******************************************************************************/
package org.eclipse.leshan.server.registration;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.URI;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import org.eclipse.leshan.core.LwM2m.LwM2mVersion;
import org.eclipse.leshan.core.LwM2m.Version;
import org.eclipse.leshan.core.endpoint.EndpointUriUtil;
import org.eclipse.leshan.core.link.Link;
import org.eclipse.leshan.core.link.attributes.Attributes;
import org.eclipse.leshan.core.link.attributes.ContentFormatAttribute;
import org.eclipse.leshan.core.link.attributes.ResourceTypeAttribute;
import org.eclipse.leshan.core.link.lwm2m.MixedLwM2mLink;
import org.eclipse.leshan.core.link.lwm2m.attributes.LwM2mAttribute;
import org.eclipse.leshan.core.link.lwm2m.attributes.LwM2mAttributes;
import org.eclipse.leshan.core.model.ObjectModel;
import org.eclipse.leshan.core.node.LwM2mPath;
import org.eclipse.leshan.core.request.BindingMode;
import org.eclipse.leshan.core.request.ContentFormat;
import org.eclipse.leshan.core.request.Identity;
import org.eclipse.leshan.core.util.StringUtils;
import org.eclipse.leshan.core.util.Validate;
import org.eclipse.leshan.server.security.Authorizer;
/**
* An immutable structure which represent a LW-M2M client registration on the server
*/
public class Registration {
private static final long DEFAULT_LIFETIME_IN_SEC = 86400L;
private final Date registrationDate;
private final Identity identity;
private final long lifeTimeInSec;
private final String smsNumber;
private final LwM2mVersion lwM2mVersion;
private final EnumSet<BindingMode> bindingMode;
private final Boolean queueMode; // since LWM2M 1.1
// The LWM2M Client's unique end point name.
private final String endpoint;
private final String id;
private final Link[] objectLinks;
private final Map<String, String> additionalRegistrationAttributes;
// The location where LWM2M objects are hosted on the device
private final String rootPath;
// All ContentFormat supported by the client
private final Set<ContentFormat> supportedContentFormats;
// All supported object (object id => version)
private final Map<Integer, Version> supportedObjects;
// All available instances
private final Set<LwM2mPath> availableInstances;
private final Date lastUpdate;
private final Map<String, String> applicationData;
private final URI lastEndpointUsed;
protected Registration(Builder builder) {
// mandatory params
id = builder.registrationId;
identity = builder.identity;
endpoint = builder.endpoint;
lastEndpointUsed = builder.lastEndpointUsed;
// object links related params
objectLinks = builder.objectLinks;
rootPath = builder.rootPath;
supportedContentFormats = builder.supportedContentFormats;
supportedObjects = builder.supportedObjects;
availableInstances = builder.availableInstances;
// other params
lifeTimeInSec = builder.lifeTimeInSec;
lwM2mVersion = builder.lwM2mVersion;
bindingMode = builder.bindingMode;
queueMode = builder.queueMode;
registrationDate = builder.registrationDate;
lastUpdate = builder.lastUpdate;
smsNumber = builder.smsNumber;
additionalRegistrationAttributes = builder.additionalRegistrationAttributes;
applicationData = builder.applicationData;
}
public String getId() {
return id;
}
public Date getRegistrationDate() {
return registrationDate;
}
/**
* Gets the clients identity.
*
* @return identity from client's most recent registration or registration update.
*/
public Identity getIdentity() {
return identity;
}
/**
* Gets the client's network socket address.
*
* @return the source address from the client's most recent CoAP message.
*/
public InetSocketAddress getSocketAddress() {
return identity.getPeerAddress();
}
/**
* Gets the client's network address.
*
* @return the source address from the client's most recent CoAP message.
*/
public InetAddress getAddress() {
return identity.getPeerAddress().getAddress();
}
/**
* Gets the client's network port number.
*
* @return the source port from the client's most recent CoAP message.
*/
public int getPort() {
return identity.getPeerAddress().getPort();
}
public Link[] getObjectLinks() {
return objectLinks;
}
public Link[] getSortedObjectLinks() {
// sort the list of objects
if (objectLinks == null) {
return null;
}
Link[] res = Arrays.copyOf(objectLinks, objectLinks.length);
Arrays.sort(res, new Comparator<Link>() {
/* sort by path */
@Override
public int compare(Link o1, Link o2) {
if (o1 == null && o2 == null)
return 0;
if (o1 == null)
return -1;
if (o2 == null)
return 1;
// by URL
String[] url1 = o1.getUriReference().split("/");
String[] url2 = o2.getUriReference().split("/");
for (int i = 0; i < url1.length && i < url2.length; i++) {
// is it two numbers?
if (isNumber(url1[i]) && isNumber(url2[i])) {
int cmp = Integer.parseInt(url1[i]) - Integer.parseInt(url2[i]);
if (cmp != 0) {
return cmp;
}
} else {
int v = url1[i].compareTo(url2[i]);
if (v != 0) {
return v;
}
}
}
return url1.length - url2.length;
}
});
return res;
}
private static boolean isNumber(String s) {
return !StringUtils.isEmpty(s) && StringUtils.isNumeric(s);
}
public Long getLifeTimeInSec() {
return lifeTimeInSec;
}
public String getSmsNumber() {
return smsNumber;
}
public LwM2mVersion getLwM2mVersion() {
return lwM2mVersion;
}
public EnumSet<BindingMode> getBindingMode() {
return bindingMode;
}
public Boolean getQueueMode() {
return queueMode;
}
/**
* @return the path where the objects are hosted on the device
*/
public String getRootPath() {
return rootPath;
}
/**
* @return all {@link ContentFormat} supported by the client.
*/
public Set<ContentFormat> getSupportedContentFormats() {
return supportedContentFormats;
}
/**
* @return all available object instance by the client
*/
public Set<LwM2mPath> getAvailableInstances() {
return availableInstances;
}
/**
* Gets the unique name the client has registered with.
*
* @return the name
*/
public String getEndpoint() {
return endpoint;
}
public Date getLastUpdate() {
return lastUpdate;
}
public long getExpirationTimeStamp() {
return getExpirationTimeStamp(0L);
}
public long getExpirationTimeStamp(long gracePeriodInSec) {
return lastUpdate.getTime() + lifeTimeInSec * 1000 + gracePeriodInSec * 1000;
}
/**
* @return True if DTLS handshake can be initiated by the Server for this registration.
*/
public boolean canInitiateConnection() {
// We consider that initiates a connection (acting as DTLS client to initiate a handshake) does not make sense
// for QueueMode as if we lost connection device is probably absent.
return !usesQueueMode();
}
/**
* @return true if the last registration update was done less than lifetime seconds ago.
*/
public boolean isAlive() {
return isAlive(0);
}
/**
* This is the same idea than {@link Registration#isAlive()} but with a grace period. <br>
*
* @param gracePeriodInSec an extra time for the registration lifetime.
* @return true if the last registration update was done less than lifetime+gracePeriod seconds ago.
*/
public boolean isAlive(long gracePeriodInSec) {
return getExpirationTimeStamp(gracePeriodInSec) > System.currentTimeMillis();
}
public Map<String, String> getAdditionalRegistrationAttributes() {
return additionalRegistrationAttributes;
}
public boolean usesQueueMode() {
if (lwM2mVersion.olderThan(LwM2mVersion.V1_1))
return bindingMode.contains(BindingMode.Q);
else
return queueMode;
}
/**
* @param objectid the object id for which we want to know the supported version.
* @return the supported version of the object with the id {@code objectid}. If the object is not supported return
* {@code null}
*/
public Version getSupportedVersion(Integer objectid) {
return getSupportedObject().get(objectid);
}
/**
* @return a map from {@code objectId} {@literal =>} {@code supportedVersion} for each supported objects. supported.
*/
public Map<Integer, Version> getSupportedObject() {
return supportedObjects;
}
/**
* @return Some application data which could have been added at Registration by the {@link Authorizer}
*/
public Map<String, String> getApplicationData() {
return applicationData;
}
public URI getLastEndpointUsed() {
return lastEndpointUsed;
}
@Override
public String toString() {
return String.format(
"Registration [registrationDate=%s, identity=%s, lifeTimeInSec=%s, smsNumber=%s, lwM2mVersion=%s, bindingMode=%s, queueMode=%s, endpoint=%s, id=%s, objectLinks=%s, additionalRegistrationAttributes=%s, rootPath=%s, supportedContentFormats=%s, supportedObjects=%s, availableInstances=%s, lastUpdate=%s, applicationData=%s]",
registrationDate, identity, lifeTimeInSec, smsNumber, lwM2mVersion, bindingMode, queueMode, endpoint,
id, Arrays.toString(objectLinks), additionalRegistrationAttributes, rootPath, supportedContentFormats,
supportedObjects, availableInstances, lastUpdate, applicationData);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((additionalRegistrationAttributes == null) ? 0 : additionalRegistrationAttributes.hashCode());
result = prime * result + ((applicationData == null) ? 0 : applicationData.hashCode());
result = prime * result + ((availableInstances == null) ? 0 : availableInstances.hashCode());
result = prime * result + ((bindingMode == null) ? 0 : bindingMode.hashCode());
result = prime * result + ((endpoint == null) ? 0 : endpoint.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((identity == null) ? 0 : identity.hashCode());
result = prime * result + ((lastUpdate == null) ? 0 : lastUpdate.hashCode());
result = prime * result + (int) (lifeTimeInSec ^ (lifeTimeInSec >>> 32));
result = prime * result + ((lwM2mVersion == null) ? 0 : lwM2mVersion.hashCode());
result = prime * result + Arrays.hashCode(objectLinks);
result = prime * result + ((queueMode == null) ? 0 : queueMode.hashCode());
result = prime * result + ((registrationDate == null) ? 0 : registrationDate.hashCode());
result = prime * result + ((rootPath == null) ? 0 : rootPath.hashCode());
result = prime * result + ((smsNumber == null) ? 0 : smsNumber.hashCode());
result = prime * result + ((supportedContentFormats == null) ? 0 : supportedContentFormats.hashCode());
result = prime * result + ((supportedObjects == null) ? 0 : supportedObjects.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Registration other = (Registration) obj;
if (additionalRegistrationAttributes == null) {
if (other.additionalRegistrationAttributes != null)
return false;
} else if (!additionalRegistrationAttributes.equals(other.additionalRegistrationAttributes))
return false;
if (applicationData == null) {
if (other.applicationData != null)
return false;
} else if (!applicationData.equals(other.applicationData))
return false;
if (availableInstances == null) {
if (other.availableInstances != null)
return false;
} else if (!availableInstances.equals(other.availableInstances))
return false;
if (bindingMode == null) {
if (other.bindingMode != null)
return false;
} else if (!bindingMode.equals(other.bindingMode))
return false;
if (endpoint == null) {
if (other.endpoint != null)
return false;
} else if (!endpoint.equals(other.endpoint))
return false;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
if (identity == null) {
if (other.identity != null)
return false;
} else if (!identity.equals(other.identity))
return false;
if (lastUpdate == null) {
if (other.lastUpdate != null)
return false;
} else if (!lastUpdate.equals(other.lastUpdate))
return false;
if (lifeTimeInSec != other.lifeTimeInSec)
return false;
if (lwM2mVersion == null) {
if (other.lwM2mVersion != null)
return false;
} else if (!lwM2mVersion.equals(other.lwM2mVersion))
return false;
if (!Arrays.equals(objectLinks, other.objectLinks))
return false;
if (queueMode == null) {
if (other.queueMode != null)
return false;
} else if (!queueMode.equals(other.queueMode))
return false;
if (registrationDate == null) {
if (other.registrationDate != null)
return false;
} else if (!registrationDate.equals(other.registrationDate))
return false;
if (rootPath == null) {
if (other.rootPath != null)
return false;
} else if (!rootPath.equals(other.rootPath))
return false;
if (smsNumber == null) {
if (other.smsNumber != null)
return false;
} else if (!smsNumber.equals(other.smsNumber))
return false;
if (supportedContentFormats == null) {
if (other.supportedContentFormats != null)
return false;
} else if (!supportedContentFormats.equals(other.supportedContentFormats))
return false;
if (supportedObjects == null) {
if (other.supportedObjects != null)
return false;
} else if (!supportedObjects.equals(other.supportedObjects))
return false;
return true;
}
public static class Builder {
private final String registrationId;
private final String endpoint;
private final Identity identity;
private final URI lastEndpointUsed;
private Date registrationDate;
private Date lastUpdate;
private Long lifeTimeInSec;
private String smsNumber;
private EnumSet<BindingMode> bindingMode;
private Boolean queueMode;
private LwM2mVersion lwM2mVersion = LwM2mVersion.getDefault();
private Link[] objectLinks;
private String rootPath;
private Set<ContentFormat> supportedContentFormats;
private Map<Integer, Version> supportedObjects;
private Set<LwM2mPath> availableInstances;
private Map<String, String> additionalRegistrationAttributes;
private Map<String, String> applicationData;
// builder setting
private boolean extractData; // if true extract data from objectLinks
public Builder(Registration registration) {
// mandatory params
registrationId = registration.id;
identity = registration.identity;
endpoint = registration.endpoint;
lastEndpointUsed = registration.lastEndpointUsed;
// object links related params
objectLinks = registration.objectLinks;
rootPath = registration.rootPath;
supportedContentFormats = registration.supportedContentFormats;
supportedObjects = registration.supportedObjects;
availableInstances = registration.availableInstances;
// other params
lifeTimeInSec = registration.lifeTimeInSec;
lwM2mVersion = registration.lwM2mVersion;
bindingMode = registration.bindingMode;
queueMode = registration.queueMode;
registrationDate = registration.registrationDate;
lastUpdate = registration.lastUpdate;
smsNumber = registration.smsNumber;
additionalRegistrationAttributes = registration.additionalRegistrationAttributes;
applicationData = registration.applicationData;
}
public Builder(String registrationId, String endpoint, Identity identity, URI lastEndpointUsed) {
Validate.notNull(registrationId);
Validate.notEmpty(endpoint);
Validate.notNull(identity);
EndpointUriUtil.validateURI(lastEndpointUsed);
this.registrationId = registrationId;
this.endpoint = endpoint;
this.identity = identity;
this.lastEndpointUsed = lastEndpointUsed;
}
public Builder extractDataFromObjectLink(boolean extract) {
this.extractData = extract;
return this;
}
public Builder registrationDate(Date registrationDate) {
this.registrationDate = registrationDate;
return this;
}
public Builder lastUpdate(Date lastUpdate) {
this.lastUpdate = lastUpdate;
return this;
}
public Builder lifeTimeInSec(Long lifetimeInSec) {
this.lifeTimeInSec = lifetimeInSec;
return this;
}
public Builder smsNumber(String smsNumber) {
this.smsNumber = smsNumber;
return this;
}
public Builder bindingMode(EnumSet<BindingMode> bindingMode) {
this.bindingMode = bindingMode;
return this;
}
public Builder queueMode(Boolean queueMode) {
this.queueMode = queueMode;
return this;
}
public Builder lwM2mVersion(LwM2mVersion lwM2mVersion) {
this.lwM2mVersion = lwM2mVersion;
return this;
}
public Builder objectLinks(Link[] objectLinks) {
this.objectLinks = objectLinks;
return this;
}
public Builder rootPath(String rootPath) {
this.rootPath = rootPath;
return this;
}
public Builder supportedContentFormats(Set<ContentFormat> supportedContentFormats) {
this.supportedContentFormats = supportedContentFormats;
return this;
}
public Builder supportedContentFormats(ContentFormat... supportedContentFormats) {
this.supportedContentFormats = new HashSet<>();
for (ContentFormat contentFormat : supportedContentFormats) {
this.supportedContentFormats.add(contentFormat);
}
return this;
}
public Builder supportedObjects(Map<Integer, Version> supportedObjects) {
this.supportedObjects = supportedObjects;
return this;
}
public Builder availableInstances(Set<LwM2mPath> availableInstances) {
this.availableInstances = availableInstances;
return this;
}
public Builder additionalRegistrationAttributes(Map<String, String> additionalRegistrationAttributes) {
this.additionalRegistrationAttributes = additionalRegistrationAttributes;
return this;
}
public Builder applicationData(Map<String, String> applicationData) {
this.applicationData = applicationData;
return this;
}
private void extractDataFromObjectLinks() {
if (objectLinks != null) {
// Search LWM2M root link
Link root = null;
for (Link link : objectLinks) {
if (link != null) {
ResourceTypeAttribute rt = link.getAttributes().get(Attributes.RT);
if (rt != null && rt.getValue().contains("oma.lwm2m")) {
// this link has the ResourceType oma.lwm2m this is the LWM2M root for sure.
root = link;
break;
} else if (link.getUriReference().equals("/")) {
// this link refer to "/", so could be the LWM2M root link unless another one has the
// ResourceType oma.lwm2m, so we continue to search.
root = link;
}
}
}
// extract root path
if (root != null) {
rootPath = root.getUriReference();
if (!rootPath.endsWith("/")) {
rootPath = rootPath + "/";
}
} else {
rootPath = "/";
}
// extract supported Content format in root link
if (root != null) {
ContentFormatAttribute ctValue = root.getAttributes().get(Attributes.CT);
if (ctValue != null) {
supportedContentFormats = extractContentFormat(ctValue);
}
}
// Extract data from link object
supportedObjects = new HashMap<>();
availableInstances = new HashSet<>();
for (Link link : objectLinks) {
if (link instanceof MixedLwM2mLink) {
LwM2mPath path = ((MixedLwM2mLink) link).getPath();
// add supported objects
if (path.isObject()) {
addSupportedObject(link, path);
} else if (path.isObjectInstance()) {
addSupportedObject(link, path);
availableInstances.add(path);
}
}
}
}
}
private Set<ContentFormat> extractContentFormat(ContentFormatAttribute ctValue) {
Set<ContentFormat> supportedContentFormats = new HashSet<>();
// add content format from ct attributes
supportedContentFormats.addAll(ctValue.getValue());
// add mandatory content format
for (ContentFormat format : ContentFormat.knownContentFormat) {
if (format.isMandatoryForClient(lwM2mVersion)) {
supportedContentFormats.add(format);
}
}
return supportedContentFormats;
}
private void addSupportedObject(Link link, LwM2mPath path) {
// extract object id and version
int objectId = path.getObjectId();
LwM2mAttribute<Version> versionParamValue = link.getAttributes().get(LwM2mAttributes.OBJECT_VERSION);
if (versionParamValue != null) {
// if there is a version attribute then use it as version for this object
supportedObjects.put(objectId, versionParamValue.getValue());
} else {
// there is no version attribute attached.
// In this case we use the DEFAULT_VERSION only if this object stored as supported object.
Version currentVersion = supportedObjects.get(objectId);
if (currentVersion == null) {
supportedObjects.put(objectId, new Version(ObjectModel.DEFAULT_VERSION));
}
}
}
public Registration build() {
// Define Default value
rootPath = rootPath == null ? "/" : rootPath;
lifeTimeInSec = lifeTimeInSec == null ? DEFAULT_LIFETIME_IN_SEC : lifeTimeInSec;
lwM2mVersion = lwM2mVersion == null ? LwM2mVersion.getDefault() : lwM2mVersion;
bindingMode = bindingMode == null ? EnumSet.of(BindingMode.U) : bindingMode;
queueMode = queueMode == null && lwM2mVersion.newerThan(LwM2mVersion.V1_0) ? Boolean.FALSE : queueMode;
registrationDate = registrationDate == null ? new Date() : registrationDate;
lastUpdate = lastUpdate == null ? new Date() : lastUpdate;
// Extract data from object links if wanted
if (extractData) {
extractDataFromObjectLinks();
}
// Make collection immutable
// We create a new Collection and make it "unmodifiable".
if (supportedContentFormats == null || supportedContentFormats.isEmpty()) {
supportedContentFormats = Collections.emptySet();
} else {
supportedContentFormats = Collections.unmodifiableSet(new HashSet<>(supportedContentFormats));
}
if (supportedObjects == null || supportedObjects.isEmpty()) {
supportedObjects = Collections.emptyMap();
} else {
supportedObjects = Collections.unmodifiableMap(new HashMap<>(supportedObjects));
}
if (availableInstances == null || availableInstances.isEmpty()) {
availableInstances = Collections.emptySet();
} else {
availableInstances = Collections.unmodifiableSet(new TreeSet<>(availableInstances));
}
if (additionalRegistrationAttributes == null || additionalRegistrationAttributes.isEmpty()) {
additionalRegistrationAttributes = Collections.emptyMap();
} else {
additionalRegistrationAttributes = Collections
.unmodifiableMap(new HashMap<>(additionalRegistrationAttributes));
}
if (applicationData == null || applicationData.isEmpty()) {
applicationData = Collections.emptyMap();
} else {
applicationData = Collections.unmodifiableMap(new HashMap<>(applicationData));
}
// Create Registration
return new Registration(this);
}
}
}