Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/jamesagnew/hapi-fhir into…
Browse files Browse the repository at this point in the history
… jaxrs-sever-evolution

# Conflicts:
#	hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/JsonParserDstu3Test.java
  • Loading branch information
SRiviere committed Jan 27, 2017
2 parents 6cc7eeb + 97f1e55 commit dabb3ea
Show file tree
Hide file tree
Showing 259 changed files with 1,932 additions and 1,103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,18 +216,6 @@ private void scanCompositeElementForChildren() {
orderToElementDef = newOrderToExtensionDef;
}

// while (orderToElementDef.size() > 0 && orderToElementDef.firstKey() <
// 0) {
// BaseRuntimeDeclaredChildDefinition elementDef =
// orderToElementDef.remove(orderToElementDef.firstKey());
// if (elementDef.getElementName().equals("identifier")) {
// orderToElementDef.put(theIdentifierOrder, elementDef);
// } else {
// throw new ConfigurationException("Don't know how to handle element: "
// + elementDef.getElementName());
// }
// }

TreeSet<Integer> orders = new TreeSet<Integer>();
orders.addAll(orderToElementDef.keySet());
orders.addAll(orderToExtensionDef.keySet());
Expand Down Expand Up @@ -372,7 +360,7 @@ private void scanCompositeElementForChildren(Set<String> elementNames, TreeMap<I
def = new RuntimeChildDirectResource(nextField, childAnnotation, descriptionAnnotation, elementName);
} else {
childIsChoiceType |= choiceTypes.size() > 1;
if (childIsChoiceType && !BaseResourceReferenceDt.class.isAssignableFrom(nextElementType) && !IBaseReference.class.isAssignableFrom(nextElementType)) {
if (extensionAttr == null && childIsChoiceType && !BaseResourceReferenceDt.class.isAssignableFrom(nextElementType) && !IBaseReference.class.isAssignableFrom(nextElementType)) {
def = new RuntimeChildChoiceDefinition(nextField, elementName, childAnnotation, descriptionAnnotation, choiceTypes);
} else if (extensionAttr != null) {
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,18 @@ public class RuntimeChildChoiceDefinition extends BaseRuntimeDeclaredChildDefini
private String myReferenceSuffix;
private List<Class<? extends IBaseResource>> myResourceTypes;

/**
* Constructor
*/
public RuntimeChildChoiceDefinition(Field theField, String theElementName, Child theChildAnnotation, Description theDescriptionAnnotation, List<Class<? extends IBase>> theChoiceTypes) {
super(theField, theChildAnnotation, theDescriptionAnnotation, theElementName);

myChoiceTypes = Collections.unmodifiableList(theChoiceTypes);
}

/**
* Constructor
*
* For extension, if myChoiceTypes will be set some other way
*/
RuntimeChildChoiceDefinition(Field theField, String theElementName, Child theChildAnnotation, Description theDescriptionAnnotation) {
Expand Down Expand Up @@ -143,6 +148,7 @@ void sealAndInitialize(FhirContext theContext, Map<Class<? extends IBase>, BaseR
if (IBaseResource.class.isAssignableFrom(next) || IBaseReference.class.isAssignableFrom(next)) {
next = theContext.getVersion().getResourceReferenceType();
elementName = getElementName() + myReferenceSuffix;
myNameToChildDefinition.put(elementName, nextDef);
}

myDatatypeToElementDefinition.put(next, nextDef);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -22,49 +22,66 @@
import static org.apache.commons.lang3.StringUtils.isNotBlank;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.IBaseResource;

import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.api.IElement;
import ca.uhn.fhir.model.api.annotation.Child;
import ca.uhn.fhir.model.api.annotation.Description;
import ca.uhn.fhir.model.api.annotation.Extension;
import ca.uhn.fhir.util.ReflectionUtil;

public class RuntimeChildDeclaredExtensionDefinition extends BaseRuntimeDeclaredChildDefinition {
public class RuntimeChildDeclaredExtensionDefinition extends RuntimeChildChoiceDefinition {

private BaseRuntimeElementDefinition<?> myChildDef;
private Class<? extends IBase> myChildType;
private String myDatatypeChildName;
private boolean myDefinedLocally;
private String myExtensionUrl;
private boolean myModifier;
private Map<String, RuntimeChildDeclaredExtensionDefinition> myUrlToChildExtension;
private volatile Object myInstanceConstructorArguments;
private Class<?> myEnumerationType;
private Class<? extends IBase> myChildType;
private RuntimeResourceBlockDefinition myChildResourceBlock;
private BaseRuntimeElementDefinition<?> myChildDef;

/**
* @param theBoundTypeBinder
* If the child is of a type that requires a constructor argument to instantiate, this is the argument to
* use
* If the child is of a type that requires a constructor argument to instantiate, this is the argument to
* use
* @param theDefinedLocally
* See {@link Extension#definedLocally()}
* See {@link Extension#definedLocally()}
*/
RuntimeChildDeclaredExtensionDefinition(Field theField, Child theChild, Description theDescriptionAnnotation, Extension theExtension, String theElementName, String theExtensionUrl, Class<? extends IBase> theChildType, Object theBoundTypeBinder)
RuntimeChildDeclaredExtensionDefinition(Field theField, Child theChild, Description theDescriptionAnnotation, Extension theExtension, String theElementName, String theExtensionUrl,
Class<? extends IBase> theChildType, Object theBoundTypeBinder)
throws ConfigurationException {
super(theField, theChild, theDescriptionAnnotation, theElementName);
super(theField, theElementName, theChild, theDescriptionAnnotation);
assert isNotBlank(theExtensionUrl);
myExtensionUrl = theExtensionUrl;
myChildType = theChildType;
myDefinedLocally = theExtension.definedLocally();
myModifier = theExtension.isModifier();
myInstanceConstructorArguments = theBoundTypeBinder;

List<Class<? extends IBase>> choiceTypes = new ArrayList<Class<? extends IBase>>();
for (Class<? extends IElement> next : theChild.type()) {
choiceTypes.add(next);
}

if (Modifier.isAbstract(theChildType.getModifiers()) == false) {
choiceTypes.add(theChildType);
}

setChoiceTypes(choiceTypes);
}

@Override
public String getElementName() {
return "value";
}

@Override
Expand All @@ -82,58 +99,66 @@ public void setEnumerationType(Class<?> theEnumerationType) {
}

@Override
public BaseRuntimeElementDefinition<?> getChildByName(String theName) {
if (myDatatypeChildName != null) {
if (myDatatypeChildName.equals(theName)) {
return myChildDef;
public String getChildNameByDatatype(Class<? extends IBase> theDatatype) {

String retVal = super.getChildNameByDatatype(theDatatype);

if (retVal != null) {
BaseRuntimeElementDefinition<?> childDef = super.getChildElementDefinitionByDatatype(theDatatype);
if (childDef instanceof RuntimeResourceBlockDefinition) {
// Child is a newted extension
retVal = null;
}
}

if (retVal == null) {
if (myModifier) {
return "modifierExtension";
} else {
return null;
return "extension";
}
} else {
return null;
}
return retVal;
}

@Override
public BaseRuntimeElementDefinition<?> getChildElementDefinitionByDatatype(Class<? extends IBase> theType) {
if (myChildType.equals(theType)) {
return myChildDef;
public BaseRuntimeElementDefinition<?> getChildByName(String theName) {
String name = theName;
if ("extension".equals(name)||"modifierExtension".equals(name)) {
if (myChildResourceBlock != null) {
return myChildResourceBlock;
}
if (myChildDef != null) {
return myChildDef;
}
}
return null;
}

public RuntimeChildDeclaredExtensionDefinition getChildExtensionForUrl(String theUrl) {
return myUrlToChildExtension.get(theUrl);
if (getValidChildNames().contains(name) == false) {
return null;
}

return super.getChildByName(name);
}

@Override
public String getChildNameByDatatype(Class<? extends IBase> theDatatype) {
if (myChildType.equals(theDatatype) && myDatatypeChildName != null) {
return myDatatypeChildName;
} else {
return "extension";
public BaseRuntimeElementDefinition<?> getChildElementDefinitionByDatatype(Class<? extends IBase> theDatatype) {
if (myChildResourceBlock != null) {
if (myChildResourceBlock.getImplementingClass().equals(theDatatype)) {
return myChildResourceBlock;
}
}
return super.getChildElementDefinitionByDatatype(theDatatype);
}

public Class<? extends IBase> getChildType() {
return myChildType;
public RuntimeChildDeclaredExtensionDefinition getChildExtensionForUrl(String theUrl) {
return myUrlToChildExtension.get(theUrl);
}

@Override
public String getExtensionUrl() {
return myExtensionUrl;
}

@Override
public BaseRuntimeElementDefinition<?> getSingleChildOrThrow() {
return myChildDef;
}

@Override
public Set<String> getValidChildNames() {
return Collections.emptySet();
}

public boolean isDefinedLocally() {
return myDefinedLocally;
}
Expand All @@ -143,50 +168,52 @@ public boolean isModifier() {
return myModifier;
}

public IBase newInstance() {
try {
return myChildType.newInstance();
} catch (InstantiationException e) {
throw new ConfigurationException("Failed to instantiate type:" + myChildType.getName(), e);
} catch (IllegalAccessException e) {
throw new ConfigurationException("Failed to instantiate type:" + myChildType.getName(), e);
}
}

@Override
void sealAndInitialize(FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
myUrlToChildExtension = new HashMap<String, RuntimeChildDeclaredExtensionDefinition>();

BaseRuntimeElementDefinition<?> elementDef = theClassToElementDefinitions.get(myChildType);

/*
* This will happen for any type that isn't defined in the base set of
* This will happen for any type that isn't defined in the base set of
* built-in types, e.g. custom structures or custom extensions
*/
if (elementDef == null) {
elementDef = theContext.getElementDefinition(myChildType);
if (Modifier.isAbstract(myChildType.getModifiers()) == false) {
elementDef = theContext.getElementDefinition(myChildType);
}
}

if (elementDef instanceof RuntimePrimitiveDatatypeDefinition || elementDef instanceof RuntimeCompositeDatatypeDefinition) {
myDatatypeChildName = "value" + elementDef.getName().substring(0, 1).toUpperCase() + elementDef.getName().substring(1);
if ("valueResourceReference".equals(myDatatypeChildName)) {
// myDatatypeChildName = "value" + elementDef.getName().substring(0, 1).toUpperCase() + elementDef.getName().substring(1);
// if ("valueResourceReference".equals(myDatatypeChildName)) {
// Per one of the examples here: http://hl7.org/implement/standards/fhir/extensibility.html#extension
myDatatypeChildName = "valueResource";
List<Class<? extends IBaseResource>> types = new ArrayList<Class<? extends IBaseResource>>();
types.add(IResource.class);
myChildDef = findResourceReferenceDefinition(theClassToElementDefinitions);
} else {
// myDatatypeChildName = "valueResource";
// List<Class<? extends IBaseResource>> types = new ArrayList<Class<? extends IBaseResource>>();
// types.add(IBaseResource.class);
// myChildDef = findResourceReferenceDefinition(theClassToElementDefinitions);
// } else {
myChildDef = elementDef;
}
} else {
// }
} else if (elementDef instanceof RuntimeResourceBlockDefinition) {
RuntimeResourceBlockDefinition extDef = ((RuntimeResourceBlockDefinition) elementDef);
for (RuntimeChildDeclaredExtensionDefinition next : extDef.getExtensions()) {
myUrlToChildExtension.put(next.getExtensionUrl(), next);
}
myChildDef = extDef;
myChildResourceBlock = (RuntimeResourceBlockDefinition) elementDef;
}

myUrlToChildExtension = Collections.unmodifiableMap(myUrlToChildExtension);

super.sealAndInitialize(theContext, theClassToElementDefinitions);
}

public IBase newInstance() {
return ReflectionUtil.newInstance(myChildType);
}

public Class<? extends IBase> getChildType() {
return myChildType;
}

}
Loading

0 comments on commit dabb3ea

Please sign in to comment.