update dev300-m58
[ooovba.git] / configmgr / source / treemgr / nodechangeinfo.cxx
blob9a6a0c21c6667c147fb39c919e22bf66164b3ca7
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: nodechangeinfo.cxx,v $
10 * $Revision: 1.12 $
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"
37 #include "tree.hxx"
39 namespace configmgr
41 namespace configuration
43 //-----------------------------------------------------------------------------
45 NodeChangeData::NodeChangeData()
46 : type(eNoChange)
47 , unoData()
48 , element()
51 //-----------------------------------------------------------------------------
53 NodeChangeData::NodeChangeData(NodeChangeData const& aOther)
54 : type(aOther.type)
55 , unoData(aOther.unoData)
56 , element(aOther.element)
59 //-----------------------------------------------------------------------------
61 NodeChangeData& NodeChangeData::operator=(NodeChangeData const& aOther)
63 type = aOther.type;
64 unoData = aOther.unoData;
65 element = aOther.element;
66 return *this;
68 //-----------------------------------------------------------------------------
70 NodeChangeData::~NodeChangeData()
73 //-----------------------------------------------------------------------------
75 bool NodeChangeData::isDataChange() const
77 if (isSetChange() && element.isDataChange())
78 return true;
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 );
103 else
104 return NodeID(0,0);
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 );
115 else
116 return NodeID(0,0);
118 //-----------------------------------------------------------------------------
120 NodeChangeLocation::NodeChangeLocation()
121 : m_path()
122 , m_base(0,0)
123 , m_affected(0,0)
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()
137 ) ) ) );
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() )
148 ) );
150 #endif
151 //-----------------------------------------------------------------------------
153 void NodeChangeLocation::setAccessor(RelativePath const& aAccessor)
155 m_path = aAccessor;
157 //-----------------------------------------------------------------------------
159 void NodeChangeLocation::setBase(NodeID const& aBaseNode)
161 m_base = 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");
206 return m_affected;
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() );
219 return aResult;
221 //-----------------------------------------------------------------------------