**** Merged from MCS ****
[mono-project.git] / mcs / class / System.Web.Services / System.Web.Services.Protocols / Fault.cs
blob18ce1bad7502f860f66608550fece8bb43a5b94c
1 //
2 // System.Web.Services.Protocols.Fault.cs
3 //
4 // Author:
5 // Lluis Sanchez Gual (lluis@ximian.com)
6 //
7 // Copyright (C) 2004 Novell, Inc.
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.Protocols
41 internal class Fault
43 static XmlSerializer serializer;
45 static Fault ()
47 serializer = new FaultSerializer ();
50 public Fault () {}
52 public Fault (SoapException ex)
54 faultcode = ex.Code;
55 faultstring = ex.Message;
56 faultactor = ex.Actor;
57 detail = ex.Detail;
60 [XmlElement (Namespace="")]
61 public XmlQualifiedName faultcode;
63 [XmlElement (Namespace="")]
64 public string faultstring;
66 [XmlElement (Namespace="")]
67 public string faultactor;
69 [SoapIgnore]
70 public XmlNode detail;
72 public static XmlSerializer Serializer
74 get { return serializer; }
78 internal class FaultSerializer : XmlSerializer
80 protected override void Serialize (object o, XmlSerializationWriter writer)
82 FaultWriter xsWriter = writer as FaultWriter;
83 xsWriter.WriteRoot_Fault (o);
86 protected override object Deserialize (XmlSerializationReader reader)
88 FaultReader xsReader = reader as FaultReader;
89 return xsReader.ReadRoot_Fault ();
92 protected override XmlSerializationWriter CreateWriter ()
94 return new FaultWriter ();
97 protected override XmlSerializationReader CreateReader ()
99 return new FaultReader ();
103 internal class FaultReader : XmlSerializationReader
105 public object ReadRoot_Fault ()
107 Reader.MoveToContent();
108 if (Reader.LocalName != "Fault" || Reader.NamespaceURI != "http://schemas.xmlsoap.org/soap/envelope/")
109 throw CreateUnknownNodeException();
110 return ReadObject_Fault (true, true);
113 public System.Web.Services.Protocols.Fault ReadObject_Fault (bool isNullable, bool checkType)
115 System.Web.Services.Protocols.Fault ob = null;
116 if (isNullable && ReadNull()) return null;
118 if (checkType)
120 System.Xml.XmlQualifiedName t = GetXsiType();
121 if (t != null)
123 if (t.Name != "Fault" || t.Namespace != "http://schemas.xmlsoap.org/soap/envelope/")
124 throw CreateUnknownTypeException(t);
128 ob = new System.Web.Services.Protocols.Fault ();
130 Reader.MoveToElement();
132 while (Reader.MoveToNextAttribute())
134 if (IsXmlnsAttribute (Reader.Name)) {
136 else {
137 UnknownNode (ob);
141 Reader.MoveToElement();
142 if (Reader.IsEmptyElement) {
143 Reader.Skip ();
144 return ob;
147 Reader.ReadStartElement();
148 Reader.MoveToContent();
150 bool b0=false, b1=false, b2=false, b3=false;
152 while (Reader.NodeType != System.Xml.XmlNodeType.EndElement)
154 if (Reader.NodeType == System.Xml.XmlNodeType.Element)
156 if (Reader.LocalName == "faultcode" && Reader.NamespaceURI == "" && !b0) {
157 b0 = true;
158 ob.@faultcode = ReadElementQualifiedName ();
160 else if (Reader.LocalName == "faultstring" && Reader.NamespaceURI == "" && !b1) {
161 b1 = true;
162 ob.@faultstring = Reader.ReadElementString ();
164 else if (Reader.LocalName == "detail" && Reader.NamespaceURI == "http://schemas.xmlsoap.org/soap/envelope/" && !b3) {
165 b3 = true;
166 ob.@detail = ReadXmlNode (true);
168 else if (Reader.LocalName == "faultactor" && Reader.NamespaceURI == "" && !b2) {
169 b2 = true;
170 ob.@faultactor = Reader.ReadElementString ();
172 else {
173 UnknownNode (ob);
176 else
177 UnknownNode(ob);
179 Reader.MoveToContent();
182 ReadEndElement();
184 return ob;
187 protected override void InitCallbacks ()
191 protected override void InitIDs ()
196 internal class FaultWriter : XmlSerializationWriter
198 public void WriteRoot_Fault (object o)
200 WriteStartDocument ();
201 System.Web.Services.Protocols.Fault ob = (System.Web.Services.Protocols.Fault) o;
202 TopLevelElement ();
203 WriteObject_Fault (ob, "Fault", "http://schemas.xmlsoap.org/soap/envelope/", true, false, true);
206 void WriteObject_Fault (System.Web.Services.Protocols.Fault ob, string element, string namesp, bool isNullable, bool needType, bool writeWrappingElem)
208 if (ob == null)
210 if (isNullable)
211 WriteNullTagLiteral(element, namesp);
212 return;
215 if (writeWrappingElem) {
216 WriteStartElement (element, namesp, ob);
219 if (needType) WriteXsiType("Fault", "http://schemas.xmlsoap.org/soap/envelope/");
221 WriteElementQualifiedName ("faultcode", "", ob.@faultcode);
222 WriteElementString ("faultstring", "", ob.@faultstring);
223 WriteElementString ("faultactor", "", ob.@faultactor);
224 WriteElementLiteral (ob.@detail, "detail", "http://schemas.xmlsoap.org/soap/envelope/", false, false);
225 if (writeWrappingElem) WriteEndElement (ob);
228 protected override void InitCallbacks ()