[accounting] Special-case quote for functional currency (bug 86)
[abstract.git] / storage / base / aaSaveDispatcher.cpp
blob8115a82c624bfd7712a3aef4aad7999eabeb8c58
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"
26 /* Unfrozen API */
28 /* Project includes */
29 #include "aaIEntity.h"
30 #include "aaIResource.h"
31 #include "aaIFlow.h"
32 #include "aaIEvent.h"
33 #include "aaIQuote.h"
34 #include "aaITransaction.h"
35 #include "aaIChart.h"
36 #include "aaISession.h"
37 #include "aaSaveDispatcher.h"
39 aaSaveDispatcher::aaSaveDispatcher(nsISupports *aSession)
41 void *tmp = nsnull;
42 aSession->QueryInterface(NS_GET_IID(aaISession), &tmp);
43 mParentSession = (aaISession *) tmp;
44 mParentSession->Release();
47 aaSaveDispatcher::~aaSaveDispatcher()
51 NS_IMPL_ISUPPORTS3(aaSaveDispatcher,
52 aaISaveQuery,
53 aaIHandler,
54 aaIChartHandler)
56 /* aaISaveQuery */
57 NS_IMETHODIMP
58 aaSaveDispatcher::Save(aaIDataNode *aNode, aaIDataNode *aOldNode)
60 NS_ENSURE_ARG_POINTER(aNode);
61 mOldNode = aOldNode;
62 return aNode->Accept(this);
65 /* aaIHandler */
66 #define AA_DISPATCH_ENTITY "@aasii.org/storage/save-entity;1"
67 #define AA_DISPATCH_RESOURCE "@aasii.org/storage/save-resource;1"
68 #define AA_DISPATCH_FLOW "@aasii.org/storage/save-flow;1"
69 #define AA_DISPATCH_EVENT "@aasii.org/storage/save-event;1"
70 #define AA_DISPATCH_QUOTE "@aasii.org/storage/save-quote;1"
71 #define AA_DISPATCH_TRANSACTION "@aasii.org/storage/save-transaction;1"
72 NS_IMETHODIMP
73 aaSaveDispatcher::HandleEntity(aaIEntity *aEntity)
75 return dispatch(AA_DISPATCH_ENTITY, aEntity);
78 NS_IMETHODIMP
79 aaSaveDispatcher::HandleResource(aaIResource *aResource)
81 return dispatch(AA_DISPATCH_RESOURCE, aResource);
84 NS_IMETHODIMP
85 aaSaveDispatcher::HandleFlow(aaIFlow *aFlow)
87 return dispatch(AA_DISPATCH_FLOW, aFlow);
90 NS_IMETHODIMP
91 aaSaveDispatcher::HandleFact(aaIFact *aFact)
93 return NS_ERROR_NOT_IMPLEMENTED;
96 NS_IMETHODIMP
97 aaSaveDispatcher::HandleEvent(aaIEvent *aEvent)
99 return dispatch(AA_DISPATCH_EVENT, aEvent);
102 NS_IMETHODIMP
103 aaSaveDispatcher::HandleQuote(aaIQuote *aQuote)
105 return dispatch(AA_DISPATCH_QUOTE, aQuote);
108 NS_IMETHODIMP
109 aaSaveDispatcher::HandleTransaction(aaITransaction *aTransaction)
111 return dispatch(AA_DISPATCH_TRANSACTION, aTransaction);
114 /* aaIHandler */
115 #define AA_DISPATCH_CHART "@aasii.org/storage/save-chart;1"
116 NS_IMETHODIMP
117 aaSaveDispatcher::HandleChart(aaIChart *aChart)
119 return dispatch(AA_DISPATCH_CHART, aChart);
123 /* Private methods */
124 nsresult
125 aaSaveDispatcher::dispatch(const char *aContractID, aaIDataNode *aNode)
127 nsresult rv;
128 nsCOMPtr<nsISupports> queryPtr;
129 rv = mParentSession->CreateQuery(aContractID, getter_AddRefs(queryPtr));
130 NS_ENSURE_SUCCESS(rv, rv);
132 nsCOMPtr<aaISaveQuery> saveQuery(do_QueryInterface(queryPtr, &rv));
133 NS_ENSURE_SUCCESS(rv, rv);
135 return saveQuery->Save(aNode, mOldNode);