xref: /trunk/main/stoc/source/defaultregistry/defaultregistry.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_stoc.hxx"
30*cdf0e10cSrcweir #include <osl/mutex.hxx>
31*cdf0e10cSrcweir #ifndef _OSL_DIAGNOSE_HXX_
32*cdf0e10cSrcweir #include <osl/diagnose.h>
33*cdf0e10cSrcweir #endif
34*cdf0e10cSrcweir #include <cppuhelper/queryinterface.hxx>
35*cdf0e10cSrcweir #include <cppuhelper/weak.hxx>
36*cdf0e10cSrcweir #include <cppuhelper/factory.hxx>
37*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
38*cdf0e10cSrcweir #include <cppuhelper/implbase4.hxx>
39*cdf0e10cSrcweir #include <cppuhelper/implbase3.hxx>
40*cdf0e10cSrcweir #ifndef _CPPUHELPER_IMPLEMENTATIONENTRY_HXX_
41*cdf0e10cSrcweir #include <cppuhelper/implementationentry.hxx>
42*cdf0e10cSrcweir #endif
43*cdf0e10cSrcweir #include <registry/registry.hxx>
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir #include <com/sun/star/registry/XSimpleRegistry.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/lang/XTypeProvider.hpp>
49*cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp>
50*cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
51*cdf0e10cSrcweir #include <com/sun/star/container/XEnumerationAccess.hpp>
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir #include <bootstrapservices.hxx>
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir using namespace com::sun::star::uno;
56*cdf0e10cSrcweir using namespace com::sun::star::registry;
57*cdf0e10cSrcweir using namespace com::sun::star::lang;
58*cdf0e10cSrcweir using namespace com::sun::star::container;
59*cdf0e10cSrcweir using namespace cppu;
60*cdf0e10cSrcweir using namespace osl;
61*cdf0e10cSrcweir using namespace rtl;
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir #define SERVICENAME "com.sun.star.registry.NestedRegistry"
65*cdf0e10cSrcweir #define IMPLNAME       "com.sun.star.comp.stoc.NestedRegistry"
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir extern rtl_StandardModuleCount g_moduleCount;
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir namespace stoc_bootstrap
70*cdf0e10cSrcweir {
71*cdf0e10cSrcweir Sequence< OUString > defreg_getSupportedServiceNames()
72*cdf0e10cSrcweir {
73*cdf0e10cSrcweir     static Sequence < OUString > *pNames = 0;
74*cdf0e10cSrcweir     if( ! pNames )
75*cdf0e10cSrcweir     {
76*cdf0e10cSrcweir         MutexGuard guard( Mutex::getGlobalMutex() );
77*cdf0e10cSrcweir         if( !pNames )
78*cdf0e10cSrcweir         {
79*cdf0e10cSrcweir             static Sequence< OUString > seqNames(1);
80*cdf0e10cSrcweir             seqNames.getArray()[0] = OUString(RTL_CONSTASCII_USTRINGPARAM(SERVICENAME));
81*cdf0e10cSrcweir             pNames = &seqNames;
82*cdf0e10cSrcweir         }
83*cdf0e10cSrcweir     }
84*cdf0e10cSrcweir     return *pNames;
85*cdf0e10cSrcweir }
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir OUString defreg_getImplementationName()
88*cdf0e10cSrcweir {
89*cdf0e10cSrcweir     static OUString *pImplName = 0;
90*cdf0e10cSrcweir     if( ! pImplName )
91*cdf0e10cSrcweir     {
92*cdf0e10cSrcweir         MutexGuard guard( Mutex::getGlobalMutex() );
93*cdf0e10cSrcweir         if( ! pImplName )
94*cdf0e10cSrcweir         {
95*cdf0e10cSrcweir             static OUString implName( RTL_CONSTASCII_USTRINGPARAM( IMPLNAME ) );
96*cdf0e10cSrcweir             pImplName = &implName;
97*cdf0e10cSrcweir         }
98*cdf0e10cSrcweir     }
99*cdf0e10cSrcweir     return *pImplName;
100*cdf0e10cSrcweir }
101*cdf0e10cSrcweir }
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir namespace stoc_defreg
104*cdf0e10cSrcweir {
105*cdf0e10cSrcweir //*************************************************************************
106*cdf0e10cSrcweir // NestedRegistryImpl
107*cdf0e10cSrcweir //*************************************************************************
108*cdf0e10cSrcweir class NestedKeyImpl;
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir class NestedRegistryImpl    : public WeakAggImplHelper4 < XSimpleRegistry, XInitialization, XServiceInfo, XEnumerationAccess >
111*cdf0e10cSrcweir {
112*cdf0e10cSrcweir public:
113*cdf0e10cSrcweir     NestedRegistryImpl( );
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir     ~NestedRegistryImpl();
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir     // XServiceInfo
118*cdf0e10cSrcweir     virtual OUString SAL_CALL getImplementationName(  ) throw(RuntimeException);
119*cdf0e10cSrcweir     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(RuntimeException);
120*cdf0e10cSrcweir     virtual Sequence< OUString > SAL_CALL getSupportedServiceNames(  ) throw(RuntimeException);
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir     // XInitialization
123*cdf0e10cSrcweir     virtual void SAL_CALL initialize( const Sequence< Any >& aArguments )
124*cdf0e10cSrcweir         throw(Exception, RuntimeException);
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir     // XSimpleRegistry
127*cdf0e10cSrcweir     virtual OUString SAL_CALL getURL() throw(RuntimeException);
128*cdf0e10cSrcweir     virtual void SAL_CALL open( const OUString& rURL, sal_Bool bReadOnly, sal_Bool bCreate ) throw(InvalidRegistryException, RuntimeException);
129*cdf0e10cSrcweir     virtual sal_Bool SAL_CALL isValid(  ) throw(RuntimeException);
130*cdf0e10cSrcweir     virtual void SAL_CALL close(  ) throw(InvalidRegistryException, RuntimeException);
131*cdf0e10cSrcweir     virtual void SAL_CALL destroy(  ) throw(InvalidRegistryException, RuntimeException);
132*cdf0e10cSrcweir     virtual Reference< XRegistryKey > SAL_CALL getRootKey(  ) throw(InvalidRegistryException, RuntimeException);
133*cdf0e10cSrcweir     virtual sal_Bool SAL_CALL isReadOnly(  ) throw(InvalidRegistryException, RuntimeException);
134*cdf0e10cSrcweir     virtual void SAL_CALL mergeKey( const OUString& aKeyName, const OUString& aUrl ) throw(InvalidRegistryException, MergeConflictException, RuntimeException);
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir     // XEnumerationAccess
137*cdf0e10cSrcweir     virtual Reference< XEnumeration > SAL_CALL createEnumeration(  ) throw (RuntimeException);
138*cdf0e10cSrcweir     virtual Type SAL_CALL getElementType(  ) throw (RuntimeException);
139*cdf0e10cSrcweir     virtual sal_Bool SAL_CALL hasElements(  ) throw (RuntimeException);
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir     friend class NestedKeyImpl;
142*cdf0e10cSrcweir protected:
143*cdf0e10cSrcweir     Mutex                       m_mutex;
144*cdf0e10cSrcweir     sal_uInt32                  m_state;
145*cdf0e10cSrcweir     Reference<XSimpleRegistry>  m_localReg;
146*cdf0e10cSrcweir     Reference<XSimpleRegistry>  m_defaultReg;
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir };
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir //*************************************************************************
151*cdf0e10cSrcweir // class NestedKeyImpl the implenetation of interface XRegistryKey
152*cdf0e10cSrcweir //*************************************************************************
153*cdf0e10cSrcweir class NestedKeyImpl : public WeakImplHelper1< XRegistryKey >
154*cdf0e10cSrcweir {
155*cdf0e10cSrcweir public:
156*cdf0e10cSrcweir     NestedKeyImpl( NestedRegistryImpl* pDefaultRegistry,
157*cdf0e10cSrcweir                    Reference<XRegistryKey>& localKey,
158*cdf0e10cSrcweir                    Reference<XRegistryKey>& defaultKey);
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir     NestedKeyImpl( const OUString& aKeyName,
161*cdf0e10cSrcweir                     NestedKeyImpl* pKey);
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir     ~NestedKeyImpl();
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir     // XRegistryKey
166*cdf0e10cSrcweir     virtual OUString SAL_CALL getKeyName() throw(RuntimeException);
167*cdf0e10cSrcweir     virtual sal_Bool SAL_CALL isReadOnly(  ) throw(InvalidRegistryException, RuntimeException);
168*cdf0e10cSrcweir     virtual sal_Bool SAL_CALL isValid(  ) throw(RuntimeException);
169*cdf0e10cSrcweir     virtual RegistryKeyType SAL_CALL getKeyType( const OUString& rKeyName ) throw(InvalidRegistryException, RuntimeException);
170*cdf0e10cSrcweir     virtual RegistryValueType SAL_CALL getValueType(  ) throw(InvalidRegistryException, RuntimeException);
171*cdf0e10cSrcweir     virtual sal_Int32 SAL_CALL getLongValue(  ) throw(InvalidRegistryException, InvalidValueException, RuntimeException);
172*cdf0e10cSrcweir     virtual void SAL_CALL setLongValue( sal_Int32 value ) throw(InvalidRegistryException, RuntimeException);
173*cdf0e10cSrcweir     virtual Sequence< sal_Int32 > SAL_CALL getLongListValue(  ) throw(InvalidRegistryException, InvalidValueException, RuntimeException);
174*cdf0e10cSrcweir     virtual void SAL_CALL setLongListValue( const ::com::sun::star::uno::Sequence< sal_Int32 >& seqValue ) throw(InvalidRegistryException, RuntimeException);
175*cdf0e10cSrcweir     virtual OUString SAL_CALL getAsciiValue(  ) throw(InvalidRegistryException, InvalidValueException, RuntimeException);
176*cdf0e10cSrcweir     virtual void SAL_CALL setAsciiValue( const OUString& value ) throw(InvalidRegistryException, RuntimeException);
177*cdf0e10cSrcweir     virtual Sequence< OUString > SAL_CALL getAsciiListValue(  ) throw(InvalidRegistryException, InvalidValueException, RuntimeException);
178*cdf0e10cSrcweir     virtual void SAL_CALL setAsciiListValue( const ::com::sun::star::uno::Sequence< OUString >& seqValue ) throw(InvalidRegistryException, RuntimeException);
179*cdf0e10cSrcweir     virtual OUString SAL_CALL getStringValue(  ) throw(InvalidRegistryException, InvalidValueException, RuntimeException);
180*cdf0e10cSrcweir     virtual void SAL_CALL setStringValue( const OUString& value ) throw(InvalidRegistryException, RuntimeException);
181*cdf0e10cSrcweir     virtual Sequence< OUString > SAL_CALL getStringListValue(  ) throw(InvalidRegistryException, InvalidValueException, RuntimeException);
182*cdf0e10cSrcweir     virtual void SAL_CALL setStringListValue( const ::com::sun::star::uno::Sequence< OUString >& seqValue ) throw(InvalidRegistryException, RuntimeException);
183*cdf0e10cSrcweir     virtual Sequence< sal_Int8 > SAL_CALL getBinaryValue(  ) throw(InvalidRegistryException, InvalidValueException, RuntimeException);
184*cdf0e10cSrcweir     virtual void SAL_CALL setBinaryValue( const ::com::sun::star::uno::Sequence< sal_Int8 >& value ) throw(InvalidRegistryException, RuntimeException);
185*cdf0e10cSrcweir     virtual Reference< XRegistryKey > SAL_CALL openKey( const OUString& aKeyName ) throw(InvalidRegistryException, RuntimeException);
186*cdf0e10cSrcweir     virtual Reference< XRegistryKey > SAL_CALL createKey( const OUString& aKeyName ) throw(InvalidRegistryException, RuntimeException);
187*cdf0e10cSrcweir     virtual void SAL_CALL closeKey(  ) throw(InvalidRegistryException, RuntimeException);
188*cdf0e10cSrcweir     virtual void SAL_CALL deleteKey( const OUString& rKeyName ) throw(InvalidRegistryException, RuntimeException);
189*cdf0e10cSrcweir     virtual Sequence< Reference< XRegistryKey > > SAL_CALL openKeys(  ) throw(InvalidRegistryException, RuntimeException);
190*cdf0e10cSrcweir     virtual Sequence< OUString > SAL_CALL getKeyNames(  ) throw(InvalidRegistryException, RuntimeException);
191*cdf0e10cSrcweir     virtual sal_Bool SAL_CALL createLink( const OUString& aLinkName, const OUString& aLinkTarget ) throw(InvalidRegistryException, RuntimeException);
192*cdf0e10cSrcweir     virtual void SAL_CALL deleteLink( const OUString& rLinkName ) throw(InvalidRegistryException, RuntimeException);
193*cdf0e10cSrcweir     virtual OUString SAL_CALL getLinkTarget( const OUString& rLinkName ) throw(InvalidRegistryException, RuntimeException);
194*cdf0e10cSrcweir     virtual OUString SAL_CALL getResolvedName( const OUString& aKeyName ) throw(InvalidRegistryException, RuntimeException);
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir protected:
197*cdf0e10cSrcweir     void        computeChanges();
198*cdf0e10cSrcweir     OUString    computeName(const OUString& name);
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir     OUString                    m_name;
201*cdf0e10cSrcweir     sal_uInt32                  m_state;
202*cdf0e10cSrcweir     NestedRegistryImpl*         m_pRegistry;
203*cdf0e10cSrcweir     Reference<XRegistryKey>     m_localKey;
204*cdf0e10cSrcweir     Reference<XRegistryKey>     m_defaultKey;
205*cdf0e10cSrcweir };
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir //*************************************************************************
209*cdf0e10cSrcweir NestedKeyImpl::NestedKeyImpl( NestedRegistryImpl* pDefaultRegistry,
210*cdf0e10cSrcweir                               Reference<XRegistryKey>& localKey,
211*cdf0e10cSrcweir                               Reference<XRegistryKey>& defaultKey )
212*cdf0e10cSrcweir     : m_pRegistry(pDefaultRegistry)
213*cdf0e10cSrcweir {
214*cdf0e10cSrcweir     m_pRegistry->acquire();
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir     m_localKey = localKey;
217*cdf0e10cSrcweir     m_defaultKey = defaultKey;
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir     if (m_localKey.is())
220*cdf0e10cSrcweir     {
221*cdf0e10cSrcweir         m_name = m_localKey->getKeyName();
222*cdf0e10cSrcweir     } else
223*cdf0e10cSrcweir     if (m_defaultKey.is())
224*cdf0e10cSrcweir     {
225*cdf0e10cSrcweir         m_name = m_defaultKey->getKeyName();
226*cdf0e10cSrcweir     }
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir     m_state = m_pRegistry->m_state;
229*cdf0e10cSrcweir }
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir //*************************************************************************
232*cdf0e10cSrcweir NestedKeyImpl::NestedKeyImpl( const OUString& rKeyName,
233*cdf0e10cSrcweir                               NestedKeyImpl* pKey)
234*cdf0e10cSrcweir     : m_pRegistry(pKey->m_pRegistry)
235*cdf0e10cSrcweir {
236*cdf0e10cSrcweir     m_pRegistry->acquire();
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir     if (pKey->m_localKey.is() && pKey->m_localKey->isValid())
239*cdf0e10cSrcweir     {
240*cdf0e10cSrcweir         m_localKey = pKey->m_localKey->openKey(rKeyName);
241*cdf0e10cSrcweir     }
242*cdf0e10cSrcweir     if (pKey->m_defaultKey.is() && pKey->m_defaultKey->isValid())
243*cdf0e10cSrcweir     {
244*cdf0e10cSrcweir         m_defaultKey = pKey->m_defaultKey->openKey(rKeyName);
245*cdf0e10cSrcweir     }
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir     if (m_localKey.is())
248*cdf0e10cSrcweir     {
249*cdf0e10cSrcweir         m_name = m_localKey->getKeyName();
250*cdf0e10cSrcweir     } else
251*cdf0e10cSrcweir     if (m_defaultKey.is())
252*cdf0e10cSrcweir     {
253*cdf0e10cSrcweir         m_name = m_defaultKey->getKeyName();
254*cdf0e10cSrcweir     }
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir     m_state = m_pRegistry->m_state;
257*cdf0e10cSrcweir }
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir //*************************************************************************
260*cdf0e10cSrcweir NestedKeyImpl::~NestedKeyImpl()
261*cdf0e10cSrcweir {
262*cdf0e10cSrcweir     if ( m_pRegistry )
263*cdf0e10cSrcweir         m_pRegistry->release();
264*cdf0e10cSrcweir }
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir //*************************************************************************
267*cdf0e10cSrcweir void NestedKeyImpl::computeChanges()
268*cdf0e10cSrcweir {
269*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
270*cdf0e10cSrcweir     if ( m_state != m_pRegistry->m_state )
271*cdf0e10cSrcweir     {
272*cdf0e10cSrcweir         Reference<XRegistryKey> rootKey(m_pRegistry->m_localReg->getRootKey());
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir         Reference<XRegistryKey> tmpKey = rootKey->openKey(m_name);
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir         if ( tmpKey.is() )
277*cdf0e10cSrcweir         {
278*cdf0e10cSrcweir             m_localKey = rootKey->openKey(m_name);
279*cdf0e10cSrcweir         }
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir         m_state = m_pRegistry->m_state;
282*cdf0e10cSrcweir     }
283*cdf0e10cSrcweir }
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir //*************************************************************************
286*cdf0e10cSrcweir // NestedKey_Impl::computeName()
287*cdf0e10cSrcweir //
288*cdf0e10cSrcweir OUString NestedKeyImpl::computeName(const OUString& name)
289*cdf0e10cSrcweir {
290*cdf0e10cSrcweir     OUString resLocalName, resDefaultName;
291*cdf0e10cSrcweir 
292*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
293*cdf0e10cSrcweir     try
294*cdf0e10cSrcweir     {
295*cdf0e10cSrcweir         if ( m_localKey.is() && m_localKey->isValid() )
296*cdf0e10cSrcweir         {
297*cdf0e10cSrcweir             resLocalName = m_localKey->getResolvedName(name);
298*cdf0e10cSrcweir         } else
299*cdf0e10cSrcweir         {
300*cdf0e10cSrcweir             if ( m_defaultKey.is() && m_defaultKey->isValid() )
301*cdf0e10cSrcweir                 return m_defaultKey->getResolvedName(name);
302*cdf0e10cSrcweir         }
303*cdf0e10cSrcweir 
304*cdf0e10cSrcweir         if ( resLocalName.getLength() > 0 && m_pRegistry->m_defaultReg->isValid() )
305*cdf0e10cSrcweir         {
306*cdf0e10cSrcweir             Reference<XRegistryKey> localRoot(m_pRegistry->m_localReg->getRootKey());
307*cdf0e10cSrcweir             Reference<XRegistryKey> defaultRoot(m_pRegistry->m_defaultReg->getRootKey());
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir             resDefaultName = defaultRoot->getResolvedName(resLocalName);
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir             sal_uInt32 count = 100;
312*cdf0e10cSrcweir 
313*cdf0e10cSrcweir             while (resLocalName != resDefaultName && count > 0)
314*cdf0e10cSrcweir             {
315*cdf0e10cSrcweir                 count--;
316*cdf0e10cSrcweir 
317*cdf0e10cSrcweir                 if (resLocalName.getLength() == 0 || resDefaultName.getLength() == 0)
318*cdf0e10cSrcweir                     throw InvalidRegistryException();
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir                 resLocalName = localRoot->getResolvedName(resDefaultName);
321*cdf0e10cSrcweir                 resDefaultName = defaultRoot->getResolvedName(resLocalName);
322*cdf0e10cSrcweir             }
323*cdf0e10cSrcweir         }
324*cdf0e10cSrcweir     }
325*cdf0e10cSrcweir     catch(InvalidRegistryException& )
326*cdf0e10cSrcweir     {
327*cdf0e10cSrcweir     }
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir     return resLocalName;
330*cdf0e10cSrcweir }
331*cdf0e10cSrcweir 
332*cdf0e10cSrcweir //*************************************************************************
333*cdf0e10cSrcweir OUString SAL_CALL NestedKeyImpl::getKeyName() throw(RuntimeException)
334*cdf0e10cSrcweir {
335*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
336*cdf0e10cSrcweir     return m_name;
337*cdf0e10cSrcweir }
338*cdf0e10cSrcweir 
339*cdf0e10cSrcweir //*************************************************************************
340*cdf0e10cSrcweir sal_Bool SAL_CALL NestedKeyImpl::isReadOnly(  )
341*cdf0e10cSrcweir     throw(InvalidRegistryException, RuntimeException)
342*cdf0e10cSrcweir {
343*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
344*cdf0e10cSrcweir     computeChanges();
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir     if ( m_localKey.is() && m_localKey->isValid() )
347*cdf0e10cSrcweir         return m_localKey->isReadOnly();
348*cdf0e10cSrcweir     else
349*cdf0e10cSrcweir         throw InvalidRegistryException();
350*cdf0e10cSrcweir }
351*cdf0e10cSrcweir 
352*cdf0e10cSrcweir //*************************************************************************
353*cdf0e10cSrcweir sal_Bool SAL_CALL NestedKeyImpl::isValid(  ) throw(RuntimeException)
354*cdf0e10cSrcweir {
355*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
356*cdf0e10cSrcweir     return ((m_localKey.is() && m_localKey->isValid()) ||
357*cdf0e10cSrcweir             (m_defaultKey.is() && m_defaultKey->isValid()) );
358*cdf0e10cSrcweir }
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir //*************************************************************************
361*cdf0e10cSrcweir RegistryKeyType SAL_CALL NestedKeyImpl::getKeyType( const OUString& rKeyName )
362*cdf0e10cSrcweir     throw(InvalidRegistryException, RuntimeException)
363*cdf0e10cSrcweir {
364*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
365*cdf0e10cSrcweir     computeChanges();
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir     if ( m_localKey.is() && m_localKey->isValid() )
368*cdf0e10cSrcweir     {
369*cdf0e10cSrcweir         return m_localKey->getKeyType(rKeyName);
370*cdf0e10cSrcweir     } else
371*cdf0e10cSrcweir     if ( m_defaultKey.is() && m_defaultKey->isValid() )
372*cdf0e10cSrcweir     {
373*cdf0e10cSrcweir         return m_defaultKey->getKeyType(rKeyName);
374*cdf0e10cSrcweir     }
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir     return RegistryKeyType_KEY;
377*cdf0e10cSrcweir }
378*cdf0e10cSrcweir 
379*cdf0e10cSrcweir //*************************************************************************
380*cdf0e10cSrcweir RegistryValueType SAL_CALL NestedKeyImpl::getValueType(  )
381*cdf0e10cSrcweir     throw(InvalidRegistryException, RuntimeException)
382*cdf0e10cSrcweir {
383*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
384*cdf0e10cSrcweir     computeChanges();
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir     if ( m_localKey.is() && m_localKey->isValid() )
387*cdf0e10cSrcweir     {
388*cdf0e10cSrcweir         return m_localKey->getValueType();
389*cdf0e10cSrcweir     } else
390*cdf0e10cSrcweir     if ( m_defaultKey.is() && m_defaultKey->isValid() )
391*cdf0e10cSrcweir     {
392*cdf0e10cSrcweir         return m_defaultKey->getValueType();
393*cdf0e10cSrcweir     }
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir     return RegistryValueType_NOT_DEFINED;
396*cdf0e10cSrcweir }
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir //*************************************************************************
399*cdf0e10cSrcweir sal_Int32 SAL_CALL NestedKeyImpl::getLongValue(  )
400*cdf0e10cSrcweir     throw(InvalidRegistryException, InvalidValueException, RuntimeException)
401*cdf0e10cSrcweir {
402*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
403*cdf0e10cSrcweir     computeChanges();
404*cdf0e10cSrcweir 
405*cdf0e10cSrcweir     if ( m_localKey.is() && m_localKey->isValid() )
406*cdf0e10cSrcweir     {
407*cdf0e10cSrcweir         return m_localKey->getLongValue();
408*cdf0e10cSrcweir     } else
409*cdf0e10cSrcweir     if ( m_defaultKey.is() && m_defaultKey->isValid() )
410*cdf0e10cSrcweir     {
411*cdf0e10cSrcweir         return m_defaultKey->getLongValue();
412*cdf0e10cSrcweir     } else
413*cdf0e10cSrcweir     {
414*cdf0e10cSrcweir         throw InvalidRegistryException();
415*cdf0e10cSrcweir     }
416*cdf0e10cSrcweir }
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir //*************************************************************************
419*cdf0e10cSrcweir void SAL_CALL NestedKeyImpl::setLongValue( sal_Int32 value )
420*cdf0e10cSrcweir     throw(InvalidRegistryException, RuntimeException)
421*cdf0e10cSrcweir {
422*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
423*cdf0e10cSrcweir     computeChanges();
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir     if ( m_localKey.is() && m_localKey->isValid() )
426*cdf0e10cSrcweir     {
427*cdf0e10cSrcweir         m_localKey->setLongValue(value);
428*cdf0e10cSrcweir     } else
429*cdf0e10cSrcweir     if ( m_defaultKey.is() && m_defaultKey->isValid() )
430*cdf0e10cSrcweir     {
431*cdf0e10cSrcweir         Reference<XRegistryKey> rootKey(m_pRegistry->m_localReg->getRootKey());
432*cdf0e10cSrcweir         m_localKey = rootKey->createKey(m_name);
433*cdf0e10cSrcweir         m_localKey->setLongValue(value);
434*cdf0e10cSrcweir         m_state = m_pRegistry->m_state++;
435*cdf0e10cSrcweir     } else
436*cdf0e10cSrcweir     {
437*cdf0e10cSrcweir         throw InvalidRegistryException();
438*cdf0e10cSrcweir     }
439*cdf0e10cSrcweir }
440*cdf0e10cSrcweir 
441*cdf0e10cSrcweir //*************************************************************************
442*cdf0e10cSrcweir Sequence< sal_Int32 > SAL_CALL NestedKeyImpl::getLongListValue(  )
443*cdf0e10cSrcweir     throw(InvalidRegistryException, InvalidValueException, RuntimeException)
444*cdf0e10cSrcweir {
445*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
446*cdf0e10cSrcweir     computeChanges();
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir     if ( m_localKey.is() && m_localKey->isValid() )
449*cdf0e10cSrcweir     {
450*cdf0e10cSrcweir         return m_localKey->getLongListValue();
451*cdf0e10cSrcweir     } else
452*cdf0e10cSrcweir     if ( m_defaultKey.is() && m_defaultKey->isValid() )
453*cdf0e10cSrcweir     {
454*cdf0e10cSrcweir         return m_defaultKey->getLongListValue();
455*cdf0e10cSrcweir     } else
456*cdf0e10cSrcweir     {
457*cdf0e10cSrcweir         throw InvalidRegistryException();
458*cdf0e10cSrcweir     }
459*cdf0e10cSrcweir }
460*cdf0e10cSrcweir 
461*cdf0e10cSrcweir //*************************************************************************
462*cdf0e10cSrcweir void SAL_CALL NestedKeyImpl::setLongListValue( const Sequence< sal_Int32 >& seqValue )
463*cdf0e10cSrcweir     throw(InvalidRegistryException, RuntimeException)
464*cdf0e10cSrcweir {
465*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
466*cdf0e10cSrcweir     computeChanges();
467*cdf0e10cSrcweir 
468*cdf0e10cSrcweir     if ( m_localKey.is() && m_localKey->isValid() )
469*cdf0e10cSrcweir     {
470*cdf0e10cSrcweir         m_localKey->setLongListValue(seqValue);
471*cdf0e10cSrcweir     } else
472*cdf0e10cSrcweir     if ( m_defaultKey.is() && m_defaultKey->isValid() )
473*cdf0e10cSrcweir     {
474*cdf0e10cSrcweir         Reference<XRegistryKey> rootKey(m_pRegistry->m_localReg->getRootKey());
475*cdf0e10cSrcweir         m_localKey = rootKey->createKey(m_name);
476*cdf0e10cSrcweir         m_localKey->setLongListValue(seqValue);
477*cdf0e10cSrcweir         m_state = m_pRegistry->m_state++;
478*cdf0e10cSrcweir     } else
479*cdf0e10cSrcweir     {
480*cdf0e10cSrcweir         throw InvalidRegistryException();
481*cdf0e10cSrcweir     }
482*cdf0e10cSrcweir }
483*cdf0e10cSrcweir 
484*cdf0e10cSrcweir //*************************************************************************
485*cdf0e10cSrcweir OUString SAL_CALL NestedKeyImpl::getAsciiValue(  )
486*cdf0e10cSrcweir     throw(InvalidRegistryException, InvalidValueException, RuntimeException)
487*cdf0e10cSrcweir {
488*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
489*cdf0e10cSrcweir     computeChanges();
490*cdf0e10cSrcweir 
491*cdf0e10cSrcweir     if ( m_localKey.is() && m_localKey->isValid() )
492*cdf0e10cSrcweir     {
493*cdf0e10cSrcweir         return m_localKey->getAsciiValue();
494*cdf0e10cSrcweir     } else
495*cdf0e10cSrcweir     if ( m_defaultKey.is() && m_defaultKey->isValid() )
496*cdf0e10cSrcweir     {
497*cdf0e10cSrcweir         return m_defaultKey->getAsciiValue();
498*cdf0e10cSrcweir     } else
499*cdf0e10cSrcweir     {
500*cdf0e10cSrcweir         throw InvalidRegistryException();
501*cdf0e10cSrcweir     }
502*cdf0e10cSrcweir }
503*cdf0e10cSrcweir 
504*cdf0e10cSrcweir //*************************************************************************
505*cdf0e10cSrcweir void SAL_CALL NestedKeyImpl::setAsciiValue( const OUString& value )
506*cdf0e10cSrcweir     throw(InvalidRegistryException, RuntimeException)
507*cdf0e10cSrcweir {
508*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
509*cdf0e10cSrcweir     computeChanges();
510*cdf0e10cSrcweir 
511*cdf0e10cSrcweir     if ( m_localKey.is() && m_localKey->isValid() )
512*cdf0e10cSrcweir     {
513*cdf0e10cSrcweir         m_localKey->setAsciiValue(value);
514*cdf0e10cSrcweir     } else
515*cdf0e10cSrcweir     if ( m_defaultKey.is() && m_defaultKey->isValid() )
516*cdf0e10cSrcweir     {
517*cdf0e10cSrcweir         Reference<XRegistryKey> rootKey(m_pRegistry->m_localReg->getRootKey());
518*cdf0e10cSrcweir         m_localKey = rootKey->createKey(m_name);
519*cdf0e10cSrcweir         m_localKey->setAsciiValue(value);
520*cdf0e10cSrcweir         m_state = m_pRegistry->m_state++;
521*cdf0e10cSrcweir     } else
522*cdf0e10cSrcweir     {
523*cdf0e10cSrcweir         throw InvalidRegistryException();
524*cdf0e10cSrcweir     }
525*cdf0e10cSrcweir }
526*cdf0e10cSrcweir 
527*cdf0e10cSrcweir //*************************************************************************
528*cdf0e10cSrcweir Sequence< OUString > SAL_CALL NestedKeyImpl::getAsciiListValue(  )
529*cdf0e10cSrcweir     throw(InvalidRegistryException, InvalidValueException, RuntimeException)
530*cdf0e10cSrcweir {
531*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
532*cdf0e10cSrcweir     computeChanges();
533*cdf0e10cSrcweir 
534*cdf0e10cSrcweir     if ( m_localKey.is() && m_localKey->isValid() )
535*cdf0e10cSrcweir     {
536*cdf0e10cSrcweir         return m_localKey->getAsciiListValue();
537*cdf0e10cSrcweir     } else
538*cdf0e10cSrcweir     if ( m_defaultKey.is() && m_defaultKey->isValid() )
539*cdf0e10cSrcweir     {
540*cdf0e10cSrcweir         return m_defaultKey->getAsciiListValue();
541*cdf0e10cSrcweir     } else
542*cdf0e10cSrcweir     {
543*cdf0e10cSrcweir         throw InvalidRegistryException();
544*cdf0e10cSrcweir     }
545*cdf0e10cSrcweir }
546*cdf0e10cSrcweir 
547*cdf0e10cSrcweir //*************************************************************************
548*cdf0e10cSrcweir void SAL_CALL NestedKeyImpl::setAsciiListValue( const Sequence< OUString >& seqValue )
549*cdf0e10cSrcweir     throw(InvalidRegistryException, RuntimeException)
550*cdf0e10cSrcweir {
551*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
552*cdf0e10cSrcweir     computeChanges();
553*cdf0e10cSrcweir 
554*cdf0e10cSrcweir     if ( m_localKey.is() && m_localKey->isValid() )
555*cdf0e10cSrcweir     {
556*cdf0e10cSrcweir         m_localKey->setAsciiListValue(seqValue);
557*cdf0e10cSrcweir     } else
558*cdf0e10cSrcweir     if ( m_defaultKey.is() && m_defaultKey->isValid() )
559*cdf0e10cSrcweir     {
560*cdf0e10cSrcweir         Reference<XRegistryKey> rootKey(m_pRegistry->m_localReg->getRootKey());
561*cdf0e10cSrcweir         m_localKey = rootKey->createKey(m_name);
562*cdf0e10cSrcweir         m_localKey->setAsciiListValue(seqValue);
563*cdf0e10cSrcweir         m_state = m_pRegistry->m_state++;
564*cdf0e10cSrcweir     } else
565*cdf0e10cSrcweir     {
566*cdf0e10cSrcweir         throw InvalidRegistryException();
567*cdf0e10cSrcweir     }
568*cdf0e10cSrcweir }
569*cdf0e10cSrcweir 
570*cdf0e10cSrcweir //*************************************************************************
571*cdf0e10cSrcweir OUString SAL_CALL NestedKeyImpl::getStringValue(  )
572*cdf0e10cSrcweir     throw(InvalidRegistryException, InvalidValueException, RuntimeException)
573*cdf0e10cSrcweir {
574*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
575*cdf0e10cSrcweir     computeChanges();
576*cdf0e10cSrcweir 
577*cdf0e10cSrcweir     if ( m_localKey.is() && m_localKey->isValid() )
578*cdf0e10cSrcweir     {
579*cdf0e10cSrcweir         return m_localKey->getStringValue();
580*cdf0e10cSrcweir     } else
581*cdf0e10cSrcweir     if ( m_defaultKey.is() && m_defaultKey->isValid() )
582*cdf0e10cSrcweir     {
583*cdf0e10cSrcweir         return m_defaultKey->getStringValue();
584*cdf0e10cSrcweir     } else
585*cdf0e10cSrcweir     {
586*cdf0e10cSrcweir         throw InvalidRegistryException();
587*cdf0e10cSrcweir     }
588*cdf0e10cSrcweir }
589*cdf0e10cSrcweir 
590*cdf0e10cSrcweir //*************************************************************************
591*cdf0e10cSrcweir void SAL_CALL NestedKeyImpl::setStringValue( const OUString& value )
592*cdf0e10cSrcweir     throw(InvalidRegistryException, RuntimeException)
593*cdf0e10cSrcweir {
594*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
595*cdf0e10cSrcweir     computeChanges();
596*cdf0e10cSrcweir 
597*cdf0e10cSrcweir     if ( m_localKey.is() && m_localKey->isValid() )
598*cdf0e10cSrcweir     {
599*cdf0e10cSrcweir         m_localKey->setStringValue(value);
600*cdf0e10cSrcweir     } else
601*cdf0e10cSrcweir     if ( m_defaultKey.is() && m_defaultKey->isValid() )
602*cdf0e10cSrcweir     {
603*cdf0e10cSrcweir         Reference<XRegistryKey> rootKey(m_pRegistry->m_localReg->getRootKey());
604*cdf0e10cSrcweir         m_localKey = rootKey->createKey(m_name);
605*cdf0e10cSrcweir         m_localKey->setStringValue(value);
606*cdf0e10cSrcweir         m_state = m_pRegistry->m_state++;
607*cdf0e10cSrcweir     } else
608*cdf0e10cSrcweir     {
609*cdf0e10cSrcweir         throw InvalidRegistryException();
610*cdf0e10cSrcweir     }
611*cdf0e10cSrcweir }
612*cdf0e10cSrcweir 
613*cdf0e10cSrcweir //*************************************************************************
614*cdf0e10cSrcweir Sequence< OUString > SAL_CALL NestedKeyImpl::getStringListValue(  )
615*cdf0e10cSrcweir     throw(InvalidRegistryException, InvalidValueException, RuntimeException)
616*cdf0e10cSrcweir {
617*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
618*cdf0e10cSrcweir     computeChanges();
619*cdf0e10cSrcweir 
620*cdf0e10cSrcweir     if ( m_localKey.is() && m_localKey->isValid() )
621*cdf0e10cSrcweir     {
622*cdf0e10cSrcweir         return m_localKey->getStringListValue();
623*cdf0e10cSrcweir     } else
624*cdf0e10cSrcweir     if ( m_defaultKey.is() && m_defaultKey->isValid() )
625*cdf0e10cSrcweir     {
626*cdf0e10cSrcweir         return m_defaultKey->getStringListValue();
627*cdf0e10cSrcweir     } else
628*cdf0e10cSrcweir     {
629*cdf0e10cSrcweir         throw InvalidRegistryException();
630*cdf0e10cSrcweir     }
631*cdf0e10cSrcweir }
632*cdf0e10cSrcweir 
633*cdf0e10cSrcweir //*************************************************************************
634*cdf0e10cSrcweir void SAL_CALL NestedKeyImpl::setStringListValue( const Sequence< OUString >& seqValue )
635*cdf0e10cSrcweir     throw(InvalidRegistryException, RuntimeException)
636*cdf0e10cSrcweir {
637*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
638*cdf0e10cSrcweir     computeChanges();
639*cdf0e10cSrcweir 
640*cdf0e10cSrcweir     if ( m_localKey.is() && m_localKey->isValid() )
641*cdf0e10cSrcweir     {
642*cdf0e10cSrcweir         m_localKey->setStringListValue(seqValue);
643*cdf0e10cSrcweir     } else
644*cdf0e10cSrcweir     if ( m_defaultKey.is() && m_defaultKey->isValid() )
645*cdf0e10cSrcweir     {
646*cdf0e10cSrcweir         Reference<XRegistryKey> rootKey(m_pRegistry->m_localReg->getRootKey());
647*cdf0e10cSrcweir         m_localKey = rootKey->createKey(m_name);
648*cdf0e10cSrcweir         m_localKey->setStringListValue(seqValue);
649*cdf0e10cSrcweir         m_state = m_pRegistry->m_state++;
650*cdf0e10cSrcweir     } else
651*cdf0e10cSrcweir     {
652*cdf0e10cSrcweir         throw InvalidRegistryException();
653*cdf0e10cSrcweir     }
654*cdf0e10cSrcweir }
655*cdf0e10cSrcweir 
656*cdf0e10cSrcweir //*************************************************************************
657*cdf0e10cSrcweir Sequence< sal_Int8 > SAL_CALL NestedKeyImpl::getBinaryValue(  )
658*cdf0e10cSrcweir     throw(InvalidRegistryException, InvalidValueException, RuntimeException)
659*cdf0e10cSrcweir {
660*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
661*cdf0e10cSrcweir     computeChanges();
662*cdf0e10cSrcweir 
663*cdf0e10cSrcweir     if ( m_localKey.is() && m_localKey->isValid() )
664*cdf0e10cSrcweir     {
665*cdf0e10cSrcweir         return m_localKey->getBinaryValue();
666*cdf0e10cSrcweir     } else
667*cdf0e10cSrcweir     if ( m_defaultKey.is() && m_defaultKey->isValid() )
668*cdf0e10cSrcweir     {
669*cdf0e10cSrcweir         return m_defaultKey->getBinaryValue();
670*cdf0e10cSrcweir     } else
671*cdf0e10cSrcweir     {
672*cdf0e10cSrcweir         throw InvalidRegistryException();
673*cdf0e10cSrcweir     }
674*cdf0e10cSrcweir }
675*cdf0e10cSrcweir 
676*cdf0e10cSrcweir //*************************************************************************
677*cdf0e10cSrcweir void SAL_CALL NestedKeyImpl::setBinaryValue( const Sequence< sal_Int8 >& value )
678*cdf0e10cSrcweir     throw(InvalidRegistryException, RuntimeException)
679*cdf0e10cSrcweir {
680*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
681*cdf0e10cSrcweir     computeChanges();
682*cdf0e10cSrcweir 
683*cdf0e10cSrcweir     if ( m_localKey.is() && m_localKey->isValid() )
684*cdf0e10cSrcweir     {
685*cdf0e10cSrcweir         m_localKey->setBinaryValue(value);
686*cdf0e10cSrcweir     } else
687*cdf0e10cSrcweir     if ( m_defaultKey.is() && m_defaultKey->isValid() )
688*cdf0e10cSrcweir     {
689*cdf0e10cSrcweir         Reference<XRegistryKey> rootKey(m_pRegistry->m_localReg->getRootKey());
690*cdf0e10cSrcweir         m_localKey = rootKey->createKey(m_name);
691*cdf0e10cSrcweir         m_localKey->setBinaryValue(value);
692*cdf0e10cSrcweir         m_state = m_pRegistry->m_state++;
693*cdf0e10cSrcweir     } else
694*cdf0e10cSrcweir     {
695*cdf0e10cSrcweir         throw InvalidRegistryException();
696*cdf0e10cSrcweir     }
697*cdf0e10cSrcweir }
698*cdf0e10cSrcweir 
699*cdf0e10cSrcweir //*************************************************************************
700*cdf0e10cSrcweir Reference< XRegistryKey > SAL_CALL NestedKeyImpl::openKey( const OUString& aKeyName )
701*cdf0e10cSrcweir     throw(InvalidRegistryException, RuntimeException)
702*cdf0e10cSrcweir {
703*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
704*cdf0e10cSrcweir     if ( !m_localKey.is() && !m_defaultKey.is() )
705*cdf0e10cSrcweir     {
706*cdf0e10cSrcweir         throw InvalidRegistryException();
707*cdf0e10cSrcweir     }
708*cdf0e10cSrcweir 
709*cdf0e10cSrcweir     OUString resolvedName = computeName(aKeyName);
710*cdf0e10cSrcweir 
711*cdf0e10cSrcweir     if ( resolvedName.getLength() == 0 )
712*cdf0e10cSrcweir         throw InvalidRegistryException();
713*cdf0e10cSrcweir 
714*cdf0e10cSrcweir     Reference<XRegistryKey> localKey, defaultKey;
715*cdf0e10cSrcweir 
716*cdf0e10cSrcweir     if ( m_localKey.is() && m_localKey->isValid() )
717*cdf0e10cSrcweir     {
718*cdf0e10cSrcweir         localKey = m_pRegistry->m_localReg->getRootKey()->openKey(resolvedName);
719*cdf0e10cSrcweir     }
720*cdf0e10cSrcweir     if ( m_defaultKey.is() && m_defaultKey->isValid() )
721*cdf0e10cSrcweir     {
722*cdf0e10cSrcweir         defaultKey = m_pRegistry->m_defaultReg->getRootKey()->openKey(resolvedName);
723*cdf0e10cSrcweir     }
724*cdf0e10cSrcweir 
725*cdf0e10cSrcweir     if ( localKey.is() || defaultKey.is() )
726*cdf0e10cSrcweir     {
727*cdf0e10cSrcweir         return ((XRegistryKey*)new NestedKeyImpl(m_pRegistry, localKey, defaultKey));
728*cdf0e10cSrcweir     } else
729*cdf0e10cSrcweir     {
730*cdf0e10cSrcweir         return Reference<XRegistryKey>();
731*cdf0e10cSrcweir     }
732*cdf0e10cSrcweir }
733*cdf0e10cSrcweir 
734*cdf0e10cSrcweir //*************************************************************************
735*cdf0e10cSrcweir Reference< XRegistryKey > SAL_CALL NestedKeyImpl::createKey( const OUString& aKeyName )
736*cdf0e10cSrcweir     throw(InvalidRegistryException, RuntimeException)
737*cdf0e10cSrcweir {
738*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
739*cdf0e10cSrcweir     if ( (!m_localKey.is() && !m_defaultKey.is()) ||
740*cdf0e10cSrcweir          (m_localKey.is() && m_localKey->isReadOnly()) )
741*cdf0e10cSrcweir     {
742*cdf0e10cSrcweir         throw InvalidRegistryException();
743*cdf0e10cSrcweir     }
744*cdf0e10cSrcweir 
745*cdf0e10cSrcweir     OUString resolvedName = computeName(aKeyName);
746*cdf0e10cSrcweir 
747*cdf0e10cSrcweir     if ( resolvedName.getLength() == 0 )
748*cdf0e10cSrcweir         throw InvalidRegistryException();
749*cdf0e10cSrcweir 
750*cdf0e10cSrcweir     if ( m_localKey.is() && m_localKey->isValid() )
751*cdf0e10cSrcweir     {
752*cdf0e10cSrcweir         Reference<XRegistryKey> localKey, defaultKey;
753*cdf0e10cSrcweir 
754*cdf0e10cSrcweir         localKey = m_pRegistry->m_localReg->getRootKey()->createKey(resolvedName);
755*cdf0e10cSrcweir         if ( localKey.is() )
756*cdf0e10cSrcweir         {
757*cdf0e10cSrcweir             if ( m_defaultKey.is() && m_defaultKey->isValid() )
758*cdf0e10cSrcweir             {
759*cdf0e10cSrcweir                 defaultKey = m_pRegistry->m_defaultReg->getRootKey()->openKey(resolvedName);
760*cdf0e10cSrcweir             }
761*cdf0e10cSrcweir 
762*cdf0e10cSrcweir             m_state = m_pRegistry->m_state++;
763*cdf0e10cSrcweir 
764*cdf0e10cSrcweir             return ((XRegistryKey*)new NestedKeyImpl(m_pRegistry, localKey, defaultKey));
765*cdf0e10cSrcweir         }
766*cdf0e10cSrcweir     } else
767*cdf0e10cSrcweir     {
768*cdf0e10cSrcweir         Reference<XRegistryKey> localKey, defaultKey;
769*cdf0e10cSrcweir 
770*cdf0e10cSrcweir         if ( m_defaultKey.is() && m_defaultKey->isValid() )
771*cdf0e10cSrcweir         {
772*cdf0e10cSrcweir             Reference<XRegistryKey> rootKey(m_pRegistry->m_localReg->getRootKey());
773*cdf0e10cSrcweir             m_localKey = rootKey->createKey(m_name);
774*cdf0e10cSrcweir 
775*cdf0e10cSrcweir             localKey = m_pRegistry->m_localReg->getRootKey()->createKey(resolvedName);
776*cdf0e10cSrcweir 
777*cdf0e10cSrcweir             if ( localKey.is() )
778*cdf0e10cSrcweir             {
779*cdf0e10cSrcweir                 defaultKey = m_pRegistry->m_defaultReg->getRootKey()->openKey(resolvedName);
780*cdf0e10cSrcweir 
781*cdf0e10cSrcweir                 m_state = m_pRegistry->m_state++;
782*cdf0e10cSrcweir 
783*cdf0e10cSrcweir                 return ((XRegistryKey*)new NestedKeyImpl(m_pRegistry, localKey, defaultKey));
784*cdf0e10cSrcweir             }
785*cdf0e10cSrcweir         }
786*cdf0e10cSrcweir     }
787*cdf0e10cSrcweir 
788*cdf0e10cSrcweir     return Reference<XRegistryKey>();
789*cdf0e10cSrcweir }
790*cdf0e10cSrcweir 
791*cdf0e10cSrcweir //*************************************************************************
792*cdf0e10cSrcweir void SAL_CALL NestedKeyImpl::closeKey(  )
793*cdf0e10cSrcweir     throw(InvalidRegistryException, RuntimeException)
794*cdf0e10cSrcweir {
795*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
796*cdf0e10cSrcweir     if ( m_localKey.is() && m_localKey->isValid() )
797*cdf0e10cSrcweir     {
798*cdf0e10cSrcweir         m_localKey->closeKey();
799*cdf0e10cSrcweir     }
800*cdf0e10cSrcweir     if ( m_defaultKey.is() && m_defaultKey->isValid() )
801*cdf0e10cSrcweir     {
802*cdf0e10cSrcweir         m_defaultKey->closeKey();
803*cdf0e10cSrcweir     }
804*cdf0e10cSrcweir }
805*cdf0e10cSrcweir 
806*cdf0e10cSrcweir //*************************************************************************
807*cdf0e10cSrcweir void SAL_CALL NestedKeyImpl::deleteKey( const OUString& rKeyName )
808*cdf0e10cSrcweir     throw(InvalidRegistryException, RuntimeException)
809*cdf0e10cSrcweir {
810*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
811*cdf0e10cSrcweir     if ( m_localKey.is() && m_localKey->isValid() &&
812*cdf0e10cSrcweir          !m_localKey->isReadOnly() )
813*cdf0e10cSrcweir     {
814*cdf0e10cSrcweir         OUString resolvedName = computeName(rKeyName);
815*cdf0e10cSrcweir 
816*cdf0e10cSrcweir         if ( resolvedName.getLength() == 0 )
817*cdf0e10cSrcweir         {
818*cdf0e10cSrcweir             throw InvalidRegistryException();
819*cdf0e10cSrcweir         }
820*cdf0e10cSrcweir 
821*cdf0e10cSrcweir         m_pRegistry->m_localReg->getRootKey()->deleteKey(resolvedName);
822*cdf0e10cSrcweir     } else
823*cdf0e10cSrcweir     {
824*cdf0e10cSrcweir         throw InvalidRegistryException();
825*cdf0e10cSrcweir     }
826*cdf0e10cSrcweir }
827*cdf0e10cSrcweir 
828*cdf0e10cSrcweir //*************************************************************************
829*cdf0e10cSrcweir Sequence< Reference< XRegistryKey > > SAL_CALL NestedKeyImpl::openKeys(  )
830*cdf0e10cSrcweir     throw(InvalidRegistryException, RuntimeException)
831*cdf0e10cSrcweir {
832*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
833*cdf0e10cSrcweir     if ( !m_localKey.is() && !m_defaultKey.is() )
834*cdf0e10cSrcweir     {
835*cdf0e10cSrcweir         throw InvalidRegistryException();
836*cdf0e10cSrcweir     }
837*cdf0e10cSrcweir 
838*cdf0e10cSrcweir     Sequence<OUString> localSeq, defaultSeq;
839*cdf0e10cSrcweir 
840*cdf0e10cSrcweir     if ( m_localKey.is() && m_localKey->isValid() )
841*cdf0e10cSrcweir     {
842*cdf0e10cSrcweir         localSeq = m_localKey->getKeyNames();
843*cdf0e10cSrcweir     }
844*cdf0e10cSrcweir     if ( m_defaultKey.is() && m_defaultKey->isValid() )
845*cdf0e10cSrcweir     {
846*cdf0e10cSrcweir         defaultSeq = m_defaultKey->getKeyNames();
847*cdf0e10cSrcweir     }
848*cdf0e10cSrcweir 
849*cdf0e10cSrcweir     sal_uInt32 local = localSeq.getLength();
850*cdf0e10cSrcweir     sal_uInt32 def = defaultSeq.getLength();
851*cdf0e10cSrcweir     sal_uInt32 len = 0;
852*cdf0e10cSrcweir 
853*cdf0e10cSrcweir     sal_uInt32 i, j;
854*cdf0e10cSrcweir     for (i=0; i < local; i++)
855*cdf0e10cSrcweir     {
856*cdf0e10cSrcweir         for (j=0 ; j < def; j++)
857*cdf0e10cSrcweir         {
858*cdf0e10cSrcweir             if ( localSeq.getConstArray()[i] == defaultSeq.getConstArray()[j] )
859*cdf0e10cSrcweir             {
860*cdf0e10cSrcweir                 len++;
861*cdf0e10cSrcweir                 break;
862*cdf0e10cSrcweir             }
863*cdf0e10cSrcweir         }
864*cdf0e10cSrcweir     }
865*cdf0e10cSrcweir 
866*cdf0e10cSrcweir     Sequence< Reference<XRegistryKey> > retSeq(local + def - len);
867*cdf0e10cSrcweir     sal_Bool                            insert = sal_True;
868*cdf0e10cSrcweir     OUString                            name;
869*cdf0e10cSrcweir     sal_Int32                           lastIndex;
870*cdf0e10cSrcweir 
871*cdf0e10cSrcweir     for (i=0; i < local; i++)
872*cdf0e10cSrcweir     {
873*cdf0e10cSrcweir         name = localSeq.getConstArray()[i];
874*cdf0e10cSrcweir         lastIndex = name.lastIndexOf('/');
875*cdf0e10cSrcweir         name = name.copy(lastIndex);
876*cdf0e10cSrcweir         retSeq.getArray()[i] =
877*cdf0e10cSrcweir             (XRegistryKey*)new NestedKeyImpl(name, this);
878*cdf0e10cSrcweir     }
879*cdf0e10cSrcweir 
880*cdf0e10cSrcweir     sal_uInt32 k = local;
881*cdf0e10cSrcweir     for (i=0; i < def; i++)
882*cdf0e10cSrcweir     {
883*cdf0e10cSrcweir         insert = sal_True;
884*cdf0e10cSrcweir 
885*cdf0e10cSrcweir         for (j=0 ; j < local; j++)
886*cdf0e10cSrcweir         {
887*cdf0e10cSrcweir             if ( retSeq.getConstArray()[j]->getKeyName()
888*cdf0e10cSrcweir                     == defaultSeq.getConstArray()[i] )
889*cdf0e10cSrcweir             {
890*cdf0e10cSrcweir                 insert = sal_False;
891*cdf0e10cSrcweir                 break;
892*cdf0e10cSrcweir             }
893*cdf0e10cSrcweir         }
894*cdf0e10cSrcweir 
895*cdf0e10cSrcweir         if ( insert )
896*cdf0e10cSrcweir         {
897*cdf0e10cSrcweir             name = defaultSeq.getConstArray()[i];
898*cdf0e10cSrcweir             lastIndex = name.lastIndexOf('/');
899*cdf0e10cSrcweir             name = name.copy(lastIndex);
900*cdf0e10cSrcweir             retSeq.getArray()[k++] =
901*cdf0e10cSrcweir                 (XRegistryKey*)new NestedKeyImpl(name, this);
902*cdf0e10cSrcweir         }
903*cdf0e10cSrcweir     }
904*cdf0e10cSrcweir 
905*cdf0e10cSrcweir     return retSeq;
906*cdf0e10cSrcweir }
907*cdf0e10cSrcweir 
908*cdf0e10cSrcweir //*************************************************************************
909*cdf0e10cSrcweir Sequence< OUString > SAL_CALL NestedKeyImpl::getKeyNames(  )
910*cdf0e10cSrcweir     throw(InvalidRegistryException, RuntimeException)
911*cdf0e10cSrcweir {
912*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
913*cdf0e10cSrcweir     if ( !m_localKey.is() && !m_defaultKey.is() )
914*cdf0e10cSrcweir     {
915*cdf0e10cSrcweir         throw InvalidRegistryException();
916*cdf0e10cSrcweir     }
917*cdf0e10cSrcweir 
918*cdf0e10cSrcweir     Sequence<OUString> localSeq, defaultSeq;
919*cdf0e10cSrcweir 
920*cdf0e10cSrcweir     if ( m_localKey.is() && m_localKey->isValid() )
921*cdf0e10cSrcweir     {
922*cdf0e10cSrcweir         localSeq = m_localKey->getKeyNames();
923*cdf0e10cSrcweir     }
924*cdf0e10cSrcweir     if ( m_defaultKey.is() && m_defaultKey->isValid() )
925*cdf0e10cSrcweir     {
926*cdf0e10cSrcweir         defaultSeq = m_defaultKey->getKeyNames();
927*cdf0e10cSrcweir     }
928*cdf0e10cSrcweir 
929*cdf0e10cSrcweir     sal_uInt32 local = localSeq.getLength();
930*cdf0e10cSrcweir     sal_uInt32 def = defaultSeq.getLength();
931*cdf0e10cSrcweir     sal_uInt32 len = 0;
932*cdf0e10cSrcweir 
933*cdf0e10cSrcweir     sal_uInt32 i, j;
934*cdf0e10cSrcweir     for (i=0; i < local; i++)
935*cdf0e10cSrcweir     {
936*cdf0e10cSrcweir         for (j=0 ; j < def; j++)
937*cdf0e10cSrcweir         {
938*cdf0e10cSrcweir             if ( localSeq.getConstArray()[i] == defaultSeq.getConstArray()[j] )
939*cdf0e10cSrcweir             {
940*cdf0e10cSrcweir                 len++;
941*cdf0e10cSrcweir                 break;
942*cdf0e10cSrcweir             }
943*cdf0e10cSrcweir         }
944*cdf0e10cSrcweir     }
945*cdf0e10cSrcweir 
946*cdf0e10cSrcweir     Sequence<OUString>  retSeq(local + def - len);
947*cdf0e10cSrcweir     sal_Bool            insert = sal_True;
948*cdf0e10cSrcweir 
949*cdf0e10cSrcweir     for (i=0; i < local; i++)
950*cdf0e10cSrcweir     {
951*cdf0e10cSrcweir         retSeq.getArray()[i] = localSeq.getConstArray()[i];
952*cdf0e10cSrcweir     }
953*cdf0e10cSrcweir 
954*cdf0e10cSrcweir     sal_uInt32 k = local;
955*cdf0e10cSrcweir     for (i=0; i < def; i++)
956*cdf0e10cSrcweir     {
957*cdf0e10cSrcweir         insert = sal_True;
958*cdf0e10cSrcweir 
959*cdf0e10cSrcweir         for (j=0 ; j < local; j++)
960*cdf0e10cSrcweir         {
961*cdf0e10cSrcweir             if ( retSeq.getConstArray()[j] == defaultSeq.getConstArray()[i] )
962*cdf0e10cSrcweir             {
963*cdf0e10cSrcweir                 insert = sal_False;
964*cdf0e10cSrcweir                 break;
965*cdf0e10cSrcweir             }
966*cdf0e10cSrcweir         }
967*cdf0e10cSrcweir 
968*cdf0e10cSrcweir         if ( insert )
969*cdf0e10cSrcweir             retSeq.getArray()[k++] = defaultSeq.getConstArray()[i];
970*cdf0e10cSrcweir     }
971*cdf0e10cSrcweir 
972*cdf0e10cSrcweir     return retSeq;
973*cdf0e10cSrcweir }
974*cdf0e10cSrcweir 
975*cdf0e10cSrcweir //*************************************************************************
976*cdf0e10cSrcweir sal_Bool SAL_CALL NestedKeyImpl::createLink( const OUString& aLinkName, const OUString& aLinkTarget )
977*cdf0e10cSrcweir     throw(InvalidRegistryException, RuntimeException)
978*cdf0e10cSrcweir {
979*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
980*cdf0e10cSrcweir 
981*cdf0e10cSrcweir     sal_Bool isCreated = sal_False;
982*cdf0e10cSrcweir     if ( !m_localKey.is() && !m_defaultKey.is() )
983*cdf0e10cSrcweir     {
984*cdf0e10cSrcweir         throw InvalidRegistryException();
985*cdf0e10cSrcweir     }
986*cdf0e10cSrcweir 
987*cdf0e10cSrcweir     OUString    linkName;
988*cdf0e10cSrcweir     OUString    resolvedName;
989*cdf0e10cSrcweir     sal_Int32   lastIndex = aLinkName.lastIndexOf('/');
990*cdf0e10cSrcweir 
991*cdf0e10cSrcweir     if ( lastIndex > 0 )
992*cdf0e10cSrcweir     {
993*cdf0e10cSrcweir         linkName = aLinkName.copy(0, lastIndex);
994*cdf0e10cSrcweir 
995*cdf0e10cSrcweir         resolvedName = computeName(linkName);
996*cdf0e10cSrcweir 
997*cdf0e10cSrcweir         if ( resolvedName.getLength() == 0 )
998*cdf0e10cSrcweir         {
999*cdf0e10cSrcweir             throw InvalidRegistryException();
1000*cdf0e10cSrcweir         }
1001*cdf0e10cSrcweir 
1002*cdf0e10cSrcweir         resolvedName = resolvedName + aLinkName.copy(lastIndex);
1003*cdf0e10cSrcweir     } else
1004*cdf0e10cSrcweir     {
1005*cdf0e10cSrcweir         if ( lastIndex == 0 )
1006*cdf0e10cSrcweir             resolvedName = m_name + aLinkName;
1007*cdf0e10cSrcweir         else
1008*cdf0e10cSrcweir             resolvedName = m_name + OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) + aLinkName;
1009*cdf0e10cSrcweir     }
1010*cdf0e10cSrcweir 
1011*cdf0e10cSrcweir     if ( m_localKey.is() && m_localKey->isValid() )
1012*cdf0e10cSrcweir     {
1013*cdf0e10cSrcweir         isCreated = m_pRegistry->m_localReg->getRootKey()->createLink(resolvedName, aLinkTarget);
1014*cdf0e10cSrcweir     } else
1015*cdf0e10cSrcweir     {
1016*cdf0e10cSrcweir         if ( m_defaultKey.is() && m_defaultKey->isValid() )
1017*cdf0e10cSrcweir         {
1018*cdf0e10cSrcweir             Reference<XRegistryKey> rootKey(m_pRegistry->m_localReg->getRootKey());
1019*cdf0e10cSrcweir             m_localKey = rootKey->createKey(m_name);
1020*cdf0e10cSrcweir 
1021*cdf0e10cSrcweir             isCreated = m_pRegistry->m_localReg->getRootKey()->createLink(resolvedName, aLinkTarget);
1022*cdf0e10cSrcweir         }
1023*cdf0e10cSrcweir     }
1024*cdf0e10cSrcweir 
1025*cdf0e10cSrcweir     if ( isCreated )
1026*cdf0e10cSrcweir         m_state = m_pRegistry->m_state++;
1027*cdf0e10cSrcweir 
1028*cdf0e10cSrcweir     return isCreated;
1029*cdf0e10cSrcweir }
1030*cdf0e10cSrcweir 
1031*cdf0e10cSrcweir //*************************************************************************
1032*cdf0e10cSrcweir void SAL_CALL NestedKeyImpl::deleteLink( const OUString& rLinkName )
1033*cdf0e10cSrcweir     throw(InvalidRegistryException, RuntimeException)
1034*cdf0e10cSrcweir {
1035*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
1036*cdf0e10cSrcweir     if ( !m_localKey.is() && !m_defaultKey.is() )
1037*cdf0e10cSrcweir     {
1038*cdf0e10cSrcweir         throw InvalidRegistryException();
1039*cdf0e10cSrcweir     }
1040*cdf0e10cSrcweir 
1041*cdf0e10cSrcweir     OUString    linkName;
1042*cdf0e10cSrcweir     OUString    resolvedName;
1043*cdf0e10cSrcweir     sal_Int32   lastIndex = rLinkName.lastIndexOf('/');
1044*cdf0e10cSrcweir 
1045*cdf0e10cSrcweir     if ( lastIndex > 0 )
1046*cdf0e10cSrcweir     {
1047*cdf0e10cSrcweir         linkName = rLinkName.copy(0, lastIndex);
1048*cdf0e10cSrcweir 
1049*cdf0e10cSrcweir         resolvedName = computeName(linkName);
1050*cdf0e10cSrcweir 
1051*cdf0e10cSrcweir         if ( resolvedName.getLength() == 0 )
1052*cdf0e10cSrcweir         {
1053*cdf0e10cSrcweir             throw InvalidRegistryException();
1054*cdf0e10cSrcweir         }
1055*cdf0e10cSrcweir 
1056*cdf0e10cSrcweir         resolvedName = resolvedName + rLinkName.copy(lastIndex);
1057*cdf0e10cSrcweir     } else
1058*cdf0e10cSrcweir     {
1059*cdf0e10cSrcweir         if ( lastIndex == 0 )
1060*cdf0e10cSrcweir             resolvedName = m_name + rLinkName;
1061*cdf0e10cSrcweir         else
1062*cdf0e10cSrcweir             resolvedName = m_name + OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) + rLinkName;
1063*cdf0e10cSrcweir     }
1064*cdf0e10cSrcweir 
1065*cdf0e10cSrcweir     if ( m_localKey.is() && m_localKey->isValid() &&
1066*cdf0e10cSrcweir          !m_localKey->isReadOnly() )
1067*cdf0e10cSrcweir     {
1068*cdf0e10cSrcweir         m_pRegistry->m_localReg->getRootKey()->deleteLink(resolvedName);
1069*cdf0e10cSrcweir     } else
1070*cdf0e10cSrcweir     {
1071*cdf0e10cSrcweir         throw InvalidRegistryException();
1072*cdf0e10cSrcweir     }
1073*cdf0e10cSrcweir }
1074*cdf0e10cSrcweir 
1075*cdf0e10cSrcweir //*************************************************************************
1076*cdf0e10cSrcweir OUString SAL_CALL NestedKeyImpl::getLinkTarget( const OUString& rLinkName )
1077*cdf0e10cSrcweir     throw(InvalidRegistryException, RuntimeException)
1078*cdf0e10cSrcweir {
1079*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
1080*cdf0e10cSrcweir     if ( !m_localKey.is() && !m_defaultKey.is() )
1081*cdf0e10cSrcweir     {
1082*cdf0e10cSrcweir         throw InvalidRegistryException();
1083*cdf0e10cSrcweir     }
1084*cdf0e10cSrcweir 
1085*cdf0e10cSrcweir     OUString    linkName;
1086*cdf0e10cSrcweir     OUString    resolvedName;
1087*cdf0e10cSrcweir     sal_Int32   lastIndex = rLinkName.lastIndexOf('/');
1088*cdf0e10cSrcweir 
1089*cdf0e10cSrcweir     if ( lastIndex > 0 )
1090*cdf0e10cSrcweir     {
1091*cdf0e10cSrcweir         linkName = rLinkName.copy(0, lastIndex);
1092*cdf0e10cSrcweir 
1093*cdf0e10cSrcweir         resolvedName = computeName(linkName);
1094*cdf0e10cSrcweir 
1095*cdf0e10cSrcweir         if ( resolvedName.getLength() == 0 )
1096*cdf0e10cSrcweir         {
1097*cdf0e10cSrcweir             throw InvalidRegistryException();
1098*cdf0e10cSrcweir         }
1099*cdf0e10cSrcweir 
1100*cdf0e10cSrcweir         resolvedName = resolvedName + rLinkName.copy(lastIndex);
1101*cdf0e10cSrcweir     } else
1102*cdf0e10cSrcweir     {
1103*cdf0e10cSrcweir         if ( lastIndex == 0 )
1104*cdf0e10cSrcweir             resolvedName = m_name + rLinkName;
1105*cdf0e10cSrcweir         else
1106*cdf0e10cSrcweir             resolvedName = m_name + OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) + rLinkName;
1107*cdf0e10cSrcweir     }
1108*cdf0e10cSrcweir 
1109*cdf0e10cSrcweir     OUString linkTarget;
1110*cdf0e10cSrcweir     if ( m_localKey.is() && m_localKey->isValid() )
1111*cdf0e10cSrcweir     {
1112*cdf0e10cSrcweir         try
1113*cdf0e10cSrcweir         {
1114*cdf0e10cSrcweir             linkTarget = m_pRegistry->m_localReg->getRootKey()->getLinkTarget(resolvedName);
1115*cdf0e10cSrcweir             return linkTarget;
1116*cdf0e10cSrcweir         }
1117*cdf0e10cSrcweir         catch(InvalidRegistryException& )
1118*cdf0e10cSrcweir         {
1119*cdf0e10cSrcweir         }
1120*cdf0e10cSrcweir     }
1121*cdf0e10cSrcweir 
1122*cdf0e10cSrcweir     if ( m_defaultKey.is() && m_defaultKey->isValid() )
1123*cdf0e10cSrcweir         linkTarget = m_pRegistry->m_defaultReg->getRootKey()->getLinkTarget(resolvedName);
1124*cdf0e10cSrcweir 
1125*cdf0e10cSrcweir     return linkTarget;
1126*cdf0e10cSrcweir }
1127*cdf0e10cSrcweir 
1128*cdf0e10cSrcweir //*************************************************************************
1129*cdf0e10cSrcweir OUString SAL_CALL NestedKeyImpl::getResolvedName( const OUString& aKeyName )
1130*cdf0e10cSrcweir     throw(InvalidRegistryException, RuntimeException)
1131*cdf0e10cSrcweir {
1132*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
1133*cdf0e10cSrcweir     if ( !m_localKey.is() && !m_defaultKey.is() )
1134*cdf0e10cSrcweir     {
1135*cdf0e10cSrcweir         throw InvalidRegistryException();
1136*cdf0e10cSrcweir     }
1137*cdf0e10cSrcweir 
1138*cdf0e10cSrcweir     OUString resolvedName = computeName(aKeyName);
1139*cdf0e10cSrcweir 
1140*cdf0e10cSrcweir     if ( resolvedName.getLength() == 0 )
1141*cdf0e10cSrcweir     {
1142*cdf0e10cSrcweir         throw InvalidRegistryException();
1143*cdf0e10cSrcweir     }
1144*cdf0e10cSrcweir 
1145*cdf0e10cSrcweir     return resolvedName;
1146*cdf0e10cSrcweir }
1147*cdf0e10cSrcweir 
1148*cdf0e10cSrcweir //*************************************************************************
1149*cdf0e10cSrcweir //
1150*cdf0e10cSrcweir // DefaultRegistry Implementation
1151*cdf0e10cSrcweir //
1152*cdf0e10cSrcweir //*************************************************************************
1153*cdf0e10cSrcweir NestedRegistryImpl::NestedRegistryImpl( )
1154*cdf0e10cSrcweir     : m_state(0)
1155*cdf0e10cSrcweir {
1156*cdf0e10cSrcweir     g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
1157*cdf0e10cSrcweir }
1158*cdf0e10cSrcweir 
1159*cdf0e10cSrcweir //*************************************************************************
1160*cdf0e10cSrcweir NestedRegistryImpl::~NestedRegistryImpl()
1161*cdf0e10cSrcweir {
1162*cdf0e10cSrcweir     g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
1163*cdf0e10cSrcweir }
1164*cdf0e10cSrcweir 
1165*cdf0e10cSrcweir 
1166*cdf0e10cSrcweir class RegistryEnumueration : public WeakImplHelper1< XEnumeration >
1167*cdf0e10cSrcweir {
1168*cdf0e10cSrcweir public:
1169*cdf0e10cSrcweir     RegistryEnumueration(
1170*cdf0e10cSrcweir         const Reference< XSimpleRegistry > &r1,
1171*cdf0e10cSrcweir         const Reference< XSimpleRegistry > &r2 )
1172*cdf0e10cSrcweir         : m_xReg1( r1 ) , m_xReg2( r2 )
1173*cdf0e10cSrcweir         {}
1174*cdf0e10cSrcweir public:
1175*cdf0e10cSrcweir     virtual sal_Bool SAL_CALL hasMoreElements(  ) throw (RuntimeException);
1176*cdf0e10cSrcweir     virtual Any SAL_CALL nextElement(  ) throw (NoSuchElementException, WrappedTargetException, RuntimeException);
1177*cdf0e10cSrcweir 
1178*cdf0e10cSrcweir private:
1179*cdf0e10cSrcweir     Reference< XSimpleRegistry > m_xReg1;
1180*cdf0e10cSrcweir     Reference< XSimpleRegistry > m_xReg2;
1181*cdf0e10cSrcweir };
1182*cdf0e10cSrcweir 
1183*cdf0e10cSrcweir sal_Bool RegistryEnumueration::hasMoreElements(  ) throw (RuntimeException)
1184*cdf0e10cSrcweir {
1185*cdf0e10cSrcweir     return m_xReg1.is() || m_xReg2.is();
1186*cdf0e10cSrcweir }
1187*cdf0e10cSrcweir 
1188*cdf0e10cSrcweir Any RegistryEnumueration::nextElement(  )
1189*cdf0e10cSrcweir     throw (NoSuchElementException, WrappedTargetException, RuntimeException)
1190*cdf0e10cSrcweir {
1191*cdf0e10cSrcweir     Any a;
1192*cdf0e10cSrcweir     if( m_xReg1.is() )
1193*cdf0e10cSrcweir     {
1194*cdf0e10cSrcweir         a <<= m_xReg1;
1195*cdf0e10cSrcweir         m_xReg1.clear();
1196*cdf0e10cSrcweir     }
1197*cdf0e10cSrcweir     else if( m_xReg2.is() )
1198*cdf0e10cSrcweir     {
1199*cdf0e10cSrcweir         a <<= m_xReg2;
1200*cdf0e10cSrcweir         m_xReg2.clear();
1201*cdf0e10cSrcweir     }
1202*cdf0e10cSrcweir     else
1203*cdf0e10cSrcweir     {
1204*cdf0e10cSrcweir         throw NoSuchElementException( OUString( RTL_CONSTASCII_USTRINGPARAM(
1205*cdf0e10cSrcweir             "NestedRegistry: no nextElement() !" ) ),Reference< XInterface > () );
1206*cdf0e10cSrcweir     }
1207*cdf0e10cSrcweir     return a;
1208*cdf0e10cSrcweir }
1209*cdf0e10cSrcweir 
1210*cdf0e10cSrcweir 
1211*cdf0e10cSrcweir Reference< XEnumeration > NestedRegistryImpl::createEnumeration(  ) throw (RuntimeException)
1212*cdf0e10cSrcweir {
1213*cdf0e10cSrcweir     MutexGuard guard( m_mutex );
1214*cdf0e10cSrcweir     return new RegistryEnumueration( m_localReg, m_defaultReg );
1215*cdf0e10cSrcweir }
1216*cdf0e10cSrcweir 
1217*cdf0e10cSrcweir Type NestedRegistryImpl::getElementType(  ) throw (RuntimeException)
1218*cdf0e10cSrcweir {
1219*cdf0e10cSrcweir     return getCppuType( &m_localReg );
1220*cdf0e10cSrcweir }
1221*cdf0e10cSrcweir 
1222*cdf0e10cSrcweir sal_Bool SAL_CALL NestedRegistryImpl::hasElements(  ) throw (RuntimeException)
1223*cdf0e10cSrcweir {
1224*cdf0e10cSrcweir     MutexGuard guard( m_mutex );
1225*cdf0e10cSrcweir     return m_localReg.is() || m_defaultReg.is();
1226*cdf0e10cSrcweir }
1227*cdf0e10cSrcweir 
1228*cdf0e10cSrcweir 
1229*cdf0e10cSrcweir 
1230*cdf0e10cSrcweir //*************************************************************************
1231*cdf0e10cSrcweir OUString SAL_CALL NestedRegistryImpl::getImplementationName(  )
1232*cdf0e10cSrcweir     throw(RuntimeException)
1233*cdf0e10cSrcweir {
1234*cdf0e10cSrcweir     return stoc_bootstrap::defreg_getImplementationName();
1235*cdf0e10cSrcweir }
1236*cdf0e10cSrcweir 
1237*cdf0e10cSrcweir //*************************************************************************
1238*cdf0e10cSrcweir sal_Bool SAL_CALL NestedRegistryImpl::supportsService( const OUString& ServiceName )
1239*cdf0e10cSrcweir     throw(RuntimeException)
1240*cdf0e10cSrcweir {
1241*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_mutex );
1242*cdf0e10cSrcweir     Sequence< OUString > aSNL = getSupportedServiceNames();
1243*cdf0e10cSrcweir     const OUString * pArray = aSNL.getArray();
1244*cdf0e10cSrcweir     for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
1245*cdf0e10cSrcweir         if( pArray[i] == ServiceName )
1246*cdf0e10cSrcweir             return sal_True;
1247*cdf0e10cSrcweir     return sal_False;
1248*cdf0e10cSrcweir }
1249*cdf0e10cSrcweir 
1250*cdf0e10cSrcweir //*************************************************************************
1251*cdf0e10cSrcweir Sequence<OUString> SAL_CALL NestedRegistryImpl::getSupportedServiceNames(  )
1252*cdf0e10cSrcweir     throw(RuntimeException)
1253*cdf0e10cSrcweir {
1254*cdf0e10cSrcweir     return stoc_bootstrap::defreg_getSupportedServiceNames();
1255*cdf0e10cSrcweir }
1256*cdf0e10cSrcweir 
1257*cdf0e10cSrcweir //*************************************************************************
1258*cdf0e10cSrcweir void SAL_CALL NestedRegistryImpl::initialize( const Sequence< Any >& aArguments )
1259*cdf0e10cSrcweir     throw( Exception, RuntimeException )
1260*cdf0e10cSrcweir {
1261*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_mutex );
1262*cdf0e10cSrcweir     if ( (aArguments.getLength() == 2) &&
1263*cdf0e10cSrcweir          (aArguments[0].getValueType().getTypeClass() == TypeClass_INTERFACE) &&
1264*cdf0e10cSrcweir          (aArguments[1].getValueType().getTypeClass() == TypeClass_INTERFACE) )
1265*cdf0e10cSrcweir     {
1266*cdf0e10cSrcweir         aArguments[0] >>= m_localReg;
1267*cdf0e10cSrcweir         aArguments[1] >>= m_defaultReg;
1268*cdf0e10cSrcweir         if ( m_localReg == m_defaultReg )
1269*cdf0e10cSrcweir             m_defaultReg = Reference< XSimpleRegistry >();
1270*cdf0e10cSrcweir     }
1271*cdf0e10cSrcweir }
1272*cdf0e10cSrcweir 
1273*cdf0e10cSrcweir //*************************************************************************
1274*cdf0e10cSrcweir OUString SAL_CALL NestedRegistryImpl::getURL() throw(RuntimeException)
1275*cdf0e10cSrcweir {
1276*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_mutex );
1277*cdf0e10cSrcweir     try
1278*cdf0e10cSrcweir     {
1279*cdf0e10cSrcweir         if ( m_localReg.is() && m_localReg->isValid() )
1280*cdf0e10cSrcweir             return m_localReg->getURL();
1281*cdf0e10cSrcweir     }
1282*cdf0e10cSrcweir     catch(InvalidRegistryException& )
1283*cdf0e10cSrcweir     {
1284*cdf0e10cSrcweir     }
1285*cdf0e10cSrcweir 
1286*cdf0e10cSrcweir     return OUString();
1287*cdf0e10cSrcweir }
1288*cdf0e10cSrcweir 
1289*cdf0e10cSrcweir //*************************************************************************
1290*cdf0e10cSrcweir void SAL_CALL NestedRegistryImpl::open( const OUString&, sal_Bool, sal_Bool )
1291*cdf0e10cSrcweir     throw(InvalidRegistryException, RuntimeException)
1292*cdf0e10cSrcweir {
1293*cdf0e10cSrcweir     throw InvalidRegistryException(
1294*cdf0e10cSrcweir             OUString::createFromAscii("the 'open' method is not specified for a nested registry"),
1295*cdf0e10cSrcweir             Reference< XInterface >() );
1296*cdf0e10cSrcweir }
1297*cdf0e10cSrcweir 
1298*cdf0e10cSrcweir //*************************************************************************
1299*cdf0e10cSrcweir sal_Bool SAL_CALL NestedRegistryImpl::isValid(  ) throw(RuntimeException)
1300*cdf0e10cSrcweir {
1301*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_mutex );
1302*cdf0e10cSrcweir     try
1303*cdf0e10cSrcweir     {
1304*cdf0e10cSrcweir         if ( (m_localReg.is() && m_localReg->isValid()) ||
1305*cdf0e10cSrcweir              (m_defaultReg.is() && m_defaultReg->isValid()) )
1306*cdf0e10cSrcweir             return sal_True;
1307*cdf0e10cSrcweir     }
1308*cdf0e10cSrcweir     catch(InvalidRegistryException& )
1309*cdf0e10cSrcweir     {
1310*cdf0e10cSrcweir     }
1311*cdf0e10cSrcweir 
1312*cdf0e10cSrcweir     return sal_False;
1313*cdf0e10cSrcweir }
1314*cdf0e10cSrcweir 
1315*cdf0e10cSrcweir //*************************************************************************
1316*cdf0e10cSrcweir void SAL_CALL NestedRegistryImpl::close(  )
1317*cdf0e10cSrcweir     throw(InvalidRegistryException, RuntimeException)
1318*cdf0e10cSrcweir {
1319*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_mutex );
1320*cdf0e10cSrcweir     if ( m_localReg.is() && m_localReg->isValid() )
1321*cdf0e10cSrcweir     {
1322*cdf0e10cSrcweir         m_localReg->close();
1323*cdf0e10cSrcweir     }
1324*cdf0e10cSrcweir     if ( m_defaultReg.is() && m_defaultReg->isValid() )
1325*cdf0e10cSrcweir     {
1326*cdf0e10cSrcweir         m_defaultReg->close();
1327*cdf0e10cSrcweir     }
1328*cdf0e10cSrcweir /*
1329*cdf0e10cSrcweir     throw InvalidRegistryException(
1330*cdf0e10cSrcweir             OUString::createFromAscii("the 'close' method is not specified for a nested registry"),
1331*cdf0e10cSrcweir             Reference< XInterface >() );
1332*cdf0e10cSrcweir */
1333*cdf0e10cSrcweir }
1334*cdf0e10cSrcweir 
1335*cdf0e10cSrcweir //*************************************************************************
1336*cdf0e10cSrcweir void SAL_CALL NestedRegistryImpl::destroy(  )
1337*cdf0e10cSrcweir     throw(InvalidRegistryException, RuntimeException)
1338*cdf0e10cSrcweir {
1339*cdf0e10cSrcweir     throw InvalidRegistryException(
1340*cdf0e10cSrcweir             OUString::createFromAscii("the 'destroy' method is not specified for a nested registry"),
1341*cdf0e10cSrcweir             Reference< XInterface >() );
1342*cdf0e10cSrcweir }
1343*cdf0e10cSrcweir 
1344*cdf0e10cSrcweir //*************************************************************************
1345*cdf0e10cSrcweir Reference< XRegistryKey > SAL_CALL NestedRegistryImpl::getRootKey(  )
1346*cdf0e10cSrcweir     throw(InvalidRegistryException, RuntimeException)
1347*cdf0e10cSrcweir {
1348*cdf0e10cSrcweir     Reference<XRegistryKey> tmpKey;
1349*cdf0e10cSrcweir 
1350*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_mutex );
1351*cdf0e10cSrcweir     if ( m_localReg.is() && m_localReg->isValid() )
1352*cdf0e10cSrcweir     {
1353*cdf0e10cSrcweir         Reference<XRegistryKey> localKey, defaultKey;
1354*cdf0e10cSrcweir 
1355*cdf0e10cSrcweir         localKey = m_localReg->getRootKey();
1356*cdf0e10cSrcweir 
1357*cdf0e10cSrcweir         if ( localKey.is() )
1358*cdf0e10cSrcweir         {
1359*cdf0e10cSrcweir             if ( m_defaultReg.is() && m_defaultReg->isValid() )
1360*cdf0e10cSrcweir             {
1361*cdf0e10cSrcweir                 defaultKey = m_defaultReg->getRootKey();
1362*cdf0e10cSrcweir             }
1363*cdf0e10cSrcweir 
1364*cdf0e10cSrcweir             return ((XRegistryKey*)new NestedKeyImpl(this, localKey, defaultKey));
1365*cdf0e10cSrcweir         }
1366*cdf0e10cSrcweir     } else
1367*cdf0e10cSrcweir     {
1368*cdf0e10cSrcweir         throw InvalidRegistryException();
1369*cdf0e10cSrcweir     }
1370*cdf0e10cSrcweir 
1371*cdf0e10cSrcweir     return Reference<XRegistryKey>();
1372*cdf0e10cSrcweir }
1373*cdf0e10cSrcweir 
1374*cdf0e10cSrcweir //*************************************************************************
1375*cdf0e10cSrcweir sal_Bool SAL_CALL NestedRegistryImpl::isReadOnly(  )
1376*cdf0e10cSrcweir     throw(InvalidRegistryException, RuntimeException)
1377*cdf0e10cSrcweir {
1378*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_mutex );
1379*cdf0e10cSrcweir     try
1380*cdf0e10cSrcweir     {
1381*cdf0e10cSrcweir         if ( m_localReg.is() && m_localReg->isValid() )
1382*cdf0e10cSrcweir             return m_localReg->isReadOnly();
1383*cdf0e10cSrcweir     }
1384*cdf0e10cSrcweir     catch(InvalidRegistryException& )
1385*cdf0e10cSrcweir     {
1386*cdf0e10cSrcweir     }
1387*cdf0e10cSrcweir 
1388*cdf0e10cSrcweir     return sal_False;
1389*cdf0e10cSrcweir }
1390*cdf0e10cSrcweir 
1391*cdf0e10cSrcweir //*************************************************************************
1392*cdf0e10cSrcweir void SAL_CALL NestedRegistryImpl::mergeKey( const OUString& aKeyName, const OUString& aUrl )
1393*cdf0e10cSrcweir     throw(InvalidRegistryException, MergeConflictException, RuntimeException)
1394*cdf0e10cSrcweir {
1395*cdf0e10cSrcweir     Guard< Mutex > aGuard( m_mutex );
1396*cdf0e10cSrcweir     if ( m_localReg.is() && m_localReg->isValid() )
1397*cdf0e10cSrcweir     {
1398*cdf0e10cSrcweir         m_localReg->mergeKey(aKeyName, aUrl);
1399*cdf0e10cSrcweir 
1400*cdf0e10cSrcweir         m_state++;
1401*cdf0e10cSrcweir     }
1402*cdf0e10cSrcweir }
1403*cdf0e10cSrcweir } // namespace stco_defreg
1404*cdf0e10cSrcweir 
1405*cdf0e10cSrcweir namespace stoc_bootstrap
1406*cdf0e10cSrcweir {
1407*cdf0e10cSrcweir //*************************************************************************
1408*cdf0e10cSrcweir Reference<XInterface> SAL_CALL NestedRegistry_CreateInstance( const Reference<XComponentContext>& )
1409*cdf0e10cSrcweir     throw(Exception)
1410*cdf0e10cSrcweir {
1411*cdf0e10cSrcweir     Reference<XInterface>   xRet;
1412*cdf0e10cSrcweir     XSimpleRegistry *pRegistry = (XSimpleRegistry*) new stoc_defreg::NestedRegistryImpl;
1413*cdf0e10cSrcweir 
1414*cdf0e10cSrcweir     if (pRegistry)
1415*cdf0e10cSrcweir     {
1416*cdf0e10cSrcweir         xRet = Reference<XInterface>::query(pRegistry);
1417*cdf0e10cSrcweir     }
1418*cdf0e10cSrcweir 
1419*cdf0e10cSrcweir     return xRet;
1420*cdf0e10cSrcweir }
1421*cdf0e10cSrcweir 
1422*cdf0e10cSrcweir }
1423*cdf0e10cSrcweir 
1424