2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / System.XML / System.Xml.Schema / XmlSchemaComplexContentRestriction.cs
index b2cc7c5db52bb00f8ed3f59b44d357b1f63c1957..89d7f7b34f8685ebd3f9fb3c738f76fcf3315630 100755 (executable)
@@ -1,5 +1,31 @@
-// Author: Dwivedi, Ajay kumar\r
-//            Adwiv@Yahoo.com\r
+//\r
+// System.Xml.Schema.XmlSchemaComplexContentRestriction.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;\r
 using System.Xml.Serialization;\r
@@ -15,7 +41,7 @@ namespace System.Xml.Schema
                private XmlSchemaObjectCollection attributes;\r
                private XmlQualifiedName baseTypeName;\r
                private XmlSchemaParticle particle;\r
-               private static string xmlname = "restriction";\r
+               const string xmlname = "restriction";\r
 \r
                public XmlSchemaComplexContentRestriction()\r
                {\r
@@ -30,44 +56,74 @@ 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=XmlSchema.Namespace)]\r
+               [XmlElement("all",typeof(XmlSchemaAll),Namespace=XmlSchema.Namespace)]\r
+               [XmlElement("choice",typeof(XmlSchemaChoice),Namespace=XmlSchema.Namespace)]\r
+               [XmlElement("sequence",typeof(XmlSchemaSequence),Namespace=XmlSchema.Namespace)]\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
-               [XmlElement("attributeGroup",typeof(XmlSchemaAttributeGroupRef),Namespace="http://www.w3.org/2001/XMLSchema")]\r
+               [XmlElement("attribute",typeof(XmlSchemaAttribute),Namespace=XmlSchema.Namespace)]\r
+               [XmlElement("attributeGroup",typeof(XmlSchemaAttributeGroupRef),Namespace=XmlSchema.Namespace)]\r
                public XmlSchemaObjectCollection Attributes \r
                {\r
                        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=XmlSchema.Namespace)]\r
+               public XmlSchemaAnyAttribute AnyAttribute \r
                {\r
-                       get{ return  particle; }\r
-                       set{ particle = value; }\r
+                       get{ return  any; }\r
+                       set{ any = value; }\r
+               }\r
+\r
+               // internal properties\r
+               internal override bool IsExtension {\r
+                       get { return false; }\r
                }\r
 \r
                /// <remarks>\r
                /// 1. base must be present\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 (this.IsComplied (schema.CompilationId))\r
+                               return 0;\r
+\r
+#if NET_2_0\r
+                       if (Particle != null)\r
+                               Particle.Parent = this;\r
+                       if (AnyAttribute != null)\r
+                               AnyAttribute.Parent = this;\r
+                       foreach (XmlSchemaObject obj in Attributes)\r
+                               obj.Parent = this;\r
+#endif\r
+\r
+                       if (this.isRedefinedComponent) {\r
+                               if (Annotation != null)\r
+                                       Annotation.isRedefinedComponent = true;\r
+                               if (AnyAttribute != null)\r
+                                       AnyAttribute.isRedefinedComponent = true;\r
+                               foreach (XmlSchemaObject obj in Attributes)\r
+                                       obj.isRedefinedComponent = true;\r
+                               if (Particle != null)\r
+                                       Particle.isRedefinedComponent = true;\r
+                       }\r
+\r
                        if(BaseTypeName == null || BaseTypeName.IsEmpty)\r
                        {\r
-                               error(h, "base must be present and a QName");\r
+                               error(h, "base must be present, as a QName");\r
                        }\r
-                       \r
+                       else if(!XmlSchemaUtil.CheckQName(BaseTypeName))\r
+                               error(h,"BaseTypeName is not a valid XmlQualifiedName");\r
+\r
                        if(this.AnyAttribute != null)\r
                        {\r
-                               errorCount += AnyAttribute.Compile(h,info);\r
+                               errorCount += AnyAttribute.Compile(h, schema);\r
                        }\r
 \r
                        foreach(XmlSchemaObject obj in Attributes)\r
@@ -75,12 +131,12 @@ namespace System.Xml.Schema
                                if(obj is XmlSchemaAttribute)\r
                                {\r
                                        XmlSchemaAttribute attr = (XmlSchemaAttribute) obj;\r
-                                       errorCount += attr.Compile(h,info);\r
+                                       errorCount += attr.Compile(h, schema);\r
                                }\r
                                else if(obj is XmlSchemaAttributeGroupRef)\r
                                {\r
                                        XmlSchemaAttributeGroupRef atgrp = (XmlSchemaAttributeGroupRef) obj;\r
-                                       errorCount += atgrp.Compile(h,info);\r
+                                       errorCount += atgrp.Compile(h, schema);\r
                                }\r
                                else\r
                                        error(h,obj.GetType() +" is not valid in this place::ComplexContentRestriction");\r
@@ -90,29 +146,41 @@ namespace System.Xml.Schema
                        {\r
                                if(Particle is XmlSchemaGroupRef)\r
                                {\r
-                                       errorCount += ((XmlSchemaGroupRef)Particle).Compile(h,info);\r
+                                       errorCount += ((XmlSchemaGroupRef)Particle).Compile(h, schema);\r
                                }\r
                                else if(Particle is XmlSchemaAll)\r
                                {\r
-                                       errorCount += ((XmlSchemaAll)Particle).Compile(h,info);\r
+                                       errorCount += ((XmlSchemaAll)Particle).Compile(h, schema);\r
                                }\r
                                else if(Particle is XmlSchemaChoice)\r
                                {\r
-                                       errorCount += ((XmlSchemaChoice)Particle).Compile(h,info);\r
+                                       errorCount += ((XmlSchemaChoice)Particle).Compile(h, schema);\r
                                }\r
                                else if(Particle is XmlSchemaSequence)\r
                                {\r
-                                       errorCount += ((XmlSchemaSequence)Particle).Compile(h,info);\r
+                                       errorCount += ((XmlSchemaSequence)Particle).Compile(h, schema);\r
                                }\r
+                               else\r
+                                       error (h, "Particle of a restriction is limited only to group, sequence, choice and all.");\r
                        }\r
-                       if(this.Id != null && !XmlSchemaUtil.CheckID(Id))\r
-                               error(h, "id must be a valid ID");\r
                        \r
+                       XmlSchemaUtil.CompileID(Id,this, schema.IDCollection,h);\r
+\r
+                       this.CompilationId = schema.CompilationId;\r
                        return errorCount;\r
                }\r
                \r
-               [MonoTODO]\r
-               internal int Validate(ValidationEventHandler h)\r
+               internal override XmlQualifiedName GetBaseTypeName ()\r
+               {\r
+                       return baseTypeName;\r
+               }\r
+\r
+               internal override XmlSchemaParticle GetParticle ()\r
+               {\r
+                       return particle;\r
+               }\r
+\r
+               internal override int Validate (ValidationEventHandler h, XmlSchema schema)\r
                {\r
                        return errorCount;\r
                }\r
@@ -152,13 +220,13 @@ namespace System.Xml.Schema
                                {\r
                                        restriction.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 restriction",null);\r
                                }\r
                                else\r
                                {\r
-                                       //TODO: Add to Unhandled attributes\r
+                                       XmlSchemaUtil.ReadUnhandledAttribute(reader,restriction);\r
                                }\r
                        }\r
                        \r