2000-11-07 07:40:31 -06:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-11 05:48:07 -05:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2000-11-07 07:40:31 -06:00
|
|
|
*
|
2008-04-11 05:48:07 -05:00
|
|
|
* Copyright 2008 by Sun Microsystems, Inc.
|
2000-11-07 07:40:31 -06:00
|
|
|
*
|
2008-04-11 05:48:07 -05:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-11-07 07:40:31 -06:00
|
|
|
*
|
2008-04-11 05:48:07 -05:00
|
|
|
* $RCSfile: apinodeaccess.cxx,v $
|
|
|
|
* $Revision: 1.15 $
|
2000-11-07 07:40:31 -06:00
|
|
|
*
|
2008-04-11 05:48:07 -05:00
|
|
|
* This file is part of OpenOffice.org.
|
2000-11-07 07:40:31 -06:00
|
|
|
*
|
2008-04-11 05:48:07 -05:00
|
|
|
* 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.
|
2000-11-07 07:40:31 -06:00
|
|
|
*
|
2008-04-11 05:48:07 -05:00
|
|
|
* 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).
|
2000-11-07 07:40:31 -06:00
|
|
|
*
|
2008-04-11 05:48:07 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2000-11-07 07:40:31 -06:00
|
|
|
*
|
|
|
|
************************************************************************/
|
2006-09-16 08:54:31 -05:00
|
|
|
|
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_configmgr.hxx"
|
2000-11-13 05:14:15 -06:00
|
|
|
#include <stdio.h>
|
2000-11-07 07:40:31 -06:00
|
|
|
#include "apinodeaccess.hxx"
|
|
|
|
|
|
|
|
#include "apitreeimplobj.hxx"
|
|
|
|
#include "apifactory.hxx"
|
|
|
|
|
|
|
|
#include "apitreeaccess.hxx"
|
|
|
|
#include "noderef.hxx"
|
2003-10-06 10:09:59 -05:00
|
|
|
|
2001-06-20 14:28:26 -05:00
|
|
|
#include "anynoderef.hxx"
|
|
|
|
#include "valueref.hxx"
|
|
|
|
|
2000-11-07 07:40:31 -06:00
|
|
|
#include "configset.hxx"
|
|
|
|
#include "configpath.hxx"
|
|
|
|
#include "confignotifier.hxx"
|
|
|
|
|
|
|
|
namespace configmgr
|
|
|
|
{
|
|
|
|
namespace configapi
|
|
|
|
{
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
NodeAccess::~NodeAccess()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2002-02-11 06:47:56 -06:00
|
|
|
configuration::NodeRef NodeAccess::getNodeRef() const
|
2000-11-07 07:40:31 -06:00
|
|
|
{
|
|
|
|
return doGetNode();
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2002-02-11 06:47:56 -06:00
|
|
|
configuration::TreeRef NodeAccess::getTreeRef() const
|
2000-11-07 07:40:31 -06:00
|
|
|
{
|
|
|
|
return getApiTree().getTree();
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2007-11-23 07:02:55 -06:00
|
|
|
configuration::Tree NodeAccess::getTree() const
|
2002-02-11 06:47:56 -06:00
|
|
|
{
|
2007-11-23 07:02:55 -06:00
|
|
|
return configuration::Tree(getApiTree().getTree());
|
2002-02-11 06:47:56 -06:00
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2000-11-07 07:40:31 -06:00
|
|
|
void NodeAccess::checkAlive() const
|
|
|
|
{
|
|
|
|
getApiTree().checkAlive();
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void NodeAccess::disposeNode()
|
|
|
|
{
|
2002-02-11 06:47:56 -06:00
|
|
|
getApiTree().disposeNode(getNodeRef(), getUnoInstance());
|
2000-11-07 07:40:31 -06:00
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
Factory& NodeAccess::getFactory() const
|
|
|
|
{
|
|
|
|
return getApiTree().getFactory();
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
Notifier NodeAccess::getNotifier() const
|
|
|
|
{
|
|
|
|
return getApiTree().getNotifier();
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2001-06-20 14:28:26 -05:00
|
|
|
UnoAny makeElement(configapi::Factory& rFactory, configuration::Tree const& aTree, configuration::AnyNodeRef const& aNode)
|
2000-11-07 07:40:31 -06:00
|
|
|
{
|
|
|
|
if (!aTree.isEmpty() && aNode.isValid())
|
|
|
|
{
|
2001-06-20 14:28:26 -05:00
|
|
|
if (aNode.isNode())
|
2000-11-07 07:40:31 -06:00
|
|
|
{
|
2001-06-20 14:28:26 -05:00
|
|
|
NodeRef aInnerNode = aNode.toNode();
|
|
|
|
|
|
|
|
if (configuration::isStructuralNode(aTree,aInnerNode))
|
|
|
|
return uno::makeAny( rFactory.makeUnoElement(aTree,aInnerNode) );
|
|
|
|
|
|
|
|
else
|
|
|
|
return configuration::getSimpleElementValue(aTree,aInnerNode);
|
2000-11-07 07:40:31 -06:00
|
|
|
}
|
2001-06-20 14:28:26 -05:00
|
|
|
else
|
2000-11-07 07:40:31 -06:00
|
|
|
{
|
2001-06-20 14:28:26 -05:00
|
|
|
return configuration::getSimpleValue(aTree,aNode.toValue());
|
2000-11-07 07:40:31 -06:00
|
|
|
}
|
|
|
|
}
|
2001-06-20 14:28:26 -05:00
|
|
|
|
|
|
|
return UnoAny();
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
UnoAny makeInnerElement(configapi::Factory& rFactory, configuration::Tree const& aTree, configuration::NodeRef const& aNode)
|
|
|
|
{
|
|
|
|
if (!aTree.isEmpty() && aNode.isValid())
|
|
|
|
{
|
|
|
|
OSL_ENSURE(configuration::isStructuralNode(aTree,aNode), "Trying to makeInnerElement for a simple value");
|
|
|
|
|
|
|
|
return uno::makeAny( rFactory.makeUnoElement(aTree,aNode) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return UnoAny();
|
2000-11-07 07:40:31 -06:00
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
UnoAny makeElement(configapi::Factory& rFactory, configuration::ElementTree const& aTree)
|
|
|
|
{
|
|
|
|
if (aTree.isValid())
|
|
|
|
{
|
2001-06-20 14:28:26 -05:00
|
|
|
return uno::makeAny( rFactory.makeUnoSetElement(aTree) );
|
2000-11-07 07:40:31 -06:00
|
|
|
}
|
2001-06-20 14:28:26 -05:00
|
|
|
|
|
|
|
return UnoAny();
|
2000-11-07 07:40:31 -06:00
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2002-02-11 06:47:56 -06:00
|
|
|
configuration::ElementRef extractElementRef(configapi::Factory& rFactory, UnoAny const& aElement, configuration::TemplateInfo const& aTemplateInfo )
|
2000-11-07 07:40:31 -06:00
|
|
|
{
|
2002-02-11 06:47:56 -06:00
|
|
|
using configuration::ElementRef;
|
|
|
|
configuration::TemplateHolder const aRequestedTemplate = aTemplateInfo.getTemplate();
|
|
|
|
OSL_ENSURE(aRequestedTemplate.is(), "ERROR: Need a template to extract a matching set element");
|
|
|
|
if (!aRequestedTemplate.is())
|
|
|
|
return ElementRef(NULL);
|
2000-11-07 07:40:31 -06:00
|
|
|
|
|
|
|
if (SetElement* pSetElement = rFactory.extractSetElement(aElement))
|
|
|
|
{
|
|
|
|
configuration::TemplateHolder aFoundTemplate = pSetElement->getTemplateInfo().getTemplate();
|
2002-02-11 06:47:56 -06:00
|
|
|
if (aFoundTemplate.is())
|
|
|
|
{
|
|
|
|
if (aFoundTemplate != aRequestedTemplate)
|
|
|
|
throw configuration::TypeMismatch(aFoundTemplate->getPathString(), aRequestedTemplate->getPathString());
|
2000-11-07 07:40:31 -06:00
|
|
|
|
2002-02-11 06:47:56 -06:00
|
|
|
return pSetElement->getElementRef( );
|
|
|
|
}
|
2000-11-07 07:40:31 -06:00
|
|
|
}
|
2002-02-11 06:47:56 -06:00
|
|
|
return ElementRef(NULL);
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
configuration::ElementTree extractElementTree(configapi::Factory& rFactory, UnoAny const& aElement, configuration::SetElementInfo const& aElementInfo )
|
|
|
|
{
|
|
|
|
using namespace configuration;
|
|
|
|
ElementRef aExtractedRef = extractElementRef(rFactory,aElement,aElementInfo.getTemplateInfo());
|
2007-11-23 07:02:55 -06:00
|
|
|
return aExtractedRef.getElementTree();
|
2000-11-07 07:40:31 -06:00
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2002-02-11 06:47:56 -06:00
|
|
|
SetElement* findSetElement(Factory& rFactory, configuration::ElementRef const& aElementTree)
|
2000-11-10 05:22:55 -06:00
|
|
|
{
|
|
|
|
SetElement* pSetElement = rFactory.findSetElement(aElementTree);
|
|
|
|
if (pSetElement)
|
|
|
|
{
|
|
|
|
// the factory always does an extra acquire
|
|
|
|
pSetElement->getUnoInstance()->release();
|
|
|
|
}
|
|
|
|
return pSetElement;
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
2000-11-07 07:40:31 -06:00
|
|
|
|
2007-11-23 07:02:55 -06:00
|
|
|
configuration::SetElementInfo NodeSetInfoAccess::getElementInfo() const
|
2000-11-07 07:40:31 -06:00
|
|
|
{
|
2000-11-16 01:46:40 -06:00
|
|
|
using configuration::SetElementInfo;
|
2002-02-11 06:47:56 -06:00
|
|
|
using configuration::TemplateHolder;
|
2000-11-07 07:40:31 -06:00
|
|
|
|
2007-11-23 07:02:55 -06:00
|
|
|
TemplateHolder aTemplate = SetElementInfo::extractElementInfo(getTree(),getNodeRef());
|
2000-11-16 01:46:40 -06:00
|
|
|
|
2002-02-11 06:47:56 -06:00
|
|
|
OSL_ENSURE(aTemplate.is(), "ERROR: Set must have an element template");
|
2000-11-16 01:46:40 -06:00
|
|
|
|
2007-11-23 07:02:55 -06:00
|
|
|
return SetElementInfo(aTemplate);
|
2000-11-07 07:40:31 -06:00
|
|
|
}
|
|
|
|
|
2002-02-11 06:47:56 -06:00
|
|
|
}
|
2000-11-07 07:40:31 -06:00
|
|
|
}
|