コード例 #1
0
ファイル: BpmnXMLUtil.cs プロジェクト: zhangzihan/nactivity
        public static void ParseChildElements(string elementName, BaseElement parentElement, XMLStreamReader xtr, IDictionary <string, BaseChildElementParser> childParsers, BpmnModel model)
        {
            IDictionary <string, BaseChildElementParser> localParserMap = new Dictionary <string, BaseChildElementParser>(genericChildParserMap);

            if (childParsers != null)
            {
                localParserMap.PutAll(childParsers);
            }

            bool inExtensionElements    = false;
            bool readyWithChildElements = false;

            while (!readyWithChildElements && xtr.HasNext())
            {
                //xtr.next();

                if (xtr.IsStartElement())
                {
                    if (BpmnXMLConstants.ELEMENT_EXTENSIONS.Equals(xtr.LocalName))
                    {
                        inExtensionElements = true;
                    }
                    else if (localParserMap.ContainsKey(xtr.LocalName))
                    {
                        BaseChildElementParser childParser = localParserMap[xtr.LocalName];
                        //if we're into an extension element but the current element is not accepted by this parentElement then is read as a custom extension element
                        if (inExtensionElements && !childParser.Accepts(parentElement))
                        {
                            ExtensionElement extensionElement = BpmnXMLUtil.ParseExtensionElement(xtr);
                            parentElement.AddExtensionElement(extensionElement);
                            continue;
                        }
                        localParserMap[xtr.LocalName].ParseChildElement(xtr, parentElement, model);
                    }
                    else if (inExtensionElements)
                    {
                        ExtensionElement extensionElement = BpmnXMLUtil.ParseExtensionElement(xtr);
                        parentElement.AddExtensionElement(extensionElement);
                    }
                }
                else if (xtr.EndElement)
                {
                    if (BpmnXMLConstants.ELEMENT_EXTENSIONS.Equals(xtr.LocalName))
                    {
                        inExtensionElements = false;
                    }
                    else if (elementName.Equals(xtr.LocalName, StringComparison.CurrentCultureIgnoreCase))
                    {
                        readyWithChildElements = true;
                    }
                }

                if (xtr.IsEmptyElement && elementName.Equals(xtr.LocalName, StringComparison.OrdinalIgnoreCase))
                {
                    readyWithChildElements = true;
                }
            }
        }