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 java.util.ArrayList;
24 import java.util.List;
25
26 import org.apache.commons.lang3.Validate;
27
28 import ca.uhn.fhir.model.api.annotation.Child;
29 import ca.uhn.fhir.model.api.annotation.DatatypeDef;
30 import ca.uhn.fhir.model.primitive.StringDt;
31
32 @DatatypeDef(name="Extension")
33 public class ExtensionDt extends BaseIdentifiableElement implements ICompositeDatatype {
34
35 private boolean myModifier;
36
37 @Child(name="url", type=StringDt.class, order=0, min=1, max=1)
38 private StringDt myUrl;
39
40 @Child(name="value", type=IDatatype.class, order=1, min=0, max=1)
41 private IElement myValue;
42
43 public ExtensionDt() {
44 }
45
46 public ExtensionDt(boolean theIsModifier) {
47 myModifier = theIsModifier;
48 }
49
50 public ExtensionDt(boolean theIsModifier, String theUrl) {
51 Validate.notEmpty(theUrl, "URL must be populated");
52
53 myModifier = theIsModifier;
54 myUrl = new StringDt(theUrl);
55 }
56
57 public ExtensionDt(boolean theIsModifier, String theUrl, IDatatype theValue) {
58 Validate.notEmpty(theUrl, "URL must be populated");
59 Validate.notNull(theValue, "Value must not be null");
60
61 myModifier = theIsModifier;
62 myUrl = new StringDt(theUrl);
63 myValue=theValue;
64 }
65
66 public StringDt getUrl() {
67 if (myUrl==null) {
68 myUrl=new StringDt();
69 }
70 return myUrl;
71 }
72
73 public String getUrlAsString() {
74 return getUrl().getValue();
75 }
76
77
78
79
80
81
82
83
84 public IElement getValue() {
85 return myValue;
86 }
87
88
89
90
91
92
93
94
95
96
97
98
99 public IPrimitiveDatatype<?> getValueAsPrimitive() {
100 if (!(getValue() instanceof IPrimitiveDatatype)) {
101 throw new ClassCastException("Extension with URL["+myUrl+"] can not be cast to primitive type, type is: "+ getClass().getCanonicalName());
102 }
103 return (IPrimitiveDatatype<?>) getValue();
104 }
105
106 @Override
107 public boolean isEmpty() {
108 return super.isBaseEmpty() && (myValue == null || myValue.isEmpty());
109 }
110
111 public boolean isModifier() {
112 return myModifier;
113 }
114
115 public void setModifier(boolean theModifier) {
116 myModifier = theModifier;
117 }
118
119 public ExtensionDt setUrl(String theUrl) {
120 myUrl = new StringDt(theUrl);
121 return this;
122 }
123
124 public ExtensionDt setUrl(StringDt theUrl) {
125 myUrl = theUrl;
126 return this;
127 }
128
129 public void setValue(IElement theValue) {
130 myValue = theValue;
131 }
132
133 @Override
134 public <T extends IElement> List<T> getAllPopulatedChildElementsOfType(Class<T> theType) {
135 return new ArrayList<T>();
136 }
137
138 }