1 // Author: Dwivedi, Ajay kumar
\r
4 using System.Collections;
\r
5 using System.Xml.Serialization;
\r
7 namespace System.Xml.Schema
\r
10 /// Summary description for XmlSchemaParticle.
\r
12 public abstract class XmlSchemaParticle : XmlSchemaAnnotated
\r
14 internal static XmlSchemaParticle Empty {
\r
16 if (empty == null) {
\r
17 empty = new EmptyParticle ();
\r
23 decimal minOccurs, maxOccurs;
\r
24 string minstr, maxstr;
\r
25 static XmlSchemaParticle empty;
\r
26 decimal validatedMinOccurs = 1, validatedMaxOccurs = 1;
\r
27 internal int recursionDepth = -1;
\r
28 private decimal minEffectiveTotalRange = -1;
\r
29 internal bool parentIsGroupDefinition;
\r
31 protected XmlSchemaParticle()
\r
33 minOccurs = decimal.One;
\r
34 maxOccurs = decimal.One;
\r
39 [System.Xml.Serialization.XmlAttribute("minOccurs")]
\r
40 public string MinOccursString
\r
42 get{ return minstr; }
\r
45 if (value == null) {
\r
46 minOccurs = decimal.One;
\r
51 decimal val = decimal.Parse(value);
\r
52 if(val >= 0 && (val == Decimal.Truncate(val)))
\r
55 minstr = val.ToString();
\r
59 throw new XmlSchemaException
\r
60 ("MinOccursString must be a non-negative number",null);
\r
65 [System.Xml.Serialization.XmlAttribute("maxOccurs")]
\r
66 public string MaxOccursString
\r
68 get{ return maxstr; }
\r
71 if(value == "unbounded")
\r
74 maxOccurs = decimal.MaxValue;
\r
78 decimal val = decimal.Parse(value);
\r
79 if(val >= 0 && (val == Decimal.Truncate(val)))
\r
82 maxstr = val.ToString();
\r
86 throw new XmlSchemaException
\r
87 ("MaxOccurs must be a non-negative integer",null);
\r
89 if (val == 0 && minstr == null)
\r
100 public decimal MinOccurs
\r
102 get{ return minOccurs; }
\r
105 MinOccursString = value.ToString ();
\r
110 public decimal MaxOccurs
\r
112 get{ return maxOccurs; }
\r
115 MaxOccursString = value.ToString ();
\r
119 internal decimal ValidatedMinOccurs
\r
121 get { return validatedMinOccurs; }
\r
124 internal decimal ValidatedMaxOccurs
\r
126 get { return validatedMaxOccurs; }
\r
130 internal XmlSchemaParticle OptimizedParticle;
\r
132 internal abstract XmlSchemaParticle GetOptimizedParticle (bool isTop);
\r
134 internal XmlSchemaParticle GetShallowClone ()
\r
136 return (XmlSchemaParticle) MemberwiseClone ();
\r
139 internal void CompileOccurence (ValidationEventHandler h, XmlSchema schema)
\r
141 if (MinOccurs > MaxOccurs && !(MaxOccurs == 0 && MinOccursString == null))
\r
142 error(h,"minOccurs must be less than or equal to maxOccurs");
\r
144 if (MaxOccursString == "unbounded")
\r
145 this.validatedMaxOccurs = decimal.MaxValue;
\r
147 this.validatedMaxOccurs = maxOccurs;
\r
148 if (this.validatedMaxOccurs == 0)
\r
149 this.validatedMinOccurs = 0;
\r
151 this.validatedMinOccurs = minOccurs;
\r
155 internal override void CopyInfo (XmlSchemaParticle obj)
\r
157 base.CopyInfo (obj);
\r
158 if (MaxOccursString == "unbounded")
\r
159 obj.maxOccurs = obj.validatedMaxOccurs = decimal.MaxValue;
\r
161 obj.maxOccurs = obj.validatedMaxOccurs = this.ValidatedMaxOccurs;
\r
162 if (MaxOccurs == 0)
\r
163 obj.minOccurs = obj.validatedMinOccurs = 0;
\r
165 obj.minOccurs = obj.validatedMinOccurs = this.ValidatedMinOccurs;
\r
166 if (MinOccursString != null)
\r
167 obj.MinOccursString = MinOccursString;
\r
168 if (MaxOccursString != null)
\r
169 obj.MaxOccursString = MaxOccursString;
\r
172 internal virtual bool ValidateOccurenceRangeOK (XmlSchemaParticle other,
\r
173 ValidationEventHandler h, XmlSchema schema, bool raiseError)
\r
175 if ((this.ValidatedMinOccurs < other.ValidatedMinOccurs) ||
\r
176 (other.ValidatedMaxOccurs != decimal.MaxValue &&
\r
177 this.ValidatedMaxOccurs > other.ValidatedMaxOccurs)) {
\r
179 error (h, "Invalid derivation occurence range was found.");
\r
185 internal virtual decimal GetMinEffectiveTotalRange ()
\r
187 return ValidatedMinOccurs;
\r
190 internal decimal GetMinEffectiveTotalRangeAllAndSequence ()
\r
192 if (minEffectiveTotalRange >= 0)
\r
193 return minEffectiveTotalRange;
\r
195 decimal product = 0; //this.ValidatedMinOccurs;
\r
196 XmlSchemaObjectCollection col = null;
\r
197 if (this is XmlSchemaAll)
\r
198 col = ((XmlSchemaAll) this).Items;
\r
200 col = ((XmlSchemaSequence) this).Items;
\r
201 foreach (XmlSchemaParticle p in col)
\r
202 product += p.GetMinEffectiveTotalRange ();
\r
204 minEffectiveTotalRange = product;
\r
208 // 3.9.6 Particle Emptiable
\r
209 internal virtual bool ValidateIsEmptiable ()
\r
211 return this.validatedMinOccurs == 0 || this.GetMinEffectiveTotalRange () == 0;
\r
214 internal abstract bool ValidateDerivationByRestriction (XmlSchemaParticle baseParticle,
\r
215 ValidationEventHandler h, XmlSchema schema, bool raiseError);
\r
217 internal abstract void ValidateUniqueParticleAttribution (
\r
218 XmlSchemaObjectTable qnames, ArrayList nsNames,
\r
219 ValidationEventHandler h, XmlSchema schema);
\r
221 internal abstract void ValidateUniqueTypeAttribution (XmlSchemaObjectTable labels,
\r
222 ValidationEventHandler h, XmlSchema schema);
\r
224 // See http://www.thaiopensource.com/relaxng/simplify.html
\r
225 internal abstract void CheckRecursion (int depth, ValidationEventHandler h, XmlSchema schema);
\r
227 internal abstract bool ParticleEquals (XmlSchemaParticle other);
\r
229 #region Internal Class
\r
230 internal class EmptyParticle : XmlSchemaParticle
\r
232 internal EmptyParticle ()
\r
236 internal override XmlSchemaParticle GetOptimizedParticle (bool isTop)
\r
241 internal override bool ParticleEquals (XmlSchemaParticle other)
\r
243 return other == this || other == XmlSchemaParticle.Empty;
\r
246 internal override bool ValidateDerivationByRestriction (XmlSchemaParticle baseParticle,
\r
247 ValidationEventHandler h, XmlSchema schema, bool raiseError)
\r
252 internal override void CheckRecursion (int depth,
\r
253 ValidationEventHandler h, XmlSchema schema)
\r
258 internal override void ValidateUniqueParticleAttribution (XmlSchemaObjectTable qnames,
\r
259 ArrayList nsNames, ValidationEventHandler h, XmlSchema schema)
\r
264 internal override void ValidateUniqueTypeAttribution (XmlSchemaObjectTable labels,
\r
265 ValidationEventHandler h, XmlSchema schema)
\r