* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / System.XML / System.Xml.Schema / XmlSchemaSimpleContent.cs
old mode 100755 (executable)
new mode 100644 (file)
index a1c3daf..81ee0a0
@@ -1,5 +1,31 @@
-// Author: Dwivedi, Ajay kumar\r
-//            Adwiv@Yahoo.com\r
+//\r
+// System.Xml.Schema.XmlSchemaSimpleContent.cs\r
+//\r
+// Author:\r
+//     Dwivedi, Ajay kumar  Adwiv@Yahoo.com\r
+//     Atsushi Enomoto  ginga@kit.hi-ho.ne.jp\r
+//\r
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
 using System;\r
 using System.Xml.Serialization;\r
 using System.Xml;\r
@@ -12,13 +38,13 @@ namespace System.Xml.Schema
        public class XmlSchemaSimpleContent : XmlSchemaContentModel\r
        {\r
                private XmlSchemaContent content;\r
-               private static string xmlname = "simpleContent";\r
+               const string xmlname = "simpleContent";\r
                public XmlSchemaSimpleContent()\r
                {\r
                }\r
 \r
-               [XmlElement("restriction",typeof(XmlSchemaSimpleContentRestriction),Namespace="http://www.w3.org/2001/XMLSchema")]\r
-               [XmlElement("extension",typeof(XmlSchemaSimpleContentExtension),Namespace="http://www.w3.org/2001/XMLSchema")]\r
+               [XmlElement("restriction",typeof(XmlSchemaSimpleContentRestriction))]\r
+               [XmlElement("extension",typeof(XmlSchemaSimpleContentExtension))]\r
                public override XmlSchemaContent Content \r
                {\r
                        get{ return  content; } \r
@@ -28,36 +54,48 @@ namespace System.Xml.Schema
                ///<remarks>\r
                /// 1. Content must be present and one of restriction or extention\r
                ///</remarks>\r
-               [MonoTODO]\r
-               internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
+               internal override int Compile(ValidationEventHandler h, XmlSchema schema)\r
                {\r
+                       // If this is already compiled this time, simply skip.\r
+                       if (CompilationId == schema.CompilationId)\r
+                               return 0;\r
+\r
                        if(Content == null)\r
                        {\r
                                error(h, "Content must be present in a simpleContent");\r
                        }\r
                        else\r
                        {\r
+#if NET_2_0\r
+                               Content.Parent = this;\r
+#endif\r
                                if(Content is XmlSchemaSimpleContentRestriction)\r
                                {\r
                                        XmlSchemaSimpleContentRestriction xscr = (XmlSchemaSimpleContentRestriction) Content;\r
-                                       errorCount += xscr.Compile(h,info);\r
+                                       errorCount += xscr.Compile(h, schema);\r
                                }\r
                                else if(Content is XmlSchemaSimpleContentExtension)\r
                                {\r
                                        XmlSchemaSimpleContentExtension xsce = (XmlSchemaSimpleContentExtension) Content;\r
-                                       errorCount += xsce.Compile(h,info);\r
+                                       errorCount += xsce.Compile(h, schema);\r
                                }\r
                                else\r
                                        error(h,"simpleContent can't have any value other than restriction or extention");\r
                        }\r
                        \r
-                       XmlSchemaUtil.CompileID(Id,this,info.IDCollection,h);\r
+                       XmlSchemaUtil.CompileID(Id,this, schema.IDCollection,h);\r
+                       this.CompilationId = schema.CompilationId;\r
                        return errorCount;\r
                }\r
                \r
-               [MonoTODO]\r
-               internal int Validate(ValidationEventHandler h)\r
+               internal override int Validate(ValidationEventHandler h, XmlSchema schema)\r
                {\r
+                       if (IsValidated (schema.ValidationId))\r
+                               return errorCount;\r
+\r
+                       errorCount += this.Content.Validate (h, schema);\r
+\r
+                       ValidationId = schema.ValidationId;\r
                        return errorCount;\r
                }\r
                //<simpleContent \r
@@ -87,17 +125,13 @@ namespace System.Xml.Schema
                                {\r
                                        simple.Id = reader.Value;\r
                                }\r
-                               else if(reader.NamespaceURI == "" || reader.NamespaceURI == XmlSchema.Namespace)\r
+                               else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)\r
                                {\r
                                        error(h,reader.Name + " is not a valid attribute for simpleContent",null);\r
                                }\r
                                else\r
                                {\r
-                                       if(reader.Prefix == "xmlns")\r
-                                               simple.Namespaces.Add(reader.LocalName, reader.Value);\r
-                                       else if(reader.Name == "xmlns")\r
-                                               simple.Namespaces.Add("",reader.Value);\r
-                                       //TODO: Add to Unhandled attributes\r
+                                       XmlSchemaUtil.ReadUnhandledAttribute(reader,simple);\r
                                }\r
                        }\r
                        \r