2 // System.Xml.Schema.XmlSchemaGroup.cs
5 // Dwivedi, Ajay kumar Adwiv@Yahoo.com
6 // Atsushi Enomoto ginga@kit.hi-ho.ne.jp
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.
30 using System.Collections;
31 using System.Xml.Serialization;
34 namespace System.Xml.Schema
37 /// refers to the named group
39 public class XmlSchemaGroup : XmlSchemaAnnotated
42 private XmlSchemaGroupBase particle;
43 private XmlQualifiedName qualifiedName;
44 private bool isCircularDefinition;
46 const string xmlname = "group";
48 public XmlSchemaGroup()
50 qualifiedName = XmlQualifiedName.Empty;
53 [System.Xml.Serialization.XmlAttribute("name")]
60 [XmlElement("all",typeof(XmlSchemaAll))]
61 [XmlElement("choice",typeof(XmlSchemaChoice))]
62 [XmlElement("sequence",typeof(XmlSchemaSequence))]
63 public XmlSchemaGroupBase Particle
65 get{ return particle; }
66 set{ particle = value; }
71 public XmlQualifiedName QualifiedName
73 internal XmlQualifiedName QualifiedName
76 get{ return qualifiedName;}
79 internal bool IsCircularDefinition
81 get { return isCircularDefinition; }
84 // 1. name must be present
85 // 2. MinOccurs & MaxOccurs of the Particle must be absent
86 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
88 // If this is already compiled this time, simply skip.
89 if (CompilationId == schema.CompilationId)
94 Particle.Parent = this;
98 error(h,"Required attribute name must be present");
99 else if(!XmlSchemaUtil.CheckNCName(this.name))
100 error(h,"attribute name must be NCName");
102 qualifiedName = new XmlQualifiedName(Name,schema.TargetNamespace);
106 error(h,"Particle is required");
110 if(Particle.MaxOccursString != null)
111 Particle.error(h,"MaxOccurs must not be present when the Particle is a child of Group");
112 if(Particle.MinOccursString != null)
113 Particle.error(h,"MinOccurs must not be present when the Particle is a child of Group");
115 Particle.Compile (h, schema);
118 XmlSchemaUtil.CompileID(Id,this,schema.IDCollection,h);
120 this.CompilationId = schema.CompilationId;
124 internal override int Validate(ValidationEventHandler h, XmlSchema schema)
126 if (this.IsValidated (schema.ValidationId))
129 // 3.8.6 Model Group Correct :: 2. Circular group disallowed.
130 if (Particle != null) { // in case of invalid schema.
131 Particle.parentIsGroupDefinition = true;
134 Particle.CheckRecursion (0, h, schema);
135 } catch (XmlSchemaException ex) {
136 error (h, ex.Message, ex);
137 this.isCircularDefinition = true;
140 errorCount += Particle.Validate (h,schema);
142 Particle.ValidateUniqueParticleAttribution (new XmlSchemaObjectTable (),
143 new ArrayList (), h, schema);
144 Particle.ValidateUniqueTypeAttribution (
145 new XmlSchemaObjectTable (), h, schema);
148 this.ValidationId = schema.ValidationId;
156 // {any attributes with non-schema namespace . . .}>
157 // Content: (annotation?, (all | choice | sequence)?)
159 internal static XmlSchemaGroup Read(XmlSchemaReader reader, ValidationEventHandler h)
161 XmlSchemaGroup group = new XmlSchemaGroup();
162 reader.MoveToElement();
164 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
166 error(h,"Should not happen :1: XmlSchemaGroup.Read, name="+reader.Name,null);
171 group.LineNumber = reader.LineNumber;
172 group.LinePosition = reader.LinePosition;
173 group.SourceUri = reader.BaseURI;
175 while(reader.MoveToNextAttribute())
177 if(reader.Name == "id")
179 group.Id = reader.Value;
181 else if(reader.Name == "name")
183 group.name = reader.Value;
185 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
187 error(h,reader.Name + " is not a valid attribute for group",null);
191 XmlSchemaUtil.ReadUnhandledAttribute(reader,group);
195 reader.MoveToElement();
196 if(reader.IsEmptyElement)
199 // Content: (annotation?, (all | choice | sequence)?)
201 while(reader.ReadNextElement())
203 if(reader.NodeType == XmlNodeType.EndElement)
205 if(reader.LocalName != xmlname)
206 error(h,"Should not happen :2: XmlSchemaGroup.Read, name="+reader.Name,null);
209 if(level <= 1 && reader.LocalName == "annotation")
211 level = 2; //Only one annotation
212 XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
213 if(annotation != null)
214 group.Annotation = annotation;
219 if(reader.LocalName == "all")
222 XmlSchemaAll all = XmlSchemaAll.Read(reader,h);
224 group.Particle = all;
227 if(reader.LocalName == "choice")
230 XmlSchemaChoice choice = XmlSchemaChoice.Read(reader,h);
232 group.Particle = choice;
235 if(reader.LocalName == "sequence")
238 XmlSchemaSequence sequence = XmlSchemaSequence.Read(reader,h);
240 group.Particle = sequence;
244 reader.RaiseInvalidElementError();