Reformat changes, and add some small debugging information to catch errors
[mono.git] / mcs / class / System.XML / System.Xml.Schema / XmlSchemaComplexContentExtension.cs
index bb9ad011b1ae1d97ca539bc734d3ca34b58ad306..4deced9326aae9df141f9e7ddffc7f74079fd38f 100755 (executable)
@@ -15,7 +15,7 @@ namespace System.Xml.Schema
                private XmlSchemaObjectCollection attributes;\r
                private XmlQualifiedName baseTypeName;\r
                private XmlSchemaParticle particle;\r
-               private int errorCount = 0;\r
+               private static string xmlname = "extension";\r
 \r
                public XmlSchemaComplexContentExtension()\r
                {\r
@@ -30,11 +30,14 @@ namespace System.Xml.Schema
                        set{ baseTypeName = value; }\r
                }\r
 \r
-               [XmlElement("anyAttribute",Namespace="http://www.w3.org/2001/XMLSchema")]\r
-               public XmlSchemaAnyAttribute AnyAttribute \r
+               [XmlElement("group",typeof(XmlSchemaGroupRef),Namespace="http://www.w3.org/2001/XMLSchema")]\r
+               [XmlElement("all",typeof(XmlSchemaAll),Namespace="http://www.w3.org/2001/XMLSchema")]\r
+               [XmlElement("choice",typeof(XmlSchemaChoice),Namespace="http://www.w3.org/2001/XMLSchema")]\r
+               [XmlElement("sequence",typeof(XmlSchemaSequence),Namespace="http://www.w3.org/2001/XMLSchema")]\r
+               public XmlSchemaParticle Particle\r
                {\r
-                       get{ return any; }\r
-                       set{ any = value;}\r
+                       get{ return  particle; }\r
+                       set{ particle = value; }\r
                }\r
 \r
                [XmlElement("attribute",typeof(XmlSchemaAttribute),Namespace="http://www.w3.org/2001/XMLSchema")]\r
@@ -44,14 +47,11 @@ namespace System.Xml.Schema
                        get{ return attributes; }\r
                }\r
 \r
-               [XmlElement("group",typeof(XmlSchemaGroupRef),Namespace="http://www.w3.org/2001/XMLSchema")]\r
-               [XmlElement("all",typeof(XmlSchemaAll),Namespace="http://www.w3.org/2001/XMLSchema")]\r
-               [XmlElement("choice",typeof(XmlSchemaChoice),Namespace="http://www.w3.org/2001/XMLSchema")]\r
-               [XmlElement("sequence",typeof(XmlSchemaSequence),Namespace="http://www.w3.org/2001/XMLSchema")]\r
-               public XmlSchemaParticle Particle\r
+               [XmlElement("anyAttribute",Namespace="http://www.w3.org/2001/XMLSchema")]\r
+               public XmlSchemaAnyAttribute AnyAttribute \r
                {\r
-                       get{ return  particle; }\r
-                       set{ particle = value; }\r
+                       get{ return any; }\r
+                       set{ any = value;}\r
                }\r
 \r
                /// <remarks>\r
@@ -63,6 +63,8 @@ namespace System.Xml.Schema
                        {\r
                                error(h, "base must be present and a QName");\r
                        }\r
+                       else if(!XmlSchemaUtil.CheckQName(BaseTypeName))\r
+                               error(h,"BaseTypeName is not a valid XmlQualifiedName");\r
                        \r
                        if(this.AnyAttribute != null)\r
                        {\r
@@ -82,7 +84,7 @@ namespace System.Xml.Schema
                                        errorCount += atgrp.Compile(h,info);\r
                                }\r
                                else\r
-                                       error(h,"object is not valid in this place");\r
+                                       error(h,obj.GetType() +" is not valid in this place::ComplexConetnetExtension");\r
                        }\r
                        \r
                        if(Particle != null)\r
@@ -104,9 +106,9 @@ namespace System.Xml.Schema
                                        errorCount += ((XmlSchemaSequence)Particle).Compile(h,info);\r
                                }\r
                        }\r
-                       if(this.Id != null && !XmlSchemaUtil.CheckID(Id))\r
-                               error(h, "id must be a valid ID");\r
                        \r
+                       XmlSchemaUtil.CompileID(Id,this,info.IDCollection,h);\r
+\r
                        return errorCount;\r
                }\r
                \r
@@ -115,11 +117,138 @@ namespace System.Xml.Schema
                {\r
                        return errorCount;\r
                }\r
