New test.
[mono.git] / mcs / class / System.Web.Services / System.Web.Services.Description / ServiceDescriptionBaseCollection.cs
1 // 
2 // System.Web.Services.Description.ServiceDescriptionBaseCollection.cs
3 //
4 // Author:
5 //   Tim Coleman (tim@timcoleman.com)
6 //
7 // Copyright (C) Tim Coleman, 2002
8 //
9
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 using System.Collections;
32 using System.Web.Services;
33
34 namespace System.Web.Services.Description {
35         public abstract class ServiceDescriptionBaseCollection : CollectionBase {
36                 
37                 #region Fields
38
39                 Hashtable table = new Hashtable ();
40                 object parent;
41
42                 #endregion // Fields
43
44                 #region Constructors
45
46                 internal ServiceDescriptionBaseCollection (object parent)
47                 {
48                         this.parent = parent;
49                 }
50
51                 #endregion // Constructors
52
53                 #region Properties
54
55                 protected virtual IDictionary Table {
56                         get { return table; }
57                 }
58
59                 #endregion // Properties
60
61                 #region Methods
62
63                 protected virtual string GetKey (object value) 
64                 {
65                         return null; 
66                 }
67
68                 protected override void OnClear ()
69                 {
70                         Table.Clear ();
71                 }
72
73                 protected override void OnInsertComplete (int index, object value)
74                 {
75                         if (GetKey (value) != null)
76                                 Table [GetKey (value)] = value;
77                         SetParent (value, parent);
78                 }
79
80                 protected override void OnRemove (int index, object value)
81                 {
82                         if (GetKey (value) != null)
83                                 Table.Remove (GetKey (value));
84                 }
85
86                 protected override void OnSet (int index, object oldValue, object newValue)
87                 {
88                         if (GetKey (oldValue) != null) 
89                                 Table.Remove (GetKey (oldValue));
90                         if (GetKey (newValue) != null)
91                                 Table [GetKey (newValue)] = newValue;
92                         SetParent (newValue, parent);
93                 }
94
95                 protected virtual void SetParent (object value, object parent)
96                 {
97                 }
98                         
99                 #endregion // Methods
100         }
101 }