extra: import at 3.0.1 beta 1
[mozilla-extra.git] / extensions / webservices / proxy / src / wspexception.cpp
blobd4b466604c26fa12cda9236d0d69cae1e9a0d8e9
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):
23 * Vidur Apparao (vidur@netscape.com) (Original author)
24 * John Bandhauer (jband@netscape.com)
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #include "wspprivate.h"
42 WSPException::WSPException(nsISOAPFault* aFault, nsresult aStatus)
43 : mFault(aFault), mData(nsnull), mStatus(aStatus), mMsg(nsnull)
47 WSPException::WSPException(nsresult aStatus, const char* aMsg,
48 nsISupports* aData)
49 : mFault(nsnull), mData(aData), mStatus(aStatus), mMsg(nsnull)
51 if (aMsg) {
52 mMsg = (char*) nsMemory::Clone(aMsg, strlen(aMsg)+1);
57 WSPException::~WSPException()
59 if (mMsg) {
60 nsMemory::Free(mMsg);
64 NS_IMPL_ISUPPORTS1_CI(WSPException, nsIException)
66 /* readonly attribute string message; */
67 NS_IMETHODIMP
68 WSPException::GetMessageMoz(char * *aMessage)
70 NS_ENSURE_ARG_POINTER(aMessage);
72 *aMessage = nsnull;
73 if (mFault) {
74 nsAutoString faultString;
75 mFault->GetFaultString(faultString);
76 *aMessage = ToNewUTF8String(faultString);
78 else if (mMsg) {
79 *aMessage = (char*) nsMemory::Clone(mMsg, strlen(mMsg)+1);
82 return NS_OK;
86 /* readonly attribute nsresult result; */
87 NS_IMETHODIMP
88 WSPException::GetResult(nsresult *aResult)
90 NS_ENSURE_ARG_POINTER(aResult);
91 *aResult = mStatus;
92 return NS_OK;
95 /* readonly attribute string name; */
96 NS_IMETHODIMP
97 WSPException::GetName(char * *aName)
99 NS_ENSURE_ARG_POINTER(aName);
100 *aName = nsnull;
101 if (mFault) {
102 nsAutoString faultCode;
103 mFault->GetFaultCode(faultCode);
104 *aName = ToNewUTF8String(faultCode);
106 return NS_OK;
109 /* readonly attribute string filename; */
110 NS_IMETHODIMP
111 WSPException::GetFilename(char * *aFilename)
113 NS_ENSURE_ARG_POINTER(aFilename);
114 *aFilename = nsnull;
115 return NS_OK;
118 /* readonly attribute PRUint32 lineNumber; */
119 NS_IMETHODIMP
120 WSPException::GetLineNumber(PRUint32 *aLineNumber)
122 NS_ENSURE_ARG_POINTER(aLineNumber);
123 *aLineNumber = 0;
124 return NS_OK;
127 /* readonly attribute PRUint32 columnNumber; */
128 NS_IMETHODIMP
129 WSPException::GetColumnNumber(PRUint32 *aColumnNumber)
131 NS_ENSURE_ARG_POINTER(aColumnNumber);
132 *aColumnNumber = 0;
133 return NS_OK;
136 /* readonly attribute nsIStackFrame location; */
137 NS_IMETHODIMP
138 WSPException::GetLocation(nsIStackFrame * *aLocation)
140 NS_ENSURE_ARG_POINTER(aLocation);
141 *aLocation = nsnull;
142 return NS_OK;
145 /* readonly attribute nsIException inner; */
146 NS_IMETHODIMP
147 WSPException::GetInner(nsIException * *aInner)
149 NS_ENSURE_ARG_POINTER(aInner);
150 *aInner = nsnull;
151 return NS_OK;
154 /* readonly attribute nsISupports data; */
155 NS_IMETHODIMP
156 WSPException::GetData(nsISupports * *aData)
158 NS_ENSURE_ARG_POINTER(aData);
159 if (mFault) {
160 *aData = mFault;
162 else if (mData) {
163 *aData = mData;
165 else {
166 *aData = nsnull;
169 NS_IF_ADDREF(*aData);
170 return NS_OK;
173 /* string toString (); */
174 NS_IMETHODIMP
175 WSPException::ToString(char **_retval)
177 if (mFault) {
178 return GetName(_retval);
180 // else
181 return GetMessageMoz(_retval);