2002-10-23 Ville Palo <vi64pa@koti.soon.fi>
[mono.git] / mcs / class / System.Data / System.Data.Common / DataTableMappingCollection.cs
1 //
2 // System.Data.Common.DataTableMappingCollection.cs
3 //
4 // Author:
5 //   Rodrigo Moya (rodrigo@ximian.com)
6 //   Tim Coleman (tim@timcoleman.com)
7 //
8 // (C) Ximian, Inc
9 // Copyright (C) 2002 Tim Coleman
10 //
11
12 using System;
13 using System.Collections;
14
15 namespace System.Data.Common
16 {
17         /// <summary>
18         /// A collection of DataTableMapping objects. This class cannot be inherited.
19         /// </summary>
20         public sealed class DataTableMappingCollection : MarshalByRefObject, ITableMappingCollection, IList, ICollection, IEnumerable
21         {
22                 #region Fields
23
24                 ArrayList mappings;
25                 Hashtable sourceTables;
26                 Hashtable dataSetTables;
27
28                 #endregion
29
30                 #region Constructors 
31
32                 public DataTableMappingCollection() 
33                 {
34                         mappings = new ArrayList ();
35                         sourceTables = new Hashtable ();
36                         dataSetTables = new Hashtable ();
37                 }
38
39                 #endregion
40
41                 #region Properties
42
43                 public int Count 
44                 {
45                         get { return mappings.Count; }
46                 }
47
48                 public DataTableMapping this[int index] {
49                         get { return (DataTableMapping)(mappings[index]); }
50                         set { 
51                                 DataTableMapping mapping = (DataTableMapping)(mappings[index]);
52                                 sourceTables[mapping.SourceTable] = value;
53                                 dataSetTables[mapping.DataSetTable] = value;
54                                 mappings[index] = value; 
55                         }
56                 }
57
58                 [MonoTODO]
59                 public DataTableMapping this[string sourceTable] {
60                         get { return (DataTableMapping)(sourceTables[sourceTable]); }
61                         set { this[mappings.IndexOf(sourceTables[sourceTable])] = value; }
62                 }
63
64         
65                 object IList.this[int index] {
66                         get { return (object)(this[index]); }
67                         set { 
68                                 if (!(value is DataTableMapping))
69                                         throw new ArgumentException (); 
70                                 this[index] = (DataTableMapping)value;
71                          } 
72                 }
73
74                 bool IList.IsReadOnly {
75                         get { return false; }
76                 }
77
78                 bool IList.IsFixedSize {
79                         get { return false; }
80                 }
81
82                 object ICollection.SyncRoot {
83                         get { return mappings.SyncRoot; }
84                 }
85
86                 bool ICollection.IsSynchronized {
87                         get { return mappings.IsSynchronized; }
88                 }
89
90                 object ITableMappingCollection.this[string sourceTable] {
91                         get { return this[sourceTable]; }
92                         set { 
93                                 if (!(value is DataTableMapping))
94                                         throw new ArgumentException ();
95                                 this[sourceTable] = (DataTableMapping)(value);
96                         }
97                 }
98
99                 #endregion
100
101                 #region Methods
102
103                 public int Add (object value) 
104                 {
105                         if (!(value is System.Data.Common.DataTableMapping))
106                                 throw new SystemException ("The object passed in was not a DataTableMapping object.");
107
108                         sourceTables[((DataTableMapping)value).SourceTable] = value;    
109                         dataSetTables[((DataTableMapping)value).DataSetTable] = value;  
110                         return mappings.Add (value);
111                 }
112
113                 public DataTableMapping Add (string sourceTable, string dataSetTable) 
114                 {
115                         DataTableMapping mapping = new DataTableMapping (sourceTable, dataSetTable);
116                         Add (mapping);
117                         return mapping;
118                 }
119
120                 public void AddRange(DataTableMapping[] values) 
121                 {
122                         foreach (DataTableMapping dataTableMapping in values)
123                                 this.Add (dataTableMapping);
124                 }
125
126                 public void Clear() 
127                 {
128                         sourceTables.Clear ();
129                         dataSetTables.Clear ();
130                         mappings.Clear ();
131                 }
132
133                 public bool Contains (object value) 
134                 {
135                         return mappings.Contains (value);
136                 }
137
138                 public bool Contains (string value) 
139                 {
140                         return sourceTables.Contains (value);
141                 }
142
143                 [MonoTODO]
144                 public void CopyTo(Array array, int index) 
145                 {
146                         throw new NotImplementedException ();
147                 }
148
149                 public DataTableMapping GetByDataSetTable (string dataSetTable) 
150                 {
151                         return (DataTableMapping)(dataSetTables[dataSetTable]);
152                 }
153
154                 public static DataTableMapping GetTableMappingBySchemaAction (DataTableMappingCollection tableMappings, string sourceTable, string dataSetTable, MissingMappingAction mappingAction) 
155                 {
156                         if (tableMappings.Contains (sourceTable))
157                                 return tableMappings[sourceTable];
158                         if (mappingAction == MissingMappingAction.Error)
159                                 throw new InvalidOperationException ();
160                         if (mappingAction == MissingMappingAction.Ignore)
161                                 return null;
162                         return new DataTableMapping (sourceTable, dataSetTable);
163                 }
164
165                 public IEnumerator GetEnumerator ()
166                 {
167                         return mappings.GetEnumerator ();
168                 }
169
170                 public int IndexOf (object value) 
171                 {
172                         return mappings.IndexOf (value);
173                 }
174
175                 public int IndexOf (string sourceTable) 
176                 {
177                         return IndexOf (sourceTables[sourceTable]);
178                 }
179
180                 public int IndexOfDataSetTable (string dataSetTable) 
181                 {
182                         return IndexOf ((DataTableMapping)(dataSetTables[dataSetTable]));
183                 }
184
185                 [MonoTODO]
186                 public void Insert (int index, object value) 
187                 {
188                         throw new NotImplementedException ();
189                 }
190
191                 [MonoTODO]
192                 ITableMapping ITableMappingCollection.Add (string sourceTableName, string dataSetTableName)
193                 {
194                         throw new NotImplementedException ();
195                 }
196
197                 [MonoTODO]
198                 ITableMapping ITableMappingCollection.GetByDataSetTable (string dataSetTableName)
199                 {
200                         throw new NotImplementedException ();
201                 }
202
203                 [MonoTODO]
204                 public void Remove (object value) 
205                 {
206                         throw new NotImplementedException ();
207                 }
208
209                 [MonoTODO]
210                 public void RemoveAt (int index) 
211                 {
212                         throw new NotImplementedException ();
213                 }
214
215                 [MonoTODO]
216                 public void RemoveAt (string index) 
217                 {
218                         throw new NotImplementedException ();
219                 }
220                 
221
222
223                 #endregion
224         }
225 }