Esempio n. 1
0
        private void ParseSchema(string fileName, string baseUrl, XMLSchema.schema schemaDOM)
        {
            string basePath = Path.GetDirectoryName(fileName);

            if (schemaDOM.Items != null)
            {
                foreach (XMLSchema.openAttrs openAttrs in schemaDOM.Items)
                {
                    string loadedFileName = "";
                    string schemaLocation = "";

                    if (openAttrs is XMLSchema.include)
                    {
                        XMLSchema.include include = openAttrs as XMLSchema.include;
                        if (include.schemaLocation != null)
                        {
                            schemaLocation = include.schemaLocation;
                        }
                    }
                    else if (openAttrs is XMLSchema.import)
                    {
                        XMLSchema.import import = openAttrs as XMLSchema.import;
                        if (import.schemaLocation != null)
                        {
                            schemaLocation = import.schemaLocation;
                        }
                    }

                    if (!string.IsNullOrEmpty(schemaLocation))
                    {
                        schemaLocation = Uri.UnescapeDataString(schemaLocation);

                        loadedFileName = basePath + Path.DirectorySeparatorChar + schemaLocation.Replace('/', Path.DirectorySeparatorChar);

                        string url = schemaLocation.Trim();
                        if (url.IndexOf("http://") == 0 || url.IndexOf("https://") == 0)
                        {
                            string lf, bu;
                            if (LoadSchemaFromUrl(basePath, url, out lf, out bu))
                            {
                                loadedFileName = lf;
                                baseUrl        = bu; // The baseUrl change for this file
                            }
                        }
                        else if (!File.Exists(loadedFileName))
                        {
                            // The relative file does not exist, so try to download it from the web with the baseUrl
                            url = baseUrl + "/" + schemaLocation;

                            string lf, bu;
                            if (LoadSchemaFromUrl(basePath, url, out lf, out bu))
                            {
                                loadedFileName = lf;
                                baseUrl        = bu; // The baseUrl change for this file
                            }
                        }
                    }

                    if (!string.IsNullOrEmpty(loadedFileName))
                    {
                        ImportSchema(loadedFileName, baseUrl);
                    }
                }
            }

            string nameSpace = schemaDOM.targetNamespace;

            if (schemaDOM.Items1 != null)
            {
                foreach (XMLSchema.openAttrs openAttrs in schemaDOM.Items1)
                {
                    if (openAttrs is XMLSchema.element)
                    {
                        XMLSchema.element element   = openAttrs as XMLSchema.element;
                        XSDObject         xsdObject = new XSDObject(fileName, element.name, nameSpace, "element", element);
                        this.hashtableElementsByName[xsdObject.FullName] = xsdObject;

                        if (this.firstElement == null)
                        {
                            this.firstElement = xsdObject;
                        }

                        elements.Add(xsdObject);
                    }
                    else if (openAttrs is XMLSchema.group)
                    {
                        XMLSchema.group group     = openAttrs as XMLSchema.group;
                        XSDObject       xsdObject = new XSDObject(fileName, group.name, nameSpace, "group", group);
                        this.hashtableElementsByName[xsdObject.FullName] = xsdObject;

                        elements.Add(xsdObject);
                    }
                    else if (openAttrs is XMLSchema.simpleType)
                    {
                        XMLSchema.simpleType simpleType = openAttrs as XMLSchema.simpleType;
                        XSDObject            xsdObject  = new XSDObject(fileName, simpleType.name, nameSpace, "simpleType", simpleType);
                        this.hashtableElementsByName[xsdObject.FullName] = xsdObject;

                        elements.Add(xsdObject);
                    }
                    else if (openAttrs is XMLSchema.complexType)
                    {
                        XMLSchema.complexType complexType = openAttrs as XMLSchema.complexType;
                        XSDObject             xsdObject   = new XSDObject(fileName, complexType.name, nameSpace, "complexType", complexType);
                        this.hashtableElementsByName[xsdObject.FullName] = xsdObject;

                        elements.Add(xsdObject);
                    }
                    else if (openAttrs is XMLSchema.attribute)
                    {
                        XMLSchema.attribute attribute    = openAttrs as XMLSchema.attribute;
                        XSDAttribute        xsdAttribute = new XSDAttribute(fileName, attribute.name, nameSpace, "attribute", attribute.@ref != null, attribute.@default, attribute.use.ToString(), attribute);
                        this.hashtableAttributesByName[xsdAttribute.FullName] = xsdAttribute;
                    }
                    else if (openAttrs is XMLSchema.attributeGroup)
                    {
                        XMLSchema.attributeGroup attributeGroup    = openAttrs as XMLSchema.attributeGroup;
                        XSDAttributeGroup        xsdAttributeGroup = new XSDAttributeGroup(fileName, attributeGroup.name, nameSpace, "attributeGroup", attributeGroup is XMLSchema.attributeGroupRef, attributeGroup);
                        this.hashtableAttributesByName[xsdAttributeGroup.FullName] = xsdAttributeGroup;
                    }
                }
            }
        }
