1 // Author: Dwivedi, Ajay kumar
\r
5 using System.Xml.Serialization;
\r
7 namespace System.Xml.Schema
\r
10 /// Summary description for XmlSchemaComplexContentRestriction.
\r
12 public class XmlSchemaComplexContentRestriction : 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 = "restriction";
\r
20 public XmlSchemaComplexContentRestriction()
\r
22 baseTypeName = XmlQualifiedName.Empty;
\r
23 attributes = new XmlSchemaObjectCollection();
\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=XmlSchema.Namespace)]
\r
34 [XmlElement("all",typeof(XmlSchemaAll),Namespace=XmlSchema.Namespace)]
\r
35 [XmlElement("choice",typeof(XmlSchemaChoice),Namespace=XmlSchema.Namespace)]
\r
36 [XmlElement("sequence",typeof(XmlSchemaSequence),Namespace=XmlSchema.Namespace)]
\r
37 public XmlSchemaParticle Particle
\r
39 get{ return particle; }
\r
40 set{ particle = value; }
\r
43 [XmlElement("attribute",typeof(XmlSchemaAttribute),Namespace=XmlSchema.Namespace)]
\r
44 [XmlElement("attributeGroup",typeof(XmlSchemaAttributeGroupRef),Namespace=XmlSchema.Namespace)]
\r
45 public XmlSchemaObjectCollection Attributes
\r
47 get{ return attributes; }
\r
50 [XmlElement("anyAttribute",Namespace=XmlSchema.Namespace)]
\r
51 public XmlSchemaAnyAttribute AnyAttribute
\r
58 /// 1. base must be present
\r
61 internal int Compile(ValidationEventHandler h, XmlSchema schema)
\r
63 // If this is already compiled this time, simply skip.
\r
64 if (this.IsComplied (schema.CompilationId))
\r
67 if(BaseTypeName == null || BaseTypeName.IsEmpty)
\r
69 error(h, "base must be present and a QName");
\r
71 else if(!XmlSchemaUtil.CheckQName(BaseTypeName))
\r
72 error(h,"BaseTypeName is not a valid XmlQualifiedName");
\r
74 if(this.AnyAttribute != null)
\r
76 errorCount += AnyAttribute.Compile(h, schema);
\r
79 foreach(XmlSchemaObject obj in Attributes)
\r
81 if(obj is XmlSchemaAttribute)
\r
83 XmlSchemaAttribute attr = (XmlSchemaAttribute) obj;
\r
84 errorCount += attr.Compile(h, schema);
\r
86 else if(obj is XmlSchemaAttributeGroupRef)
\r
88 XmlSchemaAttributeGroupRef atgrp = (XmlSchemaAttributeGroupRef) obj;
\r
89 errorCount += atgrp.Compile(h, schema);
\r
92 error(h,obj.GetType() +" is not valid in this place::ComplexContentRestriction");
\r
95 if(Particle != null)
\r
97 if(Particle is XmlSchemaGroupRef)
\r
99 errorCount += ((XmlSchemaGroupRef)Particle).Compile(h, schema);
\r
101 else if(Particle is XmlSchemaAll)
\r
103 errorCount += ((XmlSchemaAll)Particle).Compile(h, schema);
\r
105 else if(Particle is XmlSchemaChoice)
\r
107 errorCount += ((XmlSchemaChoice)Particle).Compile(h, schema);
\r
109 else if(Particle is XmlSchemaSequence)
\r
111 errorCount += ((XmlSchemaSequence)Particle).Compile(h, schema);
\r
115 XmlSchemaUtil.CompileID(Id,this, schema.IDCollection,h);
\r
117 this.CompilationId = schema.CompilationId;
\r
122 internal int Validate(ValidationEventHandler h)
\r
130 // {any attributes with non-schema namespace . . .}>
\r
131 // Content: (annotation?, ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?)))
\r
133 internal static XmlSchemaComplexContentRestriction Read(XmlSchemaReader reader, ValidationEventHandler h)
\r
135 XmlSchemaComplexContentRestriction restriction = new XmlSchemaComplexContentRestriction();
\r
136 reader.MoveToElement();
\r
138 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
\r
140 error(h,"Should not happen :1: XmlSchemaComplexContentRestriction.Read, name="+reader.Name,null);
\r
145 restriction.LineNumber = reader.LineNumber;
\r
146 restriction.LinePosition = reader.LinePosition;
\r
147 restriction.SourceUri = reader.BaseURI;
\r
149 while(reader.MoveToNextAttribute())
\r
151 if(reader.Name == "base")
\r
154 restriction.baseTypeName = XmlSchemaUtil.ReadQNameAttribute(reader,out innerex);
\r
155 if(innerex != null)
\r
156 error(h, reader.Value + " is not a valid value for base attribute",innerex);
\r
158 else if(reader.Name == "id")
\r
160 restriction.Id = reader.Value;
\r
162 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
\r
164 error(h,reader.Name + " is not a valid attribute for restriction",null);
\r
168 XmlSchemaUtil.ReadUnhandledAttribute(reader,restriction);
\r
172 reader.MoveToElement();
\r
173 if(reader.IsEmptyElement)
\r
174 return restriction;
\r
175 //Content: 1. annotation?,
\r
176 // (2.(group | all | choice | sequence)?, (3.(attribute | attributeGroup)*, 4.anyAttribute?)))
\r
178 while(reader.ReadNextElement())
\r
180 if(reader.NodeType == XmlNodeType.EndElement)
\r
182 if(reader.LocalName != xmlname)
\r
183 error(h,"Should not happen :2: XmlSchemaComplexContentRestriction.Read, name="+reader.Name,null);
\r
186 if(level <= 1 && reader.LocalName == "annotation")
\r
188 level = 2; //Only one annotation
\r
189 XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
\r
190 if(annotation != null)
\r
191 restriction.Annotation = annotation;
\r
196 if(reader.LocalName == "group")
\r
199 XmlSchemaGroupRef group = XmlSchemaGroupRef.Read(reader,h);
\r
201 restriction.particle = group;
\r
204 if(reader.LocalName == "all")
\r
207 XmlSchemaAll all = XmlSchemaAll.Read(reader,h);
\r
209 restriction.particle = all;
\r
212 if(reader.LocalName == "choice")
\r
215 XmlSchemaChoice choice = XmlSchemaChoice.Read(reader,h);
\r
217 restriction.particle = choice;
\r
220 if(reader.LocalName == "sequence")
\r
223 XmlSchemaSequence sequence = XmlSchemaSequence.Read(reader,h);
\r
224 if(sequence != null)
\r
225 restriction.particle = sequence;
\r
231 if(reader.LocalName == "attribute")
\r
234 XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader,h);
\r
236 restriction.Attributes.Add(attr);
\r
239 if(reader.LocalName == "attributeGroup")
\r
242 XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader,h);
\r
244 restriction.attributes.Add(attr);
\r
248 if(level <= 4 && reader.LocalName == "anyAttribute")
\r
251 XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader,h);
\r
252 if(anyattr != null)
\r
253 restriction.AnyAttribute = anyattr;
\r
256 reader.RaiseInvalidElementError();
\r
258 return restriction;
\r