Exemplo n.º 1
0
  public void convertToXML(XMLStreamWriter xtw, BaseElement baseElement, BpmnModel model)
      throws Exception {
    xtw.writeStartElement(getXMLElementName());
    boolean didWriteExtensionStartElement = false;
    writeDefaultAttribute(ATTRIBUTE_ID, baseElement.getId(), xtw);
    if (baseElement instanceof FlowElement) {
      writeDefaultAttribute(ATTRIBUTE_NAME, ((FlowElement) baseElement).getName(), xtw);
    }

    if (baseElement instanceof Activity) {
      final Activity activity = (Activity) baseElement;
      if (activity.isAsynchronous()) {
        writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_ASYNCHRONOUS, ATTRIBUTE_VALUE_TRUE, xtw);
        if (activity.isNotExclusive()) {
          writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_EXCLUSIVE, ATTRIBUTE_VALUE_FALSE, xtw);
        }
      }
      if (StringUtils.isNotEmpty(activity.getDefaultFlow())) {
        FlowElement defaultFlowElement = model.getFlowElement(activity.getDefaultFlow());
        if (defaultFlowElement != null && defaultFlowElement instanceof SequenceFlow) {
          writeDefaultAttribute(ATTRIBUTE_DEFAULT, activity.getDefaultFlow(), xtw);
        }
      }
    }

    if (baseElement instanceof Gateway) {
      final Gateway gateway = (Gateway) baseElement;
      if (gateway.isAsynchronous()) {
        writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_ASYNCHRONOUS, ATTRIBUTE_VALUE_TRUE, xtw);
        if (gateway.isNotExclusive()) {
          writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_EXCLUSIVE, ATTRIBUTE_VALUE_FALSE, xtw);
        }
      }
      if (StringUtils.isNotEmpty(gateway.getDefaultFlow())) {
        FlowElement defaultFlowElement = model.getFlowElement(gateway.getDefaultFlow());
        if (defaultFlowElement != null && defaultFlowElement instanceof SequenceFlow) {
          writeDefaultAttribute(ATTRIBUTE_DEFAULT, gateway.getDefaultFlow(), xtw);
        }
      }
    }

    writeAdditionalAttributes(baseElement, model, xtw);

    if (baseElement instanceof FlowElement) {
      final FlowElement flowElement = (FlowElement) baseElement;
      if (StringUtils.isNotEmpty(flowElement.getDocumentation())) {

        xtw.writeStartElement(ELEMENT_DOCUMENTATION);
        xtw.writeCharacters(flowElement.getDocumentation());
        xtw.writeEndElement();
      }
    }

    didWriteExtensionStartElement =
        writeExtensionChildElements(baseElement, didWriteExtensionStartElement, xtw);
    didWriteExtensionStartElement = writeListeners(baseElement, didWriteExtensionStartElement, xtw);
    didWriteExtensionStartElement =
        BpmnXMLUtil.writeExtensionElements(baseElement, didWriteExtensionStartElement, xtw);

    if (didWriteExtensionStartElement) {
      xtw.writeEndElement();
    }

    if (baseElement instanceof Activity) {
      final Activity activity = (Activity) baseElement;
      MultiInstanceExport.writeMultiInstance(activity, xtw);
    }

    writeAdditionalChildElements(baseElement, model, xtw);

    xtw.writeEndElement();
  }
  public void convertToXML(XMLStreamWriter xtw, FlowElement flowElement) throws Exception {
    xtw.writeStartElement(getXMLElementName());
    didWriteExtensionStartElement = false;
    writeDefaultAttribute(ATTRIBUTE_ID, flowElement.getId(), xtw);
    writeDefaultAttribute(ATTRIBUTE_NAME, flowElement.getName(), xtw);

    if (flowElement instanceof Activity) {
      Activity activity = (Activity) flowElement;
      if (activity.isAsynchronous()) {
        writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_ASYNCHRONOUS, ATTRIBUTE_VALUE_TRUE, xtw);
      }
      if (activity.isNotExclusive()) {
        writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_EXCLUSIVE, ATTRIBUTE_VALUE_FALSE, xtw);
      }
      writeDefaultAttribute(ATTRIBUTE_ACTIVITY_DEFAULT, activity.getDefaultFlow(), xtw);
    }

    writeAdditionalAttributes(flowElement, xtw);
    if (StringUtils.isNotEmpty(flowElement.getDocumentation())) {

      xtw.writeStartElement(ELEMENT_DOCUMENTATION);
      xtw.writeCharacters(flowElement.getDocumentation());
      xtw.writeEndElement();
    }
    writeAdditionalChildElements(flowElement, xtw);

    writeListeners(flowElement, xtw);

    if (didWriteExtensionStartElement) {
      xtw.writeEndElement();
    }

    if (flowElement instanceof Activity) {
      Activity activity = (Activity) flowElement;
      if (activity.getLoopCharacteristics() != null) {
        MultiInstanceLoopCharacteristics multiInstanceObject = activity.getLoopCharacteristics();
        if (StringUtils.isNotEmpty(multiInstanceObject.getLoopCardinality())
            || StringUtils.isNotEmpty(multiInstanceObject.getInputDataItem())
            || StringUtils.isNotEmpty(multiInstanceObject.getCompletionCondition())) {

          xtw.writeStartElement(ELEMENT_MULTIINSTANCE);
          writeDefaultAttribute(
              ATTRIBUTE_MULTIINSTANCE_SEQUENTIAL,
              String.valueOf(multiInstanceObject.isSequential()).toLowerCase(),
              xtw);
          if (StringUtils.isNotEmpty(multiInstanceObject.getInputDataItem())) {
            writeQualifiedAttribute(
                ATTRIBUTE_MULTIINSTANCE_COLLECTION, multiInstanceObject.getInputDataItem(), xtw);
          }
          if (StringUtils.isNotEmpty(multiInstanceObject.getElementVariable())) {
            writeQualifiedAttribute(
                ATTRIBUTE_MULTIINSTANCE_VARIABLE, multiInstanceObject.getElementVariable(), xtw);
          }
          if (StringUtils.isNotEmpty(multiInstanceObject.getLoopCardinality())) {
            xtw.writeStartElement(ELEMENT_MULTIINSTANCE_CARDINALITY);
            xtw.writeCharacters(multiInstanceObject.getLoopCardinality());
            xtw.writeEndElement();
          }
          if (StringUtils.isNotEmpty(multiInstanceObject.getCompletionCondition())) {
            xtw.writeStartElement(ELEMENT_MULTIINSTANCE_CONDITION);
            xtw.writeCharacters(multiInstanceObject.getCompletionCondition());
            xtw.writeEndElement();
          }
          xtw.writeEndElement();
        }
      }
    }

    xtw.writeEndElement();
  }