1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: committer.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_configmgr.hxx"
34 #include "committer.hxx"
35 #include "apitreeimplobj.hxx"
36 #include "providerimpl.hxx"
37 #include "roottree.hxx"
38 #include "treechangelist.hxx"
42 //-----------------------------------------------------------------------------
45 //-----------------------------------------------------------------------------
48 //-------------------------------------------------------------------------
51 ApiRootTreeImpl
& m_rTree
;
54 NotifyDisabler(ApiRootTreeImpl
& rTree
)
56 , m_bOldState(rTree
.enableNotification(false) )
62 m_rTree
.enableNotification(m_bOldState
);
65 //-------------------------------------------------------------------------
68 //-----------------------------------------------------------------------------
70 //-----------------------------------------------------------------------------
72 Committer::Committer(ApiRootTreeImpl
& rTree
)
75 //-----------------------------------------------------------------------------
77 OProviderImpl
* Committer::getUpdateProvider()
79 return &m_rTree
.getApiTree().getProvider().getProviderImpl();
82 //-----------------------------------------------------------------------------
83 void Committer::commit()
85 ApiTreeImpl
& rApiTree
= m_rTree
.getApiTree();
87 OSL_PRECOND(!m_rTree
.getLocation().isRoot(),"INTERNAL ERROR: Empty location used.");
88 OSL_PRECOND(m_rTree
.getOptions().isValid(),"INTERNAL ERROR: Invalid Options used.");
90 if (!m_rTree
.getOptions().isValid()) return;
92 RequestOptions aOptions
= m_rTree
.getOptions()->getRequestOptions();
94 OProviderImpl
* pUpdateProvider
= getUpdateProvider();
95 OSL_ASSERT(pUpdateProvider
);
97 rtl::Reference
< configuration::Tree
> aTree( rApiTree
.getTree());
98 if (!aTree
->hasChanges()) return;
100 TreeChangeList
aChangeList(aOptions
,
101 aTree
->getRootPath(),
102 aTree
->getAttributes(aTree
->getRootNode()));
105 configuration::CommitHelper
aHelper(rApiTree
.getTree());
106 if (aHelper
.prepareCommit(aChangeList
))
109 pUpdateProvider
->updateTree(aChangeList
);
111 aHelper
.finishCommit(aChangeList
);
113 NotifyDisabler
aDisableNotify(m_rTree
); // do not notify self
114 pUpdateProvider
->saveAndNotifyUpdate(aChangeList
);
118 // should be a special clean-up routine, but for now we just need a consistent state
121 aHelper
.failedCommit(aChangeList
);
123 catch(configuration::Exception
&)
125 OSL_ENSURE(false, "Cleanup really should not throw");
130 //-----------------------------------------------------------------------------