XmlSchemaIdentityConstraint.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 XmlSchemaIdentityConstraint.
  10. /// </summary>
  11. public class XmlSchemaIdentityConstraint : XmlSchemaAnnotated
  12. {
  13. private XmlSchemaObjectCollection fields;
  14. private string name;
  15. private XmlQualifiedName qName;
  16. private XmlSchemaXPath selector;
  17. public XmlSchemaIdentityConstraint()
  18. {
  19. fields = new XmlSchemaObjectCollection();
  20. qName = XmlQualifiedName.Empty;
  21. }
  22. [System.Xml.Serialization.XmlAttribute("name")]
  23. public string Name
  24. {
  25. get{ return name; }
  26. set{ name = value; }
  27. }
  28. [XmlElement("selector",typeof(XmlSchemaXPath),Namespace="http://www.w3.org/2001/XMLSchema")]
  29. public XmlSchemaXPath Selector
  30. {
  31. get{ return selector; }
  32. set{ selector = value; }
  33. }
  34. [XmlElement("field",typeof(XmlSchemaXPath),Namespace="http://www.w3.org/2001/XMLSchema")]
  35. public XmlSchemaObjectCollection Fields
  36. {
  37. get{ return fields; }
  38. }
  39. [XmlIgnore]
  40. public XmlQualifiedName QualifiedName
  41. {
  42. get{ return qName; }
  43. }
  44. /// <remarks>
  45. /// 1. name must be present
  46. /// 2. selector and field must be present
  47. /// </remarks>
  48. [MonoTODO]
  49. internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)
  50. {
  51. if(Name == null)
  52. error(h,"Required attribute name must be present");
  53. else if(!XmlSchemaUtil.CheckNCName(this.name))
  54. error(h,"attribute name must be NCName");
  55. else
  56. this.qName = new XmlQualifiedName(Name,info.TargetNamespace);
  57. //TODO: Compile Xpath.
  58. if(Selector == null)
  59. error(h,"selector must be present");
  60. else
  61. {
  62. errorCount += Selector.Compile(h,info);
  63. }
  64. if(Fields.Count == 0)
  65. error(h,"atleast one field value must be present");
  66. else
  67. {
  68. foreach(XmlSchemaObject obj in Fields)
  69. {
  70. if(obj is XmlSchemaXPath)
  71. {
  72. XmlSchemaXPath field = (XmlSchemaXPath)obj;
  73. errorCount += field.Compile(h,info);
  74. }
  75. else
  76. error(h,"Object of type "+obj.GetType()+" is invalid in the Fields Collection");
  77. }
  78. }
  79. XmlSchemaUtil.CompileID(Id,this,info.IDCollection,h);
  80. return errorCount;
  81. }
  82. }
  83. }