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