1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <osl/mutex.hxx>
21 #include <osl/diagnose.h>
22 #include <cppuhelper/queryinterface.hxx>
23 #include <cppuhelper/weak.hxx>
24 #include <cppuhelper/implbase1.hxx>
25 #include <cppuhelper/implbase4.hxx>
26 #include <cppuhelper/implbase3.hxx>
27 #include <cppuhelper/implementationentry.hxx>
28 #include <cppuhelper/supportsservice.hxx>
29 #include <registry/registry.hxx>
30 #include <rtl/ref.hxx>
32 #include <com/sun/star/registry/XSimpleRegistry.hpp>
33 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34 #include <com/sun/star/lang/XServiceInfo.hpp>
35 #include <com/sun/star/lang/XTypeProvider.hpp>
36 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
37 #include <com/sun/star/lang/XInitialization.hpp>
38 #include <com/sun/star/container/XEnumerationAccess.hpp>
40 using namespace css::uno
;
41 using namespace css::registry
;
42 using namespace css::lang
;
43 using namespace css::container
;
51 class NestedRegistryImpl
: public WeakAggImplHelper4
< XSimpleRegistry
, XInitialization
, XServiceInfo
, XEnumerationAccess
>
54 NestedRegistryImpl( );
56 virtual ~NestedRegistryImpl();
59 virtual OUString SAL_CALL
getImplementationName( ) throw(RuntimeException
, std::exception
) SAL_OVERRIDE
;
60 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) throw(RuntimeException
, std::exception
) SAL_OVERRIDE
;
61 virtual Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) throw(RuntimeException
, std::exception
) SAL_OVERRIDE
;
64 virtual void SAL_CALL
initialize( const Sequence
< Any
>& aArguments
)
65 throw(Exception
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
68 virtual OUString SAL_CALL
getURL() throw(RuntimeException
, std::exception
) SAL_OVERRIDE
;
69 virtual void SAL_CALL
open( const OUString
& rURL
, sal_Bool bReadOnly
, sal_Bool bCreate
) throw(InvalidRegistryException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
70 virtual sal_Bool SAL_CALL
isValid( ) throw(RuntimeException
, std::exception
) SAL_OVERRIDE
;
71 virtual void SAL_CALL
close( ) throw(InvalidRegistryException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
72 virtual void SAL_CALL
destroy( ) throw(InvalidRegistryException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
73 virtual Reference
< XRegistryKey
> SAL_CALL
getRootKey( ) throw(InvalidRegistryException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
74 virtual sal_Bool SAL_CALL
isReadOnly( ) throw(InvalidRegistryException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
75 virtual void SAL_CALL
mergeKey( const OUString
& aKeyName
, const OUString
& aUrl
) throw(InvalidRegistryException
, MergeConflictException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
78 virtual Reference
< XEnumeration
> SAL_CALL
createEnumeration( ) throw (RuntimeException
, std::exception
) SAL_OVERRIDE
;
79 virtual Type SAL_CALL
getElementType( ) throw (RuntimeException
, std::exception
) SAL_OVERRIDE
;
80 virtual sal_Bool SAL_CALL
hasElements( ) throw (RuntimeException
, std::exception
) SAL_OVERRIDE
;
82 friend class NestedKeyImpl
;
86 Reference
<XSimpleRegistry
> m_localReg
;
87 Reference
<XSimpleRegistry
> m_defaultReg
;
92 // class NestedKeyImpl the implenetation of interface XRegistryKey
94 class NestedKeyImpl
: public WeakImplHelper1
< XRegistryKey
>
97 NestedKeyImpl( NestedRegistryImpl
* pDefaultRegistry
,
98 Reference
<XRegistryKey
>& localKey
,
99 Reference
<XRegistryKey
>& defaultKey
);
101 NestedKeyImpl( const OUString
& aKeyName
,
102 NestedKeyImpl
* pKey
);
104 virtual ~NestedKeyImpl();
107 virtual OUString SAL_CALL
getKeyName() throw(RuntimeException
, std::exception
) SAL_OVERRIDE
;
108 virtual sal_Bool SAL_CALL
isReadOnly( ) throw(InvalidRegistryException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
109 virtual sal_Bool SAL_CALL
isValid( ) throw(RuntimeException
, std::exception
) SAL_OVERRIDE
;
110 virtual RegistryKeyType SAL_CALL
getKeyType( const OUString
& rKeyName
) throw(InvalidRegistryException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
111 virtual RegistryValueType SAL_CALL
getValueType( ) throw(InvalidRegistryException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
112 virtual sal_Int32 SAL_CALL
getLongValue( ) throw(InvalidRegistryException
, InvalidValueException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
113 virtual void SAL_CALL
setLongValue( sal_Int32 value
) throw(InvalidRegistryException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
114 virtual Sequence
< sal_Int32
> SAL_CALL
getLongListValue( ) throw(InvalidRegistryException
, InvalidValueException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
115 virtual void SAL_CALL
setLongListValue( const css::uno::Sequence
< sal_Int32
>& seqValue
) throw(InvalidRegistryException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
116 virtual OUString SAL_CALL
getAsciiValue( ) throw(InvalidRegistryException
, InvalidValueException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
117 virtual void SAL_CALL
setAsciiValue( const OUString
& value
) throw(InvalidRegistryException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
118 virtual Sequence
< OUString
> SAL_CALL
getAsciiListValue( ) throw(InvalidRegistryException
, InvalidValueException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
119 virtual void SAL_CALL
setAsciiListValue( const css::uno::Sequence
< OUString
>& seqValue
) throw(InvalidRegistryException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
120 virtual OUString SAL_CALL
getStringValue( ) throw(InvalidRegistryException
, InvalidValueException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
121 virtual void SAL_CALL
setStringValue( const OUString
& value
) throw(InvalidRegistryException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
122 virtual Sequence
< OUString
> SAL_CALL
getStringListValue( ) throw(InvalidRegistryException
, InvalidValueException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
123 virtual void SAL_CALL
setStringListValue( const css::uno::Sequence
< OUString
>& seqValue
) throw(InvalidRegistryException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
124 virtual Sequence
< sal_Int8
> SAL_CALL
getBinaryValue( ) throw(InvalidRegistryException
, InvalidValueException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
125 virtual void SAL_CALL
setBinaryValue( const css::uno::Sequence
< sal_Int8
>& value
) throw(InvalidRegistryException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
126 virtual Reference
< XRegistryKey
> SAL_CALL
openKey( const OUString
& aKeyName
) throw(InvalidRegistryException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
127 virtual Reference
< XRegistryKey
> SAL_CALL
createKey( const OUString
& aKeyName
) throw(InvalidRegistryException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
128 virtual void SAL_CALL
closeKey( ) throw(InvalidRegistryException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
129 virtual void SAL_CALL
deleteKey( const OUString
& rKeyName
) throw(InvalidRegistryException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
130 virtual Sequence
< Reference
< XRegistryKey
> > SAL_CALL
openKeys( ) throw(InvalidRegistryException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
131 virtual Sequence
< OUString
> SAL_CALL
getKeyNames( ) throw(InvalidRegistryException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
132 virtual sal_Bool SAL_CALL
createLink( const OUString
& aLinkName
, const OUString
& aLinkTarget
) throw(InvalidRegistryException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
133 virtual void SAL_CALL
deleteLink( const OUString
& rLinkName
) throw(InvalidRegistryException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
134 virtual OUString SAL_CALL
getLinkTarget( const OUString
& rLinkName
) throw(InvalidRegistryException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
135 virtual OUString SAL_CALL
getResolvedName( const OUString
& aKeyName
) throw(InvalidRegistryException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
138 void computeChanges();
139 OUString
computeName(const OUString
& name
);
143 NestedRegistryImpl
* m_pRegistry
;
144 Reference
<XRegistryKey
> m_localKey
;
145 Reference
<XRegistryKey
> m_defaultKey
;
150 NestedKeyImpl::NestedKeyImpl( NestedRegistryImpl
* pDefaultRegistry
,
151 Reference
<XRegistryKey
>& localKey
,
152 Reference
<XRegistryKey
>& defaultKey
)
153 : m_pRegistry(pDefaultRegistry
)
155 m_pRegistry
->acquire();
157 m_localKey
= localKey
;
158 m_defaultKey
= defaultKey
;
162 m_name
= m_localKey
->getKeyName();
164 else if (m_defaultKey
.is())
166 m_name
= m_defaultKey
->getKeyName();
169 m_state
= m_pRegistry
->m_state
;
173 NestedKeyImpl::NestedKeyImpl( const OUString
& rKeyName
,
175 : m_pRegistry(pKey
->m_pRegistry
)
177 m_pRegistry
->acquire();
179 if (pKey
->m_localKey
.is() && pKey
->m_localKey
->isValid())
181 m_localKey
= pKey
->m_localKey
->openKey(rKeyName
);
183 if (pKey
->m_defaultKey
.is() && pKey
->m_defaultKey
->isValid())
185 m_defaultKey
= pKey
->m_defaultKey
->openKey(rKeyName
);
190 m_name
= m_localKey
->getKeyName();
192 else if (m_defaultKey
.is())
194 m_name
= m_defaultKey
->getKeyName();
197 m_state
= m_pRegistry
->m_state
;
201 NestedKeyImpl::~NestedKeyImpl()
204 m_pRegistry
->release();
208 void NestedKeyImpl::computeChanges()
210 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
211 if ( m_state
!= m_pRegistry
->m_state
)
213 Reference
<XRegistryKey
> rootKey(m_pRegistry
->m_localReg
->getRootKey());
215 Reference
<XRegistryKey
> tmpKey
= rootKey
->openKey(m_name
);
219 m_localKey
= rootKey
->openKey(m_name
);
222 m_state
= m_pRegistry
->m_state
;
227 // NestedKey_Impl::computeName()
229 OUString
NestedKeyImpl::computeName(const OUString
& name
)
231 OUString resLocalName
, resDefaultName
;
233 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
236 if ( m_localKey
.is() && m_localKey
->isValid() )
238 resLocalName
= m_localKey
->getResolvedName(name
);
240 else if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
242 return m_defaultKey
->getResolvedName(name
);
245 if ( !resLocalName
.isEmpty() && m_pRegistry
->m_defaultReg
->isValid() )
247 Reference
<XRegistryKey
> localRoot(m_pRegistry
->m_localReg
->getRootKey());
248 Reference
<XRegistryKey
> defaultRoot(m_pRegistry
->m_defaultReg
->getRootKey());
250 resDefaultName
= defaultRoot
->getResolvedName(resLocalName
);
252 sal_uInt32 count
= 100;
254 while (resLocalName
!= resDefaultName
&& count
> 0)
258 if (resLocalName
.isEmpty() || resDefaultName
.isEmpty())
259 throw InvalidRegistryException();
261 resLocalName
= localRoot
->getResolvedName(resDefaultName
);
262 resDefaultName
= defaultRoot
->getResolvedName(resLocalName
);
266 catch(InvalidRegistryException
& )
274 OUString SAL_CALL
NestedKeyImpl::getKeyName() throw(RuntimeException
, std::exception
)
276 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
281 sal_Bool SAL_CALL
NestedKeyImpl::isReadOnly( )
282 throw(InvalidRegistryException
, RuntimeException
, std::exception
)
284 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
287 if ( m_localKey
.is() && m_localKey
->isValid() )
288 return m_localKey
->isReadOnly();
290 throw InvalidRegistryException();
294 sal_Bool SAL_CALL
NestedKeyImpl::isValid( ) throw(RuntimeException
, std::exception
)
296 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
297 return ((m_localKey
.is() && m_localKey
->isValid()) ||
298 (m_defaultKey
.is() && m_defaultKey
->isValid()) );
302 RegistryKeyType SAL_CALL
NestedKeyImpl::getKeyType( const OUString
& rKeyName
)
303 throw(InvalidRegistryException
, RuntimeException
, std::exception
)
305 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
308 if ( m_localKey
.is() && m_localKey
->isValid() )
310 return m_localKey
->getKeyType(rKeyName
);
312 else if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
314 return m_defaultKey
->getKeyType(rKeyName
);
317 return RegistryKeyType_KEY
;
321 RegistryValueType SAL_CALL
NestedKeyImpl::getValueType( )
322 throw(InvalidRegistryException
, RuntimeException
, std::exception
)
324 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
327 if ( m_localKey
.is() && m_localKey
->isValid() )
329 return m_localKey
->getValueType();
331 else if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
333 return m_defaultKey
->getValueType();
336 return RegistryValueType_NOT_DEFINED
;
340 sal_Int32 SAL_CALL
NestedKeyImpl::getLongValue( )
341 throw(InvalidRegistryException
, InvalidValueException
, RuntimeException
, std::exception
)
343 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
346 if ( m_localKey
.is() && m_localKey
->isValid() )
348 return m_localKey
->getLongValue();
350 else if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
352 return m_defaultKey
->getLongValue();
356 throw InvalidRegistryException();
361 void SAL_CALL
NestedKeyImpl::setLongValue( sal_Int32 value
)
362 throw(InvalidRegistryException
, RuntimeException
, std::exception
)
364 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
367 if ( m_localKey
.is() && m_localKey
->isValid() )
369 m_localKey
->setLongValue(value
);
371 else if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
373 Reference
<XRegistryKey
> rootKey(m_pRegistry
->m_localReg
->getRootKey());
374 m_localKey
= rootKey
->createKey(m_name
);
375 m_localKey
->setLongValue(value
);
376 m_state
= m_pRegistry
->m_state
++;
380 throw InvalidRegistryException();
385 Sequence
< sal_Int32
> SAL_CALL
NestedKeyImpl::getLongListValue( )
386 throw(InvalidRegistryException
, InvalidValueException
, RuntimeException
, std::exception
)
388 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
391 if ( m_localKey
.is() && m_localKey
->isValid() )
393 return m_localKey
->getLongListValue();
395 else if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
397 return m_defaultKey
->getLongListValue();
401 throw InvalidRegistryException();
406 void SAL_CALL
NestedKeyImpl::setLongListValue( const Sequence
< sal_Int32
>& seqValue
)
407 throw(InvalidRegistryException
, RuntimeException
, std::exception
)
409 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
412 if ( m_localKey
.is() && m_localKey
->isValid() )
414 m_localKey
->setLongListValue(seqValue
);
416 else if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
418 Reference
<XRegistryKey
> rootKey(m_pRegistry
->m_localReg
->getRootKey());
419 m_localKey
= rootKey
->createKey(m_name
);
420 m_localKey
->setLongListValue(seqValue
);
421 m_state
= m_pRegistry
->m_state
++;
425 throw InvalidRegistryException();
430 OUString SAL_CALL
NestedKeyImpl::getAsciiValue( )
431 throw(InvalidRegistryException
, InvalidValueException
, RuntimeException
, std::exception
)
433 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
436 if ( m_localKey
.is() && m_localKey
->isValid() )
438 return m_localKey
->getAsciiValue();
440 else if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
442 return m_defaultKey
->getAsciiValue();
446 throw InvalidRegistryException();
451 void SAL_CALL
NestedKeyImpl::setAsciiValue( const OUString
& value
)
452 throw(InvalidRegistryException
, RuntimeException
, std::exception
)
454 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
457 if ( m_localKey
.is() && m_localKey
->isValid() )
459 m_localKey
->setAsciiValue(value
);
461 else if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
463 Reference
<XRegistryKey
> rootKey(m_pRegistry
->m_localReg
->getRootKey());
464 m_localKey
= rootKey
->createKey(m_name
);
465 m_localKey
->setAsciiValue(value
);
466 m_state
= m_pRegistry
->m_state
++;
470 throw InvalidRegistryException();
475 Sequence
< OUString
> SAL_CALL
NestedKeyImpl::getAsciiListValue( )
476 throw(InvalidRegistryException
, InvalidValueException
, RuntimeException
, std::exception
)
478 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
481 if ( m_localKey
.is() && m_localKey
->isValid() )
483 return m_localKey
->getAsciiListValue();
485 else if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
487 return m_defaultKey
->getAsciiListValue();
491 throw InvalidRegistryException();
496 void SAL_CALL
NestedKeyImpl::setAsciiListValue( const Sequence
< OUString
>& seqValue
)
497 throw(InvalidRegistryException
, RuntimeException
, std::exception
)
499 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
502 if ( m_localKey
.is() && m_localKey
->isValid() )
504 m_localKey
->setAsciiListValue(seqValue
);
506 else if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
508 Reference
<XRegistryKey
> rootKey(m_pRegistry
->m_localReg
->getRootKey());
509 m_localKey
= rootKey
->createKey(m_name
);
510 m_localKey
->setAsciiListValue(seqValue
);
511 m_state
= m_pRegistry
->m_state
++;
515 throw InvalidRegistryException();
520 OUString SAL_CALL
NestedKeyImpl::getStringValue( )
521 throw(InvalidRegistryException
, InvalidValueException
, RuntimeException
, std::exception
)
523 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
526 if ( m_localKey
.is() && m_localKey
->isValid() )
528 return m_localKey
->getStringValue();
530 else if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
532 return m_defaultKey
->getStringValue();
536 throw InvalidRegistryException();
541 void SAL_CALL
NestedKeyImpl::setStringValue( const OUString
& value
)
542 throw(InvalidRegistryException
, RuntimeException
, std::exception
)
544 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
547 if ( m_localKey
.is() && m_localKey
->isValid() )
549 m_localKey
->setStringValue(value
);
551 else if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
553 Reference
<XRegistryKey
> rootKey(m_pRegistry
->m_localReg
->getRootKey());
554 m_localKey
= rootKey
->createKey(m_name
);
555 m_localKey
->setStringValue(value
);
556 m_state
= m_pRegistry
->m_state
++;
560 throw InvalidRegistryException();
565 Sequence
< OUString
> SAL_CALL
NestedKeyImpl::getStringListValue( )
566 throw(InvalidRegistryException
, InvalidValueException
, RuntimeException
, std::exception
)
568 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
571 if ( m_localKey
.is() && m_localKey
->isValid() )
573 return m_localKey
->getStringListValue();
575 else if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
577 return m_defaultKey
->getStringListValue();
581 throw InvalidRegistryException();
586 void SAL_CALL
NestedKeyImpl::setStringListValue( const Sequence
< OUString
>& seqValue
)
587 throw(InvalidRegistryException
, RuntimeException
, std::exception
)
589 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
592 if ( m_localKey
.is() && m_localKey
->isValid() )
594 m_localKey
->setStringListValue(seqValue
);
596 else if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
598 Reference
<XRegistryKey
> rootKey(m_pRegistry
->m_localReg
->getRootKey());
599 m_localKey
= rootKey
->createKey(m_name
);
600 m_localKey
->setStringListValue(seqValue
);
601 m_state
= m_pRegistry
->m_state
++;
605 throw InvalidRegistryException();
610 Sequence
< sal_Int8
> SAL_CALL
NestedKeyImpl::getBinaryValue( )
611 throw(InvalidRegistryException
, InvalidValueException
, RuntimeException
, std::exception
)
613 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
616 if ( m_localKey
.is() && m_localKey
->isValid() )
618 return m_localKey
->getBinaryValue();
620 else if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
622 return m_defaultKey
->getBinaryValue();
626 throw InvalidRegistryException();
631 void SAL_CALL
NestedKeyImpl::setBinaryValue( const Sequence
< sal_Int8
>& value
)
632 throw(InvalidRegistryException
, RuntimeException
, std::exception
)
634 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
637 if ( m_localKey
.is() && m_localKey
->isValid() )
639 m_localKey
->setBinaryValue(value
);
641 else if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
643 Reference
<XRegistryKey
> rootKey(m_pRegistry
->m_localReg
->getRootKey());
644 m_localKey
= rootKey
->createKey(m_name
);
645 m_localKey
->setBinaryValue(value
);
646 m_state
= m_pRegistry
->m_state
++;
650 throw InvalidRegistryException();
655 Reference
< XRegistryKey
> SAL_CALL
NestedKeyImpl::openKey( const OUString
& aKeyName
)
656 throw(InvalidRegistryException
, RuntimeException
, std::exception
)
658 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
659 if ( !m_localKey
.is() && !m_defaultKey
.is() )
661 throw InvalidRegistryException();
664 OUString resolvedName
= computeName(aKeyName
);
666 if ( resolvedName
.isEmpty() )
667 throw InvalidRegistryException();
669 Reference
<XRegistryKey
> localKey
, defaultKey
;
671 if ( m_localKey
.is() && m_localKey
->isValid() )
673 localKey
= m_pRegistry
->m_localReg
->getRootKey()->openKey(resolvedName
);
675 if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
677 defaultKey
= m_pRegistry
->m_defaultReg
->getRootKey()->openKey(resolvedName
);
680 if ( localKey
.is() || defaultKey
.is() )
682 return ((XRegistryKey
*)new NestedKeyImpl(m_pRegistry
, localKey
, defaultKey
));
686 return Reference
<XRegistryKey
>();
691 Reference
< XRegistryKey
> SAL_CALL
NestedKeyImpl::createKey( const OUString
& aKeyName
)
692 throw(InvalidRegistryException
, RuntimeException
, std::exception
)
694 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
695 if ( (!m_localKey
.is() && !m_defaultKey
.is()) ||
696 (m_localKey
.is() && m_localKey
->isReadOnly()) )
698 throw InvalidRegistryException();
701 OUString resolvedName
= computeName(aKeyName
);
703 if ( resolvedName
.isEmpty() )
704 throw InvalidRegistryException();
706 if ( m_localKey
.is() && m_localKey
->isValid() )
708 Reference
<XRegistryKey
> localKey
, defaultKey
;
710 localKey
= m_pRegistry
->m_localReg
->getRootKey()->createKey(resolvedName
);
713 if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
715 defaultKey
= m_pRegistry
->m_defaultReg
->getRootKey()->openKey(resolvedName
);
718 m_state
= m_pRegistry
->m_state
++;
720 return ((XRegistryKey
*)new NestedKeyImpl(m_pRegistry
, localKey
, defaultKey
));
725 Reference
<XRegistryKey
> localKey
, defaultKey
;
727 if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
729 Reference
<XRegistryKey
> rootKey(m_pRegistry
->m_localReg
->getRootKey());
730 m_localKey
= rootKey
->createKey(m_name
);
732 localKey
= m_pRegistry
->m_localReg
->getRootKey()->createKey(resolvedName
);
736 defaultKey
= m_pRegistry
->m_defaultReg
->getRootKey()->openKey(resolvedName
);
738 m_state
= m_pRegistry
->m_state
++;
740 return ((XRegistryKey
*)new NestedKeyImpl(m_pRegistry
, localKey
, defaultKey
));
745 return Reference
<XRegistryKey
>();
749 void SAL_CALL
NestedKeyImpl::closeKey( )
750 throw(InvalidRegistryException
, RuntimeException
, std::exception
)
752 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
753 if ( m_localKey
.is() && m_localKey
->isValid() )
755 m_localKey
->closeKey();
757 if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
759 m_defaultKey
->closeKey();
764 void SAL_CALL
NestedKeyImpl::deleteKey( const OUString
& rKeyName
)
765 throw(InvalidRegistryException
, RuntimeException
, std::exception
)
767 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
768 if ( m_localKey
.is() && m_localKey
->isValid() &&
769 !m_localKey
->isReadOnly() )
771 OUString resolvedName
= computeName(rKeyName
);
773 if ( resolvedName
.isEmpty() )
775 throw InvalidRegistryException();
778 m_pRegistry
->m_localReg
->getRootKey()->deleteKey(resolvedName
);
782 throw InvalidRegistryException();
787 Sequence
< Reference
< XRegistryKey
> > SAL_CALL
NestedKeyImpl::openKeys( )
788 throw(InvalidRegistryException
, RuntimeException
, std::exception
)
790 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
791 if ( !m_localKey
.is() && !m_defaultKey
.is() )
793 throw InvalidRegistryException();
796 Sequence
<OUString
> localSeq
, defaultSeq
;
798 if ( m_localKey
.is() && m_localKey
->isValid() )
800 localSeq
= m_localKey
->getKeyNames();
802 if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
804 defaultSeq
= m_defaultKey
->getKeyNames();
807 sal_uInt32 local
= localSeq
.getLength();
808 sal_uInt32 def
= defaultSeq
.getLength();
812 for (i
=0; i
< local
; i
++)
814 for (j
=0 ; j
< def
; j
++)
816 if ( localSeq
.getConstArray()[i
] == defaultSeq
.getConstArray()[j
] )
824 Sequence
< Reference
<XRegistryKey
> > retSeq(local
+ def
- len
);
828 for (i
=0; i
< local
; i
++)
830 name
= localSeq
.getConstArray()[i
];
831 lastIndex
= name
.lastIndexOf('/');
832 name
= name
.copy(lastIndex
);
833 retSeq
.getArray()[i
] =
834 (XRegistryKey
*)new NestedKeyImpl(name
, this);
837 sal_uInt32 k
= local
;
838 for (i
=0; i
< def
; i
++)
842 for (j
=0 ; j
< local
; j
++)
844 if ( retSeq
.getConstArray()[j
]->getKeyName()
845 == defaultSeq
.getConstArray()[i
] )
854 name
= defaultSeq
.getConstArray()[i
];
855 lastIndex
= name
.lastIndexOf('/');
856 name
= name
.copy(lastIndex
);
857 retSeq
.getArray()[k
++] =
858 (XRegistryKey
*)new NestedKeyImpl(name
, this);
866 Sequence
< OUString
> SAL_CALL
NestedKeyImpl::getKeyNames( )
867 throw(InvalidRegistryException
, RuntimeException
, std::exception
)
869 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
870 if ( !m_localKey
.is() && !m_defaultKey
.is() )
872 throw InvalidRegistryException();
875 Sequence
<OUString
> localSeq
, defaultSeq
;
877 if ( m_localKey
.is() && m_localKey
->isValid() )
879 localSeq
= m_localKey
->getKeyNames();
881 if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
883 defaultSeq
= m_defaultKey
->getKeyNames();
886 sal_uInt32 local
= localSeq
.getLength();
887 sal_uInt32 def
= defaultSeq
.getLength();
891 for (i
=0; i
< local
; i
++)
893 for (j
=0 ; j
< def
; j
++)
895 if ( localSeq
.getConstArray()[i
] == defaultSeq
.getConstArray()[j
] )
903 Sequence
<OUString
> retSeq(local
+ def
- len
);
905 for (i
=0; i
< local
; i
++)
907 retSeq
.getArray()[i
] = localSeq
.getConstArray()[i
];
910 sal_uInt32 k
= local
;
911 for (i
=0; i
< def
; i
++)
915 for (j
=0 ; j
< local
; j
++)
917 if ( retSeq
.getConstArray()[j
] == defaultSeq
.getConstArray()[i
] )
925 retSeq
.getArray()[k
++] = defaultSeq
.getConstArray()[i
];
932 sal_Bool SAL_CALL
NestedKeyImpl::createLink( const OUString
& aLinkName
, const OUString
& aLinkTarget
)
933 throw(InvalidRegistryException
, RuntimeException
, std::exception
)
935 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
937 bool isCreated
= false;
938 if ( !m_localKey
.is() && !m_defaultKey
.is() )
940 throw InvalidRegistryException();
944 OUString resolvedName
;
945 sal_Int32 lastIndex
= aLinkName
.lastIndexOf('/');
949 linkName
= aLinkName
.copy(0, lastIndex
);
951 resolvedName
= computeName(linkName
);
953 if ( resolvedName
.isEmpty() )
955 throw InvalidRegistryException();
958 resolvedName
= resolvedName
+ aLinkName
.copy(lastIndex
);
962 if ( lastIndex
== 0 )
963 resolvedName
= m_name
+ aLinkName
;
965 resolvedName
= m_name
+ "/" + aLinkName
;
968 if ( m_localKey
.is() && m_localKey
->isValid() )
970 isCreated
= m_pRegistry
->m_localReg
->getRootKey()->createLink(resolvedName
, aLinkTarget
);
974 if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
976 Reference
<XRegistryKey
> rootKey(m_pRegistry
->m_localReg
->getRootKey());
977 m_localKey
= rootKey
->createKey(m_name
);
979 isCreated
= m_pRegistry
->m_localReg
->getRootKey()->createLink(resolvedName
, aLinkTarget
);
984 m_state
= m_pRegistry
->m_state
++;
990 void SAL_CALL
NestedKeyImpl::deleteLink( const OUString
& rLinkName
)
991 throw(InvalidRegistryException
, RuntimeException
, std::exception
)
993 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
994 if ( !m_localKey
.is() && !m_defaultKey
.is() )
996 throw InvalidRegistryException();
1000 OUString resolvedName
;
1001 sal_Int32 lastIndex
= rLinkName
.lastIndexOf('/');
1003 if ( lastIndex
> 0 )
1005 linkName
= rLinkName
.copy(0, lastIndex
);
1007 resolvedName
= computeName(linkName
);
1009 if ( resolvedName
.isEmpty() )
1011 throw InvalidRegistryException();
1014 resolvedName
= resolvedName
+ rLinkName
.copy(lastIndex
);
1018 if ( lastIndex
== 0 )
1019 resolvedName
= m_name
+ rLinkName
;
1021 resolvedName
= m_name
+ "/" + rLinkName
;
1024 if ( m_localKey
.is() && m_localKey
->isValid() &&
1025 !m_localKey
->isReadOnly() )
1027 m_pRegistry
->m_localReg
->getRootKey()->deleteLink(resolvedName
);
1031 throw InvalidRegistryException();
1036 OUString SAL_CALL
NestedKeyImpl::getLinkTarget( const OUString
& rLinkName
)
1037 throw(InvalidRegistryException
, RuntimeException
, std::exception
)
1039 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
1040 if ( !m_localKey
.is() && !m_defaultKey
.is() )
1042 throw InvalidRegistryException();
1046 OUString resolvedName
;
1047 sal_Int32 lastIndex
= rLinkName
.lastIndexOf('/');
1049 if ( lastIndex
> 0 )
1051 linkName
= rLinkName
.copy(0, lastIndex
);
1053 resolvedName
= computeName(linkName
);
1055 if ( resolvedName
.isEmpty() )
1057 throw InvalidRegistryException();
1060 resolvedName
= resolvedName
+ rLinkName
.copy(lastIndex
);
1064 if ( lastIndex
== 0 )
1065 resolvedName
= m_name
+ rLinkName
;
1067 resolvedName
= m_name
+ "/" + rLinkName
;
1070 OUString linkTarget
;
1071 if ( m_localKey
.is() && m_localKey
->isValid() )
1075 linkTarget
= m_pRegistry
->m_localReg
->getRootKey()->getLinkTarget(resolvedName
);
1078 catch(InvalidRegistryException
& )
1083 if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
1084 linkTarget
= m_pRegistry
->m_defaultReg
->getRootKey()->getLinkTarget(resolvedName
);
1090 OUString SAL_CALL
NestedKeyImpl::getResolvedName( const OUString
& aKeyName
)
1091 throw(InvalidRegistryException
, RuntimeException
, std::exception
)
1093 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
1094 if ( !m_localKey
.is() && !m_defaultKey
.is() )
1096 throw InvalidRegistryException();
1099 OUString resolvedName
= computeName(aKeyName
);
1101 if ( resolvedName
.isEmpty() )
1103 throw InvalidRegistryException();
1106 return resolvedName
;
1111 // DefaultRegistry Implementation
1114 NestedRegistryImpl::NestedRegistryImpl( )
1119 NestedRegistryImpl::~NestedRegistryImpl() {}
1121 class RegistryEnumueration
: public WeakImplHelper1
< XEnumeration
>
1124 RegistryEnumueration(
1125 const Reference
< XSimpleRegistry
> &r1
,
1126 const Reference
< XSimpleRegistry
> &r2
)
1127 : m_xReg1( r1
) , m_xReg2( r2
)
1130 virtual sal_Bool SAL_CALL
hasMoreElements( ) throw (RuntimeException
, std::exception
) SAL_OVERRIDE
;
1131 virtual Any SAL_CALL
nextElement( ) throw (NoSuchElementException
, WrappedTargetException
, RuntimeException
, std::exception
) SAL_OVERRIDE
;
1134 Reference
< XSimpleRegistry
> m_xReg1
;
1135 Reference
< XSimpleRegistry
> m_xReg2
;
1138 sal_Bool
RegistryEnumueration::hasMoreElements( ) throw (RuntimeException
, std::exception
)
1140 return m_xReg1
.is() || m_xReg2
.is();
1143 Any
RegistryEnumueration::nextElement( )
1144 throw (NoSuchElementException
, WrappedTargetException
, RuntimeException
, std::exception
)
1152 else if( m_xReg2
.is() )
1159 throw NoSuchElementException( "NestedRegistry: no nextElement() !" );
1165 Reference
< XEnumeration
> NestedRegistryImpl::createEnumeration( ) throw (RuntimeException
, std::exception
)
1167 MutexGuard
guard( m_mutex
);
1168 return new RegistryEnumueration( m_localReg
, m_defaultReg
);
1171 Type
NestedRegistryImpl::getElementType( ) throw (RuntimeException
, std::exception
)
1173 return cppu::UnoType
<decltype(m_localReg
)>::get();
1176 sal_Bool SAL_CALL
NestedRegistryImpl::hasElements( ) throw (RuntimeException
, std::exception
)
1178 MutexGuard
guard( m_mutex
);
1179 return m_localReg
.is() || m_defaultReg
.is();
1185 OUString SAL_CALL
NestedRegistryImpl::getImplementationName( )
1186 throw(RuntimeException
, std::exception
)
1188 return OUString("com.sun.star.comp.stoc.NestedRegistry");
1191 sal_Bool SAL_CALL
NestedRegistryImpl::supportsService( const OUString
& ServiceName
)
1192 throw(RuntimeException
, std::exception
)
1194 return cppu::supportsService(this, ServiceName
);
1197 Sequence
<OUString
> SAL_CALL
NestedRegistryImpl::getSupportedServiceNames( )
1198 throw(RuntimeException
, std::exception
)
1200 Sequence
< OUString
> seqNames(1);
1201 seqNames
[0] = "com.sun.star.registry.NestedRegistry";
1206 void SAL_CALL
NestedRegistryImpl::initialize( const Sequence
< Any
>& aArguments
)
1207 throw( Exception
, RuntimeException
, std::exception
)
1209 Guard
< Mutex
> aGuard( m_mutex
);
1210 if ( (aArguments
.getLength() == 2) &&
1211 (aArguments
[0].getValueType().getTypeClass() == TypeClass_INTERFACE
) &&
1212 (aArguments
[1].getValueType().getTypeClass() == TypeClass_INTERFACE
) )
1214 aArguments
[0] >>= m_localReg
;
1215 aArguments
[1] >>= m_defaultReg
;
1216 if ( m_localReg
== m_defaultReg
)
1217 m_defaultReg
.clear();
1222 OUString SAL_CALL
NestedRegistryImpl::getURL() throw(RuntimeException
, std::exception
)
1224 Guard
< Mutex
> aGuard( m_mutex
);
1227 if ( m_localReg
.is() && m_localReg
->isValid() )
1228 return m_localReg
->getURL();
1230 catch(InvalidRegistryException
& )
1238 void SAL_CALL
NestedRegistryImpl::open( const OUString
&, sal_Bool
, sal_Bool
)
1239 throw(InvalidRegistryException
, RuntimeException
, std::exception
)
1241 throw InvalidRegistryException(
1242 "the 'open' method is not specified for a nested registry" );
1246 sal_Bool SAL_CALL
NestedRegistryImpl::isValid( ) throw(RuntimeException
, std::exception
)
1248 Guard
< Mutex
> aGuard( m_mutex
);
1251 if ( (m_localReg
.is() && m_localReg
->isValid()) ||
1252 (m_defaultReg
.is() && m_defaultReg
->isValid()) )
1255 catch(InvalidRegistryException
& )
1263 void SAL_CALL
NestedRegistryImpl::close( )
1264 throw(InvalidRegistryException
, RuntimeException
, std::exception
)
1266 Guard
< Mutex
> aGuard( m_mutex
);
1267 if ( m_localReg
.is() && m_localReg
->isValid() )
1269 m_localReg
->close();
1271 if ( m_defaultReg
.is() && m_defaultReg
->isValid() )
1273 m_defaultReg
->close();
1278 void SAL_CALL
NestedRegistryImpl::destroy( )
1279 throw(InvalidRegistryException
, RuntimeException
, std::exception
)
1281 throw InvalidRegistryException(
1282 "the 'destroy' method is not specified for a nested registry" );
1286 Reference
< XRegistryKey
> SAL_CALL
NestedRegistryImpl::getRootKey( )
1287 throw(InvalidRegistryException
, RuntimeException
, std::exception
)
1289 Reference
<XRegistryKey
> tmpKey
;
1291 Guard
< Mutex
> aGuard( m_mutex
);
1292 if ( m_localReg
.is() && m_localReg
->isValid() )
1294 Reference
<XRegistryKey
> localKey
, defaultKey
;
1296 localKey
= m_localReg
->getRootKey();
1298 if ( localKey
.is() )
1300 if ( m_defaultReg
.is() && m_defaultReg
->isValid() )
1302 defaultKey
= m_defaultReg
->getRootKey();
1305 return ((XRegistryKey
*)new NestedKeyImpl(this, localKey
, defaultKey
));
1310 throw InvalidRegistryException();
1313 return Reference
<XRegistryKey
>();
1317 sal_Bool SAL_CALL
NestedRegistryImpl::isReadOnly( )
1318 throw(InvalidRegistryException
, RuntimeException
, std::exception
)
1320 Guard
< Mutex
> aGuard( m_mutex
);
1323 if ( m_localReg
.is() && m_localReg
->isValid() )
1324 return m_localReg
->isReadOnly();
1326 catch(InvalidRegistryException
& )
1334 void SAL_CALL
NestedRegistryImpl::mergeKey( const OUString
& aKeyName
, const OUString
& aUrl
)
1335 throw(InvalidRegistryException
, MergeConflictException
, RuntimeException
, std::exception
)
1337 Guard
< Mutex
> aGuard( m_mutex
);
1338 if ( m_localReg
.is() && m_localReg
->isValid() )
1340 m_localReg
->mergeKey(aKeyName
, aUrl
);
1348 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
1349 com_sun_star_comp_stoc_NestedRegistry_get_implementation(
1350 SAL_UNUSED_PARAMETER
css::uno::XComponentContext
*,
1351 css::uno::Sequence
<css::uno::Any
> const &)
1353 return cppu::acquire(new NestedRegistryImpl
);
1356 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */