transport: pass correct channel
[abstract.git] / storage / base / aaSaveDispatcher.cpp
blob448c6c33e457f17eb31216a331017ffeef90311b
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent tw=79 ft=cpp: */
3 /*
4 * Copyright (C) 2007 Sergey Yanovich <ynvich@gmail.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 #include "xpcom-config.h"
24 #include "nsCOMPtr.h"
25 #include "nsISupportsUtils.h"
26 #include "nsComponentManagerUtils.h"
28 /* Unfrozen API */
30 /* Project includes */
31 #include "aaIEntity.h"
32 #include "aaIResource.h"
33 #include "aaIMoney.h"
34 #include "aaIFlow.h"
35 #include "aaIRule.h"
36 #include "aaIEvent.h"
37 #include "aaIQuote.h"
38 #include "aaITransaction.h"
39 #include "aaIChart.h"
40 #include "aaISession.h"
41 #include "aaISqlTransaction.h"
42 #include "aaSaveKeys.h"
43 #include "aaSaveDispatcher.h"
45 nsresult
46 aaSaveDispatcher::Init(nsISupports *aSession)
48 nsresult rv;
49 rv = CallQueryInterface(aSession, &mParentSession);
50 NS_ENSURE_SUCCESS(rv, rv);
51 mParentSession->Release();
52 return NS_OK;
55 NS_IMPL_ISUPPORTS3(aaSaveDispatcher,
56 aaISaveQuery,
57 aaIHandler,
58 aaIChartHandler)
60 /* aaISaveQuery */
61 NS_IMETHODIMP
62 aaSaveDispatcher::Save(aaIDataNode *aNode, aaIDataNode *aOldNode)
64 NS_ENSURE_ARG_POINTER(aNode);
65 mOldNode = aOldNode;
66 return aNode->Accept(this);
69 /* aaIHandler */
70 NS_IMETHODIMP
71 aaSaveDispatcher::HandleNode(aaIListNode *aNode)
73 return NS_ERROR_NOT_IMPLEMENTED;
76 NS_IMETHODIMP
77 aaSaveDispatcher::HandleEntity(aaIEntity *aEntity)
79 nsresult rv;
80 if (!mEntitySync) {
81 mEntitySync = do_CreateInstance(AA_SAVEENTITY_CONTRACT, &rv);
82 NS_ENSURE_SUCCESS(rv, rv);
85 rv = mEntitySync->SetParam(aEntity);
86 NS_ENSURE_SUCCESS(rv, rv);
88 return mParentSession->Execute(mEntitySync, nsnull);
91 NS_IMETHODIMP
92 aaSaveDispatcher::HandleResource(aaIResource *aResource)
94 return NS_ERROR_NOT_IMPLEMENTED;
97 NS_IMETHODIMP
98 aaSaveDispatcher::HandleMoney(aaIMoney *aMoney)
100 nsresult rv;
101 if (!mMoneySync) {
102 mMoneySync = do_CreateInstance(AA_SAVEMONEY_CONTRACT, &rv);
103 NS_ENSURE_SUCCESS(rv, rv);
106 rv = mMoneySync->SetParam(aMoney);
107 NS_ENSURE_SUCCESS(rv, rv);
109 return mParentSession->Execute(mMoneySync, nsnull);
112 NS_IMETHODIMP
113 aaSaveDispatcher::HandleAsset(aaIAsset *aAsset)
115 nsresult rv;
116 if (!mAssetSync) {
117 mAssetSync = do_CreateInstance(AA_SAVEASSET_CONTRACT, &rv);
118 NS_ENSURE_SUCCESS(rv, rv);
121 rv = mAssetSync->SetParam(aAsset);
122 NS_ENSURE_SUCCESS(rv, rv);
124 return mParentSession->Execute(mAssetSync, nsnull);
127 NS_IMETHODIMP
128 aaSaveDispatcher::HandleFlow(aaIFlow *aFlow)
130 nsresult rv;
131 if (!mFlowSync) {
132 mFlowSync = do_CreateInstance(AA_SAVEFLOW_CONTRACT, &rv);
133 NS_ENSURE_SUCCESS(rv, rv);
136 rv = mFlowSync->SetParam(aFlow);
137 NS_ENSURE_SUCCESS(rv, rv);
139 return mParentSession->Execute(mFlowSync, nsnull);
142 NS_IMETHODIMP
143 aaSaveDispatcher::HandleRule(aaIRule *aRule)
145 nsresult rv;
146 if (!mRuleSync) {
147 mRuleSync = do_CreateInstance(AA_SAVENORM_CONTRACT, &rv);
148 NS_ENSURE_SUCCESS(rv, rv);
151 rv = mRuleSync->SetParam(aRule);
152 NS_ENSURE_SUCCESS(rv, rv);
154 return mParentSession->Execute(mRuleSync, nsnull);
157 NS_IMETHODIMP
158 aaSaveDispatcher::HandleState(aaIState *aState)
160 return NS_ERROR_NOT_IMPLEMENTED;
163 NS_IMETHODIMP
164 aaSaveDispatcher::HandleFact(aaIFact *aFact)
166 return NS_OK;
169 NS_IMETHODIMP
170 aaSaveDispatcher::HandleEvent(aaIEvent *aEvent)
172 nsresult rv;
173 if (!mEventSync) {
174 mEventSync = do_CreateInstance(AA_SAVEEVENT_CONTRACT, &rv);
175 NS_ENSURE_SUCCESS(rv, rv);
178 rv = mEventSync->SetParam(aEvent);
179 NS_ENSURE_SUCCESS(rv, rv);
181 return mParentSession->Execute(mEventSync, nsnull);
184 NS_IMETHODIMP
185 aaSaveDispatcher::HandleQuote(aaIQuote *aQuote)
187 nsresult rv;
188 if (!mQuoteSync) {
189 mQuoteSync = do_CreateInstance(AA_SAVEQUOTE_CONTRACT, &rv);
190 NS_ENSURE_SUCCESS(rv, rv);
193 rv = mQuoteSync->SetParam(aQuote);
194 NS_ENSURE_SUCCESS(rv, rv);
196 return mParentSession->Execute(mQuoteSync, nsnull);
199 NS_IMETHODIMP
200 aaSaveDispatcher::HandleTransaction(aaITransaction *aTransaction)
202 nsresult rv;
203 if (!mTransactionSync) {
204 mTransactionSync = do_CreateInstance(AA_SAVETRANSACTION_CONTRACT, &rv);
205 NS_ENSURE_SUCCESS(rv, rv);
208 rv = mTransactionSync->SetParam(aTransaction);
209 NS_ENSURE_SUCCESS(rv, rv);
211 return mParentSession->Execute(mTransactionSync, nsnull);
214 /* aaIHandler */
215 NS_IMETHODIMP
216 aaSaveDispatcher::HandleChart(aaIChart *aChart)
218 nsresult rv;
219 if (!mChartSync) {
220 mChartSync = do_CreateInstance(AA_SAVECHART_CONTRACT, &rv);
221 NS_ENSURE_SUCCESS(rv, rv);
224 rv = mChartSync->SetParam(aChart);
225 NS_ENSURE_SUCCESS(rv, rv);
227 return mParentSession->Execute(mChartSync, nsnull);
230 NS_IMETHODIMP
231 aaSaveDispatcher::HandleBalance(aaIBalance *aBalance)
233 return NS_ERROR_NOT_IMPLEMENTED;
236 NS_IMETHODIMP
237 aaSaveDispatcher::HandleIncome(aaIBalance *aIncome)
239 return NS_ERROR_NOT_IMPLEMENTED;