示例#1
0
        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);
            }
        }
示例#2
0
 void TraverseElement(XmlSchemaElement elem, int level, I_PSMHasChildren Parent, P_PSMDiagram diagram)
 {
     if (elem.ElementSchemaType is XmlSchemaComplexType)
     {
         //Print("TADY: \"" + elem.SchemaType + "\" \"" + elem.SchemaTypeName + "\" \"" + elem.ElementSchemaType + "\"" + Environment.NewLine, 0);
         ProcessComplexType(elem.ElementSchemaType as XmlSchemaComplexType, level, Parent, diagram, elem);
     }
     else if (elem.ElementSchemaType is XmlSchemaSimpleType)
     {
         if ((elem.ElementSchemaType as XmlSchemaSimpleType).BaseXmlSchemaType == null)
         {
             Print("XmlSchemaElement with BaseSchemaType null: \"", level);
             P_PSMAttributeContainer c = new P_PSMAttributeContainer();
             Parent.Children.Add(c);
             c.Parent = Parent;
             P_PSMAttribute a = new P_PSMAttribute()
             {
                 Alias = elem.QualifiedName.Name, type = elem.ElementSchemaType.QualifiedName
             };
             //TODO: ANY?
             a.Lower = (uint)elem.MinOccurs;
             a.Upper = DecToUN(elem.MaxOccurs);
             c.Attributes.Add(a);
         }
         else
         {
             // Each element creates an attribute container... merged in post processing.
             // Could be done in another way that needs access 2 levels above in
             // the recursion to realise that there already exists an AC
             Print("XmlSchemaElement: \"" + elem.Name + "\" Simple type: \""
                   + elem.ElementSchemaType.BaseXmlSchemaType.QualifiedName + "\" refname: \"" + elem.RefName + "\"" + Environment.NewLine, level);
             P_PSMAttributeContainer c = new P_PSMAttributeContainer();
             Parent.Children.Add(c);
             c.Parent = Parent;
             P_PSMAttribute a = new P_PSMAttribute()
             {
                 Alias = elem.QualifiedName.Name, type = elem.ElementSchemaType.BaseXmlSchemaType.QualifiedName
             };
             a.Lower = (uint)elem.MinOccurs;
             a.Upper = DecToUN(elem.MaxOccurs);
             c.Attributes.Add(a);
         }
     }
     else if (elem.ElementSchemaType == null)
     {
         //Special case for elements inside Group...
         TraverseGroupInsides(elem, level, Parent, diagram);
     }
 }
示例#3
0
        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);
                }
            }
        }
示例#4
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);
                }
            }
        }