Reformat changes, and add some small debugging information to catch errors
[mono.git] / mcs / class / System.XML / System.Xml.Schema / XmlSchemaComplexContent.cs
index c397af5686579f02cf11c54d56694c2d42d4b9a5..45b07b3b1f008023d39970c006b6ae6105507c17 100755 (executable)
@@ -2,6 +2,7 @@
 //            Adwiv@Yahoo.com\r
 using System;\r
 using System.Xml.Serialization;\r
+using System.Xml;\r
 \r
 namespace System.Xml.Schema\r
 {\r
@@ -12,11 +13,18 @@ namespace System.Xml.Schema
        {\r
                private XmlSchemaContent content;\r
                private bool isMixed;\r
-               private int errorCount=0;\r
+               private static string xmlname = "complexContent";\r
 \r
                public XmlSchemaComplexContent()\r
                {}\r
 \r
+               [System.Xml.Serialization.XmlAttribute("mixed")]\r
+               public bool IsMixed \r
+               {\r
+                       get{ return  isMixed; } \r
+                       set{ isMixed = value; }\r
+               }\r
+\r
                [XmlElement("restriction",typeof(XmlSchemaComplexContentRestriction),Namespace="http://www.w3.org/2001/XMLSchema")]\r
                [XmlElement("extension",typeof(XmlSchemaComplexContentExtension),Namespace="http://www.w3.org/2001/XMLSchema")]\r
                public override XmlSchemaContent Content \r
@@ -25,13 +33,6 @@ namespace System.Xml.Schema
                        set{ content = value; }\r
                }\r
 \r
-               [System.Xml.Serialization.XmlAttribute("mixed")]\r
-               public bool IsMixed \r
-               {\r
-                       get{ return  isMixed; } \r
-                       set{ isMixed = value; }\r
-               }\r
-\r
                /// <remarks>\r
                /// 1. Content must be present\r
                /// </remarks>\r
@@ -58,8 +59,7 @@ namespace System.Xml.Schema
                                        error(h,"complexContent can't have any value other than restriction or extention");\r
                        }\r
 \r
-                       if(this.Id != null && !XmlSchemaUtil.CheckID(Id))\r
-                               error(h, "id must be a valid ID");\r
+                       XmlSchemaUtil.CompileID(Id,this,info.IDCollection,h);\r
 \r
                        return errorCount;\r
                }\r
@@ -69,11 +69,94 @@ namespace System.Xml.Schema
                {\r
                        return errorCount;\r
                }\r
-\r
-               internal void error(ValidationEventHandler handle,string message)\r
+               //<complexContent\r
+               //  id = ID\r
+               //  mixed = boolean\r
+               //  {any attributes with non-schema namespace . . .}>\r
+               //  Content: (annotation?, (restriction | extension))\r
+               //</complexContent>\r
+               internal static XmlSchemaComplexContent Read(XmlSchemaReader reader, ValidationEventHandler h)\r
                {\r
-                       errorCount++;\r
-                       ValidationHandler.RaiseValidationError(handle,this,message);\r
+                       XmlSchemaComplexContent complex = new XmlSchemaComplexContent();\r
+                       reader.MoveToElement();\r
+\r
+                       if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)\r
+                       {\r
+                               error(h,"Should not happen :1: XmlSchemaComplexContent.Read, name="+reader.Name,null);\r
+                               reader.Skip();\r
+                               return null;\r
+                       }\r
+\r
+                       complex.LineNumber = reader.LineNumber;\r
+                       complex.LinePosition = reader.LinePosition;\r
+                       complex.SourceUri = reader.BaseURI;\r
+\r
+                       while(reader.MoveToNextAttribute())\r
+                       {\r
+                               if(reader.Name == "id")\r
+                               {\r
+                                       complex.Id = reader.Value;\r
+                               }\r
+                               else if(reader.Name == "mixed")\r
+                               {\r
+                                       Exception innerex;\r
+                                       complex.isMixed = XmlSchemaUtil.ReadBoolAttribute(reader,out innerex);\r
+                                       if(innerex != null)\r
+                                               error(h,reader.Value + " is an invalid value for mixed",innerex);\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 complexContent",null);\r
+                               }\r
+                               else\r
+                               {\r
+                                       XmlSchemaUtil.ReadUnhandledAttribute(reader,complex);\r
+                               }\r
+                       }\r
+                       \r
+                       reader.MoveToElement();\r
+                       if(reader.IsEmptyElement)\r
+                               return complex;\r
+                       //Content: (annotation?, (restriction | extension))\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: XmlSchemaComplexContent.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
+                                               complex.Annotation = annotation;\r
+                                       continue;\r
+                               }\r
+                               if(level <=2)\r
+                               {\r
+                                       if(reader.LocalName == "restriction")\r
+                                       {\r
+                                               level = 3;\r
+                                               XmlSchemaComplexContentRestriction restriction = XmlSchemaComplexContentRestriction.Read(reader,h);\r
+                                               if(restriction != null)\r
+                                                       complex.content = restriction;\r
+                                               continue;\r
+                                       }\r
+                                       if(reader.LocalName == "extension")\r
+                                       {\r
+                                               level = 3;\r
+                                               XmlSchemaComplexContentExtension extension = XmlSchemaComplexContentExtension.Read(reader,h);\r
+                                               if(extension != null)\r
+                                                       complex.content = extension;\r
+                                               continue;\r
+                                       }\r
+                               }\r
+                               reader.RaiseInvalidElementError();\r
+                       }\r
+                       return complex;\r
                }\r
        }\r
 }\r