XmlSchemas.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. //
  2. // System.Xml.Serialization.XmlSchemas
  3. //
  4. // Author:
  5. // Tim Coleman ([email protected])
  6. //
  7. // Copyright (C) Tim Coleman, 2002
  8. //
  9. using System.Collections;
  10. using System.Xml.Schema;
  11. namespace System.Xml.Serialization {
  12. public class XmlSchemas : CollectionBase {
  13. #region Fields
  14. Hashtable table = new Hashtable ();
  15. #endregion
  16. #region Constructors
  17. public XmlSchemas ()
  18. {
  19. }
  20. #endregion // Constructors
  21. #region Properties
  22. public XmlSchema this [int index] {
  23. get {
  24. if (index < 0 || index > Count)
  25. throw new ArgumentOutOfRangeException ();
  26. return (XmlSchema) List [index];
  27. }
  28. set { List [index] = value; }
  29. }
  30. public XmlSchema this [string ns] {
  31. get { return (XmlSchema) table[ns]; }
  32. }
  33. #endregion // Properties
  34. #region Methods
  35. public int Add (XmlSchema schema)
  36. {
  37. Insert (Count, schema);
  38. return (Count - 1);
  39. }
  40. public void Add (XmlSchemas schemas)
  41. {
  42. foreach (XmlSchema schema in schemas)
  43. Add (schema);
  44. }
  45. public bool Contains (XmlSchema schema)
  46. {
  47. return List.Contains (schema);
  48. }
  49. public void CopyTo (XmlSchema[] array, int index)
  50. {
  51. List.CopyTo (array, index);
  52. }
  53. public object Find (XmlQualifiedName name, Type type)
  54. {
  55. XmlSchema schema = table [name.Namespace] as XmlSchema;
  56. if (schema == null)
  57. return null;
  58. if (!schema.IsCompiled) {
  59. try {
  60. schema.Compile (null);
  61. } catch {
  62. throw new InvalidOperationException ("Error compiling XmlSchema " +
  63. name.Namespace);
  64. }
  65. }
  66. XmlSchemaObjectTable tbl = null;
  67. if (type == typeof (XmlSchemaSimpleType) || type == typeof (XmlSchemaComplexType))
  68. tbl = schema.SchemaTypes;
  69. else if (type == typeof (XmlSchemaAttribute))
  70. tbl = schema.Attributes;
  71. else if (type == typeof (XmlSchemaAttributeGroup))
  72. tbl = schema.AttributeGroups;
  73. else if (type == typeof (XmlSchemaElement))
  74. tbl = schema.Elements;
  75. else if (type == typeof (XmlSchemaGroup))
  76. tbl = schema.Groups;
  77. else if (type == typeof (XmlSchemaNotation))
  78. tbl = schema.Notations;
  79. return (tbl != null) ? tbl [name] : null;
  80. }
  81. public int IndexOf (XmlSchema schema)
  82. {
  83. return List.IndexOf (schema);
  84. }
  85. public void Insert (int index, XmlSchema schema)
  86. {
  87. List.Insert (index, schema);
  88. }
  89. [MonoTODO]
  90. public static bool IsDataSet (XmlSchema schema)
  91. {
  92. throw new NotImplementedException ();
  93. }
  94. protected override void OnClear ()
  95. {
  96. table.Clear ();
  97. }
  98. protected override void OnInsert (int index, object value)
  99. {
  100. table [((XmlSchema) value).TargetNamespace] = value;
  101. }
  102. protected override void OnRemove (int index, object value)
  103. {
  104. table.Remove (value);
  105. }
  106. protected override void OnSet (int index, object oldValue, object newValue)
  107. {
  108. table [((XmlSchema) oldValue).TargetNamespace] = newValue;
  109. }
  110. public void Remove (XmlSchema schema)
  111. {
  112. List.Remove (schema);
  113. }
  114. #endregion // Methods
  115. }
  116. }