2 // System.Xml.Schema.XmlSchemaComplexContentRestriction.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 XmlSchemaComplexContentRestriction.
\r
17 public class XmlSchemaComplexContentRestriction : 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 = "restriction";
\r
25 public XmlSchemaComplexContentRestriction()
\r
27 baseTypeName = XmlQualifiedName.Empty;
\r
28 attributes = new XmlSchemaObjectCollection();
\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 false; }
\r
68 /// 1. base must be present
\r
70 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
\r
72 // If this is already compiled this time, simply skip.
\r
73 if (this.IsComplied (schema.CompilationId))
\r
76 if (this.isRedefinedComponent) {
\r
77 if (Annotation != null)
\r
78 Annotation.isRedefinedComponent = true;
\r
79 if (AnyAttribute != null)
\r
80 AnyAttribute.isRedefinedComponent = true;
\r
81 foreach (XmlSchemaObject obj in Attributes)
\r
82 obj.isRedefinedComponent = true;
\r
83 if (Particle != null)
\r
84 Particle.isRedefinedComponent = true;
\r
87 if(BaseTypeName == null || BaseTypeName.IsEmpty)
\r
89 error(h, "base must be present, as a QName");
\r
91 else if(!XmlSchemaUtil.CheckQName(BaseTypeName))
\r
92 error(h,"BaseTypeName is not a valid XmlQualifiedName");
\r
94 if(this.AnyAttribute != null)
\r
96 errorCount += AnyAttribute.Compile(h, schema);
\r
99 foreach(XmlSchemaObject obj in Attributes)
\r
101 if(obj is XmlSchemaAttribute)
\r
103 XmlSchemaAttribute attr = (XmlSchemaAttribute) obj;
\r
104 errorCount += attr.Compile(h, schema);
\r
106 else if(obj is XmlSchemaAttributeGroupRef)
\r
108 XmlSchemaAttributeGroupRef atgrp = (XmlSchemaAttributeGroupRef) obj;
\r
109 errorCount += atgrp.Compile(h, schema);
\r
112 error(h,obj.GetType() +" is not valid in this place::ComplexContentRestriction");
\r
115 if(Particle != null)
\r
117 if(Particle is XmlSchemaGroupRef)
\r
119 errorCount += ((XmlSchemaGroupRef)Particle).Compile(h, schema);
\r
121 else if(Particle is XmlSchemaAll)
\r
123 errorCount += ((XmlSchemaAll)Particle).Compile(h, schema);
\r
125 else if(Particle is XmlSchemaChoice)
\r
127 errorCount += ((XmlSchemaChoice)Particle).Compile(h, schema);
\r
129 else if(Particle is XmlSchemaSequence)
\r
131 errorCount += ((XmlSchemaSequence)Particle).Compile(h, schema);
\r
134 error (h, "Particle of a restriction is limited only to group, sequence, choice and all.");
\r
137 XmlSchemaUtil.CompileID(Id,this, schema.IDCollection,h);
\r
139 this.CompilationId = schema.CompilationId;
\r
143 internal override XmlQualifiedName GetBaseTypeName ()
\r
145 return baseTypeName;
\r
148 internal override XmlSchemaParticle GetParticle ()
\r
153 internal override int Validate (ValidationEventHandler h, XmlSchema schema)
\r
161 // {any attributes with non-schema namespace . . .}>
\r
162 // Content: (annotation?, ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?)))
\r
164 internal static XmlSchemaComplexContentRestriction Read(XmlSchemaReader reader, ValidationEventHandler h)
\r
166 XmlSchemaComplexContentRestriction restriction = new XmlSchemaComplexContentRestriction();
\r
167 reader.MoveToElement();
\r
169 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
\r
171 error(h,"Should not happen :1: XmlSchemaComplexContentRestriction.Read, name="+reader.Name,null);
\r
176 restriction.LineNumber = reader.LineNumber;
\r
177 restriction.LinePosition = reader.LinePosition;
\r
178 restriction.SourceUri = reader.BaseURI;
\r
180 while(reader.MoveToNextAttribute())
\r
182 if(reader.Name == "base")
\r
185 restriction.baseTypeName = XmlSchemaUtil.ReadQNameAttribute(reader,out innerex);
\r
186 if(innerex != null)
\r
187 error(h, reader.Value + " is not a valid value for base attribute",innerex);
\r
189 else if(reader.Name == "id")
\r
191 restriction.Id = reader.Value;
\r
193 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
\r
195 error(h,reader.Name + " is not a valid attribute for restriction",null);
\r
199 XmlSchemaUtil.ReadUnhandledAttribute(reader,restriction);
\r
203 reader.MoveToElement();
\r
204 if(reader.IsEmptyElement)
\r
205 return restriction;
\r
206 //Content: 1. annotation?,
\r
207 // (2.(group | all | choice | sequence)?, (3.(attribute | attributeGroup)*, 4.anyAttribute?)))
\r
209 while(reader.ReadNextElement())
\r
211 if(reader.NodeType == XmlNodeType.EndElement)
\r
213 if(reader.LocalName != xmlname)
\r
214 error(h,"Should not happen :2: XmlSchemaComplexContentRestriction.Read, name="+reader.Name,null);
\r
217 if(level <= 1 && reader.LocalName == "annotation")
\r
219 level = 2; //Only one annotation
\r
220 XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
\r
221 if(annotation != null)
\r
222 restriction.Annotation = annotation;
\r
227 if(reader.LocalName == "group")
\r
230 XmlSchemaGroupRef group = XmlSchemaGroupRef.Read(reader,h);
\r
232 restriction.particle = group;
\r
235 if(reader.LocalName == "all")
\r
238 XmlSchemaAll all = XmlSchemaAll.Read(reader,h);
\r
240 restriction.particle = all;
\r
243 if(reader.LocalName == "choice")
\r
246 XmlSchemaChoice choice = XmlSchemaChoice.Read(reader,h);
\r
248 restriction.particle = choice;
\r
251 if(reader.LocalName == "sequence")
\r
254 XmlSchemaSequence sequence = XmlSchemaSequence.Read(reader,h);
\r
255 if(sequence != null)
\r
256 restriction.particle = sequence;
\r
262 if(reader.LocalName == "attribute")
\r
265 XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader,h);
\r
267 restriction.Attributes.Add(attr);
\r
270 if(reader.LocalName == "attributeGroup")
\r
273 XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader,h);
\r
275 restriction.attributes.Add(attr);
\r
279 if(level <= 4 && reader.LocalName == "anyAttribute")
\r
282 XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader,h);
\r
283 if(anyattr != null)
\r
284 restriction.AnyAttribute = anyattr;
\r
287 reader.RaiseInvalidElementError();
\r
289 return restriction;
\r