XmlSchemas.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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!=null?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. schema.Compile (null);
  60. }
  61. XmlSchemaObjectTable tbl = null;
  62. if (type == typeof (XmlSchemaSimpleType) || type == typeof (XmlSchemaComplexType))
  63. tbl = schema.SchemaTypes;
  64. else if (type == typeof (XmlSchemaAttribute))
  65. tbl = schema.Attributes;
  66. else if (type == typeof (XmlSchemaAttributeGroup))
  67. tbl = schema.AttributeGroups;
  68. else if (type == typeof (XmlSchemaElement))
  69. tbl = schema.Elements;
  70. else if (type == typeof (XmlSchemaGroup))
  71. tbl = schema.Groups;
  72. else if (type == typeof (XmlSchemaNotation))
  73. tbl = schema.Notations;
  74. object res = (tbl != null) ? tbl [name] : null;
  75. if (res != null && res.GetType () != type) return null;
  76. else return res;
  77. }
  78. public int IndexOf (XmlSchema schema)
  79. {
  80. return List.IndexOf (schema);
  81. }
  82. public void Insert (int index, XmlSchema schema)
  83. {
  84. List.Insert (index, schema);
  85. }
  86. [MonoTODO]
  87. public static bool IsDataSet (XmlSchema schema)
  88. {
  89. throw new NotImplementedException ();
  90. }
  91. protected override void OnClear ()
  92. {
  93. table.Clear ();
  94. }
  95. protected override void OnInsert (int index, object value)
  96. {
  97. string ns = ((XmlSchema) value).TargetNamespace;
  98. if (ns == null) ns = "";
  99. table [ns] = value;
  100. }
  101. protected override void OnRemove (int index, object value)
  102. {
  103. table.Remove (value);
  104. }
  105. protected override void OnSet (int index, object oldValue, object newValue)
  106. {
  107. string ns = ((XmlSchema) oldValue).TargetNamespace;
  108. if (ns == null) ns = "";
  109. table [ns] = newValue;
  110. }
  111. public void Remove (XmlSchema schema)
  112. {
  113. List.Remove (schema);
  114. }
  115. #endregion // Methods
  116. }
  117. }