Beispiel #1
0
  private void encodeChildElementToStreamWriter(
      IBaseResource theResource,
      XMLStreamWriter theEventWriter,
      IBase nextValue,
      String childName,
      BaseRuntimeElementDefinition<?> childDef,
      String theExtensionUrl,
      boolean theIncludedResource)
      throws XMLStreamException, DataFormatException {
    if (nextValue.isEmpty()) {
      if (childDef.getChildType() == ChildTypeEnum.CONTAINED_RESOURCES
          && getContainedResources().isEmpty() == false
          && theIncludedResource == false) {
        // We still want to go in..
      } else {
        return;
      }
    }

    switch (childDef.getChildType()) {
      case PRIMITIVE_DATATYPE:
        {
          IPrimitiveType<?> pd = (IPrimitiveType<?>) nextValue;
          String value = pd.getValueAsString();
          if (value != null) {
            theEventWriter.writeStartElement(childName);
            theEventWriter.writeAttribute("value", value);
            encodeExtensionsIfPresent(theResource, theEventWriter, nextValue, theIncludedResource);
            theEventWriter.writeEndElement();
          }
          break;
        }
      case RESOURCE_BLOCK:
      case COMPOSITE_DATATYPE:
        {
          theEventWriter.writeStartElement(childName);
          if (isNotBlank(theExtensionUrl)) {
            theEventWriter.writeAttribute("url", theExtensionUrl);
          }
          BaseRuntimeElementCompositeDefinition<?> childCompositeDef =
              (BaseRuntimeElementCompositeDefinition<?>) childDef;
          encodeCompositeElementToStreamWriter(
              theResource, nextValue, theEventWriter, childCompositeDef, theIncludedResource);
          theEventWriter.writeEndElement();
          break;
        }
      case RESOURCE_REF:
        {
          BaseResourceReferenceDt ref = (BaseResourceReferenceDt) nextValue;
          if (!ref.isEmpty()) {
            theEventWriter.writeStartElement(childName);
            encodeResourceReferenceToStreamWriter(theEventWriter, ref);
            theEventWriter.writeEndElement();
          }
          break;
        }
      case CONTAINED_RESOURCES:
        {
          BaseContainedDt value = (BaseContainedDt) nextValue;
          /*
           * Disable per #103 for (IResource next : value.getContainedResources()) { if (getContainedResources().getResourceId(next) != null) { continue; }
           * theEventWriter.writeStartElement("contained"); encodeResourceToXmlStreamWriter(next, theEventWriter, true, fixContainedResourceId(next.getId().getValue()));
           * theEventWriter.writeEndElement(); }
           */
          for (IBaseResource next : getContainedResources().getContainedResources()) {
            IdDt resourceId = getContainedResources().getResourceId(next);
            theEventWriter.writeStartElement("contained");
            encodeResourceToXmlStreamWriter(
                next, theEventWriter, true, fixContainedResourceId(resourceId.getValue()));
            theEventWriter.writeEndElement();
          }
          break;
        }
      case RESOURCE:
        {
          theEventWriter.writeStartElement(childName);
          IBaseResource resource = (IBaseResource) nextValue;
          encodeResourceToXmlStreamWriter(resource, theEventWriter, false);
          theEventWriter.writeEndElement();
          break;
        }
      case PRIMITIVE_XHTML:
        {
          XhtmlDt dt = (XhtmlDt) nextValue;
          if (dt.hasContent()) {
            encodeXhtml(dt, theEventWriter);
          }
          break;
        }
      case EXTENSION_DECLARED:
      case UNDECL_EXT:
        {
          throw new IllegalStateException("state should not happen: " + childDef.getName());
        }
    }
  }