1 // Author: Dwivedi, Ajay kumar
\r
5 using System.Xml.Serialization;
\r
7 namespace System.Xml.Schema
\r
10 /// Summary description for XmlSchemaComplexContentExtension.
\r
12 public class XmlSchemaComplexContentExtension : XmlSchemaContent
\r
14 private XmlSchemaAnyAttribute any;
\r
15 private XmlSchemaObjectCollection attributes;
\r
16 private XmlQualifiedName baseTypeName;
\r
17 private XmlSchemaParticle particle;
\r
18 private static string xmlname = "extension";
\r
20 public XmlSchemaComplexContentExtension()
\r
22 attributes = new XmlSchemaObjectCollection();
\r
23 baseTypeName = XmlQualifiedName.Empty;
\r
26 [System.Xml.Serialization.XmlAttribute("base")]
\r
27 public XmlQualifiedName BaseTypeName
\r
29 get{ return baseTypeName; }
\r
30 set{ baseTypeName = value; }
\r
33 [XmlElement("group",typeof(XmlSchemaGroupRef),Namespace="http://www.w3.org/2001/XMLSchema")]
\r
34 [XmlElement("all",typeof(XmlSchemaAll),Namespace="http://www.w3.org/2001/XMLSchema")]
\r
35 [XmlElement("choice",typeof(XmlSchemaChoice),Namespace="http://www.w3.org/2001/XMLSchema")]
\r
36 [XmlElement("sequence",typeof(XmlSchemaSequence),Namespace="http://www.w3.org/2001/XMLSchema")]
\r
37 public XmlSchemaParticle Particle
\r
39 get{ return particle; }
\r
40 set{ particle = value; }
\r
43 [XmlElement("attribute",typeof(XmlSchemaAttribute),Namespace="http://www.w3.org/2001/XMLSchema")]
\r
44 [XmlElement("attributeGroup",typeof(XmlSchemaAttributeGroupRef),Namespace="http://www.w3.org/2001/XMLSchema")]
\r
45 public XmlSchemaObjectCollection Attributes
\r
47 get{ return attributes; }
\r
50 [XmlElement("anyAttribute",Namespace="http://www.w3.org/2001/XMLSchema")]
\r
51 public XmlSchemaAnyAttribute AnyAttribute
\r
60 internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)
\r
62 if(BaseTypeName == null || BaseTypeName.IsEmpty)
\r
64 error(h, "base must be present and a QName");
\r
66 else if(!XmlSchemaUtil.CheckQName(BaseTypeName))
\r
67 error(h,"BaseTypeName is not a valid XmlQualifiedName");
\r
69 if(this.AnyAttribute != null)
\r
71 errorCount += AnyAttribute.Compile(h,info);
\r
74 foreach(XmlSchemaObject obj in Attributes)
\r
76 if(obj is XmlSchemaAttribute)
\r
78 XmlSchemaAttribute attr = (XmlSchemaAttribute) obj;
\r
79 errorCount += attr.Compile(h,info);
\r
81 else if(obj is XmlSchemaAttributeGroupRef)
\r
83 XmlSchemaAttributeGroupRef atgrp = (XmlSchemaAttributeGroupRef) obj;
\r
84 errorCount += atgrp.Compile(h,info);
\r
87 error(h,obj.GetType() +" is not valid in this place::ComplexConetnetExtension");
\r
90 if(Particle != null)
\r
92 if(Particle is XmlSchemaGroupRef)
\r
94 errorCount += ((XmlSchemaGroupRef)Particle).Compile(h,info);
\r
96 else if(Particle is XmlSchemaAll)
\r
98 errorCount += ((XmlSchemaAll)Particle).Compile(h,info);
\r
100 else if(Particle is XmlSchemaChoice)
\r
102 errorCount += ((XmlSchemaChoice)Particle).Compile(h,info);
\r
104 else if(Particle is XmlSchemaSequence)
\r
106 errorCount += ((XmlSchemaSequence)Particle).Compile(h,info);
\r
110 XmlSchemaUtil.CompileID(Id,this,info.IDCollection,h);
\r
116 internal int Validate(ValidationEventHandler h)
\r
123 // {any attributes with non-schema namespace . . .}>
\r
124 // Content: (annotation?, ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?)))
\r
126 internal static XmlSchemaComplexContentExtension Read(XmlSchemaReader reader, ValidationEventHandler h)
\r
128 XmlSchemaComplexContentExtension extension = new XmlSchemaComplexContentExtension();
\r
129 reader.MoveToElement();
\r
131 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
\r
133 error(h,"Should not happen :1: XmlSchemaComplexContentExtension.Read, name="+reader.Name,null);
\r
138 extension.LineNumber = reader.LineNumber;
\r
139 extension.LinePosition = reader.LinePosition;
\r
140 extension.SourceUri = reader.BaseURI;
\r
142 while(reader.MoveToNextAttribute())
\r
144 if(reader.Name == "base")
\r
147 extension.baseTypeName = XmlSchemaUtil.ReadQNameAttribute(reader,out innerex);
\r
148 if(innerex != null)
\r
149 error(h, reader.Value + " is not a valid value for base attribute",innerex);
\r
151 else if(reader.Name == "id")
\r
153 extension.Id = reader.Value;
\r
155 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
\r
157 error(h,reader.Name + " is not a valid attribute for extension",null);
\r
161 XmlSchemaUtil.ReadUnhandledAttribute(reader,extension);
\r
165 reader.MoveToElement();
\r
166 if(reader.IsEmptyElement)
\r
168 //Content: 1. annotation?,
\r
169 // (2.(group | all | choice | sequence)?, (3.(attribute | attributeGroup)*, 4.anyAttribute?)))
\r
171 while(reader.ReadNextElement())
\r
173 if(reader.NodeType == XmlNodeType.EndElement)
\r
175 if(reader.LocalName != xmlname)
\r
176 error(h,"Should not happen :2: XmlSchemaComplexContentExtension.Read, name="+reader.Name,null);
\r
179 if(level <= 1 && reader.LocalName == "annotation")
\r
181 level = 2; //Only one annotation
\r
182 XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
\r
183 if(annotation != null)
\r
184 extension.Annotation = annotation;
\r
189 if(reader.LocalName == "group")
\r
192 XmlSchemaGroupRef group = XmlSchemaGroupRef.Read(reader,h);
\r
194 extension.particle = group;
\r
197 if(reader.LocalName == "all")
\r
200 XmlSchemaAll all = XmlSchemaAll.Read(reader,h);
\r
202 extension.particle = all;
\r
205 if(reader.LocalName == "choice")
\r
208 XmlSchemaChoice choice = XmlSchemaChoice.Read(reader,h);
\r
210 extension.particle = choice;
\r
213 if(reader.LocalName == "sequence")
\r
216 XmlSchemaSequence sequence = XmlSchemaSequence.Read(reader,h);
\r
217 if(sequence != null)
\r
218 extension.particle = sequence;
\r
224 if(reader.LocalName == "attribute")
\r
227 XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader,h);
\r
229 extension.Attributes.Add(attr);
\r
232 if(reader.LocalName == "attributeGroup")
\r
235 XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader,h);
\r
237 extension.attributes.Add(attr);
\r
241 if(level <= 4 && reader.LocalName == "anyAttribute")
\r
244 XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader,h);
\r
245 if(anyattr != null)
\r
246 extension.AnyAttribute = anyattr;
\r
249 reader.RaiseInvalidElementError();
\r