summaryrefslogtreecommitdiff
path: root/configmgr/source/registry/cfgregistrykey.hxx
blob: edf9c7d25fea3ed4792dfa90586056509b3602a0 (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
/*************************************************************************
 *
 *  $RCSfile: cfgregistrykey.hxx,v $
 *
 *  $Revision: 1.1.1.1 $
 *
 *  last change: $Author: hr $ $Date: 2000-09-18 16:13:41 $
 *
 *  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_REGISTRY_CFGREGISTRYKEY_HXX_
#define _CONFIGMGR_REGISTRY_CFGREGISTRYKEY_HXX_

#ifndef _CPPUHELPER_IMPLBASE1_HXX_
#include <cppuhelper/implbase1.hxx>
#endif

#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
#include <com/sun/star/container/XNameAccess.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XHIERARCHICALNAMEACCESS_HPP_
#include <com/sun/star/container/XHierarchicalNameAccess.hpp>
#endif
#ifndef _COM_SUN_STAR_REGISTRY_XREGISTRYKEY_HPP_
#include <com/sun/star/registry/XRegistryKey.hpp>
#endif

#ifndef _OSL_MUTEX_HXX_
#include <osl/Mutex.hxx>
#endif

//..........................................................................
namespace configmgr
{
//..........................................................................

//==========================================================================
//= OConfigurationRegistryKey
//==========================================================================
typedef ::cppu::WeakImplHelper1 <   ::com::sun::star::registry::XRegistryKey
                                >   OConfigurationRegistryKey_Base;

/** wraps the registry-like access to a single node of a configuration sub tree
*/
class OConfigurationRegistryKey
        :public OConfigurationRegistryKey_Base
{
    ::osl::Mutex    m_aMutex;           /// access safety
    sal_Bool        m_bReadOnly;        /// is the key readonly ?

    ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >
                    m_xNodeAccess;      /// the config node object, if it describes a container
    ::com::sun::star::uno::Reference< ::com::sun::star::container::XHierarchicalNameAccess >
                    m_xNodeDeepAccess;  /// for accessing elements which are grandchildren

    ::com::sun::star::uno::Any
                    m_aLeafElement;     /// if the key represents a leaf, this is the value
    ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >
                    m_xLeafParent;      /// if the key represents a leaf, this is it's parent. used for write access

    ::rtl::OUString m_sLocalName;       /** the name of the element relative to the parent, which would be
                                            m_xLeafParent in case the key represents a value node
                                        */

    // TODO : the current concept does not recognize any changes in the config tree, i.e. the values stored
    // in a configuration key wrapper are not changed if the value in the corresponding config node changes.
    // Possible solutions:
    // 1. on each value (or even on each sub key) access, the node is read from the configuration hierarchy, again.
    //      sounds very expensive.
    // 2. each registry key is a listener on the node it represents.
    //      sounds expensive, too.
    //
    // At the moment we ignore this restriction, but perhaps we can't do that forever ....

public:
    /// when used as ctor parameter, this indicates that the key wraps a config tree subtree root
    struct SubtreeRoot { };

    /** builds an registry key which wraps the root of a configuration node
    */
    OConfigurationRegistryKey(
             const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _rxContainerNode
            ,sal_Bool _bWriteable
            ,SubtreeRoot
        );

    /** builds an registry key for a configuration container node
        @param      _rxContainerNode    the container the key should represent
        @param      _rLocalName         the name of the node local to it's parent. Must be empty only if
                                        the key represents the root node of a navigatable sub tree.
        @param      _bWriteable         should the key be writeable ?
    */
    OConfigurationRegistryKey(
             const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _rxContainerNode
            ,const ::rtl::OUString& _rLocalName
            ,sal_Bool _bWriteable
        );

    /** builds an registry key for a configuration value container node.
        @param      _rCurrentValue  the current value of the node. Must be the same as _rxParentNode->getByName(_rRelativeName) would provide
        @param      _rxParentNode   the parent of the value node. Used for update access and for obtaining the initial value.
        @param      _rRelativeName  te relative name within the parent
        @param      _bWriteable     should the key be writeable ?
    */
    OConfigurationRegistryKey(
             ::com::sun::star::uno::Any _rCurrentValue
            ,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _rxParentNode
            ,const ::rtl::OUString& _rRelativeName
            ,sal_Bool _bWriteable
        );

    // XRegistryKey
    virtual ::rtl::OUString SAL_CALL getKeyName() throw(::com::sun::star::uno::RuntimeException);
    virtual sal_Bool SAL_CALL isReadOnly(  ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException);
    virtual sal_Bool SAL_CALL isValid(  ) throw(::com::sun::star::uno::RuntimeException);
    virtual ::com::sun::star::registry::RegistryKeyType SAL_CALL getKeyType( const ::rtl::OUString& rKeyName ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException);
    virtual ::com::sun::star::registry::RegistryValueType SAL_CALL getValueType(  ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException);
    virtual sal_Int32 SAL_CALL getLongValue(  ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::registry::InvalidValueException, ::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL setLongValue( sal_Int32 value ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException);
    virtual ::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL getLongListValue(  ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::registry::InvalidValueException, ::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL setLongListValue( const ::com::sun::star::uno::Sequence< sal_Int32 >& seqValue ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException);
    virtual ::rtl::OUString SAL_CALL getAsciiValue(  ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::registry::InvalidValueException, ::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL setAsciiValue( const ::rtl::OUString& value ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException);
    virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getAsciiListValue(  ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::registry::InvalidValueException, ::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL setAsciiListValue( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& seqValue ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException);
    virtual ::rtl::OUString SAL_CALL getStringValue(  ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::registry::InvalidValueException, ::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL setStringValue( const ::rtl::OUString& value ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException);
    virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getStringListValue(  ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::registry::InvalidValueException, ::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL setStringListValue( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& seqValue ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException);
    virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getBinaryValue(  ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::registry::InvalidValueException, ::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL setBinaryValue( const ::com::sun::star::uno::Sequence< sal_Int8 >& value ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException);
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::registry::XRegistryKey > SAL_CALL openKey( const ::rtl::OUString& aKeyName ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException);
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::registry::XRegistryKey > SAL_CALL createKey( const ::rtl::OUString& aKeyName ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL closeKey(  ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL deleteKey( const ::rtl::OUString& rKeyName ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException);
    virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::registry::XRegistryKey > > SAL_CALL openKeys(  ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException);
    virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getKeyNames(  ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException);
    virtual sal_Bool SAL_CALL createLink( const ::rtl::OUString& aLinkName, const ::rtl::OUString& aLinkTarget ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL deleteLink( const ::rtl::OUString& rLinkName ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException);
    virtual ::rtl::OUString SAL_CALL getLinkTarget( const ::rtl::OUString& rLinkName ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException);
    virtual ::rtl::OUString SAL_CALL getResolvedName( const ::rtl::OUString& aKeyName ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException);

protected:
    /** specifies the kind of access to the key.
    */
    enum KEY_ACCESS_TYPE
    {
        KAT_META,           /// access on a meta level, e.g. asking for the read-onyl flag
        KAT_VALUE,          /// read access to the value the node represents
        KAT_VALUE_WRITE,    /// write access to the value the node represents
        KAT_CHILD           /// access to one of the (grand-)children of the node
    };

    /** check if the registry key is valid
        @param      _eIntentedAccess    type of access which the caller wants to perform on the object
        @throws             <type scope="com.sun.star.registry">InvalidRegistryException</type> if the key is invalid
    */
    void checkValid(KEY_ACCESS_TYPE _eIntentedAccess) throw (::com::sun::star::registry::InvalidRegistryException);

    /** return an child element.
        @param      _rDescendantName    the name of the descendant to open. May have a depth of more than 1, if
                                        the node container support XHierarchicalNameAccess
        @return             the requested element. The caller can assume that the returned
                            <type scope="com.sun.star.uno">Any</type> always contains an object, all other cases are
                            handled with exceptions
        @throws             <type scope="com.sun.star.registry">InvalidRegistryException</type> if the key is invalid,
                            the element refered by _rName does not exist, the configuration node threw an exception, or
                            the name has a depth of more than one and the config node does not support this.
    */
    ::com::sun::star::uno::Any getDescendant(const ::rtl::OUString& _rDescendantName) throw(::com::sun::star::registry::InvalidRegistryException);

    /** write the given value into the configuration node the object represents.
        @throws             <type scope="com.sun.star.registry">InvalidRegistryException</type> if the key is invalid,
                            not opened for write access or the configurations parent is not able to provide a value access
        @throws             <type scope="com.sun.star.uno">RuntimeException</type> if a fatal runtime error occurs
    */
    void writeValueNode(const ::com::sun::star::uno::Any& _rValue) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException);

    /** open the sub key (depth 1 or more) determined by the given name
        @param      _rKeyName       the name of the descendant node
        @return             a XRegistryKey wrapper for the requested configuration node
        @throws             <type scope="com.sun.star.registry">InvalidRegistryException</type> if the key is invalid,
                            the element refered by _rName does not exist, the configuration node threw an exception, or
                            the name has a depth of more than one and the config node does not support this.
    */
    ::com::sun::star::uno::Reference< ::com::sun::star::registry::XRegistryKey > OConfigurationRegistryKey::implGetKey( const ::rtl::OUString& _rKeyName ) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException);

    /** check the given (relative) key name syntactically. In particular, this means that no checks are made if a node
        with the given name exists or something like that ...
        <BR>
        In addition, the given name will be normalized. Basically, this means that it does not contain trailing slashes.
        @throws InvalidRegistryException if the name is not relative (i.e. if it starts with an slash)
        @throws InvalidRegistryException if the name is empty or consists of slashes only
    */
    void checkRelativeKeyName(::rtl::OUString& _rKeyName) throw(::com::sun::star::registry::InvalidRegistryException, ::com::sun::star::uno::RuntimeException);
};


//..........................................................................
}   // namespace configmgr
//..........................................................................

#endif // _CONFIGMGR_REGISTRY_CFGREGISTRYKEY_HXX_