1 package ca.uhn.fhir.model.api;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import ca.uhn.fhir.model.primitive.IdDt;
24 import ca.uhn.fhir.parser.DataFormatException;
25
26 public abstract class BaseIdentifiableElement extends BaseElement implements IIdentifiableElement {
27
28 private String myElementSpecificId;
29
30 @Override
31 public String getElementSpecificId() {
32 return myElementSpecificId;
33 }
34
35
36
37
38
39 @Override
40 public IdDt getId() {
41 if (myElementSpecificId == null) {
42 return new LockedId();
43 } else {
44 return new LockedId(myElementSpecificId);
45 }
46 }
47
48 @Override
49 public void setElementSpecificId(String theElementSpecificId) {
50 myElementSpecificId = theElementSpecificId;
51 }
52
53
54
55
56
57 @Override
58 public void setId(IdDt theId) {
59 if (theId == null) {
60 myElementSpecificId = null;
61 } else {
62 myElementSpecificId = theId.getValue();
63 }
64 }
65
66
67
68
69
70 @Override
71 public void setId(String theId) {
72 myElementSpecificId = theId;
73 }
74
75 private static class LockedId extends IdDt {
76
77 public LockedId() {
78 }
79
80 public LockedId(String theElementSpecificId) {
81 super(theElementSpecificId);
82 }
83
84 @Override
85 public void setValue(String theValue) throws DataFormatException {
86 throw new UnsupportedOperationException("Use IElement#setElementSpecificId(String) to set the element ID for an element");
87 }
88
89 @Override
90 public void setValueAsString(String theValue) throws DataFormatException {
91 throw new UnsupportedOperationException("Use IElement#setElementSpecificId(String) to set the element ID for an element");
92 }
93
94 }
95
96 }