1 package ca.uhn.fhir.context;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import java.lang.reflect.Field;
24 import java.util.ArrayList;
25 import java.util.Collections;
26 import java.util.Comparator;
27 import java.util.List;
28 import java.util.Map;
29
30 import ca.uhn.fhir.model.api.IDatatype;
31 import ca.uhn.fhir.model.api.IElement;
32 import ca.uhn.fhir.model.api.IResource;
33 import ca.uhn.fhir.model.api.annotation.Child;
34 import ca.uhn.fhir.model.api.annotation.Description;
35 import ca.uhn.fhir.model.primitive.XhtmlDt;
36
37 public class RuntimeChildAny extends RuntimeChildChoiceDefinition {
38
39 public RuntimeChildAny(Field theField, String theElementName, Child theChildAnnotation, Description theDescriptionAnnotation) {
40 super(theField, theElementName, theChildAnnotation, theDescriptionAnnotation);
41 }
42
43 @Override
44 void sealAndInitialize(Map<Class<? extends IElement>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
45 List<Class<? extends IElement>> choiceTypes = new ArrayList<Class<? extends IElement>>();
46
47 for (Class<? extends IElement> next : theClassToElementDefinitions.keySet()) {
48 if (next.equals(XhtmlDt.class)) {
49 continue;
50 }
51 if (IResource.class.isAssignableFrom(next) || IDatatype.class.isAssignableFrom(next)) {
52 choiceTypes.add(next);
53 }
54 }
55 Collections.sort(choiceTypes,new Comparator<Class<?>>(){
56 @Override
57 public int compare(Class<?> theO1, Class<?> theO2) {
58 boolean o1res = IResource.class.isAssignableFrom(theO1);
59 boolean o2res = IResource.class.isAssignableFrom(theO2);
60 if (o1res && o2res) {
61 return theO1.getSimpleName().compareTo(theO2.getSimpleName());
62 } else if (o1res) {
63 return -1;
64 } else if (o1res == false && o2res == false) {
65 return 0;
66 }else {
67 return 1;
68 }
69 }});
70
71 setChoiceTypes(choiceTypes);
72
73 super.sealAndInitialize(theClassToElementDefinitions);
74 }
75
76
77
78 }