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