Merge pull request #268 from pcc/menudeactivate
[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                         if (ex.SubCode != null)
79                                 Code.Subcode = CreateFaultCode (ex.SubCode);
80                         Node = ex.Node;
81                         Role = ex.Role;
82                         Reason = new Soap12FaultReason ();
83                         Soap12FaultReasonText text =
84                                 new Soap12FaultReasonText ();
85                         text.XmlLang = ex.Lang;
86                         text.Value = ex.Message;
87                         Reason.Texts = new Soap12FaultReasonText [] {text};
88                         if (ex.Detail != null) {
89                                 Detail = new Soap12FaultDetail ();
90                                 if (ex.Detail.NodeType == XmlNodeType.Attribute)
91                                         Detail.Attributes = new XmlAttribute [] {
92                                                 (XmlAttribute) ex.Detail};
93                                 else if (ex.Detail.NodeType == XmlNodeType.Element)
94                                         Detail.Children = new XmlElement [] {
95                                                 (XmlElement) ex.Detail};
96                                 else
97                                         Detail.Text = ex.Detail.Value;
98                         }
99                 }
100
101                 static Soap12FaultCode CreateFaultCode (SoapFaultSubCode code)
102                 {
103                         if (code == null)
104                                 throw new ArgumentNullException ("code");
105                         Soap12FaultCode ret = new Soap12FaultCode ();
106                         ret.Value = code.Code;
107                         if (code.SubCode != null)
108                                 ret.Subcode = CreateFaultCode (code.SubCode);
109                         return ret;
110                 }
111
112                 public static SoapFaultSubCode GetSoapFaultSubCode (Soap12FaultCode src)
113                 {
114                         return (src == null) ? null :
115                                 new SoapFaultSubCode (src.Value, GetSoapFaultSubCode (src.Subcode));
116                 }
117 #endif
118
119                 public Soap12FaultCode Code;
120
121                 public Soap12FaultReason Reason;
122
123                 [XmlElement (DataType = "anyURI")]
124                 public string Node;
125
126                 [XmlElement (DataType = "anyURI")]
127                 public string Role;
128
129                 public Soap12FaultDetail Detail;
130         }
131
132         [XmlType ("Code", Namespace = "http://www.w3.org/2003/05/soap-envelope")]
133         internal class Soap12FaultCode
134         {
135                 public XmlQualifiedName Value;
136
137                 public Soap12FaultCode Subcode;
138         }
139
140         [XmlType ("Reason", Namespace = "http://www.w3.org/2003/05/soap-envelope")]
141         internal class Soap12FaultReason
142         {
143                 [XmlElement ("Text", Namespace = "http://www.w3.org/2003/05/soap-envelope")]
144                 public Soap12FaultReasonText [] Texts;
145         }
146
147         [XmlType ("Text", Namespace = "http://www.w3.org/2003/05/soap-envelope")]
148         internal class Soap12FaultReasonText
149         {
150                 [XmlAttribute ("lang", Namespace = "http://www.w3.org/XML/1998/namespace")]
151                 public string XmlLang;
152
153                 [XmlText]
154                 public string Value;
155         }
156
157         [XmlType ("Detail", Namespace = "http://www.w3.org/2003/05/soap-envelope")]
158         internal class Soap12FaultDetail
159         {
160                 [XmlAnyAttribute]
161                 public XmlAttribute [] Attributes;
162
163                 [XmlAnyElement]
164                 public XmlElement [] Children;
165
166                 [XmlText]
167                 public string Text;
168         }
169 }