1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: defaultregistry.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_stoc.hxx"
33 #include <osl/mutex.hxx>
34 #ifndef _OSL_DIAGNOSE_HXX_
35 #include <osl/diagnose.h>
37 #include <cppuhelper/queryinterface.hxx>
38 #include <cppuhelper/weak.hxx>
39 #include <cppuhelper/factory.hxx>
40 #include <cppuhelper/implbase1.hxx>
41 #include <cppuhelper/implbase4.hxx>
42 #include <cppuhelper/implbase3.hxx>
43 #ifndef _CPPUHELPER_IMPLEMENTATIONENTRY_HXX_
44 #include <cppuhelper/implementationentry.hxx>
46 #include <registry/registry.hxx>
48 #include <com/sun/star/registry/XSimpleRegistry.hpp>
49 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
50 #include <com/sun/star/lang/XServiceInfo.hpp>
51 #include <com/sun/star/lang/XTypeProvider.hpp>
52 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
53 #include <com/sun/star/lang/XInitialization.hpp>
54 #include <com/sun/star/container/XEnumerationAccess.hpp>
56 #include <bootstrapservices.hxx>
58 using namespace com::sun::star::uno
;
59 using namespace com::sun::star::registry
;
60 using namespace com::sun::star::lang
;
61 using namespace com::sun::star::container
;
67 #define SERVICENAME "com.sun.star.registry.NestedRegistry"
68 #define IMPLNAME "com.sun.star.comp.stoc.NestedRegistry"
70 extern rtl_StandardModuleCount g_moduleCount
;
72 namespace stoc_bootstrap
74 Sequence
< OUString
> defreg_getSupportedServiceNames()
76 static Sequence
< OUString
> *pNames
= 0;
79 MutexGuard
guard( Mutex::getGlobalMutex() );
82 static Sequence
< OUString
> seqNames(1);
83 seqNames
.getArray()[0] = OUString(RTL_CONSTASCII_USTRINGPARAM(SERVICENAME
));
90 OUString
defreg_getImplementationName()
92 static OUString
*pImplName
= 0;
95 MutexGuard
guard( Mutex::getGlobalMutex() );
98 static OUString
implName( RTL_CONSTASCII_USTRINGPARAM( IMPLNAME
) );
99 pImplName
= &implName
;
106 namespace stoc_defreg
108 //*************************************************************************
109 // NestedRegistryImpl
110 //*************************************************************************
113 class NestedRegistryImpl
: public WeakAggImplHelper4
< XSimpleRegistry
, XInitialization
, XServiceInfo
, XEnumerationAccess
>
116 NestedRegistryImpl( );
118 ~NestedRegistryImpl();
121 virtual OUString SAL_CALL
getImplementationName( ) throw(RuntimeException
);
122 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) throw(RuntimeException
);
123 virtual Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) throw(RuntimeException
);
126 virtual void SAL_CALL
initialize( const Sequence
< Any
>& aArguments
)
127 throw(Exception
, RuntimeException
);
130 virtual OUString SAL_CALL
getURL() throw(RuntimeException
);
131 virtual void SAL_CALL
open( const OUString
& rURL
, sal_Bool bReadOnly
, sal_Bool bCreate
) throw(InvalidRegistryException
, RuntimeException
);
132 virtual sal_Bool SAL_CALL
isValid( ) throw(RuntimeException
);
133 virtual void SAL_CALL
close( ) throw(InvalidRegistryException
, RuntimeException
);
134 virtual void SAL_CALL
destroy( ) throw(InvalidRegistryException
, RuntimeException
);
135 virtual Reference
< XRegistryKey
> SAL_CALL
getRootKey( ) throw(InvalidRegistryException
, RuntimeException
);
136 virtual sal_Bool SAL_CALL
isReadOnly( ) throw(InvalidRegistryException
, RuntimeException
);
137 virtual void SAL_CALL
mergeKey( const OUString
& aKeyName
, const OUString
& aUrl
) throw(InvalidRegistryException
, MergeConflictException
, RuntimeException
);
139 // XEnumerationAccess
140 virtual Reference
< XEnumeration
> SAL_CALL
createEnumeration( ) throw (RuntimeException
);
141 virtual Type SAL_CALL
getElementType( ) throw (RuntimeException
);
142 virtual sal_Bool SAL_CALL
hasElements( ) throw (RuntimeException
);
144 friend class NestedKeyImpl
;
148 Reference
<XSimpleRegistry
> m_localReg
;
149 Reference
<XSimpleRegistry
> m_defaultReg
;
153 //*************************************************************************
154 // class NestedKeyImpl the implenetation of interface XRegistryKey
155 //*************************************************************************
156 class NestedKeyImpl
: public WeakImplHelper1
< XRegistryKey
>
159 NestedKeyImpl( NestedRegistryImpl
* pDefaultRegistry
,
160 Reference
<XRegistryKey
>& localKey
,
161 Reference
<XRegistryKey
>& defaultKey
);
163 NestedKeyImpl( const OUString
& aKeyName
,
164 NestedKeyImpl
* pKey
);
169 virtual OUString SAL_CALL
getKeyName() throw(RuntimeException
);
170 virtual sal_Bool SAL_CALL
isReadOnly( ) throw(InvalidRegistryException
, RuntimeException
);
171 virtual sal_Bool SAL_CALL
isValid( ) throw(RuntimeException
);
172 virtual RegistryKeyType SAL_CALL
getKeyType( const OUString
& rKeyName
) throw(InvalidRegistryException
, RuntimeException
);
173 virtual RegistryValueType SAL_CALL
getValueType( ) throw(InvalidRegistryException
, RuntimeException
);
174 virtual sal_Int32 SAL_CALL
getLongValue( ) throw(InvalidRegistryException
, InvalidValueException
, RuntimeException
);
175 virtual void SAL_CALL
setLongValue( sal_Int32 value
) throw(InvalidRegistryException
, RuntimeException
);
176 virtual Sequence
< sal_Int32
> SAL_CALL
getLongListValue( ) throw(InvalidRegistryException
, InvalidValueException
, RuntimeException
);
177 virtual void SAL_CALL
setLongListValue( const ::com::sun::star::uno::Sequence
< sal_Int32
>& seqValue
) throw(InvalidRegistryException
, RuntimeException
);
178 virtual OUString SAL_CALL
getAsciiValue( ) throw(InvalidRegistryException
, InvalidValueException
, RuntimeException
);
179 virtual void SAL_CALL
setAsciiValue( const OUString
& value
) throw(InvalidRegistryException
, RuntimeException
);
180 virtual Sequence
< OUString
> SAL_CALL
getAsciiListValue( ) throw(InvalidRegistryException
, InvalidValueException
, RuntimeException
);
181 virtual void SAL_CALL
setAsciiListValue( const ::com::sun::star::uno::Sequence
< OUString
>& seqValue
) throw(InvalidRegistryException
, RuntimeException
);
182 virtual OUString SAL_CALL
getStringValue( ) throw(InvalidRegistryException
, InvalidValueException
, RuntimeException
);
183 virtual void SAL_CALL
setStringValue( const OUString
& value
) throw(InvalidRegistryException
, RuntimeException
);
184 virtual Sequence
< OUString
> SAL_CALL
getStringListValue( ) throw(InvalidRegistryException
, InvalidValueException
, RuntimeException
);
185 virtual void SAL_CALL
setStringListValue( const ::com::sun::star::uno::Sequence
< OUString
>& seqValue
) throw(InvalidRegistryException
, RuntimeException
);
186 virtual Sequence
< sal_Int8
> SAL_CALL
getBinaryValue( ) throw(InvalidRegistryException
, InvalidValueException
, RuntimeException
);
187 virtual void SAL_CALL
setBinaryValue( const ::com::sun::star::uno::Sequence
< sal_Int8
>& value
) throw(InvalidRegistryException
, RuntimeException
);
188 virtual Reference
< XRegistryKey
> SAL_CALL
openKey( const OUString
& aKeyName
) throw(InvalidRegistryException
, RuntimeException
);
189 virtual Reference
< XRegistryKey
> SAL_CALL
createKey( const OUString
& aKeyName
) throw(InvalidRegistryException
, RuntimeException
);
190 virtual void SAL_CALL
closeKey( ) throw(InvalidRegistryException
, RuntimeException
);
191 virtual void SAL_CALL
deleteKey( const OUString
& rKeyName
) throw(InvalidRegistryException
, RuntimeException
);
192 virtual Sequence
< Reference
< XRegistryKey
> > SAL_CALL
openKeys( ) throw(InvalidRegistryException
, RuntimeException
);
193 virtual Sequence
< OUString
> SAL_CALL
getKeyNames( ) throw(InvalidRegistryException
, RuntimeException
);
194 virtual sal_Bool SAL_CALL
createLink( const OUString
& aLinkName
, const OUString
& aLinkTarget
) throw(InvalidRegistryException
, RuntimeException
);
195 virtual void SAL_CALL
deleteLink( const OUString
& rLinkName
) throw(InvalidRegistryException
, RuntimeException
);
196 virtual OUString SAL_CALL
getLinkTarget( const OUString
& rLinkName
) throw(InvalidRegistryException
, RuntimeException
);
197 virtual OUString SAL_CALL
getResolvedName( const OUString
& aKeyName
) throw(InvalidRegistryException
, RuntimeException
);
200 void computeChanges();
201 OUString
computeName(const OUString
& name
);
205 NestedRegistryImpl
* m_pRegistry
;
206 Reference
<XRegistryKey
> m_localKey
;
207 Reference
<XRegistryKey
> m_defaultKey
;
211 //*************************************************************************
212 NestedKeyImpl::NestedKeyImpl( NestedRegistryImpl
* pDefaultRegistry
,
213 Reference
<XRegistryKey
>& localKey
,
214 Reference
<XRegistryKey
>& defaultKey
)
215 : m_pRegistry(pDefaultRegistry
)
217 m_pRegistry
->acquire();
219 m_localKey
= localKey
;
220 m_defaultKey
= defaultKey
;
224 m_name
= m_localKey
->getKeyName();
226 if (m_defaultKey
.is())
228 m_name
= m_defaultKey
->getKeyName();
231 m_state
= m_pRegistry
->m_state
;
234 //*************************************************************************
235 NestedKeyImpl::NestedKeyImpl( const OUString
& rKeyName
,
237 : m_pRegistry(pKey
->m_pRegistry
)
239 m_pRegistry
->acquire();
241 if (pKey
->m_localKey
.is() && pKey
->m_localKey
->isValid())
243 m_localKey
= pKey
->m_localKey
->openKey(rKeyName
);
245 if (pKey
->m_defaultKey
.is() && pKey
->m_defaultKey
->isValid())
247 m_defaultKey
= pKey
->m_defaultKey
->openKey(rKeyName
);
252 m_name
= m_localKey
->getKeyName();
254 if (m_defaultKey
.is())
256 m_name
= m_defaultKey
->getKeyName();
259 m_state
= m_pRegistry
->m_state
;
262 //*************************************************************************
263 NestedKeyImpl::~NestedKeyImpl()
266 m_pRegistry
->release();
269 //*************************************************************************
270 void NestedKeyImpl::computeChanges()
272 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
273 if ( m_state
!= m_pRegistry
->m_state
)
275 Reference
<XRegistryKey
> rootKey(m_pRegistry
->m_localReg
->getRootKey());
277 Reference
<XRegistryKey
> tmpKey
= rootKey
->openKey(m_name
);
281 m_localKey
= rootKey
->openKey(m_name
);
284 m_state
= m_pRegistry
->m_state
;
288 //*************************************************************************
289 // NestedKey_Impl::computeName()
291 OUString
NestedKeyImpl::computeName(const OUString
& name
)
293 OUString resLocalName
, resDefaultName
;
295 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
298 if ( m_localKey
.is() && m_localKey
->isValid() )
300 resLocalName
= m_localKey
->getResolvedName(name
);
303 if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
304 return m_defaultKey
->getResolvedName(name
);
307 if ( resLocalName
.getLength() > 0 && m_pRegistry
->m_defaultReg
->isValid() )
309 Reference
<XRegistryKey
> localRoot(m_pRegistry
->m_localReg
->getRootKey());
310 Reference
<XRegistryKey
> defaultRoot(m_pRegistry
->m_defaultReg
->getRootKey());
312 resDefaultName
= defaultRoot
->getResolvedName(resLocalName
);
314 sal_uInt32 count
= 100;
316 while (resLocalName
!= resDefaultName
&& count
> 0)
320 if (resLocalName
.getLength() == 0 || resDefaultName
.getLength() == 0)
321 throw InvalidRegistryException();
323 resLocalName
= localRoot
->getResolvedName(resDefaultName
);
324 resDefaultName
= defaultRoot
->getResolvedName(resLocalName
);
328 catch(InvalidRegistryException
& )
335 //*************************************************************************
336 OUString SAL_CALL
NestedKeyImpl::getKeyName() throw(RuntimeException
)
338 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
342 //*************************************************************************
343 sal_Bool SAL_CALL
NestedKeyImpl::isReadOnly( )
344 throw(InvalidRegistryException
, RuntimeException
)
346 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
349 if ( m_localKey
.is() && m_localKey
->isValid() )
350 return m_localKey
->isReadOnly();
352 throw InvalidRegistryException();
355 //*************************************************************************
356 sal_Bool SAL_CALL
NestedKeyImpl::isValid( ) throw(RuntimeException
)
358 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
359 return ((m_localKey
.is() && m_localKey
->isValid()) ||
360 (m_defaultKey
.is() && m_defaultKey
->isValid()) );
363 //*************************************************************************
364 RegistryKeyType SAL_CALL
NestedKeyImpl::getKeyType( const OUString
& rKeyName
)
365 throw(InvalidRegistryException
, RuntimeException
)
367 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
370 if ( m_localKey
.is() && m_localKey
->isValid() )
372 return m_localKey
->getKeyType(rKeyName
);
374 if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
376 return m_defaultKey
->getKeyType(rKeyName
);
379 return RegistryKeyType_KEY
;
382 //*************************************************************************
383 RegistryValueType SAL_CALL
NestedKeyImpl::getValueType( )
384 throw(InvalidRegistryException
, RuntimeException
)
386 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
389 if ( m_localKey
.is() && m_localKey
->isValid() )
391 return m_localKey
->getValueType();
393 if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
395 return m_defaultKey
->getValueType();
398 return RegistryValueType_NOT_DEFINED
;
401 //*************************************************************************
402 sal_Int32 SAL_CALL
NestedKeyImpl::getLongValue( )
403 throw(InvalidRegistryException
, InvalidValueException
, RuntimeException
)
405 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
408 if ( m_localKey
.is() && m_localKey
->isValid() )
410 return m_localKey
->getLongValue();
412 if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
414 return m_defaultKey
->getLongValue();
417 throw InvalidRegistryException();
421 //*************************************************************************
422 void SAL_CALL
NestedKeyImpl::setLongValue( sal_Int32 value
)
423 throw(InvalidRegistryException
, RuntimeException
)
425 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
428 if ( m_localKey
.is() && m_localKey
->isValid() )
430 m_localKey
->setLongValue(value
);
432 if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
434 Reference
<XRegistryKey
> rootKey(m_pRegistry
->m_localReg
->getRootKey());
435 m_localKey
= rootKey
->createKey(m_name
);
436 m_localKey
->setLongValue(value
);
437 m_state
= m_pRegistry
->m_state
++;
440 throw InvalidRegistryException();
444 //*************************************************************************
445 Sequence
< sal_Int32
> SAL_CALL
NestedKeyImpl::getLongListValue( )
446 throw(InvalidRegistryException
, InvalidValueException
, RuntimeException
)
448 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
451 if ( m_localKey
.is() && m_localKey
->isValid() )
453 return m_localKey
->getLongListValue();
455 if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
457 return m_defaultKey
->getLongListValue();
460 throw InvalidRegistryException();
464 //*************************************************************************
465 void SAL_CALL
NestedKeyImpl::setLongListValue( const Sequence
< sal_Int32
>& seqValue
)
466 throw(InvalidRegistryException
, RuntimeException
)
468 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
471 if ( m_localKey
.is() && m_localKey
->isValid() )
473 m_localKey
->setLongListValue(seqValue
);
475 if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
477 Reference
<XRegistryKey
> rootKey(m_pRegistry
->m_localReg
->getRootKey());
478 m_localKey
= rootKey
->createKey(m_name
);
479 m_localKey
->setLongListValue(seqValue
);
480 m_state
= m_pRegistry
->m_state
++;
483 throw InvalidRegistryException();
487 //*************************************************************************
488 OUString SAL_CALL
NestedKeyImpl::getAsciiValue( )
489 throw(InvalidRegistryException
, InvalidValueException
, RuntimeException
)
491 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
494 if ( m_localKey
.is() && m_localKey
->isValid() )
496 return m_localKey
->getAsciiValue();
498 if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
500 return m_defaultKey
->getAsciiValue();
503 throw InvalidRegistryException();
507 //*************************************************************************
508 void SAL_CALL
NestedKeyImpl::setAsciiValue( const OUString
& value
)
509 throw(InvalidRegistryException
, RuntimeException
)
511 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
514 if ( m_localKey
.is() && m_localKey
->isValid() )
516 m_localKey
->setAsciiValue(value
);
518 if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
520 Reference
<XRegistryKey
> rootKey(m_pRegistry
->m_localReg
->getRootKey());
521 m_localKey
= rootKey
->createKey(m_name
);
522 m_localKey
->setAsciiValue(value
);
523 m_state
= m_pRegistry
->m_state
++;
526 throw InvalidRegistryException();
530 //*************************************************************************
531 Sequence
< OUString
> SAL_CALL
NestedKeyImpl::getAsciiListValue( )
532 throw(InvalidRegistryException
, InvalidValueException
, RuntimeException
)
534 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
537 if ( m_localKey
.is() && m_localKey
->isValid() )
539 return m_localKey
->getAsciiListValue();
541 if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
543 return m_defaultKey
->getAsciiListValue();
546 throw InvalidRegistryException();
550 //*************************************************************************
551 void SAL_CALL
NestedKeyImpl::setAsciiListValue( const Sequence
< OUString
>& seqValue
)
552 throw(InvalidRegistryException
, RuntimeException
)
554 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
557 if ( m_localKey
.is() && m_localKey
->isValid() )
559 m_localKey
->setAsciiListValue(seqValue
);
561 if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
563 Reference
<XRegistryKey
> rootKey(m_pRegistry
->m_localReg
->getRootKey());
564 m_localKey
= rootKey
->createKey(m_name
);
565 m_localKey
->setAsciiListValue(seqValue
);
566 m_state
= m_pRegistry
->m_state
++;
569 throw InvalidRegistryException();
573 //*************************************************************************
574 OUString SAL_CALL
NestedKeyImpl::getStringValue( )
575 throw(InvalidRegistryException
, InvalidValueException
, RuntimeException
)
577 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
580 if ( m_localKey
.is() && m_localKey
->isValid() )
582 return m_localKey
->getStringValue();
584 if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
586 return m_defaultKey
->getStringValue();
589 throw InvalidRegistryException();
593 //*************************************************************************
594 void SAL_CALL
NestedKeyImpl::setStringValue( const OUString
& value
)
595 throw(InvalidRegistryException
, RuntimeException
)
597 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
600 if ( m_localKey
.is() && m_localKey
->isValid() )
602 m_localKey
->setStringValue(value
);
604 if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
606 Reference
<XRegistryKey
> rootKey(m_pRegistry
->m_localReg
->getRootKey());
607 m_localKey
= rootKey
->createKey(m_name
);
608 m_localKey
->setStringValue(value
);
609 m_state
= m_pRegistry
->m_state
++;
612 throw InvalidRegistryException();
616 //*************************************************************************
617 Sequence
< OUString
> SAL_CALL
NestedKeyImpl::getStringListValue( )
618 throw(InvalidRegistryException
, InvalidValueException
, RuntimeException
)
620 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
623 if ( m_localKey
.is() && m_localKey
->isValid() )
625 return m_localKey
->getStringListValue();
627 if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
629 return m_defaultKey
->getStringListValue();
632 throw InvalidRegistryException();
636 //*************************************************************************
637 void SAL_CALL
NestedKeyImpl::setStringListValue( const Sequence
< OUString
>& seqValue
)
638 throw(InvalidRegistryException
, RuntimeException
)
640 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
643 if ( m_localKey
.is() && m_localKey
->isValid() )
645 m_localKey
->setStringListValue(seqValue
);
647 if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
649 Reference
<XRegistryKey
> rootKey(m_pRegistry
->m_localReg
->getRootKey());
650 m_localKey
= rootKey
->createKey(m_name
);
651 m_localKey
->setStringListValue(seqValue
);
652 m_state
= m_pRegistry
->m_state
++;
655 throw InvalidRegistryException();
659 //*************************************************************************
660 Sequence
< sal_Int8
> SAL_CALL
NestedKeyImpl::getBinaryValue( )
661 throw(InvalidRegistryException
, InvalidValueException
, RuntimeException
)
663 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
666 if ( m_localKey
.is() && m_localKey
->isValid() )
668 return m_localKey
->getBinaryValue();
670 if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
672 return m_defaultKey
->getBinaryValue();
675 throw InvalidRegistryException();
679 //*************************************************************************
680 void SAL_CALL
NestedKeyImpl::setBinaryValue( const Sequence
< sal_Int8
>& value
)
681 throw(InvalidRegistryException
, RuntimeException
)
683 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
686 if ( m_localKey
.is() && m_localKey
->isValid() )
688 m_localKey
->setBinaryValue(value
);
690 if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
692 Reference
<XRegistryKey
> rootKey(m_pRegistry
->m_localReg
->getRootKey());
693 m_localKey
= rootKey
->createKey(m_name
);
694 m_localKey
->setBinaryValue(value
);
695 m_state
= m_pRegistry
->m_state
++;
698 throw InvalidRegistryException();
702 //*************************************************************************
703 Reference
< XRegistryKey
> SAL_CALL
NestedKeyImpl::openKey( const OUString
& aKeyName
)
704 throw(InvalidRegistryException
, RuntimeException
)
706 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
707 if ( !m_localKey
.is() && !m_defaultKey
.is() )
709 throw InvalidRegistryException();
712 OUString resolvedName
= computeName(aKeyName
);
714 if ( resolvedName
.getLength() == 0 )
715 throw InvalidRegistryException();
717 Reference
<XRegistryKey
> localKey
, defaultKey
;
719 if ( m_localKey
.is() && m_localKey
->isValid() )
721 localKey
= m_pRegistry
->m_localReg
->getRootKey()->openKey(resolvedName
);
723 if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
725 defaultKey
= m_pRegistry
->m_defaultReg
->getRootKey()->openKey(resolvedName
);
728 if ( localKey
.is() || defaultKey
.is() )
730 return ((XRegistryKey
*)new NestedKeyImpl(m_pRegistry
, localKey
, defaultKey
));
733 return Reference
<XRegistryKey
>();
737 //*************************************************************************
738 Reference
< XRegistryKey
> SAL_CALL
NestedKeyImpl::createKey( const OUString
& aKeyName
)
739 throw(InvalidRegistryException
, RuntimeException
)
741 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
742 if ( (!m_localKey
.is() && !m_defaultKey
.is()) ||
743 (m_localKey
.is() && m_localKey
->isReadOnly()) )
745 throw InvalidRegistryException();
748 OUString resolvedName
= computeName(aKeyName
);
750 if ( resolvedName
.getLength() == 0 )
751 throw InvalidRegistryException();
753 if ( m_localKey
.is() && m_localKey
->isValid() )
755 Reference
<XRegistryKey
> localKey
, defaultKey
;
757 localKey
= m_pRegistry
->m_localReg
->getRootKey()->createKey(resolvedName
);
760 if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
762 defaultKey
= m_pRegistry
->m_defaultReg
->getRootKey()->openKey(resolvedName
);
765 m_state
= m_pRegistry
->m_state
++;
767 return ((XRegistryKey
*)new NestedKeyImpl(m_pRegistry
, localKey
, defaultKey
));
771 Reference
<XRegistryKey
> localKey
, defaultKey
;
773 if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
775 Reference
<XRegistryKey
> rootKey(m_pRegistry
->m_localReg
->getRootKey());
776 m_localKey
= rootKey
->createKey(m_name
);
778 localKey
= m_pRegistry
->m_localReg
->getRootKey()->createKey(resolvedName
);
782 defaultKey
= m_pRegistry
->m_defaultReg
->getRootKey()->openKey(resolvedName
);
784 m_state
= m_pRegistry
->m_state
++;
786 return ((XRegistryKey
*)new NestedKeyImpl(m_pRegistry
, localKey
, defaultKey
));
791 return Reference
<XRegistryKey
>();
794 //*************************************************************************
795 void SAL_CALL
NestedKeyImpl::closeKey( )
796 throw(InvalidRegistryException
, RuntimeException
)
798 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
799 if ( m_localKey
.is() && m_localKey
->isValid() )
801 m_localKey
->closeKey();
803 if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
805 m_defaultKey
->closeKey();
809 //*************************************************************************
810 void SAL_CALL
NestedKeyImpl::deleteKey( const OUString
& rKeyName
)
811 throw(InvalidRegistryException
, RuntimeException
)
813 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
814 if ( m_localKey
.is() && m_localKey
->isValid() &&
815 !m_localKey
->isReadOnly() )
817 OUString resolvedName
= computeName(rKeyName
);
819 if ( resolvedName
.getLength() == 0 )
821 throw InvalidRegistryException();
824 m_pRegistry
->m_localReg
->getRootKey()->deleteKey(resolvedName
);
827 throw InvalidRegistryException();
831 //*************************************************************************
832 Sequence
< Reference
< XRegistryKey
> > SAL_CALL
NestedKeyImpl::openKeys( )
833 throw(InvalidRegistryException
, RuntimeException
)
835 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
836 if ( !m_localKey
.is() && !m_defaultKey
.is() )
838 throw InvalidRegistryException();
841 Sequence
<OUString
> localSeq
, defaultSeq
;
843 if ( m_localKey
.is() && m_localKey
->isValid() )
845 localSeq
= m_localKey
->getKeyNames();
847 if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
849 defaultSeq
= m_defaultKey
->getKeyNames();
852 sal_uInt32 local
= localSeq
.getLength();
853 sal_uInt32 def
= defaultSeq
.getLength();
857 for (i
=0; i
< local
; i
++)
859 for (j
=0 ; j
< def
; j
++)
861 if ( localSeq
.getConstArray()[i
] == defaultSeq
.getConstArray()[j
] )
869 Sequence
< Reference
<XRegistryKey
> > retSeq(local
+ def
- len
);
870 sal_Bool insert
= sal_True
;
874 for (i
=0; i
< local
; i
++)
876 name
= localSeq
.getConstArray()[i
];
877 lastIndex
= name
.lastIndexOf('/');
878 name
= name
.copy(lastIndex
);
879 retSeq
.getArray()[i
] =
880 (XRegistryKey
*)new NestedKeyImpl(name
, this);
883 sal_uInt32 k
= local
;
884 for (i
=0; i
< def
; i
++)
888 for (j
=0 ; j
< local
; j
++)
890 if ( retSeq
.getConstArray()[j
]->getKeyName()
891 == defaultSeq
.getConstArray()[i
] )
900 name
= defaultSeq
.getConstArray()[i
];
901 lastIndex
= name
.lastIndexOf('/');
902 name
= name
.copy(lastIndex
);
903 retSeq
.getArray()[k
++] =
904 (XRegistryKey
*)new NestedKeyImpl(name
, this);
911 //*************************************************************************
912 Sequence
< OUString
> SAL_CALL
NestedKeyImpl::getKeyNames( )
913 throw(InvalidRegistryException
, RuntimeException
)
915 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
916 if ( !m_localKey
.is() && !m_defaultKey
.is() )
918 throw InvalidRegistryException();
921 Sequence
<OUString
> localSeq
, defaultSeq
;
923 if ( m_localKey
.is() && m_localKey
->isValid() )
925 localSeq
= m_localKey
->getKeyNames();
927 if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
929 defaultSeq
= m_defaultKey
->getKeyNames();
932 sal_uInt32 local
= localSeq
.getLength();
933 sal_uInt32 def
= defaultSeq
.getLength();
937 for (i
=0; i
< local
; i
++)
939 for (j
=0 ; j
< def
; j
++)
941 if ( localSeq
.getConstArray()[i
] == defaultSeq
.getConstArray()[j
] )
949 Sequence
<OUString
> retSeq(local
+ def
- len
);
950 sal_Bool insert
= sal_True
;
952 for (i
=0; i
< local
; i
++)
954 retSeq
.getArray()[i
] = localSeq
.getConstArray()[i
];
957 sal_uInt32 k
= local
;
958 for (i
=0; i
< def
; i
++)
962 for (j
=0 ; j
< local
; j
++)
964 if ( retSeq
.getConstArray()[j
] == defaultSeq
.getConstArray()[i
] )
972 retSeq
.getArray()[k
++] = defaultSeq
.getConstArray()[i
];
978 //*************************************************************************
979 sal_Bool SAL_CALL
NestedKeyImpl::createLink( const OUString
& aLinkName
, const OUString
& aLinkTarget
)
980 throw(InvalidRegistryException
, RuntimeException
)
982 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
984 sal_Bool isCreated
= sal_False
;
985 if ( !m_localKey
.is() && !m_defaultKey
.is() )
987 throw InvalidRegistryException();
991 OUString resolvedName
;
992 sal_Int32 lastIndex
= aLinkName
.lastIndexOf('/');
996 linkName
= aLinkName
.copy(0, lastIndex
);
998 resolvedName
= computeName(linkName
);
1000 if ( resolvedName
.getLength() == 0 )
1002 throw InvalidRegistryException();
1005 resolvedName
= resolvedName
+ aLinkName
.copy(lastIndex
);
1008 if ( lastIndex
== 0 )
1009 resolvedName
= m_name
+ aLinkName
;
1011 resolvedName
= m_name
+ OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) + aLinkName
;
1014 if ( m_localKey
.is() && m_localKey
->isValid() )
1016 isCreated
= m_pRegistry
->m_localReg
->getRootKey()->createLink(resolvedName
, aLinkTarget
);
1019 if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
1021 Reference
<XRegistryKey
> rootKey(m_pRegistry
->m_localReg
->getRootKey());
1022 m_localKey
= rootKey
->createKey(m_name
);
1024 isCreated
= m_pRegistry
->m_localReg
->getRootKey()->createLink(resolvedName
, aLinkTarget
);
1029 m_state
= m_pRegistry
->m_state
++;
1034 //*************************************************************************
1035 void SAL_CALL
NestedKeyImpl::deleteLink( const OUString
& rLinkName
)
1036 throw(InvalidRegistryException
, RuntimeException
)
1038 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
1039 if ( !m_localKey
.is() && !m_defaultKey
.is() )
1041 throw InvalidRegistryException();
1045 OUString resolvedName
;
1046 sal_Int32 lastIndex
= rLinkName
.lastIndexOf('/');
1048 if ( lastIndex
> 0 )
1050 linkName
= rLinkName
.copy(0, lastIndex
);
1052 resolvedName
= computeName(linkName
);
1054 if ( resolvedName
.getLength() == 0 )
1056 throw InvalidRegistryException();
1059 resolvedName
= resolvedName
+ rLinkName
.copy(lastIndex
);
1062 if ( lastIndex
== 0 )
1063 resolvedName
= m_name
+ rLinkName
;
1065 resolvedName
= m_name
+ OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) + rLinkName
;
1068 if ( m_localKey
.is() && m_localKey
->isValid() &&
1069 !m_localKey
->isReadOnly() )
1071 m_pRegistry
->m_localReg
->getRootKey()->deleteLink(resolvedName
);
1074 throw InvalidRegistryException();
1078 //*************************************************************************
1079 OUString SAL_CALL
NestedKeyImpl::getLinkTarget( const OUString
& rLinkName
)
1080 throw(InvalidRegistryException
, RuntimeException
)
1082 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
1083 if ( !m_localKey
.is() && !m_defaultKey
.is() )
1085 throw InvalidRegistryException();
1089 OUString resolvedName
;
1090 sal_Int32 lastIndex
= rLinkName
.lastIndexOf('/');
1092 if ( lastIndex
> 0 )
1094 linkName
= rLinkName
.copy(0, lastIndex
);
1096 resolvedName
= computeName(linkName
);
1098 if ( resolvedName
.getLength() == 0 )
1100 throw InvalidRegistryException();
1103 resolvedName
= resolvedName
+ rLinkName
.copy(lastIndex
);
1106 if ( lastIndex
== 0 )
1107 resolvedName
= m_name
+ rLinkName
;
1109 resolvedName
= m_name
+ OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) + rLinkName
;
1112 OUString linkTarget
;
1113 if ( m_localKey
.is() && m_localKey
->isValid() )
1117 linkTarget
= m_pRegistry
->m_localReg
->getRootKey()->getLinkTarget(resolvedName
);
1120 catch(InvalidRegistryException
& )
1125 if ( m_defaultKey
.is() && m_defaultKey
->isValid() )
1126 linkTarget
= m_pRegistry
->m_defaultReg
->getRootKey()->getLinkTarget(resolvedName
);
1131 //*************************************************************************
1132 OUString SAL_CALL
NestedKeyImpl::getResolvedName( const OUString
& aKeyName
)
1133 throw(InvalidRegistryException
, RuntimeException
)
1135 Guard
< Mutex
> aGuard( m_pRegistry
->m_mutex
);
1136 if ( !m_localKey
.is() && !m_defaultKey
.is() )
1138 throw InvalidRegistryException();
1141 OUString resolvedName
= computeName(aKeyName
);
1143 if ( resolvedName
.getLength() == 0 )
1145 throw InvalidRegistryException();
1148 return resolvedName
;
1151 //*************************************************************************
1153 // DefaultRegistry Implementation
1155 //*************************************************************************
1156 NestedRegistryImpl::NestedRegistryImpl( )
1159 g_moduleCount
.modCnt
.acquire( &g_moduleCount
.modCnt
);
1162 //*************************************************************************
1163 NestedRegistryImpl::~NestedRegistryImpl()
1165 g_moduleCount
.modCnt
.release( &g_moduleCount
.modCnt
);
1169 class RegistryEnumueration
: public WeakImplHelper1
< XEnumeration
>
1172 RegistryEnumueration(
1173 const Reference
< XSimpleRegistry
> &r1
,
1174 const Reference
< XSimpleRegistry
> &r2
)
1175 : m_xReg1( r1
) , m_xReg2( r2
)
1178 virtual sal_Bool SAL_CALL
hasMoreElements( ) throw (RuntimeException
);
1179 virtual Any SAL_CALL
nextElement( ) throw (NoSuchElementException
, WrappedTargetException
, RuntimeException
);
1182 Reference
< XSimpleRegistry
> m_xReg1
;
1183 Reference
< XSimpleRegistry
> m_xReg2
;
1186 sal_Bool
RegistryEnumueration::hasMoreElements( ) throw (RuntimeException
)
1188 return m_xReg1
.is() || m_xReg2
.is();
1191 Any
RegistryEnumueration::nextElement( )
1192 throw (NoSuchElementException
, WrappedTargetException
, RuntimeException
)
1200 else if( m_xReg2
.is() )
1207 throw NoSuchElementException( OUString( RTL_CONSTASCII_USTRINGPARAM(
1208 "NestedRegistry: no nextElement() !" ) ),Reference
< XInterface
> () );
1214 Reference
< XEnumeration
> NestedRegistryImpl::createEnumeration( ) throw (RuntimeException
)
1216 MutexGuard
guard( m_mutex
);
1217 return new RegistryEnumueration( m_localReg
, m_defaultReg
);
1220 Type
NestedRegistryImpl::getElementType( ) throw (RuntimeException
)
1222 return getCppuType( &m_localReg
);
1225 sal_Bool SAL_CALL
NestedRegistryImpl::hasElements( ) throw (RuntimeException
)
1227 MutexGuard
guard( m_mutex
);
1228 return m_localReg
.is() || m_defaultReg
.is();
1233 //*************************************************************************
1234 OUString SAL_CALL
NestedRegistryImpl::getImplementationName( )
1235 throw(RuntimeException
)
1237 return stoc_bootstrap::defreg_getImplementationName();
1240 //*************************************************************************
1241 sal_Bool SAL_CALL
NestedRegistryImpl::supportsService( const OUString
& ServiceName
)
1242 throw(RuntimeException
)
1244 Guard
< Mutex
> aGuard( m_mutex
);
1245 Sequence
< OUString
> aSNL
= getSupportedServiceNames();
1246 const OUString
* pArray
= aSNL
.getArray();
1247 for( sal_Int32 i
= 0; i
< aSNL
.getLength(); i
++ )
1248 if( pArray
[i
] == ServiceName
)
1253 //*************************************************************************
1254 Sequence
<OUString
> SAL_CALL
NestedRegistryImpl::getSupportedServiceNames( )
1255 throw(RuntimeException
)
1257 return stoc_bootstrap::defreg_getSupportedServiceNames();
1260 //*************************************************************************
1261 void SAL_CALL
NestedRegistryImpl::initialize( const Sequence
< Any
>& aArguments
)
1262 throw( Exception
, RuntimeException
)
1264 Guard
< Mutex
> aGuard( m_mutex
);
1265 if ( (aArguments
.getLength() == 2) &&
1266 (aArguments
[0].getValueType().getTypeClass() == TypeClass_INTERFACE
) &&
1267 (aArguments
[1].getValueType().getTypeClass() == TypeClass_INTERFACE
) )
1269 aArguments
[0] >>= m_localReg
;
1270 aArguments
[1] >>= m_defaultReg
;
1271 if ( m_localReg
== m_defaultReg
)
1272 m_defaultReg
= Reference
< XSimpleRegistry
>();
1276 //*************************************************************************
1277 OUString SAL_CALL
NestedRegistryImpl::getURL() throw(RuntimeException
)
1279 Guard
< Mutex
> aGuard( m_mutex
);
1282 if ( m_localReg
.is() && m_localReg
->isValid() )
1283 return m_localReg
->getURL();
1285 catch(InvalidRegistryException
& )
1292 //*************************************************************************
1293 void SAL_CALL
NestedRegistryImpl::open( const OUString
&, sal_Bool
, sal_Bool
)
1294 throw(InvalidRegistryException
, RuntimeException
)
1296 throw InvalidRegistryException(
1297 OUString::createFromAscii("the 'open' method is not specified for a nested registry"),
1298 Reference
< XInterface
>() );
1301 //*************************************************************************
1302 sal_Bool SAL_CALL
NestedRegistryImpl::isValid( ) throw(RuntimeException
)
1304 Guard
< Mutex
> aGuard( m_mutex
);
1307 if ( (m_localReg
.is() && m_localReg
->isValid()) ||
1308 (m_defaultReg
.is() && m_defaultReg
->isValid()) )
1311 catch(InvalidRegistryException
& )
1318 //*************************************************************************
1319 void SAL_CALL
NestedRegistryImpl::close( )
1320 throw(InvalidRegistryException
, RuntimeException
)
1322 Guard
< Mutex
> aGuard( m_mutex
);
1323 if ( m_localReg
.is() && m_localReg
->isValid() )
1325 m_localReg
->close();
1327 if ( m_defaultReg
.is() && m_defaultReg
->isValid() )
1329 m_defaultReg
->close();
1332 throw InvalidRegistryException(
1333 OUString::createFromAscii("the 'close' method is not specified for a nested registry"),
1334 Reference< XInterface >() );
1338 //*************************************************************************
1339 void SAL_CALL
NestedRegistryImpl::destroy( )
1340 throw(InvalidRegistryException
, RuntimeException
)
1342 throw InvalidRegistryException(
1343 OUString::createFromAscii("the 'destroy' method is not specified for a nested registry"),
1344 Reference
< XInterface
>() );
1347 //*************************************************************************
1348 Reference
< XRegistryKey
> SAL_CALL
NestedRegistryImpl::getRootKey( )
1349 throw(InvalidRegistryException
, RuntimeException
)
1351 Reference
<XRegistryKey
> tmpKey
;
1353 Guard
< Mutex
> aGuard( m_mutex
);
1354 if ( m_localReg
.is() && m_localReg
->isValid() )
1356 Reference
<XRegistryKey
> localKey
, defaultKey
;
1358 localKey
= m_localReg
->getRootKey();
1360 if ( localKey
.is() )
1362 if ( m_defaultReg
.is() && m_defaultReg
->isValid() )
1364 defaultKey
= m_defaultReg
->getRootKey();
1367 return ((XRegistryKey
*)new NestedKeyImpl(this, localKey
, defaultKey
));
1371 throw InvalidRegistryException();
1374 return Reference
<XRegistryKey
>();
1377 //*************************************************************************
1378 sal_Bool SAL_CALL
NestedRegistryImpl::isReadOnly( )
1379 throw(InvalidRegistryException
, RuntimeException
)
1381 Guard
< Mutex
> aGuard( m_mutex
);
1384 if ( m_localReg
.is() && m_localReg
->isValid() )
1385 return m_localReg
->isReadOnly();
1387 catch(InvalidRegistryException
& )
1394 //*************************************************************************
1395 void SAL_CALL
NestedRegistryImpl::mergeKey( const OUString
& aKeyName
, const OUString
& aUrl
)
1396 throw(InvalidRegistryException
, MergeConflictException
, RuntimeException
)
1398 Guard
< Mutex
> aGuard( m_mutex
);
1399 if ( m_localReg
.is() && m_localReg
->isValid() )
1401 m_localReg
->mergeKey(aKeyName
, aUrl
);
1406 } // namespace stco_defreg
1408 namespace stoc_bootstrap
1410 //*************************************************************************
1411 Reference
<XInterface
> SAL_CALL
NestedRegistry_CreateInstance( const Reference
<XComponentContext
>& )
1414 Reference
<XInterface
> xRet
;
1415 XSimpleRegistry
*pRegistry
= (XSimpleRegistry
*) new stoc_defreg::NestedRegistryImpl
;
1419 xRet
= Reference
<XInterface
>::query(pRegistry
);