summaryrefslogtreecommitdiff
path: root/configmgr/source/api2/apinodeaccess.hxx
blob: 033b9c9867280f277934f0226fe8d53e97b0bdec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/*************************************************************************
 *
 *  $RCSfile: apinodeaccess.hxx,v $
 *
 *  $Revision: 1.5 $
 *
 *  last change: $Author: hr $ $Date: 2003-03-19 16:18:29 $
 *
 *  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_API_NODEACCESS_HXX_
#define CONFIGMGR_API_NODEACCESS_HXX_

#ifndef CONFIGMGR_UTILITY_HXX_
#include "utility.hxx"
#endif

namespace osl { class Mutex; }

namespace configmgr
{
    namespace memory
    {
        class Accessor;
        class Segment;
    }
    namespace configuration 
    {
        class Name;
        class AnyNodeRef;
        class NodeRef;
        class TreeRef;
        class Tree;

        class SetElementInfo;
        class TemplateInfo;
        class ElementRef;
        class ElementTree;
    }
    namespace configapi 
    {
        class Factory;
        class Notifier;
        class SetElement;

        class ApiTreeImpl;

        namespace uno = com::sun::star::uno;
        typedef uno::XInterface UnoInterface;
        typedef uno::Any UnoAny;

    // API object implementation wrappers 
        // these objects just provide the pieces needed to navigate and manipulate trees and nodes

        // The common part of all nodes, provides all you need to read and listen
        class NodeAccess : Noncopyable
        {
        public:
            virtual ~NodeAccess();

        // model access
            configuration::NodeRef	getNodeRef() const;
            configuration::TreeRef	getTreeRef() const;
            configuration::Tree	    getTree(memory::Accessor const& _aAccessor) const;

        // self-locked methods for dispose handling
            void checkAlive() const;
            void disposeNode();

        // api object handling
            UnoInterface*			getUnoInstance() const
            { return doGetUnoInstance(); }
            Factory&				getFactory() const;
            Notifier				getNotifier() const;

        // locking support
            osl::Mutex&             getDataLock() const;
            memory::Segment const*  getSourceData() const;
            osl::Mutex&				getApiLock();

        protected:
            virtual configuration::NodeRef	doGetNode() const = 0;
            virtual UnoInterface*	doGetUnoInstance() const = 0;
            virtual ApiTreeImpl&	getApiTree() const = 0;
        };

        /** builds a Uno <type scope='com::sun::star::uno'>Any</type> representing node <var>aNode</var>.
            <p>	Uses the <type scope='configmgr::configapi'>Factory</type> provided 
                to create service implementations wrapping inner nodes</p>
            <p>	returns VOID if <var>aNode</var> is empty.</p>
        */
        UnoAny	makeElement(configapi::Factory& rFactory, configuration::Tree const& aTree, configuration::AnyNodeRef const& aNode);

        /** builds a Uno <type scope='com::sun::star::uno'>Any</type> representing inner node <var>aNode</var>.
            <p>	Uses the <type scope='configmgr::configapi'>Factory</type> provided 
                to create service implementations wrapping inner nodes</p>
            <p>	returns VOID if <var>aNode</var> is empty.</p>
        */
        UnoAny	makeInnerElement(configapi::Factory& rFactory, configuration::Tree const& aTree, configuration::NodeRef const& aNode);

        /** builds a Uno <type scope='com::sun::star::uno'>Any</type> representing set element <var>aElement</var>.
            <p>	Uses the <type scope='configmgr::configapi'>Factory</type> provided 
                to create service implementations wrapping inner nodes</p>
            <p>	returns VOID if <var>aNode</var> is empty.</p>
        */
        UnoAny	makeElement(configapi::Factory& rFactory, configuration::ElementTree const& aTree);


        // Info interfaces for Group Nodes
        class NodeGroupInfoAccess : public NodeAccess
        {
        public:
            // currently only used for tagging group nodes
        };

        // Info interfaces for Set Nodes
        class NodeSetInfoAccess : public NodeAccess
        {
            friend class SetElement;
        public:
            configuration::SetElementInfo getElementInfo(memory::Accessor const& _aAccessor) const;
        };

        /** extracts a <type scope='configmgr::configuration'>ElementTree</type> from a <type scope='com::sun::star::uno'>Any</type> 
            which must contain an object which wraps an instance of the template available in <var>aElementInfo</var>.
            <p>	Uses the <type scope='configmgr::configapi'>Factory</type> provided 
                to resolve inner nodes (which may suppose that the object was created using the same factory)</p>
            <p>	returns an empty <type scope='configmgr::configuration'>Tree</type> if <var>aElement</var> is empty.</p>
            <p>	May throw exceptions if the type doesn't match the template.</p>
        */
        configuration::ElementRef  extractElementRef (Factory& rFactory, UnoAny const& aElement, configuration::TemplateInfo   const& aElementInfo );	
        configuration::ElementTree extractElementTree(Factory& rFactory, UnoAny const& aElement, configuration::SetElementInfo const& aElementInfo );	

        /// finds a existing <type>SetElement</type> for a given <type scope='configmgr::configuration'>ElementTree</type>
        SetElement* findSetElement(Factory& rFactory, configuration::ElementRef const& aElementTree);
            
    // Guarding and locking implementations
        /// guards a NodeAccess; provides an object (read) lock, ensures object was not disposed
        class NodeReadGuardImpl : Noncopyable
        {
            osl::MutexGuard	    m_aLock;
            NodeAccess&			m_rNode;
        public:
            NodeReadGuardImpl(NodeAccess& rNode) throw();
            ~NodeReadGuardImpl() throw ();
        public:
            NodeAccess&	get() const { return m_rNode; }

            configuration::Tree     getTree(memory::Accessor const& _aAccessor) const;
            configuration::NodeRef  getNode() const;
            
        };

    // Thin Wrappers around NodeAccesses: Provide guarding and convenient access
        /// wraps a NodeAccess; provides an object (read) lock, ensures object was not disposed
        template <class Access>
        class GuardedNode
        {	
            NodeReadGuardImpl	m_aViewLock;
        public:
            GuardedNode(Access& rNode) : m_aViewLock(rNode) {}
        public:
            Access&	get()		 const { return static_cast<Access&>(m_aViewLock.get()); }
        };
        typedef GuardedNode<NodeAccess> GuardedNodeAccess;

        /// wraps a NodeAccess; provides both object and provider (read) locks, ensures object was not disposed
        template <class Access>
        class GuardedNodeData
        {	
            memory::Accessor	    m_aDataAccess;
            NodeReadGuardImpl	m_aViewLock;
        public:
            GuardedNodeData(Access& rNode);
        public:
            Access&	get()		 const { return static_cast<Access&>(m_aViewLock.get()); }

            configuration::Tree     getTree() const;
            configuration::NodeRef  getNode() const;

            memory::Accessor const & getDataAccessor() const { return m_aDataAccess; }
        };
        typedef GuardedNodeData<NodeAccess> GuardedNodeDataAccess;

        template <class Access>
        GuardedNodeData<Access>::GuardedNodeData(Access& rNode)
        : m_aDataAccess(rNode.getSourceData())
        , m_aViewLock(rNode)
        {
        }

        template <class Access>
        configuration::Tree GuardedNodeData<Access>::getTree() const
        {
            return m_aViewLock.getTree(m_aDataAccess);
        }

        template <class Access>
        configuration::NodeRef GuardedNodeData<Access>::getNode() const
        {
            return m_aViewLock.getNode();
        }
    }
}

#endif // CONFIGMGR_API_NODEACCESS_HXX_