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: viewaccess.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_VIEWACCESS_HXX_
32 #define CONFIGMGR_VIEWACCESS_HXX_
34 #include "viewnode.hxx"
35 #include "viewstrategy.hxx"
36 #include <rtl/ref.hxx>
38 //-----------------------------------------------------------------------------
41 //-----------------------------------------------------------------------------
42 namespace configuration
{ class NodeRef
; }
43 //-----------------------------------------------------------------------------
46 //-----------------------------------------------------------------------------
50 rtl::Reference
< ViewStrategy
> m_xStrategy
;
51 configuration::Tree
* m_tree
;
54 explicit ViewTreeAccess(configuration::Tree
* tree
):
55 m_xStrategy(tree
->getViewBehavior()), m_tree(tree
) {}
57 rtl::Reference
< view::ViewStrategy
> getViewBehavior() { return m_xStrategy
; }
59 configuration::NodeData
* nodeData(configuration::NodeRef
const& _aNodeArg
) const;
60 configuration::NodeData
* nodeData(unsigned int _aNodePos
) const;
62 Node
makeNode(configuration::NodeRef
const& _aNodeArg
) const { return Node(m_tree
,nodeData(_aNodeArg
)); }
63 Node
makeNode(unsigned int _aNodePos
) const { return Node(m_tree
,nodeData(_aNodePos
)); }
65 bool isSetNode (configuration::NodeRef
const& _aNodeArg
) const { return makeNode(_aNodeArg
).isSetNode(); }
66 bool isGroupNode(configuration::NodeRef
const& _aNodeArg
) const { return makeNode(_aNodeArg
).isGroupNode(); }
67 bool isValueNode(configuration::NodeRef
const& _aNodeArg
) const { return makeNode(_aNodeArg
).isValueNode(); }
69 bool isSetNodeAt (unsigned int _aNodeArg
) const { return makeNode(_aNodeArg
).isSetNode(); }
70 bool isGroupNodeAt(unsigned int _aNodeArg
) const { return makeNode(_aNodeArg
).isGroupNode(); }
71 bool isValueNodeAt(unsigned int _aNodeArg
) const { return makeNode(_aNodeArg
).isValueNode(); }
73 SetNode
toSetNode (configuration::NodeRef
const& _aNodeArg
) const
74 { return SetNode (makeNode(_aNodeArg
)); }
76 GroupNode
toGroupNode(configuration::NodeRef
const& _aNodeArg
) const
77 { return GroupNode(makeNode(_aNodeArg
)); }
79 ValueNode
toValueNode(configuration::NodeRef
const& _aNodeArg
) const
80 { return ValueNode(makeNode(_aNodeArg
)); }
82 SetNode
getSetNodeAt (unsigned int _aNodeArg
) const
83 { return SetNode (makeNode(_aNodeArg
)); }
85 GroupNode
getGroupNodeAt(unsigned int _aNodeArg
) const
86 { return GroupNode(makeNode(_aNodeArg
)); }
88 ValueNode
getValueNodeAt(unsigned int _aNodeArg
) const
89 { return ValueNode(makeNode(_aNodeArg
)); }
92 /// retrieve the name of the node
93 rtl::OUString
getName(configuration::NodeRef
const& _aNode
) const
94 { return m_xStrategy
->getName(makeNode(_aNode
)); }
96 /// retrieve the attributes of the node
97 node::Attributes
getAttributes(configuration::NodeRef
const& _aNode
) const
98 { return m_xStrategy
->getAttributes(makeNode(_aNode
)); }
100 /// retrieve the name of the tree root
101 rtl::OUString
getRootName() const
102 { return m_xStrategy
->getName( getRootNode(m_tree
) ); }
104 /// retrieve the attributes of the tree root
105 node::Attributes
getRootAttributes() const
106 { return m_xStrategy
->getAttributes( getRootNode(m_tree
) ); }
108 // tracking pending changes
110 void collectChanges(configuration::NodeChanges
& rChanges
) const
111 { m_xStrategy
->collectChanges(m_tree
,rChanges
); }
113 bool hasChanges() const
114 { return m_xStrategy
->hasChanges(m_tree
); }
116 bool hasChanges(configuration::NodeRef
const& _aNode
) const
117 { return m_xStrategy
->hasChanges(makeNode(_aNode
)); }
119 void markChanged(configuration::NodeRef
const& _aNode
)
120 { m_xStrategy
->markChanged(makeNode(_aNode
)); }
124 std::auto_ptr
<SubtreeChange
> preCommitChanges(std::vector
< rtl::Reference
<configuration::ElementTree
> >& _rRemovedElements
)
125 { return m_xStrategy
->preCommitChanges(m_tree
,_rRemovedElements
); }
127 void finishCommit(SubtreeChange
& rRootChange
)
128 { m_xStrategy
->finishCommit(m_tree
,rRootChange
); }
130 void revertCommit(SubtreeChange
& rRootChange
)
131 { m_xStrategy
->revertCommit(m_tree
,rRootChange
); }
133 void recoverFailedCommit(SubtreeChange
& rRootChange
)
134 { m_xStrategy
->recoverFailedCommit(m_tree
,rRootChange
); }
136 // notification protocol
138 /// Adjust the internal representation after external changes to the original data - build NodeChangeInformation objects for notification
139 void adjustToChanges(configuration::NodeChangesInformation
& rLocalChanges
, configuration::NodeRef
const& _aNode
, SubtreeChange
const& aExternalChange
)
140 { m_xStrategy
->adjustToChanges(rLocalChanges
,makeNode(_aNode
), aExternalChange
); }
144 configuration::GroupMemberVisitor::Result
dispatchToValues(GroupNode
const& _aNode
, configuration::GroupMemberVisitor
& _aVisitor
) const
145 { return m_xStrategy
->dispatchToValues(_aNode
,_aVisitor
); }
147 /// Call <code>aVisitor.visit(aElement)</code> for each element in this set until SetNodeVisitor::DONE is returned.
148 configuration::SetNodeVisitor::Result
dispatchToElements(SetNode
const& _aNode
, configuration::SetNodeVisitor
& _aVisitor
) const
149 { return m_xStrategy
->dispatchToElements(_aNode
,_aVisitor
); }
151 // value (element) node specific operations
153 /// Does this node assume its default value
154 /// retrieve the current value of this node
155 com::sun::star::uno::Any
getValue(ValueNode
const& _aNode
) const
156 { return m_xStrategy
->getValue(_aNode
); }
157 #if OSL_DEBUG_LEVEL > 0
158 /// get the type of this value
159 com::sun::star::uno::Type
getValueType(ValueNode
const& _aNode
) const
160 { return m_xStrategy
->getValueType(_aNode
); }
163 // group node specific operations
165 /// does this hold a child value of the given name
166 bool hasValue(GroupNode
const& _aNode
, rtl::OUString
const& _aName
) const
167 { return m_xStrategy
->hasValue(_aNode
,_aName
); }
169 /// does this hold a child value
170 bool hasValue(GroupNode
const& _aNode
) const
171 { return m_xStrategy
->hasValue(_aNode
); }
173 /// are defaults for this node available ?
174 bool areValueDefaultsAvailable(GroupNode
const& _aNode
) const
175 { return m_xStrategy
->areValueDefaultsAvailable(_aNode
); }
177 /// retrieve data for the child value of the given name
178 configuration::ValueMemberNode
getValue(GroupNode
const& _aNode
, rtl::OUString
const& _aName
) const
179 { return m_xStrategy
->getValue(_aNode
,_aName
); }
181 /// retrieve data for updating the child value of the given name
182 configuration::ValueMemberUpdate
getValueForUpdate(GroupNode
const & _aNode
, rtl::OUString
const& _aName
) const
183 { return m_xStrategy
->getValueForUpdate(_aNode
,_aName
); }
185 // set node specific operations
187 /// does this set contain any elements (loads elements if needed)
188 bool isEmpty(SetNode
const& _aNode
) const
189 { return m_xStrategy
->isEmpty(_aNode
); }
191 /// does this set contain an element named <var>aName</var> (loads elements if needed)
192 configuration::SetEntry
findElement(SetNode
const& _aNode
, rtl::OUString
const& aName
) const
193 { return m_xStrategy
->findElement(_aNode
,aName
); }
195 /// does this set contain an element named <var>aName</var> (and is that element loaded ?)
196 configuration::SetEntry
findAvailableElement(SetNode
const& _aNode
, rtl::OUString
const& aName
) const
197 { return m_xStrategy
->findAvailableElement(_aNode
,aName
); }
199 /// insert a new entry into this set
200 void insertElement(SetNode
const& _aNode
, rtl::OUString
const& aName
, configuration::SetEntry
const& aNewEntry
)
201 { m_xStrategy
->insertElement(_aNode
,aName
,aNewEntry
); }
203 /// remove an existing entry into this set
204 void removeElement(SetNode
const& _aNode
, rtl::OUString
const& aName
)
205 { m_xStrategy
->removeElement(_aNode
,aName
); }
207 /** Create a Subtree change as 'diff' which allows transforming the set to its default state
208 (given that <var>_rDefaultTree</var> points to a default instance of this set)
209 <p>Ownership of added trees should be transferred to the SubtreeChange.</p>
211 std::auto_ptr
<SubtreeChange
> differenceToDefaultState(SetNode
const& _aNode
, ISubtree
& _rDefaultTree
)
212 { return m_xStrategy
->differenceToDefaultState(_aNode
,_rDefaultTree
); }
214 /// Get the template that describes elements of this set
215 rtl::Reference
<configuration::Template
> getElementTemplate(SetNode
const& _aNode
) const
216 { return m_xStrategy
->getElementTemplate(_aNode
); }
218 /// Get a template provider that can create new elements for this set
219 configuration::TemplateProvider
getTemplateProvider(SetNode
const& _aNode
) const
220 { return m_xStrategy
->getTemplateProvider(_aNode
); }
222 // changing state/strategy
224 // replace m_xStrategy by a direct ViewStrategy (commiting changes to the data), if possible
225 // void makeDirect ();
231 #endif // CONFIGMGR_VIEWACCESS_HXX_