2 // System.Xml.Serialization.XmlSchemas
\r
5 // Tim Coleman (tim@timcoleman.com)
\r
7 // Copyright (C) Tim Coleman, 2002
\r
10 using System.Collections;
\r
11 using System.Xml.Schema;
\r
13 namespace System.Xml.Serialization {
\r
14 public class XmlSchemas : CollectionBase {
\r
18 Hashtable table = new Hashtable ();
\r
22 #region Constructors
\r
24 public XmlSchemas ()
\r
28 #endregion // Constructors
\r
32 public XmlSchema this [int index] {
\r
34 if (index < 0 || index > Count)
\r
35 throw new ArgumentOutOfRangeException ();
\r
37 return (XmlSchema) List [index];
\r
39 set { List [index] = value; }
\r
42 public XmlSchema this [string ns] {
\r
43 get { return (XmlSchema) table[ns]; }
\r
46 #endregion // Properties
\r
50 public int Add (XmlSchema schema)
\r
52 Insert (Count, schema);
\r
56 public void Add (XmlSchemas schemas)
\r
58 foreach (XmlSchema schema in schemas)
\r
62 public bool Contains (XmlSchema schema)
\r
64 return List.Contains (schema);
\r
67 public void CopyTo (XmlSchema[] array, int index)
\r
69 List.CopyTo (array, index);
\r
72 public object Find (XmlQualifiedName name, Type type)
\r
74 XmlSchema schema = table [name.Namespace] as XmlSchema;
\r
78 if (!schema.IsCompiled) {
\r
80 schema.Compile (null);
\r
82 throw new InvalidOperationException ("Error compiling XmlSchema " +
\r
87 XmlSchemaObjectTable tbl = null;
\r
89 if (type == typeof (XmlSchemaSimpleType) || type == typeof (XmlSchemaComplexType))
\r
90 tbl = schema.SchemaTypes;
\r
91 else if (type == typeof (XmlSchemaAttribute))
\r
92 tbl = schema.Attributes;
\r
93 else if (type == typeof (XmlSchemaAttributeGroup))
\r
94 tbl = schema.AttributeGroups;
\r
95 else if (type == typeof (XmlSchemaElement))
\r
96 tbl = schema.Elements;
\r
97 else if (type == typeof (XmlSchemaGroup))
\r
98 tbl = schema.Groups;
\r
99 else if (type == typeof (XmlSchemaNotation))
\r
100 tbl = schema.Notations;
\r
102 return (tbl != null) ? tbl [name] : null;
\r
105 public int IndexOf (XmlSchema schema)
\r
107 return List.IndexOf (schema);
\r
110 public void Insert (int index, XmlSchema schema)
\r
112 List.Insert (index, schema);
\r
116 public static bool IsDataSet (XmlSchema schema)
\r
118 throw new NotImplementedException ();
\r
121 protected override void OnClear ()
\r
126 protected override void OnInsert (int index, object value)
\r
128 table [((XmlSchema) value).TargetNamespace] = value;
\r
131 protected override void OnRemove (int index, object value)
\r
133 table.Remove (value);
\r
136 protected override void OnSet (int index, object oldValue, object newValue)
\r
138 table [((XmlSchema) oldValue).TargetNamespace] = newValue;
\r
141 public void Remove (XmlSchema schema)
\r
143 List.Remove (schema);
\r
146 #endregion // Methods
\r