update dev300-m58
[ooovba.git] / configmgr / source / api2 / apinodeupdate.cxx
blobd7cf1d409c734eb57829f0eff234ac21120a96d3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: apinodeupdate.cxx,v $
10 * $Revision: 1.13 $
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"
33 #include <stdio.h>
34 #include "apinodeupdate.hxx"
35 #include "apitreeimplobj.hxx"
36 #include "apitreeaccess.hxx"
37 #include "noderef.hxx"
38 #include "configset.hxx"
39 #include "configgroup.hxx"
40 #include "configpath.hxx"
41 #include "apifactory.hxx"
43 namespace configmgr
45 namespace configapi
47 //-----------------------------------------------------------------------------
49 NodeGroupAccess& withDefaultData(NodeGroupAccess& _aGroup)
51 configuration::GroupDefaulter::ensureDataAvailable(_aGroup.getTreeRef(),_aGroup.getNodeRef(),
52 _aGroup.getApiTree().getDefaultProvider());
53 return _aGroup;
55 //-----------------------------------------------------------------------------
57 configuration::GroupUpdater NodeGroupAccess::getNodeUpdater()
59 return configuration::GroupUpdater(getTree(),getNodeRef(), getApiTree().getProvider().getTypeConverter());
61 //-----------------------------------------------------------------------------
63 configuration::GroupDefaulter NodeGroupAccess::getNodeDefaulter()
65 return configuration::GroupDefaulter(getTree(),getNodeRef(), getApiTree().getDefaultProvider());
67 //-----------------------------------------------------------------------------
69 configuration::SetElementFactory NodeTreeSetAccess::getElementFactory()
71 configuration::TemplateProvider aProvider = configuration::SetElementFactory::findTemplateProvider(getTree(),getNodeRef());
72 return configuration::SetElementFactory(aProvider);
74 //-----------------------------------------------------------------------------
76 configuration::SetDefaulter NodeSetAccess::getNodeDefaulter()
78 return configuration::SetDefaulter(getTree(),getNodeRef(), getApiTree().getDefaultProvider());
80 //-----------------------------------------------------------------------------
82 configuration::TreeSetUpdater NodeTreeSetAccess::getNodeUpdater()
84 return configuration::TreeSetUpdater(getTree(),getNodeRef(),getElementInfo());
86 //-----------------------------------------------------------------------------
89 configuration::ValueSetUpdater NodeValueSetAccess::getNodeUpdater()
91 return configuration::ValueSetUpdater(getTree(),getNodeRef(),getElementInfo(), getApiTree().getProvider().getTypeConverter());
93 //-----------------------------------------------------------------------------
95 void attachSetElement(NodeTreeSetAccess& aSet, SetElement& aElement)
97 OSL_ENSURE( configuration::NodeID(aSet.getTreeRef(),aSet.getNodeRef()) ==
98 configuration::NodeID(rtl::Reference< configuration::Tree >(aElement.getTreeRef()->getContextTree()),aElement.getTreeRef()->getContextNodeRef()),
99 "ERROR: Attaching an unrelated SetElement to a SetInfoAccess");
101 aElement.haveNewParent(&aSet);
103 //-----------------------------------------------------------------------------
105 bool attachSetElement(NodeTreeSetAccess& aSet, rtl::Reference< configuration::ElementTree > const& aElementTree)
107 OSL_ENSURE( configuration::NodeID(aSet.getTreeRef(),aSet.getNodeRef()) ==
108 configuration::NodeID(rtl::Reference< configuration::Tree >(aElementTree->getContextTree()), aElementTree->getContextNodeRef()),
109 "ERROR: Attaching an unrelated ElementTree to a SetInfoAccess");
111 Factory& rFactory = aSet.getFactory();
112 if (SetElement* pSetElement = rFactory.findSetElement(aElementTree))
114 // the factory always does an extra acquire
115 uno::Reference<uno::XInterface> xReleaseSetElement(pSetElement->getUnoInstance(), uno::UNO_REF_NO_ACQUIRE);
117 attachSetElement(aSet, *pSetElement);
118 return true;
120 else
121 return false;
124 //-----------------------------------------------------------------------------
126 void detachSetElement(SetElement& aElement)
128 OSL_ENSURE( configuration::isEmpty(aElement.getTreeRef()->getContextTree()),
129 "ERROR: Detaching a SetElement that has a parent");
131 aElement.haveNewParent(0);
133 //-----------------------------------------------------------------------------
135 bool detachSetElement(Factory& rFactory, rtl::Reference< configuration::ElementTree > const& aElementTree)
137 OSL_ENSURE( configuration::isEmpty(aElementTree->getContextTree()),
138 "ERROR: Detaching an ElementTree that has a parent");
140 if (SetElement* pSetElement = rFactory.findSetElement(aElementTree))
142 // the factory always does an extra acquire
143 uno::Reference<uno::XInterface> xReleaseSetElement(pSetElement->getUnoInstance(), uno::UNO_REF_NO_ACQUIRE);
145 detachSetElement(*pSetElement);
146 return true;
148 else
149 return false;
152 //-----------------------------------------------------------------------------
154 UpdateGuardImpl::UpdateGuardImpl(NodeGroupAccess& rNode)
155 : m_rNode(rNode)
157 rNode.checkAlive();
159 //-----------------------------------------------------------------------------
161 UpdateGuardImpl::UpdateGuardImpl(NodeSetAccess& rNode)
162 : m_rNode(rNode)
165 //-----------------------------------------------------------------------------
167 UpdateGuardImpl::~UpdateGuardImpl() throw ()
170 //-----------------------------------------------------------------------------