extra: import at 3.0.1 beta 1
[mozilla-extra.git] / extensions / webservices / soap / src / nsSOAPFault.cpp
blob6957f8c88652e0160efac1d85f3ad44778821a2e
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 2001
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #include "nsSOAPFault.h"
39 #include "nsSOAPUtils.h"
40 #include "nsIDOMNodeList.h"
41 #include "nsISOAPMessage.h"
42 #include "nsSOAPException.h"
43 #include "nsIClassInfoImpl.h"
45 nsSOAPFault::nsSOAPFault()
49 nsSOAPFault::~nsSOAPFault()
53 NS_IMPL_ISUPPORTS1_CI(nsSOAPFault, nsISOAPFault)
54 /* attribute nsIDOMElement element; */
55 NS_IMETHODIMP nsSOAPFault::SetElement(nsIDOMElement * aElement)
57 if (aElement) {
58 nsAutoString namespaceURI;
59 nsAutoString name;
60 nsresult rc = aElement->GetNamespaceURI(namespaceURI);
61 if (NS_FAILED(rc))
62 return rc;
63 rc = aElement->GetLocalName(name);
64 if (NS_FAILED(rc))
65 return rc;
66 if (name.Equals(gSOAPStrings->kFaultTagName)) {
67 if (namespaceURI.
68 Equals(*gSOAPStrings->kSOAPEnvURI[nsISOAPMessage::VERSION_1_2])) {
69 mVersion = nsISOAPMessage::VERSION_1_2;
70 } else if (namespaceURI.
71 Equals(*gSOAPStrings->kSOAPEnvURI[nsISOAPMessage::VERSION_1_1])) {
72 mVersion = nsISOAPMessage::VERSION_1_1;
73 } else {
74 return SOAP_EXCEPTION(NS_ERROR_ILLEGAL_VALUE,"SOAP_BADFAULT", "Cannot recognize SOAP version from namespace URI of fault");
76 } else {
77 return SOAP_EXCEPTION(NS_ERROR_ILLEGAL_VALUE,"SOAP_BADFAULT", "Cannot recognize element tag of fault.");
80 mFaultElement = aElement;
81 return NS_OK;
84 NS_IMETHODIMP nsSOAPFault::GetElement(nsIDOMElement * *aElement)
86 NS_ENSURE_ARG_POINTER(aElement);
87 *aElement = mFaultElement;
88 NS_IF_ADDREF(*aElement);
89 return NS_OK;
92 /* readonly attribute wstring faultCode; */
93 NS_IMETHODIMP nsSOAPFault::GetFaultCode(nsAString & aFaultCode)
95 if (!mFaultElement)
96 return NS_ERROR_ILLEGAL_VALUE;
97 aFaultCode.Truncate();
98 nsCOMPtr<nsIDOMElement> faultcode;
99 nsSOAPUtils::GetSpecificChildElement(nsnull, mFaultElement,
100 gSOAPStrings->kEmpty,
101 gSOAPStrings->kFaultCodeTagName,
102 getter_AddRefs(faultcode));
103 if (faultcode) {
104 nsAutoString combined;
105 nsresult rc = nsSOAPUtils::GetElementTextContent(faultcode, combined);
106 if (NS_FAILED(rc))
107 return rc;
108 return nsSOAPUtils::GetLocalName(combined, aFaultCode);
110 return NS_OK;
113 /* readonly attribute wstring faultNamespaceURI; */
114 NS_IMETHODIMP nsSOAPFault::GetFaultNamespaceURI(nsAString & aNamespaceURI)
116 if (!mFaultElement)
117 return NS_ERROR_ILLEGAL_VALUE;
118 aNamespaceURI.Truncate();
119 nsCOMPtr<nsIDOMElement> faultcode;
120 nsSOAPUtils::GetSpecificChildElement(nsnull, mFaultElement,
121 gSOAPStrings->kEmpty,
122 gSOAPStrings->kFaultCodeTagName,
123 getter_AddRefs(faultcode));
124 if (faultcode) {
125 nsAutoString combined;
126 nsresult rc = nsSOAPUtils::GetElementTextContent(faultcode, combined);
127 if (NS_FAILED(rc))
128 return rc;
129 return nsSOAPUtils::GetNamespaceURI(nsnull, faultcode, combined, aNamespaceURI);
131 return NS_OK;
134 /* readonly attribute wstring faultString; */
135 NS_IMETHODIMP nsSOAPFault::GetFaultString(nsAString & aFaultString)
137 if (!mFaultElement)
138 return NS_ERROR_ILLEGAL_VALUE;
140 aFaultString.Truncate();
141 nsCOMPtr<nsIDOMElement> element;
142 nsSOAPUtils::GetSpecificChildElement(nsnull, mFaultElement,
143 gSOAPStrings->kEmpty,
144 gSOAPStrings->kFaultStringTagName,
145 getter_AddRefs(element));
146 if (element) {
147 nsresult rc = nsSOAPUtils::GetElementTextContent(element, aFaultString);
148 if (NS_FAILED(rc))
149 return rc;
151 return NS_OK;
154 /* readonly attribute wstring faultActor; */
155 NS_IMETHODIMP nsSOAPFault::GetFaultActor(nsAString & aFaultActor)
157 if (!mFaultElement)
158 return NS_ERROR_ILLEGAL_VALUE;
160 aFaultActor.Truncate();
161 nsCOMPtr<nsIDOMElement> element;
162 nsSOAPUtils::GetSpecificChildElement(nsnull, mFaultElement,
163 gSOAPStrings->kEmpty,
164 gSOAPStrings->kFaultActorTagName,
165 getter_AddRefs(element));
166 if (element) {
167 nsresult rc = nsSOAPUtils::GetElementTextContent(element, aFaultActor);
168 if (NS_FAILED(rc))
169 return rc;
171 return NS_OK;
174 /* readonly attribute nsIDOMElement detail; */
175 NS_IMETHODIMP nsSOAPFault::GetDetail(nsIDOMElement * *aDetail)
177 NS_ENSURE_ARG_POINTER(aDetail);
178 if (!mFaultElement)
179 return NS_ERROR_ILLEGAL_VALUE;
181 nsSOAPUtils::GetSpecificChildElement(nsnull, mFaultElement,
182 gSOAPStrings->kEmpty,
183 gSOAPStrings->kFaultDetailTagName,
184 aDetail);
185 return NS_OK;