2010-03-12 Jb Evain <jbevain@novell.com>
[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 GetMatchingFilters (Message message, ICollection<MessageFilter> results)
151                 {
152                         throw new NotImplementedException ();
153                 }
154
155                 public bool GetMatchingFilters (MessageBuffer buffer, ICollection<MessageFilter> results)
156                 {
157                         throw new NotImplementedException ();
158                 }
159
160                 public bool GetMatchingValue (Message message, out TFilterData data)
161                 {
162                         throw new NotImplementedException ();
163                 }
164
165                 public bool GetMatchingValue (MessageBuffer buffer, out TFilterData data)
166                 {
167                         throw new NotImplementedException ();
168                 }
169
170                 public bool GetMatchingValues (Message message, ICollection<TFilterData> results)
171                 {
172                         throw new NotImplementedException ();
173                 }
174
175                 public bool GetMatchingValues (MessageBuffer buffer, ICollection<TFilterData> results)
176                 {
177                         throw new NotImplementedException ();
178                 }
179
180                 public bool Remove (KeyValuePair<MessageFilter,TFilterData> item)
181                 {
182                         if (dict.ContainsKey (item.Key) && dict [item.Key].Equals (item.Value)) {
183                                 dict.Remove (item.Key);
184                                 return true;
185                         }
186                         return false;
187                 }
188
189                 public bool Remove (XPathMessageFilter filter)
190                 {
191                         throw new NotImplementedException ();
192                 }
193
194                 public bool Remove (MessageFilter filter)
195                 {
196                         return dict.Remove (filter);
197                 }
198
199                 public bool TryGetValue (MessageFilter filter, out TFilterData filterData)
200                 {
201                         if (dict.ContainsKey (filter)) {
202                                 filterData = dict [filter];
203                                 return true;
204                         } else {
205                                 filterData = default (TFilterData);
206                                 return false;
207                         }
208                 }
209
210                 [MonoTODO]
211                 public void TrimToSize ()
212                 {
213                         throw new NotImplementedException ();
214                 }
215         }
216 }