2002-09-13 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mcs / class / System.XML / System.Xml.Serialization / XmlSchemas.cs
1 // \r
2 // System.Xml.Serialization.XmlSchemas \r
3 //\r
4 // Author:\r
5 //   Tim Coleman (tim@timcoleman.com)\r
6 //\r
7 // Copyright (C) Tim Coleman, 2002\r
8 //\r
9 \r
10 using System.Collections;\r
11 using System.Xml.Schema;\r
12 \r
13 namespace System.Xml.Serialization {\r
14         public class XmlSchemas : CollectionBase {\r
15 \r
16                 #region Fields\r
17 \r
18                 Hashtable table = new Hashtable ();\r
19 \r
20                 #endregion\r
21 \r
22                 #region Constructors\r
23 \r
24                 public XmlSchemas ()\r
25                 {\r
26                 }\r
27 \r
28                 #endregion // Constructors\r
29 \r
30                 #region Properties\r
31 \r
32                 public XmlSchema this [int index] {\r
33                         get { \r
34                                 if (index < 0 || index > Count)\r
35                                         throw new ArgumentOutOfRangeException ();\r
36 \r
37                                 return (XmlSchema) List [index]; \r
38                         }\r
39                         set { List [index] = value; }\r
40                 }\r
41 \r
42                 public XmlSchema this [string ns] {\r
43                         get { return (XmlSchema) table[ns]; }\r
44                 }\r
45 \r
46                 #endregion // Properties\r
47 \r
48                 #region Methods\r
49 \r
50                 public int Add (XmlSchema schema)\r
51                 {\r
52                         Insert (Count, schema);\r
53                         return (Count - 1);\r
54                 }\r
55 \r
56                 public void Add (XmlSchemas schemas) \r
57                 {\r
58                         foreach (XmlSchema schema in schemas) \r
59                                 Add (schema);\r
60                 }\r
61 \r
62                 public bool Contains (XmlSchema schema)\r
63                 {\r
64                         return List.Contains (schema);\r
65                 }\r
66 \r
67                 public void CopyTo (XmlSchema[] array, int index) \r
68                 {\r
69                         List.CopyTo (array, index);\r
70                 }\r
71 \r
72                 public object Find (XmlQualifiedName name, Type type)\r
73                 {\r
74                         XmlSchema schema = table [name.Namespace] as XmlSchema;\r
75                         if (schema == null)\r
76                                 return null;\r
77 \r
78                         if (!schema.IsCompiled) {\r
79                                 try {\r
80                                         schema.Compile (null);\r
81                                 } catch {\r
82                                         throw new InvalidOperationException ("Error compiling XmlSchema " + \r
83                                                                              name.Namespace);\r
84                                 }\r
85                         }\r
86 \r
87                         XmlSchemaObjectTable tbl = null;\r
88 \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
101 \r
102                         return (tbl != null) ? tbl [name] : null;\r
103                 }\r
104 \r
105                 public int IndexOf (XmlSchema schema)\r
106                 {\r
107                         return List.IndexOf (schema);\r
108                 }\r
109 \r
110                 public void Insert (int index, XmlSchema schema)\r
111                 {\r
112                         List.Insert (index, schema);\r
113                 }\r
114 \r
115                 [MonoTODO]\r
116                 public static bool IsDataSet (XmlSchema schema)\r
117                 {\r
118                         throw new NotImplementedException ();\r
119                 }\r
120 \r
121                 protected override void OnClear ()\r
122                 {\r
123                         table.Clear ();\r
124                 }\r
125 \r
126                 protected override void OnInsert (int index, object value)\r
127                 {       \r
128                         table [((XmlSchema) value).TargetNamespace] = value;\r
129                 }\r
130 \r
131                 protected override void OnRemove (int index, object value)\r
132                 {\r
133                         table.Remove (value);\r
134                 }\r
135 \r
136                 protected override void OnSet (int index, object oldValue, object newValue)\r
137                 {\r
138                         table [((XmlSchema) oldValue).TargetNamespace] = newValue;\r
139                 }\r
140         \r
141                 public void Remove (XmlSchema schema)\r
142                 {\r
143                         List.Remove (schema);\r
144                 }\r
145 \r
146                 #endregion // Methods\r
147         }\r
148 }\r