2 // System.Web.Services.Protocols.DiscoveryDocumentSerializer.cs
5 // Lluis Sanchez Gual (lluis@ximian.com)
7 // Copyright (C) Ximian,Inc., 2003
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:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
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.
33 using System
.Xml
.Schema
;
34 using System
.Xml
.Serialization
;
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;
58 System
.Xml
.XmlQualifiedName t
= GetXsiType();
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
)) {
79 Reader
.MoveToElement();
80 if (Reader
.IsEmptyElement
) {
85 Reader
.ReadStartElement();
86 Reader
.MoveToContent();
88 bool b0
=false, b1
=false;
90 System
.Collections
.ArrayList o3
= null;
91 System
.Collections
.ArrayList o5
= null;
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
) {
100 o3
= new System
.Collections
.ArrayList();
101 o3
.Add (ReadObject_DiscoveryDocumentReference (false, true));
104 else if (Reader
.LocalName
== "soap" && Reader
.NamespaceURI
== "http://schemas/xmlsoap.org/disco/schema/soap/" && !b1
) {
106 o5
= new System
.Collections
.ArrayList();
107 o5
.Add (ReadObject_SoapBinding (false, true));
110 else if (Reader
.LocalName
== "contractRef" && Reader
.NamespaceURI
== "http://schemas.xmlsoap.org/disco/scl/" && !b0
) {
112 o3
= new System
.Collections
.ArrayList();
113 o3
.Add (ReadObject_ContractReference (false, true));
116 else if (Reader
.LocalName
== "schemaRef" && Reader
.NamespaceURI
== "http://schemas.xmlsoap.org/disco/" && !b0
) {
118 o3
= new System
.Collections
.ArrayList();
119 o3
.Add (ReadObject_SchemaReference (false, true));
129 Reader
.MoveToContent();
133 ob
.@additionalInfo
= o5
;
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;
147 System
.Xml
.XmlQualifiedName t
= GetXsiType();
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
)) {
171 Reader
.MoveToElement();
172 if (Reader
.IsEmptyElement
) {
177 Reader
.ReadStartElement();
178 Reader
.MoveToContent();
180 while (Reader
.NodeType
!= System
.Xml
.XmlNodeType
.EndElement
)
182 if (Reader
.NodeType
== System
.Xml
.XmlNodeType
.Element
)
189 Reader
.MoveToContent();
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;
204 System
.Xml
.XmlQualifiedName t
= GetXsiType();
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
)) {
231 Reader
.MoveToElement();
232 if (Reader
.IsEmptyElement
) {
237 Reader
.ReadStartElement();
238 Reader
.MoveToContent();
240 while (Reader
.NodeType
!= System
.Xml
.XmlNodeType
.EndElement
)
242 if (Reader
.NodeType
== System
.Xml
.XmlNodeType
.Element
)
249 Reader
.MoveToContent();
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;
264 System
.Xml
.XmlQualifiedName t
= GetXsiType();
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
)) {
291 Reader
.MoveToElement();
292 if (Reader
.IsEmptyElement
) {
297 Reader
.ReadStartElement();
298 Reader
.MoveToContent();
300 while (Reader
.NodeType
!= System
.Xml
.XmlNodeType
.EndElement
)
302 if (Reader
.NodeType
== System
.Xml
.XmlNodeType
.Element
)
309 Reader
.MoveToContent();
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;
324 System
.Xml
.XmlQualifiedName t
= GetXsiType();
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
)) {
351 Reader
.MoveToElement();
352 if (Reader
.IsEmptyElement
) {
357 Reader
.ReadStartElement();
358 Reader
.MoveToContent();
360 while (Reader
.NodeType
!= System
.Xml
.XmlNodeType
.EndElement
)
362 if (Reader
.NodeType
== System
.Xml
.XmlNodeType
.Element
)
369 Reader
.MoveToContent();
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
;
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
)
402 WriteNullTagLiteral(element
, namesp
);
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
)
440 WriteNullTagLiteral(element
, namesp
);
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
)
463 WriteNullTagLiteral(element
, namesp
);
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
)
483 WriteNullTagLiteral(element
, namesp
);
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
)
504 WriteNullTagLiteral(element
, namesp
);
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 ()