(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.XML / System.Xml.Schema / XmlSchemaAttributeGroup.cs
blobc7e011a398dbec9d7e3485ae492c1c048ddeca5a
1 //
2 // System.Xml.Schema.XmlSchemaAttributeGroup.cs
3 //
4 // Authors:
5 // Dwivedi, Ajay kumar Adwiv@Yahoo.com
6 // Enomoto, Atsushi ginga@kit.hi-ho.ne.jp
7 //
9 //
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:
17 //
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 //
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.
29 using System;
30 using System.Collections;
31 using System.Xml.Serialization;
32 using System.Xml;
34 namespace System.Xml.Schema
36 /// <summary>
37 /// Summary description for XmlSchemaAttributeGroup.
38 /// </summary>
39 public class XmlSchemaAttributeGroup : XmlSchemaAnnotated
41 private XmlSchemaAnyAttribute anyAttribute;
42 private XmlSchemaObjectCollection attributes;
43 private string name;
44 private XmlSchemaAttributeGroup redefined;
45 private XmlQualifiedName qualifiedName;
46 const string xmlname = "attributeGroup";
47 private XmlSchemaObjectTable attributeUses;
48 private XmlSchemaAnyAttribute anyAttributeUse;
50 internal bool AttributeGroupRecursionCheck;
52 public XmlSchemaAttributeGroup()
54 attributes = new XmlSchemaObjectCollection();
55 qualifiedName = XmlQualifiedName.Empty;
58 [System.Xml.Serialization.XmlAttribute("name")]
59 public string Name
61 get{ return name;}
62 set{ name = value;}
65 [XmlElement("attribute",typeof(XmlSchemaAttribute),Namespace=XmlSchema.Namespace)]
66 [XmlElement("attributeGroup",typeof(XmlSchemaAttributeGroupRef),Namespace=XmlSchema.Namespace)]
67 public XmlSchemaObjectCollection Attributes
69 get{ return attributes;}
72 internal XmlSchemaObjectTable AttributeUses
74 get { return attributeUses; }
76 internal XmlSchemaAnyAttribute AnyAttributeUse
78 get { return anyAttributeUse; }
81 [XmlElement("anyAttribute",Namespace=XmlSchema.Namespace)]
82 public XmlSchemaAnyAttribute AnyAttribute
84 get{ return anyAttribute;}
85 set{ anyAttribute = value;}
88 //Undocumented property
89 [XmlIgnore]
90 public XmlSchemaAttributeGroup RedefinedAttributeGroup
92 get{ return redefined;}
95 [XmlIgnore]
96 #if NET_2_0
97 public XmlQualifiedName QualifiedName
98 #else
99 internal XmlQualifiedName QualifiedName
100 #endif
102 get{ return qualifiedName;}
105 /// <remarks>
106 /// An Attribute group can only be defined as a child of XmlSchema or in XmlSchemaRedefine.
107 /// The other attributeGroup has type XmlSchemaAttributeGroupRef.
108 /// 1. Name must be present
109 /// </remarks>
110 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
112 // If this is already compiled this time, simply skip.
113 if (this.IsComplied (schema.CompilationId))
114 return errorCount;
116 errorCount = 0;
118 if (redefinedObject != null) {
119 errorCount += redefined.Compile (h, schema);
120 if (errorCount == 0)
121 redefined = (XmlSchemaAttributeGroup) redefinedObject;
124 XmlSchemaUtil.CompileID(Id,this, schema.IDCollection,h);
126 if(this.Name == null || this.Name == String.Empty) //1
127 error(h,"Name is required in top level simpletype");
128 else if(!XmlSchemaUtil.CheckNCName(this.Name)) // b.1.2
129 error(h,"name attribute of a simpleType must be NCName");
130 else
131 this.qualifiedName = new XmlQualifiedName(this.Name, schema.TargetNamespace);
133 if(this.AnyAttribute != null)
135 errorCount += this.AnyAttribute.Compile(h, schema);
138 foreach(XmlSchemaObject obj in Attributes)
140 if(obj is XmlSchemaAttribute)
142 XmlSchemaAttribute attr = (XmlSchemaAttribute) obj;
143 errorCount += attr.Compile(h, schema);
145 else if(obj is XmlSchemaAttributeGroupRef)
147 XmlSchemaAttributeGroupRef gref = (XmlSchemaAttributeGroupRef) obj;
148 errorCount += gref.Compile(h, schema);
150 else
152 error(h,"invalid type of object in Attributes property");
155 this.CompilationId = schema.CompilationId;
156 return errorCount;
159 internal override int Validate(ValidationEventHandler h, XmlSchema schema)
161 if (IsValidated (schema.CompilationId))
162 return errorCount;
164 if (redefined == null && redefinedObject != null) {
165 redefinedObject.Compile (h, schema);
166 redefined = (XmlSchemaAttributeGroup) redefinedObject;
167 redefined.Validate (h, schema);
170 XmlSchemaObjectCollection actualAttributes = null;
172 if (this.redefined != null) {
173 actualAttributes = new XmlSchemaObjectCollection ();
174 foreach (XmlSchemaObject obj in Attributes) {
175 XmlSchemaAttributeGroupRef grp = obj as XmlSchemaAttributeGroupRef;
176 if (grp != null && grp.QualifiedName == this.QualifiedName)
177 actualAttributes.Add (redefined);
178 else
179 actualAttributes.Add (obj);
182 else
184 actualAttributes = Attributes;
186 attributeUses = new XmlSchemaObjectTable ();
187 errorCount += XmlSchemaUtil.ValidateAttributesResolved (attributeUses,
188 h, schema, actualAttributes, AnyAttribute,
189 ref anyAttributeUse, redefined);
190 ValidationId = schema.ValidationId;
191 return errorCount;
194 //<attributeGroup
195 // id = ID
196 // name = NCName
197 // ref = QName // Not present in this class.
198 // {any attributes with non-schema namespace . . .}>
199 // Content: (annotation?, ((attribute | attributeGroup)*, anyAttribute?))
200 //</attributeGroup>
201 internal static XmlSchemaAttributeGroup Read(XmlSchemaReader reader, ValidationEventHandler h)
203 XmlSchemaAttributeGroup attrgrp = new XmlSchemaAttributeGroup();
204 reader.MoveToElement();
206 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
208 error(h,"Should not happen :1: XmlSchemaAttributeGroup.Read, name="+reader.Name,null);
209 reader.SkipToEnd();
210 return null;
213 attrgrp.LineNumber = reader.LineNumber;
214 attrgrp.LinePosition = reader.LinePosition;
215 attrgrp.SourceUri = reader.BaseURI;
217 while(reader.MoveToNextAttribute())
219 if(reader.Name == "id")
221 attrgrp.Id = reader.Value;
223 else if(reader.Name == "name")
225 attrgrp.name = reader.Value;
227 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
229 error(h,reader.Name + " is not a valid attribute for attributeGroup in this context",null);
231 else
233 XmlSchemaUtil.ReadUnhandledAttribute(reader,attrgrp);
237 reader.MoveToElement();
238 if(reader.IsEmptyElement)
239 return attrgrp;
241 //Content: 1.annotation?, 2.(attribute | attributeGroup)*, 3.anyAttribute?
242 int level = 1;
243 while(reader.ReadNextElement())
245 if(reader.NodeType == XmlNodeType.EndElement)
247 if(reader.LocalName != xmlname)
248 error(h,"Should not happen :2: XmlSchemaAttributeGroup.Read, name="+reader.Name,null);
249 break;
251 if(level <= 1 && reader.LocalName == "annotation")
253 level = 2; //Only one annotation
254 XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
255 if(annotation != null)
256 attrgrp.Annotation = annotation;
257 continue;
259 if(level <= 2)
261 if(reader.LocalName == "attribute")
263 level = 2;
264 XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader,h);
265 if(attr != null)
266 attrgrp.Attributes.Add(attr);
267 continue;
269 if(reader.LocalName == "attributeGroup")
271 level = 2;
272 XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader,h);
273 if(attr != null)
274 attrgrp.attributes.Add(attr);
275 continue;
278 if(level <= 3 && reader.LocalName == "anyAttribute")
280 level = 4;
281 XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader,h);
282 if(anyattr != null)
283 attrgrp.AnyAttribute = anyattr;
284 continue;
286 reader.RaiseInvalidElementError();
288 return attrgrp;