XmlSchemaComplexContentRestriction.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // Author: Dwivedi, Ajay kumar
  2. // [email protected]
  3. using System;
  4. using System.Xml;
  5. using System.Xml.Serialization;
  6. namespace System.Xml.Schema
  7. {
  8. /// <summary>
  9. /// Summary description for XmlSchemaComplexContentRestriction.
  10. /// </summary>
  11. public class XmlSchemaComplexContentRestriction : XmlSchemaContent
  12. {
  13. private XmlSchemaAnyAttribute any;
  14. private XmlSchemaObjectCollection attributes;
  15. private XmlQualifiedName baseTypeName;
  16. private XmlSchemaParticle particle;
  17. private int errorCount = 0;
  18. public XmlSchemaComplexContentRestriction()
  19. {
  20. baseTypeName = XmlQualifiedName.Empty;
  21. attributes = new XmlSchemaObjectCollection();
  22. }
  23. [System.Xml.Serialization.XmlAttribute("base")]
  24. public XmlQualifiedName BaseTypeName
  25. {
  26. get{ return baseTypeName; }
  27. set{ baseTypeName = value; }
  28. }
  29. [XmlElement("anyAttribute",Namespace="http://www.w3.org/2001/XMLSchema")]
  30. public XmlSchemaAnyAttribute AnyAttribute
  31. {
  32. get{ return any; }
  33. set{ any = value; }
  34. }
  35. [XmlElement("attribute",typeof(XmlSchemaAttribute),Namespace="http://www.w3.org/2001/XMLSchema")]
  36. [XmlElement("attributeGroup",typeof(XmlSchemaAttributeGroupRef),Namespace="http://www.w3.org/2001/XMLSchema")]
  37. public XmlSchemaObjectCollection Attributes
  38. {
  39. get{ return attributes; }
  40. }
  41. [XmlElement("group",typeof(XmlSchemaGroupRef),Namespace="http://www.w3.org/2001/XMLSchema")]
  42. [XmlElement("all",typeof(XmlSchemaAll),Namespace="http://www.w3.org/2001/XMLSchema")]
  43. [XmlElement("choice",typeof(XmlSchemaChoice),Namespace="http://www.w3.org/2001/XMLSchema")]
  44. [XmlElement("sequence",typeof(XmlSchemaSequence),Namespace="http://www.w3.org/2001/XMLSchema")]
  45. public XmlSchemaParticle Particle
  46. {
  47. get{ return particle; }
  48. set{ particle = value; }
  49. }
  50. /// <remarks>
  51. /// 1. base must be present
  52. /// </remarks>
  53. [MonoTODO]
  54. internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)
  55. {
  56. if(BaseTypeName == null || BaseTypeName.IsEmpty)
  57. {
  58. error(h, "base must be present and a QName");
  59. }
  60. if(this.AnyAttribute != null)
  61. {
  62. errorCount += AnyAttribute.Compile(h,info);
  63. }
  64. foreach(XmlSchemaObject obj in Attributes)
  65. {
  66. if(obj is XmlSchemaAttribute)
  67. {
  68. XmlSchemaAttribute attr = (XmlSchemaAttribute) obj;
  69. errorCount += attr.Compile(h,info);
  70. }
  71. else if(obj is XmlSchemaAttributeGroupRef)
  72. {
  73. XmlSchemaAttributeGroupRef atgrp = (XmlSchemaAttributeGroupRef) obj;
  74. errorCount += atgrp.Compile(h,info);
  75. }
  76. else
  77. error(h,"object is not valid in this place");
  78. }
  79. if(Particle != null)
  80. {
  81. if(Particle is XmlSchemaGroupRef)
  82. {
  83. errorCount += ((XmlSchemaGroupRef)Particle).Compile(h,info);
  84. }
  85. else if(Particle is XmlSchemaAll)
  86. {
  87. errorCount += ((XmlSchemaAll)Particle).Compile(h,info);
  88. }
  89. else if(Particle is XmlSchemaChoice)
  90. {
  91. errorCount += ((XmlSchemaChoice)Particle).Compile(h,info);
  92. }
  93. else if(Particle is XmlSchemaSequence)
  94. {
  95. errorCount += ((XmlSchemaSequence)Particle).Compile(h,info);
  96. }
  97. }
  98. if(this.Id != null && !XmlSchemaUtil.CheckID(Id))
  99. error(h, "id must be a valid ID");
  100. return errorCount;
  101. }
  102. [MonoTODO]
  103. internal int Validate(ValidationEventHandler h)
  104. {
  105. return errorCount;
  106. }
  107. internal void error(ValidationEventHandler handle,string message)
  108. {
  109. errorCount++;
  110. ValidationHandler.RaiseValidationError(handle,this,message);
  111. }
  112. }
  113. }