Esempio n. 2
0
        private void ExpandComplexType(DiagramItem parentDiagramElement,
                                       XMLSchema.complexType complexTypeElement)
        {
            if (complexTypeElement.Items != null)
            {
                XMLSchema.annotated[]        items           = complexTypeElement.Items;
                XMLSchema.ItemsChoiceType4[] itemsChoiceType = complexTypeElement.ItemsElementName;

                for (int i = 0; i < items.Length; i++)
                {
                    if (items[i] is XMLSchema.group)
                    {
                        XMLSchema.group group = items[i] as XMLSchema.group;
                        DiagramItem     diagramCompositors = AddCompositors(parentDiagramElement,
                                                                            group, (DiagramItemGroupType)Enum.Parse(typeof(DiagramItemGroupType), itemsChoiceType[i].ToString(), true), parentDiagramElement.NameSpace);
                        parentDiagramElement.ShowChildElements = true;
                        if (diagramCompositors != null)
                        {
                            ExpandChildren(diagramCompositors);
                        }
                    }
                    else if (items[i] is XMLSchema.complexContent)
                    {
                        XMLSchema.complexContent complexContent = items[i] as XMLSchema.complexContent;
                        if (complexContent.Item is XMLSchema.extensionType)
                        {
                            XMLSchema.extensionType extensionType = complexContent.Item as XMLSchema.extensionType;

                            XSDObject xsdObject = null;
                            if (_elementsByName.TryGetValue([email protected] + ":type:" + [email protected], out xsdObject) && xsdObject != null)
                            {
                                XMLSchema.annotated annotated = xsdObject.Tag as XMLSchema.annotated;
                                ExpandAnnotated(parentDiagramElement, annotated, [email protected]);
                            }

                            XMLSchema.group group = extensionType.group as XMLSchema.group;
                            if (group != null)
                            {
                                DiagramItem diagramCompositors = AddCompositors(parentDiagramElement, group, DiagramItemGroupType.Group, [email protected]);
                                parentDiagramElement.ShowChildElements = true;
                                if (diagramCompositors != null)
                                {
                                    ExpandChildren(diagramCompositors);
                                }
                            }

                            XMLSchema.group groupSequence = extensionType.sequence as XMLSchema.group;
                            if (groupSequence != null)
                            {
                                DiagramItem diagramCompositors = AddCompositors(parentDiagramElement, groupSequence, DiagramItemGroupType.Sequence, [email protected]);
                                parentDiagramElement.ShowChildElements = true;
                                if (diagramCompositors != null)
                                {
                                    ExpandChildren(diagramCompositors);
                                }
                            }

                            XMLSchema.group groupChoice = extensionType.choice as XMLSchema.group;
                            if (groupChoice != null)
                            {
                                DiagramItem diagramCompositors = AddCompositors(parentDiagramElement, groupChoice, DiagramItemGroupType.Choice, [email protected]);
                                parentDiagramElement.ShowChildElements = true;
                                if (diagramCompositors != null)
                                {
                                    ExpandChildren(diagramCompositors);
                                }
                            }

                            XMLSchema.group groupAll = extensionType.all as XMLSchema.group;
                            if (groupAll != null)
                            {
                                DiagramItem diagramCompositors = AddCompositors(parentDiagramElement, groupAll, DiagramItemGroupType.All, [email protected]);
                                parentDiagramElement.ShowChildElements = true;
                                if (diagramCompositors != null)
                                {
                                    ExpandChildren(diagramCompositors);
                                }
                            }
                        }
                        else if (complexContent.Item is XMLSchema.restrictionType)
                        {
                            XMLSchema.restrictionType restrictionType = complexContent.Item as XMLSchema.restrictionType;
                            XSDObject xsdObject = null;
                            if (_elementsByName.TryGetValue([email protected] + ":type:" + [email protected], out xsdObject) && xsdObject != null)
                            {
                                XMLSchema.annotated annotated = xsdObject.Tag as XMLSchema.annotated;
                                ExpandAnnotated(parentDiagramElement, annotated, [email protected]);
                            }
                            else
                            {
                                //dgis fix github issue 2
                                if (restrictionType.Items != null)
                                {
                                    //for (int j = 0; j < items.Length; j++)
                                    for (int j = 0; j < restrictionType.Items.Length; j++)
                                    {
                                        if (restrictionType.Items[j] is XMLSchema.group)
                                        {
                                            XMLSchema.group group = restrictionType.Items[j] as XMLSchema.group;
                                            DiagramItem     diagramCompositors = AddCompositors(parentDiagramElement, group,
                                                                                                (DiagramItemGroupType)Enum.Parse(typeof(DiagramItemGroupType), restrictionType.ItemsElementName[j].ToString(), true), parentDiagramElement.NameSpace);
                                            parentDiagramElement.ShowChildElements = true;
                                            if (diagramCompositors != null)
                                            {
                                                ExpandChildren(diagramCompositors);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        public DiagramItem AddCompositors(DiagramItem parentDiagramElement,
                                          XMLSchema.group childGroup, DiagramItemGroupType type,
                                          string nameSpace)
        {
            ClearSearch();
            if (childGroup != null)
            {
                DiagramItem childDiagramGroup = new DiagramItem();
                childDiagramGroup.ItemType = DiagramItemType.group;

                XMLSchema.group referenceGroup = null;
                if (childGroup.@ref != null)
                {
                    childDiagramGroup.IsReference = true;
                    childDiagramGroup.Name        = [email protected] != null ? [email protected] : "";
                    childDiagramGroup.NameSpace   = [email protected] != null ? [email protected] : "";
                    XSDObject grpObject = null;
                    if (_elementsByName.TryGetValue(childDiagramGroup.FullName, out grpObject) && grpObject != null)
                    {
                        XMLSchema.group group = grpObject.Tag as XMLSchema.group;
                        if (group != null)
                        {
                            referenceGroup = childGroup;
                            childGroup     = group;
                        }
                    }
                }
                else if (type == DiagramItemGroupType.Group)
                {
                    childDiagramGroup.Name      = childGroup.name != null ? childGroup.name : "";
                    childDiagramGroup.NameSpace = nameSpace;
                }
                else
                {
                    childDiagramGroup.NameSpace = nameSpace;
                }

                childDiagramGroup.Diagram   = this;
                childDiagramGroup.TabSchema = childGroup;
                int occurrence;
                if (int.TryParse(referenceGroup != null ? referenceGroup.minOccurs : childGroup.minOccurs, out occurrence))
                {
                    childDiagramGroup.MinOccurrence = occurrence;
                }
                else
                {
                    childDiagramGroup.MinOccurrence = -1;
                }
                //try { childDiagramGroup.MinOccurrence = int.Parse(childGroup.minOccurs); }
                //catch { childDiagramGroup.MinOccurrence = -1; }
                if (int.TryParse(referenceGroup != null ? referenceGroup.maxOccurs : childGroup.maxOccurs, out occurrence))
                {
                    childDiagramGroup.MaxOccurrence = occurrence;
                }
                else
                {
                    childDiagramGroup.MaxOccurrence = -1;
                }
                //try { childDiagramGroup.MaxOccurrence = int.Parse(childGroup.maxOccurs); }
                //catch { childDiagramGroup.MaxOccurrence = -1; }
                childDiagramGroup.HasChildElements = true;
                childDiagramGroup.GroupType        = type;

                if (parentDiagramElement == null)
                {
                    _rootElements.Add(childDiagramGroup);
                }
                else
                {
                    childDiagramGroup.Parent = parentDiagramElement;
                    parentDiagramElement.ChildElements.Add(childDiagramGroup);
                }

                return(childDiagramGroup);
            }
            return(null);
        }
Esempio n. 4
0
        public bool ExpandChildren(DiagramItem parentDiagramElement)
        {
            bool result = false;

            ClearSearch();
            if (parentDiagramElement.ItemType == DiagramItemType.element || parentDiagramElement.ItemType == DiagramItemType.type)
            {
                result = true;
                DiagramItem diagramElement = parentDiagramElement;
                if (diagramElement.TabSchema is XMLSchema.element)
                {
                    XMLSchema.element element = diagramElement.TabSchema as XMLSchema.element;

                    if (element.Item is XMLSchema.complexType)
                    {
                        XMLSchema.complexType complexTypeElement = element.Item as XMLSchema.complexType;
                        ExpandComplexType(diagramElement, complexTypeElement);
                    }
                    else if (element.type != null)
                    {
                        XSDObject objectAnnotated = null;
                        if (_elementsByName.TryGetValue(element.type.Namespace + ":type:" + element.type.Name, out objectAnnotated) && objectAnnotated != null)
                        {
                            XMLSchema.annotated annotated = objectAnnotated.Tag as XMLSchema.annotated;
                            ExpandAnnotated(diagramElement, annotated, element.type.Namespace);
                        }
                    }
                }
                else if (diagramElement.TabSchema is XMLSchema.any)
                {
                    //XMLSchema.any any = diagramElement.TabSchema as XMLSchema.any;

                    if (RequestAnyElement != null)
                    {
                        XMLSchema.element requestElement;
                        string            requestNameSpace;
                        RequestAnyElement(diagramElement, out requestElement, out requestNameSpace);
                        if (requestElement != null)
                        {
                            AddElement(diagramElement, requestElement, requestNameSpace);
                            diagramElement.ShowChildElements = true;
                        }
                    }
                }
                else if (diagramElement.TabSchema is XMLSchema.complexType)
                {
                    XMLSchema.complexType complexTypeElement = diagramElement.TabSchema as XMLSchema.complexType;
                    ExpandComplexType(diagramElement, complexTypeElement);
                }
            }
            else if (parentDiagramElement.ItemType == DiagramItemType.group)
            {
                result = true;
                DiagramItem     diagramCompositors = parentDiagramElement;
                XMLSchema.group group = diagramCompositors.TabSchema as XMLSchema.group;

                if (group.Items != null)
                {
                    for (int i = 0; i < group.Items.Length; i++)
                    {
                        switch (group.ItemsElementName[i])
                        {
                        case XMLSchema.ItemsChoiceType2.element:
                            if (group.Items[i] is XMLSchema.element)
                            {
                                AddElement(diagramCompositors, group.Items[i] as XMLSchema.element, diagramCompositors.NameSpace);
                            }
                            break;

                        case XMLSchema.ItemsChoiceType2.any:
                            if (group.Items[i] is XMLSchema.any)
                            {
                                AddAny(diagramCompositors, group.Items[i] as XMLSchema.any, diagramCompositors.NameSpace);
                            }
                            break;

                        case XMLSchema.ItemsChoiceType2.group:
                            if (group.Items[i] is XMLSchema.group)
                            {
                                AddCompositors(diagramCompositors, group.Items[i] as XMLSchema.group, DiagramItemGroupType.Group, diagramCompositors.NameSpace);
                            }
                            break;

                        case XMLSchema.ItemsChoiceType2.all:
                            if (group.Items[i] is XMLSchema.group)
                            {
                                AddCompositors(diagramCompositors, group.Items[i] as XMLSchema.group, DiagramItemGroupType.All, diagramCompositors.NameSpace);
                            }
                            break;

                        case XMLSchema.ItemsChoiceType2.choice:
                            if (group.Items[i] is XMLSchema.group)
                            {
                                AddCompositors(diagramCompositors, group.Items[i] as XMLSchema.group, DiagramItemGroupType.Choice, diagramCompositors.NameSpace);
                            }
                            break;

                        case XMLSchema.ItemsChoiceType2.sequence:
                            if (group.Items[i] is XMLSchema.group)
                            {
                                AddCompositors(diagramCompositors, group.Items[i] as XMLSchema.group, DiagramItemGroupType.Sequence, diagramCompositors.NameSpace);
                            }
                            break;
                        }
                    }
                    parentDiagramElement.ShowChildElements = true;
                }
                else
                {
                    AddAny(diagramCompositors, null, diagramCompositors.NameSpace);
                }
            }
            return(result);
        }
Esempio n. 5
0
 public DiagramItem AddCompositors(DiagramItem parentDiagramElement,
                                   XMLSchema.group childElement, string nameSpace)
 {
     return(AddCompositors(parentDiagramElement,
                           childElement, DiagramItemGroupType.Group, nameSpace));
 }