New test.
[mono.git] / mcs / class / System.XML / System.Xml.Serialization / SoapAttributeOverrides.cs
1 //\r
2 // SoapAttributeOverrides.cs: \r
3 //\r
4 // Author:\r
5 //   John Donagher (john@webmeta.com)\r
6 //\r
7 // (C) 2002 John Donagher\r
8 //\r
9 \r
10 //\r
11 // Permission is hereby granted, free of charge, to any person obtaining\r
12 // a copy of this software and associated documentation files (the\r
13 // "Software"), to deal in the Software without restriction, including\r
14 // without limitation the rights to use, copy, modify, merge, publish,\r
15 // distribute, sublicense, and/or sell copies of the Software, and to\r
16 // permit persons to whom the Software is furnished to do so, subject to\r
17 // the following conditions:\r
18 // \r
19 // The above copyright notice and this permission notice shall be\r
20 // included in all copies or substantial portions of the Software.\r
21 // \r
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
29 //\r
30 \r
31 using System;\r
32 using System.Collections;\r
33 \r
34 namespace System.Xml.Serialization\r
35 {\r
36         /// <summary>\r
37         /// \r
38         /// </summary>\r
39         public class SoapAttributeOverrides\r
40         {\r
41                 /// <summary>\r
42                 /// This class requires to store SoapAttrributes indexed by a key containg\r
43                 /// both Type and Member Name. There are 3 approaches to this IMO.\r
44                 /// 1. Make the key as "FullTypeName..MemberName", with ".." seperating Type and Member.\r
45                 /// 2. Use a jagged 2D hashtable. The main hashtable is indexed by Type and each value \r
46                 ///    contains another hashtable which is indexed by member names. (Too many hashtables)\r
47                 /// 3. Use a new class which emcompasses the Type and MemberName. An implementation is there\r
48                 ///    in TypeMember class in this namespace. (Too many instantiations of the class needed)\r
49                 ///    \r
50                 /// Method 1 is the most elegent, but I am not sure if the seperator is language insensitive.\r
51                 /// What if someone writes a language which allows . in the member names.\r
52                 /// </summary>\r
53                 /// \r
54                 private Hashtable overrides;\r
55 \r
56                 public SoapAttributeOverrides ()\r
57                 {\r
58                         overrides = new Hashtable();\r
59                 }\r
60 \r
61                 public SoapAttributes this [Type type] \r
62                 {\r
63                         get { return this [type, string.Empty]; }\r
64                 }\r
65 \r
66                 public SoapAttributes this [Type type, string member]\r
67                 {\r
68                         get \r
69                         {\r
70                                 return (SoapAttributes) overrides[GetKey(type,member)];\r
71                         }\r
72                 }\r
73 \r
74                 public void Add (Type type, SoapAttributes attributes) \r
75                 {\r
76                         Add(type, string.Empty, attributes);\r
77                 }\r
78 \r
79                 public void Add (Type type, string member, SoapAttributes attributes) \r
80                 {\r
81                         if(overrides[GetKey(type, member)] != null)\r
82                                 throw new Exception("The attributes for the given type and Member already exist in the collection");\r
83                         \r
84                         overrides.Add(GetKey(type,member), attributes);\r
85                 }\r
86 \r
87                 private TypeMember GetKey(Type type, string member)\r
88                 {\r
89                         return new TypeMember(type, member);\r
90                 }\r
91 \r
92                 internal void AddKeyHash (System.Text.StringBuilder sb)\r
93                 {\r
94                         sb.Append ("SAO ");\r
95                         foreach (DictionaryEntry entry in overrides)\r
96                         {\r
97                                 SoapAttributes val = (SoapAttributes) overrides [entry.Key];\r
98                                 sb.Append (entry.Key.ToString()).Append(' ');\r
99                                 val.AddKeyHash (sb);\r
100                         }\r
101                         sb.Append ("|");\r
102                 }\r
103         }\r
104 }\r