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 private static 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
65 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
\r
67 // If this is already compiled this time, simply skip.
\r
68 if (this.IsComplied (schema.CompilationId))
\r
71 if (this.isRedefinedComponent) {
\r
72 if (Annotation != null)
\r
73 Annotation.isRedefinedComponent = true;
\r
74 if (AnyAttribute != null)
\r
75 AnyAttribute.isRedefinedComponent = true;
\r
76 foreach (XmlSchemaObject obj in Attributes)
\r
77 obj.isRedefinedComponent = true;
\r
78 if (Particle != null)
\r
79 Particle.isRedefinedComponent = true;
\r
82 if(BaseTypeName == null || BaseTypeName.IsEmpty)
\r
84 error(h, "base must be present, as a QName");
\r
86 else if(!XmlSchemaUtil.CheckQName(BaseTypeName))
\r
87 error(h,"BaseTypeName is not a valid XmlQualifiedName");
\r
89 if(this.AnyAttribute != null)
\r
91 errorCount += AnyAttribute.Compile(h, schema);
\r
94 foreach(XmlSchemaObject obj in Attributes)
\r
96 if(obj is XmlSchemaAttribute)
\r
98 XmlSchemaAttribute attr = (XmlSchemaAttribute) obj;
\r
99 errorCount += attr.Compile(h, schema);
\r
101 else if(obj is XmlSchemaAttributeGroupRef)
\r
103 XmlSchemaAttributeGroupRef atgrp = (XmlSchemaAttributeGroupRef) obj;
\r
104 errorCount += atgrp.Compile(h, schema);
\r
107 error(h,obj.GetType() +" is not valid in this place::ComplexConetnetExtension");
\r
110 if(Particle != null)
\r
112 if(Particle is XmlSchemaGroupRef)
\r
114 errorCount += ((XmlSchemaGroupRef)Particle).Compile(h, schema);
\r
116 else if(Particle is XmlSchemaAll)
\r
118 errorCount += ((XmlSchemaAll)Particle).Compile(h, schema);
\r
120 else if(Particle is XmlSchemaChoice)
\r
122 errorCount += ((XmlSchemaChoice)Particle).Compile(h, schema);
\r
124 else if(Particle is XmlSchemaSequence)
\r
126 errorCount += ((XmlSchemaSequence)Particle).Compile(h, schema);
\r
129 error (h, "Particle of a restriction is limited only to group, sequence, choice and all.");
\r
132 XmlSchemaUtil.CompileID(Id,this, schema.IDCollection,h);
\r
134 this.CompilationId = schema.CompilationId;
\r
139 internal override int Validate(ValidationEventHandler h, XmlSchema schema)
\r
141 if (IsValidated (schema.ValidationId))
\r
144 if (AnyAttribute != null)
\r
145 errorCount += AnyAttribute.Validate (h, schema);
\r
146 foreach (XmlSchemaObject attrObj in Attributes)
\r
147 errorCount += attrObj.Validate (h, schema);
\r
148 if (Particle != null)
\r
149 errorCount += Particle.Validate (h, schema);
\r
151 ValidationId = schema.ValidationId;
\r
157 // {any attributes with non-schema namespace . . .}>
\r
158 // Content: (annotation?, ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?)))
\r
160 internal static XmlSchemaComplexContentExtension Read(XmlSchemaReader reader, ValidationEventHandler h)
\r
162 XmlSchemaComplexContentExtension extension = new XmlSchemaComplexContentExtension();
\r
163 reader.MoveToElement();
\r
165 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
\r
167 error(h,"Should not happen :1: XmlSchemaComplexContentExtension.Read, name="+reader.Name,null);
\r
172 extension.LineNumber = reader.LineNumber;
\r
173 extension.LinePosition = reader.LinePosition;
\r
174 extension.SourceUri = reader.BaseURI;
\r
176 while(reader.MoveToNextAttribute())
\r
178 if(reader.Name == "base")
\r
181 extension.baseTypeName = XmlSchemaUtil.ReadQNameAttribute(reader,out innerex);
\r
182 if(innerex != null)
\r
183 error(h, reader.Value + " is not a valid value for base attribute",innerex);
\r
185 else if(reader.Name == "id")
\r
187 extension.Id = reader.Value;
\r
189 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
\r
191 error(h,reader.Name + " is not a valid attribute for extension",null);
\r
195 XmlSchemaUtil.ReadUnhandledAttribute(reader,extension);
\r
199 reader.MoveToElement();
\r
200 if(reader.IsEmptyElement)
\r
202 //Content: 1. annotation?,
\r
203 // (2.(group | all | choice | sequence)?, (3.(attribute | attributeGroup)*, 4.anyAttribute?)))
\r
205 while(reader.ReadNextElement())
\r
207 if(reader.NodeType == XmlNodeType.EndElement)
\r
209 if(reader.LocalName != xmlname)
\r
210 error(h,"Should not happen :2: XmlSchemaComplexContentExtension.Read, name="+reader.Name,null);
\r
213 if(level <= 1 && reader.LocalName == "annotation")
\r
215 level = 2; //Only one annotation
\r
216 XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
\r
217 if(annotation != null)
\r
218 extension.Annotation = annotation;
\r
223 if(reader.LocalName == "group")
\r
226 XmlSchemaGroupRef group = XmlSchemaGroupRef.Read(reader,h);
\r
228 extension.particle = group;
\r
231 if(reader.LocalName == "all")
\r
234 XmlSchemaAll all = XmlSchemaAll.Read(reader,h);
\r
236 extension.particle = all;
\r
239 if(reader.LocalName == "choice")
\r
242 XmlSchemaChoice choice = XmlSchemaChoice.Read(reader,h);
\r
244 extension.particle = choice;
\r
247 if(reader.LocalName == "sequence")
\r
250 XmlSchemaSequence sequence = XmlSchemaSequence.Read(reader,h);
\r
251 if(sequence != null)
\r
252 extension.particle = sequence;
\r
258 if(reader.LocalName == "attribute")
\r
261 XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader,h);
\r
263 extension.Attributes.Add(attr);
\r
266 if(reader.LocalName == "attributeGroup")
\r
269 XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader,h);
\r
271 extension.attributes.Add(attr);
\r
275 if(level <= 4 && reader.LocalName == "anyAttribute")
\r
278 XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader,h);
\r
279 if(anyattr != null)
\r
280 extension.AnyAttribute = anyattr;
\r
283 reader.RaiseInvalidElementError();
\r