XmlSchemaSimpleContentRestriction.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 XmlSchemaSimpleContentRestriction.
  10. /// </summary>
  11. public class XmlSchemaSimpleContentRestriction : XmlSchemaContent
  12. {
  13. private XmlSchemaAnyAttribute any;
  14. private XmlSchemaObjectCollection attributes;
  15. private XmlSchemaSimpleType baseType;
  16. private XmlQualifiedName baseTypeName;
  17. private XmlSchemaObjectCollection facets;
  18. private int errorCount=0;
  19. public XmlSchemaSimpleContentRestriction()
  20. {
  21. baseTypeName = XmlQualifiedName.Empty;
  22. attributes = new XmlSchemaObjectCollection();
  23. facets = new XmlSchemaObjectCollection();
  24. }
  25. [System.Xml.Serialization.XmlAttribute("base")]
  26. public XmlQualifiedName BaseTypeName
  27. {
  28. get{ return baseTypeName; }
  29. set{ baseTypeName = value; }
  30. }
  31. [XmlElement("anyAttribute",Namespace="http://www.w3.org/2001/XMLSchema")]
  32. public XmlSchemaAnyAttribute AnyAttribute
  33. {
  34. get{ return any; }
  35. set{ any = value; }
  36. }
  37. [XmlElement("attribute",typeof(XmlSchemaAttribute),Namespace="http://www.w3.org/2001/XMLSchema")]
  38. [XmlElement("attributeGroup",typeof(XmlSchemaAttributeGroupRef),Namespace="http://www.w3.org/2001/XMLSchema")]
  39. public XmlSchemaObjectCollection Attributes
  40. {
  41. get{ return attributes; }
  42. }
  43. [XmlElement("simpleType",Namespace="http://www.w3.org/2001/XMLSchema")]
  44. public XmlSchemaSimpleType BaseType
  45. {
  46. get{ return baseType; }
  47. set{ baseType = value; }
  48. }
  49. [XmlElement("minExclusive",typeof(XmlSchemaMinExclusiveFacet),Namespace="http://www.w3.org/2001/XMLSchema")]
  50. [XmlElement("minInclusive",typeof(XmlSchemaMinInclusiveFacet),Namespace="http://www.w3.org/2001/XMLSchema")]
  51. [XmlElement("maxExclusive",typeof(XmlSchemaMaxExclusiveFacet),Namespace="http://www.w3.org/2001/XMLSchema")]
  52. [XmlElement("maxInclusive",typeof(XmlSchemaMaxInclusiveFacet),Namespace="http://www.w3.org/2001/XMLSchema")]
  53. [XmlElement("totalDigits",typeof(XmlSchemaTotalDigitsFacet),Namespace="http://www.w3.org/2001/XMLSchema")]
  54. [XmlElement("fractionDigits",typeof(XmlSchemaFractionDigitsFacet),Namespace="http://www.w3.org/2001/XMLSchema")]
  55. [XmlElement("length",typeof(XmlSchemaLengthFacet),Namespace="http://www.w3.org/2001/XMLSchema")]
  56. [XmlElement("minLength",typeof(XmlSchemaMinLengthFacet),Namespace="http://www.w3.org/2001/XMLSchema")]
  57. [XmlElement("maxLength",typeof(XmlSchemaMaxLengthFacet),Namespace="http://www.w3.org/2001/XMLSchema")]
  58. [XmlElement("enumeration",typeof(XmlSchemaEnumerationFacet),Namespace="http://www.w3.org/2001/XMLSchema")]
  59. [XmlElement("whiteSpace",typeof(XmlSchemaWhiteSpaceFacet),Namespace="http://www.w3.org/2001/XMLSchema")]
  60. [XmlElement("pattern",typeof(XmlSchemaPatternFacet),Namespace="http://www.w3.org/2001/XMLSchema")]
  61. public XmlSchemaObjectCollection Facets
  62. {
  63. get{ return facets; }
  64. }
  65. ///<remarks>
  66. /// 1. Base must be present and a QName
  67. ///</remarks>
  68. [MonoTODO]
  69. internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)
  70. {
  71. if(BaseTypeName == null || BaseTypeName.IsEmpty)
  72. {
  73. error(h, "base must be present and a QName");
  74. }
  75. if(BaseType != null)
  76. {
  77. errorCount += BaseType.Compile(h,info);
  78. }
  79. if(this.AnyAttribute != null)
  80. {
  81. errorCount += AnyAttribute.Compile(h,info);
  82. }
  83. foreach(XmlSchemaObject obj in Attributes)
  84. {
  85. if(obj is XmlSchemaAttribute)
  86. {
  87. XmlSchemaAttribute attr = (XmlSchemaAttribute) obj;
  88. errorCount += attr.Compile(h,info);
  89. }
  90. else if(obj is XmlSchemaAttributeGroupRef)
  91. {
  92. XmlSchemaAttributeGroupRef atgrp = (XmlSchemaAttributeGroupRef) obj;
  93. errorCount += atgrp.Compile(h,info);
  94. }
  95. else
  96. error(h,"object is not valid in this place");
  97. }
  98. //TODO: Compile Facets: Looks like they are a part of datatypes. So we'll do them with the datatypes
  99. if(this.Id != null && !XmlSchemaUtil.CheckID(Id))
  100. error(h, "id must be a valid ID");
  101. return errorCount;
  102. }
  103. [MonoTODO]
  104. internal int Validate(ValidationEventHandler h)
  105. {
  106. return errorCount;
  107. }
  108. internal void error(ValidationEventHandler handle,string message)
  109. {
  110. errorCount++;
  111. ValidationHandler.RaiseValidationError(handle,this,message);
  112. }
  113. }
  114. }