merge the formfield patch from ooo-build
[ooovba.git] / configmgr / source / backend / layerupdatehandler.cxx
blob99ffd0db886578fb5e49b546684de5401a5690d2
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: layerupdatehandler.cxx,v $
10 * $Revision: 1.12 $
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 "layerupdatehandler.hxx"
35 #include "layerupdatemerger.hxx"
37 #ifndef CONFIGMGR_API_FACTORY_HXX_
38 #include "confapifactory.hxx"
39 #endif
40 #include <com/sun/star/configuration/backend/XLayerHandler.hpp>
41 #include <com/sun/star/configuration/backend/XLayer.hpp>
42 #include <com/sun/star/beans/PropertyExistException.hpp>
44 // -----------------------------------------------------------------------------
45 #define OUSTR( str ) rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( str ) )
46 // -----------------------------------------------------------------------------
47 namespace configmgr
49 // -----------------------------------------------------------------------------
50 namespace backend
52 // -----------------------------------------------------------------------------
53 namespace uno = ::com::sun::star::uno;
54 namespace lang = ::com::sun::star::lang;
55 namespace backenduno = ::com::sun::star::configuration::backend;
56 // -----------------------------------------------------------------------------
58 uno::Reference< uno::XInterface > SAL_CALL instantiateUpdateMerger
59 ( uno::Reference< uno::XComponentContext > const& xContext )
61 return * new LayerUpdateHandler( xContext );
64 // -----------------------------------------------------------------------------
66 LayerUpdateHandler::LayerUpdateHandler(uno::Reference< uno::XComponentContext > const & _xContext)
67 : UpdateService(_xContext)
68 , m_aBuilder()
71 // -----------------------------------------------------------------------------
73 LayerUpdateHandler::~LayerUpdateHandler()
76 // -----------------------------------------------------------------------------
77 inline
78 void LayerUpdateHandler::checkBuilder(bool _bForProperty)
80 if ( m_aBuilder.isEmpty() )
81 raiseMalformedDataException("LayerUpdateHandler: Illegal operation - no update is in progress");
83 if ( !m_aBuilder.isActive() )
84 raiseMalformedDataException("LayerUpdateHandler: Illegal operation - no context for update available");
86 if ( m_aBuilder.isPropertyActive() != _bForProperty )
87 raiseMalformedDataException("LayerUpdateHandler: Illegal operation - a property is in progress");
89 // -----------------------------------------------------------------------------
91 void LayerUpdateHandler::raiseMalformedDataException(sal_Char const * pMsg)
93 rtl::OUString sMsg = rtl::OUString::createFromAscii(pMsg);
94 throw backenduno::MalformedDataException(sMsg,*this,uno::Any());
96 // -----------------------------------------------------------------------------
98 void LayerUpdateHandler::raiseNodeChangedBeforeException(sal_Char const * pMsg)
100 rtl::OUString sMsg = rtl::OUString::createFromAscii(pMsg);
101 throw backenduno::MalformedDataException(sMsg,*this,uno::Any());
103 // -----------------------------------------------------------------------------
105 void LayerUpdateHandler::raisePropChangedBeforeException(sal_Char const * pMsg)
107 rtl::OUString sMsg = rtl::OUString::createFromAscii(pMsg);
108 throw backenduno::MalformedDataException(sMsg,*this,uno::Any());
110 // -----------------------------------------------------------------------------
112 void LayerUpdateHandler::raisePropExistsException(sal_Char const * pMsg)
114 rtl::OUString sMsg = rtl::OUString::createFromAscii(pMsg);
115 com::sun::star::beans::PropertyExistException e(sMsg,*this);
117 throw backenduno::MalformedDataException(sMsg,*this, uno::makeAny(e));
119 // -----------------------------------------------------------------------------
121 // XUpdateHandler
122 void SAL_CALL
123 LayerUpdateHandler::startUpdate( )
124 throw ( backenduno::MalformedDataException, lang::IllegalAccessException,
125 lang::WrappedTargetException, uno::RuntimeException)
127 this->checkSourceLayer();
128 if (!m_aBuilder.init())
129 raiseMalformedDataException("LayerUpdateHandler: Cannot start update - update is already in progress");
131 // -----------------------------------------------------------------------------
133 void SAL_CALL
134 LayerUpdateHandler::endUpdate( )
135 throw ( backenduno::MalformedDataException, lang::IllegalAccessException,
136 lang::WrappedTargetException, uno::RuntimeException)
138 checkBuilder();
140 if (!m_aBuilder.finish())
141 raiseMalformedDataException("LayerUpdateHandler: Cannot finish update - a node is still open.");
143 uno::Reference< backenduno::XLayer > xMergedLayer( LayerUpdateMerger::getMergedLayer(this->getSourceLayer(), m_aBuilder.result()) );
145 m_aBuilder.clear();
147 this->writeUpdatedLayer(xMergedLayer);
149 // -----------------------------------------------------------------------------
151 void SAL_CALL
152 LayerUpdateHandler::modifyNode( const rtl::OUString& aName, sal_Int16 aAttributes, sal_Int16 aAttributeMask, sal_Bool bReset )
153 throw (backenduno::MalformedDataException, lang::WrappedTargetException, uno::RuntimeException)
155 checkBuilder();
157 if (!m_aBuilder.modifyNode(aName,aAttributes,aAttributeMask,bReset))
158 raiseNodeChangedBeforeException("LayerUpdateHandler: Cannot start node modification - node has already been changed.");
160 // -----------------------------------------------------------------------------
162 void SAL_CALL
163 LayerUpdateHandler::addOrReplaceNode( const rtl::OUString& aName, sal_Int16 aAttributes )
164 throw (backenduno::MalformedDataException, lang::WrappedTargetException, uno::RuntimeException)
166 checkBuilder();
168 if (!m_aBuilder.replaceNode(aName,aAttributes,NULL))
169 raiseNodeChangedBeforeException("LayerUpdateHandler: Cannot start added/replaced node - node has already been changed.");
171 // -----------------------------------------------------------------------------
173 void SAL_CALL
174 LayerUpdateHandler::addOrReplaceNodeFromTemplate( const rtl::OUString& aName, sal_Int16 aAttributes, const backenduno::TemplateIdentifier& aTemplate )
175 throw (backenduno::MalformedDataException, lang::WrappedTargetException, uno::RuntimeException)
177 checkBuilder();
179 if (!m_aBuilder.replaceNode(aName,aAttributes,&aTemplate))
180 raiseNodeChangedBeforeException("LayerUpdateHandler: Cannot start added/replaced node - node has already been changed.");
182 // -----------------------------------------------------------------------------
184 void SAL_CALL
185 LayerUpdateHandler::endNode( )
186 throw (backenduno::MalformedDataException, lang::WrappedTargetException, uno::RuntimeException)
188 checkBuilder();
190 if (!m_aBuilder.finishNode())
192 OSL_ENSURE(m_aBuilder.isPropertyActive() || !m_aBuilder.isActive(), "LayerUpdateHandler: Unexpected failure mode for finishNode");
193 if (m_aBuilder.isPropertyActive())
194 raiseMalformedDataException("LayerUpdateHandler: Cannot finish node update - open property has not been ended.");
195 else
196 raiseMalformedDataException("LayerUpdateHandler: Cannot finish node update - no node has been started.");
199 // -----------------------------------------------------------------------------
201 void SAL_CALL
202 LayerUpdateHandler::removeNode( const rtl::OUString& aName )
203 throw (backenduno::MalformedDataException, lang::WrappedTargetException, uno::RuntimeException)
205 checkBuilder();
207 if (!m_aBuilder.removeNode(aName))
208 raiseNodeChangedBeforeException("LayerUpdateHandler: Cannot remove node - node has already been changed.");
210 // -----------------------------------------------------------------------------
212 void SAL_CALL
213 LayerUpdateHandler:: modifyProperty( const rtl::OUString& aName, sal_Int16 aAttributes, sal_Int16 aAttributeMask, const uno::Type & aType )
214 throw (backenduno::MalformedDataException, lang::WrappedTargetException, uno::RuntimeException)
216 checkBuilder(false);
218 if (!m_aBuilder.modifyProperty(aName,aAttributes,aAttributeMask, aType))
219 raisePropChangedBeforeException("LayerUpdateHandler: Cannot start property modification - property has already been changed.");
221 // -----------------------------------------------------------------------------
223 void SAL_CALL
224 LayerUpdateHandler:: setPropertyValue( const uno::Any& aValue )
225 throw (backenduno::MalformedDataException, lang::WrappedTargetException, uno::RuntimeException)
227 checkBuilder(true); // already checks for open property
229 OSL_VERIFY( m_aBuilder.setPropertyValue(aValue) );
231 // -----------------------------------------------------------------------------
233 void SAL_CALL
234 LayerUpdateHandler:: setPropertyValueForLocale( const uno::Any& aValue, const rtl::OUString& aLocale )
235 throw (backenduno::MalformedDataException, lang::WrappedTargetException, uno::RuntimeException)
237 checkBuilder(true); // already checks for open property
239 OSL_VERIFY( m_aBuilder.setPropertyValueForLocale(aValue,aLocale) );
241 // -----------------------------------------------------------------------------
243 void SAL_CALL
244 LayerUpdateHandler::resetPropertyValue( )
245 throw (backenduno::MalformedDataException, lang::WrappedTargetException, uno::RuntimeException)
247 checkBuilder(true); // already checks for open property
249 OSL_VERIFY( m_aBuilder.resetPropertyValue() );
251 // -----------------------------------------------------------------------------
253 void SAL_CALL
254 LayerUpdateHandler::resetPropertyValueForLocale( const rtl::OUString& aLocale )
255 throw (backenduno::MalformedDataException, lang::WrappedTargetException, uno::RuntimeException)
257 checkBuilder(true); // already checks for open property
259 OSL_VERIFY( m_aBuilder.resetPropertyValueForLocale(aLocale) );
261 // -----------------------------------------------------------------------------
263 void SAL_CALL
264 LayerUpdateHandler::endProperty( )
265 throw (backenduno::MalformedDataException, lang::WrappedTargetException, uno::RuntimeException)
267 checkBuilder(true); // already checks for open property
269 OSL_VERIFY ( m_aBuilder.finishProperty() );
271 // -----------------------------------------------------------------------------
273 void SAL_CALL
274 LayerUpdateHandler::resetProperty( const rtl::OUString& aName )
275 throw (backenduno::MalformedDataException, lang::WrappedTargetException, uno::RuntimeException)
277 if (!m_aBuilder.resetProperty(aName))
278 raisePropChangedBeforeException("LayerUpdateHandler: Cannot reset property - property has already been changed.");
280 // -----------------------------------------------------------------------------
282 void SAL_CALL
283 LayerUpdateHandler::addOrReplaceProperty( const rtl::OUString& aName, sal_Int16 aAttributes, const uno::Type& aType )
284 throw (backenduno::MalformedDataException, lang::WrappedTargetException, uno::RuntimeException)
286 if (!m_aBuilder.addNullProperty(aName,aAttributes,aType))
287 raisePropExistsException("LayerUpdateHandler: Cannot add property - property exists (and has already been changed).");
289 // -----------------------------------------------------------------------------
291 void SAL_CALL
292 LayerUpdateHandler::addOrReplacePropertyWithValue( const rtl::OUString& aName, sal_Int16 aAttributes, const uno::Any& aValue )
293 throw (backenduno::MalformedDataException, lang::WrappedTargetException, uno::RuntimeException)
295 if (!m_aBuilder.addProperty(aName,aAttributes,aValue))
296 raisePropExistsException("LayerUpdateHandler: Cannot add property - property exists (and has already been changed).");
298 // -----------------------------------------------------------------------------
300 void SAL_CALL
301 LayerUpdateHandler::removeProperty( const rtl::OUString& aName )
302 throw (backenduno::MalformedDataException, lang::WrappedTargetException, uno::RuntimeException)
304 // treat 'remove' as 'reset'. (Note: does not verify that this actually amounts to dropping the property)
305 if (!m_aBuilder.resetProperty(aName))
306 raisePropChangedBeforeException("LayerUpdateHandler: Cannot remove property - property has already been changed.");
308 // -----------------------------------------------------------------------------
310 // -----------------------------------------------------------------------------
311 // -----------------------------------------------------------------------------
312 } // namespace
314 // -----------------------------------------------------------------------------
315 } // namespace