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