2 // System.Xml.Schema.XmlSchemaComplexContentExtension.cs
\r
5 // Dwivedi, Ajay kumar Adwiv@Yahoo.com
\r
6 // Atsushi Enomoto ginga@kit.hi-ho.ne.jp
\r
10 using System.Xml.Serialization;
\r
12 namespace System.Xml.Schema
\r
15 /// Summary description for XmlSchemaComplexContentExtension.
\r
17 public class XmlSchemaComplexContentExtension : XmlSchemaContent
\r
19 private XmlSchemaAnyAttribute any;
\r
20 private XmlSchemaObjectCollection attributes;
\r
21 private XmlQualifiedName baseTypeName;
\r
22 private XmlSchemaParticle particle;
\r
23 const string xmlname = "extension";
\r
25 public XmlSchemaComplexContentExtension()
\r
27 attributes = new XmlSchemaObjectCollection();
\r
28 baseTypeName = XmlQualifiedName.Empty;
\r
31 [System.Xml.Serialization.XmlAttribute("base")]
\r
32 public XmlQualifiedName BaseTypeName
\r
34 get{ return baseTypeName; }
\r
35 set{ baseTypeName = value; }
\r
38 [XmlElement("group",typeof(XmlSchemaGroupRef),Namespace=XmlSchema.Namespace)]
\r
39 [XmlElement("all",typeof(XmlSchemaAll),Namespace=XmlSchema.Namespace)]
\r
40 [XmlElement("choice",typeof(XmlSchemaChoice),Namespace=XmlSchema.Namespace)]
\r
41 [XmlElement("sequence",typeof(XmlSchemaSequence),Namespace=XmlSchema.Namespace)]
\r
42 public XmlSchemaParticle Particle
\r
44 get{ return particle; }
\r
45 set{ particle = value; }
\r
48 [XmlElement("attribute",typeof(XmlSchemaAttribute),Namespace=XmlSchema.Namespace)]
\r
49 [XmlElement("attributeGroup",typeof(XmlSchemaAttributeGroupRef),Namespace=XmlSchema.Namespace)]
\r
50 public XmlSchemaObjectCollection Attributes
\r
52 get{ return attributes; }
\r
55 [XmlElement("anyAttribute",Namespace=XmlSchema.Namespace)]
\r
56 public XmlSchemaAnyAttribute AnyAttribute
\r
62 // internal properties
\r
63 internal override bool IsExtension {
\r
64 get { return true; }
\r
69 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
\r
71 // If this is already compiled this time, simply skip.
\r
72 if (this.IsComplied (schema.CompilationId))
\r
75 if (this.isRedefinedComponent) {
\r
76 if (Annotation != null)
\r
77 Annotation.isRedefinedComponent = true;
\r
78 if (AnyAttribute != null)
\r
79 AnyAttribute.isRedefinedComponent = true;
\r
80 foreach (XmlSchemaObject obj in Attributes)
\r
81 obj.isRedefinedComponent = true;
\r
82 if (Particle != null)
\r
83 Particle.isRedefinedComponent = true;
\r
86 if(BaseTypeName == null || BaseTypeName.IsEmpty)
\r
88 error(h, "base must be present, as a QName");
\r
90 else if(!XmlSchemaUtil.CheckQName(BaseTypeName))
\r
91 error(h,"BaseTypeName is not a valid XmlQualifiedName");
\r
93 if(this.AnyAttribute != null)
\r
95 errorCount += AnyAttribute.Compile(h, schema);
\r
98 foreach(XmlSchemaObject obj in Attributes)
\r
100 if(obj is XmlSchemaAttribute)
\r
102 XmlSchemaAttribute attr = (XmlSchemaAttribute) obj;
\r
103 errorCount += attr.Compile(h, schema);
\r
105 else if(obj is XmlSchemaAttributeGroupRef)
\r
107 XmlSchemaAttributeGroupRef atgrp = (XmlSchemaAttributeGroupRef) obj;
\r
108 errorCount += atgrp.Compile(h, schema);
\r
111 error(h,obj.GetType() +" is not valid in this place::ComplexConetnetExtension");
\r
114 if(Particle != null)
\r
116 if(Particle is XmlSchemaGroupRef)
\r
118 errorCount += ((XmlSchemaGroupRef)Particle).Compile(h, schema);
\r
120 else if(Particle is XmlSchemaAll)
\r
122 errorCount += ((XmlSchemaAll)Particle).Compile(h, schema);
\r
124 else if(Particle is XmlSchemaChoice)
\r
126 errorCount += ((XmlSchemaChoice)Particle).Compile(h, schema);
\r
128 else if(Particle is XmlSchemaSequence)
\r
130 errorCount += ((XmlSchemaSequence)Particle).Compile(h, schema);
\r
133 error (h, "Particle of a restriction is limited only to group, sequence, choice and all.");
\r
136 XmlSchemaUtil.CompileID(Id,this, schema.IDCollection,h);
\r
138 this.CompilationId = schema.CompilationId;
\r
142 internal override XmlQualifiedName GetBaseTypeName ()
\r
144 return baseTypeName;
\r
147 internal override XmlSchemaParticle GetParticle ()
\r
152 internal override int Validate(ValidationEventHandler h, XmlSchema schema)
\r
154 if (IsValidated (schema.ValidationId))
\r
157 if (AnyAttribute != null)
\r
158 errorCount += AnyAttribute.Validate (h, schema);
\r
159 foreach (XmlSchemaObject attrObj in Attributes)
\r
160 errorCount += attrObj.Validate (h, schema);
\r
161 if (Particle != null)
\r
162 errorCount += Particle.Validate (h, schema);
\r
164 ValidationId = schema.ValidationId;
\r
170 // {any attributes with non-schema namespace . . .}>
\r
171 // Content: (annotation?, ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?)))
\r
173 internal static XmlSchemaComplexContentExtension Read(XmlSchemaReader reader, ValidationEventHandler h)
\r
175 XmlSchemaComplexContentExtension extension = new XmlSchemaComplexContentExtension();
\r
176 reader.MoveToElement();
\r
178 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
\r
180 error(h,"Should not happen :1: XmlSchemaComplexContentExtension.Read, name="+reader.Name,null);
\r
185 extension.LineNumber = reader.LineNumber;
\r
186 extension.LinePosition = reader.LinePosition;
\r
187 extension.SourceUri = reader.BaseURI;
\r
189 while(reader.MoveToNextAttribute())
\r
191 if(reader.Name == "base")
\r
194 extension.baseTypeName = XmlSchemaUtil.ReadQNameAttribute(reader,out innerex);
\r
195 if(innerex != null)
\r
196 error(h, reader.Value + " is not a valid value for base attribute",innerex);
\r
198 else if(reader.Name == "id")
\r
200 extension.Id = reader.Value;
\r
202 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
\r
204 error(h,reader.Name + " is not a valid attribute for extension",null);
\r
208 XmlSchemaUtil.ReadUnhandledAttribute(reader,extension);
\r
212 reader.MoveToElement();
\r
213 if(reader.IsEmptyElement)
\r
215 //Content: 1. annotation?,
\r
216 // (2.(group | all | choice | sequence)?, (3.(attribute | attributeGroup)*, 4.anyAttribute?)))
\r
218 while(reader.ReadNextElement())
\r
220 if(reader.NodeType == XmlNodeType.EndElement)
\r
222 if(reader.LocalName != xmlname)
\r
223 error(h,"Should not happen :2: XmlSchemaComplexContentExtension.Read, name="+reader.Name,null);
\r
226 if(level <= 1 && reader.LocalName == "annotation")
\r
228 level = 2; //Only one annotation
\r
229 XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
\r
230 if(annotation != null)
\r
231 extension.Annotation = annotation;
\r
236 if(reader.LocalName == "group")
\r
239 XmlSchemaGroupRef group = XmlSchemaGroupRef.Read(reader,h);
\r
241 extension.particle = group;
\r
244 if(reader.LocalName == "all")
\r
247 XmlSchemaAll all = XmlSchemaAll.Read(reader,h);
\r
249 extension.particle = all;
\r
252 if(reader.LocalName == "choice")
\r
255 XmlSchemaChoice choice = XmlSchemaChoice.Read(reader,h);
\r
257 extension.particle = choice;
\r
260 if(reader.LocalName == "sequence")
\r
263 XmlSchemaSequence sequence = XmlSchemaSequence.Read(reader,h);
\r
264 if(sequence != null)
\r
265 extension.particle = sequence;
\r
271 if(reader.LocalName == "attribute")
\r
274 XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader,h);
\r
276 extension.Attributes.Add(attr);
\r
279 if(reader.LocalName == "attributeGroup")
\r
282 XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader,h);
\r
284 extension.attributes.Add(attr);
\r
288 if(level <= 4 && reader.LocalName == "anyAttribute")
\r
291 XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader,h);
\r
292 if(anyattr != null)
\r
293 extension.AnyAttribute = anyattr;
\r
296 reader.RaiseInvalidElementError();
\r