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: layerupdatebuilder.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 "layerupdatebuilder.hxx"
35 #include "updatedata.hxx"
36 #include "layerupdate.hxx"
37 #include <com/sun/star/configuration/backend/TemplateIdentifier.hpp>
41 // -----------------------------------------------------------------------------
44 // -----------------------------------------------------------------------------
46 LayerUpdateBuilder::LayerUpdateBuilder()
48 , m_pCurrentNode(NULL
)
49 , m_pCurrentProp(NULL
)
52 // -----------------------------------------------------------------------------
54 void LayerUpdateBuilder::clear()
56 m_pCurrentProp
= NULL
;
57 m_pCurrentNode
= NULL
;
58 m_aUpdate
= LayerUpdate();
60 OSL_POSTCOND( this->isEmpty(), "LayerUpdateBuilder: Could not reset the stored update.");
62 // -----------------------------------------------------------------------------
64 LayerUpdate
const & LayerUpdateBuilder::result() const
66 OSL_ENSURE(this->isComplete(),
67 "LayerUpdateBuilder: There is no result to retrieve"
68 " - building the data is still in progress.");
72 // -----------------------------------------------------------------------------
75 LayerUpdate
& LayerUpdateBuilder::data()
79 // -----------------------------------------------------------------------------
81 bool LayerUpdateBuilder::init()
83 if (m_pCurrentNode
) return false;
85 LayerUpdate
& update
= data();
86 m_pCurrentNode
= new NodeModification(NULL
, rtl::OUString(), 0, 0, false);
87 update
.setContextNode(m_pCurrentNode
);
89 OSL_ENSURE(m_pCurrentProp
== NULL
, "LayerUpdateBuilder: Internal error: got a current property for a new context");
93 // -----------------------------------------------------------------------------
95 bool LayerUpdateBuilder::modifyNode(rtl::OUString
const & _aName
, sal_Int16 _nFlags
, sal_Int16 _nFlagsMask
, sal_Bool _bReset
)
97 OSL_PRECOND(m_pCurrentNode
&& !m_pCurrentProp
, "LayerUpdateBuilder: Illegal state for this operation");
99 NodeUpdate
* pNewNode
= new NodeModification(m_pCurrentNode
,_aName
,_nFlags
,_nFlagsMask
,_bReset
);
100 rtl::Reference
<ElementUpdate
> xNewNode(pNewNode
);
102 if (!m_pCurrentNode
->addNodeUpdate(xNewNode
))
105 m_pCurrentNode
= pNewNode
;
108 // -----------------------------------------------------------------------------
110 bool LayerUpdateBuilder::replaceNode(rtl::OUString
const & _aName
, sal_Int16 _nFlags
, backenduno::TemplateIdentifier
const * _pTemplate
)
112 OSL_PRECOND(m_pCurrentNode
&& !m_pCurrentProp
, "LayerUpdateBuilder: Illegal state for this operation");
114 NodeUpdate
* pNewNode
= _pTemplate
?
115 new NodeReplace(m_pCurrentNode
,_aName
,_nFlags
,_pTemplate
->Name
,_pTemplate
->Component
) :
116 new NodeReplace(m_pCurrentNode
,_aName
,_nFlags
);
118 rtl::Reference
<ElementUpdate
> xNewNode(pNewNode
);
120 if (!m_pCurrentNode
->addNodeUpdate(xNewNode
))
123 m_pCurrentNode
= pNewNode
;
126 // -----------------------------------------------------------------------------
128 bool LayerUpdateBuilder::finishNode()
130 OSL_PRECOND(m_pCurrentNode
&& !m_pCurrentProp
, "LayerUpdateBuilder: Illegal state for this operation");
132 if (m_pCurrentProp
|| !m_pCurrentNode
) return false;
134 m_pCurrentNode
= m_pCurrentNode
->getParent();
137 // -----------------------------------------------------------------------------
139 bool LayerUpdateBuilder::removeNode(rtl::OUString
const & _aName
)
141 OSL_PRECOND(m_pCurrentNode
&& !m_pCurrentProp
, "LayerUpdateBuilder: Illegal state for this operation");
143 NodeDrop
* pNewNode
= new NodeDrop(m_pCurrentNode
,_aName
);
145 rtl::Reference
<ElementUpdate
> xNewNode(pNewNode
);
147 if (!m_pCurrentNode
->addNodeUpdate(xNewNode
))
152 // -----------------------------------------------------------------------------
154 bool LayerUpdateBuilder::modifyProperty(rtl::OUString
const & _aName
, sal_Int16 _nFlags
, sal_Int16 _nFlagsMask
, uno::Type
const & _aType
)
156 OSL_PRECOND(m_pCurrentNode
&& !m_pCurrentProp
, "LayerUpdateBuilder: Illegal state for this operation");
158 PropertyUpdate
* pNewProp
= new PropertyUpdate(m_pCurrentNode
,_aName
,_nFlags
,_nFlagsMask
,_aType
);
159 rtl::Reference
<ElementUpdate
> xNewProp(pNewProp
);
161 if (!m_pCurrentNode
->addPropertyUpdate(xNewProp
))
164 m_pCurrentProp
= pNewProp
;
167 // -----------------------------------------------------------------------------
169 bool LayerUpdateBuilder::setPropertyValue(uno::Any
const & _aValue
)
171 OSL_PRECOND(m_pCurrentProp
, "LayerUpdateBuilder: Illegal state for property operation");
173 return m_pCurrentProp
->setValue(_aValue
);
175 // -----------------------------------------------------------------------------
177 bool LayerUpdateBuilder::setPropertyValueForLocale(uno::Any
const & _aValue
, rtl::OUString
const & _aLocale
)
179 OSL_PRECOND(m_pCurrentProp
, "LayerUpdateBuilder: Illegal state for property operation");
181 return m_pCurrentProp
->setValueFor(_aLocale
, _aValue
);
183 // -----------------------------------------------------------------------------
185 bool LayerUpdateBuilder::resetPropertyValue()
187 OSL_PRECOND(m_pCurrentProp
, "LayerUpdateBuilder: Illegal state for property operation");
189 return m_pCurrentProp
->resetValue();
191 // -----------------------------------------------------------------------------
193 bool LayerUpdateBuilder::resetPropertyValueForLocale(rtl::OUString
const & _aLocale
)
195 OSL_PRECOND(m_pCurrentProp
, "LayerUpdateBuilder: Illegal state for property operation");
197 return m_pCurrentProp
->resetValueFor(_aLocale
);
199 // -----------------------------------------------------------------------------
201 bool LayerUpdateBuilder::finishProperty()
203 OSL_PRECOND(m_pCurrentProp
, "LayerUpdateBuilder: Illegal state for property operation");
204 if (!m_pCurrentProp
) return false;
205 m_pCurrentProp
->finishValue();
207 OSL_ASSERT(m_pCurrentNode
== m_pCurrentProp
->getParent());
209 m_pCurrentProp
= NULL
;
212 // -----------------------------------------------------------------------------
214 bool LayerUpdateBuilder::addNullProperty(rtl::OUString
const & _aName
, sal_Int16 _nFlags
, uno::Type
const & _aType
)
216 OSL_PRECOND(m_pCurrentNode
&& !m_pCurrentProp
, "LayerUpdateBuilder: Illegal state for this operation");
218 PropertyAdd
* pNewProp
= new PropertyAdd(m_pCurrentNode
,_aName
,_nFlags
,_aType
);
220 rtl::Reference
<ElementUpdate
> xNewProp(pNewProp
);
222 if (!m_pCurrentNode
->addPropertyUpdate(xNewProp
))
227 // -----------------------------------------------------------------------------
229 bool LayerUpdateBuilder::addProperty(rtl::OUString
const & _aName
, sal_Int16 _nFlags
, uno::Any
const & _aValue
)
231 OSL_PRECOND(m_pCurrentNode
&& !m_pCurrentProp
, "LayerUpdateBuilder: Illegal state for this operation");
233 PropertyAdd
* pNewProp
= new PropertyAdd(m_pCurrentNode
,_aName
,_nFlags
,_aValue
);
235 rtl::Reference
<ElementUpdate
> xNewProp(pNewProp
);
237 if (!m_pCurrentNode
->addPropertyUpdate(xNewProp
))
242 // -----------------------------------------------------------------------------
244 bool LayerUpdateBuilder::resetProperty(rtl::OUString
const & _aName
)
246 OSL_PRECOND(m_pCurrentNode
&& !m_pCurrentProp
, "LayerUpdateBuilder: Illegal state for this operation");
248 PropertyReset
* pNewProp
= new PropertyReset(m_pCurrentNode
,_aName
);
250 rtl::Reference
<ElementUpdate
> xNewProp(pNewProp
);
252 if (!m_pCurrentNode
->addPropertyUpdate(xNewProp
))
257 // -----------------------------------------------------------------------------
259 bool LayerUpdateBuilder::finish()
261 if (!this->finishNode()) return false;
263 return m_pCurrentNode
== NULL
;
265 // -----------------------------------------------------------------------------
267 bool LayerUpdateBuilder::isEmpty() const
269 OSL_ENSURE( !m_pCurrentNode
|| !m_aUpdate
.isEmpty(), "LayerUpdateBuilder: Invariant violation: got a current node without a layer");
270 return m_aUpdate
.isEmpty();
272 // -----------------------------------------------------------------------------
274 bool LayerUpdateBuilder::isActive() const
276 OSL_ENSURE( !m_pCurrentNode
|| !m_aUpdate
.isEmpty(), "LayerUpdateBuilder: Invariant violation: got a current node without a layer");
277 return m_pCurrentNode
!= 0;
279 // -----------------------------------------------------------------------------
280 #if OSL_DEBUG_LEVEL > 0
281 bool LayerUpdateBuilder::isComplete() const
283 OSL_ENSURE( !m_pCurrentNode
|| !m_aUpdate
.isEmpty(), "LayerUpdateBuilder: Invariant violation: got a current node without a layer");
284 return !m_aUpdate
.isEmpty() && m_pCurrentNode
== NULL
;
287 // -----------------------------------------------------------------------------
289 bool LayerUpdateBuilder::isPropertyActive() const
291 OSL_ENSURE( !m_pCurrentNode
|| !m_aUpdate
.isEmpty(), "LayerUpdateBuilder: Invariant violation: got a current node without a layer");
292 OSL_ENSURE(m_pCurrentNode
|| !m_pCurrentProp
, "LayerUpdateBuilder: Invariant violation: got a current property without a node");
293 return m_pCurrentProp
!= 0;
295 // -----------------------------------------------------------------------------
297 // -----------------------------------------------------------------------------
298 // -----------------------------------------------------------------------------
299 } // namespace backend
301 // -------------------------------------------------------------------------
302 } // namespace configmgr