XmlSchemaIdentityConstraint.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // Author: Dwivedi, Ajay kumar
  2. // [email protected]
  3. using System;
  4. using System.Collections;
  5. using System.Xml;
  6. using System.Xml.Serialization;
  7. using Mono.Xml.Schema;
  8. namespace System.Xml.Schema
  9. {
  10. /// <summary>
  11. /// Summary description for XmlSchemaIdentityConstraint.
  12. /// </summary>
  13. public class XmlSchemaIdentityConstraint : XmlSchemaAnnotated
  14. {
  15. private XmlSchemaObjectCollection fields;
  16. private string name;
  17. private XmlQualifiedName qName;
  18. private XmlSchemaXPath selector;
  19. private XsdIdentitySelector compiledSelector;
  20. // ArrayList compiledFields;
  21. public XmlSchemaIdentityConstraint()
  22. {
  23. fields = new XmlSchemaObjectCollection();
  24. qName = XmlQualifiedName.Empty;
  25. }
  26. [System.Xml.Serialization.XmlAttribute("name")]
  27. public string Name
  28. {
  29. get{ return name; }
  30. set{ name = value; }
  31. }
  32. [XmlElement("selector",typeof(XmlSchemaXPath),Namespace=XmlSchema.Namespace)]
  33. public XmlSchemaXPath Selector
  34. {
  35. get{ return selector; }
  36. set{ selector = value; }
  37. }
  38. [XmlElement("field",typeof(XmlSchemaXPath),Namespace=XmlSchema.Namespace)]
  39. public XmlSchemaObjectCollection Fields
  40. {
  41. get{ return fields; }
  42. }
  43. [XmlIgnore]
  44. public XmlQualifiedName QualifiedName
  45. {
  46. get{ return qName; }
  47. }
  48. internal XsdIdentitySelector CompiledSelector {
  49. get { return compiledSelector; }
  50. }
  51. /// <remarks>
  52. /// 1. name must be present
  53. /// 2. selector and field must be present
  54. /// </remarks>
  55. [MonoTODO]
  56. internal override int Compile(ValidationEventHandler h, XmlSchema schema)
  57. {
  58. // If this is already compiled this time, simply skip.
  59. if (this.IsComplied (schema.CompilationId))
  60. return 0;
  61. if(Name == null)
  62. error(h,"Required attribute name must be present");
  63. else if(!XmlSchemaUtil.CheckNCName(this.name))
  64. error(h,"attribute name must be NCName");
  65. else {
  66. this.qName = new XmlQualifiedName(Name,schema.TargetNamespace);
  67. if (schema.NamedIdentities.Contains (qName))
  68. error(h,"There is already same named identity constraint in this namespace.");
  69. else
  70. schema.NamedIdentities.Add (qName, this);
  71. }
  72. if(Selector == null)
  73. error(h,"selector must be present");
  74. else
  75. {
  76. Selector.isSelector = true;
  77. errorCount += Selector.Compile(h,schema);
  78. if (selector.errorCount == 0)
  79. compiledSelector = new XsdIdentitySelector (Selector);
  80. }
  81. if (errorCount > 0)
  82. return errorCount; // fatal
  83. if(Fields.Count == 0)
  84. error(h,"atleast one field value must be present");
  85. else
  86. {
  87. for (int i = 0; i < Fields.Count; i++)
  88. {
  89. XmlSchemaXPath field = Fields [i] as XmlSchemaXPath;
  90. if(field != null)
  91. {
  92. errorCount += field.Compile(h,schema);
  93. if (field.errorCount == 0)
  94. this.compiledSelector.AddField (new XsdIdentityField (field, i));
  95. }
  96. else
  97. error (h, "Object of type " + Fields [i].GetType() + " is invalid in the Fields Collection");
  98. }
  99. }
  100. XmlSchemaUtil.CompileID(Id,this,schema.IDCollection,h);
  101. this.CompilationId = schema.CompilationId;
  102. return errorCount;
  103. }
  104. }
  105. }