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: */
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"
28 /* Project includes */
29 #include "aaIEntity.h"
30 #include "aaIResource.h"
34 #include "aaITransaction.h"
36 #include "aaISession.h"
37 #include "aaSaveDispatcher.h"
39 aaSaveDispatcher::aaSaveDispatcher(nsISupports
*aSession
)
42 aSession
->QueryInterface(NS_GET_IID(aaISession
), &tmp
);
43 mParentSession
= (aaISession
*) tmp
;
44 mParentSession
->Release();
47 aaSaveDispatcher::~aaSaveDispatcher()
51 NS_IMPL_ISUPPORTS3(aaSaveDispatcher
,
58 aaSaveDispatcher::Save(aaIDataNode
*aNode
, aaIDataNode
*aOldNode
)
60 NS_ENSURE_ARG_POINTER(aNode
);
62 return aNode
->Accept(this);
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"
73 aaSaveDispatcher::HandleEntity(aaIEntity
*aEntity
)
75 return dispatch(AA_DISPATCH_ENTITY
, aEntity
);
79 aaSaveDispatcher::HandleResource(aaIResource
*aResource
)
81 return dispatch(AA_DISPATCH_RESOURCE
, aResource
);
85 aaSaveDispatcher::HandleFlow(aaIFlow
*aFlow
)
87 return dispatch(AA_DISPATCH_FLOW
, aFlow
);
91 aaSaveDispatcher::HandleFact(aaIFact
*aFact
)
93 return NS_ERROR_NOT_IMPLEMENTED
;
97 aaSaveDispatcher::HandleEvent(aaIEvent
*aEvent
)
99 return dispatch(AA_DISPATCH_EVENT
, aEvent
);
103 aaSaveDispatcher::HandleQuote(aaIQuote
*aQuote
)
105 return dispatch(AA_DISPATCH_QUOTE
, aQuote
);
109 aaSaveDispatcher::HandleTransaction(aaITransaction
*aTransaction
)
111 return dispatch(AA_DISPATCH_TRANSACTION
, aTransaction
);
115 #define AA_DISPATCH_CHART "@aasii.org/storage/save-chart;1"
117 aaSaveDispatcher::HandleChart(aaIChart
*aChart
)
119 return dispatch(AA_DISPATCH_CHART
, aChart
);
123 /* Private methods */
125 aaSaveDispatcher::dispatch(const char *aContractID
, aaIDataNode
*aNode
)
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
);