Merge remote-tracking branch 'joncham/sgen-msvc2'
[mono.git] / mcs / class / System.Runtime.Serialization.Formatters.Soap / System.Runtime.Serialization.Formatters.Soap / SoapFormatter.cs
1 // created on 07/04/2003 at 17:16\r
2 //\r
3 //      System.Runtime.Serialization.Formatters.Soap.SoapFormatter\r
4 //\r
5 //      Authors:\r
6 //              Jean-Marc Andre (jean-marc.andre@polymtl.ca)\r
7 //\r
8 \r
9 //\r
10 // Permission is hereby granted, free of charge, to any person obtaining\r
11 // a copy of this software and associated documentation files (the\r
12 // "Software"), to deal in the Software without restriction, including\r
13 // without limitation the rights to use, copy, modify, merge, publish,\r
14 // distribute, sublicense, and/or sell copies of the Software, and to\r
15 // permit persons to whom the Software is furnished to do so, subject to\r
16 // the following conditions:\r
17 // \r
18 // The above copyright notice and this permission notice shall be\r
19 // included in all copies or substantial portions of the Software.\r
20 // \r
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
28 //\r
29 \r
30 using System;\r
31 using System.IO;\r
32 using System.Reflection;\r
33 using System.Runtime.InteropServices;\r
34 using System.Runtime.Remoting;\r
35 using System.Runtime.Serialization;\r
36 using System.Runtime.Remoting.Messaging;\r
37 using System.Xml.Serialization;\r
38 using System.Threading;\r
39 using System.Globalization;\r
40 \r
41 \r
42 namespace System.Runtime.Serialization.Formatters.Soap {\r
43         enum RemMessageType {\r
44                 MethodCall, MethodResponse, ServerFault, NotRecognize\r
45         }\r
46         \r
47         public sealed class SoapFormatter: IRemotingFormatter, IFormatter {\r
48                 private SerializationBinder _binder;\r
49                 private StreamingContext _context;\r
50                 private ISurrogateSelector _selector;\r
51                 private FormatterAssemblyStyle _assemblyFormat = FormatterAssemblyStyle.Full;\r
52                 private FormatterTypeStyle _typeFormat = FormatterTypeStyle.TypesWhenNeeded;\r
53                 private ISoapMessage _topObject = null;\r
54                 \r
55                 TypeFilterLevel _filterLevel = TypeFilterLevel.Low;\r
56 \r
57                 public SoapFormatter() {\r
58                         _selector = null;\r
59                         _context = new StreamingContext(StreamingContextStates.All);\r
60                 }\r
61                 \r
62                 public SoapFormatter(ISurrogateSelector selector, StreamingContext context) {\r
63                         _selector = selector;\r
64                         _context = context;\r
65                 }\r
66                 \r
67                 public object Deserialize(Stream serializationStream) {\r
68                         return Deserialize(serializationStream, null);\r
69                 }\r
70                 \r
71                 public object Deserialize(Stream serializationStream, HeaderHandler handler) {\r
72                         SoapReader soapReader = new SoapReader(_binder, _selector, _context);\r
73                         return soapReader.Deserialize(serializationStream, _topObject);\r
74                 }\r
75 \r
76                 public void Serialize(Stream serializationStream, object graph) {\r
77                         Serialize(serializationStream, graph, null);\r
78                 }\r
79                 \r
80                 public void Serialize(Stream serializationStream, object graph, Header[] headers) {\r
81                         if(serializationStream == null)\r
82                                 throw new ArgumentNullException("serializationStream");\r
83                         if(!serializationStream.CanWrite)\r
84                                 throw new SerializationException("Can't write in the serialization stream");\r
85                         if(graph == null)\r
86                                 throw new ArgumentNullException("graph");\r
87                         SoapWriter soapWriter = new SoapWriter(serializationStream, _selector, _context, _topObject);\r
88                         soapWriter.Serialize (graph, headers, _typeFormat, _assemblyFormat);\r
89                 }\r
90                 \r
91                 public ISurrogateSelector SurrogateSelector {\r
92                         get {\r
93                                 return _selector;\r
94                         }\r
95                         set {\r
96                                 _selector = value;\r
97                         }\r
98                 }\r
99                 \r
100                 \r
101                 public SerializationBinder Binder {\r
102                         get {\r
103                                 return _binder;\r
104                         }\r
105                         set {\r
106                                 _binder = value;\r
107                         }\r
108                 }\r
109                 \r
110                 public StreamingContext Context {\r
111                         get {\r
112                                 return _context;\r
113                         }\r
114                         set {\r
115                                 _context = value;\r
116                         }\r
117                 }\r
118                 \r
119                 public ISoapMessage TopObject {\r
120                         get {\r
121                                 return _topObject;\r
122                         }\r
123                         set {\r
124                                 _topObject = value;\r
125                         }\r
126                 }\r
127                 \r
128                 [MonoTODO ("Interpret this")]\r
129                 public TypeFilterLevel FilterLevel {\r
130                         get {\r
131                                 return _filterLevel;\r
132                         }\r
133                         set {\r
134                                 _filterLevel = value;\r
135                         }\r
136                 }\r
137                 \r
138                 public FormatterAssemblyStyle AssemblyFormat\r
139                 {\r
140                         get {\r
141                                 return _assemblyFormat;\r
142                         }\r
143                         set {\r
144                                 _assemblyFormat = value;\r
145                         }\r
146                 }\r
147 \r
148                 public FormatterTypeStyle TypeFormat\r
149                 {\r
150                         get \r
151                         {\r
152                                 return _typeFormat;\r
153                         }\r
154                         set \r
155                         {\r
156                                 _typeFormat = value;\r
157                         }\r
158                 }\r
159 \r
160         }\r
161 }\r