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: nodeimplobj.hxx,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 #ifndef CONFIGMGR_NODEIMPLOBJECTS_HXX_
32 #define CONFIGMGR_NODEIMPLOBJECTS_HXX_
34 #include "sal/config.h"
36 #include "salhelper/simplereferenceobject.hxx"
39 #include "nodeimpl.hxx"
40 #include "groupnodeimpl.hxx"
41 #include "setnodeimpl.hxx"
42 #include "valuenodeimpl.hxx"
43 #include "utility.hxx"
45 #ifndef INCLUDED_MEMORY
47 #define INCLUDED_MEMORY
52 namespace configuration
54 //-----------------------------------------------------------------------------
56 // Specific types of nodes for direct or read only access
57 //-----------------------------------------------------------------------------
60 //-----------------------------------------------------------------------------
62 class ValueMemberNode::DeferredImpl
: public salhelper::SimpleReferenceObject
64 sharable::ValueNode
* m_valueNode
;
66 com::sun::star::uno::Any m_aNewValue
;
70 explicit DeferredImpl(sharable::ValueNode
* valueNode
);
72 /// does this wrap a change
73 bool isChange() const { return m_bChange
; }
75 /// retrieve the underlying (original) node
76 sharable::ValueNode
* getOriginalNode() const
77 { return m_valueNode
; }
79 /// Does this node change to default
80 bool isToDefault() const { return m_bToDefault
; }
82 /// retrieve the current value of this node
83 com::sun::star::uno::Any
getNewValue() const { return m_aNewValue
; }
85 /// Set this node to a new value
86 void setValue(com::sun::star::uno::Any
const& aNewValue
, sharable::ValueNode
* originalNode
);
88 /// Set this node to assume its default value
89 void setValueToDefault(sharable::ValueNode
* originalNode
);
93 std::auto_ptr
<ValueChange
> preCommitChange();
94 void finishCommit(ValueChange
& rChange
);
95 void revertCommit(ValueChange
& rChange
);
96 void failedCommit(ValueChange
& rChange
);
98 ValueChangeImpl
* collectChange();
99 ValueChangeImpl
* adjustToChange(ValueChange
const& rExternalChange
);
101 // notification protocol
102 void adjustToChange(NodeChangesInformation
& rLocalChange
, ValueChange
const& rExternalChange
, Tree
& rParentTree
, unsigned int nParentPos
, rtl::OUString
const& aName
);
104 //-----------------------------------------------------------------------------
107 //-----------------------------------------------------------------------------
110 //-----------------------------------------------------------------------------
112 class DeferredGroupNodeImpl
: public GroupNodeImpl
116 DeferredGroupNodeImpl(sharable::GroupNode
* const& _aNodeRef
);
118 DeferredGroupNodeImpl(sharable::GroupNode
* const& _aNewAddress
, GroupNodeImpl
& rOriginal
);
120 ~DeferredGroupNodeImpl();
124 std::auto_ptr
<SubtreeChange
> preCommitValueChanges();
125 void finishCommit(SubtreeChange
& rChange
);
126 void revertCommit(SubtreeChange
& rChange
);
127 void failedCommit(SubtreeChange
& rChange
);
129 void collectValueChanges(NodeChanges
& rChanges
, Tree
* pParent
, unsigned int nNode
) const;
133 bool hasChanges() const;
136 rtl::Reference
<ValueMemberNode::DeferredImpl
> findValueChange(rtl::OUString
const& aName
);
138 using GroupNodeImpl::makeValueMember
;
139 ValueMemberNode
makeValueMember(rtl::OUString
const& _aName
, bool _bForUpdate
);
142 typedef std::map
< rtl::OUString
, rtl::Reference
<ValueMemberNode::DeferredImpl
> > MemberChanges
;
144 MemberChanges m_aChanges
;
146 //-----------------------------------------------------------------------------
149 //-----------------------------------------------------------------------------
151 class DeferredSetNodeImpl
: public SetNodeImpl
155 DeferredSetNodeImpl(sharable::SetNode
* const& _aNodeRef
, Template
* pTemplate
);
158 bool hasChanges() const;
160 void collectElementChanges(NodeChanges
& rChanges
) const;
163 std::auto_ptr
<SubtreeChange
> preCommitChanges(std::vector
< rtl::Reference
<ElementTree
> >& _rRemovedElements
);
164 void failedCommit(SubtreeChange
& rChanges
);
165 void finishCommit(SubtreeChange
& rChanges
);
166 void revertCommit(SubtreeChange
& rChanges
);
168 void insertNewElement(rtl::OUString
const& aName
, ElementTreeData
const& aNewElement
);
169 void removeOldElement(rtl::OUString
const& aName
);
170 // Base Overrideables
172 // NodeImpl implementation
173 virtual bool doIsEmpty() const;
174 virtual ElementTree
* doFindElement(rtl::OUString
const& aName
) ;
175 virtual SetNodeVisitor::Result
doDispatchToElements(SetNodeVisitor
& aVisitor
);
177 virtual void doDifferenceToDefaultState(SubtreeChange
& _rChangeToDefault
, ISubtree
& _rDefaultTree
);
179 virtual SetElementChangeImpl
* doAdjustToAddedElement(rtl::OUString
const& aName
, AddNode
const& aAddNodeChange
, ElementTreeData
const & aNewElement
);
180 virtual SetElementChangeImpl
* doAdjustToRemovedElement(rtl::OUString
const& aName
, RemoveNode
const& aRemoveNodeChange
);
182 virtual SetElementChangeImpl
* doAdjustChangedElement(NodeChangesInformation
& rLocalChanges
, rtl::OUString
const& aName
, Change
const& aChange
);
184 virtual void doTransferElements(ElementSet
& rReplacement
);
188 void rebuildElement(rtl::OUString
const& aName
, ElementTreeData
const& _aElement
);
191 ElementSet m_aChangedData
;
195 //-----------------------------------------------------------------------------
197 //-----------------------------------------------------------------------------
201 #endif // CONFIGMGR_NODEIMPLOBJECTS_HXX_