XmlSchemaSet.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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_1_2
  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. public void Compile ()
  106. {
  107. throw new NotImplementedException ();
  108. }
  109. public bool Contains (string targetNamespace)
  110. {
  111. return schemas.ContainsKey (targetNamespace);
  112. }
  113. public bool Contains (XmlSchema targetNamespace)
  114. {
  115. return schemas.Contains (targetNamespace);
  116. }
  117. public void CopyTo (XmlSchema[] array, int index)
  118. {
  119. schemas.CopyTo (array, index);
  120. }
  121. internal void CopyTo (Array array, int index)
  122. {
  123. schemas.CopyTo (array, index);
  124. }
  125. internal XmlSchema Get (string ns)
  126. {
  127. return (XmlSchema) schemas [GetSafeNs (ns)];
  128. }
  129. internal IEnumerator GetEnumerator()
  130. {
  131. return schemas.GetEnumerator();
  132. }
  133. string GetSafeNs (string ns)
  134. {
  135. return ns == null ? "" : ns;
  136. }
  137. internal void OnValidationError (object o, ValidationEventArgs e)
  138. {
  139. if (col != null)
  140. col.OnValidationError (o, e);
  141. if (ValidationEventHandler != null)
  142. ValidationEventHandler (o, e);
  143. else if (e.Severity == XmlSeverityType.Error)
  144. throw e.Exception;
  145. }
  146. [MonoTODO ("Check exact behavior")]
  147. public XmlSchema Remove (XmlSchema schema)
  148. {
  149. schemas.Remove (schema);
  150. return schema;
  151. }
  152. public ArrayList Schemas ()
  153. {
  154. return new ArrayList (schemas);
  155. }
  156. [MonoTODO]
  157. public ArrayList Schemas (string targetNamespace)
  158. {
  159. throw new NotImplementedException ();
  160. }
  161. }
  162. }