2006-12-12 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / System.Web.Services / System.Web.Services.Protocols / Fault12.cs
1 // 
2 // Fault12.cs
3 //
4 // Author:
5 //      Atsushi Enomoto  <atsushi@ximian.com>
6 //
7 // Copyright (C) 2006 Novell, Inc.
8 //
9
10 //
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.
29 //
30
31 //
32 // This file is used to generate Fault12Serializer.cs with fault-12.genxs.
33 // To generate the file, do:
34 //      - replace _internal_ class in this file to _public_ class
35 //      - optionally you might have to remove Fault12Serializer.cs from
36 //        System.Web.Services.dll.sources.
37 //      - Build System.Web.Services.dll with make PROFILE=net_2_0.
38 //      - run genxs.exe with 2.0 libraries (the easiest way would be
39 //        to build genxs under 2.0 profile i.e. make PROFILE=net_2_0)
40 //      - Edit Fault12Serializer.cs to rename "FaultSerializer" to
41 //        "Fault12Serializer" as the name is a duplicate, and
42 //        wrap the entire code with #if NET_2_0.
43 //      - revert _public_ class in this file to _internal_ class back.
44 //
45
46 using System;
47 using System.Xml;
48 using System.Xml.Schema;
49 using System.Xml.Serialization;
50 using System.Text;
51 using System.Collections;
52 using System.Globalization;
53
54 namespace System.Web.Services.Protocols
55 {
56         [XmlRoot ("Fault", Namespace = "http://www.w3.org/2003/05/soap-envelope")]
57         [XmlType ("Fault", Namespace = "http://www.w3.org/2003/05/soap-envelope")]
58         internal class Soap12Fault
59         {
60                 // dummy constructor to not be rejected by genxs.
61                 public Soap12Fault ()
62                 {
63                 }
64
65                 public static XmlSerializer Serializer =
66 #if NET_2_0
67                         new Fault12Serializer ();
68 #else
69                         null;
70 #endif
71
72 #if NET_2_0
73
74                 public Soap12Fault (SoapException ex) 
75                 {
76                         Code = new Soap12FaultCode ();
77                         Code.Value = ex.Code;
78                         Code.Subcode = CreateFaultCode (ex.SubCode);
79                         Node = ex.Node;
80                         Role = ex.Role;
81                         Reason = new Soap12FaultReason ();
82                         Soap12FaultReasonText text =
83                                 new Soap12FaultReasonText ();
84                         text.XmlLang = ex.Lang;
85                         text.Value = ex.Message;
86                         Reason.Texts = new Soap12FaultReasonText [] {text};
87                         if (ex.Detail != null) {
88                                 Detail = new Soap12FaultDetail ();
89                                 if (ex.Detail.NodeType == XmlNodeType.Attribute)
90                                         Detail.Attributes = new XmlAttribute [] {
91                                                 (XmlAttribute) ex.Detail};
92                                 else if (ex.Detail.NodeType == XmlNodeType.Element)
93                                         Detail.Children = new XmlElement [] {
94                                                 (XmlElement) ex.Detail};
95                                 else
96                                         Detail.Text = ex.Detail.Value;
97                         }
98                 }
99
100                 static Soap12FaultCode CreateFaultCode (SoapFaultSubCode code)
101                 {
102                         Soap12FaultCode ret = new Soap12FaultCode ();
103                         ret.Value = code.Code;
104                         if (code.SubCode != null)
105                                 ret.Subcode = CreateFaultCode (code.SubCode);
106                         return ret;
107                 }
108
109                 public static SoapFaultSubCode GetSoapFaultSubCode (Soap12FaultCode src)
110                 {
111                         return (src == null) ? null :
112                                 new SoapFaultSubCode (src.Value, GetSoapFaultSubCode (src.Subcode));
113                 }
114 #endif
115
116                 public Soap12FaultCode Code;
117
118                 public Soap12FaultReason Reason;
119
120                 [XmlElement (DataType = "anyURI")]
121                 public string Node;
122
123                 [XmlElement (DataType = "anyURI")]
124                 public string Role;
125
126                 public Soap12FaultDetail Detail;
127         }
128
129         [XmlType ("Code", Namespace = "http://www.w3.org/2003/05/soap-envelope")]
130         internal class Soap12FaultCode
131         {
132                 public XmlQualifiedName Value;
133
134                 public Soap12FaultCode Subcode;
135         }
136
137         [XmlType ("Reason", Namespace = "http://www.w3.org/2003/05/soap-envelope")]
138         internal class Soap12FaultReason
139         {
140                 [XmlElement ("Text", Namespace = "http://www.w3.org/2003/05/soap-envelope")]
141                 public Soap12FaultReasonText [] Texts;
142         }
143
144         [XmlType ("Text", Namespace = "http://www.w3.org/2003/05/soap-envelope")]
145         internal class Soap12FaultReasonText
146         {
147                 [XmlAttribute ("lang", Namespace = "http://www.w3.org/XML/1998/namespace")]
148                 public string XmlLang;
149
150                 [XmlText]
151                 public string Value;
152         }
153
154         [XmlType ("Detail", Namespace = "http://www.w3.org/2003/05/soap-envelope")]
155         internal class Soap12FaultDetail
156         {
157                 [XmlAnyAttribute]
158                 public XmlAttribute [] Attributes;
159
160                 [XmlAnyElement]
161                 public XmlElement [] Children;
162
163                 [XmlText]
164                 public string Text;
165         }
166 }