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
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System.Collections;
\r
31 using System.Xml.Serialization;
\r
34 namespace System.Xml.Schema
\r
37 /// Summary description for XmlSchemaAttributeGroup.
\r
39 public class XmlSchemaAttributeGroup : XmlSchemaAnnotated
\r
41 private XmlSchemaAnyAttribute anyAttribute;
\r
42 private XmlSchemaObjectCollection attributes;
\r
43 private string name;
\r
44 private XmlSchemaAttributeGroup redefined;
\r
45 private XmlQualifiedName qualifiedName;
\r
46 const string xmlname = "attributeGroup";
\r
47 private XmlSchemaObjectTable attributeUses;
\r
48 private XmlSchemaAnyAttribute anyAttributeUse;
\r
50 internal bool AttributeGroupRecursionCheck;
\r
52 public XmlSchemaAttributeGroup()
\r
54 attributes = new XmlSchemaObjectCollection();
\r
57 [System.Xml.Serialization.XmlAttribute("name")]
\r
64 [XmlElement("attribute",typeof(XmlSchemaAttribute),Namespace=XmlSchema.Namespace)]
\r
65 [XmlElement("attributeGroup",typeof(XmlSchemaAttributeGroupRef),Namespace=XmlSchema.Namespace)]
\r
66 public XmlSchemaObjectCollection Attributes
\r
68 get{ return attributes;}
\r
71 internal XmlSchemaObjectTable AttributeUses
\r
73 get { return attributeUses; }
\r
75 internal XmlSchemaAnyAttribute AnyAttributeUse
\r
77 get { return anyAttributeUse; }
\r
80 [XmlElement("anyAttribute",Namespace=XmlSchema.Namespace)]
\r
81 public XmlSchemaAnyAttribute AnyAttribute
\r
83 get{ return anyAttribute;}
\r
84 set{ anyAttribute = value;}
\r
87 //Undocumented property
\r
89 public XmlSchemaAttributeGroup RedefinedAttributeGroup
\r
91 get{ return redefined;}
\r
95 internal XmlQualifiedName QualifiedName
\r
97 get{ return qualifiedName;}
\r
101 /// An Attribute group can only be defined as a child of XmlSchema or in XmlSchemaRedefine.
\r
102 /// The other attributeGroup has type XmlSchemaAttributeGroupRef.
\r
103 /// 1. Name must be present
\r
105 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
\r
107 // If this is already compiled this time, simply skip.
\r
108 if (this.IsComplied (schema.CompilationId))
\r
113 if (redefinedObject != null) {
\r
114 errorCount += redefined.Compile (h, schema);
\r
115 if (errorCount == 0)
\r
116 redefined = (XmlSchemaAttributeGroup) redefinedObject;
\r
119 XmlSchemaUtil.CompileID(Id,this, schema.IDCollection,h);
\r
121 if(this.Name == null || this.Name == String.Empty) //1
\r
122 error(h,"Name is required in top level simpletype");
\r
123 else if(!XmlSchemaUtil.CheckNCName(this.Name)) // b.1.2
\r
124 error(h,"name attribute of a simpleType must be NCName");
\r
126 this.qualifiedName = new XmlQualifiedName(this.Name, schema.TargetNamespace);
\r
128 if(this.AnyAttribute != null)
\r
130 errorCount += this.AnyAttribute.Compile(h, schema);
\r
133 foreach(XmlSchemaObject obj in Attributes)
\r
135 if(obj is XmlSchemaAttribute)
\r
137 XmlSchemaAttribute attr = (XmlSchemaAttribute) obj;
\r
138 errorCount += attr.Compile(h, schema);
\r
140 else if(obj is XmlSchemaAttributeGroupRef)
\r
142 XmlSchemaAttributeGroupRef gref = (XmlSchemaAttributeGroupRef) obj;
\r
143 errorCount += gref.Compile(h, schema);
\r
147 error(h,"invalid type of object in Attributes property");
\r
150 this.CompilationId = schema.CompilationId;
\r
154 internal override int Validate(ValidationEventHandler h, XmlSchema schema)
\r
156 if (IsValidated (schema.CompilationId))
\r
159 if (redefined == null && redefinedObject != null) {
\r
160 redefinedObject.Compile (h, schema);
\r
161 redefined = (XmlSchemaAttributeGroup) redefinedObject;
\r
162 redefined.Validate (h, schema);
\r
165 XmlSchemaObjectCollection actualAttributes = null;
\r
167 if (this.redefined != null) {
\r
168 actualAttributes = new XmlSchemaObjectCollection ();
\r
169 foreach (XmlSchemaObject obj in Attributes) {
\r
170 XmlSchemaAttributeGroupRef grp = obj as XmlSchemaAttributeGroupRef;
\r
171 if (grp != null && grp.QualifiedName == this.QualifiedName)
\r
172 actualAttributes.Add (redefined);
\r
174 actualAttributes.Add (obj);
\r
179 actualAttributes = Attributes;
\r
181 attributeUses = new XmlSchemaObjectTable ();
\r
182 errorCount += XmlSchemaUtil.ValidateAttributesResolved (attributeUses,
\r
183 h, schema, actualAttributes, AnyAttribute,
\r
184 ref anyAttributeUse, redefined);
\r
185 ValidationId = schema.ValidationId;
\r
192 // ref = QName // Not present in this class.
\r
193 // {any attributes with non-schema namespace . . .}>
\r
194 // Content: (annotation?, ((attribute | attributeGroup)*, anyAttribute?))
\r
195 //</attributeGroup>
\r
196 internal static XmlSchemaAttributeGroup Read(XmlSchemaReader reader, ValidationEventHandler h)
\r
198 XmlSchemaAttributeGroup attrgrp = new XmlSchemaAttributeGroup();
\r
199 reader.MoveToElement();
\r
201 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
\r
203 error(h,"Should not happen :1: XmlSchemaAttributeGroup.Read, name="+reader.Name,null);
\r
204 reader.SkipToEnd();
\r
208 attrgrp.LineNumber = reader.LineNumber;
\r
209 attrgrp.LinePosition = reader.LinePosition;
\r
210 attrgrp.SourceUri = reader.BaseURI;
\r
212 while(reader.MoveToNextAttribute())
\r
214 if(reader.Name == "id")
\r
216 attrgrp.Id = reader.Value;
\r
218 else if(reader.Name == "name")
\r
220 attrgrp.name = reader.Value;
\r
222 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
\r
224 error(h,reader.Name + " is not a valid attribute for attributeGroup in this context",null);
\r
228 XmlSchemaUtil.ReadUnhandledAttribute(reader,attrgrp);
\r
232 reader.MoveToElement();
\r
233 if(reader.IsEmptyElement)
\r
236 //Content: 1.annotation?, 2.(attribute | attributeGroup)*, 3.anyAttribute?
\r
238 while(reader.ReadNextElement())
\r
240 if(reader.NodeType == XmlNodeType.EndElement)
\r
242 if(reader.LocalName != xmlname)
\r
243 error(h,"Should not happen :2: XmlSchemaAttributeGroup.Read, name="+reader.Name,null);
\r
246 if(level <= 1 && reader.LocalName == "annotation")
\r
248 level = 2; //Only one annotation
\r
249 XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
\r
250 if(annotation != null)
\r
251 attrgrp.Annotation = annotation;
\r
256 if(reader.LocalName == "attribute")
\r
259 XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader,h);
\r
261 attrgrp.Attributes.Add(attr);
\r
264 if(reader.LocalName == "attributeGroup")
\r
267 XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader,h);
\r
269 attrgrp.attributes.Add(attr);
\r
273 if(level <= 3 && reader.LocalName == "anyAttribute")
\r
276 XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader,h);
\r
277 if(anyattr != null)
\r
278 attrgrp.AnyAttribute = anyattr;
\r
281 reader.RaiseInvalidElementError();
\r