Merge pull request #1349 from martinjt/MachineKeyProtect
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel.Dispatcher / XPathMessageFilterTable.cs
1 //
2 // XPathMessageFilterTable.cs
3 //
4 // Author:
5 //      Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // Copyright (C) 2006 Novell, Inc.  http://www.novell.com
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28 using System;
29 using System.Collections;
30 using System.Collections.Generic;
31 using System.Reflection;
32 using System.Runtime.Serialization;
33 using System.ServiceModel.Channels;
34 using System.Xml.XPath;
35 using System.ServiceModel;
36
37 namespace System.ServiceModel.Dispatcher
38 {
39         [DataContract]
40         public class XPathMessageFilterTable<TFilterData>
41                 : IDictionary<MessageFilter,TFilterData>,
42                   IMessageFilterTable<TFilterData>,
43                   IEnumerable,
44                   ICollection<KeyValuePair<MessageFilter,TFilterData>>,
45                   IEnumerable<KeyValuePair<MessageFilter,TFilterData>>
46         {
47                 Dictionary<MessageFilter,TFilterData> dict
48                         = new Dictionary<MessageFilter,TFilterData> ();
49
50                 int quota;
51
52                 [MonoTODO]
53                 public XPathMessageFilterTable ()
54                         : this (int.MaxValue)
55                 {
56                 }
57
58                 public XPathMessageFilterTable (int quota)
59                 {
60                         this.quota = quota;
61                 }
62
63                 [DataMember]
64                 public int NodeQuota {
65                         get { return quota; }
66                         set { quota = value; }
67                 }
68
69                 public TFilterData this [MessageFilter key] {
70                         get { return dict [key]; }
71                         set { dict [key] = value; }
72                 }
73
74                 public int Count {
75                         get { return dict.Count; }
76                 }
77
78                 public bool IsReadOnly {
79                         get { return false; }
80                 }
81
82                 public ICollection<MessageFilter> Keys {
83                         get { return dict.Keys; }
84                 }
85
86                 public ICollection<TFilterData> Values {
87                         get { return dict.Values; }
88                 }
89
90                 public void Add (KeyValuePair<MessageFilter,TFilterData> item)
91                 {
92                         dict.Add (item.Key, item.Value);
93                 }
94
95                 [MonoTODO]
96                 public void Add (XPathMessageFilter filter, TFilterData data)
97                 {
98                         throw new NotImplementedException ();
99                 }
100
101                 public void Add (MessageFilter filter, TFilterData data)
102                 {
103                         dict.Add (filter, data);
104                 }
105
106                 public void Clear ()
107                 {
108                         dict.Clear ();
109                 }
110
111                 public bool Contains (KeyValuePair<MessageFilter,TFilterData> item)
112                 {
113                         return dict.ContainsKey (item.Key) &&
114                                 dict [item.Key].Equals (item.Value);
115                 }
116
117                 public bool ContainsKey (MessageFilter key)
118                 {
119                         return dict.ContainsKey (key);
120                 }
121
122                 public void CopyTo (KeyValuePair<MessageFilter,TFilterData> [] array, int index)
123                 {
124                         if (index < 0 || dict.Count >= array.Length - index)
125                                 throw new ArgumentOutOfRangeException ("index");
126                         foreach (KeyValuePair<MessageFilter,TFilterData> item in dict)
127                                 array [index++] = item;
128                 }
129
130                 public IEnumerator<KeyValuePair<MessageFilter,TFilterData>> GetEnumerator ()
131                 {
132                         return dict.GetEnumerator ();
133                 }
134
135                 IEnumerator IEnumerable.GetEnumerator ()
136                 {
137                         return GetEnumerator ();
138                 }
139
140                 public bool GetMatchingFilter (Message message, out MessageFilter result)
141                 {
142                         throw new NotImplementedException ();
143                 }
144
145                 public bool GetMatchingFilter (MessageBuffer buffer, out MessageFilter result)
146                 {
147                         throw new NotImplementedException ();
148                 }
149
150                 public bool GetMatchingFilter (SeekableXPathNavigator navigator, out MessageFilter filter)
151                 {
152                         throw new NotImplementedException ();
153                 }
154
155                 public bool GetMatchingFilter (XPathNavigator navigator, out MessageFilter filter)
156                 {
157                         throw new NotImplementedException ();
158                 }
159
160                 public bool GetMatchingFilters (Message message, ICollection<MessageFilter> results)
161                 {
162                         throw new NotImplementedException ();
163                 }
164
165                 public bool GetMatchingFilters (MessageBuffer buffer, ICollection<MessageFilter> results)
166                 {
167                         throw new NotImplementedException ();
168                 }
169
170                 public bool GetMatchingFilters (SeekableXPathNavigator navigator, ICollection<MessageFilter> results)
171                 {
172                         throw new NotImplementedException ();
173                 }
174
175                 public bool GetMatchingFilters (XPathNavigator navigator, ICollection<MessageFilter> results)
176                 {
177                         throw new NotImplementedException ();
178                 }
179
180                 public bool GetMatchingValue (Message message, out TFilterData data)
181                 {
182                         throw new NotImplementedException ();
183                 }
184
185                 public bool GetMatchingValue (MessageBuffer buffer, out TFilterData data)
186                 {
187                         throw new NotImplementedException ();
188                 }
189
190                 public bool GetMatchingValue (SeekableXPathNavigator navigator, out TFilterData data)
191                 {
192                         throw new NotImplementedException ();
193                 }
194
195                 public bool GetMatchingValue (XPathNavigator navigator, out TFilterData data)
196                 {
197                         throw new NotImplementedException ();
198                 }
199
200                 public bool GetMatchingValues (Message message, ICollection<TFilterData> results)
201                 {
202                         throw new NotImplementedException ();
203                 }
204
205                 public bool GetMatchingValues (MessageBuffer buffer, ICollection<TFilterData> results)
206                 {
207                         throw new NotImplementedException ();
208                 }
209
210                 public bool GetMatchingValues (SeekableXPathNavigator navigator, ICollection<TFilterData> results)
211                 {
212                         throw new NotImplementedException ();
213                 }
214
215                 public bool GetMatchingValues (XPathNavigator navigator, ICollection<TFilterData> results)
216                 {
217                         throw new NotImplementedException ();
218                 }
219
220                 public bool Remove (KeyValuePair<MessageFilter,TFilterData> item)
221                 {
222                         if (dict.ContainsKey (item.Key) && dict [item.Key].Equals (item.Value)) {
223                                 dict.Remove (item.Key);
224                                 return true;
225                         }
226                         return false;
227                 }
228
229                 public bool Remove (XPathMessageFilter filter)
230                 {
231                         return dict.Remove (filter);
232                 }
233
234                 public bool Remove (MessageFilter filter)
235                 {
236                         return Remove ((XPathMessageFilter) filter);
237                 }
238
239                 static Exception trim_to_size_error;
240
241                 public void TrimToSize ()
242                 {
243                         // This is the documented behavior: throws NIE.
244                         if (trim_to_size_error == null)
245                                 trim_to_size_error = new NotImplementedException ();
246                         throw trim_to_size_error;
247                 }
248
249                 public bool TryGetValue (MessageFilter filter, out TFilterData data)
250                 {
251                         return dict.TryGetValue (filter, out data);
252                 }
253         }
254 }