private void GetChildrenInfo(XMLSchema.complexType complexTypeElement, out bool hasChildren, out bool isSimpleType) { bool hasSimpleContent = false; if (complexTypeElement.Items != null) { for (int i = 0; i < complexTypeElement.Items.Length; i++) { if (complexTypeElement.Items[i] is XMLSchema.group || complexTypeElement.Items[i] is XMLSchema.complexType || complexTypeElement.Items[i] is XMLSchema.complexContent) { hasChildren = true; isSimpleType = complexTypeElement.mixed; if (complexTypeElement.Items[i] is XMLSchema.complexContent) { //hasChildren = false; XMLSchema.complexContent complexContent = complexTypeElement.Items[i] as XMLSchema.complexContent; if (complexContent.Item is XMLSchema.extensionType) { hasChildren = false; XMLSchema.extensionType extensionType = complexContent.Item as XMLSchema.extensionType; if (extensionType.all != null || extensionType.group != null || extensionType.choice != null || extensionType.sequence != null) { hasChildren = true; } else if (extensionType.@base != null) { XSDObject xsdObject = null; if (_elementsByName.TryGetValue([email protected] + ":type:" + [email protected], out xsdObject) && xsdObject != null) { XMLSchema.complexType baseComplexType = xsdObject.Tag as XMLSchema.complexType; if (baseComplexType != null) { GetChildrenInfo(baseComplexType, out hasChildren, out isSimpleType); } } } } //else if (complexContent.Item is XMLSchema.complexRestrictionType) //{ // XMLSchema.complexRestrictionType complexRestrictionType = complexContent.Item as XMLSchema.complexRestrictionType; //} } return; } else if (complexTypeElement.Items[i] is XMLSchema.simpleContent) { hasSimpleContent = true; } } } hasChildren = false; isSimpleType = (hasSimpleContent ? true : complexTypeElement.mixed); }
private void GetChildrenInfo(XMLSchema.element childElement, out bool hasChildren, out bool isSimpleType) { if (childElement.Item is XMLSchema.complexType) { XMLSchema.complexType complexTypeElement = childElement.Item as XMLSchema.complexType; GetChildrenInfo(complexTypeElement, out hasChildren, out isSimpleType); return; //if (complexTypeElement.Items != null) //{ // for (int i = 0; i < complexTypeElement.Items.Length; i++) // { // if (complexTypeElement.Items[i] is XMLSchema.group || // complexTypeElement.Items[i] is XMLSchema.complexType || // complexTypeElement.Items[i] is XMLSchema.complexContent) // { // return true; // } // } //} } else if (childElement.type != null) { XSDObject xsdObject = null; if (_elementsByName.TryGetValue(childElement.type.Namespace + ":type:" + childElement.type.Name, out xsdObject) && xsdObject != null) //if (_elementsByName.ContainsKey(childElement.type.Namespace + ":type:" + childElement.type.Name)) { XMLSchema.annotated annotated = xsdObject.Tag as XMLSchema.annotated; if (annotated is XMLSchema.simpleType) { hasChildren = false; isSimpleType = true; } else { GetChildrenInfo(annotated as XMLSchema.complexType, out hasChildren, out isSimpleType); } return; } } hasChildren = false; isSimpleType = true; }
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); } } } } } } } } } }
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); }
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); }
public DiagramItem AddElement(DiagramItem parentDiagramElement, XMLSchema.element childElement, string nameSpace) { ClearSearch(); if (childElement != null) { DiagramItem childDiagramElement = new DiagramItem(); XMLSchema.element referenceElement = null; if (childElement.@ref != null) { if ([email protected]) { childDiagramElement.IsReference = true; XSDObject objectReferred = null; if (_elementsByName.TryGetValue([email protected] + ":element:" + [email protected], out objectReferred) && objectReferred != null) { XMLSchema.element elementReferred = objectReferred.Tag as XMLSchema.element; if (elementReferred != null) { referenceElement = childElement; childElement = elementReferred; } } else { childElement.name = [email protected]; } } } childDiagramElement.Diagram = this; childDiagramElement.TabSchema = childElement; childDiagramElement.Name = childElement.name != null ? childElement.name : ""; childDiagramElement.NameSpace = nameSpace; string type = childDiagramElement.GetTypeAnnotation(); if (!String.IsNullOrEmpty(type)) { childDiagramElement.Type = type; } childDiagramElement.ItemType = DiagramItemType.element; int occurrence; if (int.TryParse(referenceElement != null ? referenceElement.minOccurs : childElement.minOccurs, out occurrence)) { childDiagramElement.MinOccurrence = occurrence; } else { childDiagramElement.MinOccurrence = -1; } //try { childDiagramElement.MinOccurrence = int.Parse(referenceElement != null ? referenceElement.minOccurs : childElement.minOccurs); } //catch { childDiagramElement.MinOccurrence = -1; } if (int.TryParse(referenceElement != null ? referenceElement.maxOccurs : childElement.maxOccurs, out occurrence)) { childDiagramElement.MaxOccurrence = occurrence; } else { childDiagramElement.MaxOccurrence = -1; } //try { childDiagramElement.MaxOccurrence = int.Parse(referenceElement != null ? referenceElement.maxOccurs : childElement.maxOccurs); } //catch { childDiagramElement.MaxOccurrence = -1; } bool hasChildren; bool isSimpleType; GetChildrenInfo(childElement, out hasChildren, out isSimpleType); childDiagramElement.HasChildElements = hasChildren; childDiagramElement.IsSimpleContent = isSimpleType; if (parentDiagramElement == null) { _rootElements.Add(childDiagramElement); } else { childDiagramElement.Parent = parentDiagramElement; parentDiagramElement.ChildElements.Add(childDiagramElement); } if (childElement.@abstract) { string abstractElementFullName = childDiagramElement.FullName; foreach (XSDObject xsdObject in _elementsByName.Values) { if (xsdObject != null && xsdObject.Tag is XMLSchema.element) { XMLSchema.element element = xsdObject.Tag as XMLSchema.element; if (element.substitutionGroup != null) { string elementFullName = element.substitutionGroup.Namespace + ":element:" + element.substitutionGroup.Name; if (elementFullName == abstractElementFullName) { DiagramItem diagramBase = AddElement(parentDiagramElement, element, xsdObject.NameSpace); if (diagramBase != null) { diagramBase.InheritFrom = childDiagramElement; } } } } } } return(childDiagramElement); } return(null); }