/************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * Copyright 2008 by Sun Microsystems, Inc. * * OpenOffice.org - a multi-platform office productivity suite * * $RCSfile: treeimpl.cxx,v $ * $Revision: 1.33 $ * * This file is part of OpenOffice.org. * * OpenOffice.org is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License version 3 * only, as published by the Free Software Foundation. * * OpenOffice.org is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License version 3 for more details * (a copy is included in the LICENSE file that accompanied this code). * * You should have received a copy of the GNU Lesser General Public License * version 3 along with OpenOffice.org. If not, see * * for a copy of the LGPLv3 License. * ************************************************************************/ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_configmgr.hxx" #include #include "anynoderef.hxx" #include "builddata.hxx" #include "configset.hxx" #include "tracer.hxx" #include "tree.hxx" #include "roottreeimpl.hxx" #include "nodeimpl.hxx" #include "nodechange.hxx" #include "nodechangeimpl.hxx" #include "noderef.hxx" #include "template.hxx" #include "nodevisitor.hxx" #include "valueref.hxx" #include "valuenode.hxx" #include "change.hxx" #include "valuenodeimpl.hxx" #include "setnodeimpl.hxx" #include "groupnodeimpl.hxx" #include "viewaccess.hxx" #include "viewfactory.hxx" #include "nodefactory.hxx" #include namespace configmgr { //----------------------------------------------------------------------------- namespace configuration { //----------------------------------------------------------------------------- // class TreeImplBuilder - friend of Tree //----------------------------------------------------------------------------- /** is a visitor-style algorithm to construct a Tree::NodeList representing a configuration hierarchy */ class TreeImplBuilder : public data::NodeVisitor { public: /** constructs a TreeImplBuilder to append onto rList the products of rFactory up to depth nDepth */ TreeImplBuilder( TemplateProvider const& aTemplateProvider, rtl::Reference const& _xStrategy, Tree& rTree ) : m_xStrategy(_xStrategy) , m_aTemplateProvider(aTemplateProvider) , m_rFactory(_xStrategy->getNodeFactory()) , m_rTree(rTree) , m_nParent(0) , m_nDepthLeft(rTree.m_nDepth) { OSL_ASSERT(m_rTree.m_aNodes.empty()); OSL_DEBUG_ONLY(m_bMemberCheck = false); m_rTree.m_xStrategy = _xStrategy; } private: using NodeVisitor::handle; virtual bool handle(sharable::ValueNode * node); virtual bool handle(sharable::GroupNode * node); virtual bool handle(sharable::SetNode * node); /// add a Node for group node _aGroup to the list void addGroup(sharable::GroupNode * group); /// add a Node for set node _aSet to the list void addSet(sharable::SetNode * set); /// add a Node for value node rValue to the list void addValueElement(sharable::ValueNode * value); /// add a Member for value node rValue to the list void addValueMember(sharable::ValueNode * value); rtl::Reference m_xStrategy; TemplateProvider m_aTemplateProvider; view::NodeFactory& m_rFactory; Tree& m_rTree; unsigned int m_nParent; unsigned int m_nDepthLeft; #if OSL_DEBUG_LEVEL > 0 bool m_bMemberCheck; #endif }; //----------------------------------------------------------------------------- bool TreeImplBuilder::handle(sharable::ValueNode * node) { if (m_nParent == 0) addValueElement(node); // if it is the root it is a value set element else addValueMember(node); // if it is not the root it is a group member return false; } //----------------------------------------------------------------------------- bool TreeImplBuilder::handle(sharable::GroupNode * node) { addGroup(node); return false; } //----------------------------------------------------------------------------- bool TreeImplBuilder::handle(sharable::SetNode * node) { addSet(node); return false; } //----------------------------------------------------------------------------- void TreeImplBuilder::addValueElement(sharable::ValueNode * value) { rtl::Reference aValueNode( m_rFactory.makeValueNode(value) ); OSL_ENSURE( aValueNode.is(), "could not make value node wrapper" ); OSL_ENSURE( m_nParent == 0, "Adding value element that is not root of its fragment" ); // TODO:!isValid() => maybe substitute a SimpleValueNodeImpl if possible if( aValueNode.is() ) { m_rTree.m_aNodes.push_back( NodeData(aValueNode, value->info.getName(), m_nParent) ); } } //----------------------------------------------------------------------------- void TreeImplBuilder::addValueMember(sharable::ValueNode *) { // nothing to do OSL_DEBUG_ONLY(m_bMemberCheck = true); } //----------------------------------------------------------------------------- void TreeImplBuilder::addGroup(sharable::GroupNode * group) { rtl::Reference aGroupNode( m_rFactory.makeGroupNode(group) ); OSL_ENSURE( aGroupNode.is(), "could not make group node wrapper" ); // TODO:!isValid() => maybe substitute a SimpleValueNodeImpl if possible if( aGroupNode.is() ) { m_rTree.m_aNodes.push_back( NodeData(aGroupNode,group->info.getName(),m_nParent) ); // now fill in group members if (m_nDepthLeft > 0) { unsigned int nSaveParent = m_nParent; decDepth(m_nDepthLeft); m_nParent = m_rTree.m_aNodes.size() + Tree::ROOT - 1; #if OSL_DEBUG_LEVEL > 0 bool bSaveMemberCheck = m_bMemberCheck; m_bMemberCheck = false; #endif // now recurse: this->visitChildren(group); OSL_ENSURE(m_nParent < m_rTree.m_aNodes.size() || m_bMemberCheck, "WARNING: Configuration: Group within requested depth has no members"); OSL_DEBUG_ONLY(m_bMemberCheck = bSaveMemberCheck); incDepth(m_nDepthLeft); m_nParent = nSaveParent; } } } //----------------------------------------------------------------------------- void TreeImplBuilder::addSet(sharable::SetNode * set) { rtl::Reference