Merge pull request #319 from pragmatrix/master
[mono.git] / mcs / class / System.XML / System.Xml.Schema / XmlSchemaAttributeGroup.cs
index 2d8bb3cb843f723fbc737e16d5a7d066533620c8..5922b8c1e907ce2bc4b5e6d54b6234c8064eab37 100644 (file)
@@ -1,10 +1,10 @@
-//\r
-// System.Xml.Schema.XmlSchemaAttributeGroup.cs\r
-//\r
-// Authors:\r
-//     Dwivedi, Ajay kumar  Adwiv@Yahoo.com\r
-//     Enomoto, Atsushi     ginga@kit.hi-ho.ne.jp\r
-//\r
+//
+// System.Xml.Schema.XmlSchemaAttributeGroup.cs
+//
+// Authors:
+//     Dwivedi, Ajay kumar  Adwiv@Yahoo.com
+//     Enomoto, Atsushi     ginga@kit.hi-ho.ne.jp
+//
 
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // 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.Collections;\r
-using System.Xml.Serialization;\r
-using System.Xml;\r
-\r
-namespace System.Xml.Schema\r
-{\r
-       /// <summary>\r
-       /// Summary description for XmlSchemaAttributeGroup.\r
-       /// </summary>\r
-       public class XmlSchemaAttributeGroup : XmlSchemaAnnotated\r
-       {\r
-               private XmlSchemaAnyAttribute anyAttribute;\r
-               private XmlSchemaObjectCollection attributes;\r
-               private string name;\r
-               private XmlSchemaAttributeGroup redefined;\r
-               private XmlQualifiedName qualifiedName;\r
-               const string xmlname = "attributeGroup";\r
-               private XmlSchemaObjectTable attributeUses;\r
-               private XmlSchemaAnyAttribute anyAttributeUse;\r
-\r
-               internal bool AttributeGroupRecursionCheck;\r
-\r
-               public XmlSchemaAttributeGroup()\r
-               {\r
-                       attributes  = new XmlSchemaObjectCollection();\r
-                       qualifiedName = XmlQualifiedName.Empty;\r
-               }\r
-\r
-               [System.Xml.Serialization.XmlAttribute("name")]\r
-               public string Name \r
-               {\r
-                       get{ return name;}\r
-                       set{ name = value;}\r
-               }\r
-\r
-               [XmlElement("attribute",typeof(XmlSchemaAttribute))]\r
-               [XmlElement("attributeGroup",typeof(XmlSchemaAttributeGroupRef))]\r
-               public XmlSchemaObjectCollection Attributes \r
-               {\r
-                       get{ return attributes;}\r
-               }\r
-\r
-               internal XmlSchemaObjectTable AttributeUses\r
-               {\r
-                       get { return attributeUses; }\r
-               }\r
-               internal XmlSchemaAnyAttribute AnyAttributeUse\r
-               {\r
-                       get { return anyAttributeUse; }\r
-               }\r
-\r
-               [XmlElement("anyAttribute")]\r
-               public XmlSchemaAnyAttribute AnyAttribute \r
-               {\r
-                       get{ return anyAttribute;}\r
-                       set{ anyAttribute = value;}\r
-               }\r
-\r
-               //Undocumented property\r
-               [XmlIgnore]\r
-               public XmlSchemaAttributeGroup RedefinedAttributeGroup \r
-               {\r
-                       get{ return redefined;}\r
-               }\r
-\r
-               [XmlIgnore]\r
-#if NET_2_0\r
-               public XmlQualifiedName QualifiedName \r
-#else\r
-               internal XmlQualifiedName QualifiedName \r
-#endif\r
-               {\r
-                       get{ return qualifiedName;}\r
-               }\r
-\r
-               /// <remarks>\r
-               /// An Attribute group can only be defined as a child of XmlSchema or in XmlSchemaRedefine.\r
-               /// The other attributeGroup has type XmlSchemaAttributeGroupRef.\r
-               ///  1. Name must be present\r
-               /// </remarks>\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 errorCount;\r
-\r
-                       errorCount = 0;\r
-\r
-                       if (redefinedObject != null) {\r
-                               errorCount += redefined.Compile (h, schema);\r
-                               if (errorCount == 0)\r
-                                       redefined = (XmlSchemaAttributeGroup) redefinedObject;\r
-                       }\r
-\r
-                       XmlSchemaUtil.CompileID(Id,this, schema.IDCollection,h);\r
-\r
-                       if(this.Name == null || this.Name == String.Empty) //1\r
-                               error(h,"Name is required in top level simpletype");\r
-                       else if(!XmlSchemaUtil.CheckNCName(this.Name)) // b.1.2\r
-                               error(h,"name attribute of a simpleType must be NCName");\r
-                       else\r
-                               this.qualifiedName = new XmlQualifiedName(this.Name, schema.TargetNamespace);\r
-                       \r
-                       if(this.AnyAttribute != null)\r
-                       {\r
-#if NET_2_0\r
-                               this.AnyAttribute.Parent = this;\r
-#endif\r
-                               errorCount += this.AnyAttribute.Compile(h, schema);\r
-                       }\r
-                       \r
-                       foreach(XmlSchemaObject obj in Attributes)\r
-                       {\r
-#if NET_2_0\r
-                               obj.Parent = this;\r
-#endif\r
-\r
-                               if(obj is XmlSchemaAttribute)\r
-                               {\r
-                                       XmlSchemaAttribute attr = (XmlSchemaAttribute) obj;\r
-                                       errorCount += attr.Compile(h, schema);\r
-                               }\r
-                               else if(obj is XmlSchemaAttributeGroupRef)\r
-                               {\r
-                                       XmlSchemaAttributeGroupRef gref = (XmlSchemaAttributeGroupRef) obj;\r
-                                       errorCount += gref.Compile(h, schema);\r
-                               }\r
-                               else\r
-                               {\r
-                                       error(h,"invalid type of object in Attributes property");\r
-                               }\r
-                       }\r
-                       this.CompilationId = schema.CompilationId;\r
-                       return errorCount;\r
-               }\r
-\r
-               internal override int Validate(ValidationEventHandler h, XmlSchema schema)\r
-               {\r
-                       if (IsValidated (schema.CompilationId))\r
-                               return errorCount;\r
-\r
-                       if (redefined == null && redefinedObject != null) {\r
-                               redefinedObject.Compile (h, schema);\r
-                               redefined = (XmlSchemaAttributeGroup) redefinedObject;\r
-                               redefined.Validate (h, schema);\r
-                       }\r
-\r
-                       XmlSchemaObjectCollection actualAttributes = null;\r
-                       /*\r
-                       if (this.redefined != null) {\r
-                               actualAttributes = new XmlSchemaObjectCollection ();\r
-                               foreach (XmlSchemaObject obj in Attributes) {\r
-                                       XmlSchemaAttributeGroupRef grp = obj as XmlSchemaAttributeGroupRef;\r
-                                       if (grp != null && grp.QualifiedName == this.QualifiedName)\r
-                                               actualAttributes.Add (redefined);\r
-                                       else\r
-                                               actualAttributes.Add (obj);\r
-                               }\r
-                       }\r
-                       else\r
-                       */\r
-                               actualAttributes = Attributes;\r
-\r
-                       attributeUses = new XmlSchemaObjectTable ();\r
-                       errorCount += XmlSchemaUtil.ValidateAttributesResolved (attributeUses,\r
-                               h, schema, actualAttributes, AnyAttribute, \r
-                               ref anyAttributeUse, redefined, false);\r
-                       ValidationId = schema.ValidationId;\r
-                       return errorCount;\r
-               }\r
-\r
-               //<attributeGroup\r
-               //  id = ID\r
-               //  name = NCName\r
-               //  ref = QName // Not present in this class.\r
-               //  {any attributes with non-schema namespace . . .}>\r
-               //  Content: (annotation?, ((attribute | attributeGroup)*, anyAttribute?))\r
-               //</attributeGroup>\r
-               internal static XmlSchemaAttributeGroup Read(XmlSchemaReader reader, ValidationEventHandler h)\r
-               {\r
-                       XmlSchemaAttributeGroup attrgrp = new XmlSchemaAttributeGroup();\r
-                       reader.MoveToElement();\r
-\r
-                       if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)\r
-                       {\r
-                               error(h,"Should not happen :1: XmlSchemaAttributeGroup.Read, name="+reader.Name,null);\r
-                               reader.SkipToEnd();\r
-                               return null;\r
-                       }\r
-\r
-                       attrgrp.LineNumber = reader.LineNumber;\r
-                       attrgrp.LinePosition = reader.LinePosition;\r
-                       attrgrp.SourceUri = reader.BaseURI;\r
-\r
-                       while(reader.MoveToNextAttribute())\r
-                       {\r
-                               if(reader.Name == "id")\r
-                               {\r
-                                       attrgrp.Id = reader.Value;\r
-                               }\r
-                               else if(reader.Name == "name")\r
-                               {\r
-                                       attrgrp.name = 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 attributeGroup in this context",null);\r
-                               }\r
-                               else\r
-                               {\r
-                                       XmlSchemaUtil.ReadUnhandledAttribute(reader,attrgrp);\r
-                               }\r
-                       }\r
-                       \r
-                       reader.MoveToElement();\r
-                       if(reader.IsEmptyElement)\r
-                               return attrgrp;\r
-\r
-                       //Content: 1.annotation?, 2.(attribute | attributeGroup)*, 3.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: XmlSchemaAttributeGroup.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
-                                               attrgrp.Annotation = annotation;\r
-                                       continue;\r
-                               }\r
-                               if(level <= 2)\r
-                               {\r
-                                       if(reader.LocalName == "attribute")\r
-                                       {\r
-                                               level = 2;\r
-                                               XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader,h);\r
-                                               if(attr != null)\r
-                                                       attrgrp.Attributes.Add(attr);\r
-                                               continue;\r
-                                       }\r
-                                       if(reader.LocalName == "attributeGroup")\r
-                                       {\r
-                                               level = 2;\r
-                                               XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader,h);\r
-                                               if(attr != null)\r
-                                                       attrgrp.attributes.Add(attr);\r
-                                               continue;\r
-                                       }\r
-                               }\r
-                               if(level <= 3 && reader.LocalName == "anyAttribute")\r
-                               {\r
-                                       level = 4;\r
-                                       XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader,h);\r
-                                       if(anyattr != null)\r
-                                               attrgrp.AnyAttribute = anyattr;\r
-                                       continue;\r
-                               }\r
-                               reader.RaiseInvalidElementError();\r
-                       }\r
-                       return attrgrp;\r
-               }\r
-               \r
-       }\r
-}\r
+using System;
+using System.Collections;
+using System.Xml.Serialization;
+using System.Xml;
+
+namespace System.Xml.Schema
+{
+       /// <summary>
+       /// Summary description for XmlSchemaAttributeGroup.
+       /// </summary>
+       public class XmlSchemaAttributeGroup : XmlSchemaAnnotated
+       {
+               private XmlSchemaAnyAttribute anyAttribute;
+               private XmlSchemaObjectCollection attributes;
+               private string name;
+               private XmlSchemaAttributeGroup redefined;
+               private XmlQualifiedName qualifiedName;
+               const string xmlname = "attributeGroup";
+               private XmlSchemaObjectTable attributeUses;
+               private XmlSchemaAnyAttribute anyAttributeUse;
+
+               internal bool AttributeGroupRecursionCheck;
+
+               public XmlSchemaAttributeGroup()
+               {
+                       attributes  = new XmlSchemaObjectCollection();
+                       qualifiedName = XmlQualifiedName.Empty;
+               }
+
+               [System.Xml.Serialization.XmlAttribute("name")]
+               public string Name 
+               {
+                       get{ return name;}
+                       set{ name = value;}
+               }
+
+               [XmlElement("attribute",typeof(XmlSchemaAttribute))]
+               [XmlElement("attributeGroup",typeof(XmlSchemaAttributeGroupRef))]
+               public XmlSchemaObjectCollection Attributes 
+               {
+                       get{ return attributes;}
+               }
+
+               internal XmlSchemaObjectTable AttributeUses
+               {
+                       get { return attributeUses; }
+               }
+               internal XmlSchemaAnyAttribute AnyAttributeUse
+               {
+                       get { return anyAttributeUse; }
+               }
+
+               [XmlElement("anyAttribute")]
+               public XmlSchemaAnyAttribute AnyAttribute 
+               {
+                       get{ return anyAttribute;}
+                       set{ anyAttribute = value;}
+               }
+
+               //Undocumented property
+               [XmlIgnore]
+               public XmlSchemaAttributeGroup RedefinedAttributeGroup 
+               {
+                       get{ return redefined;}
+               }
+
+               [XmlIgnore]
+#if NET_2_0
+               public XmlQualifiedName QualifiedName 
+#else
+               internal XmlQualifiedName QualifiedName 
+#endif
+               {
+                       get{ return qualifiedName;}
+               }
+
+               internal override void SetParent (XmlSchemaObject parent)
+               {
+                       base.SetParent (parent);
+                       if (this.AnyAttribute != null)
+                               this.AnyAttribute.SetParent (this);
+                       foreach (XmlSchemaObject obj in Attributes)
+                               obj.SetParent (this);
+               }
+
+               /// <remarks>
+               /// An Attribute group can only be defined as a child of XmlSchema or in XmlSchemaRedefine.
+               /// The other attributeGroup has type XmlSchemaAttributeGroupRef.
+               ///  1. Name must be present
+               /// </remarks>
+               internal override int Compile(ValidationEventHandler h, XmlSchema schema)
+               {
+                       // If this is already compiled this time, simply skip.
+                       if (CompilationId == schema.CompilationId)
+                               return errorCount;
+
+                       errorCount = 0;
+
+                       if (redefinedObject != null) {
+                               errorCount += redefined.Compile (h, schema);
+                               if (errorCount == 0)
+                                       redefined = (XmlSchemaAttributeGroup) redefinedObject;
+                       }
+
+                       XmlSchemaUtil.CompileID(Id,this, schema.IDCollection,h);
+
+                       if(this.Name == null || this.Name == String.Empty) //1
+                               error(h,"Name is required in top level simpletype");
+                       else if(!XmlSchemaUtil.CheckNCName(this.Name)) // b.1.2
+                               error(h,"name attribute of a simpleType must be NCName");
+                       else
+                               this.qualifiedName = new XmlQualifiedName(this.Name, AncestorSchema.TargetNamespace);
+                       
+                       if(this.AnyAttribute != null)
+                       {
+                               errorCount += this.AnyAttribute.Compile(h, schema);
+                       }
+                       
+                       foreach(XmlSchemaObject obj in Attributes)
+                       {
+                               if(obj is XmlSchemaAttribute)
+                               {
+                                       XmlSchemaAttribute attr = (XmlSchemaAttribute) obj;
+                                       errorCount += attr.Compile(h, schema);
+                               }
+                               else if(obj is XmlSchemaAttributeGroupRef)
+                               {
+                                       XmlSchemaAttributeGroupRef gref = (XmlSchemaAttributeGroupRef) obj;
+                                       errorCount += gref.Compile(h, schema);
+                               }
+                               else
+                               {
+                                       error(h,"invalid type of object in Attributes property");
+                               }
+                       }
+                       this.CompilationId = schema.CompilationId;
+                       return errorCount;
+               }
+
+               internal override int Validate(ValidationEventHandler h, XmlSchema schema)
+               {
+                       if (IsValidated (schema.CompilationId))
+                               return errorCount;
+
+                       if (redefined == null && redefinedObject != null) {
+                               redefinedObject.Compile (h, schema);
+                               redefined = (XmlSchemaAttributeGroup) redefinedObject;
+                               redefined.Validate (h, schema);
+                       }
+
+                       XmlSchemaObjectCollection actualAttributes = null;
+                       /*
+                       if (this.redefined != null) {
+                               actualAttributes = new XmlSchemaObjectCollection ();
+                               foreach (XmlSchemaObject obj in Attributes) {
+                                       XmlSchemaAttributeGroupRef grp = obj as XmlSchemaAttributeGroupRef;
+                                       if (grp != null && grp.QualifiedName == this.QualifiedName)
+                                               actualAttributes.Add (redefined);
+                                       else
+                                               actualAttributes.Add (obj);
+                               }
+                       }
+                       else
+                       */
+                               actualAttributes = Attributes;
+
+                       attributeUses = new XmlSchemaObjectTable ();
+                       errorCount += XmlSchemaUtil.ValidateAttributesResolved (attributeUses,
+                               h, schema, actualAttributes, AnyAttribute, 
+                               ref anyAttributeUse, redefined, false);
+                       ValidationId = schema.ValidationId;
+                       return errorCount;
+               }
+
+               //<attributeGroup
+               //  id = ID
+               //  name = NCName
+               //  ref = QName // Not present in this class.
+               //  {any attributes with non-schema namespace . . .}>
+               //  Content: (annotation?, ((attribute | attributeGroup)*, anyAttribute?))
+               //</attributeGroup>
+               internal static XmlSchemaAttributeGroup Read(XmlSchemaReader reader, ValidationEventHandler h)
+               {
+                       XmlSchemaAttributeGroup attrgrp = new XmlSchemaAttributeGroup();
+                       reader.MoveToElement();
+
+                       if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
+                       {
+                               error(h,"Should not happen :1: XmlSchemaAttributeGroup.Read, name="+reader.Name,null);
+                               reader.SkipToEnd();
+                               return null;
+                       }
+
+                       attrgrp.LineNumber = reader.LineNumber;
+                       attrgrp.LinePosition = reader.LinePosition;
+                       attrgrp.SourceUri = reader.BaseURI;
+
+                       while(reader.MoveToNextAttribute())
+                       {
+                               if(reader.Name == "id")
+                               {
+                                       attrgrp.Id = reader.Value;
+                               }
+                               else if(reader.Name == "name")
+                               {
+                                       attrgrp.name = reader.Value;
+                               }
+                               else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
+                               {
+                                       error(h,reader.Name + " is not a valid attribute for attributeGroup in this context",null);
+                               }
+                               else
+                               {
+                                       XmlSchemaUtil.ReadUnhandledAttribute(reader,attrgrp);
+                               }
+                       }
+                       
+                       reader.MoveToElement();
+                       if(reader.IsEmptyElement)
+                               return attrgrp;
+
+                       //Content: 1.annotation?, 2.(attribute | attributeGroup)*, 3.anyAttribute?
+                       int level = 1;
+                       while(reader.ReadNextElement())
+                       {
+                               if(reader.NodeType == XmlNodeType.EndElement)
+                               {
+                                       if(reader.LocalName != xmlname)
+                                               error(h,"Should not happen :2: XmlSchemaAttributeGroup.Read, name="+reader.Name,null);
+                                       break;
+                               }
+                               if(level <= 1 && reader.LocalName == "annotation")
+                               {
+                                       level = 2; //Only one annotation
+                                       XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
+                                       if(annotation != null)
+                                               attrgrp.Annotation = annotation;
+                                       continue;
+                               }
+                               if(level <= 2)
+                               {
+                                       if(reader.LocalName == "attribute")
+                                       {
+                                               level = 2;
+                                               XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader,h);
+                                               if(attr != null)
+                                                       attrgrp.Attributes.Add(attr);
+                                               continue;
+                                       }
+                                       if(reader.LocalName == "attributeGroup")
+                                       {
+                                               level = 2;
+                                               XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader,h);
+                                               if(attr != null)
+                                                       attrgrp.attributes.Add(attr);
+                                               continue;
+                                       }
+                               }
+                               if(level <= 3 && reader.LocalName == "anyAttribute")
+                               {
+                                       level = 4;
+                                       XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader,h);
+                                       if(anyattr != null)
+                                               attrgrp.AnyAttribute = anyattr;
+                                       continue;
+                               }
+                               reader.RaiseInvalidElementError();
+                       }
+                       return attrgrp;
+               }
+               
+       }
+}