Back to index

lightning-sunbird  0.9+nobinonly
nsTransactionList.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) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "nsITransactionManager.h"
00039 #include "nsTransactionItem.h"
00040 #include "nsTransactionList.h"
00041 #include "nsTransactionStack.h"
00042 
00043 NS_IMPL_ISUPPORTS1(nsTransactionList, nsITransactionList)
00044 
00045 nsTransactionList::nsTransactionList(nsITransactionManager *aTxnMgr, nsTransactionStack *aTxnStack)
00046   : mTxnStack(aTxnStack)
00047   , mTxnItem(0)
00048 {
00049   if (aTxnMgr)
00050     mTxnMgr = do_GetWeakReference(aTxnMgr);
00051 }
00052 
00053 nsTransactionList::nsTransactionList(nsITransactionManager *aTxnMgr, nsTransactionItem *aTxnItem)
00054   : mTxnStack(0)
00055   , mTxnItem(aTxnItem)
00056 {
00057   if (aTxnMgr)
00058     mTxnMgr = do_GetWeakReference(aTxnMgr);
00059 }
00060 
00061 nsTransactionList::~nsTransactionList()
00062 {
00063   mTxnStack = 0;
00064   mTxnItem  = 0;
00065 }
00066 
00067 /* readonly attribute long numItems; */
00068 NS_IMETHODIMP nsTransactionList::GetNumItems(PRInt32 *aNumItems)
00069 {
00070   if (!aNumItems)
00071     return NS_ERROR_NULL_POINTER;
00072 
00073   *aNumItems = 0;
00074 
00075   nsCOMPtr<nsITransactionManager> txMgr = do_QueryReferent(mTxnMgr);
00076 
00077   if (!txMgr)
00078     return NS_ERROR_FAILURE;
00079 
00080   nsresult result = NS_ERROR_FAILURE;
00081 
00082   if (mTxnStack)
00083     result = mTxnStack->GetSize(aNumItems);
00084   else if (mTxnItem)
00085     result = mTxnItem->GetNumberOfChildren(aNumItems);
00086 
00087   return result;
00088 }
00089 
00090 /* boolean itemIsBatch (in long aIndex); */
00091 NS_IMETHODIMP nsTransactionList::ItemIsBatch(PRInt32 aIndex, PRBool *aIsBatch)
00092 {
00093   if (!aIsBatch)
00094     return NS_ERROR_NULL_POINTER;
00095 
00096   *aIsBatch = PR_FALSE;
00097 
00098   nsCOMPtr<nsITransactionManager> txMgr = do_QueryReferent(mTxnMgr);
00099 
00100   if (!txMgr)
00101     return NS_ERROR_FAILURE;
00102 
00103   nsTransactionItem *item = 0;
00104 
00105   nsresult result = NS_ERROR_FAILURE;
00106 
00107   if (mTxnStack)
00108     result = mTxnStack->GetItem(aIndex, &item);
00109   else if (mTxnItem)
00110     result = mTxnItem->GetChild(aIndex, &item);
00111 
00112   if (NS_FAILED(result))
00113     return result;
00114 
00115   if (!item)
00116     return NS_ERROR_FAILURE;
00117 
00118   return item->GetIsBatch(aIsBatch);
00119 }
00120 
00121 /* nsITransaction getItem (in long aIndex); */
00122 NS_IMETHODIMP nsTransactionList::GetItem(PRInt32 aIndex, nsITransaction **aItem)
00123 {
00124   if (!aItem)
00125     return NS_ERROR_NULL_POINTER;
00126 
00127   *aItem = 0;
00128 
00129   nsCOMPtr<nsITransactionManager> txMgr = do_QueryReferent(mTxnMgr);
00130 
00131   if (!txMgr)
00132     return NS_ERROR_FAILURE;
00133 
00134   nsTransactionItem *item = 0;
00135 
00136   nsresult result = NS_ERROR_FAILURE;
00137 
00138   if (mTxnStack)
00139     result = mTxnStack->GetItem(aIndex, &item);
00140   else if (mTxnItem)
00141     result = mTxnItem->GetChild(aIndex, &item);
00142 
00143   if (NS_FAILED(result))
00144     return result;
00145 
00146   if (!item)
00147     return NS_ERROR_FAILURE;
00148 
00149   result = item->GetTransaction(aItem);
00150 
00151   if (NS_FAILED(result))
00152     return result;
00153 
00154   NS_IF_ADDREF(*aItem);
00155 
00156   return NS_OK;
00157 }
00158 
00159 /* long getNumChildrenForItem (in long aIndex); */
00160 NS_IMETHODIMP nsTransactionList::GetNumChildrenForItem(PRInt32 aIndex, PRInt32 *aNumChildren)
00161 {
00162   if (!aNumChildren)
00163     return NS_ERROR_NULL_POINTER;
00164 
00165   *aNumChildren = 0;
00166 
00167   nsCOMPtr<nsITransactionManager> txMgr = do_QueryReferent(mTxnMgr);
00168 
00169   if (!txMgr)
00170     return NS_ERROR_FAILURE;
00171 
00172   nsTransactionItem *item = 0;
00173 
00174   nsresult result = NS_ERROR_FAILURE;
00175 
00176   if (mTxnStack)
00177     result = mTxnStack->GetItem(aIndex, &item);
00178   else if (mTxnItem)
00179     result = mTxnItem->GetChild(aIndex, &item);
00180 
00181   if (NS_FAILED(result))
00182     return result;
00183 
00184   if (!item)
00185     return NS_ERROR_FAILURE;
00186 
00187   return item->GetNumberOfChildren(aNumChildren);
00188 }
00189 
00190 /* nsITransactionList getChildListForItem (in long aIndex); */
00191 NS_IMETHODIMP nsTransactionList::GetChildListForItem(PRInt32 aIndex, nsITransactionList **aTxnList)
00192 {
00193   if (!aTxnList)
00194     return NS_ERROR_NULL_POINTER;
00195 
00196   *aTxnList = 0;
00197 
00198   nsCOMPtr<nsITransactionManager> txMgr = do_QueryReferent(mTxnMgr);
00199 
00200   if (!txMgr)
00201     return NS_ERROR_FAILURE;
00202 
00203   nsTransactionItem *item = 0;
00204 
00205   nsresult result = NS_ERROR_FAILURE;
00206 
00207   if (mTxnStack)
00208     result = mTxnStack->GetItem(aIndex, &item);
00209   else if (mTxnItem)
00210     result = mTxnItem->GetChild(aIndex, &item);
00211 
00212   if (NS_FAILED(result))
00213     return result;
00214 
00215   if (!item)
00216     return NS_ERROR_FAILURE;
00217 
00218   *aTxnList = (nsITransactionList *)new nsTransactionList(txMgr, item);
00219 
00220   if (!*aTxnList)
00221     return NS_ERROR_OUT_OF_MEMORY;
00222 
00223   NS_ADDREF(*aTxnList);
00224 
00225   return NS_OK;
00226 }
00227