Back to index

lightning-sunbird  0.9+nobinonly
wspexception.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 2001
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Vidur Apparao (vidur@netscape.com) (Original author)
00024  *   John Bandhauer (jband@netscape.com)
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #include "wspprivate.h"
00041 
00042 WSPException::WSPException(nsISOAPFault* aFault, nsresult aStatus)
00043   : mFault(aFault), mData(nsnull), mStatus(aStatus), mMsg(nsnull)
00044 {
00045 }
00046 
00047 WSPException::WSPException(nsresult aStatus, const char* aMsg,
00048                            nsISupports* aData)
00049   : mFault(nsnull), mData(aData), mStatus(aStatus), mMsg(nsnull)
00050 {
00051   if (aMsg) {
00052     mMsg = (char*) nsMemory::Clone(aMsg, strlen(aMsg)+1);
00053   }
00054 }
00055 
00056 
00057 WSPException::~WSPException()
00058 {
00059   if (mMsg) {
00060     nsMemory::Free(mMsg);
00061   }
00062 }
00063 
00064 NS_IMPL_ISUPPORTS1_CI(WSPException, nsIException)
00065 
00066 /* readonly attribute string message; */
00067 NS_IMETHODIMP
00068 WSPException::GetMessage(char * *aMessage)
00069 {
00070   NS_ENSURE_ARG_POINTER(aMessage);
00071 
00072   *aMessage = nsnull;
00073   if (mFault) {
00074     nsAutoString faultString;
00075     mFault->GetFaultString(faultString);
00076     *aMessage = ToNewUTF8String(faultString);
00077   }
00078   else if (mMsg) {
00079     *aMessage = (char*) nsMemory::Clone(mMsg, strlen(mMsg)+1);
00080   }
00081 
00082   return NS_OK;
00083 
00084 }
00085 
00086 /* readonly attribute nsresult result; */
00087 NS_IMETHODIMP
00088 WSPException::GetResult(nsresult *aResult)
00089 {
00090   NS_ENSURE_ARG_POINTER(aResult);
00091   *aResult = mStatus;
00092   return NS_OK;
00093 }
00094 
00095 /* readonly attribute string name; */
00096 NS_IMETHODIMP
00097 WSPException::GetName(char * *aName)
00098 {
00099   NS_ENSURE_ARG_POINTER(aName);
00100   *aName = nsnull;
00101   if (mFault) {
00102     nsAutoString faultCode;
00103     mFault->GetFaultCode(faultCode);
00104     *aName = ToNewUTF8String(faultCode);
00105   }
00106   return NS_OK;
00107 }
00108 
00109 /* readonly attribute string filename; */
00110 NS_IMETHODIMP
00111 WSPException::GetFilename(char * *aFilename)
00112 {
00113   NS_ENSURE_ARG_POINTER(aFilename);
00114   *aFilename = nsnull;
00115   return NS_OK;
00116 }
00117 
00118 /* readonly attribute PRUint32 lineNumber; */
00119 NS_IMETHODIMP
00120 WSPException::GetLineNumber(PRUint32 *aLineNumber)
00121 {
00122   NS_ENSURE_ARG_POINTER(aLineNumber);
00123   *aLineNumber = 0;
00124   return NS_OK;
00125 }
00126 
00127 /* readonly attribute PRUint32 columnNumber; */
00128 NS_IMETHODIMP
00129 WSPException::GetColumnNumber(PRUint32 *aColumnNumber)
00130 {
00131   NS_ENSURE_ARG_POINTER(aColumnNumber);
00132   *aColumnNumber = 0;
00133   return NS_OK;
00134 }
00135 
00136 /* readonly attribute nsIStackFrame location; */
00137 NS_IMETHODIMP
00138 WSPException::GetLocation(nsIStackFrame * *aLocation)
00139 {
00140   NS_ENSURE_ARG_POINTER(aLocation);
00141   *aLocation = nsnull;
00142   return NS_OK;
00143 }
00144 
00145 /* readonly attribute nsIException inner; */
00146 NS_IMETHODIMP
00147 WSPException::GetInner(nsIException * *aInner)
00148 {
00149   NS_ENSURE_ARG_POINTER(aInner);
00150   *aInner = nsnull;
00151   return NS_OK;
00152 }
00153 
00154 /* readonly attribute nsISupports data; */
00155 NS_IMETHODIMP
00156 WSPException::GetData(nsISupports * *aData)
00157 {
00158   NS_ENSURE_ARG_POINTER(aData);
00159   if (mFault) {
00160     *aData = mFault;
00161   }
00162   else if (mData) {
00163     *aData = mData;
00164   }
00165   else {
00166     *aData = nsnull;
00167   }
00168 
00169   NS_IF_ADDREF(*aData);
00170   return NS_OK;
00171 }
00172 
00173 /* string toString (); */
00174 NS_IMETHODIMP
00175 WSPException::ToString(char **_retval)
00176 {
00177   if (mFault) {
00178     return GetName(_retval);
00179   }
00180   // else
00181   return GetMessage(_retval);
00182 }
00183