update readme (#21797)
[mono-project.git] / mcs / class / System.Web.Services / System.Web.Services.Discovery / DiscoveryDocumentSerializer.cs
blobe2cfc3f9cb89856e53cbd10ec9579e9b88ca1ca0
1 //
2 // System.Web.Services.Protocols.DiscoveryDocumentSerializer.cs
3 //
4 // Author:
5 // Lluis Sanchez Gual (lluis@ximian.com)
6 //
7 // Copyright (C) Ximian,Inc., 2003
8 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System;
32 using System.Xml;
33 using System.Xml.Schema;
34 using System.Xml.Serialization;
35 using System.Text;
36 using System.Collections;
37 using System.Globalization;
39 namespace System.Web.Services.Discovery
41 internal class DiscoveryDocumentReader : XmlSerializationReader
43 public object ReadRoot_DiscoveryDocument ()
45 Reader.MoveToContent();
46 if (Reader.LocalName != "discovery" || Reader.NamespaceURI != "http://schemas.xmlsoap.org/disco/")
47 throw CreateUnknownNodeException();
48 return ReadObject_DiscoveryDocument (true, true);
51 public System.Web.Services.Discovery.DiscoveryDocument ReadObject_DiscoveryDocument (bool isNullable, bool checkType)
53 System.Web.Services.Discovery.DiscoveryDocument ob = null;
54 if (isNullable && ReadNull()) return null;
56 if (checkType)
58 System.Xml.XmlQualifiedName t = GetXsiType();
59 if (t != null)
61 if (t.Name != "DiscoveryDocument" || t.Namespace != "http://schemas.xmlsoap.org/disco/")
62 throw CreateUnknownTypeException(t);
66 ob = new System.Web.Services.Discovery.DiscoveryDocument ();
68 Reader.MoveToElement();
70 while (Reader.MoveToNextAttribute())
72 if (IsXmlnsAttribute (Reader.Name)) {
74 else {
75 UnknownNode (ob);
79 Reader.MoveToElement();
80 if (Reader.IsEmptyElement) {
81 Reader.Skip ();
82 return ob;
85 Reader.ReadStartElement();
86 Reader.MoveToContent();
88 bool b0=false, b1=false;
90 System.Collections.ArrayList o3 = null;
91 System.Collections.ArrayList o5 = null;
92 int n2=0, n4=0;
94 while (Reader.NodeType != System.Xml.XmlNodeType.EndElement)
96 if (Reader.NodeType == System.Xml.XmlNodeType.Element)
98 if (Reader.LocalName == "discoveryRef" && Reader.NamespaceURI == "http://schemas.xmlsoap.org/disco/" && !b0) {
99 if (o3 == null)
100 o3 = new System.Collections.ArrayList();
101 o3.Add (ReadObject_DiscoveryDocumentReference (false, true));
102 n2++;
104 else if (Reader.LocalName == "soap" && Reader.NamespaceURI == "http://schemas/xmlsoap.org/disco/schema/soap/" && !b1) {
105 if (o5 == null)
106 o5 = new System.Collections.ArrayList();
107 o5.Add (ReadObject_SoapBinding (false, true));
108 n4++;
110 else if (Reader.LocalName == "contractRef" && Reader.NamespaceURI == "http://schemas.xmlsoap.org/disco/scl/" && !b0) {
111 if (o3 == null)
112 o3 = new System.Collections.ArrayList();
113 o3.Add (ReadObject_ContractReference (false, true));
114 n2++;
116 else if (Reader.LocalName == "schemaRef" && Reader.NamespaceURI == "http://schemas.xmlsoap.org/disco/" && !b0) {
117 if (o3 == null)
118 o3 = new System.Collections.ArrayList();
119 o3.Add (ReadObject_SchemaReference (false, true));
120 n2++;
122 else {
123 UnknownNode (ob);
126 else
127 UnknownNode(ob);
129 Reader.MoveToContent();
132 ob.@references = o3;
133 ob.@additionalInfo = o5;
135 ReadEndElement();
137 return ob;
140 public System.Web.Services.Discovery.DiscoveryDocumentReference ReadObject_DiscoveryDocumentReference (bool isNullable, bool checkType)
142 System.Web.Services.Discovery.DiscoveryDocumentReference ob = null;
143 if (isNullable && ReadNull()) return null;
145 if (checkType)
147 System.Xml.XmlQualifiedName t = GetXsiType();
148 if (t != null)
150 if (t.Name != "DiscoveryDocumentReference" || t.Namespace != "http://schemas.xmlsoap.org/disco/")
151 throw CreateUnknownTypeException(t);
155 ob = new System.Web.Services.Discovery.DiscoveryDocumentReference ();
157 Reader.MoveToElement();
159 while (Reader.MoveToNextAttribute())
161 if (Reader.LocalName == "ref" && Reader.NamespaceURI == "") {
162 ob.@Ref = Reader.Value;
164 else if (IsXmlnsAttribute (Reader.Name)) {
166 else {
167 UnknownNode (ob);
171 Reader.MoveToElement();
172 if (Reader.IsEmptyElement) {
173 Reader.Skip ();
174 return ob;
177 Reader.ReadStartElement();
178 Reader.MoveToContent();
180 while (Reader.NodeType != System.Xml.XmlNodeType.EndElement)
182 if (Reader.NodeType == System.Xml.XmlNodeType.Element)
184 UnknownNode (ob);
186 else
187 UnknownNode(ob);
189 Reader.MoveToContent();
192 ReadEndElement();
194 return ob;
197 public System.Web.Services.Discovery.SoapBinding ReadObject_SoapBinding (bool isNullable, bool checkType)
199 System.Web.Services.Discovery.SoapBinding ob = null;
200 if (isNullable && ReadNull()) return null;
202 if (checkType)
204 System.Xml.XmlQualifiedName t = GetXsiType();
205 if (t != null)
207 if (t.Name != "SoapBinding" || t.Namespace != "http://schemas/xmlsoap.org/disco/schema/soap/")
208 throw CreateUnknownTypeException(t);
212 ob = new System.Web.Services.Discovery.SoapBinding ();
214 Reader.MoveToElement();
216 while (Reader.MoveToNextAttribute())
218 if (Reader.LocalName == "binding" && Reader.NamespaceURI == "") {
219 ob.@Binding = ToXmlQualifiedName (Reader.Value);
221 else if (Reader.LocalName == "address" && Reader.NamespaceURI == "") {
222 ob.@Address = Reader.Value;
224 else if (IsXmlnsAttribute (Reader.Name)) {
226 else {
227 UnknownNode (ob);
231 Reader.MoveToElement();
232 if (Reader.IsEmptyElement) {
233 Reader.Skip ();
234 return ob;
237 Reader.ReadStartElement();
238 Reader.MoveToContent();
240 while (Reader.NodeType != System.Xml.XmlNodeType.EndElement)
242 if (Reader.NodeType == System.Xml.XmlNodeType.Element)
244 UnknownNode (ob);
246 else
247 UnknownNode(ob);
249 Reader.MoveToContent();
252 ReadEndElement();
254 return ob;
257 public System.Web.Services.Discovery.ContractReference ReadObject_ContractReference (bool isNullable, bool checkType)
259 System.Web.Services.Discovery.ContractReference ob = null;
260 if (isNullable && ReadNull()) return null;
262 if (checkType)
264 System.Xml.XmlQualifiedName t = GetXsiType();
265 if (t != null)
267 if (t.Name != "ContractReference" || t.Namespace != "http://schemas.xmlsoap.org/disco/scl/")
268 throw CreateUnknownTypeException(t);
272 ob = new System.Web.Services.Discovery.ContractReference ();
274 Reader.MoveToElement();
276 while (Reader.MoveToNextAttribute())
278 if (Reader.LocalName == "docRef" && Reader.NamespaceURI == "") {
279 ob.@DocRef = Reader.Value;
281 else if (Reader.LocalName == "ref" && Reader.NamespaceURI == "") {
282 ob.@Ref = Reader.Value;
284 else if (IsXmlnsAttribute (Reader.Name)) {
286 else {
287 UnknownNode (ob);
291 Reader.MoveToElement();
292 if (Reader.IsEmptyElement) {
293 Reader.Skip ();
294 return ob;
297 Reader.ReadStartElement();
298 Reader.MoveToContent();
300 while (Reader.NodeType != System.Xml.XmlNodeType.EndElement)
302 if (Reader.NodeType == System.Xml.XmlNodeType.Element)
304 UnknownNode (ob);
306 else
307 UnknownNode(ob);
309 Reader.MoveToContent();
312 ReadEndElement();
314 return ob;
317 public System.Web.Services.Discovery.SchemaReference ReadObject_SchemaReference (bool isNullable, bool checkType)
319 System.Web.Services.Discovery.SchemaReference ob = null;
320 if (isNullable && ReadNull()) return null;
322 if (checkType)
324 System.Xml.XmlQualifiedName t = GetXsiType();
325 if (t != null)
327 if (t.Name != "SchemaReference" || t.Namespace != "http://schemas/xmlsoap.org/disco/schema/")
328 throw CreateUnknownTypeException(t);
332 ob = new System.Web.Services.Discovery.SchemaReference ();
334 Reader.MoveToElement();
336 while (Reader.MoveToNextAttribute())
338 if (Reader.LocalName == "targetNamespace" && Reader.NamespaceURI == "") {
339 ob.@TargetNamespace = Reader.Value;
341 else if (Reader.LocalName == "ref" && Reader.NamespaceURI == "") {
342 ob.@Ref = Reader.Value;
344 else if (IsXmlnsAttribute (Reader.Name)) {
346 else {
347 UnknownNode (ob);
351 Reader.MoveToElement();
352 if (Reader.IsEmptyElement) {
353 Reader.Skip ();
354 return ob;
357 Reader.ReadStartElement();
358 Reader.MoveToContent();
360 while (Reader.NodeType != System.Xml.XmlNodeType.EndElement)
362 if (Reader.NodeType == System.Xml.XmlNodeType.Element)
364 UnknownNode (ob);
366 else
367 UnknownNode(ob);
369 Reader.MoveToContent();
372 ReadEndElement();
374 return ob;
377 protected override void InitCallbacks ()
381 protected override void InitIDs ()
387 internal class DiscoveryDocumentWriter : XmlSerializationWriter
389 public void WriteRoot_DiscoveryDocument (object o)
391 WriteStartDocument ();
392 System.Web.Services.Discovery.DiscoveryDocument ob = (System.Web.Services.Discovery.DiscoveryDocument) o;
393 TopLevelElement ();
394 WriteObject_DiscoveryDocument (ob, "discovery", "http://schemas.xmlsoap.org/disco/", true, false, true);
397 void WriteObject_DiscoveryDocument (System.Web.Services.Discovery.DiscoveryDocument ob, string element, string namesp, bool isNullable, bool needType, bool writeWrappingElem)
399 if (ob == null)
401 if (isNullable)
402 WriteNullTagLiteral(element, namesp);
403 return;
406 if (writeWrappingElem) {
407 WriteStartElement (element, namesp, ob);
410 if (needType) WriteXsiType("DiscoveryDocument", "http://schemas.xmlsoap.org/disco/");
412 if (ob.@references != null) {
413 for (int n6 = 0; n6 < ob.@references.Count; n6++) {
414 if (ob.@references[n6] == null) { }
415 else if (ob.@references[n6].GetType() == typeof(System.Web.Services.Discovery.SchemaReference)) {
416 WriteObject_SchemaReference (((System.Web.Services.Discovery.SchemaReference) ob.@references[n6]), "schemaRef", "http://schemas.xmlsoap.org/disco/", false, false, true);
418 else if (ob.@references[n6].GetType() == typeof(System.Web.Services.Discovery.DiscoveryDocumentReference)) {
419 WriteObject_DiscoveryDocumentReference (((System.Web.Services.Discovery.DiscoveryDocumentReference) ob.@references[n6]), "discoveryRef", "http://schemas.xmlsoap.org/disco/", false, false, true);
421 else if (ob.@references[n6].GetType() == typeof(System.Web.Services.Discovery.ContractReference)) {
422 WriteObject_ContractReference (((System.Web.Services.Discovery.ContractReference) ob.@references[n6]), "contractRef", "http://schemas.xmlsoap.org/disco/scl/", false, false, true);
424 else throw CreateUnknownTypeException (ob.@references[n6]);
427 if (ob.@additionalInfo != null) {
428 for (int n7 = 0; n7 < ob.@additionalInfo.Count; n7++) {
429 WriteObject_SoapBinding (((System.Web.Services.Discovery.SoapBinding) ob.@additionalInfo[n7]), "soap", "http://schemas/xmlsoap.org/disco/schema/soap/", false, false, true);
432 if (writeWrappingElem) WriteEndElement (ob);
435 void WriteObject_SchemaReference (System.Web.Services.Discovery.SchemaReference ob, string element, string namesp, bool isNullable, bool needType, bool writeWrappingElem)
437 if (ob == null)
439 if (isNullable)
440 WriteNullTagLiteral(element, namesp);
441 return;
444 if (writeWrappingElem) {
445 WriteStartElement (element, namesp, ob);
448 if (needType) WriteXsiType("SchemaReference", "http://schemas/xmlsoap.org/disco/schema/");
450 if (ob.@TargetNamespace != "") {
451 WriteAttribute ("targetNamespace", "", ob.@TargetNamespace);
453 WriteAttribute ("ref", "", ob.@Ref);
455 if (writeWrappingElem) WriteEndElement (ob);
458 void WriteObject_DiscoveryDocumentReference (System.Web.Services.Discovery.DiscoveryDocumentReference ob, string element, string namesp, bool isNullable, bool needType, bool writeWrappingElem)
460 if (ob == null)
462 if (isNullable)
463 WriteNullTagLiteral(element, namesp);
464 return;
467 if (writeWrappingElem) {
468 WriteStartElement (element, namesp, ob);
471 if (needType) WriteXsiType("DiscoveryDocumentReference", "http://schemas.xmlsoap.org/disco/");
473 WriteAttribute ("ref", "", ob.@Ref);
475 if (writeWrappingElem) WriteEndElement (ob);
478 void WriteObject_ContractReference (System.Web.Services.Discovery.ContractReference ob, string element, string namesp, bool isNullable, bool needType, bool writeWrappingElem)
480 if (ob == null)
482 if (isNullable)
483 WriteNullTagLiteral(element, namesp);
484 return;
487 if (writeWrappingElem) {
488 WriteStartElement (element, namesp, ob);
491 if (needType) WriteXsiType("ContractReference", "http://schemas.xmlsoap.org/disco/scl/");
493 WriteAttribute ("docRef", "", ob.@DocRef);
494 WriteAttribute ("ref", "", ob.@Ref);
496 if (writeWrappingElem) WriteEndElement (ob);
499 void WriteObject_SoapBinding (System.Web.Services.Discovery.SoapBinding ob, string element, string namesp, bool isNullable, bool needType, bool writeWrappingElem)
501 if (ob == null)
503 if (isNullable)
504 WriteNullTagLiteral(element, namesp);
505 return;
508 if (writeWrappingElem) {
509 WriteStartElement (element, namesp, ob);
512 if (needType) WriteXsiType("SoapBinding", "http://schemas/xmlsoap.org/disco/schema/soap/");
514 WriteAttribute ("binding", "", FromXmlQualifiedName (ob.@Binding));
515 WriteAttribute ("address", "", ob.@Address);
517 if (writeWrappingElem) WriteEndElement (ob);
520 protected override void InitCallbacks ()