1 // Author: Dwivedi, Ajay kumar
\r
5 // Permission is hereby granted, free of charge, to any person obtaining
6 // a copy of this software and associated documentation files (the
7 // "Software"), to deal in the Software without restriction, including
8 // without limitation the rights to use, copy, modify, merge, publish,
9 // distribute, sublicense, and/or sell copies of the Software, and to
10 // permit persons to whom the Software is furnished to do so, subject to
11 // the following conditions:
13 // The above copyright notice and this permission notice shall be
14 // included in all copies or substantial portions of the Software.
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 using System.Collections;
\r
26 using System.Globalization;
27 using System.Xml.Serialization;
\r
29 namespace System.Xml.Schema
\r
32 /// Summary description for XmlSchemaParticle.
\r
34 public abstract class XmlSchemaParticle : XmlSchemaAnnotated
\r
36 internal static XmlSchemaParticle Empty {
\r
38 if (empty == null) {
\r
39 empty = new EmptyParticle ();
\r
45 decimal minOccurs, maxOccurs;
\r
46 string minstr, maxstr;
\r
47 static XmlSchemaParticle empty;
\r
48 decimal validatedMinOccurs = 1, validatedMaxOccurs = 1;
\r
49 internal int recursionDepth = -1;
\r
50 private decimal minEffectiveTotalRange = -1;
\r
51 internal bool parentIsGroupDefinition;
\r
53 protected XmlSchemaParticle()
\r
55 minOccurs = decimal.One;
\r
56 maxOccurs = decimal.One;
\r
61 [System.Xml.Serialization.XmlAttribute("minOccurs")]
\r
62 public string MinOccursString
\r
64 get{ return minstr; }
\r
67 if (value == null) {
\r
68 minOccurs = decimal.One;
\r
73 decimal val = decimal.Parse (value, CultureInfo.InvariantCulture);
\r
74 if(val >= 0 && (val == Decimal.Truncate(val)))
\r
77 minstr = val.ToString (CultureInfo.InvariantCulture);
\r
81 throw new XmlSchemaException
\r
82 ("MinOccursString must be a non-negative number",null);
\r
87 [System.Xml.Serialization.XmlAttribute("maxOccurs")]
\r
88 public string MaxOccursString
\r
90 get{ return maxstr; }
\r
93 if(value == "unbounded")
\r
96 maxOccurs = decimal.MaxValue;
\r
100 decimal val = decimal.Parse (value, CultureInfo.InvariantCulture);
\r
101 if(val >= 0 && (val == Decimal.Truncate(val)))
\r
104 maxstr = val.ToString (CultureInfo.InvariantCulture);
\r
108 throw new XmlSchemaException
\r
109 ("MaxOccurs must be a non-negative integer",null);
\r
111 if (val == 0 && minstr == null)
\r
122 public decimal MinOccurs
\r
124 get{ return minOccurs; }
\r
127 MinOccursString = value.ToString (CultureInfo.InvariantCulture);
\r
132 public decimal MaxOccurs
\r
134 get{ return maxOccurs; }
\r
137 if (value == decimal.MaxValue)
138 MaxOccursString = "unbounded";
\r
140 MaxOccursString = value.ToString (CultureInfo.InvariantCulture);
\r
144 internal decimal ValidatedMinOccurs
\r
146 get { return validatedMinOccurs; }
\r
149 internal decimal ValidatedMaxOccurs
\r
151 get { return validatedMaxOccurs; }
\r
152 // set { validatedMaxOccurs = value; }
\r
156 internal XmlSchemaParticle OptimizedParticle;
\r
158 internal virtual XmlSchemaParticle GetOptimizedParticle (bool isTop)
\r
163 internal XmlSchemaParticle GetShallowClone ()
\r
165 return (XmlSchemaParticle) MemberwiseClone ();
\r
168 internal void CompileOccurence (ValidationEventHandler h, XmlSchema schema)
\r
170 if (MinOccurs > MaxOccurs && !(MaxOccurs == 0 && MinOccursString == null))
\r
171 error(h,"minOccurs must be less than or equal to maxOccurs");
\r
173 if (MaxOccursString == "unbounded")
\r
174 this.validatedMaxOccurs = decimal.MaxValue;
\r
176 this.validatedMaxOccurs = maxOccurs;
\r
177 if (this.validatedMaxOccurs == 0)
\r
178 this.validatedMinOccurs = 0;
\r
180 this.validatedMinOccurs = minOccurs;
\r
184 internal override void CopyInfo (XmlSchemaParticle obj)
\r
186 base.CopyInfo (obj);
\r
187 if (MaxOccursString == "unbounded")
\r
188 obj.maxOccurs = obj.validatedMaxOccurs = decimal.MaxValue;
\r
190 obj.maxOccurs = obj.validatedMaxOccurs = this.ValidatedMaxOccurs;
\r
191 if (MaxOccurs == 0)
\r
192 obj.minOccurs = obj.validatedMinOccurs = 0;
\r
194 obj.minOccurs = obj.validatedMinOccurs = this.ValidatedMinOccurs;
\r
195 if (MinOccursString != null)
\r
196 obj.MinOccursString = MinOccursString;
\r
197 if (MaxOccursString != null)
\r
198 obj.MaxOccursString = MaxOccursString;
\r
201 internal virtual bool ValidateOccurenceRangeOK (XmlSchemaParticle other,
\r
202 ValidationEventHandler h, XmlSchema schema, bool raiseError)
\r
204 if ((this.ValidatedMinOccurs < other.ValidatedMinOccurs) ||
\r
205 (other.ValidatedMaxOccurs != decimal.MaxValue &&
\r
206 this.ValidatedMaxOccurs > other.ValidatedMaxOccurs)) {
\r
208 error (h, "Invalid derivation occurence range was found.");
\r
214 internal virtual decimal GetMinEffectiveTotalRange ()
\r
216 return ValidatedMinOccurs;
\r
219 internal decimal GetMinEffectiveTotalRangeAllAndSequence ()
\r
221 if (minEffectiveTotalRange >= 0)
\r
222 return minEffectiveTotalRange;
\r
224 decimal product = 0; //this.ValidatedMinOccurs;
\r
225 XmlSchemaObjectCollection col = null;
\r
226 if (this is XmlSchemaAll)
\r
227 col = ((XmlSchemaAll) this).Items;
\r
229 col = ((XmlSchemaSequence) this).Items;
\r
230 foreach (XmlSchemaParticle p in col)
\r
231 product += p.GetMinEffectiveTotalRange ();
\r
233 minEffectiveTotalRange = product;
\r
237 // 3.9.6 Particle Emptiable
\r
238 internal virtual bool ValidateIsEmptiable ()
\r
240 return this.validatedMinOccurs == 0 || this.GetMinEffectiveTotalRange () == 0;
\r
243 internal virtual bool ValidateDerivationByRestriction (XmlSchemaParticle baseParticle,
\r
244 ValidationEventHandler h, XmlSchema schema, bool raiseError)
\r
249 internal virtual void ValidateUniqueParticleAttribution (
\r
250 XmlSchemaObjectTable qnames, ArrayList nsNames,
\r
251 ValidationEventHandler h, XmlSchema schema)
\r
255 internal virtual void ValidateUniqueTypeAttribution (XmlSchemaObjectTable labels,
\r
256 ValidationEventHandler h, XmlSchema schema)
\r
260 // See http://www.thaiopensource.com/relaxng/simplify.html
\r
261 internal virtual void CheckRecursion (int depth, ValidationEventHandler h, XmlSchema schema)
\r
265 internal virtual bool ParticleEquals (XmlSchemaParticle other)
\r
270 #region Internal Class
\r
271 internal class EmptyParticle : XmlSchemaParticle
\r
273 internal EmptyParticle ()
\r
277 internal override XmlSchemaParticle GetOptimizedParticle (bool isTop)
\r
282 internal override bool ParticleEquals (XmlSchemaParticle other)
\r
284 return other == this || other == XmlSchemaParticle.Empty;
\r
287 internal override bool ValidateDerivationByRestriction (XmlSchemaParticle baseParticle,
\r
288 ValidationEventHandler h, XmlSchema schema, bool raiseError)
\r
293 internal override void CheckRecursion (int depth,
\r
294 ValidationEventHandler h, XmlSchema schema)
\r
299 internal override void ValidateUniqueParticleAttribution (XmlSchemaObjectTable qnames,
\r
300 ArrayList nsNames, ValidationEventHandler h, XmlSchema schema)
\r
305 internal override void ValidateUniqueTypeAttribution (XmlSchemaObjectTable labels,
\r
306 ValidationEventHandler h, XmlSchema schema)
\r