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"
35 #include "aaISession.h"
36 #include "aaSaveDispatcher.h"
38 aaSaveDispatcher::aaSaveDispatcher(nsISupports
*aSession
)
41 aSession
->QueryInterface(NS_GET_IID(aaISession
), &tmp
);
42 mParentSession
= (aaISession
*) tmp
;
43 mParentSession
->Release();
46 aaSaveDispatcher::~aaSaveDispatcher()
50 NS_IMPL_ISUPPORTS2(aaSaveDispatcher
,
56 aaSaveDispatcher::Save(aaIDataNode
*aNode
, aaIDataNode
*aOldNode
)
58 NS_ENSURE_ARG_POINTER(aNode
);
60 return aNode
->Accept(this);
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"
71 aaSaveDispatcher::HandleEntity(aaIEntity
*aEntity
)
73 return dispatch(AA_DISPATCH_ENTITY
, aEntity
);
77 aaSaveDispatcher::HandleResource(aaIResource
*aResource
)
79 return dispatch(AA_DISPATCH_RESOURCE
, aResource
);
83 aaSaveDispatcher::HandleFlow(aaIFlow
*aFlow
)
85 return dispatch(AA_DISPATCH_FLOW
, aFlow
);
89 aaSaveDispatcher::HandleFact(aaIFact
*aFact
)
91 return NS_ERROR_NOT_IMPLEMENTED
;
95 aaSaveDispatcher::HandleEvent(aaIEvent
*aEvent
)
97 return dispatch(AA_DISPATCH_EVENT
, aEvent
);
101 aaSaveDispatcher::HandleQuote(aaIQuote
*aQuote
)
103 return dispatch(AA_DISPATCH_QUOTE
, aQuote
);
107 aaSaveDispatcher::HandleTransaction(aaITransaction
*aTransaction
)
109 return dispatch(AA_DISPATCH_TRANSACTION
, aTransaction
);
112 /* Private methods */
114 aaSaveDispatcher::dispatch(const char *aContractID
, aaIDataNode
*aNode
)
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
);