From d8e14e42133645b887cd38a1982309d46e22a719 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Wed, 10 Dec 2014 17:40:47 -0500 Subject: [PATCH] ...more work on HL7 structs --- .../BaseRuntimeChildDatatypeDefinition.java | 17 +-- .../context/BaseRuntimeChildDefinition.java | 12 +- ...BaseRuntimeElementCompositeDefinition.java | 8 +- .../context/BaseRuntimeElementDefinition.java | 6 +- .../java/ca/uhn/fhir/context/FhirContext.java | 18 +-- .../ca/uhn/fhir/context/ModelScanner.java | 127 ++++++++++++------ .../ca/uhn/fhir/context/RuntimeChildAny.java | 9 +- .../context/RuntimeChildChoiceDefinition.java | 28 ++-- ...ChildCompositeBoundDatatypeDefinition.java | 5 +- ...ntimeChildCompositeDatatypeDefinition.java | 5 +- .../RuntimeChildContainedResources.java | 9 +- ...ntimeChildDeclaredExtensionDefinition.java | 19 +-- .../RuntimeChildNarrativeDefinition.java | 5 +- ...dPrimitiveBoundCodeDatatypeDefinition.java | 4 +- ...ntimeChildPrimitiveDatatypeDefinition.java | 5 +- .../RuntimeChildResourceBlockDefinition.java | 14 +- .../RuntimeChildResourceDefinition.java | 20 +-- ...imeChildUndeclaredExtensionDefinition.java | 20 +-- .../RuntimeCompositeDatatypeDefinition.java | 10 +- .../context/RuntimeExtensionDtDefinition.java | 9 +- .../RuntimePrimitiveDatatypeDefinition.java | 13 +- ...ePrimitiveDatatypeNarrativeDefinition.java | 5 +- .../context/RuntimeResourceDefinition.java | 10 +- .../RuntimeResourceReferenceDefinition.java | 21 +-- .../java/ca/uhn/fhir/parser/JsonParser.java | 7 +- .../java/ca/uhn/fhir/parser/ParserState.java | 66 ++++----- .../bin/.gitignore | 1 - 27 files changed, 275 insertions(+), 198 deletions(-) delete mode 100644 hapi-fhir-structures-hl7org-dev/bin/.gitignore diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/BaseRuntimeChildDatatypeDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/BaseRuntimeChildDatatypeDefinition.java index a1de3f93d0d..b68c2af533a 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/BaseRuntimeChildDatatypeDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/BaseRuntimeChildDatatypeDefinition.java @@ -25,27 +25,28 @@ import java.util.Collections; import java.util.Map; import java.util.Set; +import org.hl7.fhir.instance.model.IBase; + import ca.uhn.fhir.model.api.ICodeEnum; import ca.uhn.fhir.model.api.IDatatype; -import ca.uhn.fhir.model.api.IElement; import ca.uhn.fhir.model.api.annotation.Child; import ca.uhn.fhir.model.api.annotation.Description; public abstract class BaseRuntimeChildDatatypeDefinition extends BaseRuntimeDeclaredChildDefinition { private Class myCodeType; - private Class myDatatype; + private Class myDatatype; private BaseRuntimeElementDefinition myElementDefinition; - public BaseRuntimeChildDatatypeDefinition(Field theField, String theElementName, Child theChildAnnotation, Description theDescriptionAnnotation, Class theDatatype) { + public BaseRuntimeChildDatatypeDefinition(Field theField, String theElementName, Child theChildAnnotation, Description theDescriptionAnnotation, Class theDatatype) { super(theField, theChildAnnotation, theDescriptionAnnotation, theElementName); assert theDatatype != IDatatype.class; // should use RuntimeChildAny myDatatype = theDatatype; } @Override - public String getChildNameByDatatype(Class theDatatype) { + public String getChildNameByDatatype(Class theDatatype) { if (myDatatype.equals(theDatatype)) { return getElementName(); } @@ -53,8 +54,8 @@ public abstract class BaseRuntimeChildDatatypeDefinition extends BaseRuntimeDecl } @Override - public BaseRuntimeElementDefinition getChildElementDefinitionByDatatype(Class theDatatype) { - Class datatype = theDatatype; + public BaseRuntimeElementDefinition getChildElementDefinitionByDatatype(Class theDatatype) { + Class datatype = theDatatype; if (myDatatype.equals(datatype)) { return myElementDefinition; } @@ -73,7 +74,7 @@ public abstract class BaseRuntimeChildDatatypeDefinition extends BaseRuntimeDecl return myCodeType; } - public Class getDatatype() { + public Class getDatatype() { return myDatatype; } @@ -83,7 +84,7 @@ public abstract class BaseRuntimeChildDatatypeDefinition extends BaseRuntimeDecl } @Override - void sealAndInitialize(Map, BaseRuntimeElementDefinition> theClassToElementDefinitions) { + void sealAndInitialize(Map, BaseRuntimeElementDefinition> theClassToElementDefinitions) { myElementDefinition = theClassToElementDefinitions.get(getDatatype()); assert myElementDefinition != null : "Unknown type: " + getDatatype(); } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/BaseRuntimeChildDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/BaseRuntimeChildDefinition.java index bdaf9c6fba5..04e19a881b3 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/BaseRuntimeChildDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/BaseRuntimeChildDefinition.java @@ -24,7 +24,7 @@ import java.util.List; import java.util.Map; import java.util.Set; -import ca.uhn.fhir.model.api.IElement; +import org.hl7.fhir.instance.model.IBase; public abstract class BaseRuntimeChildDefinition { @@ -37,18 +37,18 @@ public abstract class BaseRuntimeChildDefinition { public abstract BaseRuntimeElementDefinition getChildByName(String theName); - public abstract BaseRuntimeElementDefinition getChildElementDefinitionByDatatype(Class theType); + public abstract BaseRuntimeElementDefinition getChildElementDefinitionByDatatype(Class theType); - public abstract String getChildNameByDatatype(Class theDatatype); + public abstract String getChildNameByDatatype(Class theDatatype); public abstract IMutator getMutator(); public abstract Set getValidChildNames(); - abstract void sealAndInitialize(Map, BaseRuntimeElementDefinition> theClassToElementDefinitions); + abstract void sealAndInitialize(Map, BaseRuntimeElementDefinition> theClassToElementDefinitions); public interface IAccessor { - List getValues(Object theTarget); + List getValues(Object theTarget); } public abstract String getElementName(); @@ -58,7 +58,7 @@ public abstract class BaseRuntimeChildDefinition { public abstract int getMin(); public interface IMutator { - void addValue(Object theTarget, IElement theValue); + void addValue(Object theTarget, IBase theValue); } public String getExtensionUrl() { diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/BaseRuntimeElementCompositeDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/BaseRuntimeElementCompositeDefinition.java index db4d6613e48..854a184ebcd 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/BaseRuntimeElementCompositeDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/BaseRuntimeElementCompositeDefinition.java @@ -27,11 +27,11 @@ import java.util.List; import java.util.Map; import java.util.TreeSet; -import ca.uhn.fhir.model.api.ICompositeElement; -import ca.uhn.fhir.model.api.IElement; +import org.hl7.fhir.instance.model.IBase; + import ca.uhn.fhir.parser.DataFormatException; -public abstract class BaseRuntimeElementCompositeDefinition extends BaseRuntimeElementDefinition { +public abstract class BaseRuntimeElementCompositeDefinition extends BaseRuntimeElementDefinition { private List myChildren = new ArrayList(); private List myChildrenAndExtensions; @@ -76,7 +76,7 @@ public abstract class BaseRuntimeElementCompositeDefinition, BaseRuntimeElementDefinition> theClassToElementDefinitions) { + public void sealAndInitialize(Map, BaseRuntimeElementDefinition> theClassToElementDefinitions) { super.sealAndInitialize(theClassToElementDefinitions); for (BaseRuntimeChildDefinition next : myChildren) { diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/BaseRuntimeElementDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/BaseRuntimeElementDefinition.java index 7828dd97084..75fb1ce33a6 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/BaseRuntimeElementDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/BaseRuntimeElementDefinition.java @@ -28,11 +28,11 @@ import java.util.List; import java.util.Map; import org.apache.commons.lang3.StringUtils; +import org.hl7.fhir.instance.model.IBase; -import ca.uhn.fhir.model.api.IElement; import ca.uhn.fhir.model.api.IValueSetEnumBinder; -public abstract class BaseRuntimeElementDefinition { +public abstract class BaseRuntimeElementDefinition { private String myName; private Class myImplementingClass; @@ -129,7 +129,7 @@ public abstract class BaseRuntimeElementDefinition { * Invoked prior to use to perform any initialization and make object * mutable */ - void sealAndInitialize(Map, BaseRuntimeElementDefinition> theClassToElementDefinitions) { + void sealAndInitialize(Map, BaseRuntimeElementDefinition> theClassToElementDefinitions) { for (BaseRuntimeChildDefinition next : myExtensions) { next.sealAndInitialize(theClassToElementDefinitions); } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirContext.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirContext.java index fed73528524..f7c893227d3 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirContext.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirContext.java @@ -67,7 +67,7 @@ import ca.uhn.fhir.validation.FhirValidator; */ public class FhirContext { - private static final List> EMPTY_LIST = Collections.emptyList(); + private static final List> EMPTY_LIST = Collections.emptyList(); private volatile Map, BaseRuntimeElementDefinition> myClassToElementDefinition = Collections.emptyMap(); private volatile Map myIdToResourceDefinition = Collections.emptyMap(); private HapiLocalizer myLocalizer = new HapiLocalizer(); @@ -85,7 +85,7 @@ public class FhirContext { this(EMPTY_LIST); } - public FhirContext(Class theResourceType) { + public FhirContext(Class theResourceType) { this(toCollection(theResourceType)); } @@ -93,7 +93,7 @@ public class FhirContext { this(toCollection(theResourceTypes)); } - public FhirContext(Collection> theResourceTypes) { + public FhirContext(Collection> theResourceTypes) { scanResourceTypes(theResourceTypes); if (FhirVersionEnum.DSTU1.isPresentOnClasspath()) { @@ -295,8 +295,8 @@ public class FhirContext { return new XmlParser(this); } - private RuntimeResourceDefinition scanResourceType(Class theResourceType) { - ArrayList> resourceTypes = new ArrayList>(); + private RuntimeResourceDefinition scanResourceType(Class theResourceType) { + ArrayList> resourceTypes = new ArrayList>(); resourceTypes.add(theResourceType); Map, BaseRuntimeElementDefinition> defs = scanResourceTypes(resourceTypes); return (RuntimeResourceDefinition) defs.get(theResourceType); @@ -340,15 +340,15 @@ public class FhirContext { myNarrativeGenerator = theNarrativeGenerator; } - private static Collection> toCollection(Class theResourceType) { - ArrayList> retVal = new ArrayList>(1); + private static Collection> toCollection(Class theResourceType) { + ArrayList> retVal = new ArrayList>(1); retVal.add(theResourceType); return retVal; } @SuppressWarnings("unchecked") - private static List> toCollection(Class[] theResourceTypes) { - ArrayList> retVal = new ArrayList>(1); + private static List> toCollection(Class[] theResourceTypes) { + ArrayList> retVal = new ArrayList>(1); for (Class clazz : theResourceTypes) { if (!IResource.class.isAssignableFrom(clazz)) { throw new IllegalArgumentException(clazz.getCanonicalName() + " is not an instance of " + IResource.class.getSimpleName()); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java index 12e08b3ec3d..544d266b147 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/ModelScanner.java @@ -24,9 +24,14 @@ import static org.apache.commons.lang3.StringUtils.isBlank; import java.io.IOException; import java.io.InputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Field; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Proxy; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Collection; @@ -43,15 +48,19 @@ import java.util.Set; import java.util.TreeMap; import java.util.TreeSet; +import org.hl7.fhir.instance.model.BackboneElement; +import org.hl7.fhir.instance.model.DomainResource; import org.hl7.fhir.instance.model.IBase; import org.hl7.fhir.instance.model.IBaseResource; import org.hl7.fhir.instance.model.ICompositeType; +import org.hl7.fhir.instance.model.IPrimitiveType; +import org.hl7.fhir.instance.model.Narrative; +import org.hl7.fhir.instance.model.Reference; import ca.uhn.fhir.model.api.CodeableConceptElement; import ca.uhn.fhir.model.api.ExtensionDt; import ca.uhn.fhir.model.api.IBoundCodeableConcept; import ca.uhn.fhir.model.api.ICodeEnum; -import ca.uhn.fhir.model.api.ICompositeDatatype; import ca.uhn.fhir.model.api.ICompositeElement; import ca.uhn.fhir.model.api.IDatatype; import ca.uhn.fhir.model.api.IElement; @@ -108,7 +117,7 @@ class ModelScanner { init(null, new HashSet>(theResourceTypes)); } - ModelScanner(FhirContext theContext, Map, BaseRuntimeElementDefinition> theExistingDefinitions, Collection> theResourceTypes) throws ConfigurationException { + ModelScanner(FhirContext theContext, Map, BaseRuntimeElementDefinition> theExistingDefinitions, Collection> theResourceTypes) throws ConfigurationException { myContext=theContext; init(theExistingDefinitions, new HashSet>(theResourceTypes)); } @@ -133,7 +142,7 @@ class ModelScanner { return myRuntimeChildUndeclaredExtensionDefinition; } - private void addScanAlso(Class theType) { + private void addScanAlso(Class theType) { if (theType.isInterface()) { return; } @@ -261,17 +270,17 @@ class ModelScanner { return; } - ResourceDef resourceDefinition = theClass.getAnnotation(ResourceDef.class); + ResourceDef resourceDefinition = pullAnnotation(theClass,ResourceDef.class); if (resourceDefinition != null) { if (!IResource.class.isAssignableFrom(theClass)) { throw new ConfigurationException("Resource type contains a @" + ResourceDef.class.getSimpleName() + " annotation but does not implement " + IResource.class.getCanonicalName() + ": " + theClass.getCanonicalName()); } @SuppressWarnings("unchecked") - Class resClass = (Class) theClass; + Class resClass = (Class) theClass; scanResource(resClass, resourceDefinition); } - DatatypeDef datatypeDefinition = theClass.getAnnotation(DatatypeDef.class); + DatatypeDef datatypeDefinition = pullAnnotation(theClass,DatatypeDef.class); if (datatypeDefinition != null) { if (ICompositeType.class.isAssignableFrom(theClass)) { @SuppressWarnings("unchecked") @@ -279,14 +288,14 @@ class ModelScanner { scanCompositeDatatype(resClass, datatypeDefinition); } else if (IPrimitiveType.class.isAssignableFrom(theClass)) { @SuppressWarnings({ "unchecked" }) - Class) theClass; + Class resClass = (Class) theClass; scanPrimitiveDatatype(resClass, datatypeDefinition); } else { throw new ConfigurationException("Resource type contains a @" + DatatypeDef.class.getSimpleName() + " annotation but does not implement " + IDatatype.class.getCanonicalName() + ": " + theClass.getCanonicalName()); } } - Block blockDefinition = theClass.getAnnotation(Block.class); + Block blockDefinition = pullAnnotation(theClass,Block.class); if (blockDefinition != null) { if (IResourceBlock.class.isAssignableFrom(theClass)) { @SuppressWarnings("unchecked") @@ -316,7 +325,7 @@ class ModelScanner { scanCompositeElementForChildren(theClass, resourceDef); } - private void scanCompositeDatatype(Class theClass, DatatypeDef theDatatypeDefinition) { + private void scanCompositeDatatype(Class theClass, DatatypeDef theDatatypeDefinition) { ourLog.debug("Scanning resource class: {}", theClass.getName()); RuntimeCompositeDatatypeDefinition resourceDef; @@ -330,27 +339,27 @@ class ModelScanner { } @SuppressWarnings("unchecked") - private void scanCompositeElementForChildren(Class theClass, BaseRuntimeElementCompositeDefinition theDefinition) { + private void scanCompositeElementForChildren(Class theClass, BaseRuntimeElementCompositeDefinition theDefinition) { Set elementNames = new HashSet(); TreeMap orderToElementDef = new TreeMap(); TreeMap orderToExtensionDef = new TreeMap(); - LinkedList> classes = new LinkedList>(); + LinkedList> classes = new LinkedList>(); /* * We scan classes for annotated fields in the class but also all of its superclasses */ - Class current = theClass; + Class current = theClass; do { classes.push(current); if (ICompositeElement.class.isAssignableFrom(current.getSuperclass())) { - current = (Class) current.getSuperclass(); + current = (Class) current.getSuperclass(); } else { current = null; } } while (current != null); - for (Class next : classes) { + for (Class next : classes) { scanCompositeElementForChildren(next, elementNames, orderToElementDef, orderToExtensionDef); } @@ -384,7 +393,7 @@ class ModelScanner { } @SuppressWarnings("unchecked") - private void scanCompositeElementForChildren(Class theClass, Set elementNames, TreeMap theOrderToElementDef, TreeMap theOrderToExtensionDef) { + private void scanCompositeElementForChildren(Class theClass, Set elementNames, TreeMap theOrderToElementDef, TreeMap theOrderToExtensionDef) { int baseElementOrder = theOrderToElementDef.isEmpty() ? 0 : theOrderToElementDef.lastEntry().getKey() + 1; for (Field next : theClass.getDeclaredFields()) { @@ -394,16 +403,16 @@ class ModelScanner { continue; } - Child childAnnotation = next.getAnnotation(Child.class); + Child childAnnotation = pullAnnotation(next, Child.class); if (childAnnotation == null) { ourLog.trace("Ignoring non @Child field {} on target type {}",next.getName() , theClass); continue; } - Description descriptionAnnotation = next.getAnnotation(Description.class); + Description descriptionAnnotation = pullAnnotation(next,Description.class); TreeMap orderMap = theOrderToElementDef; - Extension extensionAttr = next.getAnnotation(Extension.class); + Extension extensionAttr = pullAnnotation(next,Extension.class); if (extensionAttr != null) { orderMap = theOrderToExtensionDef; } @@ -465,8 +474,8 @@ class ModelScanner { order--; } - List> choiceTypes = new ArrayList>(); - for (Class nextChoiceType : childAnnotation.type()) { + List> choiceTypes = new ArrayList>(); + for (Class nextChoiceType : childAnnotation.type()) { choiceTypes.add(nextChoiceType); } @@ -480,18 +489,18 @@ class ModelScanner { Class nextElementType = determineElementType(next); - if (nextElementType.equals(ContainedDt.class)) { + if (nextElementType.equals(ContainedDt.class) || (childAnnotation.name().equals("contained") && DomainResource.class.isAssignableFrom(theClass))) { /* * Child is contained resources */ RuntimeChildContainedResources def = new RuntimeChildContainedResources(next, childAnnotation, descriptionAnnotation, elementName); orderMap.put(order, def); - } else if (choiceTypes.size() > 1 && !BaseResourceReferenceDt.class.isAssignableFrom(nextElementType)) { + } else if (choiceTypes.size() > 1 && !BaseResourceReferenceDt.class.isAssignableFrom(nextElementType) && !Reference.class.isAssignableFrom(nextElementType)) { /* * Child is a choice element */ - for (Class nextType : choiceTypes) { + for (Class nextType : choiceTypes) { addScanAlso(nextType); } RuntimeChildChoiceDefinition def = new RuntimeChildChoiceDefinition(next, elementName, childAnnotation, descriptionAnnotation, choiceTypes); @@ -509,34 +518,34 @@ class ModelScanner { /* * Child is an extension */ - Class et = (Class) nextElementType; + Class et = (Class) nextElementType; RuntimeChildDeclaredExtensionDefinition def = new RuntimeChildDeclaredExtensionDefinition(next, childAnnotation, descriptionAnnotation, extensionAttr, elementName, extensionAttr.url(), et); orderMap.put(order, def); if (IElement.class.isAssignableFrom(nextElementType)) { addScanAlso((Class) nextElementType); } - } else if (BaseResourceReferenceDt.class.isAssignableFrom(nextElementType)) { + } else if (BaseResourceReferenceDt.class.isAssignableFrom(nextElementType) || Reference.class.isAssignableFrom(nextElementType)) { /* * Child is a resource reference */ - List> refTypesList = new ArrayList>(); + List> refTypesList = new ArrayList>(); for (Class nextType : childAnnotation.type()) { - if (IResource.class.isAssignableFrom(nextType) == false) { + if (IBaseResource.class.isAssignableFrom(nextType) == false) { throw new ConfigurationException("Field '" + next.getName() + "' in class '" + next.getDeclaringClass().getCanonicalName() + "' is of type " + BaseResourceReferenceDt.class + " but contains a non-resource type: " + nextType.getCanonicalName()); } - refTypesList.add((Class) nextType); + refTypesList.add((Class) nextType); addScanAlso(nextType); } RuntimeChildResourceDefinition def = new RuntimeChildResourceDefinition(next, elementName, childAnnotation, descriptionAnnotation, refTypesList); orderMap.put(order, def); - } else if (IResourceBlock.class.isAssignableFrom(nextElementType)) { + } else if (IResourceBlock.class.isAssignableFrom(nextElementType) || BackboneElement.class.isAssignableFrom(nextElementType)) { /* * Child is a resource block (i.e. a sub-tag within a resource) TODO: do these have a better name * according to HL7? */ - Class blockDef = (Class) nextElementType; + Class blockDef = (Class) nextElementType; addScanAlso(blockDef); RuntimeChildResourceBlockDefinition def = new RuntimeChildResourceBlockDefinition(next, childAnnotation, descriptionAnnotation, elementName, blockDef); orderMap.put(order, def); @@ -546,8 +555,8 @@ class ModelScanner { RuntimeChildAny def = new RuntimeChildAny(next, elementName, childAnnotation, descriptionAnnotation); orderMap.put(order, def); - } else if (IDatatype.class.isAssignableFrom(nextElementType)) { - Class nextDatatype = (Class) nextElementType; + } else if (IDatatype.class.isAssignableFrom(nextElementType) || IPrimitiveType.class.isAssignableFrom(nextElementType) || ICompositeType.class.isAssignableFrom(nextElementType)) { + Class nextDatatype = (Class) nextElementType; addScanAlso(nextDatatype); BaseRuntimeChildDatatypeDefinition def; @@ -562,14 +571,14 @@ class ModelScanner { if (IBoundCodeableConcept.class.isAssignableFrom(nextElementType)) { IValueSetEnumBinder> binder = getBoundCodeBinder(next); def = new RuntimeChildCompositeBoundDatatypeDefinition(next, elementName, childAnnotation, descriptionAnnotation, nextDatatype, binder); - } else if (NarrativeDt.class.getSimpleName().equals(nextElementType.getSimpleName())) { + } else if (NarrativeDt.class.getSimpleName().equals(nextElementType.getSimpleName()) || Narrative.class.getName().equals(nextElementType.getClass().getName())) { def = new RuntimeChildNarrativeDefinition(next, elementName, childAnnotation, descriptionAnnotation, nextDatatype); } else { def = new RuntimeChildCompositeDatatypeDefinition(next, elementName, childAnnotation, descriptionAnnotation, nextDatatype); } } - CodeableConceptElement concept = next.getAnnotation(CodeableConceptElement.class); + CodeableConceptElement concept = pullAnnotation(next,CodeableConceptElement.class); if (concept != null) { if (!ICodedDatatype.class.isAssignableFrom(nextDatatype)) { throw new ConfigurationException("Field '" + elementName + "' in type '" + theClass.getCanonicalName() + "' is marked as @" + CodeableConceptElement.class.getCanonicalName() + " but type is not a subtype of " + ICodedDatatype.class.getName()); @@ -590,7 +599,47 @@ class ModelScanner { } } - private String scanPrimitiveDatatype(Class> theClass, DatatypeDef theDatatypeDefinition) { + /** + * There are two implementations of all of the annotations (e.g. {@link Child} and {@link org.hl7.fhir.instance.model.annotations.Child}) + * since the HL7.org ones will eventually replace the HAPI ones. Annotations can't extend each other or implement interfaces or anything + * like that, so rather than duplicate all of the annotation processing code this method just creates an interface Proxy to simulate the + * HAPI annotations if the HL7.org ones are found instead. + */ + @SuppressWarnings("unchecked") + private T pullAnnotation(AnnotatedElement theTarget, Class theAnnotationType) { + T retVal = theTarget.getAnnotation(theAnnotationType); + if (retVal == null) { + String sourceClassName = theAnnotationType.getClass().getName(); + String candidateAltClassName = sourceClassName.replace("ca.uhn.fhir.model.api.annotation", "org.hl7.fhir.instance.model.annotations"); + + if (!sourceClassName.equals(candidateAltClassName)) { + try { + final Class altAnnotationClass = (Class) Class.forName(candidateAltClassName); + final Annotation altAnnotation = theTarget.getAnnotation(altAnnotationClass); + if (altAnnotation == null) { + return null; + } + + ourLog.debug("Forwarding annotation request for [{}] to class [{}]", sourceClassName, candidateAltClassName); + + InvocationHandler h = new InvocationHandler() { + @Override + public Object invoke(Object theProxy, Method theMethod, Object[] theArgs) throws Throwable { + Method altMethod = altAnnotationClass.getMethod(theMethod.getName(), theMethod.getParameterTypes()); + return altMethod.invoke(altAnnotation, theArgs); + } + }; + retVal = (T) Proxy.newProxyInstance(theAnnotationType.getClassLoader(), new Class[]{theAnnotationType}, h); + + } catch (ClassNotFoundException e) { + return null; + } + } + } + return retVal; + } + + private String scanPrimitiveDatatype(Class theClass, DatatypeDef theDatatypeDefinition) { ourLog.debug("Scanning resource class: {}", theClass.getName()); String resourceName = theDatatypeDefinition.name(); @@ -611,7 +660,7 @@ class ModelScanner { return resourceName; } - private String scanResource(Class theClass, ResourceDef resourceDefinition) { + private String scanResource(Class theClass, ResourceDef resourceDefinition) { ourLog.debug("Scanning resource class: {}", theClass.getName()); boolean primaryNameProvider = true; @@ -620,7 +669,7 @@ class ModelScanner { Class parent = theClass.getSuperclass(); primaryNameProvider = false; while (parent.equals(Object.class) == false && isBlank(resourceName)) { - ResourceDef nextDef = parent.getAnnotation(ResourceDef.class); + ResourceDef nextDef = pullAnnotation(parent,ResourceDef.class); if (nextDef != null) { resourceName = nextDef.name(); } @@ -671,13 +720,13 @@ class ModelScanner { return resourceName; } - private void scanResourceForSearchParams(Class theClass, RuntimeResourceDefinition theResourceDef) { + private void scanResourceForSearchParams(Class theClass, RuntimeResourceDefinition theResourceDef) { Map nameToParam = new HashMap(); Map compositeFields = new LinkedHashMap(); for (Field nextField : theClass.getFields()) { - SearchParamDefinition searchParam = nextField.getAnnotation(SearchParamDefinition.class); + SearchParamDefinition searchParam = pullAnnotation(nextField,SearchParamDefinition.class); if (searchParam != null) { SearchParamTypeEnum paramType = SearchParamTypeEnum.valueOf(searchParam.type().toUpperCase()); if (paramType == null) { diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildAny.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildAny.java index bcb99fb6aff..9b70ebfc01c 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildAny.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildAny.java @@ -27,8 +27,9 @@ import java.util.Comparator; import java.util.List; import java.util.Map; +import org.hl7.fhir.instance.model.IBase; + import ca.uhn.fhir.model.api.IDatatype; -import ca.uhn.fhir.model.api.IElement; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.annotation.Child; import ca.uhn.fhir.model.api.annotation.Description; @@ -41,10 +42,10 @@ public class RuntimeChildAny extends RuntimeChildChoiceDefinition { } @Override - void sealAndInitialize(Map, BaseRuntimeElementDefinition> theClassToElementDefinitions) { - List> choiceTypes = new ArrayList>(); + void sealAndInitialize(Map, BaseRuntimeElementDefinition> theClassToElementDefinitions) { + List> choiceTypes = new ArrayList>(); - for (Class next : theClassToElementDefinitions.keySet()) { + for (Class next : theClassToElementDefinitions.keySet()) { if (next.equals(XhtmlDt.class)) { continue; } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildChoiceDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildChoiceDefinition.java index 0fb7e71dfc6..ae2f7c22716 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildChoiceDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildChoiceDefinition.java @@ -29,8 +29,8 @@ import java.util.Map; import java.util.Set; import org.apache.commons.lang3.StringUtils; +import org.hl7.fhir.instance.model.IBase; -import ca.uhn.fhir.model.api.IElement; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.annotation.Child; import ca.uhn.fhir.model.api.annotation.Description; @@ -38,12 +38,12 @@ import ca.uhn.fhir.model.dstu.composite.ResourceReferenceDt; public class RuntimeChildChoiceDefinition extends BaseRuntimeDeclaredChildDefinition { - private List> myChoiceTypes; + private List> myChoiceTypes; private Map> myNameToChildDefinition; - private Map, String> myDatatypeToElementName; - private Map, BaseRuntimeElementDefinition> myDatatypeToElementDefinition; + private Map, String> myDatatypeToElementName; + private Map, BaseRuntimeElementDefinition> myDatatypeToElementDefinition; - public RuntimeChildChoiceDefinition(Field theField, String theElementName, Child theChildAnnotation, Description theDescriptionAnnotation, List> theChoiceTypes) { + public RuntimeChildChoiceDefinition(Field theField, String theElementName, Child theChildAnnotation, Description theDescriptionAnnotation, List> theChoiceTypes) { super(theField, theChildAnnotation, theDescriptionAnnotation, theElementName); myChoiceTypes = Collections.unmodifiableList(theChoiceTypes); @@ -56,11 +56,11 @@ public class RuntimeChildChoiceDefinition extends BaseRuntimeDeclaredChildDefini super(theField, theChildAnnotation, theDescriptionAnnotation, theElementName); } - void setChoiceTypes(List> theChoiceTypes) { + void setChoiceTypes(List> theChoiceTypes) { myChoiceTypes = Collections.unmodifiableList(theChoiceTypes); } - public List> getChoices() { + public List> getChoices() { return myChoiceTypes; } @@ -78,12 +78,12 @@ public class RuntimeChildChoiceDefinition extends BaseRuntimeDeclaredChildDefini @SuppressWarnings("unchecked") @Override - void sealAndInitialize(Map, BaseRuntimeElementDefinition> theClassToElementDefinitions) { + void sealAndInitialize(Map, BaseRuntimeElementDefinition> theClassToElementDefinitions) { myNameToChildDefinition = new HashMap>(); - myDatatypeToElementName = new HashMap, String>(); - myDatatypeToElementDefinition = new HashMap, BaseRuntimeElementDefinition>(); + myDatatypeToElementName = new HashMap, String>(); + myDatatypeToElementDefinition = new HashMap, BaseRuntimeElementDefinition>(); - for (Class next : myChoiceTypes) { + for (Class next : myChoiceTypes) { String elementName; String alternateElementName = null; @@ -122,16 +122,16 @@ public class RuntimeChildChoiceDefinition extends BaseRuntimeDeclaredChildDefini } @Override - public String getChildNameByDatatype(Class theDatatype) { + public String getChildNameByDatatype(Class theDatatype) { return myDatatypeToElementName.get(theDatatype); } @Override - public BaseRuntimeElementDefinition getChildElementDefinitionByDatatype(Class theDatatype) { + public BaseRuntimeElementDefinition getChildElementDefinitionByDatatype(Class theDatatype) { return myDatatypeToElementDefinition.get(theDatatype); } - public Set> getValidChildTypes() { + public Set> getValidChildTypes() { return Collections.unmodifiableSet((myDatatypeToElementDefinition.keySet())); } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildCompositeBoundDatatypeDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildCompositeBoundDatatypeDefinition.java index 7ac5f1d3aa2..5b3c26d1a65 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildCompositeBoundDatatypeDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildCompositeBoundDatatypeDefinition.java @@ -22,7 +22,8 @@ package ca.uhn.fhir.context; import java.lang.reflect.Field; -import ca.uhn.fhir.model.api.IDatatype; +import org.hl7.fhir.instance.model.IBase; + import ca.uhn.fhir.model.api.IValueSetEnumBinder; import ca.uhn.fhir.model.api.annotation.Child; import ca.uhn.fhir.model.api.annotation.Description; @@ -31,7 +32,7 @@ public class RuntimeChildCompositeBoundDatatypeDefinition extends RuntimeChildCo private IValueSetEnumBinder> myBinder; - public RuntimeChildCompositeBoundDatatypeDefinition(Field theField, String theElementName, Child theChildAnnotation, Description theDescriptionAnnotation, Class theDatatype, IValueSetEnumBinder> theBinder) { + public RuntimeChildCompositeBoundDatatypeDefinition(Field theField, String theElementName, Child theChildAnnotation, Description theDescriptionAnnotation, Class theDatatype, IValueSetEnumBinder> theBinder) { super(theField, theElementName, theChildAnnotation, theDescriptionAnnotation, theDatatype); myBinder = theBinder; if (theBinder==null) { diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildCompositeDatatypeDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildCompositeDatatypeDefinition.java index 523f503e238..6a83a266f30 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildCompositeDatatypeDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildCompositeDatatypeDefinition.java @@ -22,13 +22,14 @@ package ca.uhn.fhir.context; import java.lang.reflect.Field; -import ca.uhn.fhir.model.api.IDatatype; +import org.hl7.fhir.instance.model.IBase; + import ca.uhn.fhir.model.api.annotation.Child; import ca.uhn.fhir.model.api.annotation.Description; public class RuntimeChildCompositeDatatypeDefinition extends BaseRuntimeChildDatatypeDefinition { - public RuntimeChildCompositeDatatypeDefinition(Field theField, String theElementName, Child theChildAnnotation, Description theDescriptionAnnotation, Class theDatatype) { + public RuntimeChildCompositeDatatypeDefinition(Field theField, String theElementName, Child theChildAnnotation, Description theDescriptionAnnotation, Class theDatatype) { super(theField, theElementName, theChildAnnotation,theDescriptionAnnotation, theDatatype); } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildContainedResources.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildContainedResources.java index b16da68e33e..2b840fd1a00 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildContainedResources.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildContainedResources.java @@ -25,7 +25,8 @@ import java.util.Collections; import java.util.Map; import java.util.Set; -import ca.uhn.fhir.model.api.IElement; +import org.hl7.fhir.instance.model.IBase; + import ca.uhn.fhir.model.api.annotation.Child; import ca.uhn.fhir.model.api.annotation.Description; import ca.uhn.fhir.model.dstu.composite.ContainedDt; @@ -45,13 +46,13 @@ public class RuntimeChildContainedResources extends BaseRuntimeDeclaredChildDefi } @Override - public BaseRuntimeElementDefinition getChildElementDefinitionByDatatype(Class theType) { + public BaseRuntimeElementDefinition getChildElementDefinitionByDatatype(Class theType) { assert theType.equals(ContainedDt.class); return myElem; } @Override - public String getChildNameByDatatype(Class theDatatype) { + public String getChildNameByDatatype(Class theDatatype) { assert theDatatype.equals(ContainedDt.class); return getElementName(); } @@ -62,7 +63,7 @@ public class RuntimeChildContainedResources extends BaseRuntimeDeclaredChildDefi } @Override - void sealAndInitialize(Map, BaseRuntimeElementDefinition> theClassToElementDefinitions) { + void sealAndInitialize(Map, BaseRuntimeElementDefinition> theClassToElementDefinitions) { myElem = new RuntimeElemContainedResources(); } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildDeclaredExtensionDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildDeclaredExtensionDefinition.java index dea5b5f7725..528a1d14013 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildDeclaredExtensionDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildDeclaredExtensionDefinition.java @@ -20,7 +20,7 @@ package ca.uhn.fhir.context; * #L% */ -import static org.apache.commons.lang3.StringUtils.*; +import static org.apache.commons.lang3.StringUtils.isNotBlank; import java.lang.reflect.Field; import java.util.ArrayList; @@ -30,7 +30,8 @@ import java.util.List; import java.util.Map; import java.util.Set; -import ca.uhn.fhir.model.api.IElement; +import org.hl7.fhir.instance.model.IBase; + import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.annotation.Child; import ca.uhn.fhir.model.api.annotation.Description; @@ -39,7 +40,7 @@ import ca.uhn.fhir.model.api.annotation.Extension; public class RuntimeChildDeclaredExtensionDefinition extends BaseRuntimeDeclaredChildDefinition { private BaseRuntimeElementDefinition myChildDef; - private Class myChildType; + private Class myChildType; private String myDatatypeChildName; private boolean myDefinedLocally; private String myExtensionUrl; @@ -49,7 +50,7 @@ public class RuntimeChildDeclaredExtensionDefinition extends BaseRuntimeDeclared /** * @param theDefinedLocally See {@link Extension#definedLocally()} */ - RuntimeChildDeclaredExtensionDefinition(Field theField, Child theChild, Description theDescriptionAnnotation, Extension theExtension, String theElementName, String theExtensionUrl, Class theChildType) throws ConfigurationException { + RuntimeChildDeclaredExtensionDefinition(Field theField, Child theChild, Description theDescriptionAnnotation, Extension theExtension, String theElementName, String theExtensionUrl, Class theChildType) throws ConfigurationException { super(theField, theChild, theDescriptionAnnotation, theElementName); assert isNotBlank(theExtensionUrl); myExtensionUrl = theExtensionUrl; @@ -72,7 +73,7 @@ public class RuntimeChildDeclaredExtensionDefinition extends BaseRuntimeDeclared } @Override - public BaseRuntimeElementDefinition getChildElementDefinitionByDatatype(Class theType) { + public BaseRuntimeElementDefinition getChildElementDefinitionByDatatype(Class theType) { if (myChildType.equals(theType)) { return myChildDef; } @@ -84,7 +85,7 @@ public class RuntimeChildDeclaredExtensionDefinition extends BaseRuntimeDeclared } @Override - public String getChildNameByDatatype(Class theDatatype) { + public String getChildNameByDatatype(Class theDatatype) { if (myChildType.equals(theDatatype) && myDatatypeChildName != null) { return myDatatypeChildName; } else { @@ -92,7 +93,7 @@ public class RuntimeChildDeclaredExtensionDefinition extends BaseRuntimeDeclared } } - public Class getChildType() { + public Class getChildType() { return myChildType; } @@ -119,7 +120,7 @@ public class RuntimeChildDeclaredExtensionDefinition extends BaseRuntimeDeclared return myModifier; } - public IElement newInstance() { + public IBase newInstance() { try { return myChildType.newInstance(); } catch (InstantiationException e) { @@ -130,7 +131,7 @@ public class RuntimeChildDeclaredExtensionDefinition extends BaseRuntimeDeclared } @Override - void sealAndInitialize(Map, BaseRuntimeElementDefinition> theClassToElementDefinitions) { + void sealAndInitialize(Map, BaseRuntimeElementDefinition> theClassToElementDefinitions) { myUrlToChildExtension = new HashMap(); BaseRuntimeElementDefinition elementDef = theClassToElementDefinitions.get(myChildType); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildNarrativeDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildNarrativeDefinition.java index a5926c3f00c..6ba9801a429 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildNarrativeDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildNarrativeDefinition.java @@ -22,13 +22,14 @@ package ca.uhn.fhir.context; import java.lang.reflect.Field; -import ca.uhn.fhir.model.api.IDatatype; +import org.hl7.fhir.instance.model.IBase; + import ca.uhn.fhir.model.api.annotation.Child; import ca.uhn.fhir.model.api.annotation.Description; public class RuntimeChildNarrativeDefinition extends RuntimeChildCompositeDatatypeDefinition { - public RuntimeChildNarrativeDefinition(Field theField, String theElementName, Child theChildAnnotation, Description theDescriptionAnnotation, Class theDatatype) { + public RuntimeChildNarrativeDefinition(Field theField, String theElementName, Child theChildAnnotation, Description theDescriptionAnnotation, Class theDatatype) { super(theField, theElementName, theChildAnnotation,theDescriptionAnnotation, theDatatype); } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildPrimitiveBoundCodeDatatypeDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildPrimitiveBoundCodeDatatypeDefinition.java index d29dc4042d4..c5e152e4b0c 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildPrimitiveBoundCodeDatatypeDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildPrimitiveBoundCodeDatatypeDefinition.java @@ -22,6 +22,8 @@ package ca.uhn.fhir.context; import java.lang.reflect.Field; +import org.hl7.fhir.instance.model.IBase; + import ca.uhn.fhir.model.api.IDatatype; import ca.uhn.fhir.model.api.IValueSetEnumBinder; import ca.uhn.fhir.model.api.annotation.Child; @@ -31,7 +33,7 @@ public class RuntimeChildPrimitiveBoundCodeDatatypeDefinition extends RuntimeChi private IValueSetEnumBinder> myBinder; - public RuntimeChildPrimitiveBoundCodeDatatypeDefinition(Field theField, String theElementName, Child theChildAnnotation, Description theDescriptionAnnotation, Class theDatatype, IValueSetEnumBinder> theBinder) { + public RuntimeChildPrimitiveBoundCodeDatatypeDefinition(Field theField, String theElementName, Child theChildAnnotation, Description theDescriptionAnnotation, Class theDatatype, IValueSetEnumBinder> theBinder) { super(theField, theElementName, theDescriptionAnnotation, theChildAnnotation, theDatatype); myBinder = theBinder; diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildPrimitiveDatatypeDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildPrimitiveDatatypeDefinition.java index fce33e1b60f..3d53053c95e 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildPrimitiveDatatypeDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildPrimitiveDatatypeDefinition.java @@ -22,13 +22,14 @@ package ca.uhn.fhir.context; import java.lang.reflect.Field; -import ca.uhn.fhir.model.api.IDatatype; +import org.hl7.fhir.instance.model.IBase; + import ca.uhn.fhir.model.api.annotation.Child; import ca.uhn.fhir.model.api.annotation.Description; public class RuntimeChildPrimitiveDatatypeDefinition extends BaseRuntimeChildDatatypeDefinition { - public RuntimeChildPrimitiveDatatypeDefinition(Field theField, String theElementName, Description theDescriptionAnnotation, Child theChildAnnotation, Class theDatatype) { + public RuntimeChildPrimitiveDatatypeDefinition(Field theField, String theElementName, Description theDescriptionAnnotation, Child theChildAnnotation, Class theDatatype) { super(theField, theElementName, theChildAnnotation, theDescriptionAnnotation, theDatatype); } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildResourceBlockDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildResourceBlockDefinition.java index b77d652b72c..6449838fcc2 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildResourceBlockDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildResourceBlockDefinition.java @@ -25,17 +25,17 @@ import java.util.Collections; import java.util.Map; import java.util.Set; -import ca.uhn.fhir.model.api.IElement; -import ca.uhn.fhir.model.api.IResourceBlock; +import org.hl7.fhir.instance.model.IBase; + import ca.uhn.fhir.model.api.annotation.Child; import ca.uhn.fhir.model.api.annotation.Description; public class RuntimeChildResourceBlockDefinition extends BaseRuntimeDeclaredChildDefinition { private RuntimeResourceBlockDefinition myElementDef; - private Class myResourceBlockType; + private Class myResourceBlockType; - public RuntimeChildResourceBlockDefinition(Field theField, Child theChildAnnotation, Description theDescriptionAnnotation, String theElementName, Class theResourceBlockType) throws ConfigurationException { + public RuntimeChildResourceBlockDefinition(Field theField, Child theChildAnnotation, Description theDescriptionAnnotation, String theElementName, Class theResourceBlockType) throws ConfigurationException { super(theField, theChildAnnotation, theDescriptionAnnotation, theElementName); myResourceBlockType = theResourceBlockType; } @@ -50,7 +50,7 @@ public class RuntimeChildResourceBlockDefinition extends BaseRuntimeDeclaredChil } @Override - public String getChildNameByDatatype(Class theDatatype) { + public String getChildNameByDatatype(Class theDatatype) { if (myResourceBlockType.equals(theDatatype)) { return getElementName(); } @@ -58,7 +58,7 @@ public class RuntimeChildResourceBlockDefinition extends BaseRuntimeDeclaredChil } @Override - public BaseRuntimeElementDefinition getChildElementDefinitionByDatatype(Class theDatatype) { + public BaseRuntimeElementDefinition getChildElementDefinitionByDatatype(Class theDatatype) { if (myResourceBlockType.equals(theDatatype)) { return myElementDef; } @@ -71,7 +71,7 @@ public class RuntimeChildResourceBlockDefinition extends BaseRuntimeDeclaredChil } @Override - void sealAndInitialize(Map, BaseRuntimeElementDefinition> theClassToElementDefinitions) { + void sealAndInitialize(Map, BaseRuntimeElementDefinition> theClassToElementDefinitions) { myElementDef = (RuntimeResourceBlockDefinition) theClassToElementDefinitions.get(myResourceBlockType); } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildResourceDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildResourceDefinition.java index af92e4e5d45..ea89c132639 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildResourceDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildResourceDefinition.java @@ -28,7 +28,9 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; -import ca.uhn.fhir.model.api.IElement; +import org.hl7.fhir.instance.model.IBase; +import org.hl7.fhir.instance.model.IBaseResource; + import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.annotation.Child; import ca.uhn.fhir.model.api.annotation.Description; @@ -37,10 +39,10 @@ import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt; public class RuntimeChildResourceDefinition extends BaseRuntimeDeclaredChildDefinition { private BaseRuntimeElementDefinition myRuntimeDef; - private List> myResourceTypes; + private List> myResourceTypes; private Set myValidChildNames; - public RuntimeChildResourceDefinition(Field theField, String theElementName, Child theChildAnnotation, Description theDescriptionAnnotation, List> theResourceTypes) { + public RuntimeChildResourceDefinition(Field theField, String theElementName, Child theChildAnnotation, Description theDescriptionAnnotation, List> theResourceTypes) { super(theField, theChildAnnotation, theDescriptionAnnotation, theElementName); myResourceTypes = theResourceTypes; @@ -50,7 +52,7 @@ public class RuntimeChildResourceDefinition extends BaseRuntimeDeclaredChildDefi } @Override - public String getChildNameByDatatype(Class theDatatype) { + public String getChildNameByDatatype(Class theDatatype) { if (BaseResourceReferenceDt.class.isAssignableFrom(theDatatype)) { return getElementName(); } @@ -58,7 +60,7 @@ public class RuntimeChildResourceDefinition extends BaseRuntimeDeclaredChildDefi } @Override - public BaseRuntimeElementDefinition getChildElementDefinitionByDatatype(Class theDatatype) { + public BaseRuntimeElementDefinition getChildElementDefinitionByDatatype(Class theDatatype) { if (BaseResourceReferenceDt.class.isAssignableFrom(theDatatype)) { return myRuntimeDef; } @@ -76,7 +78,7 @@ public class RuntimeChildResourceDefinition extends BaseRuntimeDeclaredChildDefi } @Override - void sealAndInitialize(Map, BaseRuntimeElementDefinition> theClassToElementDefinitions) { + void sealAndInitialize(Map, BaseRuntimeElementDefinition> theClassToElementDefinitions) { myRuntimeDef = new RuntimeResourceReferenceDefinition(getElementName(), myResourceTypes); myRuntimeDef.sealAndInitialize(theClassToElementDefinitions); @@ -84,9 +86,9 @@ public class RuntimeChildResourceDefinition extends BaseRuntimeDeclaredChildDefi myValidChildNames.add(getElementName()); myValidChildNames.add(getElementName() + "Resource"); - for (Class next : myResourceTypes) { + for (Class next : myResourceTypes) { if (next == IResource.class) { - for (Entry, BaseRuntimeElementDefinition> nextEntry : theClassToElementDefinitions.entrySet()) { + for (Entry, BaseRuntimeElementDefinition> nextEntry : theClassToElementDefinitions.entrySet()) { if (IResource.class.isAssignableFrom(nextEntry.getKey())) { RuntimeResourceDefinition nextDef = (RuntimeResourceDefinition) nextEntry.getValue(); myValidChildNames.add(getElementName() + nextDef.getName()); @@ -105,7 +107,7 @@ public class RuntimeChildResourceDefinition extends BaseRuntimeDeclaredChildDefi myValidChildNames = Collections.unmodifiableSet(myValidChildNames); } - public List> getResourceTypes() { + public List> getResourceTypes() { return myResourceTypes; } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java index f9d0366af70..c241ff44b0c 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java @@ -29,10 +29,10 @@ import java.util.Map.Entry; import java.util.Set; import org.apache.commons.lang3.text.WordUtils; +import org.hl7.fhir.instance.model.IBase; import ca.uhn.fhir.model.api.ExtensionDt; import ca.uhn.fhir.model.api.IDatatype; -import ca.uhn.fhir.model.api.IElement; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt; import ca.uhn.fhir.model.dstu.composite.ResourceReferenceDt; @@ -40,8 +40,8 @@ import ca.uhn.fhir.model.dstu.composite.ResourceReferenceDt; public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildDefinition { private Map> myAttributeNameToDefinition; - private Map, String> myDatatypeToAttributeName; - private Map, BaseRuntimeElementDefinition> myDatatypeToDefinition; + private Map, String> myDatatypeToAttributeName; + private Map, BaseRuntimeElementDefinition> myDatatypeToDefinition; public RuntimeChildUndeclaredExtensionDefinition() { // nothing @@ -58,19 +58,19 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD } @Override - public String getChildNameByDatatype(Class theDatatype) { + public String getChildNameByDatatype(Class theDatatype) { return myDatatypeToAttributeName.get(theDatatype); } @Override - public BaseRuntimeElementDefinition getChildElementDefinitionByDatatype(Class theType) { + public BaseRuntimeElementDefinition getChildElementDefinitionByDatatype(Class theType) { return myDatatypeToDefinition.get(theType); } @Override - void sealAndInitialize(Map, BaseRuntimeElementDefinition> theClassToElementDefinitions) { + void sealAndInitialize(Map, BaseRuntimeElementDefinition> theClassToElementDefinitions) { Map> datatypeAttributeNameToDefinition = new HashMap>(); - myDatatypeToAttributeName = new HashMap, String>(); + myDatatypeToAttributeName = new HashMap, String>(); for (BaseRuntimeElementDefinition next : theClassToElementDefinitions.values()) { if (next instanceof IRuntimeDatatypeDefinition) { @@ -89,7 +89,7 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD myAttributeNameToDefinition = datatypeAttributeNameToDefinition; - myDatatypeToDefinition = new HashMap, BaseRuntimeElementDefinition>(); + myDatatypeToDefinition = new HashMap, BaseRuntimeElementDefinition>(); for (Entry> next : myAttributeNameToDefinition.entrySet()) { @SuppressWarnings("unchecked") @@ -112,7 +112,7 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD public IAccessor getAccessor() { return new IAccessor() { @Override - public List getValues(Object theTarget) { + public List getValues(Object theTarget) { ExtensionDt target = (ExtensionDt) theTarget; if (target.getValue() != null) { return Collections.singletonList(target.getValue()); @@ -126,7 +126,7 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD public IMutator getMutator() { return new IMutator() { @Override - public void addValue(Object theTarget, IElement theValue) { + public void addValue(Object theTarget, IBase theValue) { ExtensionDt target = (ExtensionDt) theTarget; if (theValue instanceof IDatatype) { target.setValue((IDatatype) theTarget); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeCompositeDatatypeDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeCompositeDatatypeDefinition.java index 65feca3230e..d38863fcd99 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeCompositeDatatypeDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeCompositeDatatypeDefinition.java @@ -20,16 +20,18 @@ package ca.uhn.fhir.context; * #L% */ -import static org.apache.commons.lang3.StringUtils.*; -import ca.uhn.fhir.model.api.ICompositeDatatype; +import static org.apache.commons.lang3.StringUtils.isBlank; + +import org.hl7.fhir.instance.model.ICompositeType; + import ca.uhn.fhir.model.api.annotation.DatatypeDef; import ca.uhn.fhir.model.api.annotation.ResourceDef; -public class RuntimeCompositeDatatypeDefinition extends BaseRuntimeElementCompositeDefinition implements IRuntimeDatatypeDefinition { +public class RuntimeCompositeDatatypeDefinition extends BaseRuntimeElementCompositeDefinition implements IRuntimeDatatypeDefinition { private boolean mySpecialization; - public RuntimeCompositeDatatypeDefinition(DatatypeDef theDef, Class theImplementingClass) { + public RuntimeCompositeDatatypeDefinition(DatatypeDef theDef, Class theImplementingClass) { super(theDef.name(), theImplementingClass); String resourceName = theDef.name(); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeExtensionDtDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeExtensionDtDefinition.java index 2124f8c1fb4..e37b151e1e6 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeExtensionDtDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeExtensionDtDefinition.java @@ -25,15 +25,16 @@ import java.util.Collections; import java.util.List; import java.util.Map; -import ca.uhn.fhir.model.api.ICompositeDatatype; -import ca.uhn.fhir.model.api.IElement; +import org.hl7.fhir.instance.model.IBase; +import org.hl7.fhir.instance.model.ICompositeType; + import ca.uhn.fhir.model.api.annotation.DatatypeDef; public class RuntimeExtensionDtDefinition extends RuntimeCompositeDatatypeDefinition { private List myChildren; - public RuntimeExtensionDtDefinition(DatatypeDef theDef, Class theImplementingClass) { + public RuntimeExtensionDtDefinition(DatatypeDef theDef, Class theImplementingClass) { super(theDef, theImplementingClass); } @@ -43,7 +44,7 @@ public class RuntimeExtensionDtDefinition extends RuntimeCompositeDatatypeDefini } @Override - public void sealAndInitialize(Map, BaseRuntimeElementDefinition> theClassToElementDefinitions) { + public void sealAndInitialize(Map, BaseRuntimeElementDefinition> theClassToElementDefinitions) { super.sealAndInitialize(theClassToElementDefinitions); /* diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimePrimitiveDatatypeDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimePrimitiveDatatypeDefinition.java index 8a7fbbed3bb..25e24bdaede 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimePrimitiveDatatypeDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimePrimitiveDatatypeDefinition.java @@ -20,20 +20,21 @@ package ca.uhn.fhir.context; * #L% */ -import static org.apache.commons.lang3.StringUtils.*; +import static org.apache.commons.lang3.StringUtils.isBlank; import java.util.Map; -import ca.uhn.fhir.model.api.IElement; -import ca.uhn.fhir.model.api.IPrimitiveDatatype; +import org.hl7.fhir.instance.model.IBase; +import org.hl7.fhir.instance.model.IPrimitiveType; + import ca.uhn.fhir.model.api.annotation.DatatypeDef; import ca.uhn.fhir.model.api.annotation.ResourceDef; -public class RuntimePrimitiveDatatypeDefinition extends BaseRuntimeElementDefinition> implements IRuntimeDatatypeDefinition { +public class RuntimePrimitiveDatatypeDefinition extends BaseRuntimeElementDefinition implements IRuntimeDatatypeDefinition { private boolean mySpecialization; - public RuntimePrimitiveDatatypeDefinition(DatatypeDef theDef, Class> theImplementingClass) { + public RuntimePrimitiveDatatypeDefinition(DatatypeDef theDef, Class theImplementingClass) { super(theDef.name(), theImplementingClass); String resourceName = theDef.name(); @@ -50,7 +51,7 @@ public class RuntimePrimitiveDatatypeDefinition extends BaseRuntimeElementDefini } @Override - void sealAndInitialize(Map, BaseRuntimeElementDefinition> theClassToElementDefinitions) { + void sealAndInitialize(Map, BaseRuntimeElementDefinition> theClassToElementDefinitions) { // nothing } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimePrimitiveDatatypeNarrativeDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimePrimitiveDatatypeNarrativeDefinition.java index cf72cab1e6b..59060e4f84e 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimePrimitiveDatatypeNarrativeDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimePrimitiveDatatypeNarrativeDefinition.java @@ -22,7 +22,8 @@ package ca.uhn.fhir.context; import java.util.Map; -import ca.uhn.fhir.model.api.IElement; +import org.hl7.fhir.instance.model.IBase; + import ca.uhn.fhir.model.primitive.XhtmlDt; public class RuntimePrimitiveDatatypeNarrativeDefinition extends BaseRuntimeElementDefinition { @@ -37,7 +38,7 @@ public class RuntimePrimitiveDatatypeNarrativeDefinition extends BaseRuntimeEle } @Override - void sealAndInitialize(Map, BaseRuntimeElementDefinition> theClassToElementDefinitions) { + void sealAndInitialize(Map, BaseRuntimeElementDefinition> theClassToElementDefinitions) { // nothing } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceDefinition.java index f357bd32f97..4ee233e1e3c 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceDefinition.java @@ -27,11 +27,13 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import ca.uhn.fhir.model.api.IElement; +import org.hl7.fhir.instance.model.IBase; +import org.hl7.fhir.instance.model.IBaseResource; + import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.annotation.ResourceDef; -public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefinition { +public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefinition { private RuntimeResourceDefinition myBaseDefinition; private Map myNameToSearchParam = new LinkedHashMap(); @@ -41,7 +43,7 @@ public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefini private FhirContext myContext; private String myId; - public RuntimeResourceDefinition(FhirContext theContext, String theResourceName, Class theClass, ResourceDef theResourceAnnotation) { + public RuntimeResourceDefinition(FhirContext theContext, String theResourceName, Class theClass, ResourceDef theResourceAnnotation) { super(theResourceName, theClass); myContext= theContext; myResourceProfile = theResourceAnnotation.profile(); @@ -91,7 +93,7 @@ public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefini } @Override - public void sealAndInitialize(Map, BaseRuntimeElementDefinition> theClassToElementDefinitions) { + public void sealAndInitialize(Map, BaseRuntimeElementDefinition> theClassToElementDefinitions) { super.sealAndInitialize(theClassToElementDefinitions); myNameToSearchParam = Collections.unmodifiableMap(myNameToSearchParam); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceReferenceDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceReferenceDefinition.java index d123f9901f0..be0bc8d01ab 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceReferenceDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceReferenceDefinition.java @@ -24,16 +24,19 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import ca.uhn.fhir.model.api.IElement; +import org.hl7.fhir.instance.model.IBase; +import org.hl7.fhir.instance.model.IBaseResource; +import org.hl7.fhir.instance.model.Resource; + import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt; public class RuntimeResourceReferenceDefinition extends BaseRuntimeElementDefinition { - private final List> myResourceTypes; - private HashMap, RuntimeResourceDefinition> myResourceTypeToDefinition; + private final List> myResourceTypes; + private HashMap, RuntimeResourceDefinition> myResourceTypeToDefinition; - public RuntimeResourceReferenceDefinition(String theName, List> theResourceTypes) { + public RuntimeResourceReferenceDefinition(String theName, List> theResourceTypes) { super(theName, BaseResourceReferenceDt.class); if (theResourceTypes == null || theResourceTypes.isEmpty()) { throw new ConfigurationException("Element '" + theName + "' has no resource types noted"); @@ -41,15 +44,15 @@ public class RuntimeResourceReferenceDefinition extends BaseRuntimeElementDefini myResourceTypes = theResourceTypes; } - public List> getResourceTypes() { + public List> getResourceTypes() { return myResourceTypes; } @Override - void sealAndInitialize(Map, BaseRuntimeElementDefinition> theClassToElementDefinitions) { - myResourceTypeToDefinition = new HashMap, RuntimeResourceDefinition>(); - for (Class next : myResourceTypes) { - if (next.equals(IResource.class)) { + void sealAndInitialize(Map, BaseRuntimeElementDefinition> theClassToElementDefinitions) { + myResourceTypeToDefinition = new HashMap, RuntimeResourceDefinition>(); + for (Class next : myResourceTypes) { + if (next.equals(IResource.class) || next.equals(Resource.class)) { continue; } RuntimeResourceDefinition definition = (RuntimeResourceDefinition) theClassToElementDefinitions.get(next); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/JsonParser.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/JsonParser.java index cf2498e8766..93a095d1b51 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/JsonParser.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/JsonParser.java @@ -20,7 +20,9 @@ package ca.uhn.fhir.parser; * #L% */ -import static org.apache.commons.lang3.StringUtils.*; +import static org.apache.commons.lang3.StringUtils.defaultString; +import static org.apache.commons.lang3.StringUtils.isBlank; +import static org.apache.commons.lang3.StringUtils.isNotBlank; import java.io.IOException; import java.io.Reader; @@ -49,6 +51,7 @@ import javax.json.stream.JsonParsingException; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.Validate; +import org.hl7.fhir.instance.model.IBaseResource; import ca.uhn.fhir.context.BaseRuntimeChildDefinition; import ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition; @@ -835,7 +838,7 @@ public class JsonParser extends BaseParser implements IParser { } @Override - public T parseResource(Class theResourceType, Reader theReader) { + public T parseResource(Class theResourceType, Reader theReader) { JsonReader reader = Json.createReader(theReader); JsonObject object = reader.readObject(); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java index 5144e5833fb..34c96799df2 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java @@ -20,7 +20,9 @@ package ca.uhn.fhir.parser; * #L% */ -import static org.apache.commons.lang3.StringUtils.*; +import static org.apache.commons.lang3.StringUtils.defaultIfBlank; +import static org.apache.commons.lang3.StringUtils.isNotBlank; +import static org.apache.commons.lang3.StringUtils.isNotEmpty; import java.util.ArrayList; import java.util.HashMap; @@ -32,6 +34,7 @@ import javax.xml.stream.events.XMLEvent; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.Validate; +import org.hl7.fhir.instance.model.IBaseResource; import ca.uhn.fhir.context.BaseRuntimeChildDefinition; import ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition; @@ -53,6 +56,7 @@ import ca.uhn.fhir.model.api.ICompositeElement; import ca.uhn.fhir.model.api.IElement; import ca.uhn.fhir.model.api.IIdentifiableElement; import ca.uhn.fhir.model.api.IPrimitiveDatatype; +import ca.uhn.fhir.model.api.IBaseResource; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.IResourceBlock; import ca.uhn.fhir.model.api.ISupportsUndeclaredExtensions; @@ -135,7 +139,7 @@ class ParserState { if (def == null) { throw new DataFormatException("Entry references unknown resource type: " + resourceType); } - resource = def.newInstance(); + resource = (IResource) def.newInstance(); resource.setId(id); entry.setResource(resource); } @@ -164,7 +168,7 @@ class ParserState { myState.xmlEvent(theNextEvent); } - public static ParserState getPreAtomInstance(FhirContext theContext, Class theResourceType, boolean theJsonMode) throws DataFormatException { + public static ParserState getPreAtomInstance(FhirContext theContext, Class theResourceType, boolean theJsonMode) throws DataFormatException { ParserState retVal = new ParserState(theContext, theJsonMode); retVal.push(retVal.new PreAtomState(theResourceType)); return retVal; @@ -174,7 +178,7 @@ class ParserState { * @param theResourceType * May be null */ - public static ParserState getPreResourceInstance(Class theResourceType, FhirContext theContext, boolean theJsonMode) throws DataFormatException { + public static ParserState getPreResourceInstance(Class theResourceType, FhirContext theContext, boolean theJsonMode) throws DataFormatException { ParserState retVal = new ParserState(theContext, theJsonMode); retVal.push(retVal.new PreResourceState(theResourceType)); return retVal; @@ -291,7 +295,7 @@ class ParserState { public class AtomDeletedEntryState extends AtomEntryState { - public AtomDeletedEntryState(Bundle theInstance, Class theResourceType) { + public AtomDeletedEntryState(Bundle theInstance, Class theResourceType) { super(theInstance, theResourceType); } @@ -388,9 +392,9 @@ class ParserState { private boolean myDeleted; private BundleEntry myEntry; - private Class myResourceType; + private Class myResourceType; - public AtomEntryState(Bundle theInstance, Class theResourceType) { + public AtomEntryState(Bundle theInstance, Class theResourceType) { super(null); myEntry = new BundleEntry(); myResourceType = theResourceType; @@ -601,9 +605,9 @@ class ParserState { private class AtomState extends BaseState { private Bundle myInstance; - private Class myResourceType; + private Class myResourceType; - public AtomState(Bundle theInstance, Class theResourceType) { + public AtomState(Bundle theInstance, Class theResourceType) { super(null); myInstance = theInstance; myResourceType = theResourceType; @@ -750,8 +754,8 @@ class ParserState { if ("id".equals(theName)) { if (myInstance instanceof IIdentifiableElement) { ((IIdentifiableElement) myInstance).setElementSpecificId((theValue)); - } else if (myInstance instanceof IResource) { - ((IResource) myInstance).setId(new IdDt(theValue)); + } else if (myInstance instanceof IBaseResource) { + ((IBaseResource) myInstance).setId(new IdDt(theValue)); } } else if ("contentType".equals(theName)) { myInstance.setContentType(theValue); @@ -822,7 +826,7 @@ class ParserState { @Override public void wereBack() { - IResource res = getCurrentElement(); + IBaseResource res = getCurrentElement(); assert res != null; if (res.getId() == null || res.getId().isEmpty()) { ourLog.debug("Discarding contained resource with no ID!"); @@ -936,8 +940,8 @@ class ParserState { if ("id".equals(theName)) { if (myInstance instanceof IIdentifiableElement) { ((IIdentifiableElement) myInstance).setElementSpecificId((theValue)); - } else if (myInstance instanceof IResource) { - ((IResource) myInstance).setId(new IdDt(theValue)); + } else if (myInstance instanceof IBaseResource) { + ((IBaseResource) myInstance).setId(new IdDt(theValue)); } } else if ("url".equals(theName) && myInstance instanceof ExtensionDt) { ((ExtensionDt) myInstance).setUrl(theValue); @@ -1125,9 +1129,9 @@ class ParserState { private class PreAtomState extends BaseState { private Bundle myInstance; - private Class myResourceType; + private Class myResourceType; - public PreAtomState(Class theResourceType) { + public PreAtomState(Class theResourceType) { super(null); myResourceType = theResourceType; } @@ -1162,19 +1166,19 @@ class ParserState { * Stitch together resource references */ - Map idToResource = new HashMap(); - List resources = myInstance.toListOfResources(); - for (IResource next : resources) { + Map idToResource = new HashMap(); + List resources = myInstance.toListOfResources(); + for (IBaseResource next : resources) { if (next.getId() != null && next.getId().isEmpty() == false) { idToResource.put(next.getId().toUnqualifiedVersionless().getValue(), next); } } - for (IResource next : resources) { + for (IBaseResource next : resources) { List refs = myContext.newTerser().getAllPopulatedChildElementsOfType(next, ResourceReferenceDt.class); for (ResourceReferenceDt nextRef : refs) { if (nextRef.isEmpty() == false && nextRef.getReference() != null) { - IResource target = idToResource.get(nextRef.getReference().getValue()); + IBaseResource target = idToResource.get(nextRef.getReference().getValue()); if (target != null) { nextRef.setResource(target); } @@ -1188,13 +1192,13 @@ class ParserState { private class PreResourceState extends BaseState { - private Map myContainedResources = new HashMap(); + private Map myContainedResources = new HashMap(); private BundleEntry myEntry; - private IResource myInstance; + private IBaseResource myInstance; private List myResourceReferences = new ArrayList(); - private Class myResourceType; + private Class myResourceType; - public PreResourceState(BundleEntry theEntry, Class theResourceType) { + public PreResourceState(BundleEntry theEntry, Class theResourceType) { super(null); myEntry = theEntry; myResourceType = theResourceType; @@ -1204,7 +1208,7 @@ class ParserState { * @param theResourceType * May be null */ - public PreResourceState(Class theResourceType) { + public PreResourceState(Class theResourceType) { super(null); myResourceType = theResourceType; } @@ -1249,12 +1253,12 @@ class ParserState { } } - public Map getContainedResources() { + public Map getContainedResources() { return myContainedResources; } @Override - protected IResource getCurrentElement() { + protected IBaseResource getCurrentElement() { return myInstance; } @@ -1297,7 +1301,7 @@ class ParserState { String ref = nextRef.getReference().getValue(); if (isNotBlank(ref)) { if (ref.startsWith("#")) { - IResource target = myContainedResources.get(ref.substring(1)); + IBaseResource target = myContainedResources.get(ref.substring(1)); if (target != null) { nextRef.setResource(target); } else { @@ -1369,8 +1373,8 @@ class ParserState { } else if ("id".equals(theName)) { if (myInstance instanceof IIdentifiableElement) { ((IIdentifiableElement) myInstance).setElementSpecificId(theValue); - } else if (myInstance instanceof IResource) { - ((IResource) myInstance).setId(new IdDt(theValue)); + } else if (myInstance instanceof IBaseResource) { + ((IBaseResource) myInstance).setId(new IdDt(theValue)); } } } diff --git a/hapi-fhir-structures-hl7org-dev/bin/.gitignore b/hapi-fhir-structures-hl7org-dev/bin/.gitignore deleted file mode 100644 index ae3c1726048..00000000000 --- a/hapi-fhir-structures-hl7org-dev/bin/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/bin/