2010-02-05 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel.Dispatcher / ActionMessageFilterTable.cs
1 //
2 // System.ServiceModel.ActionMessageFilterTable.cs
3 //
4 // Author: Duncan Mak (duncan@novell.com)
5 //
6 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining
9 // a copy of this software and associated documentation files (the
10 // "Software"), to deal in the Software without restriction, including
11 // without limitation the rights to use, copy, modify, merge, publish,
12 // distribute, sublicense, and/or sell copies of the Software, and to
13 // permit persons to whom the Software is furnished to do so, subject to
14 // the following conditions:
15 // 
16 // The above copyright notice and this permission notice shall be
17 // included in all copies or substantial portions of the Software.
18 // 
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 //
27
28 using System;
29 using System.Collections;
30 using System.Collections.Generic;
31 using System.Runtime.Serialization;
32 using System.ServiceModel;
33 using System.ServiceModel.Channels;
34
35 namespace System.ServiceModel.Dispatcher {
36
37         [DataContract]
38         internal class ActionMessageFilterTable<TFilterData>
39                 : IMessageFilterTable<TFilterData>, 
40                   IDictionary<MessageFilter,TFilterData>,
41                   ICollection<KeyValuePair<MessageFilter, TFilterData>>, 
42                   IEnumerable<KeyValuePair<MessageFilter,TFilterData>>, 
43                   IEnumerable
44         {
45                 Dictionary<MessageFilter, TFilterData> table;
46                 
47                 public ActionMessageFilterTable ()
48                 {
49                         table = new Dictionary<MessageFilter, TFilterData> ();
50                 }
51
52                 public void Add (KeyValuePair<MessageFilter, TFilterData> item)
53                 {
54                         table.Add (item.Key, item.Value);
55                 }
56
57                 public void Add (ActionMessageFilter filter, TFilterData data)
58                 {
59                         table.Add (filter, data);
60                 }
61
62                 public void Add (MessageFilter filter, TFilterData data)
63                 {
64                         table.Add (filter, data);
65                 }
66
67                 public void Clear ()
68                 {
69                         table.Clear ();
70                 }
71
72                 public bool Contains (KeyValuePair<MessageFilter, TFilterData> item)
73                 {
74                         return table.ContainsKey (item.Key);
75                 }
76
77                 public bool ContainsKey (MessageFilter filter)
78                 {
79                         return table.ContainsKey (filter);
80                 }
81
82                 public void CopyTo (KeyValuePair<MessageFilter, TFilterData> [] array, int index)
83                 {
84                         ((ICollection<KeyValuePair<MessageFilter, TFilterData>>) table).CopyTo (array, index);
85                 }
86
87                 public IEnumerator<KeyValuePair<MessageFilter, TFilterData>> GetEnumerator ()
88                 {
89                         return ((ICollection<KeyValuePair<MessageFilter, TFilterData>>) table).GetEnumerator ();
90                 }
91
92                 public bool GetMatchingFilter (Message message, out MessageFilter result)
93                 {
94                         throw new NotImplementedException ();
95                 }
96
97                 public bool GetMatchingFilter (MessageBuffer buffer, out MessageFilter result)
98                 {
99                         throw new NotImplementedException ();
100                 }
101
102                 public bool GetMatchingFilters (Message message, ICollection<MessageFilter> results)
103                 {
104                         throw new NotImplementedException ();
105                 }
106
107                 public bool GetMatchingFilters (MessageBuffer buffer, ICollection<MessageFilter> results)
108                 {
109                         throw new NotImplementedException ();
110                 }
111
112                 public bool GetMatchingValue (Message message, out TFilterData data)
113                 {
114                         throw new NotImplementedException ();
115                 }
116
117                 public bool GetMatchingValue (MessageBuffer buffer, out TFilterData data)
118                 {
119                         throw new NotImplementedException ();
120                 }
121
122                 public bool GetMatchingValues (Message message, ICollection<TFilterData> results)
123                 {
124                         throw new NotImplementedException ();
125                 }
126
127                 public bool GetMatchingValues (MessageBuffer buffer, ICollection<TFilterData> results)
128                 {
129                         throw new NotImplementedException ();
130                 }
131
132                 public bool Remove (ActionMessageFilter filter)
133                 {
134                         if (filter == null)
135                                 throw new ArgumentNullException ("filter is null.");
136
137                         return table.Remove (filter);
138                 }
139
140                 public bool Remove (MessageFilter filter)
141                 {
142                         if (filter == null)
143                                 throw new ArgumentNullException ("filter is null.");
144
145                         return table.Remove (filter);
146                 }
147
148                 public bool Remove (KeyValuePair<MessageFilter, TFilterData> item)
149                 {
150                         return table.Remove (item.Key);
151                 }
152
153                 IEnumerator IEnumerable.GetEnumerator ()
154                 {
155                         return table.GetEnumerator ();
156                 }
157
158                 public bool TryGetValue (MessageFilter filter, out TFilterData data)
159                 {
160                         if (table.ContainsKey (filter)){
161                                 data = table [filter];
162                                 return true;
163                         }
164
165                         data = default (TFilterData);
166                         return false;
167                 }
168
169                 public int Count { get { return table.Count; }}
170
171                 public bool IsReadOnly { get { return false; }}
172
173                 public TFilterData this [MessageFilter filter] {
174                         get { return table [filter]; }
175                         set { table [filter] = value; }
176                 }
177
178                 public ICollection<MessageFilter> Keys {
179                         get { return table.Keys; }
180                 }
181
182                 public ICollection<TFilterData> Values {
183                         get { return table.Values; }
184                 }
185         }
186 }