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 abstract XmlSchemaParticle GetOptimizedParticle (bool isTop);
\r
160 internal XmlSchemaParticle GetShallowClone ()
\r
162 return (XmlSchemaParticle) MemberwiseClone ();
\r
165 internal void CompileOccurence (ValidationEventHandler h, XmlSchema schema)
\r
167 if (MinOccurs > MaxOccurs && !(MaxOccurs == 0 && MinOccursString == null))
\r
168 error(h,"minOccurs must be less than or equal to maxOccurs");
\r
170 if (MaxOccursString == "unbounded")
\r
171 this.validatedMaxOccurs = decimal.MaxValue;
\r
173 this.validatedMaxOccurs = maxOccurs;
\r
174 if (this.validatedMaxOccurs == 0)
\r
175 this.validatedMinOccurs = 0;
\r
177 this.validatedMinOccurs = minOccurs;
\r
181 internal override void CopyInfo (XmlSchemaParticle obj)
\r
183 base.CopyInfo (obj);
\r
184 if (MaxOccursString == "unbounded")
\r
185 obj.maxOccurs = obj.validatedMaxOccurs = decimal.MaxValue;
\r
187 obj.maxOccurs = obj.validatedMaxOccurs = this.ValidatedMaxOccurs;
\r
188 if (MaxOccurs == 0)
\r
189 obj.minOccurs = obj.validatedMinOccurs = 0;
\r
191 obj.minOccurs = obj.validatedMinOccurs = this.ValidatedMinOccurs;
\r
192 if (MinOccursString != null)
\r
193 obj.MinOccursString = MinOccursString;
\r
194 if (MaxOccursString != null)
\r
195 obj.MaxOccursString = MaxOccursString;
\r
198 internal virtual bool ValidateOccurenceRangeOK (XmlSchemaParticle other,
\r
199 ValidationEventHandler h, XmlSchema schema, bool raiseError)
\r
201 if ((this.ValidatedMinOccurs < other.ValidatedMinOccurs) ||
\r
202 (other.ValidatedMaxOccurs != decimal.MaxValue &&
\r
203 this.ValidatedMaxOccurs > other.ValidatedMaxOccurs)) {
\r
205 error (h, "Invalid derivation occurence range was found.");
\r
211 internal virtual decimal GetMinEffectiveTotalRange ()
\r
213 return ValidatedMinOccurs;
\r
216 internal decimal GetMinEffectiveTotalRangeAllAndSequence ()
\r
218 if (minEffectiveTotalRange >= 0)
\r
219 return minEffectiveTotalRange;
\r
221 decimal product = 0; //this.ValidatedMinOccurs;
\r
222 XmlSchemaObjectCollection col = null;
\r
223 if (this is XmlSchemaAll)
\r
224 col = ((XmlSchemaAll) this).Items;
\r
226 col = ((XmlSchemaSequence) this).Items;
\r
227 foreach (XmlSchemaParticle p in col)
\r
228 product += p.GetMinEffectiveTotalRange ();
\r
230 minEffectiveTotalRange = product;
\r
234 // 3.9.6 Particle Emptiable
\r
235 internal virtual bool ValidateIsEmptiable ()
\r
237 return this.validatedMinOccurs == 0 || this.GetMinEffectiveTotalRange () == 0;
\r
240 internal abstract bool ValidateDerivationByRestriction (XmlSchemaParticle baseParticle,
\r
241 ValidationEventHandler h, XmlSchema schema, bool raiseError);
\r
243 internal abstract void ValidateUniqueParticleAttribution (
\r
244 XmlSchemaObjectTable qnames, ArrayList nsNames,
\r
245 ValidationEventHandler h, XmlSchema schema);
\r
247 internal abstract void ValidateUniqueTypeAttribution (XmlSchemaObjectTable labels,
\r
248 ValidationEventHandler h, XmlSchema schema);
\r
250 // See http://www.thaiopensource.com/relaxng/simplify.html
\r
251 internal abstract void CheckRecursion (int depth, ValidationEventHandler h, XmlSchema schema);
\r
253 internal abstract bool ParticleEquals (XmlSchemaParticle other);
\r
255 #region Internal Class
\r
256 internal class EmptyParticle : XmlSchemaParticle
\r
258 internal EmptyParticle ()
\r
262 internal override XmlSchemaParticle GetOptimizedParticle (bool isTop)
\r
267 internal override bool ParticleEquals (XmlSchemaParticle other)
\r
269 return other == this || other == XmlSchemaParticle.Empty;
\r
272 internal override bool ValidateDerivationByRestriction (XmlSchemaParticle baseParticle,
\r
273 ValidationEventHandler h, XmlSchema schema, bool raiseError)
\r
278 internal override void CheckRecursion (int depth,
\r
279 ValidationEventHandler h, XmlSchema schema)
\r
284 internal override void ValidateUniqueParticleAttribution (XmlSchemaObjectTable qnames,
\r
285 ArrayList nsNames, ValidationEventHandler h, XmlSchema schema)
\r
290 internal override void ValidateUniqueTypeAttribution (XmlSchemaObjectTable labels,
\r
291 ValidationEventHandler h, XmlSchema schema)
\r