public static String createExtensionChildName(BaseRuntimeElementDefinition<?> next) { String attrName = "value" + WordUtils.capitalize(next.getName()); return attrName; }
public T newInstance() { return newInstance(null); }
@Override public String toString() { return getClass().getSimpleName()+"[" + getName() + ", " + getImplementingClass().getSimpleName() + "]"; }
public T newInstance(Object theArgument) { try { if (theArgument == null) { return getConstructor(null).newInstance(); } return getConstructor(theArgument).newInstance(theArgument); } catch (Exception e) { throw new ConfigurationException("Failed to instantiate type:" + getImplementingClass().getName(), e); } }
if (next instanceof IRuntimeDatatypeDefinition) { myDatatypeToDefinition.put(next.getImplementingClass(), next); ourLog.trace("Not adding specialization: {}", next.getImplementingClass()); if (!next.isStandardType()) { continue; String qualifiedName = next.getImplementingClass().getName(); if (datatypeAttributeNameToDefinition.containsKey(attrName)) { BaseRuntimeElementDefinition<?> existing = datatypeAttributeNameToDefinition.get(attrName); throw new ConfigurationException("More than one child of " + getElementName() + " matches attribute name " + attrName + ". Found [" + existing.getImplementingClass().getName() + "] and [" + next.getImplementingClass().getName() + "]"); myDatatypeToAttributeName.put(next.getImplementingClass(), attrName);
String name = def.getName(); if (!expectedPath.equals(name)) { path.pollLast(); theElement.getDefinition().getNameReference().setValue(def.getName()); return; fillExtensions(theStruct, path, def.getExtensionsNonModifier(), "extension", false); fillExtensions(theStruct, path, def.getExtensionsModifier(), "modifierExtension", true); if (def.getChildType() == ChildTypeEnum.RESOURCE) { StructureElement narrative = theStruct.addElement(); narrative.setName("text");
@SuppressWarnings("unchecked") private void addParam(String theName, IBase theValue) { BaseRuntimeChildDefinition parameterChild = myParametersDef.getChildByName("parameter"); BaseRuntimeElementCompositeDefinition<?> parameterElem = (BaseRuntimeElementCompositeDefinition<?>) parameterChild.getChildByName("parameter"); IBase parameter = parameterElem.newInstance(); parameterChild.getMutator().addValue(myParameters, parameter); IPrimitiveType<String> name = (IPrimitiveType<String>) myContext.getElementDefinition("string").newInstance(); name.setValue(theName); parameterElem.getChildByName("name").getMutator().setValue(parameter, name); if (theValue instanceof IBaseDatatype) { BaseRuntimeElementDefinition<?> datatypeDef = myContext.getElementDefinition(theValue.getClass()); if (datatypeDef instanceof IRuntimeDatatypeDefinition) { Class<? extends IBaseDatatype> profileOf = ((IRuntimeDatatypeDefinition) datatypeDef).getProfileOf(); if (profileOf != null) { datatypeDef = myContext.getElementDefinition(profileOf); } } String childElementName = "value" + StringUtils.capitalize(datatypeDef.getName()); BaseRuntimeChildDefinition childByName = parameterElem.getChildByName(childElementName); childByName.getMutator().setValue(parameter, theValue); } else if (theValue instanceof IBaseResource) { parameterElem.getChildByName("resource").getMutator().setValue(parameter, theValue); } else { throw new IllegalArgumentException("Don't know how to handle parameter of type " + theValue.getClass()); } }
if (IBaseMetaType.class.isAssignableFrom(metaChild.getImplementingClass())) { IBaseMetaType newType = (IBaseMetaType) metaChild.newInstance(); theValues = Collections.singletonList(newType); retVal = new ArrayList<>(theValues); IBaseReference newRef = (IBaseReference) myContext.getElementDefinition(nextRef.getClass()).newInstance(); myContext.newTerser().cloneInto(nextRef, newRef, true); newRef.setReference(refText);
switch (childDef.getChildType()) { case ID_DATATYPE: { IIdType value = IIdType.class.cast(theElement); throw new IllegalStateException("state should not happen: " + childDef.getName());
for (Constructor<?> next : getImplementingClass().getConstructors()) { if (argumentType == VOID_CLASS) { if (next.getParameterTypes().length == 0) { throw new ConfigurationException("Class " + getImplementingClass() + " has no constructor with a single argument of type " + argumentType);
switch (theDefinition.getChildType()) { case ID_DATATYPE: case PRIMITIVE_XHTML_HL7ORG: for (Iterator<String> iter = new TreeSet<String>(nextChild.getValidChildNames()).iterator(); iter.hasNext(); ) { BaseRuntimeElementDefinition<?> childByName = nextChild.getChildByName(iter.next()); b.append(childByName.getImplementingClass().getSimpleName()); if (iter.hasNext()) { b.append(", "); throw new IllegalStateException("state should not happen: " + theDefinition.getChildType());
protected boolean isChildContained(BaseRuntimeElementDefinition<?> childDef, boolean theIncludedResource) { return (childDef.getChildType() == ChildTypeEnum.CONTAINED_RESOURCES || childDef.getChildType() == ChildTypeEnum.CONTAINED_RESOURCE_LIST) && getContainedResources().isEmpty() == false && theIncludedResource == false; }
private void extractDeclaredExtensions(IBase theResource, BaseRuntimeElementDefinition<?> resDef, List<HeldExtension> extensions, List<HeldExtension> modifierExtensions, CompositeChildElement theChildElem) { for (RuntimeChildDeclaredExtensionDefinition nextDef : resDef.getExtensionsNonModifier()) { for (IBase nextValue : nextDef.getAccessor().getValues(theResource)) { if (nextValue != null) { if (nextValue.isEmpty()) { continue; } extensions.add(new HeldExtension(nextDef, nextValue, theChildElem)); } } } for (RuntimeChildDeclaredExtensionDefinition nextDef : resDef.getExtensionsModifier()) { for (IBase nextValue : nextDef.getAccessor().getValues(theResource)) { if (nextValue != null) { if (nextValue.isEmpty()) { continue; } modifierExtensions.add(new HeldExtension(nextDef, nextValue, theChildElem)); } } } }
@SuppressWarnings("unchecked") private void addParam(String theName, IBase theValue) { BaseRuntimeChildDefinition parameterChild = myParametersDef.getChildByName("parameter"); BaseRuntimeElementCompositeDefinition<?> parameterElem = (BaseRuntimeElementCompositeDefinition<?>) parameterChild.getChildByName("parameter"); IBase parameter = parameterElem.newInstance(); parameterChild.getMutator().addValue(myParameters, parameter); IPrimitiveType<String> name = (IPrimitiveType<String>) myContext.getElementDefinition("string").newInstance(); name.setValue(theName); parameterElem.getChildByName("name").getMutator().setValue(parameter, name); if (theValue instanceof IBaseDatatype) { BaseRuntimeElementDefinition<?> datatypeDef = myContext.getElementDefinition(theValue.getClass()); if (datatypeDef instanceof IRuntimeDatatypeDefinition) { Class<? extends IBaseDatatype> profileOf = ((IRuntimeDatatypeDefinition) datatypeDef).getProfileOf(); if (profileOf != null) { datatypeDef = myContext.getElementDefinition(profileOf); } } String childElementName = "value" + StringUtils.capitalize(datatypeDef.getName()); BaseRuntimeChildDefinition childByName = parameterElem.getChildByName(childElementName); childByName.getMutator().setValue(parameter, theValue); } else if (theValue instanceof IBaseResource) { parameterElem.getChildByName("resource").getMutator().setValue(parameter, theValue); } else { throw new IllegalArgumentException("Don't know how to handle parameter of type " + theValue.getClass()); } }
if (IBaseMetaType.class.isAssignableFrom(metaChild.getImplementingClass())) { IBaseMetaType newType = (IBaseMetaType) metaChild.newInstance(); theValues = Collections.singletonList(newType); retVal = new ArrayList<>(theValues); IBaseReference newRef = (IBaseReference) myContext.getElementDefinition(nextRef.getClass()).newInstance(); myContext.newTerser().cloneInto(nextRef, newRef, true); newRef.setReference(refText);
switch (childDef.getChildType()) { case ID_DATATYPE: { IIdType value = IIdType.class.cast(theElement); throw new IllegalStateException("state should not happen: " + childDef.getName());
if (Date.class.equals(genericType)) { BaseRuntimeElementDefinition<?> dateTimeDef = theContext.getElementDefinition("dateTime"); parameterType = dateTimeDef.getImplementingClass(); } else if (String.class.equals(genericType) || genericType == null) { BaseRuntimeElementDefinition<?> dateTimeDef = theContext.getElementDefinition("string"); parameterType = dateTimeDef.getImplementingClass();
switch (theDefinition.getChildType()) { case ID_DATATYPE: case PRIMITIVE_XHTML_HL7ORG: for (Iterator<String> iter = new TreeSet<String>(nextChild.getValidChildNames()).iterator(); iter.hasNext(); ) { BaseRuntimeElementDefinition<?> childByName = nextChild.getChildByName(iter.next()); b.append(childByName.getImplementingClass().getSimpleName()); if (iter.hasNext()) { b.append(", "); throw new IllegalStateException("state should not happen: " + theDefinition.getChildType());
private void managePrimitiveExtension(final IBase theValue, final RuntimeResourceDefinition theResDef, final IBaseResource theResource, final JsonLikeWriter theEventWriter, final BaseRuntimeElementDefinition<?> def, final String childName) throws IOException { if (def.getChildType().equals(ID_DATATYPE) || def.getChildType().equals(PRIMITIVE_DATATYPE)) { final List<HeldExtension> extensions = new ArrayList<HeldExtension>(0); final List<HeldExtension> modifierExtensions = new ArrayList<HeldExtension>(0); // Undeclared extensions extractUndeclaredExtensions(theValue, extensions, modifierExtensions, myParent, null); // Declared extensions if (def != null) { extractDeclaredExtensions(theValue, def, extensions, modifierExtensions, myParent); } boolean haveContent = false; if (!extensions.isEmpty() || !modifierExtensions.isEmpty()) { haveContent = true; } if (haveContent) { beginObject(theEventWriter, '_' + childName); writeExtensionsAsDirectChild(theResource, theEventWriter, theResDef, extensions, modifierExtensions); theEventWriter.endObject(); } } }
public T newInstance(Object theArgument) { try { if (theArgument == null) { return getConstructor(null).newInstance(); } return getConstructor(theArgument).newInstance(theArgument); } catch (Exception e) { throw new ConfigurationException("Failed to instantiate type:" + getImplementingClass().getName(), e); } }