merge the formfield patch from ooo-build
[ooovba.git] / configmgr / source / backend / mergedcomponentdata.cxx
blobbc3604fd0f24e3a252f1e2cbaec39d25a6013006
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: mergedcomponentdata.cxx,v $
10 * $Revision: 1.8 $
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 "mergedcomponentdata.hxx"
35 #include "treenodefactory.hxx"
37 namespace configmgr
39 // -----------------------------------------------------------------------------
40 namespace backend
42 // -----------------------------------------------------------------------------
44 MergedComponentData::MergedComponentData( )
45 : m_pSchemaTree()
46 , m_pTemplatesTree()
50 // -----------------------------------------------------------------------------
52 MergedComponentData::~MergedComponentData( )
56 // -----------------------------------------------------------------------------
58 void MergedComponentData::clear( )
60 m_pTemplatesTree.reset();
61 m_pSchemaTree.reset();
63 // -----------------------------------------------------------------------------
65 bool MergedComponentData::hasSchema()const
67 return m_pSchemaTree.get() != NULL;
69 // -----------------------------------------------------------------------------
72 bool MergedComponentData::hasTemplates() const
74 return m_pTemplatesTree.get() != NULL;
76 // -----------------------------------------------------------------------------
78 rtl::OUString MergedComponentData::getTemplateAccessor (backenduno::TemplateIdentifier const & _aTemplateName) const
80 return _aTemplateName.Name;
82 // -----------------------------------------------------------------------------
84 bool MergedComponentData::hasTemplate(rtl::OUString const & _aTemplateName) const
86 return m_pTemplatesTree.get() != NULL &&
87 m_pTemplatesTree->getChild( _aTemplateName ) != NULL;
89 // -----------------------------------------------------------------------------
91 std::auto_ptr<ISubtree> MergedComponentData::extractSchemaTree()
93 return m_pSchemaTree;
95 // -----------------------------------------------------------------------------
97 std::auto_ptr<ISubtree> MergedComponentData::extractTemplatesTree()
99 return m_pTemplatesTree;
101 // -----------------------------------------------------------------------------
103 std::auto_ptr<INode> MergedComponentData::extractTemplateNode(rtl::OUString const & _aTemplateName)
105 if (m_pTemplatesTree.get() == NULL)
106 return std::auto_ptr<INode>();
108 return m_pTemplatesTree->removeChild(_aTemplateName);
110 // -----------------------------------------------------------------------------
112 ISubtree const * MergedComponentData::findTemplate(rtl::OUString const & _aTemplateName) const
114 INode const * pTemplateNode = m_pTemplatesTree->getChild(_aTemplateName);
116 ISubtree const * pTemplateTree = pTemplateNode ? pTemplateNode->asISubtree() : NULL;
118 OSL_ENSURE(pTemplateTree || !pTemplateNode, "ERROR: Template is not a subtree");
120 return pTemplateTree;
122 // -----------------------------------------------------------------------------
124 std::auto_ptr<INode> MergedComponentData::instantiateTemplate(rtl::OUString const & _aName, rtl::OUString const & _aTemplateName) const
126 if (INode const * pTemplateNode = m_pTemplatesTree->getChild(_aTemplateName))
128 std::auto_ptr<INode> aResult = pTemplateNode->clone();
129 aResult->setName(_aName);
130 return aResult;
132 else
134 return std::auto_ptr<INode>();
137 // -----------------------------------------------------------------------------
139 ISubtree * MergedComponentData::setSchemaRoot(std::auto_ptr<ISubtree> _aSchemaRoot)
141 OSL_PRECOND(_aSchemaRoot.get(),"ERROR: Setting a NULL schema root.");
142 OSL_PRECOND(!hasSchema(),"ERROR: Schema root already set");
144 m_pSchemaTree = _aSchemaRoot;
146 return m_pSchemaTree.get();
148 // -----------------------------------------------------------------------------
149 void MergedComponentData::setTemplatesTree(std::auto_ptr<ISubtree> _aTemplateTree)
151 OSL_PRECOND(!hasTemplates(),"ERROR: Template Tree already set");
152 m_pTemplatesTree = _aTemplateTree;
154 // -----------------------------------------------------------------------------
155 ISubtree * MergedComponentData::addTemplate(std::auto_ptr<ISubtree> _aNode, backenduno::TemplateIdentifier const & aTemplate)
157 OSL_PRECOND(_aNode.get(), "ERROR: Adding a NULL template");
159 if (!m_pTemplatesTree.get())
161 m_pTemplatesTree = getDefaultTreeNodeFactory().createGroupNode( aTemplate.Component, node::Attributes() );
163 else
165 OSL_ENSURE(m_pTemplatesTree->getName().equals(aTemplate.Component),
166 "Template Component names do not match");
169 return m_pTemplatesTree->addChild( base_ptr(_aNode) )->asISubtree();
171 // -----------------------------------------------------------------------------
172 // -----------------------------------------------------------------------------
173 } // namespace backend
175 // -------------------------------------------------------------------------
176 } // namespace configmgr