[storage] Migrate to mozbuild (bug #114)
[abstract.git] / storage / base / aaSaveDispatcher.cpp
blob9c941312c99b554c6e01e98b7a2cf613f86a17f7
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 "aaISession.h"
36 #include "aaSaveDispatcher.h"
38 aaSaveDispatcher::aaSaveDispatcher(nsISupports *aSession)
40 void *tmp = nsnull;
41 aSession->QueryInterface(NS_GET_IID(aaISession), &tmp);
42 mParentSession = (aaISession *) tmp;
43 mParentSession->Release();
46 aaSaveDispatcher::~aaSaveDispatcher()
50 NS_IMPL_ISUPPORTS2(aaSaveDispatcher,
51 aaISaveQuery,
52 aaIHandler)
54 /* aaISaveQuery */
55 NS_IMETHODIMP
56 aaSaveDispatcher::Save(aaIDataNode *aNode, aaIDataNode *aOldNode)
58 NS_ENSURE_ARG_POINTER(aNode);
59 mOldNode = aOldNode;
60 return aNode->Accept(this);
63 /* aaIHandler */
64 #define AA_DISPATCH_ENTITY "@aasii.org/storage/save-entity;1"
65 #define AA_DISPATCH_RESOURCE "@aasii.org/storage/save-resource;1"
66 #define AA_DISPATCH_FLOW "@aasii.org/storage/save-flow;1"
67 #define AA_DISPATCH_EVENT "@aasii.org/storage/save-event;1"
68 #define AA_DISPATCH_QUOTE "@aasii.org/storage/save-quote;1"
69 #define AA_DISPATCH_TRANSACTION "@aasii.org/storage/save-transaction;1"
70 NS_IMETHODIMP
71 aaSaveDispatcher::HandleEntity(aaIEntity *aEntity)
73 return dispatch(AA_DISPATCH_ENTITY, aEntity);
76 NS_IMETHODIMP
77 aaSaveDispatcher::HandleResource(aaIResource *aResource)
79 return dispatch(AA_DISPATCH_RESOURCE, aResource);
82 NS_IMETHODIMP
83 aaSaveDispatcher::HandleFlow(aaIFlow *aFlow)
85 return dispatch(AA_DISPATCH_FLOW, aFlow);
88 NS_IMETHODIMP
89 aaSaveDispatcher::HandleFact(aaIFact *aFact)
91 return NS_ERROR_NOT_IMPLEMENTED;
94 NS_IMETHODIMP
95 aaSaveDispatcher::HandleEvent(aaIEvent *aEvent)
97 return dispatch(AA_DISPATCH_EVENT, aEvent);
100 NS_IMETHODIMP
101 aaSaveDispatcher::HandleQuote(aaIQuote *aQuote)
103 return dispatch(AA_DISPATCH_QUOTE, aQuote);
106 NS_IMETHODIMP
107 aaSaveDispatcher::HandleTransaction(aaITransaction *aTransaction)
109 return dispatch(AA_DISPATCH_TRANSACTION, aTransaction);
112 /* Private methods */
113 nsresult
114 aaSaveDispatcher::dispatch(const char *aContractID, aaIDataNode *aNode)
116 nsresult rv;
117 nsCOMPtr<nsISupports> queryPtr;
118 rv = mParentSession->CreateQuery(aContractID, getter_AddRefs(queryPtr));
119 NS_ENSURE_SUCCESS(rv, rv);
121 nsCOMPtr<aaISaveQuery> saveQuery(do_QueryInterface(queryPtr, &rv));
122 NS_ENSURE_SUCCESS(rv, rv);
124 return saveQuery->Save(aNode, mOldNode);