[System] Fixes SmtpClientTest.Deliver_Async
[mono.git] / mcs / class / System.Web.Services / System.Web.Services.Discovery / DiscoveryDocument.cs
1 // 
2 // System.Web.Services.Protocols.DiscoveryDocument.cs
3 //
4 // Author:
5 //   Dave Bettin (javabettin@yahoo.com)
6 //   Tim Coleman (tim@timcoleman.com)  
7 //   Lluis Sanchez Gual (lluis@ximian.com)
8 //
9 // Copyright (C) Dave Bettin, 2002
10 // Copyright (C) Tim Coleman, 2002
11 //
12
13 //
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
21 // 
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
24 // 
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 //
33
34 using System.Collections;
35 using System.IO;
36 using System.Xml;
37 using System.Xml.Serialization;
38
39 namespace System.Web.Services.Discovery {
40         [XmlRoot ("discovery", Namespace = "http://schemas.xmlsoap.org/disco/")]
41         public sealed class DiscoveryDocument {
42
43                 #region Fields
44                 
45                 public const string Namespace = "http://schemas.xmlsoap.org/disco/";
46                 
47                 [XmlElement(typeof(ContractReference), Namespace="http://schemas.xmlsoap.org/disco/scl/")]
48                 [XmlElement(typeof(DiscoveryDocumentReference))]
49                 [XmlElement(typeof(SchemaReference))]
50                 internal ArrayList references = new ArrayList();
51                 
52                 [XmlElement(typeof(SoapBinding), ElementName="soap", Namespace="http://schemas/xmlsoap.org/disco/schema/soap/")]
53                 internal ArrayList additionalInfo = new ArrayList();
54                 
55                 #endregion // Fields
56                 
57                 #region Constructors
58
59                 public DiscoveryDocument () 
60                 {
61                 }
62                 
63                 #endregion // Constructors
64
65                 #region Properties
66         
67                 [XmlIgnore]
68                 public IList References {
69                         get { return references; }
70                 }
71                 
72                 [XmlIgnore]
73                 internal IList AdditionalInfo {
74                         get { return additionalInfo; }
75                 }
76                 
77                 #endregion // Properties
78
79                 #region Methods
80
81                 public static bool CanRead (XmlReader xmlReader)
82                 {
83                         xmlReader.MoveToContent ();
84                         return xmlReader.NodeType == XmlNodeType.Element &&
85                                         xmlReader.LocalName == "discovery" && 
86                                         xmlReader.NamespaceURI == Namespace;
87                 }
88
89                 public static DiscoveryDocument Read (Stream stream)
90                 {
91                         return Read (new XmlTextReader (stream));
92                 }
93                 
94                 public static DiscoveryDocument Read (TextReader textReader)
95                 {
96                         return Read (new XmlTextReader (textReader));
97                 }
98                 
99                 public static DiscoveryDocument Read (XmlReader xmlReader)
100                 {
101                         DiscoveryDocumentSerializer ser = new DiscoveryDocumentSerializer();
102                         return (DiscoveryDocument) ser.Deserialize (xmlReader);
103                 }
104                 
105                 public void Write (Stream stream)
106                 {
107                         DiscoveryDocumentSerializer ser = new DiscoveryDocumentSerializer();
108                         ser.Serialize (stream, this, GetNamespaceList());
109                 }
110                 
111                 public void Write (TextWriter textWriter)
112                 {
113                         DiscoveryDocumentSerializer ser = new DiscoveryDocumentSerializer();
114                         ser.Serialize (textWriter, this, GetNamespaceList());
115                 }
116                 
117                 public void Write (XmlWriter xmlWriter)
118                 {
119                         DiscoveryDocumentSerializer ser = new DiscoveryDocumentSerializer();
120                         ser.Serialize (xmlWriter, this, GetNamespaceList());
121                 }
122
123                 XmlSerializerNamespaces GetNamespaceList ()
124                 {
125                         XmlSerializerNamespaces ns = new XmlSerializerNamespaces ();
126                         ns.Add ("scl", ContractReference.Namespace);
127                         return ns;
128                 }
129                 
130                 #endregion // Methods
131         }
132
133         internal class DiscoveryDocumentSerializer : XmlSerializer 
134         {
135                 protected override void Serialize (object o, XmlSerializationWriter writer)
136                 {
137                         DiscoveryDocumentWriter xsWriter = writer as DiscoveryDocumentWriter;
138                         xsWriter.WriteRoot_DiscoveryDocument (o);
139                 }
140                 
141                 protected override object Deserialize (XmlSerializationReader reader)
142                 {
143                         DiscoveryDocumentReader xsReader = reader as DiscoveryDocumentReader;
144                         return xsReader.ReadRoot_DiscoveryDocument ();
145                 }
146                 
147                 protected override XmlSerializationWriter CreateWriter ()
148                 {
149                         return new DiscoveryDocumentWriter ();
150                 }
151                 
152                 protected override XmlSerializationReader CreateReader ()
153                 {
154                         return new DiscoveryDocumentReader ();
155                 }
156         }       
157 }