2 // XmlSchemaGroupBase.cs
\r
5 // Dwivedi, Ajay kumar Adwiv@Yahoo.com
\r
6 // Atsushi Enomoto atsushi@ximian.com
\r
9 using System.Xml.Serialization;
\r
11 namespace System.Xml.Schema
\r
13 public abstract class XmlSchemaGroupBase : XmlSchemaParticle
\r
15 private XmlSchemaObjectCollection compiledItems;
\r
17 protected XmlSchemaGroupBase ()
\r
19 compiledItems = new XmlSchemaObjectCollection ();
\r
23 public abstract XmlSchemaObjectCollection Items { get; }
\r
25 internal XmlSchemaObjectCollection CompiledItems
\r
27 get{ return compiledItems; }
\r
30 internal void CopyOptimizedItems (XmlSchemaGroupBase gb)
\r
32 for (int i = 0; i < Items.Count; i++) {
\r
33 XmlSchemaParticle p = Items [i] as XmlSchemaParticle;
\r
34 p = p.GetOptimizedParticle (false);
\r
35 if (p == XmlSchemaParticle.Empty)
\r
38 gb.CompiledItems.Add (p);
\r
42 internal override bool ParticleEquals (XmlSchemaParticle other)
\r
44 XmlSchemaGroupBase gb = other as XmlSchemaGroupBase;
\r
47 if (this.GetType () != gb.GetType ())
\r
50 if (this.ValidatedMaxOccurs != gb.ValidatedMaxOccurs ||
\r
51 this.ValidatedMinOccurs != gb.ValidatedMinOccurs)
\r
53 if (this.CompiledItems.Count != gb.CompiledItems.Count)
\r
55 for (int i = 0; i < CompiledItems.Count; i++) {
\r
56 XmlSchemaParticle p1 = this.CompiledItems [i] as XmlSchemaParticle;
\r
57 XmlSchemaParticle p2 = gb.CompiledItems [i] as XmlSchemaParticle;
\r
58 if (!p1.ParticleEquals (p2))
\r
64 internal override void CheckRecursion (int depth, ValidationEventHandler h, XmlSchema schema)
\r
66 foreach (XmlSchemaParticle p in this.Items)
\r
67 p.CheckRecursion (depth, h, schema);
\r
70 internal bool ValidateNSRecurseCheckCardinality (XmlSchemaAny any,
\r
71 ValidationEventHandler h, XmlSchema schema, bool raiseError)
\r
73 foreach (XmlSchemaParticle p in Items)
\r
74 if (!p.ValidateDerivationByRestriction (any, h, schema, raiseError))
\r
76 return ValidateOccurenceRangeOK (any, h, schema, raiseError);
\r
79 internal bool ValidateRecurse (XmlSchemaGroupBase baseGroup,
\r
80 ValidationEventHandler h, XmlSchema schema, bool raiseError)
\r
82 return ValidateSeqRecurseMapSumCommon (baseGroup, h, schema, false, false, raiseError);
\r
85 internal bool ValidateSeqRecurseMapSumCommon (XmlSchemaGroupBase baseGroup,
\r
86 ValidationEventHandler h, XmlSchema schema, bool isLax, bool isMapAndSum, bool raiseError)
\r
90 decimal baseOccured = 0;
\r
91 if (baseGroup.CompiledItems.Count == 0 && this.CompiledItems.Count > 0) {
\r
93 error (h, "Invalid particle derivation by restriction was found. base particle does not contain particles.");
\r
97 for (int i = 0; i < CompiledItems.Count; i++) {
\r
98 // get non-empty derived particle
\r
99 XmlSchemaParticle pd = null;
\r
100 while (this.CompiledItems.Count > index) {
\r
101 pd = ((XmlSchemaParticle) this.CompiledItems [index]);//.GetOptimizedParticle (false);
\r
102 if (pd != XmlSchemaParticle.Empty)// && pd.ValidatedMaxOccurs > 0)
\r
107 if (index >= CompiledItems.Count) {
\r
109 error (h, "Invalid particle derivation by restriction was found. Cannot be mapped to base particle.");
\r
113 // get non-empty base particle
\r
114 XmlSchemaParticle pb = null;
\r
115 while (baseGroup.CompiledItems.Count > baseIndex) {
\r
116 pb = ((XmlSchemaParticle) baseGroup.CompiledItems [baseIndex]);//.GetOptimizedParticle (false);
\r
117 if (pb == XmlSchemaParticle.Empty && pb.ValidatedMaxOccurs > 0)
\r
119 if (!pd.ValidateDerivationByRestriction (pb, h, schema, false)) {
\r
120 if (!isLax && !isMapAndSum && pb.MinOccurs > baseOccured && !pb.ValidateIsEmptiable ()) {
\r
122 error (h, "Invalid particle derivation by restriction was found. Invalid sub-particle derivation was found.");
\r
130 baseOccured += pb.ValidatedMinOccurs;
\r
131 if (baseOccured >= baseGroup.ValidatedMaxOccurs) {
\r
140 if (this.CompiledItems.Count > 0 && index != this.CompiledItems.Count) {
\r
142 error (h, "Invalid particle derivation by restriction was found. Extraneous derived particle was found.");
\r
145 if (!isLax && !isMapAndSum) {
\r
146 if (baseOccured > 0)
\r
148 for (int i = baseIndex; i < baseGroup.CompiledItems.Count; i++) {
\r
149 XmlSchemaParticle p = baseGroup.CompiledItems [i] as XmlSchemaParticle;
\r
150 if (!p.ValidateIsEmptiable ()) {
\r
152 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