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: nodechangeimpl.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 "nodechangeimpl.hxx"
35 #include "nodechangeinfo.hxx"
36 #include "nodeimpl.hxx"
38 #include "configset.hxx"
39 #include "setnodeimpl.hxx"
40 #include "groupnodeimpl.hxx"
41 #include "valuenode.hxx"
46 namespace configuration
48 //-----------------------------------------------------------------------------
50 //-----------------------------------------------------------------------------
51 // All Changes:NodeChangeImpl - common base
52 //-----------------------------------------------------------------------------
54 // life cycle states for a NodeChangeImpl
55 enum { eTestedChange
= 0x01, eAppliedChange
= 0x02, eNoCheck
= 0x07 };
56 //-----------------------------------------------------------------------------
58 NodeChangeImpl::NodeChangeImpl(bool bNoCheck
)
63 if (bNoCheck
) m_nState
= eNoCheck
;
65 //-----------------------------------------------------------------------------
67 view::ViewTreeAccess
NodeChangeImpl::getTargetView()
69 OSL_ENSURE( m_aAffectedTree
.is(), "ERROR: Configuration Change: Target Tree Access has not been set up" );
71 return view::ViewTreeAccess(m_aAffectedTree
.get());
73 //-----------------------------------------------------------------------------
75 rtl::Reference
<Tree
> NodeChangeImpl::getTargetTree() const
77 rtl::Reference
<Tree
> aRet
= m_aAffectedTree
;
78 OSL_ENSURE( aRet
.is(), "ERROR: Configuration Change: Target Tree has not been set up" );
82 //-----------------------------------------------------------------------------
84 unsigned int NodeChangeImpl::getTargetNode() const
86 unsigned int nRet
= m_nAffectedNode
;
87 OSL_ENSURE( nRet
!= 0, "ERROR: Configuration Change: Target Node has not been set up" );
88 OSL_ENSURE( m_aAffectedTree
.is() && m_aAffectedTree
->isValidNode(nRet
),
89 "ERROR: Configuration Change: Changing Node does not match tree" );
93 //-----------------------------------------------------------------------------
95 void NodeChangeImpl::setTarget(view::Node _aAffectedNode
)
97 this->setTarget(_aAffectedNode
.tree(), _aAffectedNode
.get_offset());
100 void NodeChangeImpl::setTarget(rtl::Reference
<Tree
> const& _aAffectedTree
, unsigned int _nAffectedNode
)
102 OSL_ENSURE(m_nState
== 0 || (!m_aAffectedTree
.is() && m_nState
== eNoCheck
), "WARNING: Configuration: Retargeting change that already was tested or applied");
104 OSL_ENSURE( _aAffectedTree
.is(), "ERROR: Configuration Change: NULL Target Tree is not allowed" );
105 OSL_ENSURE( _nAffectedNode
, "ERROR: Configuration Change: NULL Target Node is not allowed" );
106 OSL_ENSURE( _aAffectedTree
->isValidNode(_nAffectedNode
), "ERROR: Configuration Change: Target Node does not match Tree" );
108 if (m_nState
!= eNoCheck
) m_nState
= 0; // previous checks are invalidated
110 m_aAffectedTree
= _aAffectedTree
;
111 m_nAffectedNode
= _nAffectedNode
;
113 //-----------------------------------------------------------------------------
115 bool NodeChangeImpl::isChange(bool bAllowUntested
) const
117 OSL_ENSURE(bAllowUntested
|| (m_nState
& eTestedChange
), "WARNING: Configuration: Change was not tested - isChange is meaningless");
119 if (m_nState
== eNoCheck
)
122 if (!(m_nState
& eTestedChange
))
123 return bAllowUntested
;
127 //-----------------------------------------------------------------------------
129 sal_uInt32
NodeChangeImpl::getChangeDataCount() const
131 OSL_PRECOND(m_nState
& eTestedChange
, "WARNING: Configuration: Change was not tested - change data count may be incorrect");
133 return doGetChangeCount();
135 //-----------------------------------------------------------------------------
137 bool NodeChangeImpl::fillChangeData(NodeChangeData
& rChange
, sal_uInt32 _ix
) const
139 OSL_PRECOND(_ix
< doGetChangeCount(), "ERROR: Configuration: Change index out of range");
140 OSL_PRECOND(m_nState
& eTestedChange
, "WARNING: Configuration: Change was not tested - fillChange is partially meaningless");
142 return doFillChange(rChange
, _ix
) || rChange
.isDataChange(); // force true if the data is signaling change
144 //-----------------------------------------------------------------------------
146 bool NodeChangeImpl::fillChangeLocation(NodeChangeLocation
& rChange
, sal_uInt32 _ix
) const
148 if (!m_aAffectedTree
.is()) return false;
150 rChange
.setBase( NodeID(this->getTargetTree().get(), this->getTargetNode()) );
152 rChange
.setAccessor( this->doGetChangingNodePath(_ix
) );
154 rChange
.setAffected( NodeID(this->getTargetTree().get(), this->getTargetNode()) );
156 rChange
.setChangingSubnode( this->doIsChangingSubnode() );
160 //-----------------------------------------------------------------------------
162 bool NodeChangeImpl::fillChangeInfo(NodeChangeInformation
& rChange
, sal_uInt32 _ix
) const
164 return fillChangeLocation(rChange
.location
, _ix
) & fillChangeData(rChange
.change
, _ix
);
166 //-----------------------------------------------------------------------------
168 void NodeChangeImpl::test()
170 if (!(m_nState
& eTestedChange
))
172 doTest(implGetTarget());
173 m_nState
|= eTestedChange
;
176 //-----------------------------------------------------------------------------
178 void NodeChangeImpl::apply()
180 if (!(m_nState
& eAppliedChange
))
184 OSL_ENSURE(m_nState
& eAppliedChange
, "ERROR: Configuration: Change could not be applied");
185 OSL_ENSURE(m_nState
& eTestedChange
, "ERROR: Configuration: Change was not tested while applied");
188 OSL_ENSURE(m_nState
& eTestedChange
, "ERROR: Configuration: Change marked applied but not tested");
190 //-----------------------------------------------------------------------------
192 // default count is 1
193 sal_uInt32
NodeChangeImpl::doGetChangeCount() const
197 //-----------------------------------------------------------------------------
199 /// apply this change to the given node - start state is nState (which is then updated)
200 void NodeChangeImpl::implApply()
202 OSL_ASSERT( !(m_nState
& eAppliedChange
)); // Caller must check
204 view::Node aTarget
= implGetTarget();
206 if (!(m_nState
& eTestedChange
)) // Test checks the old value if there is realy a change
207 { // for eventlisteners to say "the old value is kept"
209 m_nState
|= eTestedChange
;
213 m_nState
|= eAppliedChange
;
215 //-----------------------------------------------------------------------------
217 view::Node
NodeChangeImpl::implGetTarget()
219 OSL_ENSURE(m_aAffectedTree
.is(), "ERROR: Configuration Change: no target tree set");
221 OSL_ENSURE(m_aAffectedTree
->isValidNode(m_nAffectedNode
), "ERROR: Configuration Change: target node not in target tree");
223 view::Node aTarget
= getTargetView().makeNode(m_nAffectedNode
);
224 OSL_ENSURE(aTarget
.is(), "ERROR: Configuration: No target for change");
227 //-----------------------------------------------------------------------------
229 //-----------------------------------------------------------------------------
230 // Value operations: ValueChangeImpl = common base
231 //-----------------------------------------------------------------------------
233 ValueChangeImpl::ValueChangeImpl()
238 //-----------------------------------------------------------------------------
240 ValueChangeImpl::ValueChangeImpl(com::sun::star::uno::Any
const& aNewValue
)
241 : m_aNewValue(aNewValue
)
245 //-----------------------------------------------------------------------------
247 ValueChangeImpl::ValueChangeImpl(com::sun::star::uno::Any
const& aNewValue
, com::sun::star::uno::Any
const& aOldValue
)
248 : NodeChangeImpl(true)
249 , m_aNewValue(aNewValue
)
250 , m_aOldValue(aOldValue
)
253 //-----------------------------------------------------------------------------
255 ValueChangeImpl::~ValueChangeImpl()
258 //-----------------------------------------------------------------------------
260 void ValueChangeImpl::setTarget(view::GroupNode
const& _aParentNode
, rtl::OUString
const& sNodeName
)
262 OSL_ENSURE(sNodeName
.getLength() != 0, "ValueChangeTarget is being set without a name");
264 NodeChangeImpl::setTarget(_aParentNode
.node());
267 //-----------------------------------------------------------------------------
269 void ValueChangeImpl::setTarget(rtl::Reference
<Tree
> const& aAffectedTree
, unsigned int nParentNode
, rtl::OUString
const& sNodeName
)
271 OSL_ENSURE(sNodeName
.getLength() != 0, "ValueChangeTarget is being set without a name");
273 NodeChangeImpl::setTarget(aAffectedTree
,nParentNode
);
276 //-----------------------------------------------------------------------------
278 RelativePath
ValueChangeImpl::doGetChangingNodePath(sal_uInt32
) const
280 return RelativePath( Path::wrapSimpleName(m_aName
) );
282 //-----------------------------------------------------------------------------
284 bool ValueChangeImpl::doIsChangingSubnode() const
286 return m_aName
.getLength() != 0;
288 //-----------------------------------------------------------------------------
290 bool ValueChangeImpl::doIsChange() const
292 return !!(getNewValue() != getOldValue());
294 //-----------------------------------------------------------------------------
296 bool ValueChangeImpl::doFillChange(NodeChangeData
& rChange
, sal_uInt32
) const
298 rChange
.unoData
.newValue
= getNewValue();
299 rChange
.unoData
.oldValue
= getOldValue();
300 return rChange
.unoData
.isDataChange();
302 //-----------------------------------------------------------------------------
304 void ValueChangeImpl::doTest( view::Node
const& rTarget
)
306 view::ViewTreeAccess aTargetView
= getTargetView();
308 OSL_ENSURE(rTarget
.isGroupNode(), "ERROR: Configuration: Target type mismatch: expected a group node holding the value");
310 ValueMemberNode aValueTarget
= aTargetView
.getValue( view::GroupNode(rTarget
), m_aName
);
312 OSL_ENSURE(aValueTarget
.isValid(), "ERROR: Configuration: Target missing: could not find the changing value");
314 preCheckValue(aValueTarget
, m_aOldValue
, m_aNewValue
);
316 //-----------------------------------------------------------------------------
318 void ValueChangeImpl::doApply( view::Node
const& rTarget
)
320 view::ViewTreeAccess aTargetView
= getTargetView();
322 OSL_ENSURE(rTarget
.isGroupNode(), "ERROR: Configuration: Target type mismatch: expected a group node holding the value");
324 ValueMemberUpdate aValueTarget
= aTargetView
.getValueForUpdate( view::GroupNode(rTarget
), m_aName
);
326 OSL_ENSURE(aValueTarget
.isValid(), "ERROR: Configuration: Target missing: could not find the changing value");
328 doApplyChange(aValueTarget
);
329 configmgr::configuration::ValueMemberNode
aNode(aValueTarget
.getNode());
330 postCheckValue(aNode
, m_aNewValue
); // Sideeffect: m_aNewValue will be changed
332 //-----------------------------------------------------------------------------
334 void ValueChangeImpl::preCheckValue(ValueMemberNode
& rNode
, com::sun::star::uno::Any
& rOld
, com::sun::star::uno::Any
& )
336 com::sun::star::uno::Any aPrevValue
= rNode
.getValue();
337 OSL_ENSURE(!rOld
.hasValue() || rOld
== aPrevValue
, "ERROR: Configuration: Stored old value of target does not match the actual value");
340 //-----------------------------------------------------------------------------
342 void ValueChangeImpl::postCheckValue(ValueMemberNode
& rNode
, com::sun::star::uno::Any
& rNew
)
344 com::sun::star::uno::Any aResultValue
= rNode
.getValue();
345 OSL_ENSURE(!rNew
.hasValue() || rNew
== aResultValue
, "ERROR: Configuration: New value of target does not match the predicted result");
348 //-----------------------------------------------------------------------------
350 //-----------------------------------------------------------------------------
351 // Value operations: ValueReplaceImpl = set local value
352 //-----------------------------------------------------------------------------
354 ValueReplaceImpl::ValueReplaceImpl(com::sun::star::uno::Any
const& aNewValue
)
355 :ValueChangeImpl(aNewValue
)
358 //-----------------------------------------------------------------------------
360 ValueReplaceImpl::ValueReplaceImpl(com::sun::star::uno::Any
const& aNewValue
, com::sun::star::uno::Any
const& aOldValue
)
361 :ValueChangeImpl(aNewValue
, aOldValue
)
364 //-----------------------------------------------------------------------------
366 void ValueReplaceImpl::doApplyChange( ValueMemberUpdate
& rNode
)
368 rNode
.setValue(getNewValue());
370 //-----------------------------------------------------------------------------
372 bool ValueReplaceImpl::doFillChange( NodeChangeData
& rChange
, sal_uInt32 _ix
) const
374 rChange
.type
= NodeChangeData::eSetValue
;
375 return ValueChangeImpl::doFillChange(rChange
, _ix
);
378 //-----------------------------------------------------------------------------
379 // Value operations: ValueResetImpl = set to default
380 //-----------------------------------------------------------------------------
382 ValueResetImpl::ValueResetImpl()
384 , m_bTargetIsDefault(false)
387 //-----------------------------------------------------------------------------
389 ValueResetImpl::ValueResetImpl(com::sun::star::uno::Any
const& aNewValue
, com::sun::star::uno::Any
const& aOldValue
)
390 :ValueChangeImpl(aNewValue
, aOldValue
)
391 , m_bTargetIsDefault(false)
394 //-----------------------------------------------------------------------------
396 void ValueResetImpl::doApplyChange( ValueMemberUpdate
& rNode
)
400 //-----------------------------------------------------------------------------
402 bool ValueResetImpl::doIsChange() const
404 return !m_bTargetIsDefault
;
406 //-----------------------------------------------------------------------------
408 bool ValueResetImpl::doFillChange( NodeChangeData
& rChange
, sal_uInt32 _ix
) const
410 rChange
.type
= NodeChangeData::eSetDefault
;
411 ValueChangeImpl::doFillChange(rChange
,_ix
);
412 return !m_bTargetIsDefault
&& !rChange
.isEmptyChange(); // do it defensively here - default (= 'new') may be unknown still
414 //-----------------------------------------------------------------------------
416 void ValueResetImpl::preCheckValue(ValueMemberNode
& rNode
, com::sun::star::uno::Any
& rOld
, com::sun::star::uno::Any
& rNew
)
418 ValueChangeImpl::preCheckValue(rNode
,rOld
,rNew
);
420 com::sun::star::uno::Any aDefaultValue
= rNode
.getDefaultValue();
421 OSL_ENSURE(!rNew
.hasValue() || rNew
== aDefaultValue
, "ERROR: Configuration: Stored new value of target does not match the actual default value");
422 rNew
= aDefaultValue
;
423 m_bTargetIsDefault
= rNode
.isDefault();
426 //-----------------------------------------------------------------------------
427 // All Set Changes: SetChangeImpl - common base
428 //-----------------------------------------------------------------------------
430 SetChangeImpl::SetChangeImpl(bool bNoCheck
)
431 : NodeChangeImpl(bNoCheck
)
434 //-----------------------------------------------------------------------------
436 bool SetChangeImpl::doIsChangingSubnode() const
441 //-----------------------------------------------------------------------------
442 // Resetting a set to its default state
443 //-----------------------------------------------------------------------------
445 SetResetImpl::SetResetImpl(
446 SetElementFactory
& _rElementFactory
,
447 std::auto_ptr
<ISubtree
> _pDefaultData
,
450 : SetChangeImpl(_bNoCheck
)
451 , m_aDefaultData(_pDefaultData
)
452 , m_rElementFactory(_rElementFactory
)
456 //-----------------------------------------------------------------------------
458 SetResetImpl::~SetResetImpl()
461 //-----------------------------------------------------------------------------
463 RelativePath
SetResetImpl::doGetChangingNodePath(sal_uInt32 _ix
) const
465 OSL_ENSURE( _ix
< m_aTreeChanges
.size() || _ix
== scCommonBase
, "Illegal Change index" );
466 OSL_ASSERT( static_cast<size_t>(scCommonBase
) > m_aTreeChanges
.size() );
468 if ( _ix
< m_aTreeChanges
.size() )
469 return RelativePath( m_aTreeChanges
[_ix
].m_aElementName
);
472 return RelativePath();
474 //-----------------------------------------------------------------------------
476 static NodeChangeData::Type
getChangeType(ElementTreeChange
const& aChange
)
478 sal_Bool bHasNew
= aChange
.m_aAddedElement
.is();
479 sal_Bool bHasOld
= aChange
.m_aRemovedElement
.is();
481 NodeChangeData::Type aResult
;
483 aResult
= bHasOld
? NodeChangeData::eReplaceElement
: NodeChangeData::eInsertElement
;
485 aResult
= bHasOld
? NodeChangeData::eRemoveElement
: NodeChangeData::eSetDefault
;
489 //-----------------------------------------------------------------------------
491 bool SetResetImpl::doIsChange() const
493 return !m_aTreeChanges
.empty() || m_aDefaultData
.get();
495 //-----------------------------------------------------------------------------
497 bool SetResetImpl::doFillChange(NodeChangeData
& rChange
, sal_uInt32 _ix
) const
499 OSL_ENSURE( _ix
< m_aTreeChanges
.size() || _ix
== scCommonBase
, "Illegal Change index" );
500 if (_ix
>= m_aTreeChanges
.size())
502 rChange
.type
= NodeChangeData::eResetSetDefault
;
503 return m_aDefaultData
.get() != NULL
;
505 ElementTreeChange
const& aChange
= m_aTreeChanges
[_ix
];
507 rChange
.type
= getChangeType(aChange
);
509 rChange
.element
.newValue
= aChange
.m_aAddedElement
;
510 rChange
.element
.oldValue
= aChange
.m_aRemovedElement
;
514 //-----------------------------------------------------------------------------
516 void SetResetImpl::doTest( view::Node
const& rTarget
)
518 if ( m_aDefaultData
.get() )
520 view::ViewTreeAccess accessor
= this->getTargetView();
522 view::SetNode
aTargetSet(rTarget
);
524 std::auto_ptr
<SubtreeChange
> pChanges
= accessor
.differenceToDefaultState(aTargetSet
, *m_aDefaultData
);
528 for (SubtreeChange::MutatingChildIterator it
= pChanges
->begin_changes(),
529 stop
= pChanges
->end_changes();
533 rtl::OUString
aName(it
->getNodeName());
535 SetEntry anExistingEntry
= accessor
.findElement(aTargetSet
,aName
);
537 rtl::Reference
<ElementTree
> aOldTree
= anExistingEntry
.tree();
538 rtl::Reference
<ElementTree
> aNewTree
;
540 if (AddNode
* addNode
= dynamic_cast< AddNode
* >(&*it
))
542 rtl::Reference
< data::TreeSegment
> pAddedNode
= addNode
->getNewTree();
544 OSL_ENSURE(pAddedNode
.is(), "Processing an addNode to default - no node to add");
546 aNewTree
= m_rElementFactory
.instantiateOnDefault(pAddedNode
,accessor
.getElementTemplate(aTargetSet
)).get();
550 Path::Component aFullName
=
551 aNewTree
.is() ? aNewTree
->getExtendedRootName() :
552 aOldTree
.is() ? aOldTree
->getExtendedRootName() :
553 Path::makeCompositeName(aName
,accessor
.getElementTemplate(aTargetSet
)->getName());
555 OSL_ENSURE(aOldTree
.is() || aNewTree
.is(), "No data for change to default");
557 m_aTreeChanges
.push_back(ElementTreeChange(aFullName
,aNewTree
,aOldTree
));
561 m_aDefaultData
.reset();
564 //-----------------------------------------------------------------------------
566 void SetResetImpl::doApply( view::Node
const& rTarget
)
568 view::ViewTreeAccess accessor
= this->getTargetView();
570 view::SetNode
aTargetSet(rTarget
);
572 for (std::vector
< ElementTreeChange
>::iterator it
= m_aTreeChanges
.begin(); it
!= m_aTreeChanges
.end(); ++it
)
574 rtl::OUString aElementName
= it
->m_aElementName
.getName();
576 if (it
->m_aRemovedElement
.is())
577 accessor
.removeElement(aTargetSet
, aElementName
);
579 if (it
->m_aAddedElement
.is())
581 SetEntry
aNewEntry( it
->m_aAddedElement
.get() );
582 accessor
.insertElement(aTargetSet
, aElementName
, aNewEntry
);
585 OSL_ENSURE(getChangeType(*it
) != NodeChangeData::eSetDefault
,
586 "Cannot apply change without data");
590 //-----------------------------------------------------------------------------
591 // All Set Changes affecting a single element: SetElementChangeImpl - common base
592 //-----------------------------------------------------------------------------
594 SetElementChangeImpl::SetElementChangeImpl(Path::Component
const& aName
, bool bNoCheck
)
595 : SetChangeImpl(bNoCheck
)
599 //-----------------------------------------------------------------------------
601 RelativePath
SetElementChangeImpl::doGetChangingNodePath(sal_uInt32
) const
603 return RelativePath(getFullElementName());
605 //-----------------------------------------------------------------------------
607 void SetElementChangeImpl::doTest( view::Node
const& rTarget
)
609 doTestElement(view::SetNode(rTarget
), getElementName() );
611 //-----------------------------------------------------------------------------
613 void SetElementChangeImpl::doApply( view::Node
const& rTarget
)
615 doApplyToElement(view::SetNode(rTarget
), getElementName() );
618 //-----------------------------------------------------------------------------
619 // Full Sets: SetInsertTreeImpl
620 //-----------------------------------------------------------------------------
622 SetInsertImpl::SetInsertImpl(Path::Component
const& aName
, rtl::Reference
<ElementTree
> const& aNewTree
, bool bNoCheck
)
623 : SetElementChangeImpl(aName
,bNoCheck
)
624 , m_aNewTree(aNewTree
)
627 //-----------------------------------------------------------------------------
629 bool SetInsertImpl::doIsChange() const
631 return !!m_aNewTree
.is();
633 //-----------------------------------------------------------------------------
635 bool SetInsertImpl::doFillChange(NodeChangeData
& rChange
, sal_uInt32
) const
637 rChange
.type
= NodeChangeData::eInsertElement
;
639 rChange
.element
.newValue
= m_aNewTree
;
641 return isChange(true);
643 //-----------------------------------------------------------------------------
645 void SetInsertImpl::doTestElement( view::SetNode
const& _aNode
, rtl::OUString
const& aName
)
647 SetEntry anEntry
= getTargetView().findElement(_aNode
,aName
); // require loaded children
648 OSL_ENSURE(!anEntry
.isValid(), "ERROR: Configuration: Adding a node that already exists");
650 //-----------------------------------------------------------------------------
652 void SetInsertImpl::doApplyToElement( view::SetNode
const& _aNode
, rtl::OUString
const& aName
)
656 SetEntry
aNewEntry( m_aNewTree
.get() );
657 getTargetView().insertElement( _aNode
, aName
, aNewEntry
);
661 //-----------------------------------------------------------------------------
662 // Full Sets: SetReplaceTreeImpl
663 //-----------------------------------------------------------------------------
665 SetReplaceImpl::SetReplaceImpl(Path::Component
const& aName
, rtl::Reference
<ElementTree
> const& aNewTree
)
666 : SetElementChangeImpl(aName
)
667 , m_aNewTree(aNewTree
)
671 //-----------------------------------------------------------------------------
673 SetReplaceImpl::SetReplaceImpl(Path::Component
const& aName
, rtl::Reference
<ElementTree
> const& aNewTree
, rtl::Reference
<ElementTree
> const& aOldTree
)
674 : SetElementChangeImpl(aName
,true)
675 , m_aNewTree(aNewTree
)
676 , m_aOldTree(aOldTree
)
679 //-----------------------------------------------------------------------------
681 /// checks, if this represents an actual change
682 bool SetReplaceImpl::doIsChange() const
684 return !(m_aOldTree
== m_aNewTree
);
686 //-----------------------------------------------------------------------------
688 /// fills in pre- and post-change values, returns wether they differ
689 bool SetReplaceImpl::doFillChange(NodeChangeData
& rChange
, sal_uInt32
) const
691 rChange
.type
= NodeChangeData::eReplaceElement
;
693 rChange
.element
.newValue
= m_aNewTree
;
696 rChange
.element
.oldValue
= m_aOldTree
;
698 return isChange(true);
700 //-----------------------------------------------------------------------------
702 void SetReplaceImpl::doTestElement( view::SetNode
const& _aNode
, rtl::OUString
const& aName
)
704 OSL_ASSERT(!m_aOldTree
.is()); // already tested ?
706 // remove the old node
707 SetEntry anEntry
= getTargetView().findElement(_aNode
,aName
); // require loaded children
708 OSL_ENSURE(anEntry
.isValid(), "ERROR: Configuration: Replacing a node that doesn't exist");
710 m_aOldTree
= anEntry
.tree();
712 //-----------------------------------------------------------------------------
714 void SetReplaceImpl::doApplyToElement( view::SetNode
const& _aNode
, rtl::OUString
const& aName
)
716 if (m_aOldTree
!= m_aNewTree
)
718 view::ViewTreeAccess aTargetView
= this->getTargetView();
720 OSL_ENSURE(m_aOldTree
.is(), "ERROR: Configuration: Replacing a node that doesn't exist");
721 aTargetView
.removeElement(_aNode
, aName
);
724 OSL_ENSURE(m_aNewTree
.is(), "ERROR: Configuration: Replacing a node with nothing");
727 SetEntry
aNewEntry( m_aNewTree
.get() );
728 aTargetView
.insertElement( _aNode
, aName
, aNewEntry
);
733 //-----------------------------------------------------------------------------
734 // Full Sets: SetRemoveTreeImpl
735 //-----------------------------------------------------------------------------
737 SetRemoveImpl::SetRemoveImpl(Path::Component
const& aName
)
738 : SetElementChangeImpl(aName
)
742 //-----------------------------------------------------------------------------
744 SetRemoveImpl::SetRemoveImpl(Path::Component
const& aName
, rtl::Reference
<ElementTree
> const& aOldTree
)
745 : SetElementChangeImpl(aName
,true)
746 , m_aOldTree(aOldTree
)
749 //-----------------------------------------------------------------------------
751 /// checks, if this represents an actual change
752 bool SetRemoveImpl::doIsChange() const
754 return !!m_aOldTree
.is();
756 //-----------------------------------------------------------------------------
758 /// fills in pre- and post-change values, returns wether they differ
759 bool SetRemoveImpl::doFillChange(NodeChangeData
& rChange
, sal_uInt32
) const
761 rChange
.type
= NodeChangeData::eRemoveElement
;
763 rChange
.element
.oldValue
= m_aOldTree
;
765 return isChange(true);
767 //-----------------------------------------------------------------------------
769 void SetRemoveImpl::doTestElement( view::SetNode
const& _aNode
, rtl::OUString
const& aName
)
771 OSL_ASSERT(!m_aOldTree
.is()); // already tested ?
773 // remove the old node
774 SetEntry anEntry
= getTargetView().findElement(_aNode
,aName
); // require loaded children
775 OSL_ENSURE(anEntry
.isValid(), "ERROR: Configuration: Removing a node that doesn't exist");
777 m_aOldTree
= anEntry
.tree();
779 //-----------------------------------------------------------------------------
781 void SetRemoveImpl::doApplyToElement( view::SetNode
const& _aNode
, rtl::OUString
const& aName
)
783 getTargetView().removeElement(_aNode
, aName
);
786 //-----------------------------------------------------------------------------