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: nodechangeinfo.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 "nodechangeinfo.hxx"
36 #include "noderef.hxx"
41 namespace configuration
43 //-----------------------------------------------------------------------------
45 NodeChangeData::NodeChangeData()
51 //-----------------------------------------------------------------------------
53 NodeChangeData::NodeChangeData(NodeChangeData
const& aOther
)
55 , unoData(aOther
.unoData
)
56 , element(aOther
.element
)
59 //-----------------------------------------------------------------------------
61 NodeChangeData
& NodeChangeData::operator=(NodeChangeData
const& aOther
)
64 unoData
= aOther
.unoData
;
65 element
= aOther
.element
;
68 //-----------------------------------------------------------------------------
70 NodeChangeData::~NodeChangeData()
73 //-----------------------------------------------------------------------------
75 bool NodeChangeData::isDataChange() const
77 if (isSetChange() && element
.isDataChange())
80 return unoData
.isDataChange();
82 //-----------------------------------------------------------------------------
84 rtl::Reference
< Tree
> NodeChangeData::getNewElementTree() const
86 return element
.newValue
.get();
88 //-----------------------------------------------------------------------------
90 rtl::Reference
< Tree
> NodeChangeData::getOldElementTree() const
92 return element
.oldValue
.get();
94 //-----------------------------------------------------------------------------
96 NodeID
NodeChangeData::getNewElementNodeID() const
98 rtl::Reference
<ElementTree
> newElement
= this->element
.newValue
;
99 if ( newElement
.is() && newElement
->nodeCount() > 0)
101 return NodeID( newElement
.get(), Tree::ROOT
);
106 //-----------------------------------------------------------------------------
108 NodeID
NodeChangeData::getOldElementNodeID() const
110 rtl::Reference
<ElementTree
> oldElement
= this->element
.oldValue
;
111 if ( oldElement
.is() && oldElement
->nodeCount() > 0)
113 return NodeID( oldElement
.get(), Tree::ROOT
);
118 //-----------------------------------------------------------------------------
120 NodeChangeLocation::NodeChangeLocation()
124 , m_bSubNodeChanging(false)
127 //-----------------------------------------------------------------------------
128 bool NodeChangeLocation::isValidLocation() const
130 return m_base
.isValidNode() &&
131 (m_affected
.isEmpty()
132 ? ! m_bSubNodeChanging
133 : ( m_affected
.isValidNode() &&
134 (! m_bSubNodeChanging
||
135 (!m_path
.isEmpty() &&
136 SubNodeID(m_affected
,m_path
.getLocalName().getName()).isValidNode()
139 #if OSL_DEBUG_LEVEL > 0
140 //-----------------------------------------------------------------------------
141 bool NodeChangeLocation::isValidData() const
143 return m_base
.isValidNode() &&
144 (m_affected
.isEmpty()
145 ? ! m_bSubNodeChanging
146 : ( m_affected
.isValidNode() &&
147 (! m_bSubNodeChanging
|| !m_path
.isEmpty() )
151 //-----------------------------------------------------------------------------
153 void NodeChangeLocation::setAccessor(RelativePath
const& aAccessor
)
157 //-----------------------------------------------------------------------------
159 void NodeChangeLocation::setBase(NodeID
const& aBaseNode
)
163 //-----------------------------------------------------------------------------
165 void NodeChangeLocation::setAffected(NodeID
const& aTargetNode
)
167 m_affected
= aTargetNode
;
169 if (m_base
.isEmpty())
170 setBase(aTargetNode
);
172 //-----------------------------------------------------------------------------
174 void NodeChangeLocation::setChangingSubnode( bool bSubnode
)
176 OSL_ENSURE(!m_affected
.isEmpty() || !bSubnode
, "Change without target cannot affect subnode");
178 m_bSubNodeChanging
= bSubnode
;
180 //-----------------------------------------------------------------------------
182 rtl::Reference
< Tree
> NodeChangeLocation::getBaseTree() const
184 OSL_ENSURE(m_base
.isValidNode(), "Invalid base location set in NodeChangeLocation");
185 return m_base
.getTree();
187 //-----------------------------------------------------------------------------
189 NodeRef
NodeChangeLocation::getBaseNode() const
191 OSL_ENSURE(m_base
.isValidNode(), "Invalid base location set in NodeChangeLocation");
192 return m_base
.getNode();
194 //-----------------------------------------------------------------------------
196 rtl::Reference
< Tree
> NodeChangeLocation::getAffectedTreeRef() const
198 NodeID aAffected
= this->getAffectedNodeID();
199 return aAffected
.getTree();
201 //-----------------------------------------------------------------------------
203 NodeID
NodeChangeLocation::getAffectedNodeID() const
205 OSL_ENSURE(m_affected
.isEmpty() || m_affected
.isValidNode(), "Invalid target location set in NodeChangeLocation");
208 //-----------------------------------------------------------------------------
210 SubNodeID
NodeChangeLocation::getChangingValueID() const
212 if (!m_bSubNodeChanging
) return SubNodeID::createEmpty();
214 OSL_ENSURE(!m_affected
.isEmpty() && m_affected
.isValidNode(), "Invalid target location set in NodeChangeLocation with subnode");
215 OSL_ENSURE(!m_path
.isEmpty(), "No target accessor set in NodeChangeLocation with subnode");
217 SubNodeID
aResult( m_affected
, m_path
.getLocalName().getName() );
221 //-----------------------------------------------------------------------------