Update ooo320-m1
[ooovba.git] / stoc / source / simpleregistry / simpleregistry.cxx
blob0fa866c2f24619a5c89007e6fbe2b502a89c05b9
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: simpleregistry.cxx,v $
10 * $Revision: 1.18 $
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/diagnose.h>
34 #include <osl/mutex.hxx>
35 #include <rtl/alloc.h>
36 #ifndef _RTL_USTRBUF_H_
37 #include <rtl/ustrbuf.hxx>
38 #endif
39 #include <cppuhelper/queryinterface.hxx>
40 #include <cppuhelper/weak.hxx>
41 #include <cppuhelper/factory.hxx>
42 #include <cppuhelper/implbase1.hxx>
43 #include <cppuhelper/implbase2.hxx>
44 #ifndef _CPPUHELPER_IMPLEMENTATIONENTRY_HXX_
45 #include <cppuhelper/implementationentry.hxx>
46 #endif
47 #include <registry/registry.hxx>
49 #include <com/sun/star/registry/XSimpleRegistry.hpp>
50 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
51 #include <com/sun/star/lang/XServiceInfo.hpp>
52 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
54 using namespace com::sun::star::uno;
55 using namespace com::sun::star::registry;
56 using namespace com::sun::star::lang;
57 using namespace cppu;
58 using namespace osl;
59 using namespace rtl;
61 #define SERVICENAME "com.sun.star.registry.SimpleRegistry"
62 #define IMPLNAME "com.sun.star.comp.stoc.SimpleRegistry"
64 extern rtl_StandardModuleCount g_moduleCount;
66 namespace stoc_bootstrap
68 Sequence< OUString > simreg_getSupportedServiceNames()
70 static Sequence < OUString > *pNames = 0;
71 if( ! pNames )
73 MutexGuard guard( Mutex::getGlobalMutex() );
74 if( !pNames )
76 static Sequence< OUString > seqNames(1);
77 seqNames.getArray()[0] = OUString(RTL_CONSTASCII_USTRINGPARAM(SERVICENAME));
78 pNames = &seqNames;
81 return *pNames;
84 OUString simreg_getImplementationName()
86 static OUString *pImplName = 0;
87 if( ! pImplName )
89 MutexGuard guard( Mutex::getGlobalMutex() );
90 if( ! pImplName )
92 static OUString implName( RTL_CONSTASCII_USTRINGPARAM( IMPLNAME ) );
93 pImplName = &implName;
96 return *pImplName;
100 namespace stoc_simreg {
102 //*************************************************************************
103 // class RegistryKeyImpl the implenetation of interface XRegistryKey
104 //*************************************************************************
105 class RegistryKeyImpl;
107 //*************************************************************************
108 // SimpleRegistryImpl
109 //*************************************************************************
110 class SimpleRegistryImpl : public WeakImplHelper2< XSimpleRegistry, XServiceInfo >
112 public:
113 SimpleRegistryImpl( const Registry& rRegistry );
115 ~SimpleRegistryImpl();
117 // XServiceInfo
118 virtual OUString SAL_CALL getImplementationName( ) throw(RuntimeException);
119 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(RuntimeException);
120 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw(RuntimeException);
122 // XSimpleRegistry
123 virtual OUString SAL_CALL getURL() throw(RuntimeException);
124 virtual void SAL_CALL open( const OUString& rURL, sal_Bool bReadOnly, sal_Bool bCreate ) throw(InvalidRegistryException, RuntimeException);
125 virtual sal_Bool SAL_CALL isValid( ) throw(RuntimeException);
126 virtual void SAL_CALL close( ) throw(InvalidRegistryException, RuntimeException);
127 virtual void SAL_CALL destroy( ) throw(InvalidRegistryException, RuntimeException);
128 virtual Reference< XRegistryKey > SAL_CALL getRootKey( ) throw(InvalidRegistryException, RuntimeException);
129 virtual sal_Bool SAL_CALL isReadOnly( ) throw(InvalidRegistryException, RuntimeException);
130 virtual void SAL_CALL mergeKey( const OUString& aKeyName, const OUString& aUrl ) throw(InvalidRegistryException, MergeConflictException, RuntimeException);
132 friend class RegistryKeyImpl;
133 protected:
134 Mutex m_mutex;
135 OUString m_url;
136 Registry m_registry;
140 class RegistryKeyImpl : public WeakImplHelper1< XRegistryKey >
142 public:
143 RegistryKeyImpl( const RegistryKey& rKey, SimpleRegistryImpl* pRegistry );
145 RegistryKeyImpl( const OUString& rKeyName, SimpleRegistryImpl* pRegistry );
147 ~RegistryKeyImpl();
149 // XRegistryKey
150 virtual OUString SAL_CALL getKeyName() throw(RuntimeException);
151 virtual sal_Bool SAL_CALL isReadOnly( ) throw(InvalidRegistryException, RuntimeException);
152 virtual sal_Bool SAL_CALL isValid( ) throw(RuntimeException);
153 virtual RegistryKeyType SAL_CALL getKeyType( const OUString& rKeyName ) throw(InvalidRegistryException, RuntimeException);
154 virtual RegistryValueType SAL_CALL getValueType( ) throw(InvalidRegistryException, RuntimeException);
155 virtual sal_Int32 SAL_CALL getLongValue( ) throw(InvalidRegistryException, InvalidValueException, RuntimeException);
156 virtual void SAL_CALL setLongValue( sal_Int32 value ) throw(InvalidRegistryException, RuntimeException);
157 virtual Sequence< sal_Int32 > SAL_CALL getLongListValue( ) throw(InvalidRegistryException, InvalidValueException, RuntimeException);
158 virtual void SAL_CALL setLongListValue( const ::com::sun::star::uno::Sequence< sal_Int32 >& seqValue ) throw(InvalidRegistryException, RuntimeException);
159 virtual OUString SAL_CALL getAsciiValue( ) throw(InvalidRegistryException, InvalidValueException, RuntimeException);
160 virtual void SAL_CALL setAsciiValue( const OUString& value ) throw(InvalidRegistryException, RuntimeException);
161 virtual Sequence< OUString > SAL_CALL getAsciiListValue( ) throw(InvalidRegistryException, InvalidValueException, RuntimeException);
162 virtual void SAL_CALL setAsciiListValue( const ::com::sun::star::uno::Sequence< OUString >& seqValue ) throw(InvalidRegistryException, RuntimeException);
163 virtual OUString SAL_CALL getStringValue( ) throw(InvalidRegistryException, InvalidValueException, RuntimeException);
164 virtual void SAL_CALL setStringValue( const OUString& value ) throw(InvalidRegistryException, RuntimeException);
165 virtual Sequence< OUString > SAL_CALL getStringListValue( ) throw(InvalidRegistryException, InvalidValueException, RuntimeException);
166 virtual void SAL_CALL setStringListValue( const ::com::sun::star::uno::Sequence< OUString >& seqValue ) throw(InvalidRegistryException, RuntimeException);
167 virtual Sequence< sal_Int8 > SAL_CALL getBinaryValue( ) throw(InvalidRegistryException, InvalidValueException, RuntimeException);
168 virtual void SAL_CALL setBinaryValue( const ::com::sun::star::uno::Sequence< sal_Int8 >& value ) throw(InvalidRegistryException, RuntimeException);
169 virtual Reference< XRegistryKey > SAL_CALL openKey( const OUString& aKeyName ) throw(InvalidRegistryException, RuntimeException);
170 virtual Reference< XRegistryKey > SAL_CALL createKey( const OUString& aKeyName ) throw(InvalidRegistryException, RuntimeException);
171 virtual void SAL_CALL closeKey( ) throw(InvalidRegistryException, RuntimeException);
172 virtual void SAL_CALL deleteKey( const OUString& rKeyName ) throw(InvalidRegistryException, RuntimeException);
173 virtual Sequence< Reference< XRegistryKey > > SAL_CALL openKeys( ) throw(InvalidRegistryException, RuntimeException);
174 virtual Sequence< OUString > SAL_CALL getKeyNames( ) throw(InvalidRegistryException, RuntimeException);
175 virtual sal_Bool SAL_CALL createLink( const OUString& aLinkName, const OUString& aLinkTarget ) throw(InvalidRegistryException, RuntimeException);
176 virtual void SAL_CALL deleteLink( const OUString& rLinkName ) throw(InvalidRegistryException, RuntimeException);
177 virtual OUString SAL_CALL getLinkTarget( const OUString& rLinkName ) throw(InvalidRegistryException, RuntimeException);
178 virtual OUString SAL_CALL getResolvedName( const OUString& aKeyName ) throw(InvalidRegistryException, RuntimeException);
180 protected:
181 OUString m_name;
182 RegistryKey m_key;
183 SimpleRegistryImpl* m_pRegistry;
186 //*************************************************************************
187 RegistryKeyImpl::RegistryKeyImpl( const RegistryKey& key, SimpleRegistryImpl* pRegistry )
188 : m_key(key)
189 , m_pRegistry(pRegistry)
191 m_pRegistry->acquire();
192 m_name = m_key.getName();
195 //*************************************************************************
196 RegistryKeyImpl::RegistryKeyImpl( const OUString& rKeyName,
197 SimpleRegistryImpl* pRegistry )
198 : m_pRegistry(pRegistry)
200 m_pRegistry->acquire();
202 RegistryKey rootKey;
203 if (!pRegistry->m_registry.isValid() ||
204 pRegistry->m_registry.openRootKey(rootKey))
206 throw InvalidRegistryException(
207 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
208 (OWeakObject *)this );
209 } else
211 if ( rootKey.openKey(rKeyName, m_key) )
213 throw InvalidRegistryException(
214 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
215 (OWeakObject *)this );
216 } else
218 m_name = rKeyName;
223 //*************************************************************************
224 RegistryKeyImpl::~RegistryKeyImpl()
226 m_pRegistry->release();
229 //*************************************************************************
230 OUString SAL_CALL RegistryKeyImpl::getKeyName() throw(RuntimeException)
232 Guard< Mutex > aGuard( m_pRegistry->m_mutex );
233 return m_name;
236 //*************************************************************************
237 sal_Bool SAL_CALL RegistryKeyImpl::isReadOnly( )
238 throw(InvalidRegistryException, RuntimeException)
240 Guard< Mutex > aGuard( m_pRegistry->m_mutex );
241 if (m_key.isValid())
243 return(m_key.isReadOnly());
244 } else
246 throw InvalidRegistryException(
247 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
248 (OWeakObject *)this );
252 //*************************************************************************
253 sal_Bool SAL_CALL RegistryKeyImpl::isValid( ) throw(RuntimeException)
255 Guard< Mutex > aGuard( m_pRegistry->m_mutex );
256 return m_key.isValid();
259 //*************************************************************************
260 RegistryKeyType SAL_CALL RegistryKeyImpl::getKeyType( const OUString& rKeyName )
261 throw(InvalidRegistryException, RuntimeException)
263 Guard< Mutex > aGuard( m_pRegistry->m_mutex );
264 if ( m_key.isValid() )
266 RegKeyType keyType;
267 if ( !m_key.getKeyType(rKeyName, &keyType) )
269 switch (keyType)
271 case RG_KEYTYPE:
272 return RegistryKeyType_KEY;
273 case RG_LINKTYPE:
274 return RegistryKeyType_LINK;
276 } else
278 throw InvalidRegistryException(
279 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
280 (OWeakObject *)this );
282 } else
284 throw InvalidRegistryException(
285 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
286 (OWeakObject *)this );
289 return RegistryKeyType_KEY;
292 //*************************************************************************
293 RegistryValueType SAL_CALL RegistryKeyImpl::getValueType( )
294 throw(InvalidRegistryException, RuntimeException)
296 Guard< Mutex > aGuard( m_pRegistry->m_mutex );
297 if (!m_key.isValid())
299 throw InvalidRegistryException(
300 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
301 (OWeakObject *)this );
302 } else
304 RegValueType type;
305 sal_uInt32 size;
307 if (m_key.getValueInfo(OUString(), &type, &size))
309 return RegistryValueType_NOT_DEFINED;
310 } else
312 switch (type)
314 case RG_VALUETYPE_LONG: return RegistryValueType_LONG;
315 case RG_VALUETYPE_STRING: return RegistryValueType_ASCII;
316 case RG_VALUETYPE_UNICODE: return RegistryValueType_STRING;
317 case RG_VALUETYPE_BINARY: return RegistryValueType_BINARY;
318 case RG_VALUETYPE_LONGLIST: return RegistryValueType_LONGLIST;
319 case RG_VALUETYPE_STRINGLIST: return RegistryValueType_ASCIILIST;
320 case RG_VALUETYPE_UNICODELIST: return RegistryValueType_STRINGLIST;
321 default: return RegistryValueType_NOT_DEFINED;
326 return RegistryValueType_NOT_DEFINED;
329 //*************************************************************************
330 sal_Int32 SAL_CALL RegistryKeyImpl::getLongValue( )
331 throw(InvalidRegistryException, InvalidValueException, RuntimeException)
333 Guard< Mutex > aGuard( m_pRegistry->m_mutex );
334 if (!m_key.isValid())
336 throw InvalidRegistryException(
337 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
338 (OWeakObject *)this );
339 } else
341 RegValueType type;
342 sal_uInt32 size;
344 if ( !m_key.getValueInfo(OUString(), &type, &size) )
346 if (type == RG_VALUETYPE_LONG)
348 sal_Int32 value;
349 if ( !m_key.getValue(OUString(), (RegValue)&value) )
351 return value;
356 throw InvalidValueException(
357 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidValueException") ),
358 (OWeakObject *)this );
362 //*************************************************************************
363 void SAL_CALL RegistryKeyImpl::setLongValue( sal_Int32 value )
364 throw(InvalidRegistryException, RuntimeException)
366 Guard< Mutex > aGuard( m_pRegistry->m_mutex );
367 if ( !m_key.isValid() )
369 throw InvalidRegistryException(
370 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
371 (OWeakObject *)this );
372 } else
374 if (m_key.setValue(OUString(), RG_VALUETYPE_LONG, &value, sizeof(sal_Int32)))
376 throw InvalidValueException(
377 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidValueException") ),
378 (OWeakObject *)this );
383 //*************************************************************************
384 Sequence< sal_Int32 > SAL_CALL RegistryKeyImpl::getLongListValue( )
385 throw(InvalidRegistryException, InvalidValueException, RuntimeException)
387 Guard< Mutex > aGuard( m_pRegistry->m_mutex );
388 if ( !m_key.isValid() )
390 throw InvalidRegistryException(
391 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
392 (OWeakObject *)this );
393 } else
395 RegValueType type;
396 sal_uInt32 size;
398 if ( !m_key.getValueInfo(OUString(), &type, &size) )
400 if (type == RG_VALUETYPE_LONGLIST)
402 RegistryValueList<sal_Int32> tmpValue;
403 if ( !m_key.getLongListValue(OUString(), tmpValue) )
405 Sequence<sal_Int32> seqValue(size);
407 for (sal_uInt32 i=0; i < size; i++)
409 seqValue.getArray()[i] = tmpValue.getElement(i);
412 return seqValue;
417 throw InvalidValueException(
418 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidValueException") ),
419 (OWeakObject *)this );
423 //*************************************************************************
424 void SAL_CALL RegistryKeyImpl::setLongListValue( const Sequence< sal_Int32 >& seqValue )
425 throw(InvalidRegistryException, RuntimeException)
427 Guard< Mutex > aGuard( m_pRegistry->m_mutex );
428 if ( !m_key.isValid() )
430 throw InvalidRegistryException(
431 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
432 (OWeakObject *)this );
433 } else
435 sal_uInt32 length = seqValue.getLength();
436 sal_Int32* tmpValue = new sal_Int32[length];
438 for (sal_uInt32 i=0; i < length; i++)
440 tmpValue[i] = seqValue.getConstArray()[i];
443 if ( m_key.setLongListValue(OUString(), tmpValue, length) )
445 delete[] tmpValue;
446 throw InvalidValueException(
447 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidValueException") ),
448 (OWeakObject *)this );
451 delete[] tmpValue;
455 //*************************************************************************
456 OUString SAL_CALL RegistryKeyImpl::getAsciiValue( )
457 throw(InvalidRegistryException, InvalidValueException, RuntimeException)
459 Guard< Mutex > aGuard( m_pRegistry->m_mutex );
460 if (!m_key.isValid())
462 throw InvalidRegistryException(
463 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
464 (OWeakObject *)this );
465 } else
467 RegValueType type;
468 sal_uInt32 size;
470 if ( !m_key.getValueInfo(OUString(), &type, &size) )
472 if ( type == RG_VALUETYPE_STRING )
474 char* value = new char[size];
475 if ( m_key.getValue(OUString(), (RegValue)value) )
477 delete [] value;
478 throw InvalidValueException(
479 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidValueException") ),
480 (OWeakObject *)this );
481 } else
483 OUString ret(OStringToOUString(value, RTL_TEXTENCODING_UTF8));
484 delete [] value;
485 return ret;
490 throw InvalidValueException(
491 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidValueException") ),
492 (OWeakObject *)this );
496 //*************************************************************************
497 void SAL_CALL RegistryKeyImpl::setAsciiValue( const OUString& value )
498 throw(InvalidRegistryException, RuntimeException)
500 Guard< Mutex > aGuard( m_pRegistry->m_mutex );
501 if ( !m_key.isValid() )
503 throw InvalidRegistryException(
504 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
505 (OWeakObject *)this );
506 } else
508 OString sValue = OUStringToOString(value, RTL_TEXTENCODING_UTF8);
509 sal_uInt32 size = sValue.getLength()+1;
510 if ( m_key.setValue(OUString(), RG_VALUETYPE_STRING,
511 (RegValue)(sValue.getStr()), size) )
513 throw InvalidValueException(
514 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidValueException") ),
515 (OWeakObject *)this );
520 //*************************************************************************
521 Sequence< OUString > SAL_CALL RegistryKeyImpl::getAsciiListValue( )
522 throw(InvalidRegistryException, InvalidValueException, RuntimeException)
524 Guard< Mutex > aGuard( m_pRegistry->m_mutex );
525 if ( !m_key.isValid() )
527 throw InvalidRegistryException(
528 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
529 (OWeakObject *)this );
530 } else
532 RegValueType type;
533 sal_uInt32 size;
535 if ( !m_key.getValueInfo(OUString(), &type, &size) )
537 if (type == RG_VALUETYPE_STRINGLIST)
539 RegistryValueList<char*> tmpValue;
540 if ( !m_key.getStringListValue(OUString(), tmpValue) )
542 Sequence<OUString> seqValue(size);
544 for (sal_uInt32 i=0; i < size; i++)
546 seqValue.getArray()[i] =
547 OStringToOUString(tmpValue.getElement(i), RTL_TEXTENCODING_UTF8);
550 return seqValue;
555 throw InvalidValueException(
556 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidValueException") ),
557 (OWeakObject *)this );
561 //*************************************************************************
562 void SAL_CALL RegistryKeyImpl::setAsciiListValue( const Sequence< OUString >& seqValue )
563 throw(InvalidRegistryException, RuntimeException)
565 Guard< Mutex > aGuard( m_pRegistry->m_mutex );
566 if ( !m_key.isValid() )
568 throw InvalidRegistryException(
569 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
570 (OWeakObject *)this );
571 } else
573 sal_uInt32 length = seqValue.getLength();
574 OString* pSValue = new OString[length];
575 char** tmpValue = new char*[length];
577 for (sal_uInt32 i=0; i < length; i++)
579 pSValue[i] = OUStringToOString(seqValue.getConstArray()[i], RTL_TEXTENCODING_UTF8);
580 tmpValue[i] = (char*)pSValue[i].getStr();
583 if ( m_key.setStringListValue(OUString(), tmpValue, length) )
585 delete[] pSValue;
586 delete[] tmpValue;
587 throw InvalidValueException(
588 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidValueException") ),
589 (OWeakObject *)this );
592 delete[] pSValue;
593 delete[] tmpValue;
597 //*************************************************************************
598 OUString SAL_CALL RegistryKeyImpl::getStringValue( )
599 throw(InvalidRegistryException, InvalidValueException, RuntimeException)
601 Guard< Mutex > aGuard( m_pRegistry->m_mutex );
602 if ( !m_key.isValid() )
604 throw InvalidRegistryException(
605 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
606 (OWeakObject *)this );
607 } else
609 RegValueType type;
610 sal_uInt32 size;
612 if ( !m_key.getValueInfo(OUString(), &type, &size) )
614 if (type == RG_VALUETYPE_UNICODE)
616 sal_Unicode* value = new sal_Unicode[size];
617 if ( m_key.getValue(OUString(), (RegValue)value) )
619 delete [] value;
620 throw InvalidValueException(
621 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidValueException") ),
622 (OWeakObject *)this );
623 } else
625 OUString ret(value);
626 delete [] value;
627 return ret;
632 throw InvalidValueException(
633 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidValueException") ),
634 (OWeakObject *)this );
638 //*************************************************************************
639 void SAL_CALL RegistryKeyImpl::setStringValue( const OUString& value )
640 throw(InvalidRegistryException, RuntimeException)
642 Guard< Mutex > aGuard( m_pRegistry->m_mutex );
643 if ( !m_key.isValid() )
645 throw InvalidRegistryException(
646 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
647 (OWeakObject *)this );
648 } else
650 sal_uInt32 size = (value.getLength() + 1) * sizeof(sal_Unicode);
651 if ( m_key.setValue(OUString(), RG_VALUETYPE_UNICODE,
652 (RegValue)(value.getStr()), size) )
654 throw InvalidValueException(
655 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidValueException") ),
656 (OWeakObject *)this );
661 //*************************************************************************
662 Sequence< OUString > SAL_CALL RegistryKeyImpl::getStringListValue( )
663 throw(InvalidRegistryException, InvalidValueException, RuntimeException)
665 Guard< Mutex > aGuard( m_pRegistry->m_mutex );
666 if ( !m_key.isValid() )
668 throw InvalidRegistryException(
669 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
670 (OWeakObject *)this );
671 } else
673 RegValueType type;
674 sal_uInt32 size;
676 if ( !m_key.getValueInfo(OUString(), &type, &size) )
678 if (type == RG_VALUETYPE_UNICODELIST)
680 RegistryValueList<sal_Unicode*> tmpValue;
681 if ( !m_key.getUnicodeListValue(OUString(), tmpValue) )
683 Sequence<OUString> seqValue(size);
685 for (sal_uInt32 i=0; i < size; i++)
687 seqValue.getArray()[i] = OUString(tmpValue.getElement(i));
690 return seqValue;
695 throw InvalidValueException(
696 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidValueException") ),
697 (OWeakObject *)this );
701 //*************************************************************************
702 void SAL_CALL RegistryKeyImpl::setStringListValue( const Sequence< OUString >& seqValue )
703 throw(InvalidRegistryException, RuntimeException)
705 Guard< Mutex > aGuard( m_pRegistry->m_mutex );
706 if ( !m_key.isValid() )
708 throw InvalidRegistryException(
709 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
710 (OWeakObject *)this );
711 } else
713 sal_uInt32 length = seqValue.getLength();
714 sal_Unicode** tmpValue = new sal_Unicode*[length];
716 for (sal_uInt32 i=0; i < length; i++)
718 tmpValue[i] = (sal_Unicode*)seqValue.getConstArray()[i].getStr();
721 if (m_key.setUnicodeListValue(OUString(), tmpValue, length))
723 delete[] tmpValue;
724 throw InvalidValueException(
725 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidValueException") ),
726 (OWeakObject *)this );
729 delete[] tmpValue;
733 //*************************************************************************
734 Sequence< sal_Int8 > SAL_CALL RegistryKeyImpl::getBinaryValue( )
735 throw(InvalidRegistryException, InvalidValueException, RuntimeException)
737 Guard< Mutex > aGuard( m_pRegistry->m_mutex );
738 if ( !m_key.isValid() )
740 throw InvalidRegistryException(
741 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
742 (OWeakObject *)this );
743 } else
745 RegValueType type;
746 sal_uInt32 size;
748 if ( !m_key.getValueInfo(OUString(), &type, &size) )
750 if (type == RG_VALUETYPE_BINARY)
752 sal_Int8* value = new sal_Int8[size];
753 if (m_key.getValue(OUString(), (RegValue)value))
755 delete [] value;
756 throw InvalidValueException(
757 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidValueException") ),
758 (OWeakObject *)this );
759 } else
761 Sequence<sal_Int8> seqBytes(value, size);
762 delete [] value;
763 return seqBytes;
768 throw InvalidValueException(
769 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidValueException") ),
770 (OWeakObject *)this );
774 //*************************************************************************
775 void SAL_CALL RegistryKeyImpl::setBinaryValue( const Sequence< sal_Int8 >& value )
776 throw(InvalidRegistryException, RuntimeException)
778 Guard< Mutex > aGuard( m_pRegistry->m_mutex );
779 if ( !m_key.isValid() )
781 throw InvalidRegistryException(
782 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
783 (OWeakObject *)this );
784 } else
786 sal_uInt32 size = value.getLength();
787 if ( m_key.setValue(OUString(), RG_VALUETYPE_BINARY,
788 (RegValue)(value.getConstArray()), size) )
790 throw InvalidValueException(
791 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidValueException") ),
792 (OWeakObject *)this );
797 //*************************************************************************
798 Reference< XRegistryKey > SAL_CALL RegistryKeyImpl::openKey( const OUString& aKeyName )
799 throw(InvalidRegistryException, RuntimeException)
801 RegistryKey newKey;
803 Guard< Mutex > aGuard( m_pRegistry->m_mutex );
804 if ( !m_key.isValid() )
806 throw InvalidRegistryException(
807 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
808 (OWeakObject *)this );
809 } else
811 RegError _ret = m_key.openKey(aKeyName, newKey);
812 if ( _ret )
814 if ( _ret == REG_INVALID_KEY )
816 throw InvalidRegistryException(
817 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
818 (OWeakObject *)this );
821 return Reference<XRegistryKey>();
822 } else
824 return ((XRegistryKey*)new RegistryKeyImpl(newKey, m_pRegistry));
829 //*************************************************************************
830 Reference< XRegistryKey > SAL_CALL RegistryKeyImpl::createKey( const OUString& aKeyName )
831 throw(InvalidRegistryException, RuntimeException)
833 RegistryKey newKey;
835 Guard< Mutex > aGuard( m_pRegistry->m_mutex );
836 if ( !m_key.isValid() )
838 throw InvalidRegistryException(
839 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
840 (OWeakObject *)this );
841 } else
843 RegError _ret = m_key.createKey(aKeyName, newKey);
844 if ( _ret )
846 if (_ret == REG_INVALID_KEY)
848 throw InvalidRegistryException(
849 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
850 (OWeakObject *)this );
853 return Reference<XRegistryKey>();
854 } else
856 return ((XRegistryKey*)new RegistryKeyImpl(newKey, m_pRegistry));
861 //*************************************************************************
862 void SAL_CALL RegistryKeyImpl::closeKey( )
863 throw(InvalidRegistryException, RuntimeException)
865 Guard< Mutex > aGuard( m_pRegistry->m_mutex );
866 if ( m_key.isValid() )
868 if ( !m_key.closeKey() )
869 return;
872 throw InvalidRegistryException(
873 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
874 (OWeakObject *)this );
877 //*************************************************************************
878 void SAL_CALL RegistryKeyImpl::deleteKey( const OUString& rKeyName )
879 throw(InvalidRegistryException, RuntimeException)
881 Guard< Mutex > aGuard( m_pRegistry->m_mutex );
882 if ( m_key.isValid() )
884 if ( !m_key.deleteKey(rKeyName) )
885 return;
888 throw InvalidRegistryException(
889 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
890 (OWeakObject *)this );
893 //*************************************************************************
894 Sequence< Reference< XRegistryKey > > SAL_CALL RegistryKeyImpl::openKeys( )
895 throw(InvalidRegistryException, RuntimeException)
897 Guard< Mutex > aGuard( m_pRegistry->m_mutex );
898 if ( !m_key.isValid() )
900 throw InvalidRegistryException(
901 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
902 (OWeakObject *)this );
903 } else
905 RegistryKeyArray subKeys;
906 RegError _ret = REG_NO_ERROR;
907 if ( (_ret = m_key.openSubKeys(OUString(), subKeys)) )
909 if ( _ret == REG_INVALID_KEY )
911 throw InvalidRegistryException(
912 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
913 (OWeakObject *)this );
916 return Sequence< Reference<XRegistryKey> >();
917 } else
919 sal_uInt32 length = subKeys.getLength();
920 Sequence< Reference<XRegistryKey> > seqKeys(length);
922 for (sal_uInt32 i=0; i < length; i++)
924 seqKeys.getArray()[i] =
925 (XRegistryKey*) new RegistryKeyImpl(subKeys.getElement(i), m_pRegistry);
927 return seqKeys;
932 //*************************************************************************
933 Sequence< OUString > SAL_CALL RegistryKeyImpl::getKeyNames( )
934 throw(InvalidRegistryException, RuntimeException)
936 Guard< Mutex > aGuard( m_pRegistry->m_mutex );
937 if ( !m_key.isValid() )
939 throw InvalidRegistryException(
940 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
941 (OWeakObject *)this );
942 } else
944 RegistryKeyNames subKeys;
945 RegError _ret = REG_NO_ERROR;
946 if ( (_ret = m_key.getKeyNames(OUString(), subKeys)) )
948 if ( _ret == REG_INVALID_KEY )
950 throw InvalidRegistryException(
951 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
952 (OWeakObject *)this );
955 return Sequence<OUString>();
956 } else
958 sal_uInt32 length = subKeys.getLength();
959 Sequence<OUString> seqKeys(length);
961 for (sal_uInt32 i=0; i < length; i++)
963 seqKeys.getArray()[i] = subKeys.getElement(i);
965 return seqKeys;
970 //*************************************************************************
971 sal_Bool SAL_CALL RegistryKeyImpl::createLink( const OUString& aLinkName, const OUString& aLinkTarget )
972 throw(InvalidRegistryException, RuntimeException)
974 Guard< Mutex > aGuard( m_pRegistry->m_mutex );
975 if ( !m_key.isValid() )
977 throw InvalidRegistryException(
978 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
979 (OWeakObject *)this );
980 } else
982 RegError ret = m_key.createLink(aLinkName, aLinkTarget);
983 if ( ret )
985 if ( ret == REG_DETECT_RECURSION ||
986 ret == REG_INVALID_KEY )
988 throw InvalidRegistryException(
989 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
990 (OWeakObject *)this );
991 } else
993 return sal_False;
997 return sal_True;
1000 //*************************************************************************
1001 void SAL_CALL RegistryKeyImpl::deleteLink( const OUString& rLinkName )
1002 throw(InvalidRegistryException, RuntimeException)
1004 Guard< Mutex > aGuard( m_pRegistry->m_mutex );
1005 if ( !m_key.isValid() )
1007 throw InvalidRegistryException(
1008 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
1009 (OWeakObject *)this );
1010 } else
1012 if ( m_key.deleteLink(rLinkName) )
1014 throw InvalidRegistryException(
1015 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
1016 (OWeakObject *)this );
1021 //*************************************************************************
1022 OUString SAL_CALL RegistryKeyImpl::getLinkTarget( const OUString& rLinkName )
1023 throw(InvalidRegistryException, RuntimeException)
1025 OUString linkTarget;
1027 Guard< Mutex > aGuard( m_pRegistry->m_mutex );
1028 if ( !m_key.isValid() )
1030 throw InvalidRegistryException(
1031 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
1032 (OWeakObject *)this );
1033 } else
1035 RegError ret = m_key.getLinkTarget(rLinkName, linkTarget);
1036 if ( ret )
1038 throw InvalidRegistryException(
1039 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
1040 (OWeakObject *)this );
1044 return linkTarget;
1047 //*************************************************************************
1048 OUString SAL_CALL RegistryKeyImpl::getResolvedName( const OUString& aKeyName )
1049 throw(InvalidRegistryException, RuntimeException)
1051 OUString resolvedName;
1053 Guard< Mutex > aGuard( m_pRegistry->m_mutex );
1054 if ( !m_key.isValid() )
1056 throw InvalidRegistryException(
1057 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
1058 (OWeakObject *)this );
1059 } else
1061 RegError ret = m_key.getResolvedKeyName(
1062 aKeyName, sal_True, resolvedName);
1063 if ( ret )
1065 throw InvalidRegistryException(
1066 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
1067 (OWeakObject *)this );
1071 return resolvedName;
1074 //*************************************************************************
1075 SimpleRegistryImpl::SimpleRegistryImpl( const Registry& rRegistry )
1076 : m_registry(rRegistry)
1078 g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
1081 //*************************************************************************
1082 SimpleRegistryImpl::~SimpleRegistryImpl()
1084 g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
1087 //*************************************************************************
1088 OUString SAL_CALL SimpleRegistryImpl::getImplementationName( )
1089 throw(RuntimeException)
1091 return stoc_bootstrap::simreg_getImplementationName();
1094 //*************************************************************************
1095 sal_Bool SAL_CALL SimpleRegistryImpl::supportsService( const OUString& ServiceName )
1096 throw(RuntimeException)
1098 Guard< Mutex > aGuard( m_mutex );
1099 Sequence< OUString > aSNL = getSupportedServiceNames();
1100 const OUString * pArray = aSNL.getArray();
1101 for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
1102 if( pArray[i] == ServiceName )
1103 return sal_True;
1104 return sal_False;
1107 //*************************************************************************
1108 Sequence<OUString> SAL_CALL SimpleRegistryImpl::getSupportedServiceNames( )
1109 throw(RuntimeException)
1111 return stoc_bootstrap::simreg_getSupportedServiceNames();
1114 //*************************************************************************
1115 OUString SAL_CALL SimpleRegistryImpl::getURL() throw(RuntimeException)
1117 Guard< Mutex > aGuard( m_mutex );
1118 return m_url;
1121 //*************************************************************************
1122 void SAL_CALL SimpleRegistryImpl::open( const OUString& rURL, sal_Bool bReadOnly, sal_Bool bCreate )
1123 throw(InvalidRegistryException, RuntimeException)
1125 Guard< Mutex > aGuard( m_mutex );
1126 if ( m_registry.isValid() )
1128 m_registry.close();
1131 RegAccessMode accessMode = REG_READWRITE;
1133 if ( bReadOnly )
1134 accessMode = REG_READONLY;
1136 if ( !m_registry.open(rURL, accessMode) )
1138 m_url = rURL;
1139 return;
1142 if ( bCreate )
1144 if ( !m_registry.create(rURL) )
1146 m_url = rURL;
1147 return;
1151 m_url = OUString();
1153 OUStringBuffer reason( 128 );
1154 reason.appendAscii( RTL_CONSTASCII_STRINGPARAM("Couldn't ") );
1155 if( bCreate )
1157 reason.appendAscii( RTL_CONSTASCII_STRINGPARAM("create") );
1159 else
1161 reason.appendAscii( RTL_CONSTASCII_STRINGPARAM("open") );
1163 reason.appendAscii( RTL_CONSTASCII_STRINGPARAM(" registry ") );
1164 reason.append( rURL );
1165 if( bReadOnly )
1167 reason.appendAscii( RTL_CONSTASCII_STRINGPARAM(" for reading") );
1169 else
1171 reason.appendAscii( RTL_CONSTASCII_STRINGPARAM(" for writing" ) );
1173 throw InvalidRegistryException( reason.makeStringAndClear() , Reference< XInterface >() );
1176 //*************************************************************************
1177 sal_Bool SAL_CALL SimpleRegistryImpl::isValid( ) throw(RuntimeException)
1179 Guard< Mutex > aGuard( m_mutex );
1180 return m_registry.isValid();
1183 //*************************************************************************
1184 void SAL_CALL SimpleRegistryImpl::close( )
1185 throw(InvalidRegistryException, RuntimeException)
1187 Guard< Mutex > aGuard( m_mutex );
1188 if ( m_registry.isValid() )
1190 if ( !m_registry.close() )
1192 m_url = OUString();
1193 return;
1197 throw InvalidRegistryException(
1198 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
1199 (OWeakObject *)this );
1202 //*************************************************************************
1203 void SAL_CALL SimpleRegistryImpl::destroy( )
1204 throw(InvalidRegistryException, RuntimeException)
1206 Guard< Mutex > aGuard( m_mutex );
1207 if ( m_registry.isValid() )
1209 if ( !m_registry.destroy(OUString()) )
1211 m_url = OUString();
1212 return;
1216 throw InvalidRegistryException(
1217 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
1218 (OWeakObject *)this );
1221 //*************************************************************************
1222 Reference< XRegistryKey > SAL_CALL SimpleRegistryImpl::getRootKey( )
1223 throw(InvalidRegistryException, RuntimeException)
1225 Guard< Mutex > aGuard( m_mutex );
1226 if ( m_registry.isValid() )
1227 return ((XRegistryKey*)new RegistryKeyImpl(OUString( RTL_CONSTASCII_USTRINGPARAM("/") ), this));
1228 else
1230 throw InvalidRegistryException(
1231 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
1232 (OWeakObject *)this );
1236 //*************************************************************************
1237 sal_Bool SAL_CALL SimpleRegistryImpl::isReadOnly( )
1238 throw(InvalidRegistryException, RuntimeException)
1240 Guard< Mutex > aGuard( m_mutex );
1241 if ( m_registry.isValid() )
1242 return m_registry.isReadOnly();
1243 else
1245 throw InvalidRegistryException(
1246 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
1247 (OWeakObject *)this );
1251 //*************************************************************************
1252 void SAL_CALL SimpleRegistryImpl::mergeKey( const OUString& aKeyName, const OUString& aUrl )
1253 throw(InvalidRegistryException, MergeConflictException, RuntimeException)
1255 Guard< Mutex > aGuard( m_mutex );
1256 if ( m_registry.isValid() )
1258 RegistryKey rootKey;
1259 if ( !m_registry.openRootKey(rootKey) )
1261 RegError ret = m_registry.mergeKey(rootKey, aKeyName, aUrl, sal_False, sal_False);
1262 if (ret)
1264 if ( ret == REG_MERGE_CONFLICT )
1265 return;
1266 if ( ret == REG_MERGE_ERROR )
1268 throw MergeConflictException(
1269 OUString( RTL_CONSTASCII_USTRINGPARAM("MergeConflictException") ),
1270 (OWeakObject *)this );
1272 else
1274 throw InvalidRegistryException(
1275 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
1276 (OWeakObject *)this );
1280 return;
1284 throw InvalidRegistryException(
1285 OUString( RTL_CONSTASCII_USTRINGPARAM("InvalidRegistryException") ),
1286 (OWeakObject *)this );
1290 namespace stoc_bootstrap
1292 //*************************************************************************
1293 Reference<XInterface> SAL_CALL SimpleRegistry_CreateInstance( const Reference<XComponentContext>& )
1295 Reference<XInterface> xRet;
1297 Registry reg;
1299 XSimpleRegistry *pRegistry = (XSimpleRegistry*) new stoc_simreg::SimpleRegistryImpl(reg);
1301 if (pRegistry)
1303 xRet = Reference<XInterface>::query(pRegistry);
1306 return xRet;