Esempio n. 1
0
        void TraverseGroupBase(XmlSchemaGroupBase GroupBase, int level, I_PSMHasChildren Current, P_PSMDiagram diagram)
        {
            Print(GroupBaseName(GroupBase) + " Subitems: "
                  + GroupBase.Items.Count + Environment.NewLine, level);

            if (GroupBase is XmlSchemaSequence)
            {
                P_PSMDummy D = new P_PSMDummy();
                D.Parent = Current;
                Current.Children.Add(D);

                foreach (XmlSchemaParticle subParticle in GroupBase.Items)
                {
                    //TODO: Vyresit sequence v choice
                    TraverseParticle(subParticle, level + 1, D, diagram);
                }
            }
            else if (GroupBase is XmlSchemaChoice)
            {
                P_PSMContentChoice CC = new P_PSMContentChoice();
                Current.Children.Add(CC);
                CC.Parent = Current;
                foreach (XmlSchemaParticle subParticle in GroupBase.Items)
                {
                    TraverseParticle(subParticle, level + 1, CC, diagram);
                }
            }
            else
            {
                foreach (XmlSchemaParticle subParticle in GroupBase.Items)
                {
                    TraverseParticle(subParticle, level + 1, Current, diagram);
                }
            }
        }
Esempio n. 2
0
        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);
                }
            }
        }