private void addRemoteProcessGroup(
      final Element parentElement, final RemoteProcessGroup remoteRef) {
    final Document doc = parentElement.getOwnerDocument();
    final Element element = doc.createElement("remoteProcessGroup");
    parentElement.appendChild(element);
    addTextElement(element, "id", remoteRef.getIdentifier());
    addTextElement(element, "name", remoteRef.getName());
    addPosition(element, remoteRef.getPosition());
    addTextElement(element, "comment", remoteRef.getComments());
    addTextElement(element, "url", remoteRef.getTargetUri().toString());
    addTextElement(element, "timeout", remoteRef.getCommunicationsTimeout());
    addTextElement(element, "yieldPeriod", remoteRef.getYieldDuration());
    addTextElement(element, "transmitting", String.valueOf(remoteRef.isTransmitting()));

    for (final RemoteGroupPort port : remoteRef.getInputPorts()) {
      if (port.hasIncomingConnection()) {
        addRemoteGroupPort(element, port, "inputPort");
      }
    }

    for (final RemoteGroupPort port : remoteRef.getOutputPorts()) {
      if (!port.getConnections().isEmpty()) {
        addRemoteGroupPort(element, port, "outputPort");
      }
    }

    parentElement.appendChild(element);
  }
  private void addRemoteGroupPort(
      final Element parentElement, final RemoteGroupPort port, final String elementName) {
    final Document doc = parentElement.getOwnerDocument();
    final Element element = doc.createElement(elementName);
    parentElement.appendChild(element);
    addTextElement(element, "id", port.getIdentifier());
    addTextElement(element, "name", port.getName());
    addPosition(element, port.getPosition());
    addTextElement(element, "comments", port.getComments());
    addTextElement(element, "scheduledState", port.getScheduledState().name());
    addTextElement(element, "maxConcurrentTasks", port.getMaxConcurrentTasks());
    addTextElement(
        element, "useCompression", String.valueOf(((RemoteGroupPort) port).isUseCompression()));

    parentElement.appendChild(element);
  }