protected internal override void WriteAdditionalChildElements(BaseElement element, BpmnModel model, XMLStreamWriter xtw)
        {
            ScriptTask scriptTask = (ScriptTask)element;

            if (!string.IsNullOrWhiteSpace(scriptTask.Script))
            {
                xtw.WriteStartElement(BpmnXMLConstants.BPMN_PREFIX, BpmnXMLConstants.ATTRIBUTE_TASK_SCRIPT_TEXT, BpmnXMLConstants.BPMN2_NAMESPACE);
                xtw.WriteCData(scriptTask.Script);
                xtw.WriteEndElement();
            }
        }
Beispiel #2
0
        protected internal override void WriteAdditionalChildElements(BaseElement element, BpmnModel model, XMLStreamWriter xtw)
        {
            SequenceFlow sequenceFlow = (SequenceFlow)element;

            if (!string.IsNullOrWhiteSpace(sequenceFlow.ConditionExpression))
            {
                xtw.WriteStartElement(BpmnXMLConstants.BPMN_PREFIX, BpmnXMLConstants.ELEMENT_FLOW_CONDITION, BpmnXMLConstants.BPMN2_NAMESPACE);
                xtw.WriteAttribute(BpmnXMLConstants.XSI_PREFIX, BpmnXMLConstants.XSI_NAMESPACE, "type", "tFormalExpression");
                xtw.WriteCData(sequenceFlow.ConditionExpression);
                xtw.WriteEndElement();
            }
        }
        protected internal override bool WriteExtensionChildElements(BaseElement element, bool didWriteExtensionStartElement, XMLStreamWriter xtw)
        {
            ValuedDataObject dataObject = (ValuedDataObject)element;

            if (!string.IsNullOrWhiteSpace(dataObject.Id) && dataObject.Value != null)
            {
                if (!didWriteExtensionStartElement)
                {
                    xtw.WriteStartElement(BpmnXMLConstants.BPMN_PREFIX, BpmnXMLConstants.ELEMENT_EXTENSIONS, BpmnXMLConstants.BPMN2_NAMESPACE);
                    didWriteExtensionStartElement = true;
                }

                xtw.WriteStartElement(BpmnXMLConstants.ACTIVITI_EXTENSIONS_PREFIX, BpmnXMLConstants.ELEMENT_DATA_VALUE, BpmnXMLConstants.ACTIVITI_EXTENSIONS_NAMESPACE);
                if (dataObject.Value != null)
                {
                    string value;
                    if (dataObject is DateDataObject)
                    {
                        value = ((DateTime)dataObject.Value).ToString(sdf);
                    }
                    else
                    {
                        value = dataObject.Value.ToString();
                    }

                    if (dataObject is StringDataObject && xmlChars.IsMatch(value))
                    {
                        xtw.WriteCData(value);
                    }
                    else
                    {
                        xtw.WriteCharacters(value);
                    }
                }
                xtw.WriteEndElement();
            }

            return(didWriteExtensionStartElement);
        }
        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);
            }
        }