2 // XmlSchemaGroupBase.cs
\r
5 // Dwivedi, Ajay kumar Adwiv@Yahoo.com
\r
6 // Atsushi Enomoto atsushi@ximian.com
\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.Xml.Serialization;
\r
32 namespace System.Xml.Schema
\r
34 public abstract class XmlSchemaGroupBase : XmlSchemaParticle
\r
36 private XmlSchemaObjectCollection compiledItems;
\r
38 protected XmlSchemaGroupBase ()
\r
40 compiledItems = new XmlSchemaObjectCollection ();
\r
44 public abstract XmlSchemaObjectCollection Items { get; }
\r
46 internal XmlSchemaObjectCollection CompiledItems
\r
48 get{ return compiledItems; }
\r
51 internal void CopyOptimizedItems (XmlSchemaGroupBase gb)
\r
53 for (int i = 0; i < Items.Count; i++) {
\r
54 XmlSchemaParticle p = Items [i] as XmlSchemaParticle;
\r
55 p = p.GetOptimizedParticle (false);
\r
56 if (p == XmlSchemaParticle.Empty)
\r
59 gb.CompiledItems.Add (p);
\r
63 internal override bool ParticleEquals (XmlSchemaParticle other)
\r
65 XmlSchemaGroupBase gb = other as XmlSchemaGroupBase;
\r
68 if (this.GetType () != gb.GetType ())
\r
71 if (this.ValidatedMaxOccurs != gb.ValidatedMaxOccurs ||
\r
72 this.ValidatedMinOccurs != gb.ValidatedMinOccurs)
\r
74 if (this.CompiledItems.Count != gb.CompiledItems.Count)
\r
76 for (int i = 0; i < CompiledItems.Count; i++) {
\r
77 XmlSchemaParticle p1 = this.CompiledItems [i] as XmlSchemaParticle;
\r
78 XmlSchemaParticle p2 = gb.CompiledItems [i] as XmlSchemaParticle;
\r
79 if (!p1.ParticleEquals (p2))
\r
85 internal override void CheckRecursion (int depth, ValidationEventHandler h, XmlSchema schema)
\r
87 foreach (XmlSchemaParticle p in this.Items)
\r
88 p.CheckRecursion (depth, h, schema);
\r
91 internal bool ValidateNSRecurseCheckCardinality (XmlSchemaAny any,
\r
92 ValidationEventHandler h, XmlSchema schema, bool raiseError)
\r
94 foreach (XmlSchemaParticle p in Items)
\r
95 if (!p.ValidateDerivationByRestriction (any, h, schema, raiseError))
\r
97 return ValidateOccurenceRangeOK (any, h, schema, raiseError);
\r
100 internal bool ValidateRecurse (XmlSchemaGroupBase baseGroup,
\r
101 ValidationEventHandler h, XmlSchema schema, bool raiseError)
\r
103 return ValidateSeqRecurseMapSumCommon (baseGroup, h, schema, false, false, raiseError);
\r
106 internal bool ValidateSeqRecurseMapSumCommon (XmlSchemaGroupBase baseGroup,
\r
107 ValidationEventHandler h, XmlSchema schema, bool isLax, bool isMapAndSum, bool raiseError)
\r
111 decimal baseOccured = 0;
\r
112 if (baseGroup.CompiledItems.Count == 0 && this.CompiledItems.Count > 0) {
\r
114 error (h, "Invalid particle derivation by restriction was found. base particle does not contain particles.");
\r
118 for (int i = 0; i < CompiledItems.Count; i++) {
\r
119 // get non-empty derived particle
\r
120 XmlSchemaParticle pd = null;
\r
121 while (this.CompiledItems.Count > index) {
\r
122 pd = ((XmlSchemaParticle) this.CompiledItems [index]);//.GetOptimizedParticle (false);
\r
123 if (pd != XmlSchemaParticle.Empty)// && pd.ValidatedMaxOccurs > 0)
\r
128 if (index >= CompiledItems.Count) {
\r
130 error (h, "Invalid particle derivation by restriction was found. Cannot be mapped to base particle.");
\r
134 // get non-empty base particle
\r
135 XmlSchemaParticle pb = null;
\r
136 while (baseGroup.CompiledItems.Count > baseIndex) {
\r
137 pb = ((XmlSchemaParticle) baseGroup.CompiledItems [baseIndex]);//.GetOptimizedParticle (false);
\r
138 if (pb == XmlSchemaParticle.Empty && pb.ValidatedMaxOccurs > 0)
\r
140 if (!pd.ValidateDerivationByRestriction (pb, h, schema, false)) {
\r
141 if (!isLax && !isMapAndSum && pb.MinOccurs > baseOccured && !pb.ValidateIsEmptiable ()) {
\r
143 error (h, "Invalid particle derivation by restriction was found. Invalid sub-particle derivation was found.");
\r
151 baseOccured += pb.ValidatedMinOccurs;
\r
152 if (baseOccured >= baseGroup.ValidatedMaxOccurs) {
\r
161 if (this.CompiledItems.Count > 0 && index != this.CompiledItems.Count) {
\r
163 error (h, "Invalid particle derivation by restriction was found. Extraneous derived particle was found.");
\r
166 if (!isLax && !isMapAndSum) {
\r
167 if (baseOccured > 0)
\r
169 for (int i = baseIndex; i < baseGroup.CompiledItems.Count; i++) {
\r
170 XmlSchemaParticle p = baseGroup.CompiledItems [i] as XmlSchemaParticle;
\r
171 if (!p.ValidateIsEmptiable ()) {
\r
173 error (h, "Invalid particle derivation by restriction was found. There is a base particle which does not have mapped derived particle and is not emptiable.");
\r