XmlSchemaCollection.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // Author: Dwivedi, Ajay kumar
  2. // [email protected]
  3. using System;
  4. using System.Collections;
  5. using System.Xml;
  6. namespace System.Xml.Schema
  7. {
  8. /// <summary>
  9. /// Summary description for XmlSchemaCollection.
  10. /// </summary>
  11. public sealed class XmlSchemaCollection : ICollection, IEnumerable
  12. {
  13. //private fields
  14. private Hashtable htable;
  15. private Hashtable uriTable;
  16. private XmlNameTable ntable;
  17. public XmlSchemaCollection()
  18. : this (new NameTable ())
  19. {
  20. }
  21. public XmlSchemaCollection(XmlNameTable nametable)
  22. {
  23. htable = new Hashtable();
  24. uriTable = new Hashtable ();
  25. ntable = nametable;
  26. }
  27. //properties
  28. public int Count
  29. {
  30. get
  31. {
  32. return this.htable.Count;
  33. }
  34. }
  35. public XmlNameTable NameTable
  36. {
  37. get
  38. {
  39. return this.ntable;
  40. }
  41. }
  42. public XmlSchema this[ string ns ]
  43. {
  44. get
  45. {
  46. return (XmlSchema) this.htable[GetSafeNs(ns)];
  47. }
  48. }
  49. // Events
  50. public event ValidationEventHandler ValidationEventHandler;
  51. // Methods
  52. [MonoTODO]
  53. public XmlSchema Add(string ns, XmlReader reader)
  54. {
  55. if (reader == null)
  56. throw new ArgumentNullException ("reader");
  57. XmlSchema schema = XmlSchema.Read (reader, ValidationEventHandler);
  58. return Add (schema);
  59. }
  60. [MonoTODO]
  61. public XmlSchema Add(string ns, string uri)
  62. {
  63. if (uri == null || uri == String.Empty)
  64. throw new ArgumentNullException ("uri");
  65. return Add (ns, new XmlTextReader (uri));
  66. }
  67. [MonoTODO]
  68. public XmlSchema Add(XmlSchema schema)
  69. {
  70. if (schema == null)
  71. throw new ArgumentNullException ("schema");
  72. htable [GetSafeNs(schema.TargetNamespace)] = schema;
  73. return schema;
  74. }
  75. public void Add(XmlSchemaCollection schema)
  76. {
  77. if (schema == null)
  78. throw new ArgumentNullException ("schema");
  79. foreach (XmlSchema s in schema)
  80. Add (s);
  81. }
  82. string GetSafeNs (string ns)
  83. {
  84. return ns == null ? "" : ns;
  85. }
  86. public bool Contains(string ns)
  87. {
  88. return this.htable.Contains(GetSafeNs(ns));
  89. }
  90. public bool Contains(XmlSchema schema)
  91. {
  92. return this.htable.Contains(GetSafeNs(schema.TargetNamespace));
  93. }
  94. public void CopyTo(XmlSchema[] array, int index)
  95. {
  96. throw new NotImplementedException ();
  97. }
  98. public XmlSchemaCollectionEnumerator GetEnumerator()
  99. {
  100. return new XmlSchemaCollectionEnumerator(this);
  101. }
  102. //assembly Methods
  103. [MonoTODO]
  104. void ICollection.CopyTo(Array array, int index)
  105. {
  106. throw new NotImplementedException ();
  107. }
  108. bool ICollection.IsSynchronized
  109. {
  110. get { return false; }
  111. }
  112. IEnumerator IEnumerable.GetEnumerator()
  113. {
  114. return this.htable.GetEnumerator();
  115. }
  116. Object ICollection.SyncRoot
  117. {
  118. get { return this; }
  119. }
  120. }
  121. }