XmlSchemaGroupBase.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Author: Dwivedi, Ajay kumar
  2. // [email protected]
  3. using System;
  4. using System.Xml.Serialization;
  5. namespace System.Xml.Schema
  6. {
  7. /// <summary>
  8. /// Summary description for XmlSchemaGroupBase.
  9. /// </summary>
  10. public abstract class XmlSchemaGroupBase : XmlSchemaParticle
  11. {
  12. private XmlSchemaObjectCollection compiledItems;
  13. protected XmlSchemaGroupBase()
  14. {
  15. compiledItems = new XmlSchemaObjectCollection ();
  16. }
  17. [XmlIgnore]
  18. public abstract XmlSchemaObjectCollection Items { get; }
  19. internal XmlSchemaObjectCollection CompiledItems
  20. {
  21. get{ return compiledItems; }
  22. }
  23. internal override bool ParticleEquals (XmlSchemaParticle other)
  24. {
  25. XmlSchemaChoice choice = other as XmlSchemaChoice;
  26. if (choice == null)
  27. return false;
  28. if (this.ValidatedMaxOccurs != choice.ValidatedMaxOccurs ||
  29. this.ValidatedMinOccurs != choice.ValidatedMinOccurs)
  30. return false;
  31. if (this.CompiledItems.Count != choice.CompiledItems.Count)
  32. return false;
  33. for (int i = 0; i < CompiledItems.Count; i++) {
  34. XmlSchemaParticle p1 = this.CompiledItems [i] as XmlSchemaParticle;
  35. XmlSchemaParticle p2 = choice.CompiledItems [i] as XmlSchemaParticle;
  36. if (!p1.ParticleEquals (p2))
  37. return false;
  38. }
  39. return true;
  40. }
  41. internal void ValidateNSRecurseCheckCardinality (XmlSchemaAny any,
  42. ValidationEventHandler h, XmlSchema schema)
  43. {
  44. foreach (XmlSchemaParticle p in Items)
  45. p.ValidateDerivationByRestriction (any, h, schema);
  46. ValidateOccurenceRangeOK (any, h, schema);
  47. }
  48. internal void ValidateRecurse (XmlSchemaGroupBase baseGroup,
  49. ValidationEventHandler h, XmlSchema schema)
  50. {
  51. int index = 0;
  52. for (int i = 0; i < baseGroup.CompiledItems.Count; i++) {
  53. XmlSchemaParticle pb = baseGroup.CompiledItems [i] as XmlSchemaParticle;
  54. if (pb.ActualParticle == XmlSchemaParticle.Empty)
  55. continue;
  56. XmlSchemaParticle pd = null;
  57. while (this.CompiledItems.Count > index) {
  58. pd = this.CompiledItems [index] as XmlSchemaParticle;
  59. index++;
  60. if (pd.ActualParticle != XmlSchemaParticle.Empty)
  61. break;
  62. }
  63. if (pd != null) {
  64. try {
  65. pd.ActualParticle.ValidateDerivationByRestriction (pb.ActualParticle, h, schema);
  66. } catch (XmlSchemaException ex) {
  67. if (!pb.ValidateIsEmptiable ())
  68. error (h, "Invalid particle derivation by restriction was found. Invalid sub-particle derivation was found.", ex);
  69. else
  70. index--; // try the same derived particle and next base particle.
  71. }
  72. } else if (!pb.ValidateIsEmptiable ()) {
  73. error (h, "Invalid particle derivation by restriction was found. Base schema particle has non-emptiable sub particle that is not mapped to the derived particle.");
  74. return;
  75. }
  76. }
  77. if (index != this.CompiledItems.Count)
  78. error (h, "Invalid particle derivation by restriction was found. Extraneous derived particle was found.");
  79. }
  80. }
  81. }