1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: apinodeaccess.hxx,v $
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 #ifndef CONFIGMGR_API_NODEACCESS_HXX_
32 #define CONFIGMGR_API_NODEACCESS_HXX_
34 #include "sal/config.h"
36 #include "boost/utility.hpp"
38 #include "datalock.hxx"
39 #include "utility.hxx"
40 #include "noderef.hxx"
42 namespace osl
{ class Mutex
; }
46 namespace configuration
60 namespace uno
= com::sun::star::uno
;
62 // API object implementation wrappers
63 // these objects just provide the pieces needed to navigate and manipulate trees and nodes
65 // The common part of all nodes, provides all you need to read and listen
66 class NodeAccess
: private boost::noncopyable
69 virtual ~NodeAccess();
72 configuration::NodeRef
getNodeRef() const;
73 rtl::Reference
< configuration::Tree
> getTreeRef() const;
74 rtl::Reference
< configuration::Tree
> getTree() const;
76 // self-locked methods for dispose handling
77 void checkAlive() const;
80 // api object handling
81 uno::XInterface
* getUnoInstance() const
82 { return doGetUnoInstance(); }
83 Factory
& getFactory() const;
84 Notifier
getNotifier() const;
87 virtual configuration::NodeRef
doGetNode() const = 0;
88 virtual uno::XInterface
* doGetUnoInstance() const = 0;
89 virtual ApiTreeImpl
& getApiTree() const = 0;
92 /** builds a Uno <type scope='com::sun::star::uno'>Any</type> representing node <var>aNode</var>.
93 <p> Uses the <type scope='configmgr::configapi'>Factory</type> provided
94 to create service implementations wrapping inner nodes</p>
95 <p> returns VOID if <var>aNode</var> is empty.</p>
97 uno::Any
makeElement(configapi::Factory
& rFactory
, rtl::Reference
< configuration::Tree
> const& aTree
, configuration::AnyNodeRef
const& aNode
);
99 /** builds a Uno <type scope='com::sun::star::uno'>Any</type> representing inner node <var>aNode</var>.
100 <p> Uses the <type scope='configmgr::configapi'>Factory</type> provided
101 to create service implementations wrapping inner nodes</p>
102 <p> returns VOID if <var>aNode</var> is empty.</p>
104 uno::Any
makeInnerElement(configapi::Factory
& rFactory
, rtl::Reference
< configuration::Tree
> const& aTree
, configuration::NodeRef
const& aNode
);
106 /** builds a Uno <type scope='com::sun::star::uno'>Any</type> representing set element <var>aElement</var>.
107 <p> Uses the <type scope='configmgr::configapi'>Factory</type> provided
108 to create service implementations wrapping inner nodes</p>
109 <p> returns VOID if <var>aNode</var> is empty.</p>
111 uno::Any
makeElement(configapi::Factory
& rFactory
, rtl::Reference
< configuration::ElementTree
> const& aTree
);
114 // Info interfaces for Group Nodes
115 class NodeGroupInfoAccess
: public NodeAccess
118 // currently only used for tagging group nodes
121 // Info interfaces for Set Nodes
122 class NodeSetInfoAccess
: public NodeAccess
124 friend class SetElement
;
126 rtl::Reference
< configuration::Template
> getElementInfo() const;
129 /** extracts a <type scope='configmgr::configuration'>ElementTree</type> from a <type scope='com::sun::star::uno'>Any</type>
130 which must contain an object which wraps an instance of the template available in <var>aTemplate</var>.
131 <p> Uses the <type scope='configmgr::configapi'>Factory</type> provided
132 to resolve inner nodes (which may suppose that the object was created using the same factory)</p>
133 <p> returns an empty tree if <var>aElement</var> is empty.</p>
134 <p> May throw exceptions if the type doesn't match the template.</p>
136 rtl::Reference
< configuration::ElementTree
> extractElementTree(Factory
& rFactory
, uno::Any
const& aElement
, rtl::Reference
< configuration::Template
> const& aTemplate
);
138 /// wraps a NodeAccess; provides both object and provider (read) locks,
139 // ensures object was not disposed
140 template <class Access
>
141 class GuardedNodeData
146 GuardedNodeData(Access
& rNode
);
148 Access
& get() const { return m_rNode
; }
150 rtl::Reference
< configuration::Tree
> getTree() const;
151 configuration::NodeRef
getNode() const;
154 template <class Access
>
155 GuardedNodeData
<Access
>::GuardedNodeData(Access
& rNode
)
161 template <class Access
>
162 rtl::Reference
< configuration::Tree
> GuardedNodeData
<Access
>::getTree() const
164 return m_rNode
.getTree();
167 template <class Access
>
168 configuration::NodeRef GuardedNodeData
<Access
>::getNode() const
170 return m_rNode
.getNodeRef();
175 #endif // CONFIGMGR_API_NODEACCESS_HXX_