XmlSchemaSet.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. //
  2. // XmlSchemaSet.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // (C)2003 Atsushi Enomoto
  8. // (C)2004 Novell Inc.
  9. //
  10. using System;
  11. using System.Collections;
  12. using System.Collections.Specialized;
  13. using System.ComponentModel;
  14. using System.IO;
  15. using System.Security.Policy;
  16. using System.Xml.Schema;
  17. using System.Xml.XPath;
  18. namespace System.Xml.Schema
  19. {
  20. #if NET_2_0
  21. public class XmlSchemaSet
  22. #else
  23. internal class XmlSchemaSet
  24. #endif
  25. {
  26. XmlNameTable nameTable;
  27. XmlResolver xmlResolver;
  28. Hashtable schemas;
  29. XmlSchemaObjectTable attributes;
  30. XmlSchemaObjectTable elements;
  31. XmlSchemaObjectTable types;
  32. XmlSchemaCollection col;
  33. bool isCompiled;
  34. internal Guid CompilationId;
  35. public XmlSchemaSet () : this (new NameTable ())
  36. {
  37. }
  38. public XmlSchemaSet (XmlNameTable nameTable)
  39. {
  40. this.nameTable = nameTable;
  41. schemas = new Hashtable ();
  42. attributes = new XmlSchemaObjectTable ();
  43. elements = new XmlSchemaObjectTable ();
  44. types = new XmlSchemaObjectTable ();
  45. CompilationId = Guid.NewGuid ();
  46. }
  47. public event ValidationEventHandler ValidationEventHandler;
  48. public int Count {
  49. get { return schemas.Count; }
  50. }
  51. public XmlSchemaObjectTable GlobalAttributes {
  52. get { return attributes; }
  53. }
  54. public XmlSchemaObjectTable GlobalElements {
  55. get { return elements; }
  56. }
  57. public XmlSchemaObjectTable GlobalTypes {
  58. get { return types; }
  59. }
  60. public bool IsCompiled {
  61. get { return isCompiled; }
  62. }
  63. public XmlNameTable NameTable {
  64. get { return nameTable; }
  65. }
  66. // This is mainly used for event delegating
  67. internal XmlSchemaCollection SchemaCollection {
  68. get { return col; }
  69. set { col = value; }
  70. }
  71. public XmlResolver XmlResolver {
  72. set { xmlResolver = value; }
  73. }
  74. public XmlSchema Add (string targetNamespace, string url)
  75. {
  76. XmlTextReader r = null;
  77. try {
  78. r = new XmlTextReader (url);
  79. return Add (targetNamespace, r);
  80. } finally {
  81. if (r != null)
  82. r.Close ();
  83. }
  84. }
  85. [MonoTODO ("Check how targetNamespace is used")]
  86. public XmlSchema Add (string targetNamespace, XmlReader reader)
  87. {
  88. return Add (XmlSchema.Read (reader, null));
  89. }
  90. [MonoTODO ("Check the exact behavior when namespaces are in conflict")]
  91. public void Add (XmlSchemaSet schemaSet)
  92. {
  93. foreach (XmlSchema schema in schemaSet.schemas)
  94. schemas.Add (schema.TargetNamespace, schema);
  95. }
  96. [MonoTODO ("Check the exact behavior when namespaces are in conflict")]
  97. public XmlSchema Add (XmlSchema schema)
  98. {
  99. XmlSchema existing = schemas [GetSafeNs (schema.TargetNamespace)] as XmlSchema;
  100. if (existing != null)
  101. return existing;
  102. schemas.Add (GetSafeNs (schema.TargetNamespace), schema);
  103. return schema;
  104. }
  105. [MonoTODO]
  106. public void Compile ()
  107. {
  108. throw new NotImplementedException ();
  109. }
  110. public bool Contains (string targetNamespace)
  111. {
  112. return schemas.ContainsKey (targetNamespace);
  113. }
  114. public bool Contains (XmlSchema targetNamespace)
  115. {
  116. return schemas.Contains (targetNamespace);
  117. }
  118. public void CopyTo (XmlSchema[] array, int index)
  119. {
  120. schemas.CopyTo (array, index);
  121. }
  122. internal void CopyTo (Array array, int index)
  123. {
  124. schemas.CopyTo (array, index);
  125. }
  126. internal XmlSchema Get (string ns)
  127. {
  128. return (XmlSchema) schemas [GetSafeNs (ns)];
  129. }
  130. internal IEnumerator GetEnumerator ()
  131. {
  132. return schemas.GetEnumerator ();
  133. }
  134. string GetSafeNs (string ns)
  135. {
  136. return ns == null ? "" : ns;
  137. }
  138. internal void OnValidationError (object o, ValidationEventArgs e)
  139. {
  140. if (col != null)
  141. col.OnValidationError (o, e);
  142. if (ValidationEventHandler != null)
  143. ValidationEventHandler (o, e);
  144. else if (e.Severity == XmlSeverityType.Error)
  145. throw e.Exception;
  146. }
  147. [MonoTODO ("Check exact behavior")]
  148. public XmlSchema Remove (XmlSchema schema)
  149. {
  150. schemas.Remove (schema);
  151. return schema;
  152. }
  153. [MonoTODO]
  154. public bool RemoveRecursive (XmlSchema schema)
  155. {
  156. throw new NotImplementedException ();
  157. }
  158. [MonoTODO]
  159. public XmlSchema Reprocess (XmlSchema schema)
  160. {
  161. throw new NotImplementedException ();
  162. }
  163. public ArrayList Schemas ()
  164. {
  165. return new ArrayList (schemas.Values);
  166. }
  167. [MonoTODO]
  168. public ArrayList Schemas (string targetNamespace)
  169. {
  170. throw new NotImplementedException ();
  171. }
  172. }
  173. }