merge the formfield patch from ooo-build
[ooovba.git] / configmgr / source / treecache / invalidatetree.cxx
blob931071617116969e6f07dec8fa1f0e14c9ada335
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: invalidatetree.cxx,v $
10 * $Revision: 1.24 $
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"
35 #include "cachecontroller.hxx"
36 #include "change.hxx"
37 #include "valuenode.hxx"
38 #include "updatehelper.hxx"
39 #include "treeactions.hxx"
40 #include "tracer.hxx"
41 #include <com/sun/star/uno/Any.hxx>
42 #include <com/sun/star/container/NoSuchElementException.hpp>
44 #ifndef INCLUDED_ALGORITHM
45 #include <algorithm>
46 #define INCLUDED_ALGORITHM
47 #endif
49 namespace configmgr
52 namespace container = com::sun::star::container;
53 // -----------------------------------------------------------------------------
54 // ------------------------------- invalidateTree -------------------------------
55 // -----------------------------------------------------------------------------
57 namespace backend
59 // -----------------------------------------------------------------------------
60 std::auto_ptr<SubtreeChange> createDiffs(sharable::Node * cachedNode,
61 ISubtree const * _pLoadedSubtree,
62 configuration::AbsolutePath const& _aAbsoluteSubtreePath)
64 OSL_PRECOND(cachedNode != 0, "Need an existing node to create a diff");
65 OSL_PRECOND(_pLoadedSubtree != 0, "Need a result node to create a diff");
66 // Create a TreeChangeList with the right name, parentname and ConfigurationProperties
67 std::auto_ptr<SubtreeChange> aNewChange(new SubtreeChange(_aAbsoluteSubtreePath.getLocalName().getName(),
68 node::Attributes()) );
70 if (!createUpdateFromDifference(*aNewChange, cachedNode, *_pLoadedSubtree))
71 aNewChange.reset();
73 return aNewChange;
75 // -----------------------------------------------------------------------------
76 #if 0
77 std::auto_ptr<ISubtree> TreeManager::loadNodeFromSession( configuration::AbsolutePath const& _aAbsoluteSubtreePath,
78 const vos::ORef < OOptions >& _xOptions,
79 sal_Int16 _nMinLevels) SAL_THROW((com::sun::star::uno::Exception))
81 TreeInfo* pInfo = this->requestTreeInfo(_xOptions,true /*create TreeInfo*/);
83 CFG_TRACE_INFO_NI("cache manager: cache miss. going to load the node");
84 rtl::Reference< OTreeLoader > xLoader = pInfo->getNewLoaderWithoutPending(_aAbsoluteSubtreePath, _nMinLevels, _xOptions, m_xBackend.get());
86 OSL_ENSURE(xLoader.is(), "Did not receive a loader for retrieving the node");
87 CFG_TRACE_INFO_NI("cache manager: cache miss. going to load the node");
88 if (!xLoader.is())
89 throw container::NoSuchElementException((::rtl::OUString::createFromAscii("Error while retrieving the node")), NULL);
91 // now block for reading
92 std::auto_ptr<ISubtree> pResponse;
93 try
95 pResponse = xLoader->waitToResponse();
97 catch (uno::Exception& e)
99 pInfo->releaseLoader(xLoader);
100 throw;
103 pInfo->releaseLoader(xLoader);
105 return pResponse;
107 #endif
108 // -----------------------------------------------------------------------------
110 sharable::TreeFragment * CacheController::refreshComponent(ComponentRequest const & _aRequest) SAL_THROW((com::sun::star::uno::Exception))
112 if (m_bDisposing) return NULL;
114 rtl::Reference<CacheLoadingAccess> aCache = this->getCacheAlways(_aRequest.getOptions());
116 if (!aCache.is()) return NULL;
118 // load the Node direct from the session, without using the cache
119 ComponentRequest aForcedRequest(_aRequest);
120 aForcedRequest.forceReload();
122 ResultHolder< ComponentInstance > aLoadedInstance = this->getComponentData(aForcedRequest,false);
123 configuration::AbsolutePath aRequestPath = configuration::AbsolutePath::makeModulePath(_aRequest.getComponentName());
124 NodeInstance aNodeInstance(aLoadedInstance.mutableInstance().mutableData(),aRequestPath) ;
125 ResultHolder< NodeInstance > aLoadedNodeInstance(aNodeInstance) ;
127 sharable::TreeFragment * aResult = NULL;
128 if (aLoadedNodeInstance.is())
130 rtl::OUString aModuleName = aLoadedNodeInstance->root().getModuleName();
132 bool bAcquired = aCache->acquireModule(aModuleName);
133 aResult = (sharable::TreeFragment *)( aCache->getTreeAddress(aModuleName) );
135 if (bAcquired)
138 std::auto_ptr<SubtreeChange> aTreeChanges;
139 sharable::Node * aRootAddress;
142 sharable::Node * rootNode = aResult == 0 ? 0 : aResult->getRootNode();
144 aTreeChanges = createDiffs(rootNode, aLoadedNodeInstance->data().get(), aLoadedNodeInstance->root());
145 aRootAddress = rootNode;
148 if (aTreeChanges.get() != NULL)
150 // change all Values... found in the Subtree in the CacheTree
151 applyUpdateWithAdjustmentToTree(*aTreeChanges, aRootAddress);
153 UpdateRequest anUpdateReq( aTreeChanges.get(),
154 aLoadedNodeInstance->root(),
155 _aRequest.getOptions()
158 m_aNotifier.notifyChanged(anUpdateReq);
160 aCache->releaseModule(aModuleName);
162 catch (...)
164 aCache->releaseModule(aModuleName);
165 throw;
168 return aResult;
171 // -----------------------------------------------------------------------------
172 } // namespace backend
174 // -----------------------------------------------------------------------------
175 } // namespace configmgr