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
9 using System.Collections;
\r
10 using System.Xml.Serialization;
\r
13 namespace System.Xml.Schema
\r
16 /// refers to the named group
\r
18 public class XmlSchemaGroup : XmlSchemaAnnotated
\r
20 private string name;
\r
21 private XmlSchemaGroupBase particle;
\r
22 private XmlQualifiedName qualifiedName;
\r
23 private bool isCircularDefinition;
\r
25 private static string xmlname = "group";
\r
27 public XmlSchemaGroup()
\r
31 [System.Xml.Serialization.XmlAttribute("name")]
\r
34 get{ return name; }
\r
35 set{ name = value; }
\r
38 [XmlElement("all",typeof(XmlSchemaAll),Namespace=XmlSchema.Namespace)]
\r
39 [XmlElement("choice",typeof(XmlSchemaChoice),Namespace=XmlSchema.Namespace)]
\r
40 [XmlElement("sequence",typeof(XmlSchemaSequence),Namespace=XmlSchema.Namespace)]
\r
41 public XmlSchemaGroupBase Particle
\r
43 get{ return particle; }
\r
44 set{ particle = value; }
\r
48 internal XmlQualifiedName QualifiedName
\r
50 get{ return qualifiedName;}
\r
53 internal bool IsCircularDefinition
\r
55 get { return isCircularDefinition; }
\r
58 // 1. name must be present
\r
59 // 2. MinOccurs & MaxOccurs of the Particle must be absent
\r
61 internal override 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
68 error(h,"Required attribute name must be present");
\r
69 else if(!XmlSchemaUtil.CheckNCName(this.name))
\r
70 error(h,"attribute name must be NCName");
\r
72 qualifiedName = new XmlQualifiedName(Name,schema.TargetNamespace);
\r
74 if(Particle == null)
\r
76 error(h,"Particle is required");
\r
80 if(Particle.MaxOccursString != null)
\r
81 Particle.error(h,"MaxOccurs must not be present when the Particle is a child of Group");
\r
82 if(Particle.MinOccursString != null)
\r
83 Particle.error(h,"MinOccurs must not be present when the Particle is a child of Group");
\r
85 if(Particle is XmlSchemaChoice)
\r
87 errorCount += ((XmlSchemaChoice)Particle).Compile(h,schema);
\r
89 else if(Particle is XmlSchemaSequence)
\r
91 errorCount += ((XmlSchemaSequence)Particle).Compile(h,schema);
\r
93 else if(Particle is XmlSchemaAll)
\r
95 errorCount += ((XmlSchemaAll)Particle).Compile(h,schema);
\r
99 error(h,"only all,choice or sequence are allowed");
\r
103 XmlSchemaUtil.CompileID(Id,this,schema.IDCollection,h);
\r
105 this.CompilationId = schema.CompilationId;
\r
110 internal override int Validate(ValidationEventHandler h, XmlSchema schema)
\r
112 if (this.IsValidated (schema.ValidationId))
\r
115 // 3.8.6 Model Group Correct :: 2. Circular group disallowed.
\r
116 if (Particle != null) { // in case of invalid schema.
\r
117 Particle.parentIsGroupDefinition = true;
\r
120 Particle.CheckRecursion (0, h, schema);
\r
121 } catch (XmlSchemaException ex) {
\r
122 error (h, ex.Message, ex);
\r
123 this.isCircularDefinition = true;
\r
126 errorCount += Particle.Validate (h,schema);
\r
128 Particle.ValidateUniqueParticleAttribution (new XmlSchemaObjectTable (),
\r
129 new ArrayList (), h, schema);
\r
130 Particle.ValidateUniqueTypeAttribution (
\r
131 new XmlSchemaObjectTable (), h, schema);
\r
134 this.ValidationId = schema.ValidationId;
\r
142 // {any attributes with non-schema namespace . . .}>
\r
143 // Content: (annotation?, (all | choice | sequence)?)
\r
145 internal static XmlSchemaGroup Read(XmlSchemaReader reader, ValidationEventHandler h)
\r
147 XmlSchemaGroup group = new XmlSchemaGroup();
\r
148 reader.MoveToElement();
\r
150 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
\r
152 error(h,"Should not happen :1: XmlSchemaGroup.Read, name="+reader.Name,null);
\r
157 group.LineNumber = reader.LineNumber;
\r
158 group.LinePosition = reader.LinePosition;
\r
159 group.SourceUri = reader.BaseURI;
\r
161 while(reader.MoveToNextAttribute())
\r
163 if(reader.Name == "id")
\r
165 group.Id = reader.Value;
\r
167 else if(reader.Name == "name")
\r
169 group.name = reader.Value;
\r
171 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
\r
173 error(h,reader.Name + " is not a valid attribute for group",null);
\r
177 XmlSchemaUtil.ReadUnhandledAttribute(reader,group);
\r
181 reader.MoveToElement();
\r
182 if(reader.IsEmptyElement)
\r
185 // Content: (annotation?, (all | choice | sequence)?)
\r
187 while(reader.ReadNextElement())
\r
189 if(reader.NodeType == XmlNodeType.EndElement)
\r
191 if(reader.LocalName != xmlname)
\r
192 error(h,"Should not happen :2: XmlSchemaGroup.Read, name="+reader.Name,null);
\r
195 if(level <= 1 && reader.LocalName == "annotation")
\r
197 level = 2; //Only one annotation
\r
198 XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
\r
199 if(annotation != null)
\r
200 group.Annotation = annotation;
\r
205 if(reader.LocalName == "all")
\r
208 XmlSchemaAll all = XmlSchemaAll.Read(reader,h);
\r
210 group.Particle = all;
\r
213 if(reader.LocalName == "choice")
\r
216 XmlSchemaChoice choice = XmlSchemaChoice.Read(reader,h);
\r
218 group.Particle = choice;
\r
221 if(reader.LocalName == "sequence")
\r
224 XmlSchemaSequence sequence = XmlSchemaSequence.Read(reader,h);
\r
225 if(sequence != null)
\r
226 group.Particle = sequence;
\r
230 reader.RaiseInvalidElementError();
\r