update dev300-m58
[ooovba.git] / stoc / source / defaultregistry / defaultregistry.cxx
blobf474fd260852ae41bb4905b4115f88a33770ce53
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: defaultregistry.cxx,v $
10 * $Revision: 1.13 $
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>
36 #endif
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>
45 #endif
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;
62 using namespace cppu;
63 using namespace osl;
64 using namespace rtl;
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;
77 if( ! pNames )
79 MutexGuard guard( Mutex::getGlobalMutex() );
80 if( !pNames )
82 static Sequence< OUString > seqNames(1);
83 seqNames.getArray()[0] = OUString(RTL_CONSTASCII_USTRINGPARAM(SERVICENAME));
84 pNames = &seqNames;
87 return *pNames;
90 OUString defreg_getImplementationName()
92 static OUString *pImplName = 0;
93 if( ! pImplName )
95 MutexGuard guard( Mutex::getGlobalMutex() );
96 if( ! pImplName )
98 static OUString implName( RTL_CONSTASCII_USTRINGPARAM( IMPLNAME ) );
99 pImplName = &implName;
102 return *pImplName;
106 namespace stoc_defreg
108 //*************************************************************************
109 // NestedRegistryImpl
110 //*************************************************************************
111 class NestedKeyImpl;
113 class NestedRegistryImpl : public WeakAggImplHelper4 < XSimpleRegistry, XInitialization, XServiceInfo, XEnumerationAccess >
115 public:
116 NestedRegistryImpl( );
118 ~NestedRegistryImpl();
120 // XServiceInfo
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);
125 // XInitialization
126 virtual void SAL_CALL initialize( const Sequence< Any >& aArguments )
127 throw(Exception, RuntimeException);
129 // XSimpleRegistry
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;
145 protected:
146 Mutex m_mutex;
147 sal_uInt32 m_state;
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 >
158 public:
159 NestedKeyImpl( NestedRegistryImpl* pDefaultRegistry,
160 Reference<XRegistryKey>& localKey,
161 Reference<XRegistryKey>& defaultKey);
163 NestedKeyImpl( const OUString& aKeyName,
164 NestedKeyImpl* pKey);
166 ~NestedKeyImpl();
168 // XRegistryKey
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);
199 protected:
200 void computeChanges();
201 OUString computeName(const OUString& name);
203 OUString m_name;
204 sal_uInt32 m_state;
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;
222 if (m_localKey.is())
224 m_name = m_localKey->getKeyName();
225 } else
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,
236 NestedKeyImpl* pKey)
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);
250 if (m_localKey.is())
252 m_name = m_localKey->getKeyName();
253 } else
254 if (m_defaultKey.is())
256 m_name = m_defaultKey->getKeyName();
259 m_state = m_pRegistry->m_state;
262 //*************************************************************************
263 NestedKeyImpl::~NestedKeyImpl()
265 if ( m_pRegistry )
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);
279 if ( tmpKey.is() )
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);
301 } else
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)
318 count--;
320 if (resLocalName.getLength() == 0 || resDefaultName.getLength() == 0)
321 throw InvalidRegistryException();
323 resLocalName = localRoot->getResolvedName(resDefaultName);
324 resDefaultName = defaultRoot->getResolvedName(resLocalName);
328 catch(InvalidRegistryException& )
332 return resLocalName;
335 //*************************************************************************
336 OUString SAL_CALL NestedKeyImpl::getKeyName() throw(RuntimeException)
338 Guard< Mutex > aGuard( m_pRegistry->m_mutex );
339 return m_name;
342 //*************************************************************************
343 sal_Bool SAL_CALL NestedKeyImpl::isReadOnly( )
344 throw(InvalidRegistryException, RuntimeException)
346 Guard< Mutex > aGuard( m_pRegistry->m_mutex );
347 computeChanges();
349 if ( m_localKey.is() && m_localKey->isValid() )
350 return m_localKey->isReadOnly();
351 else
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 );
368 computeChanges();
370 if ( m_localKey.is() && m_localKey->isValid() )
372 return m_localKey->getKeyType(rKeyName);
373 } else
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 );
387 computeChanges();
389 if ( m_localKey.is() && m_localKey->isValid() )
391 return m_localKey->getValueType();
392 } else
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 );
406 computeChanges();
408 if ( m_localKey.is() && m_localKey->isValid() )
410 return m_localKey->getLongValue();
411 } else
412 if ( m_defaultKey.is() && m_defaultKey->isValid() )
414 return m_defaultKey->getLongValue();
415 } else
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 );
426 computeChanges();
428 if ( m_localKey.is() && m_localKey->isValid() )
430 m_localKey->setLongValue(value);
431 } else
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++;
438 } else
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 );
449 computeChanges();
451 if ( m_localKey.is() && m_localKey->isValid() )
453 return m_localKey->getLongListValue();
454 } else
455 if ( m_defaultKey.is() && m_defaultKey->isValid() )
457 return m_defaultKey->getLongListValue();
458 } else
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 );
469 computeChanges();
471 if ( m_localKey.is() && m_localKey->isValid() )
473 m_localKey->setLongListValue(seqValue);
474 } else
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++;
481 } else
483 throw InvalidRegistryException();
487 //*************************************************************************
488 OUString SAL_CALL NestedKeyImpl::getAsciiValue( )
489 throw(InvalidRegistryException, InvalidValueException, RuntimeException)
491 Guard< Mutex > aGuard( m_pRegistry->m_mutex );
492 computeChanges();
494 if ( m_localKey.is() && m_localKey->isValid() )
496 return m_localKey->getAsciiValue();
497 } else
498 if ( m_defaultKey.is() && m_defaultKey->isValid() )
500 return m_defaultKey->getAsciiValue();
501 } else
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 );
512 computeChanges();
514 if ( m_localKey.is() && m_localKey->isValid() )
516 m_localKey->setAsciiValue(value);
517 } else
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++;
524 } else
526 throw InvalidRegistryException();
530 //*************************************************************************
531 Sequence< OUString > SAL_CALL NestedKeyImpl::getAsciiListValue( )
532 throw(InvalidRegistryException, InvalidValueException, RuntimeException)
534 Guard< Mutex > aGuard( m_pRegistry->m_mutex );
535 computeChanges();
537 if ( m_localKey.is() && m_localKey->isValid() )
539 return m_localKey->getAsciiListValue();
540 } else
541 if ( m_defaultKey.is() && m_defaultKey->isValid() )
543 return m_defaultKey->getAsciiListValue();
544 } else
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 );
555 computeChanges();
557 if ( m_localKey.is() && m_localKey->isValid() )
559 m_localKey->setAsciiListValue(seqValue);
560 } else
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++;
567 } else
569 throw InvalidRegistryException();
573 //*************************************************************************
574 OUString SAL_CALL NestedKeyImpl::getStringValue( )
575 throw(InvalidRegistryException, InvalidValueException, RuntimeException)
577 Guard< Mutex > aGuard( m_pRegistry->m_mutex );
578 computeChanges();
580 if ( m_localKey.is() && m_localKey->isValid() )
582 return m_localKey->getStringValue();
583 } else
584 if ( m_defaultKey.is() && m_defaultKey->isValid() )
586 return m_defaultKey->getStringValue();
587 } else
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 );
598 computeChanges();
600 if ( m_localKey.is() && m_localKey->isValid() )
602 m_localKey->setStringValue(value);
603 } else
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++;
610 } else
612 throw InvalidRegistryException();
616 //*************************************************************************
617 Sequence< OUString > SAL_CALL NestedKeyImpl::getStringListValue( )
618 throw(InvalidRegistryException, InvalidValueException, RuntimeException)
620 Guard< Mutex > aGuard( m_pRegistry->m_mutex );
621 computeChanges();
623 if ( m_localKey.is() && m_localKey->isValid() )
625 return m_localKey->getStringListValue();
626 } else
627 if ( m_defaultKey.is() && m_defaultKey->isValid() )
629 return m_defaultKey->getStringListValue();
630 } else
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 );
641 computeChanges();
643 if ( m_localKey.is() && m_localKey->isValid() )
645 m_localKey->setStringListValue(seqValue);
646 } else
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++;
653 } else
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 );
664 computeChanges();
666 if ( m_localKey.is() && m_localKey->isValid() )
668 return m_localKey->getBinaryValue();
669 } else
670 if ( m_defaultKey.is() && m_defaultKey->isValid() )
672 return m_defaultKey->getBinaryValue();
673 } else
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 );
684 computeChanges();
686 if ( m_localKey.is() && m_localKey->isValid() )
688 m_localKey->setBinaryValue(value);
689 } else
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++;
696 } else
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));
731 } else
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);
758 if ( localKey.is() )
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));
769 } else
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);
780 if ( localKey.is() )
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);
825 } else
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();
854 sal_uInt32 len = 0;
856 sal_uInt32 i, j;
857 for (i=0; i < local; i++)
859 for (j=0 ; j < def; j++)
861 if ( localSeq.getConstArray()[i] == defaultSeq.getConstArray()[j] )
863 len++;
864 break;
869 Sequence< Reference<XRegistryKey> > retSeq(local + def - len);
870 sal_Bool insert = sal_True;
871 OUString name;
872 sal_Int32 lastIndex;
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++)
886 insert = sal_True;
888 for (j=0 ; j < local; j++)
890 if ( retSeq.getConstArray()[j]->getKeyName()
891 == defaultSeq.getConstArray()[i] )
893 insert = sal_False;
894 break;
898 if ( insert )
900 name = defaultSeq.getConstArray()[i];
901 lastIndex = name.lastIndexOf('/');
902 name = name.copy(lastIndex);
903 retSeq.getArray()[k++] =
904 (XRegistryKey*)new NestedKeyImpl(name, this);
908 return retSeq;
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();
934 sal_uInt32 len = 0;
936 sal_uInt32 i, j;
937 for (i=0; i < local; i++)
939 for (j=0 ; j < def; j++)
941 if ( localSeq.getConstArray()[i] == defaultSeq.getConstArray()[j] )
943 len++;
944 break;
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++)
960 insert = sal_True;
962 for (j=0 ; j < local; j++)
964 if ( retSeq.getConstArray()[j] == defaultSeq.getConstArray()[i] )
966 insert = sal_False;
967 break;
971 if ( insert )
972 retSeq.getArray()[k++] = defaultSeq.getConstArray()[i];
975 return retSeq;
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();
990 OUString linkName;
991 OUString resolvedName;
992 sal_Int32 lastIndex = aLinkName.lastIndexOf('/');
994 if ( lastIndex > 0 )
996 linkName = aLinkName.copy(0, lastIndex);
998 resolvedName = computeName(linkName);
1000 if ( resolvedName.getLength() == 0 )
1002 throw InvalidRegistryException();
1005 resolvedName = resolvedName + aLinkName.copy(lastIndex);
1006 } else
1008 if ( lastIndex == 0 )
1009 resolvedName = m_name + aLinkName;
1010 else
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);
1017 } else
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);
1028 if ( isCreated )
1029 m_state = m_pRegistry->m_state++;
1031 return isCreated;
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();
1044 OUString linkName;
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);
1060 } else
1062 if ( lastIndex == 0 )
1063 resolvedName = m_name + rLinkName;
1064 else
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);
1072 } else
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();
1088 OUString linkName;
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);
1104 } else
1106 if ( lastIndex == 0 )
1107 resolvedName = m_name + rLinkName;
1108 else
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);
1118 return linkTarget;
1120 catch(InvalidRegistryException& )
1125 if ( m_defaultKey.is() && m_defaultKey->isValid() )
1126 linkTarget = m_pRegistry->m_defaultReg->getRootKey()->getLinkTarget(resolvedName);
1128 return linkTarget;
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( )
1157 : m_state(0)
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 >
1171 public:
1172 RegistryEnumueration(
1173 const Reference< XSimpleRegistry > &r1,
1174 const Reference< XSimpleRegistry > &r2 )
1175 : m_xReg1( r1 ) , m_xReg2( r2 )
1177 public:
1178 virtual sal_Bool SAL_CALL hasMoreElements( ) throw (RuntimeException);
1179 virtual Any SAL_CALL nextElement( ) throw (NoSuchElementException, WrappedTargetException, RuntimeException);
1181 private:
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)
1194 Any a;
1195 if( m_xReg1.is() )
1197 a <<= m_xReg1;
1198 m_xReg1.clear();
1200 else if( m_xReg2.is() )
1202 a <<= m_xReg2;
1203 m_xReg2.clear();
1205 else
1207 throw NoSuchElementException( OUString( RTL_CONSTASCII_USTRINGPARAM(
1208 "NestedRegistry: no nextElement() !" ) ),Reference< XInterface > () );
1210 return a;
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 )
1249 return sal_True;
1250 return sal_False;
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& )
1289 return OUString();
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()) )
1309 return sal_True;
1311 catch(InvalidRegistryException& )
1315 return sal_False;
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));
1369 } else
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& )
1391 return sal_False;
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);
1403 m_state++;
1406 } // namespace stco_defreg
1408 namespace stoc_bootstrap
1410 //*************************************************************************
1411 Reference<XInterface> SAL_CALL NestedRegistry_CreateInstance( const Reference<XComponentContext>& )
1412 throw(Exception)
1414 Reference<XInterface> xRet;
1415 XSimpleRegistry *pRegistry = (XSimpleRegistry*) new stoc_defreg::NestedRegistryImpl;
1417 if (pRegistry)
1419 xRet = Reference<XInterface>::query(pRegistry);
1422 return xRet;