void PostProcessSR(P_PSMDiagram d) { List <P_PSMClass> RootClasses = d.Children.OfType <P_PSMClass>().ToList <P_PSMClass>(); foreach (P_PSMClass rootClass in RootClasses) { if (DeleteUnnecessarySRsMadeByExtensions && rootClass.CreatedAsExtensionSR && rootClass.SRepresentedBy.Count == 0) { //Remove useless SRs created because a global ComplexType is an extension of some other type d.Children.Remove(rootClass); d.GlobalIDs[rootClass.SRofType].SRepresentedBy.Remove(rootClass); } if (ResolveSRs && rootClass.SRepresentedBy.Count == 1) { //Move a root class that is represented only at one place to that place instead of SR P_PSMClass Rep = rootClass.SRepresentedBy[0]; //Cycle avoidance if (Rep.Ancestors.Contains(rootClass)) { continue; } //Element label loss avoidance else if (Rep.ElementLabel != null && rootClass.ElementLabel != null) { continue; } else if (d.GlobalIDs.ContainsValue(Rep)) { //Shouldn't happen, but... Debug.Assert(false, "d.GlobalIDs.ContainsValue(Rep)"); continue; } else if (d.GlobalElementTypes.ContainsValue(Rep.Name)) { //Shouldn't happen, but... Debug.Assert(false, "d.GlobalElementTypes.ContainsValue(Rep.Name)"); continue; } else if (Rep.SRepresentedBy.Count > 0) { //Shouldn't happen, but... Debug.Assert(false, "Rep.SRepresentedBy.Count > 0"); continue; } if (Rep.ElementLabel != null && rootClass.ElementLabel == null) { rootClass.ElementLabel = Rep.ElementLabel; } rootClass.SRepresentedBy.Clear(); d.Children.Remove(rootClass); rootClass.Parent = Rep.Parent; rootClass.Documentation = Rep.Documentation; //for CContainers and Comments int index = Rep.Parent.Children.IndexOf(Rep); Rep.Parent.Children.Remove(Rep); Rep.Parent.Children.Insert(index, rootClass); } } }
void ProcessAttributeGroup(XmlSchemaAttributeGroup group, P_PSMDiagram diagram, int level) { P_PSMClass C = new P_PSMClass(); C.Name = new XmlQualifiedName(group.Name, diagram.TargetNamespace); ProcessAttributes(group.Attributes, level, C); diagram.GlobalIDs.Add(C.Name, C); C.Parent = diagram; diagram.Children.Add(C); }
void TraverseGroupInsides(XmlSchemaElement elem, int level, I_PSMHasChildren Parent, P_PSMDiagram diagram) { if (elem.SchemaTypeName.IsEmpty) { if (elem.SchemaType is XmlSchemaComplexType) { ProcessComplexType(elem.SchemaType as XmlSchemaComplexType, level, Parent, diagram, elem); } else if (elem.SchemaType is XmlSchemaSimpleType) { P_PSMAttributeContainer c = new P_PSMAttributeContainer(); Parent.Children.Add(c); c.Parent = Parent; P_PSMAttribute a = new P_PSMAttribute() { Alias = elem.Name, type = elem.SchemaType.BaseXmlSchemaType.QualifiedName }; a.Lower = (uint)elem.MinOccurs; a.Upper = DecToUN(elem.MaxOccurs); c.Attributes.Add(a); } else if (!elem.RefName.IsEmpty) { P_PSMClass current = new P_PSMClass(); Parent.Children.Add(current); current.Parent = Parent; /* Structural representative, end of recursion */ current.SRofElemRef = elem.RefName; current.Name = new XmlQualifiedName(GetUniqueName(elem.RefName.Name, elem.QualifiedName.Namespace, "_g", diagram), elem.QualifiedName.Namespace); diagram.UsedNames.Add(current.Name); } else { Print("WARNING: Unknown SchemaType Type" + Environment.NewLine, level); } } else { //Copied from ProcessComplexType Print("XmlSchemaElementRef: \"" + elem.Name + "\" Complex type: \"" + elem.SchemaTypeName.Name + "\" refname: \"" + elem.RefName.Namespace + ": " + elem.RefName.Name + "\" qname: \"" + elem.QualifiedName + "\"" + Environment.NewLine, level); P_PSMClass current = new P_PSMClass(); Parent.Children.Add(current); current.Parent = Parent; /* Structural representative, end of recursion */ current.SRofType = elem.SchemaTypeName; current.Name = new XmlQualifiedName(GetUniqueName(elem.SchemaTypeName.Name, elem.SchemaTypeName.Namespace, "_g", diagram), elem.SchemaTypeName.Namespace); diagram.UsedNames.Add(current.Name); } }
void PrintDiagram(object parent, int level) { if (parent is P_PSMDiagram) { Print("PSM Diagram" + Environment.NewLine, level); foreach (I_PSMHasParent child in (parent as I_PSMHasChildren).Children) { PrintDiagram(child, level + 1); } } else if (parent is P_PSMClass) { P_PSMClass c = parent as P_PSMClass; Print("PSM Class: \"" + c.Name + "\" EL: \"" + c.ElementLabel + "\"" + Environment.NewLine, level); if (c.SRofType != null) { Print("SR of Type: \"" + c.SRofType + "\"" + Environment.NewLine, level); } if (c.SRofElemRef != null) { Print("SR of ElemRef: \"" + c.SRofElemRef + "\"" + Environment.NewLine, level); } foreach (P_PSMAttribute A in (parent as I_PSMHasAttributes).Attributes) { Print("Attribute: \"" + A.Alias + "\" type: \"" + A.type + "\"" + Environment.NewLine, level + 1); } foreach (I_PSMHasParent child in (parent as I_PSMHasChildren).Children) { PrintDiagram(child, level + 1); } } else if (parent is P_PSMAttributeContainer) { Print("Attribute container" + Environment.NewLine, level); foreach (P_PSMAttribute A in (parent as I_PSMHasAttributes).Attributes) { Print("Attribute: \"" + A.Alias + "\" type: \"" + A.type + "\"" + Environment.NewLine, level + 1); } } else if (parent is P_PSMContentChoice) { Print("Content choice" + Environment.NewLine, level); foreach (I_PSMHasParent child in (parent as I_PSMHasChildren).Children) { PrintDiagram(child, level + 1); } } else { } }
void ProcessGroup(XmlSchemaGroup G, P_PSMDiagram diagram) { Print("Group: " + G.Name + Environment.NewLine, 0); P_PSMClass C = new P_PSMClass() { Name = G.QualifiedName }; diagram.GlobalIDs.Add(C.Name, C); diagram.UsedNames.Add(C.Name); diagram.Children.Add(C); C.Parent = diagram; TraverseParticle(G.Particle, 1, C, diagram); }
void ProcessAttributes(XmlSchemaObjectCollection Atts, int level, P_PSMClass current) { if (Atts.Count > 0) { Print("Attributes: " + Atts.Count + Environment.NewLine, level); foreach (XmlSchemaObject O in Atts) { if (O is XmlSchemaAttribute) { XmlSchemaAttribute A = O as XmlSchemaAttribute; Print("Att name: \"" + A.Name + "\" type: \"" + A.SchemaTypeName.Namespace + ": " + A.SchemaTypeName.Name + "\" use: \"" + A.Use + "\"" + Environment.NewLine, level + 1); if (current != null) { P_PSMAttribute a = new P_PSMAttribute() { Alias = A.Name, type = A.SchemaTypeName, DefaultValue = A.DefaultValue, FixedValue = A.FixedValue, Form = A.Form }; SetAttributeUse(a, A); current.Attributes.Add(a); } } else if (O is XmlSchemaAttributeGroupRef) { XmlSchemaAttributeGroupRef G = O as XmlSchemaAttributeGroupRef; Print("AttGroupRef: \"" + G.RefName.Name + "\"" + Environment.NewLine, level); /* CANNOT HAVE MULTIPLE REPRESENTED CLASSES - MUST COPY ATTRIBUTES * //create SR * if (current.SRof != null) Print("Warning: Overwriting SRof \"" + * current.SRof + " with \"" + G.RefName.Name + "\"." + Environment.NewLine, level); * current.SRof = G.RefName.Name;*/ current.AttrGroupRefs.Add(G.RefName); } else { Print("Unknown object in type.Attributes collection" + Environment.NewLine, level); } } } }
void LinkSRs(I_PSMHasChildren D) { if (D is P_PSMClass) { P_PSMClass C = D as P_PSMClass; foreach (P_PSMClass SR in C.SRepresentedBy) { SetRepresentedPSMClassCommand c = SetRepresentedPSMClassCommandFactory.Factory().Create(DiagramController) as SetRepresentedPSMClassCommand; c.Set(C.Super as PSMClass, SR.Super as PSMClass); c.Execute(); } } foreach (I_PSMHasParent child in D.Children) { if (child is I_PSMHasChildren) { LinkSRs(child as I_PSMHasChildren); } } }
void ProcessComplexType(XmlSchemaComplexType type, int level, I_PSMHasChildren Parent, P_PSMDiagram diagram, XmlSchemaElement elem) { if (elem != null && !elem.SchemaTypeName.IsEmpty) //The type of the element has a name => a global complex type, end of recursion <element type="bar"/> { Print("XmlSchemaElement (of a global type): \"" + elem.Name + "\" Complex type: \"" + elem.ElementSchemaType.Name + "\" refname: \"" + elem.RefName.Namespace + ": " + elem.RefName.Name + "\" qname: \"" + elem.QualifiedName + "\"" + Environment.NewLine, level); if (diagram.GlobalIDs.ContainsKey(elem.ElementSchemaType.QualifiedName) && diagram.GlobalIDs[elem.ElementSchemaType.QualifiedName].Parent == diagram && diagram.GlobalIDs[elem.ElementSchemaType.QualifiedName].ElementLabel == null) { // REDUCES NUMBER OF ELEMENT-COMPLEXTYPE pairs // Root P_PSMClass representing the complexType of the element and not having an element label gets it // and is moved to the place where the the element should be. Works primarily for global elements // as they are processed after all global complex types P_PSMClass candidate = diagram.GlobalIDs[elem.ElementSchemaType.QualifiedName]; diagram.Children.Remove(candidate); Parent.Children.Add(candidate); candidate.Parent = Parent; candidate.ElementLabel = elem.Name; candidate.MinOccurs = (uint)elem.MinOccurs; candidate.MaxOccurs = DecToUN(elem.MaxOccurs); if (elem.Parent is XmlSchema) { //If this was global element, we need to create the mapping for the case //it is referenced by <element ref="foo"/> somewhere in the schema diagram.GlobalElementTypes.Add(elem.QualifiedName, candidate.Name); } } else { // No merging, create a new root P_PSMClass, SR of the P_PSMClass representing // the type from <element type="bar"/> P_PSMClass current = new P_PSMClass() { ElementLabel = elem.Name, AppInfo = GetAppInfo(elem.Annotation), Documentation = GetDoc(elem.Annotation), MinOccurs = (uint)elem.MinOccurs, MaxOccurs = DecToUN(elem.MaxOccurs), Name = new XmlQualifiedName(GetUniqueName(elem.QualifiedName.Name, elem.QualifiedName.Namespace, "_t", diagram), elem.QualifiedName.Namespace) }; if (elem.ElementSchemaType != null) { current.Documentation.AddRange(GetDoc(elem.ElementSchemaType.Annotation)); } else if (elem.SchemaType != null) { current.Documentation.AddRange(GetDoc(elem.SchemaType.Annotation)); } if (elem.Parent is XmlSchema) { //Global element, can be referenced by <element ref="foo"/> //We create a mapping in diagram.GlobalElementTypes //and the type will be accessible through GlobalIDs diagram.GlobalElementTypes.Add(elem.QualifiedName, current.Name); diagram.GlobalIDs.Add(current.Name, current); } Parent.Children.Add(current); current.Parent = Parent; current.SRofType = elem.SchemaTypeName; diagram.UsedNames.Add(current.Name); } } else if (elem != null && !elem.RefName.IsEmpty) //Non-global element like this: <element ref="foo"/> //It cannot be global because ref is not allowed for global elements in XML Schema { Print("XmlSchemaElementRef: \"" + elem.Name + "\" Complex type: \"" + elem.ElementSchemaType.Name + "\" refname: \"" + elem.RefName.Namespace + ": " + elem.RefName.Name + "\" qname: \"" + elem.QualifiedName + "\"" + Environment.NewLine, level); P_PSMClass current = new P_PSMClass(); Parent.Children.Add(current); current.Parent = Parent; /* Structural representative, end of recursion */ current.SRofElemRef = elem.RefName; current.AppInfo = GetAppInfo(elem.Annotation); current.Documentation = GetDoc(elem.Annotation); if (elem.ElementSchemaType != null) { current.Documentation.AddRange(GetDoc(elem.ElementSchemaType.Annotation)); } else if (elem.SchemaType != null) { current.Documentation.AddRange(GetDoc(elem.SchemaType.Annotation)); } current.Name = new XmlQualifiedName( GetUniqueName(elem.RefName.Name, elem.QualifiedName.Namespace, "_r", diagram), elem.QualifiedName.Namespace); current.MinOccurs = (uint)elem.MinOccurs; current.MaxOccurs = DecToUN(elem.MaxOccurs); //current.Name = new XmlQualifiedName("REF" + GetNextInt().ToString() + "_" + elem.RefName.Name, elem.QualifiedName.Namespace); //diagram.GlobalIDs.Add(current.Name, current); diagram.UsedNames.Add(current.Name); } else //The type is global or the type of the element does not have a name (it is embedded) //Either global <complexType> or <element ... ><complexType>... { P_PSMClass current = new P_PSMClass(); Parent.Children.Add(current); current.Parent = Parent; ProcessAttributes(type.Attributes, level + 1, current); if (elem != null) //Complex type inside an element, type.name == null - <element ... ><complexType>... { if (elem.ElementSchemaType != null) { Print("XmlSchemaElement: \"" + elem.Name + "\" Complex type: \"" + elem.ElementSchemaType.Name + "\" refname: \"" + elem.RefName.Namespace + ": " + elem.RefName.Name + "\" qname: \"" + elem.QualifiedName + "\"" + Environment.NewLine, level); } else { Print("XmlSchemaElement: \"" + elem.Name + "\" Complex type: \"" + elem.SchemaType.Name + "\" refname: \"" + elem.RefName.Namespace + ": " + elem.RefName.Name + "\" qname: \"" + elem.QualifiedName + "\"" + Environment.NewLine, level); } current.Name = new XmlQualifiedName( GetUniqueName(elem.QualifiedName.Name, elem.QualifiedName.Namespace, "_t", diagram), elem.QualifiedName.Namespace); current.AppInfo = GetAppInfo(elem.Annotation); current.Documentation = GetDoc(elem.Annotation); if (elem.ElementSchemaType != null) { current.Documentation.AddRange(GetDoc(elem.ElementSchemaType.Annotation)); } else if (elem.SchemaType != null) { current.Documentation.AddRange(GetDoc(elem.SchemaType.Annotation)); } current.MinOccurs = (uint)elem.MinOccurs; current.MaxOccurs = DecToUN(elem.MaxOccurs); if (elem.Parent is XmlSchema) //Global element, unnamed type (embedded) => Create mapping { diagram.GlobalElementTypes.Add(elem.QualifiedName, current.Name); //Added to fix global <element name="blabal"/> not being able to be target of SR diagram.GlobalIDs.Add(current.Name, current); } diagram.UsedNames.Add(current.Name); current.ElementLabel = elem.Name; } else //Global Complex Type { Print("Complex type: \"" + type.Name + "\"" + Environment.NewLine, 0); //Here we don't generate a unique name //we use the one "reserved" in the beginning of the process //therefore it is already in UsedNames //We only create the mapping for post-processing current.Name = type.QualifiedName; diagram.GlobalIDs.Add(current.Name, current); //diagram.UsedNames.Add(current.Name); } if (type.ContentType == XmlSchemaContentType.Empty) { /* Empty element, end of recursion */ } else if (elem == null || elem.RefName.IsEmpty) { //It's type is not "ref" and it has some content if (type.ContentModel == null) { TraverseParticle(type.Particle, level + 1, current, diagram); } else if (type.ContentModel is XmlSchemaComplexContent) { if (type.ContentModel.Content is XmlSchemaComplexContentExtension) { current.ExtensionOf = (type.ContentModel.Content as XmlSchemaComplexContentExtension).BaseTypeName; TraverseParticle(type.ContentTypeParticle, level + 1, current, diagram); } else if (type.ContentModel.Content is XmlSchemaComplexContentRestriction) { current.RestrictionOf = (type.ContentModel.Content as XmlSchemaComplexContentRestriction).BaseTypeName; TraverseParticle(type.ContentTypeParticle, level + 1, current, diagram); } else { TraverseParticle(type.Particle, level + 1, current, diagram); } } else /* Simple content */ { // Merge attributes within simple content if (type.ContentModel.Content is XmlSchemaSimpleContentExtension) { XmlSchemaSimpleContentExtension E = type.ContentModel.Content as XmlSchemaSimpleContentExtension; ProcessAttributes(E.Attributes, level + 1, current); //TODO: groupref inside extension? Restriction? } Print("Simple Content" + Environment.NewLine, level); } } } }
void PostProcessCCandComment(object current, int level, P_PSMDiagram diagram) { if (current is I_PSMHasChildren) { #region Content Container if (current is P_PSMClass && !((current as P_PSMClass).Parent is P_PSMDiagram) && (current as P_PSMClass).Documentation.Count > 0 && (current as P_PSMClass).Documentation[0].Equals("PSM: ContentContainer")) { P_PSMClass cPSMClass = current as P_PSMClass; if (cPSMClass.SRepresentedBy.Count == 0) { P_PSMContentContainer CC = new P_PSMContentContainer(); CC.ElementLabel = cPSMClass.ElementLabel.Equals("") ? cPSMClass.Name.Name : cPSMClass.ElementLabel; CC.Parent = cPSMClass.Parent; int index = CC.Parent.Children.IndexOf(cPSMClass); CC.Parent.Children.Remove(cPSMClass); CC.Parent.Children.Insert(index, CC); foreach (I_PSMHasParent child in cPSMClass.Children) { CC.Children.Add(child); child.Parent = CC; } if (cPSMClass.Attributes.Count > 0) { P_PSMAttributeContainer AC = new P_PSMAttributeContainer(); AC.Parent = CC; CC.Children.Insert(0, AC); foreach (P_PSMAttribute A in cPSMClass.Attributes) { AC.Attributes.Add(A); } } current = CC; } } if (current is P_PSMClass) { ClassesCount++; } #endregion #region Comment if (current is P_PSMClass && (current as P_PSMClass).Documentation.Count > 0) { P_PSMClass cPSMClass = current as P_PSMClass; foreach (string S in cPSMClass.Documentation) { P_PSMComment C = new P_PSMComment(); C.Parent = cPSMClass; C.text = S; cPSMClass.Children.Add(C); } } #endregion List <I_PSMHasParent> Children2 = (current as I_PSMHasChildren).Children.ToList <I_PSMHasParent>(); foreach (I_PSMHasParent child in Children2) { PostProcessCCandComment(child, level + 1, diagram); } } }
void PostProcess(object current, int level, P_PSMDiagram diagram) { //TODO: resolve references? (SR + type + attrgroups) if (current is I_PSMHasChildren) { #region Merge AttributeContainers P_PSMAttributeContainer first = null; List <P_PSMAttributeContainer> temp = new List <P_PSMAttributeContainer>(); foreach (I_PSMHasParent AC in (current as I_PSMHasChildren).Children) { if (AC is P_PSMAttributeContainer) { temp.Add(AC as P_PSMAttributeContainer); } } foreach (P_PSMAttributeContainer AC in temp) { if (AC != null) { if (first == null) { first = AC; } else { AC.Parent.Children.Remove(AC); foreach (P_PSMAttribute A in AC.Attributes) { first.Attributes.Add(A); } } } } temp = null; #endregion #region Resolve AttributeGroups //RESOLVE ATTRGROUPS BY COPYING - CAN IT BE DONE IN ANOTHER WAY? if (current is I_PSMHasAttributes) { foreach (XmlQualifiedName N in (current as I_PSMHasAttributes).AttrGroupRefs) { if (diagram.GlobalIDs.ContainsKey(N)) { foreach (P_PSMAttribute A in GetAttributes(diagram.GlobalIDs[N], diagram, level)) { P_PSMAttribute a = new P_PSMAttribute() { Alias = GetUniqueAlias(A.Alias, (current as I_PSMHasAttributes).Attributes), //Alias = "AGREF_" + GetNextInt().ToString() + A.Alias, DefaultValue = A.DefaultValue, FixedValue = A.FixedValue, Form = A.Form, type = A.type, Lower = A.Lower, Upper = A.Upper }; (current as I_PSMHasAttributes).Attributes.Add(a); } } else { Print("ERROR: Unresolved AttributeGroupRef \"" + N + "\"" + Environment.NewLine, level); } } (current as I_PSMHasAttributes).AttrGroupRefs.Clear(); } #endregion #region Resolve Groups foreach (XmlQualifiedName N in (current as I_PSMHasChildren).GroupRefs) { if (diagram.GlobalIDs.ContainsKey(N)) { P_PSMClass C = new P_PSMClass() { Name = new XmlQualifiedName(GetUniqueName(N.Name, N.Namespace, "_gr", diagram)), //Name = new XmlQualifiedName("GREF_" + GetNextInt().ToString() + N.Name, N.Namespace), Parent = current as I_PSMHasChildren, SRofType = N }; (current as I_PSMHasChildren).Children.Add(C); diagram.UsedNames.Add(C.Name); } else { Print("ERROR: Unresolved GroupRef \"" + N + "\"" + Environment.NewLine, level); } } #endregion if (current is P_PSMClass) { P_PSMClass Class = current as P_PSMClass; #region Resolve Extensions //Move the P_PSMClasses "under" the classes they extend and create a SR instead of them if (Class.ExtensionOf != null && !(Class.Parent is P_PSMClass && Class.ExtensionOf == (Class.Parent as P_PSMClass).Name)) // Is extension of something and is not moved there yet { if (diagram.GlobalIDs.ContainsKey(Class.ExtensionOf)) { P_PSMClass ExtendedClass = diagram.GlobalIDs[Class.ExtensionOf]; I_PSMHasChildren Parent = Class.Parent; string EL = Class.ElementLabel; Parent.Children.Remove(Class); ExtendedClass.Children.Add(Class); Class.Parent = ExtendedClass; if (!diagram.GlobalIDs.ContainsKey(Class.Name)) { diagram.GlobalIDs.Add(Class.Name, Class); } Class.ElementLabel = null; P_PSMClass NewSR = new P_PSMClass() { SRofType = Class.Name, Parent = Parent, ElementLabel = EL, CreatedAsExtensionSR = true, Name = new XmlQualifiedName(GetUniqueName(Class.Name.Name, Class.Name.Namespace, "_e", diagram), Class.Name.Namespace) }; Parent.Children.Add(NewSR); PostProcess(NewSR, level, diagram); } else { Print("POSTPROCESSING WARNING: Could not resolve ExtensionOf: \"" + Class.ExtensionOf + "\"" + Environment.NewLine, 0); } } #endregion #region Register Structural Representatives with the represented classes if (Class.SRofType != null) { if (diagram.GlobalIDs.ContainsKey(Class.SRofType)) { diagram.GlobalIDs[Class.SRofType].SRepresentedBy.Add(Class); } else { Print("POSTPROCESSING WARNING: Could not resolve SRofType: \"" + Class.SRofType + "\"" + Environment.NewLine, 0); } } else if (Class.SRofElemRef != null) { if (diagram.GlobalElementTypes.ContainsKey(Class.SRofElemRef)) { XmlQualifiedName N = diagram.GlobalElementTypes[Class.SRofElemRef]; if (diagram.GlobalIDs.ContainsKey(N)) { diagram.GlobalIDs[N].SRepresentedBy.Add(Class); } else { Print("POSTPROCESSING WARNING: Could not resolve SRofType (from SRofElemRef): \"" + N + "\"" + Environment.NewLine, 0); } } else { Print("POSTPROCESSING WARNING: Could not resolve SRofElemRef: \"" + Class.SRofElemRef + "\"" + Environment.NewLine, 0); } } } #endregion #region Remove Dummies if (current is P_PSMDummy) //Sequence - introduced because of merging ACs in ContentChoices removed the "choice sematics" { P_PSMDummy D = current as P_PSMDummy; D.Parent.Children.Remove(D); //Because the "Children" collection can be changed in the process, we need to create a copy List <I_PSMHasParent> Children = D.Children.ToList <I_PSMHasParent>(); foreach (I_PSMHasParent child in Children) { D.Children.Remove(child); D.Parent.Children.Add(child); child.Parent = D.Parent; PostProcess(child, level + 1, diagram); } } #endregion //Recursion //Because the "Children" collection can be changed in the process, we need to create a copy List <I_PSMHasParent> Children2 = (current as I_PSMHasChildren).Children.ToList <I_PSMHasParent>(); foreach (I_PSMHasParent child in Children2) { PostProcess(child, level + 1, diagram); } } }
void GeneratePSM(I_PSMHasChildren current) { foreach (I_PSMHasParent child in current.Children) { //TODO: Macrocommand if (child is P_PSMClass) { //UPDATE GUI: This is wrong, but better than crash due to detected deadlock: X.l.Content = (++currentClassCount).ToString() + "/" + X.ClassesCount.ToString() + " PSM Classes"; X.p.Value = currentClassCount; if (currentClassCount % (Math.Min(25, X.ClassesCount / 10) + 1) == 0) { Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new ThreadStart(delegate { })); } P_PSMClass C = child as P_PSMClass; ElementHolder <PSMClass> hldPSMClass = new ElementHolder <PSMClass>(); NewPSMClassCommand c0 = NewPSMClassCommandFactory.Factory().Create(DiagramController.ModelController) as NewPSMClassCommand; c0.RepresentedClass = tempPIMClass; c0.CreatedClass = hldPSMClass; c0.Execute(); C.Super = hldPSMClass.Element; //TODO commandy hldPSMClass.Element.Name = C.Name.Name; hldPSMClass.Element.ElementName = C.ElementLabel; PSMClassToDiagram_ModelCommand c1_1 = PSMClassToDiagram_ModelCommandFactory.Factory().Create(DiagramController.ModelController) as PSMClassToDiagram_ModelCommand; c1_1.Set(hldPSMClass, new HolderBase <PSMDiagram>(DiagramController.Diagram as PSMDiagram)); c1_1.Execute(); //Attributes foreach (P_PSMAttribute A in C.Attributes) { NewAttributeCommand c5 = NewAttributeCommandFactory.Factory().Create(DiagramController.ModelController) as NewAttributeCommand; c5.Owner = C.Super as PSMClass; c5.Name = A.Alias; c5.Default = A.DefaultValue; c5.Lower = A.Lower; c5.Upper = A.Upper; ElementHolder <Property> h = new ElementHolder <Property>(); c5.createdAttributeHolder = h; //Model.SimpleDataType T = DiagramController.Project.Schema.. //c5.Type.Element //XmlSchemaType.GetBuiltInSimpleType(A.type); c5.Execute(); (h.Element as PSMAttribute).Alias = A.Alias; } if (current is P_PSMDiagram) { AddPSMClassToRoots_ModelCommand c1 = AddPSMClassToRoots_ModelCommandFactory.Factory().Create(DiagramController.ModelController) as AddPSMClassToRoots_ModelCommand; c1.Set(hldPSMClass, new HolderBase <PSMDiagram>(DiagramController.Diagram as PSMDiagram)); c1.Execute(); } else { if (C.ExtensionOf != null) { NewPSMSpecializationCommand c2s = NewPSMSpecializationCommandFactory.Factory().Create(DiagramController.ModelController) as NewPSMSpecializationCommand; c2s.GeneralPSMClass = new ElementHolder <PSMClass>() { Element = (current as P_PSMClass).Super as PSMClass }; c2s.SpecificPSMClass = new ElementHolder <PSMClass>() { Element = C.Super as PSMClass }; ElementHolder <Generalization> hldGeneralization = new ElementHolder <Generalization>(); c2s.CreatedGeneralization = hldGeneralization; c2s.Execute(); ElementToDiagramCommand <Generalization, GeneralizationViewHelper> c5s = (ElementToDiagramCommand <Generalization, GeneralizationViewHelper>) ElementToDiagramCommandFactory <Generalization, GeneralizationViewHelper> .Factory().Create(DiagramController); c5s.IncludedElement = hldGeneralization; c5s.Execute(); } else { NewPSMAssociationCommand c2 = NewPSMAssociationCommandFactory.Factory().Create(DiagramController.ModelController) as NewPSMAssociationCommand; ElementHolder <PSMAssociation> hldAssoc = new ElementHolder <PSMAssociation>(); c2.Lower = C.MinOccurs; c2.Upper = C.MaxOccurs; c2.Set((current as P_PSMBase).Super, hldPSMClass.Element, hldAssoc, null); c2.Execute(); ElementToDiagramCommand <PSMAssociation, PSMAssociationViewHelper> c5 = (ElementToDiagramCommand <PSMAssociation, PSMAssociationViewHelper>) ElementToDiagramCommandFactory <PSMAssociation, PSMAssociationViewHelper> .Factory().Create(DiagramController); c5.IncludedElement = hldAssoc; c5.Execute(); } } GeneratePSM(C); } else if (!(current is P_PSMDiagram) && child is P_PSMContentChoice) { NewPSMContentChoiceCommand c3 = NewPSMContentChoiceCommandFactory.Factory().Create(DiagramController) as NewPSMContentChoiceCommand; c3.Parent = (current as P_PSMBase).Super; c3.Execute(); (child as P_PSMContentChoice).Super = c3.CreatedChoice.Element; GeneratePSM(child as P_PSMContentChoice); } else if (!(current is P_PSMDiagram) && child is P_PSMAttributeContainer) { NewPSMAttributeContainerCommand c4 = NewPSMAttributeContainerCommandFactory.Factory().Create(DiagramController) as NewPSMAttributeContainerCommand; PSMClass owner = null; if (current is P_PSMClass) { owner = c4.PSMClass = (current as P_PSMClass).Super as PSMClass; } else if (current is P_PSMContentChoice) { c4.PSMSuper = (current as P_PSMContentChoice).Super as PSMSuperordinateComponent; owner = c4.PSMClass = (current as P_PSMContentChoice).P_PSMClass.Super as PSMClass; } else if (current is P_PSMContentContainer) { c4.PSMSuper = (current as P_PSMContentContainer).Super as PSMSuperordinateComponent; owner = c4.PSMClass = (current as P_PSMContentContainer).P_PSMClass.Super as PSMClass; } foreach (P_PSMAttribute A in (child as P_PSMAttributeContainer).Attributes) { NewAttributeCommand c5 = NewAttributeCommandFactory.Factory().Create(DiagramController.ModelController) as NewAttributeCommand; c5.Owner = owner; c5.Name = A.Alias; c5.Default = A.DefaultValue; c5.Lower = A.Lower; c5.Upper = A.Upper; ElementHolder <Property> h = new ElementHolder <Property>(); c5.createdAttributeHolder = h; c5.Execute(); (h.Element as PSMAttribute).Alias = A.Alias; c4.PSMAttributes.Add(h.Element as PSMAttribute); } c4.Execute(); } else if ((current is P_PSMClass) && child is P_PSMComment) { NewModelCommentToDiagramCommand C = NewModelCommentaryToDiagramCommandFactory.Factory().Create(DiagramController) as NewModelCommentToDiagramCommand; C.AnnotatedElement = (current as P_PSMClass).Super; C.Text = (child as P_PSMComment).text; C.Set(DiagramController.ModelController, DiagramController.ModelController.Model); C.Execute(); } else if (!(current is P_PSMDiagram) && child is P_PSMContentContainer) { P_PSMContentContainer CC = child as P_PSMContentContainer; NewPSMContentContainerCommand C = NewPSMContentContainerCommandFactory.Factory().Create(DiagramController) as NewPSMContentContainerCommand; if (current is P_PSMBase) { C.Parent = (current as P_PSMBase).Super; } C.Name = CC.ElementLabel; C.Execute(); CC.Super = C.CreatedContainer.Element; GeneratePSM(CC); } } }
void GeneratePSM2(I_PSMHasChildren current) { foreach (I_PSMHasParent child in current.Children) { if (child is P_PSMClass) { //UPDATE GUI: This is wrong, but better than crash due to detected deadlock: X.l.Content = (++currentClassCount).ToString() + "/" + X.ClassesCount.ToString() + " PSM Classes"; X.p.Value = currentClassCount; if (currentClassCount % (Math.Min(25, X.ClassesCount / 10) + 1) == 0) { Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new ThreadStart(delegate { })); } P_PSMClass C = child as P_PSMClass; PSMClass psmClass = tempPIMClass.DerivePSMClass(); C.Super = psmClass; psmClass.Name = C.Name.Name; psmClass.ElementName = C.ElementLabel; ViewHelper v = new PSMElementViewHelper(DiagramController.Diagram) { X = 0, Y = 0, Height = double.NaN, Width = double.NaN }; DiagramController.Diagram.AddModelElement(psmClass, v); psmClass.Diagram = DiagramController.Diagram as PSMDiagram; //Attributes foreach (P_PSMAttribute A in C.Attributes) { Property At = (C.Super as PSMClass).AddAttribute(); At.Name = A.Alias; At.Lower = A.Lower; /*if (Type != null && Type.Element != null) * createdAttribute.Type = Type.Element;*/ At.Upper = A.Upper; At.Default = A.DefaultValue; (At as PSMAttribute).Alias = A.Alias; } if (current is P_PSMDiagram) { (DiagramController.Diagram as PSMDiagram).Roots.Add(psmClass); } else { if (C.ExtensionOf != null) { Generalization generalization = DiagramController.ModelController.Model.Schema.SetGeneralization((current as P_PSMClass).Super as PSMClass, C.Super as PSMClass); DiagramController.Diagram.AddModelElement(generalization, new GeneralizationViewHelper(DiagramController.Diagram)); } else { PSMAssociation PSMAssoc = (PSMAssociation)(current as P_PSMBase).Super.AddComponent(PSMAssociationFactory.Instance); PSMAssoc.Child = psmClass; PSMAssoc.Upper = C.MaxOccurs; PSMAssoc.Lower = C.MinOccurs; DiagramController.Diagram.AddModelElement(PSMAssoc, new PSMAssociationViewHelper(DiagramController.Diagram)); PSMAssoc.Diagram = DiagramController.Diagram as PSMDiagram; } } GeneratePSM2(C); } else if (!(current is P_PSMDiagram) && child is P_PSMContentChoice) { PSMContentChoice psmChoice = (PSMContentChoice)(current as P_PSMBase).Super.AddComponent(PSMContentChoiceFactory.Instance); DiagramController.Diagram.AddModelElement(psmChoice, new PSMElementViewHelper(DiagramController.Diagram)); (child as P_PSMContentChoice).Super = psmChoice; GeneratePSM2(child as P_PSMContentChoice); } else if (!(current is P_PSMDiagram) && child is P_PSMAttributeContainer) { PSMClass owner = null; PSMSuperordinateComponent PSMSuper = null; PSMAttributeContainer psmAttributeContainer = null; if (current is P_PSMClass) { owner = (current as P_PSMClass).Super as PSMClass; } else if (current is P_PSMContentChoice) { PSMSuper = (current as P_PSMContentChoice).Super as PSMSuperordinateComponent; owner = (current as P_PSMContentChoice).P_PSMClass.Super as PSMClass; } else if (current is P_PSMContentContainer) { PSMSuper = (current as P_PSMContentContainer).Super as PSMSuperordinateComponent; owner = (current as P_PSMContentContainer).P_PSMClass.Super as PSMClass; } List <PSMAttribute> PSMAttributes = new List <PSMAttribute>(); foreach (P_PSMAttribute A in (child as P_PSMAttributeContainer).Attributes) { Property At = owner.AddAttribute(); At.Name = A.Alias; At.Lower = A.Lower; /*if (Type != null && Type.Element != null) * createdAttribute.Type = Type.Element;*/ At.Upper = A.Upper; At.Default = A.DefaultValue; (At as PSMAttribute).Alias = A.Alias; PSMAttributes.Add(At as PSMAttribute); owner.PSMAttributes.Remove(At as PSMAttribute); } if (PSMSuper != null) { psmAttributeContainer = (PSMAttributeContainer)PSMSuper.AddComponent(PSMAttributeContainerFactory.Instance); } else { psmAttributeContainer = (PSMAttributeContainer)owner.AddComponent(PSMAttributeContainerFactory.Instance); } foreach (PSMAttribute attribute in PSMAttributes) { psmAttributeContainer.PSMAttributes.Add(attribute); } DiagramController.Diagram.AddModelElement(psmAttributeContainer, new PSMElementViewHelper(DiagramController.Diagram)); } else if ((current is P_PSMClass) && child is P_PSMComment) { Comment C = (current as P_PSMClass).Super.AddComment(NameSuggestor <Comment> .SuggestUniqueName((current as P_PSMClass).Super.Comments, "Comment", comment => comment.Body)); C.Body = (child as P_PSMComment).text; DiagramController.Diagram.AddModelElement(C, new CommentViewHelper(DiagramController.Diagram)); } else if (!(current is P_PSMDiagram) && child is P_PSMContentContainer) { P_PSMContentContainer CC = child as P_PSMContentContainer; PSMContentContainer psmContainer = (PSMContentContainer)(current as P_PSMBase).Super.AddComponent(PSMContentContainerFactory.Instance); psmContainer.Name = CC.ElementLabel; CC.Super = psmContainer; DiagramController.Diagram.AddModelElement(psmContainer, new PSMElementViewHelper(DiagramController.Diagram)); GeneratePSM2(CC); } } }