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 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Xml.Serialization;
\r
33 namespace System.Xml.Schema
\r
36 /// Summary description for XmlSchemaComplexContentRestriction.
\r
38 public class XmlSchemaComplexContentRestriction : XmlSchemaContent
\r
40 private XmlSchemaAnyAttribute any;
\r
41 private XmlSchemaObjectCollection attributes;
\r
42 private XmlQualifiedName baseTypeName;
\r
43 private XmlSchemaParticle particle;
\r
44 const string xmlname = "restriction";
\r
46 public XmlSchemaComplexContentRestriction()
\r
48 baseTypeName = XmlQualifiedName.Empty;
\r
49 attributes = new XmlSchemaObjectCollection();
\r
52 [System.Xml.Serialization.XmlAttribute("base")]
\r
53 public XmlQualifiedName BaseTypeName
\r
55 get{ return baseTypeName; }
\r
56 set{ baseTypeName = value; }
\r
59 [XmlElement("group",typeof(XmlSchemaGroupRef),Namespace=XmlSchema.Namespace)]
\r
60 [XmlElement("all",typeof(XmlSchemaAll),Namespace=XmlSchema.Namespace)]
\r
61 [XmlElement("choice",typeof(XmlSchemaChoice),Namespace=XmlSchema.Namespace)]
\r
62 [XmlElement("sequence",typeof(XmlSchemaSequence),Namespace=XmlSchema.Namespace)]
\r
63 public XmlSchemaParticle Particle
\r
65 get{ return particle; }
\r
66 set{ particle = value; }
\r
69 [XmlElement("attribute",typeof(XmlSchemaAttribute),Namespace=XmlSchema.Namespace)]
\r
70 [XmlElement("attributeGroup",typeof(XmlSchemaAttributeGroupRef),Namespace=XmlSchema.Namespace)]
\r
71 public XmlSchemaObjectCollection Attributes
\r
73 get{ return attributes; }
\r
76 [XmlElement("anyAttribute",Namespace=XmlSchema.Namespace)]
\r
77 public XmlSchemaAnyAttribute AnyAttribute
\r
83 // internal properties
\r
84 internal override bool IsExtension {
\r
85 get { return false; }
\r
89 /// 1. base must be present
\r
91 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
\r
93 // If this is already compiled this time, simply skip.
\r
94 if (this.IsComplied (schema.CompilationId))
\r
98 if (Particle != null)
\r
99 Particle.Parent = this;
\r
100 if (AnyAttribute != null)
\r
101 AnyAttribute.Parent = this;
\r
102 foreach (XmlSchemaObject obj in Attributes)
\r
106 if (this.isRedefinedComponent) {
\r
107 if (Annotation != null)
\r
108 Annotation.isRedefinedComponent = true;
\r
109 if (AnyAttribute != null)
\r
110 AnyAttribute.isRedefinedComponent = true;
\r
111 foreach (XmlSchemaObject obj in Attributes)
\r
112 obj.isRedefinedComponent = true;
\r
113 if (Particle != null)
\r
114 Particle.isRedefinedComponent = true;
\r
117 if(BaseTypeName == null || BaseTypeName.IsEmpty)
\r
119 error(h, "base must be present, as a QName");
\r
121 else if(!XmlSchemaUtil.CheckQName(BaseTypeName))
\r
122 error(h,"BaseTypeName is not a valid XmlQualifiedName");
\r
124 if(this.AnyAttribute != null)
\r
126 errorCount += AnyAttribute.Compile(h, schema);
\r
129 foreach(XmlSchemaObject obj in Attributes)
\r
131 if(obj is XmlSchemaAttribute)
\r
133 XmlSchemaAttribute attr = (XmlSchemaAttribute) obj;
\r
134 errorCount += attr.Compile(h, schema);
\r
136 else if(obj is XmlSchemaAttributeGroupRef)
\r
138 XmlSchemaAttributeGroupRef atgrp = (XmlSchemaAttributeGroupRef) obj;
\r
139 errorCount += atgrp.Compile(h, schema);
\r
142 error(h,obj.GetType() +" is not valid in this place::ComplexContentRestriction");
\r
145 if(Particle != null)
\r
147 if(Particle is XmlSchemaGroupRef)
\r
149 errorCount += ((XmlSchemaGroupRef)Particle).Compile(h, schema);
\r
151 else if(Particle is XmlSchemaAll)
\r
153 errorCount += ((XmlSchemaAll)Particle).Compile(h, schema);
\r
155 else if(Particle is XmlSchemaChoice)
\r
157 errorCount += ((XmlSchemaChoice)Particle).Compile(h, schema);
\r
159 else if(Particle is XmlSchemaSequence)
\r
161 errorCount += ((XmlSchemaSequence)Particle).Compile(h, schema);
\r
164 error (h, "Particle of a restriction is limited only to group, sequence, choice and all.");
\r
167 XmlSchemaUtil.CompileID(Id,this, schema.IDCollection,h);
\r
169 this.CompilationId = schema.CompilationId;
\r
173 internal override XmlQualifiedName GetBaseTypeName ()
\r
175 return baseTypeName;
\r
178 internal override XmlSchemaParticle GetParticle ()
\r
183 internal override int Validate (ValidationEventHandler h, XmlSchema schema)
\r
191 // {any attributes with non-schema namespace . . .}>
\r
192 // Content: (annotation?, ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?)))
\r
194 internal static XmlSchemaComplexContentRestriction Read(XmlSchemaReader reader, ValidationEventHandler h)
\r
196 XmlSchemaComplexContentRestriction restriction = new XmlSchemaComplexContentRestriction();
\r
197 reader.MoveToElement();
\r
199 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
\r
201 error(h,"Should not happen :1: XmlSchemaComplexContentRestriction.Read, name="+reader.Name,null);
\r
206 restriction.LineNumber = reader.LineNumber;
\r
207 restriction.LinePosition = reader.LinePosition;
\r
208 restriction.SourceUri = reader.BaseURI;
\r
210 while(reader.MoveToNextAttribute())
\r
212 if(reader.Name == "base")
\r
215 restriction.baseTypeName = XmlSchemaUtil.ReadQNameAttribute(reader,out innerex);
\r
216 if(innerex != null)
\r
217 error(h, reader.Value + " is not a valid value for base attribute",innerex);
\r
219 else if(reader.Name == "id")
\r
221 restriction.Id = reader.Value;
\r
223 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
\r
225 error(h,reader.Name + " is not a valid attribute for restriction",null);
\r
229 XmlSchemaUtil.ReadUnhandledAttribute(reader,restriction);
\r
233 reader.MoveToElement();
\r
234 if(reader.IsEmptyElement)
\r
235 return restriction;
\r
236 //Content: 1. annotation?,
\r
237 // (2.(group | all | choice | sequence)?, (3.(attribute | attributeGroup)*, 4.anyAttribute?)))
\r
239 while(reader.ReadNextElement())
\r
241 if(reader.NodeType == XmlNodeType.EndElement)
\r
243 if(reader.LocalName != xmlname)
\r
244 error(h,"Should not happen :2: XmlSchemaComplexContentRestriction.Read, name="+reader.Name,null);
\r
247 if(level <= 1 && reader.LocalName == "annotation")
\r
249 level = 2; //Only one annotation
\r
250 XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
\r
251 if(annotation != null)
\r
252 restriction.Annotation = annotation;
\r
257 if(reader.LocalName == "group")
\r
260 XmlSchemaGroupRef group = XmlSchemaGroupRef.Read(reader,h);
\r
262 restriction.particle = group;
\r
265 if(reader.LocalName == "all")
\r
268 XmlSchemaAll all = XmlSchemaAll.Read(reader,h);
\r
270 restriction.particle = all;
\r
273 if(reader.LocalName == "choice")
\r
276 XmlSchemaChoice choice = XmlSchemaChoice.Read(reader,h);
\r
278 restriction.particle = choice;
\r
281 if(reader.LocalName == "sequence")
\r
284 XmlSchemaSequence sequence = XmlSchemaSequence.Read(reader,h);
\r
285 if(sequence != null)
\r
286 restriction.particle = sequence;
\r
292 if(reader.LocalName == "attribute")
\r
295 XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader,h);
\r
297 restriction.Attributes.Add(attr);
\r
300 if(reader.LocalName == "attributeGroup")
\r
303 XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader,h);
\r
305 restriction.attributes.Add(attr);
\r
309 if(level <= 4 && reader.LocalName == "anyAttribute")
\r
312 XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader,h);
\r
313 if(anyattr != null)
\r
314 restriction.AnyAttribute = anyattr;
\r
317 reader.RaiseInvalidElementError();
\r
319 return restriction;
\r