2 // System.Xml.Schema.XmlSchemaAttributeGroup.cs
\r
5 // Dwivedi, Ajay kumar Adwiv@Yahoo.com
\r
6 // Enomoto, Atsushi ginga@kit.hi-ho.ne.jp
\r
9 using System.Collections;
\r
10 using System.Xml.Serialization;
\r
13 namespace System.Xml.Schema
\r
16 /// Summary description for XmlSchemaAttributeGroup.
\r
18 public class XmlSchemaAttributeGroup : XmlSchemaAnnotated
\r
20 private XmlSchemaAnyAttribute anyAttribute;
\r
21 private XmlSchemaObjectCollection attributes;
\r
22 private string name;
\r
23 private XmlSchemaAttributeGroup redefined;
\r
24 private XmlQualifiedName qualifiedName;
\r
25 private static string xmlname = "attributeGroup";
\r
26 private XmlSchemaObjectTable attributeUses;
\r
27 private XmlSchemaAnyAttribute anyAttributeUse;
\r
29 internal bool AttributeGroupRecursionCheck;
\r
31 public XmlSchemaAttributeGroup()
\r
33 attributes = new XmlSchemaObjectCollection();
\r
36 [System.Xml.Serialization.XmlAttribute("name")]
\r
43 [XmlElement("attribute",typeof(XmlSchemaAttribute),Namespace=XmlSchema.Namespace)]
\r
44 [XmlElement("attributeGroup",typeof(XmlSchemaAttributeGroupRef),Namespace=XmlSchema.Namespace)]
\r
45 public XmlSchemaObjectCollection Attributes
\r
47 get{ return attributes;}
\r
50 internal XmlSchemaObjectTable AttributeUses
\r
52 get { return attributeUses; }
\r
54 internal XmlSchemaAnyAttribute AnyAttributeUse
\r
56 get { return anyAttributeUse; }
\r
59 [XmlElement("anyAttribute",Namespace=XmlSchema.Namespace)]
\r
60 public XmlSchemaAnyAttribute AnyAttribute
\r
62 get{ return anyAttribute;}
\r
63 set{ anyAttribute = value;}
\r
66 //Undocumented property
\r
68 public XmlSchemaAttributeGroup RedefinedAttributeGroup
\r
70 get{ return redefined;}
\r
74 internal XmlQualifiedName QualifiedName
\r
76 get{ return qualifiedName;}
\r
80 /// An Attribute group can only be defined as a child of XmlSchema or in XmlSchemaRedefine.
\r
81 /// The other attributeGroup has type XmlSchemaAttributeGroupRef.
\r
82 /// 1. Name must be present
\r
84 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
\r
86 // If this is already compiled this time, simply skip.
\r
87 if (this.IsComplied (schema.CompilationId))
\r
92 if (redefinedObject != null) {
\r
93 errorCount += redefined.Compile (h, schema);
\r
94 if (errorCount == 0)
\r
95 redefined = (XmlSchemaAttributeGroup) redefinedObject;
\r
98 XmlSchemaUtil.CompileID(Id,this, schema.IDCollection,h);
\r
100 if(this.Name == null || this.Name == String.Empty) //1
\r
101 error(h,"Name is required in top level simpletype");
\r
102 else if(!XmlSchemaUtil.CheckNCName(this.Name)) // b.1.2
\r
103 error(h,"name attribute of a simpleType must be NCName");
\r
105 this.qualifiedName = new XmlQualifiedName(this.Name, schema.TargetNamespace);
\r
107 if(this.AnyAttribute != null)
\r
109 errorCount += this.AnyAttribute.Compile(h, schema);
\r
112 foreach(XmlSchemaObject obj in Attributes)
\r
114 if(obj is XmlSchemaAttribute)
\r
116 XmlSchemaAttribute attr = (XmlSchemaAttribute) obj;
\r
117 errorCount += attr.Compile(h, schema);
\r
119 else if(obj is XmlSchemaAttributeGroupRef)
\r
121 XmlSchemaAttributeGroupRef gref = (XmlSchemaAttributeGroupRef) obj;
\r
122 errorCount += gref.Compile(h, schema);
\r
126 error(h,"invalid type of object in Attributes property");
\r
129 this.CompilationId = schema.CompilationId;
\r
133 internal override int Validate(ValidationEventHandler h, XmlSchema schema)
\r
135 if (IsValidated (schema.CompilationId))
\r
138 if (redefined == null && redefinedObject != null) {
\r
139 redefinedObject.Compile (h, schema);
\r
140 redefined = (XmlSchemaAttributeGroup) redefinedObject;
\r
141 redefined.Validate (h, schema);
\r
144 XmlSchemaObjectCollection actualAttributes = null;
\r
146 if (this.redefined != null) {
\r
147 actualAttributes = new XmlSchemaObjectCollection ();
\r
148 foreach (XmlSchemaObject obj in Attributes) {
\r
149 XmlSchemaAttributeGroupRef grp = obj as XmlSchemaAttributeGroupRef;
\r
150 if (grp != null && grp.QualifiedName == this.QualifiedName)
\r
151 actualAttributes.Add (redefined);
\r
153 actualAttributes.Add (obj);
\r
158 actualAttributes = Attributes;
\r
160 attributeUses = new XmlSchemaObjectTable ();
\r
161 errorCount += XmlSchemaUtil.ValidateAttributesResolved (attributeUses,
\r
162 h, schema, actualAttributes, AnyAttribute,
\r
163 ref anyAttributeUse, redefined);
\r
164 ValidationId = schema.ValidationId;
\r
171 // ref = QName // Not present in this class.
\r
172 // {any attributes with non-schema namespace . . .}>
\r
173 // Content: (annotation?, ((attribute | attributeGroup)*, anyAttribute?))
\r
174 //</attributeGroup>
\r
175 internal static XmlSchemaAttributeGroup Read(XmlSchemaReader reader, ValidationEventHandler h)
\r
177 XmlSchemaAttributeGroup attrgrp = new XmlSchemaAttributeGroup();
\r
178 reader.MoveToElement();
\r
180 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
\r
182 error(h,"Should not happen :1: XmlSchemaAttributeGroup.Read, name="+reader.Name,null);
\r
183 reader.SkipToEnd();
\r
187 attrgrp.LineNumber = reader.LineNumber;
\r
188 attrgrp.LinePosition = reader.LinePosition;
\r
189 attrgrp.SourceUri = reader.BaseURI;
\r
191 while(reader.MoveToNextAttribute())
\r
193 if(reader.Name == "id")
\r
195 attrgrp.Id = reader.Value;
\r
197 else if(reader.Name == "name")
\r
199 attrgrp.name = reader.Value;
\r
201 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
\r
203 error(h,reader.Name + " is not a valid attribute for attributeGroup in this context",null);
\r
207 XmlSchemaUtil.ReadUnhandledAttribute(reader,attrgrp);
\r
211 reader.MoveToElement();
\r
212 if(reader.IsEmptyElement)
\r
215 //Content: 1.annotation?, 2.(attribute | attributeGroup)*, 3.anyAttribute?
\r
217 while(reader.ReadNextElement())
\r
219 if(reader.NodeType == XmlNodeType.EndElement)
\r
221 if(reader.LocalName != xmlname)
\r
222 error(h,"Should not happen :2: XmlSchemaAttributeGroup.Read, name="+reader.Name,null);
\r
225 if(level <= 1 && reader.LocalName == "annotation")
\r
227 level = 2; //Only one annotation
\r
228 XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
\r
229 if(annotation != null)
\r
230 attrgrp.Annotation = annotation;
\r
235 if(reader.LocalName == "attribute")
\r
238 XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader,h);
\r
240 attrgrp.Attributes.Add(attr);
\r
243 if(reader.LocalName == "attributeGroup")
\r
246 XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader,h);
\r
248 attrgrp.attributes.Add(attr);
\r
252 if(level <= 3 && reader.LocalName == "anyAttribute")
\r
255 XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader,h);
\r
256 if(anyattr != null)
\r
257 attrgrp.AnyAttribute = anyattr;
\r
260 reader.RaiseInvalidElementError();
\r