Пример #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 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);
                    }
                }
            }
        }
Пример #4
0
        void SetAttributeUse(P_PSMAttribute A, XmlSchemaAttribute a)
        {
            //TODO: Move to XSDtoPPSM
            switch (a.Use)
            {
            case XmlSchemaUse.Optional:
                A.Lower = 0;
                A.Upper = 1;
                break;

            case XmlSchemaUse.Required:
                A.Lower = 1;
                A.Upper = 1;
                break;

            case XmlSchemaUse.Prohibited:
                A.Lower = 0;
                A.Upper = 0;
                break;
            }
        }
Пример #5
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);
                }
            }
        }