2000-11-03 02:01:46 -06:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
|
|
|
* $RCSfile: valuenode.hxx,v $
|
|
|
|
*
|
2001-08-08 05:23:48 -05:00
|
|
|
* $Revision: 1.13 $
|
2000-11-03 02:01:46 -06:00
|
|
|
*
|
2001-08-08 05:23:48 -05:00
|
|
|
* last change: $Author: avy $ $Date: 2001-08-08 11:23:02 $
|
2000-11-03 02:01:46 -06:00
|
|
|
*
|
|
|
|
* The Contents of this file are made available subject to the terms of
|
|
|
|
* either of the following licenses
|
|
|
|
*
|
|
|
|
* - GNU Lesser General Public License Version 2.1
|
|
|
|
* - Sun Industry Standards Source License Version 1.1
|
|
|
|
*
|
|
|
|
* Sun Microsystems Inc., October, 2000
|
|
|
|
*
|
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2000 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library 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 for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Sun Industry Standards Source License Version 1.1
|
|
|
|
* =================================================
|
|
|
|
* The contents of this file are subject to the Sun Industry Standards
|
|
|
|
* Source License Version 1.1 (the "License"); You may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of the
|
|
|
|
* License at http://www.openoffice.org/license.html.
|
|
|
|
*
|
|
|
|
* Software provided under this License is provided on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
|
|
|
|
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
|
|
|
|
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
|
|
|
|
* See the License for the specific provisions governing your rights and
|
|
|
|
* obligations concerning the Software.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
|
|
|
|
*
|
|
|
|
* Copyright: 2000 by Sun Microsystems, Inc.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s): _______________________________________
|
|
|
|
*
|
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
#ifndef _CONFIGMGR_TREE_VALUENODE_HXX
|
|
|
|
#define _CONFIGMGR_TREE_VALUENODE_HXX
|
|
|
|
|
2000-11-15 03:30:41 -06:00
|
|
|
#include <memory>
|
2000-11-15 00:14:58 -06:00
|
|
|
#include "rttimacros.hxx"
|
|
|
|
#include <rtl/ustring.hxx>
|
|
|
|
|
|
|
|
#ifndef _COM_SUN_STAR_UNO_ANY_H_
|
|
|
|
#include <com/sun/star/uno/Any.h>
|
|
|
|
#endif
|
|
|
|
|
2000-11-30 02:01:47 -06:00
|
|
|
#ifndef CONFIGMGR_CONFIGPATH_HXX_
|
|
|
|
#include "configpath.hxx"
|
|
|
|
#endif
|
|
|
|
|
2001-06-20 14:17:35 -05:00
|
|
|
#ifndef _UNO_ANY2_H_
|
|
|
|
#include <uno/any2.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <anypair.hxx>
|
|
|
|
|
2000-11-15 00:14:58 -06:00
|
|
|
namespace configmgr
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace css = com::sun::star;
|
|
|
|
namespace uno = css::uno;
|
|
|
|
|
|
|
|
class INode;
|
|
|
|
class ISubtree;
|
|
|
|
class ValueNode;
|
|
|
|
|
2001-04-05 08:43:14 -05:00
|
|
|
// helper (tag) class
|
2001-08-08 05:23:48 -05:00
|
|
|
namespace treeop { struct NoChildCopy {}; }
|
2000-11-15 00:14:58 -06:00
|
|
|
//==========================================================================
|
|
|
|
//= Visitors
|
|
|
|
//==========================================================================
|
|
|
|
struct NodeAction
|
|
|
|
{
|
|
|
|
virtual void handle(ValueNode const&) = 0;
|
|
|
|
virtual void handle(ISubtree const&) = 0;
|
|
|
|
|
|
|
|
void applyToNode(INode const&);
|
|
|
|
void applyToChildren(ISubtree const&);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct NodeModification
|
|
|
|
{
|
|
|
|
virtual void handle(ValueNode&) = 0;
|
|
|
|
virtual void handle(ISubtree&) = 0;
|
|
|
|
|
|
|
|
void applyToNode(INode&);
|
|
|
|
void applyToChildren(ISubtree&);
|
|
|
|
};
|
|
|
|
|
|
|
|
class INode
|
|
|
|
{
|
2000-11-30 02:01:47 -06:00
|
|
|
rtl::OUString m_aName;
|
|
|
|
configuration::Attributes m_aAttributes;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
INode(){}
|
2000-11-15 00:14:58 -06:00
|
|
|
|
|
|
|
public:
|
2001-03-20 01:01:46 -06:00
|
|
|
explicit INode(configuration::Attributes);
|
2000-11-30 02:01:47 -06:00
|
|
|
INode(rtl::OUString const& aName, configuration::Attributes);
|
2000-11-15 00:14:58 -06:00
|
|
|
virtual ~INode();
|
|
|
|
virtual INode* clone() const = 0;
|
|
|
|
|
2000-11-30 02:01:47 -06:00
|
|
|
const rtl::OUString& getName() const {return m_aName;}
|
|
|
|
configuration::Attributes getAttributes() const {return m_aAttributes;}
|
2000-11-15 00:14:58 -06:00
|
|
|
|
2000-11-30 02:01:47 -06:00
|
|
|
bool isLocalized() const {return m_aAttributes.bLocalized;}
|
|
|
|
bool isReplacing() const {return m_aAttributes.bReplacing;}
|
2000-11-15 00:14:58 -06:00
|
|
|
void setName(const rtl::OUString& _rNewName) { m_aName = _rNewName; }
|
|
|
|
// to be used with caution. If the node is referenced from somewhere else under it's old name,
|
|
|
|
// you may have problems with this inconsistence
|
|
|
|
|
|
|
|
virtual ValueNode* asValueNode();
|
|
|
|
virtual ValueNode const* asValueNode() const;
|
|
|
|
virtual ISubtree* asISubtree();
|
|
|
|
virtual ISubtree const* asISubtree() const;
|
|
|
|
|
|
|
|
// double dispatch support
|
|
|
|
virtual void dispatch(NodeAction&) const = 0;
|
|
|
|
virtual void dispatch(NodeModification&) = 0;
|
|
|
|
|
|
|
|
// "rtti"
|
|
|
|
RTTI_BASE(INode);
|
|
|
|
};
|
|
|
|
|
2001-06-20 14:17:35 -05:00
|
|
|
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//= ISubtree
|
|
|
|
//==========================================================================
|
|
|
|
// Abstract class
|
|
|
|
|
|
|
|
class ASubtree : public INode
|
|
|
|
{
|
|
|
|
sal_Int16 m_nLevel; /// determines if everything is read
|
|
|
|
::rtl::OUString m_sId;
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual bool isSetNode() const = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//= GroupTree
|
|
|
|
//==========================================================================
|
|
|
|
class GroupTree : public ASubtree
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual bool isSetNode() const; // always false!
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//= SetTree
|
|
|
|
//==========================================================================
|
|
|
|
class SetTree : public ASubtree
|
|
|
|
{
|
|
|
|
::rtl::OUString m_sTemplateName; /// path of the template for child instantiation
|
|
|
|
::rtl::OUString m_sTemplateModule; /// module of the template for child instantiation
|
|
|
|
public:
|
|
|
|
virtual bool isSetNode() const; // always true!
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// ----------------------------------- O L D -----------------------------------
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2000-11-15 00:14:58 -06:00
|
|
|
//==========================================================================
|
|
|
|
//= ISubtree
|
|
|
|
//==========================================================================
|
|
|
|
class ISubtree : public INode
|
|
|
|
{
|
2000-11-30 02:01:47 -06:00
|
|
|
sal_Int16 m_nLevel; /// determines if everything is read
|
|
|
|
::rtl::OUString m_sId;
|
|
|
|
::rtl::OUString m_sTemplateName; /// path of the template for child instantiation
|
2001-03-12 07:58:00 -06:00
|
|
|
::rtl::OUString m_sTemplateModule; /// module of the template for child instantiation
|
2000-11-30 02:01:47 -06:00
|
|
|
|
2000-11-15 00:14:58 -06:00
|
|
|
virtual INode* doGetChild(rtl::OUString const& name) const = 0;
|
|
|
|
|
2000-11-30 02:01:47 -06:00
|
|
|
protected:
|
|
|
|
ISubtree():m_nLevel(0){}
|
2000-11-15 00:14:58 -06:00
|
|
|
|
2000-12-20 05:14:21 -06:00
|
|
|
ISubtree(ISubtree const& other)
|
|
|
|
:INode(other)
|
|
|
|
,m_nLevel(other.m_nLevel)
|
|
|
|
,m_sTemplateName(other.m_sTemplateName)
|
2001-03-12 07:58:00 -06:00
|
|
|
,m_sTemplateModule(other.m_sTemplateModule)
|
2000-12-20 05:14:21 -06:00
|
|
|
,m_sId() // do not copy ID while cloning !
|
|
|
|
{}
|
|
|
|
|
2000-11-15 00:14:58 -06:00
|
|
|
public:
|
2000-11-30 02:01:47 -06:00
|
|
|
// subtree does current not support attributes in the right way
|
|
|
|
// ISubtree(const configuration::Attributes& _rAttrs) : INode(_rAttrs), m_nLevel(0) {}
|
2001-03-12 07:58:00 -06:00
|
|
|
|
|
|
|
// Ctor for group trees
|
|
|
|
ISubtree(const rtl::OUString& aName, const configuration::Attributes& _rAttrs)
|
|
|
|
:INode(aName, _rAttrs)
|
|
|
|
,m_nLevel(0)
|
|
|
|
{}
|
|
|
|
|
|
|
|
// Ctor for set trees
|
|
|
|
ISubtree(const rtl::OUString& aName,
|
|
|
|
const rtl::OUString& _rTemplateName,
|
|
|
|
const rtl::OUString& _rTemplateModule,
|
2000-11-30 02:01:47 -06:00
|
|
|
const configuration::Attributes& _rAttrs)
|
|
|
|
:INode(aName, _rAttrs)
|
|
|
|
,m_nLevel(0)
|
2001-03-12 07:58:00 -06:00
|
|
|
,m_sTemplateName(_rTemplateName)
|
|
|
|
,m_sTemplateModule(_rTemplateModule){}
|
2000-11-15 00:14:58 -06:00
|
|
|
|
2000-12-20 05:14:21 -06:00
|
|
|
bool hasId() const { return m_sId.getLength() != 0; }
|
2000-11-15 00:14:58 -06:00
|
|
|
::rtl::OUString getId() const { return m_sId; }
|
|
|
|
void setId(const ::rtl::OUString& _rId) { m_sId = _rId; }
|
|
|
|
|
|
|
|
INode* getChild(rtl::OUString const& name) { return doGetChild(name); }
|
|
|
|
INode const* getChild(rtl::OUString const& name) const { return doGetChild(name); }
|
|
|
|
|
|
|
|
ISubtree* asISubtree();
|
|
|
|
ISubtree const* asISubtree() const;
|
|
|
|
|
2000-11-30 02:01:47 -06:00
|
|
|
sal_Int16 getLevel() const {return m_nLevel;}
|
|
|
|
void setLevel(sal_Int16);
|
2000-11-15 00:14:58 -06:00
|
|
|
|
|
|
|
bool isSetNode() const { return m_sTemplateName.getLength() != 0; }
|
2001-03-12 07:58:00 -06:00
|
|
|
::rtl::OUString getElementTemplateName() const { return m_sTemplateName; }
|
|
|
|
::rtl::OUString getElementTemplateModule() const { return m_sTemplateModule; }
|
2000-11-30 02:01:47 -06:00
|
|
|
|
|
|
|
virtual INode* addChild(std::auto_ptr<INode> node) =0; // takes ownership
|
|
|
|
virtual ::std::auto_ptr<INode> removeChild(rtl::OUString const& name) =0; // releases ownership
|
|
|
|
|
|
|
|
// Iteration support, stop if (action returns true)
|
|
|
|
virtual void forEachChild(NodeAction& anAction) const = 0;
|
|
|
|
virtual void forEachChild(NodeModification& anAction) = 0;
|
2000-11-15 00:14:58 -06:00
|
|
|
|
|
|
|
// double dispatch support
|
|
|
|
virtual void dispatch(NodeAction& anAction) const { anAction.handle(*this); }
|
|
|
|
virtual void dispatch(NodeModification& anAction) { anAction.handle(*this); }
|
|
|
|
|
|
|
|
// "rtti"
|
|
|
|
RTTI(ISubtree, INode);
|
|
|
|
};
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//= ValueNode
|
|
|
|
//==========================================================================
|
|
|
|
class ValueNode : public INode
|
|
|
|
{
|
2001-06-20 14:17:35 -05:00
|
|
|
AnyPair m_aValuePair;
|
|
|
|
// uno::Type m_aType;
|
|
|
|
// uno::Any m_aValue;
|
|
|
|
// uno::Any m_aDefaultValue;
|
2000-11-30 02:01:47 -06:00
|
|
|
|
2000-11-15 00:14:58 -06:00
|
|
|
public:
|
|
|
|
ValueNode(){}
|
|
|
|
|
2001-03-20 01:01:46 -06:00
|
|
|
explicit ValueNode(configuration::Attributes _aAttrs):INode(_aAttrs){}
|
2000-11-30 02:01:47 -06:00
|
|
|
|
|
|
|
ValueNode(rtl::OUString const& aName, configuration::Attributes _aAttrs)
|
|
|
|
:INode(aName, _aAttrs)
|
2000-11-15 00:14:58 -06:00
|
|
|
{}
|
2000-11-30 02:01:47 -06:00
|
|
|
ValueNode(rtl::OUString const& aName,uno::Type const& aType, configuration::Attributes _aAttrs)
|
2001-06-20 14:17:35 -05:00
|
|
|
:INode(aName, _aAttrs), m_aValuePair(aType)
|
|
|
|
{
|
|
|
|
check_init();
|
|
|
|
}
|
2000-11-30 02:01:47 -06:00
|
|
|
ValueNode(rtl::OUString const& aName,uno::Any const& anAny, configuration::Attributes _aAttrs)
|
2001-06-20 14:17:35 -05:00
|
|
|
:INode(aName, _aAttrs), m_aValuePair(anAny)
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
2000-11-30 02:01:47 -06:00
|
|
|
ValueNode(rtl::OUString const& aName,uno::Any const& anAny,uno::Any const& aDefault, configuration::Attributes _aAttrs)
|
2001-06-20 14:17:35 -05:00
|
|
|
:INode(aName, _aAttrs), m_aValuePair(anAny, aDefault)
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
2000-11-15 00:14:58 -06:00
|
|
|
|
|
|
|
|
2001-06-20 14:17:35 -05:00
|
|
|
bool isNull() const {return m_aValuePair.isNull();}
|
|
|
|
bool hasDefault() const {return getAttributes().bNullable || m_aValuePair.hasSecond();}
|
|
|
|
bool isDefault() const {return !m_aValuePair.hasFirst() && hasDefault();}
|
2000-12-01 06:40:40 -06:00
|
|
|
|
2001-06-20 14:17:35 -05:00
|
|
|
uno::Type getValueType() const {return m_aValuePair.getValueType();}
|
|
|
|
uno::Any getValue() const {return isDefault() ? m_aValuePair.getSecond() : m_aValuePair.getFirst();}
|
|
|
|
uno::Any getDefault() const {return m_aValuePair.getSecond();}
|
2000-11-15 00:14:58 -06:00
|
|
|
|
2001-06-20 14:17:35 -05:00
|
|
|
void setValue(uno::Any const& _aValue);
|
|
|
|
void changeDefault(uno::Any const& _aValue);
|
2000-11-15 00:14:58 -06:00
|
|
|
void setDefault();
|
|
|
|
|
|
|
|
virtual INode* clone() const;
|
|
|
|
|
|
|
|
ValueNode* asValueNode();
|
|
|
|
ValueNode const* asValueNode() const;
|
|
|
|
// double dispatch support
|
|
|
|
virtual void dispatch(NodeAction& anAction) const { anAction.handle(*this); }
|
|
|
|
virtual void dispatch(NodeModification& anAction) { anAction.handle(*this); }
|
|
|
|
|
|
|
|
// "rtti"
|
|
|
|
RTTI(ValueNode, INode);
|
|
|
|
private:
|
|
|
|
void init();
|
|
|
|
void check_init();
|
|
|
|
};
|
2001-04-05 08:43:14 -05:00
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
extern bool isLocalizedValueSet(ISubtree const& _aSubtree);
|
|
|
|
|
2000-11-19 18:38:19 -06:00
|
|
|
//==========================================================================
|
|
|
|
//= inlines
|
|
|
|
//==========================================================================
|
|
|
|
inline void NodeAction::applyToNode(INode const& aNode)
|
|
|
|
{ aNode.dispatch(*this); }
|
|
|
|
inline void NodeAction::applyToChildren(ISubtree const& aSubtree)
|
|
|
|
{ aSubtree.forEachChild(*this); }
|
|
|
|
|
|
|
|
inline void NodeModification::applyToNode(INode& aNode)
|
|
|
|
{ aNode.dispatch(*this); }
|
|
|
|
inline void NodeModification::applyToChildren(ISubtree& aSubtree)
|
|
|
|
{ aSubtree.forEachChild(*this); }
|
|
|
|
|
2000-11-15 00:14:58 -06:00
|
|
|
|
|
|
|
} // namespace configmgr
|
2000-11-03 02:01:46 -06:00
|
|
|
|
|
|
|
#endif
|