update dev300-m58
[ooovba.git] / configmgr / source / treemgr / viewstrategy.hxx
blob8e77c0bf4a9082b4778ca0017a370960dc4156fc
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: viewstrategy.hxx,v $
10 * $Revision: 1.9 $
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_VIEWBEHAVIOR_HXX_
32 #define CONFIGMGR_VIEWBEHAVIOR_HXX_
34 #include "viewnode.hxx"
35 #include "groupnodeimpl.hxx"
36 #include "setnodeimpl.hxx"
37 #include "utility.hxx"
38 #include <rtl/ref.hxx>
39 #include <salhelper/simplereferenceobject.hxx>
41 namespace configmgr
43 //-----------------------------------------------------------------------------
44 namespace configuration
46 class SetElementChangeImpl;
47 class ValueChangeImpl;
49 //-----------------------------------------------------------------------------
50 namespace view
52 //-----------------------------------------------------------------------------
53 struct NodeFactory;
54 //-----------------------------------------------------------------------------
55 class ViewStrategy : public salhelper::SimpleReferenceObject
57 // node attributes
58 public:
59 /// retrieve the attributes of the node
60 rtl::OUString getName(Node const& _aNode) const;
62 /// retrieve the attributes of the node
63 node::Attributes getAttributes(Node const& _aNode) const;
65 // tracking pending changes
66 public:
67 void collectChanges(configuration::Tree * tree, configuration::NodeChanges& rChanges) const;
69 bool hasChanges(configuration::Tree * tree) const;
71 bool hasChanges(Node const& _aNode) const;
73 void markChanged(Node const& _aNode);
75 // commit protocol
76 public:
77 std::auto_ptr<SubtreeChange> preCommitChanges(configuration::Tree * tree, std::vector< rtl::Reference<configuration::ElementTree> >& _rRemovedElements);
79 void finishCommit(configuration::Tree * tree, SubtreeChange& rRootChange);
81 void revertCommit(configuration::Tree * tree, SubtreeChange& rRootChange);
83 void recoverFailedCommit(configuration::Tree * tree, SubtreeChange& rRootChange);
85 // notification protocol
86 public:
87 /// Adjust the internal representation after external changes to the original data - build NodeChangeInformation objects for notification
88 void adjustToChanges(configuration::NodeChangesInformation& rLocalChanges, Node const & _aNode, SubtreeChange const& aExternalChange);
90 // visitor dispatch
91 public:
92 configuration::GroupMemberVisitor::Result dispatchToValues(GroupNode const& _aNode, configuration::GroupMemberVisitor& _aVisitor);
94 /// Call <code>aVisitor.visit(aElement)</code> for each element in this set until SetNodeVisitor::DONE is returned.
95 configuration::SetNodeVisitor::Result dispatchToElements(SetNode const& _aNode, configuration::SetNodeVisitor& _aVisitor);
97 // value (element) node specific operations
98 public:
99 /// Does this node assume its default value
100 /// retrieve the current value of this node
101 com::sun::star::uno::Any getValue(ValueNode const& _aNode) const;
102 #if OSL_DEBUG_LEVEL > 0
103 /// get the type of this value
104 com::sun::star::uno::Type getValueType(ValueNode const& _aNode) const;
105 #endif
107 // group node specific operations
108 public:
109 /// does this hold a child value of the given name
110 bool hasValue(GroupNode const& _aNode, rtl::OUString const& _aName) const;
112 /// does this hold a child value
113 bool hasValue(GroupNode const& _aNode) const;
115 /// are defaults for this node available ?
116 bool areValueDefaultsAvailable(GroupNode const& _aNode) const;
118 /// retrieve data for the child value of the given name
119 configuration::ValueMemberNode getValue(GroupNode const& _aNode, rtl::OUString const& _aName) const;
121 /// retrieve data for updating the child value of the given name
122 configuration::ValueMemberUpdate getValueForUpdate(GroupNode const & _aNode, rtl::OUString const& _aName);
124 // set node specific operations
125 public:
126 /// does this set contain any elements (loads elements if needed)
127 bool isEmpty(SetNode const& _aNode) const;
129 /// does this set contain an element named <var>aName</var> (loads elements if needed)
130 configuration::SetEntry findElement(SetNode const& _aNode, rtl::OUString const& aName) const;
132 /// does this set contain an element named <var>aName</var> (and is that element loaded ?)
133 configuration::SetEntry findAvailableElement(SetNode const& _aNode, rtl::OUString const& aName) const;
135 /// insert a new entry into this set
136 void insertElement(SetNode const& _aNode, rtl::OUString const& aName, configuration::SetEntry const& aNewEntry);
138 /// remove an existing entry into this set
139 void removeElement(SetNode const& _aNode, rtl::OUString const& aName);
141 /** Create a Subtree change as 'diff' which allows transforming the set to its default state
142 (given that <var>_rDefaultTree</var> points to a default instance of this set)
143 <p>Ownership of added trees should be transferred to the SubtreeChange.</p>
145 std::auto_ptr<SubtreeChange> differenceToDefaultState(SetNode const& _aNode, ISubtree& _rDefaultTree) const;
147 /// Get the template that describes elements of this set
148 rtl::Reference<configuration::Template> getElementTemplate(SetNode const& _aNode) const;
150 /// Get a template provider that can create new elements for this set
151 configuration::TemplateProvider getTemplateProvider(SetNode const& _aNode) const;
153 // create a configuration::Tree * from a configuration::SetEntry
154 configuration::Tree * extractTree(configuration::SetEntry const& _anEntry);
156 // creating/changing state/strategy
157 public:
158 NodeFactory& getNodeFactory();
160 // access to node innards
161 protected:
162 /// provide access to the address of the underlying node
163 sharable::Node * getNodeAddress(Node const& _aNode) const;
165 /// retrieve the attributes of the underlying node
166 node::Attributes getNodeAttributes(Node const& _aNode) const;
168 protected:
169 //helper for migration to new (info based) model for adjusting to changes
170 static void addLocalChangeHelper( configuration::NodeChangesInformation& rLocalChanges, configuration::NodeChange const& aChange);
172 private:
173 void implAdjustToValueChanges(configuration::NodeChangesInformation& rLocalChanges, GroupNode const& _aGroupNode, SubtreeChange const& rExternalChanges);
174 void implAdjustToSubChanges(configuration::NodeChangesInformation& rLocalChanges, GroupNode const & _aGroupNode, SubtreeChange const& rExternalChanges);
175 void implAdjustToElementChanges(configuration::NodeChangesInformation& rLocalChanges, SetNode const& _aNode, SubtreeChange const& rExternalChanges, unsigned int nDepth);
176 void implAdjustToElementChange (configuration::NodeChangesInformation& rLocalChanges, SetNode const& _aNode, Change const& rElementChange, unsigned int nElementDepth);
177 void implCommitDirectIn(sharable::TreeFragment * placeHolder, Node const& _aNode);
179 protected:
180 void checkInstance(configuration::Tree * tree) const;
181 configuration::SetEntry implFindElement(SetNode const& _aNode, rtl::OUString const& aName) const;
182 configuration::ElementTreeData implMakeElement(SetNode const& _aNode, configuration::SetEntry const& anEntry) const;
184 // virtual interface - these functions must be provided
185 private:
186 // change handling
187 virtual bool doHasChanges(Node const& _aNode) const = 0;
188 virtual void doMarkChanged(Node const& _aNode) = 0;
190 virtual NodeFactory& doGetNodeFactory() = 0;
192 // virtual interface - these functions all have default implementations without support for pending changes
193 protected:
194 // change handling
195 virtual void doCollectChanges(Node const& _aNode, configuration::NodeChanges& rChanges) const;
197 // commit protocol
198 virtual std::auto_ptr<SubtreeChange> doPreCommitChanges(configuration::Tree * tree, std::vector< rtl::Reference<configuration::ElementTree> >& _rRemovedElements);
199 virtual void doFailedCommit(configuration::Tree * tree, SubtreeChange& rChanges);
200 virtual void doFinishCommit(configuration::Tree * tree, SubtreeChange& rChanges);
201 virtual void doRevertCommit(configuration::Tree * tree, SubtreeChange& rChanges);
203 // notification protocol
204 virtual configuration::ValueChangeImpl* doAdjustToValueChange(GroupNode const& _aGroupNode, rtl::OUString const& aName, ValueChange const& rExternalChange);
206 // common attributes
207 virtual node::Attributes doAdjustAttributes(node::Attributes const& _aAttributes) const = 0;
209 // group member access
210 virtual configuration::ValueMemberNode doGetValueMember(GroupNode const& _aNode, rtl::OUString const& _aName, bool _bForUpdate) const = 0;
212 // set element access
213 virtual void doInsertElement(SetNode const& _aNode, rtl::OUString const& aName, configuration::SetEntry const& aNewEntry) = 0;
214 virtual void doRemoveElement(SetNode const& _aNode, rtl::OUString const& aName) = 0;
217 inline node::Attributes ViewStrategy::getAttributes(Node const& _aNode) const
218 { return doAdjustAttributes(getNodeAttributes(_aNode)); }
220 inline bool ViewStrategy::hasChanges(Node const& _aNode) const
221 { return doHasChanges(_aNode); }
223 inline NodeFactory& ViewStrategy::getNodeFactory()
224 { return doGetNodeFactory(); }
226 //-----------------------------------------------------------------------------
228 //-----------------------------------------------------------------------------
231 #endif // CONFIGMGR_CONFIGNODEBEHAVIOR_HXX_