Пример #1
0
        public virtual void ConvertToXML(XMLStreamWriter xtw, BaseElement baseElement, BpmnModel model)
        {
            xtw.WriteStartElement(BpmnXMLConstants.BPMN_PREFIX, XMLElementName, BpmnXMLConstants.BPMN2_NAMESPACE);
            bool didWriteExtensionStartElement = false;

            WriteDefaultAttribute(BpmnXMLConstants.ATTRIBUTE_ID, baseElement.Id, xtw);
            if (baseElement is FlowElement)
            {
                WriteDefaultAttribute(BpmnXMLConstants.ATTRIBUTE_NAME, ((FlowElement)baseElement).Name, xtw);
            }

            if (baseElement is FlowNode flowNode)
            {
                if (flowNode.Asynchronous)
                {
                    WriteQualifiedAttribute(BpmnXMLConstants.ATTRIBUTE_ACTIVITY_ASYNCHRONOUS, BpmnXMLConstants.ATTRIBUTE_VALUE_TRUE, xtw);
                    if (flowNode.NotExclusive)
                    {
                        WriteQualifiedAttribute(BpmnXMLConstants.ATTRIBUTE_ACTIVITY_EXCLUSIVE, BpmnXMLConstants.ATTRIBUTE_VALUE_FALSE, xtw);
                    }
                }

                if (baseElement is Activity activity)
                {
                    if (activity.ForCompensation)
                    {
                        WriteDefaultAttribute(BpmnXMLConstants.ATTRIBUTE_ACTIVITY_ISFORCOMPENSATION, BpmnXMLConstants.ATTRIBUTE_VALUE_TRUE, xtw);
                    }
                    if (!string.IsNullOrWhiteSpace(activity.DefaultFlow))
                    {
                        FlowElement defaultFlowElement = model.GetFlowElement(activity.DefaultFlow);
                        if (defaultFlowElement is SequenceFlow)
                        {
                            WriteDefaultAttribute(BpmnXMLConstants.ATTRIBUTE_DEFAULT, activity.DefaultFlow, xtw);
                        }
                    }
                }

                if (baseElement is Gateway gateway)
                {
                    if (!string.IsNullOrWhiteSpace(gateway.DefaultFlow))
                    {
                        FlowElement defaultFlowElement = model.GetFlowElement(gateway.DefaultFlow);
                        if (defaultFlowElement is SequenceFlow)
                        {
                            WriteDefaultAttribute(BpmnXMLConstants.ATTRIBUTE_DEFAULT, gateway.DefaultFlow, xtw);
                        }
                    }
                }
            }

            WriteAdditionalAttributes(baseElement, model, xtw);

            if (baseElement is FlowElement flowElement)
            {
                if (!string.IsNullOrWhiteSpace(flowElement.Documentation))
                {
                    xtw.WriteStartElement(BpmnXMLConstants.BPMN_PREFIX, BpmnXMLConstants.ELEMENT_DOCUMENTATION, BpmnXMLConstants.BPMN2_NAMESPACE);
                    xtw.WriteCharacters(flowElement.Documentation);
                    xtw.WriteEndElement();
                }
            }

            didWriteExtensionStartElement = WriteExtensionChildElements(baseElement, didWriteExtensionStartElement, xtw);
            didWriteExtensionStartElement = WriteListeners(baseElement, didWriteExtensionStartElement, xtw);
            didWriteExtensionStartElement = BpmnXMLUtil.WriteExtensionElements(baseElement, didWriteExtensionStartElement, model.Namespaces, xtw);
            if (baseElement is Activity)
            {
                FailedJobRetryCountExport.WriteFailedJobRetryCount(baseElement as Activity, xtw);
            }

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

            if (baseElement is Activity)
            {
                MultiInstanceExport.WriteMultiInstance(baseElement as Activity, xtw);
            }

            WriteAdditionalChildElements(baseElement, model, xtw);

            xtw.WriteEndElement();
        }
