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
),Namespace
=XmlSchema
.Namespace
)]
61 [XmlElement("choice",typeof(XmlSchemaChoice
),Namespace
=XmlSchema
.Namespace
)]
62 [XmlElement("sequence",typeof(XmlSchemaSequence
),Namespace
=XmlSchema
.Namespace
)]
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 (this.IsComplied (schema
.CompilationId
))
93 error(h
,"Required attribute name must be present");
94 else if(!XmlSchemaUtil
.CheckNCName(this.name
))
95 error(h
,"attribute name must be NCName");
97 qualifiedName
= new XmlQualifiedName(Name
,schema
.TargetNamespace
);
101 error(h
,"Particle is required");
105 if(Particle
.MaxOccursString
!= null)
106 Particle
.error(h
,"MaxOccurs must not be present when the Particle is a child of Group");
107 if(Particle
.MinOccursString
!= null)
108 Particle
.error(h
,"MinOccurs must not be present when the Particle is a child of Group");
110 Particle
.Compile (h
, schema
);
113 XmlSchemaUtil
.CompileID(Id
,this,schema
.IDCollection
,h
);
115 this.CompilationId
= schema
.CompilationId
;
119 internal override int Validate(ValidationEventHandler h
, XmlSchema schema
)
121 if (this.IsValidated (schema
.ValidationId
))
124 // 3.8.6 Model Group Correct :: 2. Circular group disallowed.
125 if (Particle
!= null) { // in case of invalid schema.
126 Particle
.parentIsGroupDefinition
= true;
129 Particle
.CheckRecursion (0, h
, schema
);
130 } catch (XmlSchemaException ex
) {
131 error (h
, ex
.Message
, ex
);
132 this.isCircularDefinition
= true;
135 errorCount
+= Particle
.Validate (h
,schema
);
137 Particle
.ValidateUniqueParticleAttribution (new XmlSchemaObjectTable (),
138 new ArrayList (), h
, schema
);
139 Particle
.ValidateUniqueTypeAttribution (
140 new XmlSchemaObjectTable (), h
, schema
);
143 this.ValidationId
= schema
.ValidationId
;
151 // {any attributes with non-schema namespace . . .}>
152 // Content: (annotation?, (all | choice | sequence)?)
154 internal static XmlSchemaGroup
Read(XmlSchemaReader reader
, ValidationEventHandler h
)
156 XmlSchemaGroup
group = new XmlSchemaGroup();
157 reader
.MoveToElement();
159 if(reader
.NamespaceURI
!= XmlSchema
.Namespace
|| reader
.LocalName
!= xmlname
)
161 error(h
,"Should not happen :1: XmlSchemaGroup.Read, name="+reader
.Name
,null);
166 group.LineNumber
= reader
.LineNumber
;
167 group.LinePosition
= reader
.LinePosition
;
168 group.SourceUri
= reader
.BaseURI
;
170 while(reader
.MoveToNextAttribute())
172 if(reader
.Name
== "id")
174 group.Id
= reader
.Value
;
176 else if(reader
.Name
== "name")
178 group.name
= reader
.Value
;
180 else if((reader
.NamespaceURI
== "" && reader
.Name
!= "xmlns") || reader
.NamespaceURI
== XmlSchema
.Namespace
)
182 error(h
,reader
.Name
+ " is not a valid attribute for group",null);
186 XmlSchemaUtil
.ReadUnhandledAttribute(reader
,group);
190 reader
.MoveToElement();
191 if(reader
.IsEmptyElement
)
194 // Content: (annotation?, (all | choice | sequence)?)
196 while(reader
.ReadNextElement())
198 if(reader
.NodeType
== XmlNodeType
.EndElement
)
200 if(reader
.LocalName
!= xmlname
)
201 error(h
,"Should not happen :2: XmlSchemaGroup.Read, name="+reader
.Name
,null);
204 if(level
<= 1 && reader
.LocalName
== "annotation")
206 level
= 2; //Only one annotation
207 XmlSchemaAnnotation annotation
= XmlSchemaAnnotation
.Read(reader
,h
);
208 if(annotation
!= null)
209 group.Annotation
= annotation
;
214 if(reader
.LocalName
== "all")
217 XmlSchemaAll all
= XmlSchemaAll
.Read(reader
,h
);
219 group.Particle
= all
;
222 if(reader
.LocalName
== "choice")
225 XmlSchemaChoice choice
= XmlSchemaChoice
.Read(reader
,h
);
227 group.Particle
= choice
;
230 if(reader
.LocalName
== "sequence")
233 XmlSchemaSequence sequence
= XmlSchemaSequence
.Read(reader
,h
);
235 group.Particle
= sequence
;
239 reader
.RaiseInvalidElementError();