-\r
-               internal void error(ValidationEventHandler handle,string message)\r
+               //<extension\r
+               //  base = QName\r
+               //  id = ID\r
+               //  {any attributes with non-schema namespace . . .}>\r
+               //  Content: (annotation?, ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?)))\r
+               //</extension>\r
+               internal static XmlSchemaComplexContentExtension Read(XmlSchemaReader reader, ValidationEventHandler h)\r
                {\r
-                       errorCount++;\r
-                       ValidationHandler.RaiseValidationError(handle,this,message);\r
+                       XmlSchemaComplexContentExtension extension = new XmlSchemaComplexContentExtension();\r
+                       reader.MoveToElement();\r
+\r
+                       if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)\r
+                       {\r
+                               error(h,"Should not happen :1: XmlSchemaComplexContentExtension.Read, name="+reader.Name,null);\r
+                               reader.Skip();\r
+                               return null;\r
+                       }\r
+\r
+                       extension.LineNumber = reader.LineNumber;\r
+                       extension.LinePosition = reader.LinePosition;\r
+                       extension.SourceUri = reader.BaseURI;\r
+\r
+                       while(reader.MoveToNextAttribute())\r
+                       {\r
+                               if(reader.Name == "base")\r
+                               {\r
+                                       Exception innerex;\r
+                                       extension.baseTypeName = XmlSchemaUtil.ReadQNameAttribute(reader,out innerex);\r
+                                       if(innerex != null)\r
+                                               error(h, reader.Value + " is not a valid value for base attribute",innerex);\r
+                               }\r
+                               else if(reader.Name == "id")\r
+                               {\r
+                                       extension.Id = reader.Value;\r
+                               }\r
+                               else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)\r
+                               {\r
+                                       error(h,reader.Name + " is not a valid attribute for extension",null);\r
+                               }\r
+                               else\r
+                               {\r
+                                       XmlSchemaUtil.ReadUnhandledAttribute(reader,extension);\r
+                               }\r
+                       }\r
+                       \r
+                       reader.MoveToElement();\r
+                       if(reader.IsEmptyElement)\r
+                               return extension;\r
+                       //Content: 1. annotation?, \r
+                       //                      (2.(group | all | choice | sequence)?, (3.(attribute | attributeGroup)*, 4.anyAttribute?)))\r
+                       int level = 1;\r
+                       while(reader.ReadNextElement())\r
+                       {\r
+                               if(reader.NodeType == XmlNodeType.EndElement)\r
+                               {\r
+                                       if(reader.LocalName != xmlname)\r
+                                               error(h,"Should not happen :2: XmlSchemaComplexContentExtension.Read, name="+reader.Name,null);\r
+                                       break;\r
+                               }\r
+                               if(level <= 1 && reader.LocalName == "annotation")\r
+                               {\r
+                                       level = 2; //Only one annotation\r
+                                       XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);\r
+                                       if(annotation != null)\r
+                                               extension.Annotation = annotation;\r
+                                       continue;\r
+                               }\r
+                               if(level <= 2)\r
+                               {\r
+                                       if(reader.LocalName == "group")\r
+                                       {\r
+                                               level = 3;\r
+                                               XmlSchemaGroupRef group = XmlSchemaGroupRef.Read(reader,h);\r
+                                               if(group != null)\r
+                                                       extension.particle = group;\r
+                                               continue;\r
+                                       }\r
+                                       if(reader.LocalName == "all")\r
+                                       {\r
+                                               level = 3;\r
+                                               XmlSchemaAll all = XmlSchemaAll.Read(reader,h);\r
+                                               if(all != null)\r
+                                                       extension.particle = all;\r
+                                               continue;\r
+                                       }\r
+                                       if(reader.LocalName == "choice")\r
+                                       {\r
+                                               level = 3;\r
+                                               XmlSchemaChoice choice = XmlSchemaChoice.Read(reader,h);\r
+                                               if(choice != null)\r
+                                                       extension.particle = choice;\r
+                                               continue;\r
+                                       }\r
+                                       if(reader.LocalName == "sequence")\r
+                                       {\r
+                                               level = 3;\r
+                                               XmlSchemaSequence sequence = XmlSchemaSequence.Read(reader,h);\r
+                                               if(sequence != null)\r
+                                                       extension.particle = sequence;\r
+                                               continue;\r
+                                       }\r
+                               }\r
+                               if(level <= 3)\r
+                               {\r
+                                       if(reader.LocalName == "attribute")\r
+                                       {\r
+                                               level = 3;\r
+                                               XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader,h);\r
+                                               if(attr != null)\r
+                                                       extension.Attributes.Add(attr);\r
+                                               continue;\r
+                                       }\r
+                                       if(reader.LocalName == "attributeGroup")\r
+                                       {\r
+                                               level = 3;\r
+                                               XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader,h);\r
+                                               if(attr != null)\r
+                                                       extension.attributes.Add(attr);\r
+                                               continue;\r
+                                       }\r
+                               }\r
+                               if(level <= 4 && reader.LocalName == "anyAttribute")\r
+                               {\r
+                                       level = 5;\r
+                                       XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader,h);\r
+                                       if(anyattr != null)\r
+                                               extension.AnyAttribute = anyattr;\r
+                                       continue;\r
+                               }\r
+                               reader.RaiseInvalidElementError();\r
+                       }\r
+                       return extension;\r
                }\r
        }\r
 }\r