XmlSchemaSet.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. using System;
  31. using System.Collections;
  32. using System.Collections.Specialized;
  33. using System.ComponentModel;
  34. using System.IO;
  35. using System.Security.Policy;
  36. using System.Xml.Schema;
  37. using System.Xml.XPath;
  38. namespace System.Xml.Schema
  39. {
  40. #if NET_2_0
  41. public class XmlSchemaSet
  42. #else
  43. internal class XmlSchemaSet
  44. #endif
  45. {
  46. XmlNameTable nameTable;
  47. XmlResolver xmlResolver;
  48. Hashtable schemas;
  49. XmlSchemaObjectTable attributes;
  50. XmlSchemaObjectTable elements;
  51. XmlSchemaObjectTable types;
  52. XmlSchemaCollection col;
  53. bool isCompiled;
  54. internal Guid CompilationId;
  55. public XmlSchemaSet () : this (new NameTable ())
  56. {
  57. }
  58. public XmlSchemaSet (XmlNameTable nameTable)
  59. {
  60. this.nameTable = nameTable;
  61. schemas = new Hashtable ();
  62. attributes = new XmlSchemaObjectTable ();
  63. elements = new XmlSchemaObjectTable ();
  64. types = new XmlSchemaObjectTable ();
  65. CompilationId = Guid.NewGuid ();
  66. }
  67. public event ValidationEventHandler ValidationEventHandler;
  68. public int Count {
  69. get { return schemas.Count; }
  70. }
  71. public XmlSchemaObjectTable GlobalAttributes {
  72. get { return attributes; }
  73. }
  74. public XmlSchemaObjectTable GlobalElements {
  75. get { return elements; }
  76. }
  77. public XmlSchemaObjectTable GlobalTypes {
  78. get { return types; }
  79. }
  80. public bool IsCompiled {
  81. get { return isCompiled; }
  82. }
  83. public XmlNameTable NameTable {
  84. get { return nameTable; }
  85. }
  86. // This is mainly used for event delegating
  87. internal XmlSchemaCollection SchemaCollection {
  88. get { return col; }
  89. set { col = value; }
  90. }
  91. public XmlResolver XmlResolver {
  92. set { xmlResolver = value; }
  93. }
  94. public XmlSchema Add (string targetNamespace, string url)
  95. {
  96. XmlTextReader r = null;
  97. try {
  98. r = new XmlTextReader (url);
  99. return Add (targetNamespace, r);
  100. } finally {
  101. if (r != null)
  102. r.Close ();
  103. }
  104. }
  105. [MonoTODO ("Check how targetNamespace is used")]
  106. public XmlSchema Add (string targetNamespace, XmlReader reader)
  107. {
  108. return Add (XmlSchema.Read (reader, null));
  109. }
  110. [MonoTODO ("Check the exact behavior when namespaces are in conflict")]
  111. public void Add (XmlSchemaSet schemaSet)
  112. {
  113. foreach (XmlSchema schema in schemaSet.schemas)
  114. schemas.Add (schema.TargetNamespace, schema);
  115. }
  116. [MonoTODO ("Check the exact behavior when namespaces are in conflict")]
  117. public XmlSchema Add (XmlSchema schema)
  118. {
  119. XmlSchema existing = schemas [GetSafeNs (schema.TargetNamespace)] as XmlSchema;
  120. if (existing != null)
  121. return existing;
  122. schemas.Add (GetSafeNs (schema.TargetNamespace), schema);
  123. return schema;
  124. }
  125. [MonoTODO]
  126. public void Compile ()
  127. {
  128. throw new NotImplementedException ();
  129. }
  130. public bool Contains (string targetNamespace)
  131. {
  132. return schemas.ContainsKey (targetNamespace);
  133. }
  134. public bool Contains (XmlSchema targetNamespace)
  135. {
  136. return schemas.Contains (targetNamespace);
  137. }
  138. public void CopyTo (XmlSchema[] array, int index)
  139. {
  140. schemas.CopyTo (array, index);
  141. }
  142. internal void CopyTo (Array array, int index)
  143. {
  144. schemas.CopyTo (array, index);
  145. }
  146. internal XmlSchema Get (string ns)
  147. {
  148. return (XmlSchema) schemas [GetSafeNs (ns)];
  149. }
  150. internal IEnumerator GetEnumerator ()
  151. {
  152. return schemas.GetEnumerator ();
  153. }
  154. string GetSafeNs (string ns)
  155. {
  156. return ns == null ? "" : ns;
  157. }
  158. internal void OnValidationError (object o, ValidationEventArgs e)
  159. {
  160. if (col != null)
  161. col.OnValidationError (o, e);
  162. if (ValidationEventHandler != null)
  163. ValidationEventHandler (o, e);
  164. else if (e.Severity == XmlSeverityType.Error)
  165. throw e.Exception;
  166. }
  167. [MonoTODO ("Check exact behavior")]
  168. public XmlSchema Remove (XmlSchema schema)
  169. {
  170. schemas.Remove (schema);
  171. return schema;
  172. }
  173. [MonoTODO]
  174. public bool RemoveRecursive (XmlSchema schema)
  175. {
  176. throw new NotImplementedException ();
  177. }
  178. [MonoTODO]
  179. public XmlSchema Reprocess (XmlSchema schema)
  180. {
  181. throw new NotImplementedException ();
  182. }
  183. public ArrayList Schemas ()
  184. {
  185. return new ArrayList (schemas.Values);
  186. }
  187. [MonoTODO]
  188. public ArrayList Schemas (string targetNamespace)
  189. {
  190. throw new NotImplementedException ();
  191. }
  192. }
  193. }