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: updatedata.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_BACKEND_UPDATEDATA_HXX
32 #define CONFIGMGR_BACKEND_UPDATEDATA_HXX
34 #include <com/sun/star/uno/Any.hxx>
35 #include <com/sun/star/uno/Type.hxx>
36 #include <rtl/ref.hxx>
37 #include <rtl/ustring.hxx>
38 #include <salhelper/simplereferenceobject.hxx>
39 #include "utility.hxx"
50 namespace com
{ namespace sun
{ namespace star
{ namespace configuration
{ namespace backend
{
53 // -----------------------------------------------------------------------------
57 // -----------------------------------------------------------------------------
60 // -----------------------------------------------------------------------------
61 namespace uno
= ::com::sun::star::uno
;
62 namespace backenduno
= ::com::sun::star::configuration::backend
;
63 // -----------------------------------------------------------------------------
66 class NodeModification
;
73 // -----------------------------------------------------------------------------
75 class NamedUpdate
: public salhelper::SimpleReferenceObject
77 rtl::OUString
const m_aName
;
81 NamedUpdate(rtl::OUString
const & _aName
)
88 rtl::OUString
const & getName() const { return m_aName
; }
90 // -----------------------------------------------------------------------------
91 class ElementUpdate
: public NamedUpdate
93 NodeUpdate
* m_pParent
;
95 sal_Int16 m_nFlagsMask
;
97 ElementUpdate(NodeUpdate
* _pParent
, rtl::OUString
const & _aName
, sal_Int16 _nFlags
, sal_Int16 _nFlagsMask
);
100 virtual NodeUpdate
* asNodeUpdate(bool _bMerged
= false);
101 virtual PropertyUpdate
* asPropertyUpdate();
103 virtual void writeToLayer(backenduno::XLayerHandler
* _pLayer
) = 0;
106 NodeUpdate
* getParent() const { return m_pParent
; }
108 sal_Int16
changedFlags() const { return m_nFlagsMask
; }
109 sal_Int16
updateFlags(sal_Int16 _nFlags
= 0) const;
112 // -----------------------------------------------------------------------------
114 class NodeUpdate
: public ElementUpdate
116 typedef std::map
< rtl::OUString
, rtl::Reference
<ElementUpdate
> > ElementList
;
118 enum Op
{ modify
, reset
, replace
};
121 NodeUpdate(NodeUpdate
* _pParent
, rtl::OUString
const & _aName
, sal_Int16 _nFlags
, sal_Int16 _nFlagsMask
, Op _op
);
123 virtual NodeUpdate
* asNodeUpdate(bool _bMerged
);
126 bool addNodeUpdate (rtl::Reference
<ElementUpdate
> const & _aNode
);
127 bool addPropertyUpdate (rtl::Reference
<ElementUpdate
> const & _aProp
);
128 void removeNodeByName (rtl::OUString
const & _aName
);
129 void removePropertyByName (rtl::OUString
const & _aName
);
131 Op
getOperation() const { return m_op
; }
133 rtl::Reference
<ElementUpdate
> getNodeByName (rtl::OUString
const & _aName
) const;
134 rtl::Reference
<ElementUpdate
> getPropertyByName (rtl::OUString
const & _aName
) const;
136 ElementList::const_iterator
beginNodes() const { return m_aNodes
.begin(); }
137 ElementList::const_iterator
endNodes() const { return m_aNodes
.end(); };
138 ElementList::const_iterator
beginProperties() const { return m_aProperties
.begin(); };
139 ElementList::const_iterator
endProperties() const { return m_aProperties
.end(); };
141 bool hasChildren() const { return !m_aNodes
.empty() || !m_aProperties
.empty(); }
143 void writeChildrenToLayer(backenduno::XLayerHandler
* _pLayer
);
145 ElementList m_aNodes
;
146 ElementList m_aProperties
;
147 ElementList m_aRemovedElements
;
150 // -----------------------------------------------------------------------------
152 class NodeModification
: public NodeUpdate
155 NodeModification(NodeUpdate
* _pParent
, rtl::OUString
const & _aName
, sal_Int16 _nFlags
, sal_Int16 _nFlagsMask
, sal_Bool _bReset
);
156 virtual void writeToLayer(backenduno::XLayerHandler
* _pLayer
);
158 // -----------------------------------------------------------------------------
160 class NodeReplace
: public NodeUpdate
163 NodeReplace(NodeUpdate
* _pParent
, rtl::OUString
const & _aName
, sal_Int16 _nFlags
);
164 NodeReplace(NodeUpdate
* _pParent
, rtl::OUString
const & _aName
, sal_Int16 _nFlags
, rtl::OUString
const & _aTemplateName
, rtl::OUString
const & _aTemplateComponent
);
166 bool hasTemplate() const;
167 rtl::OUString
getTemplateName() const { return m_aTemplateName
; }
168 rtl::OUString
getTemplateComponent() const { return m_aTemplateComponent
; }
170 virtual void writeToLayer(backenduno::XLayerHandler
* _pLayer
);
172 rtl::OUString m_aTemplateName
;
173 rtl::OUString m_aTemplateComponent
;
175 // -----------------------------------------------------------------------------
177 class NodeDrop
: public ElementUpdate
180 NodeDrop(NodeUpdate
* _pParent
, rtl::OUString
const & _aName
);
182 virtual void writeToLayer(backenduno::XLayerHandler
* _pLayer
);
184 // -----------------------------------------------------------------------------
186 class PropertyUpdate
: public ElementUpdate
188 typedef std::map
< rtl::OUString
, uno::Any
> ValueList
;
193 PropertyUpdate(NodeUpdate
* _pParent
, rtl::OUString
const & _aName
, sal_Int16 _nFlags
, sal_Int16 _nFlagsMask
, uno::Type
const & _aType
);
195 bool setValueFor(rtl::OUString
const & _aLocale
, uno::Any
const & _aValueUpdate
);
196 bool resetValueFor(rtl::OUString
const & _aLocale
);
197 void removeValueFor(rtl::OUString
const & _aLocale
);
199 bool setValue(uno::Any
const & _aValueUpdate
) { return setValueFor(primarySlot(), _aValueUpdate
); }
200 bool resetValue() { return resetValueFor(primarySlot()); }
201 void removeValue() { removeValueFor(primarySlot()); }
205 uno::Type
const & getValueType() const { return m_aType
; }
207 bool hasValueFor(rtl::OUString
const & _aLocale
) const;
208 bool hasValue() const { return hasValueFor(primarySlot()); }
210 bool hasResetFor(rtl::OUString
const & _aLocale
) const;
211 bool hasReset() const { return hasResetFor(primarySlot()); }
213 bool hasChangeFor(rtl::OUString
const & _aLocale
) const;
214 bool hasChange() const { return hasChangeFor(primarySlot()); }
216 uno::Any
getValueFor(rtl::OUString
const & _aLocale
) const;
217 uno::Any
getValue() const { return getValueFor(primarySlot()); }
219 ValueList::const_iterator
beginValues() const { return m_aValues
.begin(); }
220 ValueList::const_iterator
endValues() const { return m_aValues
.end(); }
222 void writeValueToLayerFor(backenduno::XLayerHandler
* _pLayer
, uno::Any
const & _aValue
, rtl::OUString
const & _aLocale
);
223 void writeValueToLayer(backenduno::XLayerHandler
* _pLayer
, uno::Any
const & _aValue
);
224 void writeValuesToLayer(backenduno::XLayerHandler
* _pLayer
);
225 virtual void writeToLayer(backenduno::XLayerHandler
* _pLayer
);
227 rtl::OUString
primarySlot() const { return rtl::OUString(); }
229 static uno::Any
const & getResetMarker();
230 static inline bool isResetMarker(uno::Any
const & _aValue
);
232 virtual PropertyUpdate
* asPropertyUpdate();
234 // -----------------------------------------------------------------------------
236 class PropertyAdd
: public ElementUpdate
238 uno::Type m_aValueType
;
241 PropertyAdd(NodeUpdate
* _pParent
, rtl::OUString
const & _aName
, sal_Int16 _nFlags
, uno::Type
const & _aType
);
242 PropertyAdd(NodeUpdate
* _pParent
, rtl::OUString
const & _aName
, sal_Int16 _nFlags
, uno::Any
const & _aValue
);
244 bool hasValue() const { return !! m_aValue
.hasValue(); }
245 uno::Any
const & getValue() const { return m_aValue
; }
246 uno::Type
const & getValueType() const { return m_aValueType
; }
248 virtual void writeToLayer(backenduno::XLayerHandler
* _pLayer
);
250 // -----------------------------------------------------------------------------
252 class PropertyReset
: public ElementUpdate
255 PropertyReset(NodeUpdate
* _pParent
, rtl::OUString
const & _aName
);
257 virtual void writeToLayer(backenduno::XLayerHandler
* _pLayer
);
259 // -----------------------------------------------------------------------------
261 } // namespace backend
262 // -----------------------------------------------------------------------------
264 } // namespace configmgr