XmlSchemaGroupBase.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //
  2. // XmlSchemaGroupBase.cs
  3. //
  4. // Authors:
  5. // Dwivedi, Ajay kumar [email protected]
  6. // Atsushi Enomoto [email protected]
  7. //
  8. using System;
  9. using System.Xml.Serialization;
  10. namespace System.Xml.Schema
  11. {
  12. public abstract class XmlSchemaGroupBase : XmlSchemaParticle
  13. {
  14. private XmlSchemaObjectCollection compiledItems;
  15. protected XmlSchemaGroupBase ()
  16. {
  17. compiledItems = new XmlSchemaObjectCollection ();
  18. }
  19. [XmlIgnore]
  20. public abstract XmlSchemaObjectCollection Items { get; }
  21. internal XmlSchemaObjectCollection CompiledItems
  22. {
  23. get{ return compiledItems; }
  24. }
  25. internal override bool ParticleEquals (XmlSchemaParticle other)
  26. {
  27. XmlSchemaGroupBase gb = other as XmlSchemaGroupBase;
  28. if (gb == null)
  29. return false;
  30. if (this.GetType () != gb.GetType ())
  31. return false;
  32. if (this.ValidatedMaxOccurs != gb.ValidatedMaxOccurs ||
  33. this.ValidatedMinOccurs != gb.ValidatedMinOccurs)
  34. return false;
  35. if (this.CompiledItems.Count != gb.CompiledItems.Count)
  36. return false;
  37. for (int i = 0; i < CompiledItems.Count; i++) {
  38. XmlSchemaParticle p1 = this.CompiledItems [i] as XmlSchemaParticle;
  39. XmlSchemaParticle p2 = gb.CompiledItems [i] as XmlSchemaParticle;
  40. if (!p1.ParticleEquals (p2))
  41. return false;
  42. }
  43. return true;
  44. }
  45. internal override void CheckRecursion (int depth, ValidationEventHandler h, XmlSchema schema)
  46. {
  47. foreach (XmlSchemaParticle p in this.Items)
  48. p.CheckRecursion (depth, h, schema);
  49. }
  50. internal void ValidateNSRecurseCheckCardinality (XmlSchemaAny any,
  51. ValidationEventHandler h, XmlSchema schema)
  52. {
  53. foreach (XmlSchemaParticle p in Items)
  54. p.ValidateDerivationByRestriction (any, h, schema);
  55. ValidateOccurenceRangeOK (any, h, schema);
  56. }
  57. internal void ValidateRecurse (XmlSchemaGroupBase baseGroup,
  58. ValidationEventHandler h, XmlSchema schema)
  59. {
  60. int index = 0;
  61. for (int i = 0; i < baseGroup.CompiledItems.Count; i++) {
  62. XmlSchemaParticle pb = ((XmlSchemaParticle) baseGroup.CompiledItems [i]).ActualParticle;
  63. if (pb == XmlSchemaParticle.Empty)
  64. continue;
  65. XmlSchemaParticle pd = null;
  66. while (this.CompiledItems.Count > index) {
  67. pd = ((XmlSchemaParticle) this.CompiledItems [index]).ActualParticle;
  68. index++;
  69. if (pd != XmlSchemaParticle.Empty)
  70. break;
  71. }
  72. ValidateParticleSection (ref index, pd, pb, h, schema);
  73. }
  74. if (this.compiledItems.Count > 0 && index != this.CompiledItems.Count)
  75. error (h, "Invalid particle derivation by restriction was found. Extraneous derived particle was found.");
  76. }
  77. private void ValidateParticleSection (ref int index, XmlSchemaParticle pd, XmlSchemaParticle pb, ValidationEventHandler h, XmlSchema schema)
  78. {
  79. if (pd == pb) // they are same particle
  80. return;
  81. if (pd != null) {
  82. try {
  83. XmlSchemaElement el = pd as XmlSchemaElement;
  84. XmlSchemaParticle pdx = pd;
  85. if (el != null && el.SubstitutingElements.Count > 0)
  86. pdx = el.SubstitutingChoice;
  87. pdx.ValidateDerivationByRestriction (pb, h, schema);
  88. } catch (XmlSchemaException ex) {
  89. if (!pb.ValidateIsEmptiable ())
  90. error (h, "Invalid particle derivation by restriction was found. Invalid sub-particle derivation was found.", ex);
  91. else
  92. index--; // try the same derived particle and next base particle.
  93. }
  94. } else if (!pb.ValidateIsEmptiable ()) {
  95. 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.");
  96. return;
  97. }
  98. }
  99. }
  100. }