2001-09-25 22:53:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2001-03-02 15:18:56 +00:00
|
|
|
|
2012-07-13 06:33:42 +00:00
|
|
|
#include "mozilla/mozalloc.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "nsError.h"
|
|
|
|
#include "nsID.h"
|
|
|
|
#include "nsISupportsUtils.h"
|
2001-03-02 15:18:56 +00:00
|
|
|
#include "nsITransactionManager.h"
|
|
|
|
#include "nsTransactionItem.h"
|
|
|
|
#include "nsTransactionList.h"
|
|
|
|
#include "nsTransactionStack.h"
|
2012-07-13 06:33:42 +00:00
|
|
|
#include "nscore.h"
|
|
|
|
#include "prtypes.h"
|
2001-03-02 15:18:56 +00:00
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(nsTransactionList, nsITransactionList)
|
|
|
|
|
|
|
|
nsTransactionList::nsTransactionList(nsITransactionManager *aTxnMgr, nsTransactionStack *aTxnStack)
|
|
|
|
: mTxnStack(aTxnStack)
|
|
|
|
, mTxnItem(0)
|
|
|
|
{
|
|
|
|
if (aTxnMgr)
|
2003-07-25 19:06:59 +00:00
|
|
|
mTxnMgr = do_GetWeakReference(aTxnMgr);
|
2001-03-02 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsTransactionList::nsTransactionList(nsITransactionManager *aTxnMgr, nsTransactionItem *aTxnItem)
|
|
|
|
: mTxnStack(0)
|
|
|
|
, mTxnItem(aTxnItem)
|
|
|
|
{
|
|
|
|
if (aTxnMgr)
|
2003-07-25 19:06:59 +00:00
|
|
|
mTxnMgr = do_GetWeakReference(aTxnMgr);
|
2001-03-02 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsTransactionList::~nsTransactionList()
|
|
|
|
{
|
|
|
|
mTxnStack = 0;
|
|
|
|
mTxnItem = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* readonly attribute long numItems; */
|
|
|
|
NS_IMETHODIMP nsTransactionList::GetNumItems(PRInt32 *aNumItems)
|
|
|
|
{
|
2010-06-17 20:40:48 +00:00
|
|
|
NS_ENSURE_TRUE(aNumItems, NS_ERROR_NULL_POINTER);
|
2001-03-02 15:18:56 +00:00
|
|
|
|
|
|
|
*aNumItems = 0;
|
|
|
|
|
|
|
|
nsCOMPtr<nsITransactionManager> txMgr = do_QueryReferent(mTxnMgr);
|
|
|
|
|
2010-06-17 20:40:48 +00:00
|
|
|
NS_ENSURE_TRUE(txMgr, NS_ERROR_FAILURE);
|
2001-03-02 15:18:56 +00:00
|
|
|
|
2012-03-02 20:08:40 +00:00
|
|
|
nsresult result = NS_OK;
|
2001-03-02 15:18:56 +00:00
|
|
|
|
|
|
|
if (mTxnStack)
|
2012-03-02 20:08:40 +00:00
|
|
|
*aNumItems = mTxnStack->GetSize();
|
2001-03-02 15:18:56 +00:00
|
|
|
else if (mTxnItem)
|
|
|
|
result = mTxnItem->GetNumberOfChildren(aNumItems);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* boolean itemIsBatch (in long aIndex); */
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP nsTransactionList::ItemIsBatch(PRInt32 aIndex, bool *aIsBatch)
|
2001-03-02 15:18:56 +00:00
|
|
|
{
|
2010-06-17 20:40:48 +00:00
|
|
|
NS_ENSURE_TRUE(aIsBatch, NS_ERROR_NULL_POINTER);
|
2001-03-02 15:18:56 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
*aIsBatch = false;
|
2001-03-02 15:18:56 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsITransactionManager> txMgr = do_QueryReferent(mTxnMgr);
|
|
|
|
|
2010-06-17 20:40:48 +00:00
|
|
|
NS_ENSURE_TRUE(txMgr, NS_ERROR_FAILURE);
|
2001-03-02 15:18:56 +00:00
|
|
|
|
2008-12-10 16:46:36 +00:00
|
|
|
nsRefPtr<nsTransactionItem> item;
|
2001-03-02 15:18:56 +00:00
|
|
|
|
2012-03-02 20:08:40 +00:00
|
|
|
nsresult result = NS_OK;
|
2001-03-02 15:18:56 +00:00
|
|
|
|
|
|
|
if (mTxnStack)
|
2012-03-02 20:08:40 +00:00
|
|
|
item = mTxnStack->GetItem(aIndex);
|
2001-03-02 15:18:56 +00:00
|
|
|
else if (mTxnItem)
|
2008-12-10 16:46:36 +00:00
|
|
|
result = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
|
2001-03-02 15:18:56 +00:00
|
|
|
|
2010-06-17 20:44:35 +00:00
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
2001-03-02 15:18:56 +00:00
|
|
|
|
2010-06-17 20:40:48 +00:00
|
|
|
NS_ENSURE_TRUE(item, NS_ERROR_FAILURE);
|
2001-03-02 15:18:56 +00:00
|
|
|
|
|
|
|
return item->GetIsBatch(aIsBatch);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* nsITransaction getItem (in long aIndex); */
|
|
|
|
NS_IMETHODIMP nsTransactionList::GetItem(PRInt32 aIndex, nsITransaction **aItem)
|
|
|
|
{
|
2010-06-17 20:40:48 +00:00
|
|
|
NS_ENSURE_TRUE(aItem, NS_ERROR_NULL_POINTER);
|
2001-03-02 15:18:56 +00:00
|
|
|
|
|
|
|
*aItem = 0;
|
|
|
|
|
|
|
|
nsCOMPtr<nsITransactionManager> txMgr = do_QueryReferent(mTxnMgr);
|
|
|
|
|
2010-06-17 20:40:48 +00:00
|
|
|
NS_ENSURE_TRUE(txMgr, NS_ERROR_FAILURE);
|
2001-03-02 15:18:56 +00:00
|
|
|
|
2008-12-10 16:46:36 +00:00
|
|
|
nsRefPtr<nsTransactionItem> item;
|
2001-03-02 15:18:56 +00:00
|
|
|
|
2012-03-02 20:08:40 +00:00
|
|
|
nsresult result = NS_OK;
|
2001-03-02 15:18:56 +00:00
|
|
|
|
|
|
|
if (mTxnStack)
|
2012-03-02 20:08:40 +00:00
|
|
|
item = mTxnStack->GetItem(aIndex);
|
2001-03-02 15:18:56 +00:00
|
|
|
else if (mTxnItem)
|
2008-12-10 16:46:36 +00:00
|
|
|
result = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
|
2001-03-02 15:18:56 +00:00
|
|
|
|
2010-06-17 20:44:35 +00:00
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
2001-03-02 15:18:56 +00:00
|
|
|
|
2010-06-17 20:40:48 +00:00
|
|
|
NS_ENSURE_TRUE(item, NS_ERROR_FAILURE);
|
2001-03-02 15:18:56 +00:00
|
|
|
|
2012-06-19 13:23:36 +00:00
|
|
|
*aItem = item->GetTransaction().get();
|
|
|
|
|
|
|
|
return NS_OK;
|
2001-03-02 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* long getNumChildrenForItem (in long aIndex); */
|
|
|
|
NS_IMETHODIMP nsTransactionList::GetNumChildrenForItem(PRInt32 aIndex, PRInt32 *aNumChildren)
|
|
|
|
{
|
2010-06-17 20:40:48 +00:00
|
|
|
NS_ENSURE_TRUE(aNumChildren, NS_ERROR_NULL_POINTER);
|
2001-03-02 15:18:56 +00:00
|
|
|
|
|
|
|
*aNumChildren = 0;
|
|
|
|
|
|
|
|
nsCOMPtr<nsITransactionManager> txMgr = do_QueryReferent(mTxnMgr);
|
|
|
|
|
2010-06-17 20:40:48 +00:00
|
|
|
NS_ENSURE_TRUE(txMgr, NS_ERROR_FAILURE);
|
2001-03-02 15:18:56 +00:00
|
|
|
|
2008-12-10 16:46:36 +00:00
|
|
|
nsRefPtr<nsTransactionItem> item;
|
2001-03-02 15:18:56 +00:00
|
|
|
|
2012-03-02 20:08:40 +00:00
|
|
|
nsresult result = NS_OK;
|
2001-03-02 15:18:56 +00:00
|
|
|
|
|
|
|
if (mTxnStack)
|
2012-03-02 20:08:40 +00:00
|
|
|
item = mTxnStack->GetItem(aIndex);
|
2001-03-02 15:18:56 +00:00
|
|
|
else if (mTxnItem)
|
2008-12-10 16:46:36 +00:00
|
|
|
result = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
|
2001-03-02 15:18:56 +00:00
|
|
|
|
2010-06-17 20:44:35 +00:00
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
2001-03-02 15:18:56 +00:00
|
|
|
|
2010-06-17 20:40:48 +00:00
|
|
|
NS_ENSURE_TRUE(item, NS_ERROR_FAILURE);
|
2001-03-02 15:18:56 +00:00
|
|
|
|
|
|
|
return item->GetNumberOfChildren(aNumChildren);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* nsITransactionList getChildListForItem (in long aIndex); */
|
|
|
|
NS_IMETHODIMP nsTransactionList::GetChildListForItem(PRInt32 aIndex, nsITransactionList **aTxnList)
|
|
|
|
{
|
2010-06-17 20:40:48 +00:00
|
|
|
NS_ENSURE_TRUE(aTxnList, NS_ERROR_NULL_POINTER);
|
2001-03-02 15:18:56 +00:00
|
|
|
|
|
|
|
*aTxnList = 0;
|
|
|
|
|
|
|
|
nsCOMPtr<nsITransactionManager> txMgr = do_QueryReferent(mTxnMgr);
|
|
|
|
|
2010-06-17 20:40:48 +00:00
|
|
|
NS_ENSURE_TRUE(txMgr, NS_ERROR_FAILURE);
|
2001-03-02 15:18:56 +00:00
|
|
|
|
2008-12-10 16:46:36 +00:00
|
|
|
nsRefPtr<nsTransactionItem> item;
|
2001-03-02 15:18:56 +00:00
|
|
|
|
2012-03-02 20:08:40 +00:00
|
|
|
nsresult result = NS_OK;
|
2001-03-02 15:18:56 +00:00
|
|
|
|
|
|
|
if (mTxnStack)
|
2012-03-02 20:08:40 +00:00
|
|
|
item = mTxnStack->GetItem(aIndex);
|
2001-03-02 15:18:56 +00:00
|
|
|
else if (mTxnItem)
|
2008-12-10 16:46:36 +00:00
|
|
|
result = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
|
2001-03-02 15:18:56 +00:00
|
|
|
|
2010-06-17 20:44:35 +00:00
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
2001-03-02 15:18:56 +00:00
|
|
|
|
2010-06-17 20:40:48 +00:00
|
|
|
NS_ENSURE_TRUE(item, NS_ERROR_FAILURE);
|
2001-03-02 15:18:56 +00:00
|
|
|
|
|
|
|
*aTxnList = (nsITransactionList *)new nsTransactionList(txMgr, item);
|
|
|
|
|
2010-06-17 20:40:48 +00:00
|
|
|
NS_ENSURE_TRUE(*aTxnList, NS_ERROR_OUT_OF_MEMORY);
|
2001-03-02 15:18:56 +00:00
|
|
|
|
|
|
|
NS_ADDREF(*aTxnList);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|