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
4 : *
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/
9 : *
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.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 1998
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either of the GNU General Public License Version 2 or later (the "GPL"),
26 : * or 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.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : #include "nsITransactionManager.h"
39 : #include "nsTransactionItem.h"
40 : #include "nsTransactionList.h"
41 : #include "nsTransactionStack.h"
42 :
43 0 : NS_IMPL_ISUPPORTS1(nsTransactionList, nsITransactionList)
44 :
45 0 : nsTransactionList::nsTransactionList(nsITransactionManager *aTxnMgr, nsTransactionStack *aTxnStack)
46 : : mTxnStack(aTxnStack)
47 0 : , mTxnItem(0)
48 : {
49 0 : if (aTxnMgr)
50 0 : mTxnMgr = do_GetWeakReference(aTxnMgr);
51 0 : }
52 :
53 0 : nsTransactionList::nsTransactionList(nsITransactionManager *aTxnMgr, nsTransactionItem *aTxnItem)
54 : : mTxnStack(0)
55 0 : , mTxnItem(aTxnItem)
56 : {
57 0 : if (aTxnMgr)
58 0 : mTxnMgr = do_GetWeakReference(aTxnMgr);
59 0 : }
60 :
61 0 : nsTransactionList::~nsTransactionList()
62 : {
63 0 : mTxnStack = 0;
64 0 : mTxnItem = 0;
65 0 : }
66 :
67 : /* readonly attribute long numItems; */
68 0 : NS_IMETHODIMP nsTransactionList::GetNumItems(PRInt32 *aNumItems)
69 : {
70 0 : NS_ENSURE_TRUE(aNumItems, NS_ERROR_NULL_POINTER);
71 :
72 0 : *aNumItems = 0;
73 :
74 0 : nsCOMPtr<nsITransactionManager> txMgr = do_QueryReferent(mTxnMgr);
75 :
76 0 : NS_ENSURE_TRUE(txMgr, NS_ERROR_FAILURE);
77 :
78 0 : nsresult result = NS_OK;
79 :
80 0 : if (mTxnStack)
81 0 : *aNumItems = mTxnStack->GetSize();
82 0 : else if (mTxnItem)
83 0 : result = mTxnItem->GetNumberOfChildren(aNumItems);
84 :
85 0 : return result;
86 : }
87 :
88 : /* boolean itemIsBatch (in long aIndex); */
89 0 : NS_IMETHODIMP nsTransactionList::ItemIsBatch(PRInt32 aIndex, bool *aIsBatch)
90 : {
91 0 : NS_ENSURE_TRUE(aIsBatch, NS_ERROR_NULL_POINTER);
92 :
93 0 : *aIsBatch = false;
94 :
95 0 : nsCOMPtr<nsITransactionManager> txMgr = do_QueryReferent(mTxnMgr);
96 :
97 0 : NS_ENSURE_TRUE(txMgr, NS_ERROR_FAILURE);
98 :
99 0 : nsRefPtr<nsTransactionItem> item;
100 :
101 0 : nsresult result = NS_OK;
102 :
103 0 : if (mTxnStack)
104 0 : item = mTxnStack->GetItem(aIndex);
105 0 : else if (mTxnItem)
106 0 : result = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
107 :
108 0 : NS_ENSURE_SUCCESS(result, result);
109 :
110 0 : NS_ENSURE_TRUE(item, NS_ERROR_FAILURE);
111 :
112 0 : return item->GetIsBatch(aIsBatch);
113 : }
114 :
115 : /* nsITransaction getItem (in long aIndex); */
116 0 : NS_IMETHODIMP nsTransactionList::GetItem(PRInt32 aIndex, nsITransaction **aItem)
117 : {
118 0 : NS_ENSURE_TRUE(aItem, NS_ERROR_NULL_POINTER);
119 :
120 0 : *aItem = 0;
121 :
122 0 : nsCOMPtr<nsITransactionManager> txMgr = do_QueryReferent(mTxnMgr);
123 :
124 0 : NS_ENSURE_TRUE(txMgr, NS_ERROR_FAILURE);
125 :
126 0 : nsRefPtr<nsTransactionItem> item;
127 :
128 0 : nsresult result = NS_OK;
129 :
130 0 : if (mTxnStack)
131 0 : item = mTxnStack->GetItem(aIndex);
132 0 : else if (mTxnItem)
133 0 : result = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
134 :
135 0 : NS_ENSURE_SUCCESS(result, result);
136 :
137 0 : NS_ENSURE_TRUE(item, NS_ERROR_FAILURE);
138 :
139 0 : return item->GetTransaction(aItem);
140 : }
141 :
142 : /* long getNumChildrenForItem (in long aIndex); */
143 0 : NS_IMETHODIMP nsTransactionList::GetNumChildrenForItem(PRInt32 aIndex, PRInt32 *aNumChildren)
144 : {
145 0 : NS_ENSURE_TRUE(aNumChildren, NS_ERROR_NULL_POINTER);
146 :
147 0 : *aNumChildren = 0;
148 :
149 0 : nsCOMPtr<nsITransactionManager> txMgr = do_QueryReferent(mTxnMgr);
150 :
151 0 : NS_ENSURE_TRUE(txMgr, NS_ERROR_FAILURE);
152 :
153 0 : nsRefPtr<nsTransactionItem> item;
154 :
155 0 : nsresult result = NS_OK;
156 :
157 0 : if (mTxnStack)
158 0 : item = mTxnStack->GetItem(aIndex);
159 0 : else if (mTxnItem)
160 0 : result = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
161 :
162 0 : NS_ENSURE_SUCCESS(result, result);
163 :
164 0 : NS_ENSURE_TRUE(item, NS_ERROR_FAILURE);
165 :
166 0 : return item->GetNumberOfChildren(aNumChildren);
167 : }
168 :
169 : /* nsITransactionList getChildListForItem (in long aIndex); */
170 0 : NS_IMETHODIMP nsTransactionList::GetChildListForItem(PRInt32 aIndex, nsITransactionList **aTxnList)
171 : {
172 0 : NS_ENSURE_TRUE(aTxnList, NS_ERROR_NULL_POINTER);
173 :
174 0 : *aTxnList = 0;
175 :
176 0 : nsCOMPtr<nsITransactionManager> txMgr = do_QueryReferent(mTxnMgr);
177 :
178 0 : NS_ENSURE_TRUE(txMgr, NS_ERROR_FAILURE);
179 :
180 0 : nsRefPtr<nsTransactionItem> item;
181 :
182 0 : nsresult result = NS_OK;
183 :
184 0 : if (mTxnStack)
185 0 : item = mTxnStack->GetItem(aIndex);
186 0 : else if (mTxnItem)
187 0 : result = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
188 :
189 0 : NS_ENSURE_SUCCESS(result, result);
190 :
191 0 : NS_ENSURE_TRUE(item, NS_ERROR_FAILURE);
192 :
193 0 : *aTxnList = (nsITransactionList *)new nsTransactionList(txMgr, item);
194 :
195 0 : NS_ENSURE_TRUE(*aTxnList, NS_ERROR_OUT_OF_MEMORY);
196 :
197 0 : NS_ADDREF(*aTxnList);
198 :
199 0 : return NS_OK;
200 : }
201 :
|