merge the formfield patch from ooo-build
[ooovba.git] / configmgr / source / api2 / apinodeaccess.cxx
blobc5f9cd07170494447d7dafea32a7efa8fc1ba48b
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: apinodeaccess.cxx,v $
10 * $Revision: 1.16 $
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"
33 #include <stdio.h>
34 #include "apinodeaccess.hxx"
36 #include "apitreeimplobj.hxx"
37 #include "apifactory.hxx"
39 #include "apitreeaccess.hxx"
40 #include "noderef.hxx"
42 #include "anynoderef.hxx"
43 #include "valueref.hxx"
45 #include "configset.hxx"
46 #include "configpath.hxx"
47 #include "confignotifier.hxx"
49 namespace configmgr
51 namespace configapi
53 //-----------------------------------------------------------------------------
55 NodeAccess::~NodeAccess()
58 //-----------------------------------------------------------------------------
60 configuration::NodeRef NodeAccess::getNodeRef() const
62 return doGetNode();
64 //-----------------------------------------------------------------------------
66 rtl::Reference< configuration::Tree > NodeAccess::getTreeRef() const
68 return getApiTree().getTree();
70 //-----------------------------------------------------------------------------
72 rtl::Reference< configuration::Tree > NodeAccess::getTree() const
74 return getApiTree().getTree();
76 //-----------------------------------------------------------------------------
78 void NodeAccess::checkAlive() const
80 getApiTree().checkAlive();
82 //-----------------------------------------------------------------------------
84 void NodeAccess::disposeNode()
86 getApiTree().disposeNode(getNodeRef(), getUnoInstance());
88 //-----------------------------------------------------------------------------
91 Factory& NodeAccess::getFactory() const
93 return getApiTree().getFactory();
95 //-----------------------------------------------------------------------------
97 Notifier NodeAccess::getNotifier() const
99 return getApiTree().getNotifier();
102 //-----------------------------------------------------------------------------
104 uno::Any makeElement(configapi::Factory& rFactory, rtl::Reference< configuration::Tree > const& aTree, configuration::AnyNodeRef const& aNode)
106 if (!configuration::isEmpty(aTree.get()) && aNode.isValid())
108 if (aNode.isNode())
110 configuration::NodeRef aInnerNode = aNode.toNode();
112 if (configuration::isStructuralNode(aTree,aInnerNode))
113 return uno::makeAny( rFactory.makeUnoElement(aTree,aInnerNode) );
115 else
116 return configuration::getSimpleElementValue(aTree,aInnerNode);
118 else
120 return configuration::getSimpleValue(aTree,aNode.toValue());
124 return uno::Any();
126 //-----------------------------------------------------------------------------
128 uno::Any makeInnerElement(configapi::Factory& rFactory, rtl::Reference< configuration::Tree > const& aTree, configuration::NodeRef const& aNode)
130 if (!configuration::isEmpty(aTree.get()) && aNode.isValid())
132 OSL_ENSURE(configuration::isStructuralNode(aTree,aNode), "Trying to makeInnerElement for a simple value");
134 return uno::makeAny( rFactory.makeUnoElement(aTree,aNode) );
137 return uno::Any();
139 //-----------------------------------------------------------------------------
141 uno::Any makeElement(configapi::Factory& rFactory, rtl::Reference< configuration::ElementTree > const& aTree)
143 if (aTree.is())
145 return uno::makeAny( rFactory.makeUnoSetElement(aTree) );
148 return uno::Any();
150 //-----------------------------------------------------------------------------
152 rtl::Reference< configuration::ElementTree > extractElementTree(configapi::Factory& rFactory, uno::Any const& aElement, rtl::Reference< configuration::Template > const& aTemplate )
154 OSL_ENSURE(aTemplate.is(), "ERROR: Need a template to extract a matching set element");
156 if (SetElement* pSetElement = rFactory.extractSetElement(aElement))
158 rtl::Reference<configuration::Template> aFoundTemplate = pSetElement->getTemplateInfo();
159 if (aFoundTemplate.is())
161 if (aFoundTemplate != aTemplate)
162 throw configuration::TypeMismatch(aFoundTemplate->getPathString(), aTemplate->getPathString());
164 return pSetElement->getElementRef( );
167 return rtl::Reference< configuration::ElementTree >();
169 //-----------------------------------------------------------------------------
171 rtl::Reference< configuration::Template > NodeSetInfoAccess::getElementInfo() const
173 rtl::Reference<configuration::Template> aTemplate = getTree()->extractElementInfo(getNodeRef());
175 OSL_ENSURE(aTemplate.is(), "ERROR: Set must have an element template");
177 return aTemplate;