Пример #2
0
        public virtual void CreateXML(FlowElement flowElement, BpmnModel model, XMLStreamWriter xtw)
        {
            if (flowElement is SubProcess subProcess)
            {
                if (flowElement is Transaction)
                {
                    xtw.WriteStartElement(BpmnXMLConstants.BPMN_PREFIX, BpmnXMLConstants.ELEMENT_TRANSACTION, BpmnXMLConstants.BPMN2_NAMESPACE);
                }
                else if (flowElement is AdhocSubProcess)
                {
                    xtw.WriteStartElement(BpmnXMLConstants.BPMN_PREFIX, BpmnXMLConstants.ELEMENT_ADHOC_SUBPROCESS, BpmnXMLConstants.BPMN2_NAMESPACE);
                }
                else
                {
                    xtw.WriteStartElement(BpmnXMLConstants.BPMN_PREFIX, BpmnXMLConstants.ELEMENT_SUBPROCESS, BpmnXMLConstants.BPMN2_NAMESPACE);
                }

                xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_ID, subProcess.Id);
                if (!string.IsNullOrWhiteSpace(subProcess.Name))
                {
                    xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_NAME, subProcess.Name);
                }
                else
                {
                    xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_NAME, "subProcess");
                }

                if (subProcess is EventSubProcess)
                {
                    xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_TRIGGERED_BY, BpmnXMLConstants.ATTRIBUTE_VALUE_TRUE);
                }
                else if (!(subProcess is Transaction))
                {
                    if (subProcess.Asynchronous)
                    {
                        BpmnXMLUtil.WriteQualifiedAttribute(BpmnXMLConstants.ATTRIBUTE_ACTIVITY_ASYNCHRONOUS, BpmnXMLConstants.ATTRIBUTE_VALUE_TRUE, xtw);
                        if (subProcess.NotExclusive)
                        {
                            BpmnXMLUtil.WriteQualifiedAttribute(BpmnXMLConstants.ATTRIBUTE_ACTIVITY_EXCLUSIVE, BpmnXMLConstants.ATTRIBUTE_VALUE_FALSE, xtw);
                        }
                    }
                }
                else if (subProcess is AdhocSubProcess hocSubProcess)
                {
                    BpmnXMLUtil.WriteDefaultAttribute(BpmnXMLConstants.ATTRIBUTE_CANCEL_REMAINING_INSTANCES, hocSubProcess.CancelRemainingInstances.ToString(), xtw);
                    if (!string.IsNullOrWhiteSpace(hocSubProcess.Ordering))
                    {
                        BpmnXMLUtil.WriteDefaultAttribute(BpmnXMLConstants.ATTRIBUTE_ORDERING, hocSubProcess.Ordering, xtw);
                    }
                }

                if (!string.IsNullOrWhiteSpace(subProcess.Documentation))
                {
                    xtw.WriteStartElement(BpmnXMLConstants.BPMN_PREFIX, BpmnXMLConstants.ELEMENT_DOCUMENTATION, BpmnXMLConstants.BPMN2_NAMESPACE);
                    xtw.WriteCharacters(subProcess.Documentation);
                    xtw.WriteEndElement();
                }

                bool didWriteExtensionStartElement = ActivitiListenerExport.WriteListeners(subProcess, false, xtw);

                didWriteExtensionStartElement = BpmnXMLUtil.WriteExtensionElements(subProcess, didWriteExtensionStartElement, model.Namespaces, xtw);
                if (didWriteExtensionStartElement)
                {
                    // closing extensions element
                    xtw.WriteEndElement();
                }

                MultiInstanceExport.WriteMultiInstance(subProcess, xtw);

                if (subProcess is AdhocSubProcess adhocSubProcess)
                {
                    if (!string.IsNullOrWhiteSpace(adhocSubProcess.CompletionCondition))
                    {
                        xtw.WriteStartElement(BpmnXMLConstants.BPMN_PREFIX, BpmnXMLConstants.ELEMENT_COMPLETION_CONDITION, BpmnXMLConstants.BPMN2_NAMESPACE);
                        xtw.WriteCData(adhocSubProcess.CompletionCondition);
                        xtw.WriteEndElement();
                    }
                }

                foreach (FlowElement subElement in subProcess.FlowElements)
                {
                    CreateXML(subElement, model, xtw);
                }

                foreach (Artifact artifact in subProcess.Artifacts)
                {
                    CreateXML(artifact, model, xtw);
                }

                xtw.WriteEndElement();
            }
            else
            {
                BaseBpmnXMLConverter converter = convertersToXMLMap[flowElement.GetType()];

                if (converter == null)
                {
                    throw new XMLException("No converter for " + flowElement.GetType() + " found");
                }

                converter.ConvertToXML(xtw, flowElement, model);
            }
        }