Remove some unused code

This commit is contained in:
jamesagnew 2016-05-26 21:42:03 -04:00
parent badcbfc0ee
commit 9ed1bb94f9
8 changed files with 33 additions and 287 deletions

View File

@ -195,7 +195,7 @@ public abstract class BaseRuntimeElementDefinition<T extends IBase> {
public abstract ChildTypeEnum getChildType();
public enum ChildTypeEnum {
COMPOSITE_DATATYPE, PRIMITIVE_DATATYPE, RESOURCE, RESOURCE_REF, RESOURCE_BLOCK,
COMPOSITE_DATATYPE, PRIMITIVE_DATATYPE, RESOURCE, RESOURCE_BLOCK,
/**
* HAPI style.
*/

View File

@ -1,45 +0,0 @@
package ca.uhn.fhir.context;
/*
* #%L
* HAPI FHIR - Core Library
* %%
* Copyright (C) 2014 - 2016 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import java.util.Map;
import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.IBaseReference;
public class RuntimeResourceReferenceDefinition extends BaseRuntimeElementCompositeDefinition<IBaseReference> {
public RuntimeResourceReferenceDefinition(String theName, Class<? extends IBaseReference> theImplementingClass, boolean theStandardType) {
super(theName, theImplementingClass, theStandardType);
}
@Override
void sealAndInitialize(FhirContext theContext, Map<Class<? extends IBase>, BaseRuntimeElementDefinition<?>> theClassToElementDefinitions) {
super.sealAndInitialize(theContext, theClassToElementDefinitions);
}
@Override
public ca.uhn.fhir.context.BaseRuntimeElementDefinition.ChildTypeEnum getChildType() {
return ChildTypeEnum.RESOURCE_REF;
}
}

View File

@ -471,7 +471,6 @@ public class JsonParser extends BaseParser implements IParser {
}
break;
}
case RESOURCE_REF:
case RESOURCE_BLOCK:
case COMPOSITE_DATATYPE: {
if (theChildName != null) {

View File

@ -91,6 +91,7 @@ import ca.uhn.fhir.rest.server.Constants;
import ca.uhn.fhir.util.BundleUtil;
import ca.uhn.fhir.util.FhirTerser;
import ca.uhn.fhir.util.IModelVisitor;
import ca.uhn.fhir.util.ReflectionUtil;
class ParserState<T> {
@ -128,16 +129,6 @@ class ParserState<T> {
}
}
private BaseState createResourceReferenceState(ParserState<T>.PreResourceState thePreResourceState, IBase newChildInstance) {
BaseState newState;
if (newChildInstance instanceof IBaseReference) {
newState = new ResourceReferenceStateHl7Org(thePreResourceState, (IBaseReference) newChildInstance);
} else {
newState = new ResourceReferenceStateHapi(thePreResourceState, (BaseResourceReferenceDt) newChildInstance);
}
return newState;
}
public void endingElement() throws DataFormatException {
myState.endingElement();
}
@ -159,31 +150,7 @@ class ParserState<T> {
}
private Object newContainedDt(IResource theTarget) {
Object newChildInstance;
try {
newChildInstance = theTarget.getStructureFhirVersionEnum().getVersionImplementation().getContainedType().newInstance();
} catch (InstantiationException e) {
throw new ConfigurationException("Failed to instantiate " + myContext.getVersion().getResourceReferenceType(), e);
} catch (IllegalAccessException e) {
throw new ConfigurationException("Failed to instantiate " + myContext.getVersion().getResourceReferenceType(), e);
}
return newChildInstance;
}
private IBase newResourceReferenceDt(IBaseResource theTarget) {
IBase newChildInstance;
try {
IFhirVersion version;
version = theTarget.getStructureFhirVersionEnum().getVersionImplementation();
newChildInstance = version.getResourceReferenceType().newInstance();
} catch (InstantiationException e) {
throw new ConfigurationException("Failed to instantiate " + myContext.getVersion().getResourceReferenceType(), e);
} catch (IllegalAccessException e) {
throw new ConfigurationException("Failed to instantiate " + myContext.getVersion().getResourceReferenceType(), e);
}
return newChildInstance;
return ReflectionUtil.newInstance(theTarget.getStructureFhirVersionEnum().getVersionImplementation().getContainedType());
}
@SuppressWarnings("unchecked")
@ -1539,13 +1506,6 @@ class ParserState<T> {
push(newState);
return;
}
case RESOURCE_REF: {
IBase newChildInstance = newResourceReferenceDt(myPreResourceState.myInstance);
myDefinition.getMutator().addValue(myParentInstance, newChildInstance);
BaseState newState = createResourceReferenceState(getPreResourceState(), newChildInstance);
push(newState);
return;
}
case PRIMITIVE_XHTML:
case RESOURCE:
case RESOURCE_BLOCK:
@ -1607,7 +1567,6 @@ class ParserState<T> {
}
}
@SuppressWarnings("unchecked")
@Override
public void endingElement() {
pop();
@ -1666,13 +1625,6 @@ class ParserState<T> {
push(newState);
return;
}
case RESOURCE_REF: {
IBase newChildInstance = newResourceReferenceDt(getPreResourceState().myInstance);
child.getMutator().addValue(myInstance, newChildInstance);
BaseState newState = createResourceReferenceState(getPreResourceState(), newChildInstance);
push(newState);
return;
}
case RESOURCE_BLOCK: {
RuntimeResourceBlockDefinition blockTarget = (RuntimeResourceBlockDefinition) target;
IBase newBlockInstance = blockTarget.newInstance();
@ -1846,18 +1798,6 @@ class ParserState<T> {
push(newState);
return;
}
case RESOURCE_REF: {
ICompositeType newChildInstance = (ICompositeType) newResourceReferenceDt(getPreResourceState().myInstance);
myExtension.setValue(newChildInstance);
if (myContext.getVersion().getVersion().isRi()) {
ParserState<T>.ResourceReferenceStateHl7Org newState = new ResourceReferenceStateHl7Org(getPreResourceState(), (IBaseReference) newChildInstance);
push(newState);
} else {
ResourceReferenceStateHapi newState = new ResourceReferenceStateHapi(getPreResourceState(), (BaseResourceReferenceDt) newChildInstance);
push(newState);
}
return;
}
case PRIMITIVE_XHTML:
case RESOURCE:
case RESOURCE_BLOCK:
@ -2304,7 +2244,6 @@ class ParserState<T> {
}
}
@SuppressWarnings("unchecked")
@Override
public void wereBack() {
super.wereBack();
@ -2347,7 +2286,6 @@ class ParserState<T> {
}
}
@SuppressWarnings("unchecked")
@Override
public void wereBack() {
super.wereBack();
@ -2460,151 +2398,6 @@ class ParserState<T> {
}
private class ResourceReferenceStateHapi extends BaseState {
private BaseResourceReferenceDt myInstance;
private ResourceReferenceSubState mySubState;
public ResourceReferenceStateHapi(PreResourceState thePreResourceState, BaseResourceReferenceDt theInstance) {
super(thePreResourceState);
myInstance = theInstance;
mySubState = ResourceReferenceSubState.INITIAL;
}
@Override
public void attributeValue(String theName, String theValue) throws DataFormatException {
if (!"value".equals(theName)) {
return;
}
switch (mySubState) {
case DISPLAY:
myInstance.getDisplayElement().setValue(theValue);
break;
case INITIAL:
throw new DataFormatException("Unexpected attribute: " + theValue);
case REFERENCE:
myInstance.getReference().setValue(theValue);
break;
}
}
@Override
public void endingElement() {
switch (mySubState) {
case INITIAL:
pop();
break;
case DISPLAY:
case REFERENCE:
mySubState = ResourceReferenceSubState.INITIAL;
}
}
@Override
public void enteringNewElement(String theNamespaceUri, String theLocalPart) throws DataFormatException {
switch (mySubState) {
case INITIAL:
if ("display".equals(theLocalPart)) {
mySubState = ResourceReferenceSubState.DISPLAY;
break;
} else if ("reference".equals(theLocalPart)) {
mySubState = ResourceReferenceSubState.REFERENCE;
break;
} else if ("resource".equals(theLocalPart)) {
mySubState = ResourceReferenceSubState.REFERENCE;
break;
}
//$FALL-THROUGH$
case DISPLAY:
case REFERENCE:
throw new DataFormatException("Unexpected element: " + theLocalPart);
}
}
@Override
protected IElement getCurrentElement() {
return myInstance;
}
}
private class ResourceReferenceStateHl7Org extends BaseState {
private IBaseReference myInstance;
private ResourceReferenceSubState mySubState;
public ResourceReferenceStateHl7Org(PreResourceState thePreResourceState, IBaseReference theInstance) {
super(thePreResourceState);
myInstance = theInstance;
mySubState = ResourceReferenceSubState.INITIAL;
}
@Override
public void attributeValue(String theName, String theValue) throws DataFormatException {
if (!"value".equals(theName)) {
return;
}
switch (mySubState) {
case DISPLAY:
myInstance.setDisplay(theValue);
break;
case INITIAL:
throw new DataFormatException("Unexpected attribute: " + theValue);
case REFERENCE:
myInstance.setReference(theValue);
break;
}
}
@Override
public void endingElement() {
switch (mySubState) {
case INITIAL:
pop();
break;
case DISPLAY:
case REFERENCE:
mySubState = ResourceReferenceSubState.INITIAL;
}
}
@Override
public void enteringNewElement(String theNamespaceUri, String theLocalPart) throws DataFormatException {
switch (mySubState) {
case INITIAL:
if ("display".equals(theLocalPart)) {
mySubState = ResourceReferenceSubState.DISPLAY;
break;
} else if ("reference".equals(theLocalPart)) {
mySubState = ResourceReferenceSubState.REFERENCE;
break;
} else if ("resource".equals(theLocalPart)) {
mySubState = ResourceReferenceSubState.REFERENCE;
break;
} else {
logAndSwallowUnexpectedElement(theLocalPart);
break;
}
case DISPLAY:
case REFERENCE:
logAndSwallowUnexpectedElement(theLocalPart);
break;
}
}
@Override
protected IBaseReference getCurrentElement() {
return myInstance;
}
}
private enum ResourceReferenceSubState {
DISPLAY, INITIAL, REFERENCE
}
private class ResourceStateHapi extends ElementCompositeState {
private IResource myInstance;

View File

@ -531,7 +531,6 @@ public class XmlParser extends BaseParser implements IParser {
}
break;
}
case RESOURCE_REF:
case RESOURCE_BLOCK:
case COMPOSITE_DATATYPE: {
theEventWriter.writeStartElement(childName);

View File

@ -422,16 +422,6 @@ public class FhirTerser {
case PRIMITIVE_DATATYPE:
// These are primitive types, so we don't need to visit their children
break;
case RESOURCE_REF:
IBaseReference resRefDt = (IBaseReference) theElement;
if (resRefDt.getReferenceElement().getValue() == null && resRefDt.getResource() != null) {
IBaseResource theResource = resRefDt.getResource();
if (theResource.getIdElement() == null || theResource.getIdElement().isEmpty() || theResource.getIdElement().isLocal()) {
BaseRuntimeElementCompositeDefinition<?> def = myContext.getResourceDefinition(theResource);
visit(theResource, null, def, theCallback, theContainingElementPath, theChildDefinitionPath, theElementDefinitionPath);
}
}
break;
case RESOURCE:
case RESOURCE_BLOCK:
case COMPOSITE_DATATYPE: {
@ -575,7 +565,6 @@ public class FhirTerser {
case PRIMITIVE_DATATYPE:
// These are primitive types
break;
case RESOURCE_REF:
case RESOURCE:
case RESOURCE_BLOCK:
case COMPOSITE_DATATYPE: {

View File

@ -0,0 +1,28 @@
package ca.uhn.fhir.util;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import ca.uhn.fhir.context.ConfigurationException;
public class ReflectionUtilTest {
@Test
public void testNewInstance() {
assertEquals(ArrayList.class, ReflectionUtil.newInstance(ArrayList.class).getClass());
}
@Test
public void testNewInstanceFail() {
try {
ReflectionUtil.newInstance(List.class);
fail();
} catch (ConfigurationException e) {
assertEquals("Failed to instantiate java.util.List", e.getMessage());
}
}
}

View File

@ -19,8 +19,8 @@ package ca.uhn.fhir.model.dstu;
* limitations under the License.
* #L%
*/
import static org.apache.commons.lang3.StringUtils.*;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.apache.commons.lang3.StringUtils.join;
import java.io.InputStream;
import java.util.Collections;
@ -59,7 +59,6 @@ import ca.uhn.fhir.context.RuntimeCompositeDatatypeDefinition;
import ca.uhn.fhir.context.RuntimePrimitiveDatatypeDefinition;
import ca.uhn.fhir.context.RuntimeResourceBlockDefinition;
import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.context.RuntimeResourceReferenceDefinition;
import ca.uhn.fhir.model.api.ICompositeDatatype;
import ca.uhn.fhir.model.api.IFhirVersion;
import ca.uhn.fhir.model.api.IPrimitiveDatatype;
@ -168,22 +167,6 @@ public class FhirDstu1 implements IFhirVersion {
private void fillName(StructureElement elem, BaseRuntimeElementDefinition<?> nextDef, String theServerBase) {
assert nextDef != null;
if (nextDef instanceof RuntimeResourceReferenceDefinition) {
// RuntimeResourceReferenceDefinition rr = (RuntimeResourceReferenceDefinition) nextDef;
// for (Class<? extends IBaseResource> next : rr.getResourceTypes()) {
// StructureElementDefinitionType type = elem.getDefinition().addType();
// type.getCode().setValue("ResourceReference");
//
// if (next != IResource.class) {
// @SuppressWarnings("unchecked")
// RuntimeResourceDefinition resDef = rr.getDefinitionForResourceType((Class<? extends IResource>) next);
// type.getProfile().setValueAsString(resDef.getResourceProfile(theServerBase));
// }
// }
return;
}
StructureElementDefinitionType type = elem.getDefinition().addType();
String name = nextDef.getName();