2 // System.Xml.Schema.XmlSchemaComplexContentExtension.cs
5 // Dwivedi, Ajay kumar Adwiv@Yahoo.com
6 // Atsushi Enomoto ginga@kit.hi-ho.ne.jp
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.
31 using System.Xml.Serialization;
33 namespace System.Xml.Schema
36 /// Summary description for XmlSchemaComplexContentExtension.
38 public class XmlSchemaComplexContentExtension : XmlSchemaContent
40 private XmlSchemaAnyAttribute any;
41 private XmlSchemaObjectCollection attributes;
42 private XmlQualifiedName baseTypeName;
43 private XmlSchemaParticle particle;
44 const string xmlname = "extension";
46 public XmlSchemaComplexContentExtension()
48 attributes = new XmlSchemaObjectCollection();
49 baseTypeName = XmlQualifiedName.Empty;
52 [System.Xml.Serialization.XmlAttribute("base")]
53 public XmlQualifiedName BaseTypeName
55 get{ return baseTypeName; }
56 set{ baseTypeName = value; }
59 [XmlElement("group",typeof(XmlSchemaGroupRef))]
60 [XmlElement("all",typeof(XmlSchemaAll))]
61 [XmlElement("choice",typeof(XmlSchemaChoice))]
62 [XmlElement("sequence",typeof(XmlSchemaSequence))]
63 public XmlSchemaParticle Particle
65 get{ return particle; }
66 set{ particle = value; }
69 [XmlElement("attribute",typeof(XmlSchemaAttribute))]
70 [XmlElement("attributeGroup",typeof(XmlSchemaAttributeGroupRef))]
71 public XmlSchemaObjectCollection Attributes
73 get{ return attributes; }
76 [XmlElement("anyAttribute")]
77 public XmlSchemaAnyAttribute AnyAttribute
83 // internal properties
84 internal override bool IsExtension {
88 internal override void SetParent (XmlSchemaObject parent)
90 base.SetParent (parent);
92 Particle.SetParent (this);
93 if (AnyAttribute != null)
94 AnyAttribute.SetParent (this);
95 foreach (XmlSchemaObject obj in Attributes)
101 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
103 // If this is already compiled this time, simply skip.
104 if (CompilationId == schema.CompilationId)
107 if (this.isRedefinedComponent) {
108 if (Annotation != null)
109 Annotation.isRedefinedComponent = true;
110 if (AnyAttribute != null)
111 AnyAttribute.isRedefinedComponent = true;
112 foreach (XmlSchemaObject obj in Attributes)
113 obj.isRedefinedComponent = true;
114 if (Particle != null)
115 Particle.isRedefinedComponent = true;
118 if(BaseTypeName == null || BaseTypeName.IsEmpty)
120 error(h, "base must be present, as a QName");
122 else if(!XmlSchemaUtil.CheckQName(BaseTypeName))
123 error(h,"BaseTypeName is not a valid XmlQualifiedName");
125 if(this.AnyAttribute != null)
127 errorCount += AnyAttribute.Compile(h, schema);
130 foreach(XmlSchemaObject obj in Attributes)
132 if(obj is XmlSchemaAttribute)
134 XmlSchemaAttribute attr = (XmlSchemaAttribute) obj;
135 errorCount += attr.Compile(h, schema);
137 else if(obj is XmlSchemaAttributeGroupRef)
139 XmlSchemaAttributeGroupRef atgrp = (XmlSchemaAttributeGroupRef) obj;
140 errorCount += atgrp.Compile(h, schema);
143 error(h,obj.GetType() +" is not valid in this place::ComplexConetnetExtension");
148 if(Particle is XmlSchemaGroupRef)
150 errorCount += ((XmlSchemaGroupRef)Particle).Compile(h, schema);
152 else if(Particle is XmlSchemaAll)
154 errorCount += ((XmlSchemaAll)Particle).Compile(h, schema);
156 else if(Particle is XmlSchemaChoice)
158 errorCount += ((XmlSchemaChoice)Particle).Compile(h, schema);
160 else if(Particle is XmlSchemaSequence)
162 errorCount += ((XmlSchemaSequence)Particle).Compile(h, schema);
165 error (h, "Particle of a restriction is limited only to group, sequence, choice and all.");
168 XmlSchemaUtil.CompileID(Id,this, schema.IDCollection,h);
170 this.CompilationId = schema.CompilationId;
174 internal override XmlQualifiedName GetBaseTypeName ()
179 internal override XmlSchemaParticle GetParticle ()
184 internal override int Validate(ValidationEventHandler h, XmlSchema schema)
186 if (IsValidated (schema.ValidationId))
189 if (AnyAttribute != null)
190 errorCount += AnyAttribute.Validate (h, schema);
191 foreach (XmlSchemaObject attrObj in Attributes)
192 errorCount += attrObj.Validate (h, schema);
193 if (Particle != null)
194 errorCount += Particle.Validate (h, schema);
196 ValidationId = schema.ValidationId;
202 // {any attributes with non-schema namespace . . .}>
203 // Content: (annotation?, ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?)))
205 internal static XmlSchemaComplexContentExtension Read(XmlSchemaReader reader, ValidationEventHandler h)
207 XmlSchemaComplexContentExtension extension = new XmlSchemaComplexContentExtension();
208 reader.MoveToElement();
210 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
212 error(h,"Should not happen :1: XmlSchemaComplexContentExtension.Read, name="+reader.Name,null);
217 extension.LineNumber = reader.LineNumber;
218 extension.LinePosition = reader.LinePosition;
219 extension.SourceUri = reader.BaseURI;
221 while(reader.MoveToNextAttribute())
223 if(reader.Name == "base")
226 extension.baseTypeName = XmlSchemaUtil.ReadQNameAttribute(reader,out innerex);
228 error(h, reader.Value + " is not a valid value for base attribute",innerex);
230 else if(reader.Name == "id")
232 extension.Id = reader.Value;
234 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
236 error(h,reader.Name + " is not a valid attribute for extension",null);
240 XmlSchemaUtil.ReadUnhandledAttribute(reader,extension);
244 reader.MoveToElement();
245 if(reader.IsEmptyElement)
247 //Content: 1. annotation?,
248 // (2.(group | all | choice | sequence)?, (3.(attribute | attributeGroup)*, 4.anyAttribute?)))
250 while(reader.ReadNextElement())
252 if(reader.NodeType == XmlNodeType.EndElement)
254 if(reader.LocalName != xmlname)
255 error(h,"Should not happen :2: XmlSchemaComplexContentExtension.Read, name="+reader.Name,null);
258 if(level <= 1 && reader.LocalName == "annotation")
260 level = 2; //Only one annotation
261 XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
262 if(annotation != null)
263 extension.Annotation = annotation;
268 if(reader.LocalName == "group")
271 XmlSchemaGroupRef group = XmlSchemaGroupRef.Read(reader,h);
273 extension.particle = group;
276 if(reader.LocalName == "all")
279 XmlSchemaAll all = XmlSchemaAll.Read(reader,h);
281 extension.particle = all;
284 if(reader.LocalName == "choice")
287 XmlSchemaChoice choice = XmlSchemaChoice.Read(reader,h);
289 extension.particle = choice;
292 if(reader.LocalName == "sequence")
295 XmlSchemaSequence sequence = XmlSchemaSequence.Read(reader,h);
297 extension.particle = sequence;
303 if(reader.LocalName == "attribute")
306 XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader,h);
308 extension.Attributes.Add(attr);
311 if(reader.LocalName == "attributeGroup")
314 XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader,h);
316 extension.attributes.Add(attr);
320 if(level <= 4 && reader.LocalName == "anyAttribute")
323 XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader,h);
325 extension.AnyAttribute = anyattr;
328 reader.RaiseInvalidElementError();