LCOV - code coverage report
Current view: top level - stoc/source/simpleregistry - simpleregistry.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 148 448 33.0 %
Date: 2015-06-13 12:38:46 Functions: 26 47 55.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <sal/config.h>
      21             : 
      22             : #include <cstdlib>
      23             : #include <vector>
      24             : 
      25             : #include <com/sun/star/lang/XServiceInfo.hpp>
      26             : #include <com/sun/star/registry/InvalidRegistryException.hpp>
      27             : #include <com/sun/star/registry/InvalidValueException.hpp>
      28             : #include <com/sun/star/registry/MergeConflictException.hpp>
      29             : #include <com/sun/star/registry/RegistryKeyType.hpp>
      30             : #include <com/sun/star/registry/XRegistryKey.hpp>
      31             : #include <com/sun/star/registry/XSimpleRegistry.hpp>
      32             : #include <com/sun/star/uno/Reference.hxx>
      33             : #include <com/sun/star/uno/RuntimeException.hpp>
      34             : #include <com/sun/star/uno/XComponentContext.hpp>
      35             : #include <com/sun/star/uno/XInterface.hpp>
      36             : #include <com/sun/star/uno/Sequence.hxx>
      37             : #include <cppuhelper/implbase1.hxx>
      38             : #include <cppuhelper/implbase2.hxx>
      39             : #include <cppuhelper/supportsservice.hxx>
      40             : #include <cppuhelper/weak.hxx>
      41             : #include <osl/mutex.hxx>
      42             : #include <registry/registry.hxx>
      43             : #include <registry/regtype.h>
      44             : #include <rtl/ref.hxx>
      45             : #include <rtl/string.h>
      46             : #include <rtl/string.hxx>
      47             : #include <rtl/textcvt.h>
      48             : #include <rtl/textenc.h>
      49             : #include <rtl/ustring.h>
      50             : #include <rtl/ustring.hxx>
      51             : #include <sal/types.h>
      52             : 
      53             : namespace {
      54             : 
      55             : class SimpleRegistry:
      56             :     public cppu::WeakImplHelper2<
      57             :         css::registry::XSimpleRegistry, css::lang::XServiceInfo >
      58             : {
      59             : public:
      60           5 :     SimpleRegistry() {}
      61             : 
      62           6 :     virtual ~SimpleRegistry() {}
      63             : 
      64             :     osl::Mutex mutex_;
      65             : 
      66             : private:
      67             :     virtual OUString SAL_CALL getURL() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      68             : 
      69             :     virtual void SAL_CALL open(
      70             :         OUString const & rURL, sal_Bool bReadOnly, sal_Bool bCreate)
      71             :         throw (
      72             :             css::registry::InvalidRegistryException,
      73             :             css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      74             : 
      75             :     virtual sal_Bool SAL_CALL isValid() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      76             : 
      77             :     virtual void SAL_CALL close() throw (
      78             :         css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      79             : 
      80             :     virtual void SAL_CALL destroy() throw(
      81             :         css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      82             : 
      83             :     virtual css::uno::Reference< css::registry::XRegistryKey > SAL_CALL
      84             :     getRootKey() throw(
      85             :         css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      86             : 
      87             :     virtual sal_Bool SAL_CALL isReadOnly() throw(
      88             :         css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      89             : 
      90             :     virtual void SAL_CALL mergeKey(
      91             :         OUString const & aKeyName, OUString const & aUrl)
      92             :         throw (
      93             :             css::registry::InvalidRegistryException,
      94             :             css::registry::MergeConflictException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      95             : 
      96           1 :     virtual OUString SAL_CALL getImplementationName()
      97             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      98           1 :     { return OUString("com.sun.star.comp.stoc.SimpleRegistry"); }
      99             : 
     100           0 :     virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
     101             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
     102           0 :     { return cppu::supportsService(this, ServiceName); }
     103             : 
     104             :     virtual css::uno::Sequence< OUString > SAL_CALL
     105           1 :     getSupportedServiceNames() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
     106             :     {
     107           1 :         css::uno::Sequence< OUString > names(1);
     108           1 :         names[0] = "com.sun.star.registry.SimpleRegistry";
     109           1 :         return names;
     110             :     }
     111             : 
     112             :     Registry registry_;
     113             : };
     114             : 
     115          78 : class Key: public cppu::WeakImplHelper1< css::registry::XRegistryKey > {
     116             : public:
     117          46 :     Key(
     118             :         rtl::Reference< SimpleRegistry > const & registry,
     119             :         RegistryKey const & key):
     120          46 :         registry_(registry), key_(key) {}
     121             : 
     122             : private:
     123             :     virtual OUString SAL_CALL getKeyName()
     124             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     125             : 
     126             :     virtual sal_Bool SAL_CALL isReadOnly() throw (
     127             :         css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     128             : 
     129             :     virtual sal_Bool SAL_CALL isValid() throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     130             : 
     131             :     virtual css::registry::RegistryKeyType SAL_CALL getKeyType(
     132             :         OUString const & rKeyName)
     133             :         throw (
     134             :             css::registry::InvalidRegistryException,
     135             :             css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     136             : 
     137             :     virtual css::registry::RegistryValueType SAL_CALL getValueType() throw(
     138             :         css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     139             : 
     140             :     virtual sal_Int32 SAL_CALL getLongValue() throw (
     141             :         css::registry::InvalidRegistryException,
     142             :         css::registry::InvalidValueException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     143             : 
     144             :     virtual void SAL_CALL setLongValue(sal_Int32 value) throw (
     145             :         css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     146             : 
     147             :     virtual css::uno::Sequence< sal_Int32 > SAL_CALL getLongListValue() throw(
     148             :         css::registry::InvalidRegistryException,
     149             :         css::registry::InvalidValueException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     150             : 
     151             :     virtual void SAL_CALL setLongListValue(
     152             :         css::uno::Sequence< sal_Int32 > const & seqValue)
     153             :         throw (
     154             :             css::registry::InvalidRegistryException,
     155             :             css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     156             : 
     157             :     virtual OUString SAL_CALL getAsciiValue() throw (
     158             :         css::registry::InvalidRegistryException,
     159             :         css::registry::InvalidValueException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     160             : 
     161             :     virtual void SAL_CALL setAsciiValue(OUString const & value) throw (
     162             :         css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     163             : 
     164             :     virtual css::uno::Sequence< OUString > SAL_CALL getAsciiListValue()
     165             :         throw (
     166             :             css::registry::InvalidRegistryException,
     167             :             css::registry::InvalidValueException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     168             : 
     169             :     virtual void SAL_CALL setAsciiListValue(
     170             :         css::uno::Sequence< OUString > const & seqValue)
     171             :         throw (
     172             :             css::registry::InvalidRegistryException,
     173             :             css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     174             : 
     175             :     virtual OUString SAL_CALL getStringValue() throw(
     176             :         css::registry::InvalidRegistryException,
     177             :         css::registry::InvalidValueException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     178             : 
     179             :     virtual void SAL_CALL setStringValue(OUString const & value) throw (
     180             :         css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     181             : 
     182             :     virtual css::uno::Sequence< OUString > SAL_CALL getStringListValue()
     183             :         throw (
     184             :             css::registry::InvalidRegistryException,
     185             :             css::registry::InvalidValueException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     186             : 
     187             :     virtual void SAL_CALL setStringListValue(
     188             :         css::uno::Sequence< OUString > const & seqValue)
     189             :         throw (
     190             :             css::registry::InvalidRegistryException,
     191             :             css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     192             : 
     193             :     virtual css::uno::Sequence< sal_Int8 > SAL_CALL getBinaryValue() throw (
     194             :         css::registry::InvalidRegistryException,
     195             :         css::registry::InvalidValueException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     196             : 
     197             :     virtual void SAL_CALL setBinaryValue(
     198             :         css::uno::Sequence< sal_Int8 > const & value)
     199             :         throw (
     200             :             css::registry::InvalidRegistryException,
     201             :             css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     202             : 
     203             :     virtual css::uno::Reference< css::registry::XRegistryKey > SAL_CALL openKey(
     204             :         OUString const & aKeyName)
     205             :         throw (
     206             :             css::registry::InvalidRegistryException,
     207             :             css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     208             : 
     209             :     virtual css::uno::Reference< css::registry::XRegistryKey > SAL_CALL
     210             :     createKey(OUString const & aKeyName) throw (
     211             :         css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     212             : 
     213             :     virtual void SAL_CALL closeKey() throw (
     214             :         css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     215             : 
     216             :     virtual void SAL_CALL deleteKey(OUString const & rKeyName) throw (
     217             :         css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     218             : 
     219             :     virtual
     220             :     css::uno::Sequence< css::uno::Reference< css::registry::XRegistryKey > >
     221             :     SAL_CALL openKeys() throw (
     222             :         css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     223             : 
     224             :     virtual css::uno::Sequence< OUString > SAL_CALL getKeyNames() throw (
     225             :         css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     226             : 
     227             :     virtual sal_Bool SAL_CALL createLink(
     228             :         OUString const & aLinkName, OUString const & aLinkTarget)
     229             :         throw (
     230             :             css::registry::InvalidRegistryException,
     231             :             css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     232             : 
     233             :     virtual void SAL_CALL deleteLink(OUString const & rLinkName) throw (
     234             :         css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     235             : 
     236             :     virtual OUString SAL_CALL getLinkTarget(OUString const & rLinkName)
     237             :         throw (
     238             :             css::registry::InvalidRegistryException,
     239             :             css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     240             : 
     241             :     virtual OUString SAL_CALL getResolvedName(OUString const & aKeyName)
     242             :         throw (
     243             :             css::registry::InvalidRegistryException,
     244             :             css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     245             : 
     246             :     rtl::Reference< SimpleRegistry > registry_;
     247             :     RegistryKey key_;
     248             : };
     249             : 
     250          28 : OUString Key::getKeyName() throw (css::uno::RuntimeException, std::exception) {
     251          28 :     osl::MutexGuard guard(registry_->mutex_);
     252          28 :     return key_.getName();
     253             : }
     254             : 
     255           1 : sal_Bool Key::isReadOnly()
     256             :     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception)
     257             : {
     258           1 :     osl::MutexGuard guard(registry_->mutex_);
     259           1 :     return key_.isReadOnly();
     260             : }
     261             : 
     262          19 : sal_Bool Key::isValid() throw (css::uno::RuntimeException, std::exception) {
     263          19 :     osl::MutexGuard guard(registry_->mutex_);
     264          19 :     return key_.isValid();
     265             : }
     266             : 
     267           7 : css::registry::RegistryKeyType Key::getKeyType(OUString const & )
     268             :     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception)
     269             : {
     270           7 :     return css::registry::RegistryKeyType_KEY;
     271             : }
     272             : 
     273          11 : css::registry::RegistryValueType Key::getValueType()
     274             :     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception)
     275             : {
     276          11 :     osl::MutexGuard guard(registry_->mutex_);
     277             :     RegValueType type;
     278             :     sal_uInt32 size;
     279          11 :     RegError err = key_.getValueInfo(OUString(), &type, &size);
     280          11 :     switch (err) {
     281             :     case RegError::NO_ERROR:
     282           3 :         break;
     283             :     case RegError::INVALID_VALUE:
     284           8 :         type = RegValueType::NOT_DEFINED;
     285           8 :         break;
     286             :     default:
     287             :         throw css::registry::InvalidRegistryException(
     288             :             (("com.sun.star.registry.SimpleRegistry key getValueType:"
     289           0 :                       " underlying RegistryKey::getValueInfo() = ") +
     290           0 :              OUString::number(static_cast<int>(err))),
     291           0 :             static_cast< OWeakObject * >(this));
     292             :     }
     293          11 :     switch (type) {
     294             :     default:
     295           0 :         std::abort(); // this cannot happen
     296             :         // pseudo-fall-through to avoid warnings on MSC
     297             :     case RegValueType::NOT_DEFINED:
     298           8 :         return css::registry::RegistryValueType_NOT_DEFINED;
     299             :     case RegValueType::LONG:
     300           0 :         return css::registry::RegistryValueType_LONG;
     301             :     case RegValueType::STRING:
     302           3 :         return css::registry::RegistryValueType_ASCII;
     303             :     case RegValueType::UNICODE:
     304           0 :         return css::registry::RegistryValueType_STRING;
     305             :     case RegValueType::BINARY:
     306           0 :         return css::registry::RegistryValueType_BINARY;
     307             :     case RegValueType::LONGLIST:
     308           0 :         return css::registry::RegistryValueType_LONGLIST;
     309             :     case RegValueType::STRINGLIST:
     310           0 :         return css::registry::RegistryValueType_ASCIILIST;
     311             :     case RegValueType::UNICODELIST:
     312           0 :         return css::registry::RegistryValueType_STRINGLIST;
     313          11 :     }
     314             : }
     315             : 
     316           0 : sal_Int32 Key::getLongValue() throw (
     317             :     css::registry::InvalidRegistryException,
     318             :     css::registry::InvalidValueException, css::uno::RuntimeException, std::exception)
     319             : {
     320           0 :     osl::MutexGuard guard(registry_->mutex_);
     321             :     sal_Int32 value;
     322           0 :     RegError err = key_.getValue(OUString(), &value);
     323           0 :     switch (err) {
     324             :     case RegError::NO_ERROR:
     325           0 :         break;
     326             :     case RegError::INVALID_VALUE:
     327             :         throw css::registry::InvalidValueException(
     328             :             OUString("com.sun.star.registry.SimpleRegistry key getLongValue:"
     329             :                      " underlying RegistryKey::getValue() = RegError::INVALID_VALUE"),
     330           0 :             static_cast< OWeakObject * >(this));
     331             :     default:
     332             :         throw css::registry::InvalidRegistryException(
     333             :             (("com.sun.star.registry.SimpleRegistry key getLongValue:"
     334           0 :                       " underlying RegistryKey::getValue() = ") +
     335           0 :              OUString::number(static_cast<int>(err))),
     336           0 :             static_cast< OWeakObject * >(this));
     337             :     }
     338           0 :     return value;
     339             : }
     340             : 
     341           0 : void Key::setLongValue(sal_Int32 value)
     342             :     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception)
     343             : {
     344           0 :     osl::MutexGuard guard(registry_->mutex_);
     345             :     RegError err = key_.setValue(
     346           0 :         OUString(), RegValueType::LONG, &value, sizeof (sal_Int32));
     347           0 :     if (err != RegError::NO_ERROR) {
     348             :         throw css::registry::InvalidRegistryException(
     349             :             (("com.sun.star.registry.SimpleRegistry key setLongValue:"
     350           0 :                       " underlying RegistryKey::setValue() = ") +
     351           0 :              OUString::number(static_cast<int>(err))),
     352           0 :             static_cast< OWeakObject * >(this));
     353           0 :     }
     354           0 : }
     355             : 
     356           0 : css::uno::Sequence< sal_Int32 > Key::getLongListValue() throw (
     357             :     css::registry::InvalidRegistryException,
     358             :     css::registry::InvalidValueException, css::uno::RuntimeException, std::exception)
     359             : {
     360           0 :     osl::MutexGuard guard(registry_->mutex_);
     361           0 :     RegistryValueList< sal_Int32 > list;
     362           0 :     RegError err = key_.getLongListValue(OUString(), list);
     363           0 :     switch (err) {
     364             :     case RegError::NO_ERROR:
     365           0 :         break;
     366             :     case RegError::VALUE_NOT_EXISTS:
     367           0 :         return css::uno::Sequence< sal_Int32 >();
     368             :     case RegError::INVALID_VALUE:
     369             :         throw css::registry::InvalidValueException(
     370             :             OUString("com.sun.star.registry.SimpleRegistry key getLongListValue:"
     371             :                      " underlying RegistryKey::getLongListValue() ="
     372             :                      " RegError::INVALID_VALUE"),
     373           0 :             static_cast< OWeakObject * >(this));
     374             :     default:
     375             :         throw css::registry::InvalidRegistryException(
     376             :             (("com.sun.star.registry.SimpleRegistry key getLongListValue:"
     377           0 :                       " underlying RegistryKey::getLongListValue() = ") +
     378           0 :              OUString::number(static_cast<int>(err))),
     379           0 :             static_cast< OWeakObject * >(this));
     380             :     }
     381           0 :     sal_uInt32 n = list.getLength();
     382           0 :     if (n > SAL_MAX_INT32) {
     383             :         throw css::registry::InvalidValueException(
     384             :             OUString("com.sun.star.registry.SimpleRegistry key getLongListValue:"
     385             :                      " underlying RegistryKey::getLongListValue() too large"),
     386           0 :             static_cast< OWeakObject * >(this));
     387             :     }
     388           0 :     css::uno::Sequence< sal_Int32 > value(static_cast< sal_Int32 >(n));
     389           0 :     for (sal_uInt32 i = 0; i < n; ++i) {
     390           0 :         value[static_cast< sal_Int32 >(i)] = list.getElement(i);
     391             :     }
     392           0 :     return value;
     393             : }
     394             : 
     395           0 : void Key::setLongListValue(css::uno::Sequence< sal_Int32 > const & seqValue)
     396             :     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception)
     397             : {
     398           0 :     osl::MutexGuard guard(registry_->mutex_);
     399           0 :     std::vector< sal_Int32 > list;
     400           0 :     for (sal_Int32 i = 0; i < seqValue.getLength(); ++i) {
     401           0 :         list.push_back(seqValue[i]);
     402             :     }
     403             :     RegError err = key_.setLongListValue(
     404           0 :         OUString(), list.data(), static_cast< sal_uInt32 >(list.size()));
     405           0 :     if (err != RegError::NO_ERROR) {
     406             :         throw css::registry::InvalidRegistryException(
     407             :             (("com.sun.star.registry.SimpleRegistry key setLongListValue:"
     408           0 :                       " underlying RegistryKey::setLongListValue() = ") +
     409           0 :              OUString::number(static_cast<int>(err))),
     410           0 :             static_cast< OWeakObject * >(this));
     411           0 :     }
     412           0 : }
     413             : 
     414           3 : OUString Key::getAsciiValue() throw (
     415             :     css::registry::InvalidRegistryException,
     416             :     css::registry::InvalidValueException, css::uno::RuntimeException, std::exception)
     417             : {
     418           3 :     osl::MutexGuard guard(registry_->mutex_);
     419             :     RegValueType type;
     420             :     sal_uInt32 size;
     421           3 :     RegError err = key_.getValueInfo(OUString(), &type, &size);
     422           3 :     if (err != RegError::NO_ERROR) {
     423             :         throw css::registry::InvalidRegistryException(
     424             :             (("com.sun.star.registry.SimpleRegistry key getAsciiValue:"
     425           0 :                       " underlying RegistryKey::getValueInfo() = ") +
     426           0 :              OUString::number(static_cast<int>(err))),
     427           0 :             static_cast< OWeakObject * >(this));
     428             :     }
     429           3 :     if (type != RegValueType::STRING) {
     430             :         throw css::registry::InvalidValueException(
     431             :             (("com.sun.star.registry.SimpleRegistry key getAsciiValue:"
     432           0 :                       " underlying RegistryKey type = ") +
     433           0 :              OUString::number(static_cast<int>(type))),
     434           0 :             static_cast< OWeakObject * >(this));
     435             :     }
     436             :     // size contains terminating null (error in underlying registry.cxx):
     437           3 :     if (size == 0) {
     438             :         throw css::registry::InvalidValueException(
     439             :             OUString("com.sun.star.registry.SimpleRegistry key getAsciiValue:"
     440             :                      " underlying RegistryKey size 0 cannot happen due to"
     441             :                      " design error"),
     442           0 :             static_cast< OWeakObject * >(this));
     443             :     }
     444           3 :     if (size > SAL_MAX_INT32) {
     445             :         throw css::registry::InvalidValueException(
     446             :             OUString("com.sun.star.registry.SimpleRegistry key getAsciiValue:"
     447             :                      " underlying RegistryKey size too large"),
     448           0 :             static_cast< OWeakObject * >(this));
     449             :     }
     450           6 :     std::vector< char > list(size);
     451           3 :     err = key_.getValue(OUString(), &list[0]);
     452           3 :     if (err != RegError::NO_ERROR) {
     453             :         throw css::registry::InvalidRegistryException(
     454             :             (("com.sun.star.registry.SimpleRegistry key getAsciiValue:"
     455           0 :                       " underlying RegistryKey::getValue() = ") +
     456           0 :              OUString::number(static_cast<int>(err))),
     457           0 :             static_cast< OWeakObject * >(this));
     458             :     }
     459           3 :     if (list[size - 1] != '\0') {
     460             :         throw css::registry::InvalidValueException(
     461             :             OUString("com.sun.star.registry.SimpleRegistry key getAsciiValue:"
     462             :                      " underlying RegistryKey value must be null-terminated due"
     463             :                      " to design error"),
     464           0 :             static_cast< OWeakObject * >(this));
     465             :     }
     466           3 :     OUString value;
     467           3 :     if (!rtl_convertStringToUString(
     468           3 :             &value.pData, &list[0],
     469           3 :             static_cast< sal_Int32 >(size - 1), RTL_TEXTENCODING_UTF8,
     470             :             (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR |
     471             :              RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR |
     472           6 :              RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR)))
     473             :     {
     474             :         throw css::registry::InvalidValueException(
     475             :             OUString("com.sun.star.registry.SimpleRegistry key getAsciiValue:"
     476             :                      " underlying RegistryKey not UTF-8"),
     477           0 :             static_cast< OWeakObject * >(this));
     478             :     }
     479           6 :     return value;
     480             : }
     481             : 
     482           4 : void Key::setAsciiValue(OUString const & value)
     483             :     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception)
     484             : {
     485           4 :     osl::MutexGuard guard(registry_->mutex_);
     486           8 :     OString utf8;
     487           4 :     if (!value.convertToString(
     488             :             &utf8, RTL_TEXTENCODING_UTF8,
     489             :             (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |
     490           4 :              RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR)))
     491             :     {
     492             :         throw css::uno::RuntimeException(
     493             :             OUString("com.sun.star.registry.SimpleRegistry key setAsciiValue:"
     494             :                      " value not UTF-16"),
     495           0 :             static_cast< OWeakObject * >(this));
     496             :     }
     497             :     RegError err = key_.setValue(
     498             :         OUString(), RegValueType::STRING,
     499           4 :         const_cast< char * >(utf8.getStr()), utf8.getLength() + 1);
     500             :         // +1 for terminating null (error in underlying registry.cxx)
     501           4 :     if (err != RegError::NO_ERROR) {
     502             :         throw css::registry::InvalidRegistryException(
     503             :             (("com.sun.star.registry.SimpleRegistry key setAsciiValue:"
     504           0 :                       " underlying RegistryKey::setValue() = ") +
     505           0 :              OUString::number(static_cast<int>(err))),
     506           0 :             static_cast< OWeakObject * >(this));
     507           4 :     }
     508           4 : }
     509             : 
     510           0 : css::uno::Sequence< OUString > Key::getAsciiListValue() throw (
     511             :     css::registry::InvalidRegistryException,
     512             :     css::registry::InvalidValueException, css::uno::RuntimeException, std::exception)
     513             : {
     514           0 :     osl::MutexGuard guard(registry_->mutex_);
     515           0 :     RegistryValueList< char * > list;
     516           0 :     RegError err = key_.getStringListValue(OUString(), list);
     517           0 :     switch (err) {
     518             :     case RegError::NO_ERROR:
     519           0 :         break;
     520             :     case RegError::VALUE_NOT_EXISTS:
     521           0 :         return css::uno::Sequence< OUString >();
     522             :     case RegError::INVALID_VALUE:
     523             :         throw css::registry::InvalidValueException(
     524             :             OUString("com.sun.star.registry.SimpleRegistry key"
     525             :                      " getAsciiListValue: underlying"
     526             :                      " RegistryKey::getStringListValue() = RegError::INVALID_VALUE"),
     527           0 :             static_cast< OWeakObject * >(this));
     528             :     default:
     529             :         throw css::registry::InvalidRegistryException(
     530             :             (("com.sun.star.registry.SimpleRegistry key"
     531             :                       " getAsciiListValue: underlying"
     532           0 :                       " RegistryKey::getStringListValue() = ") +
     533           0 :              OUString::number(static_cast<int>(err))),
     534           0 :             static_cast< OWeakObject * >(this));
     535             :     }
     536           0 :     sal_uInt32 n = list.getLength();
     537           0 :     if (n > SAL_MAX_INT32) {
     538             :         throw css::registry::InvalidValueException(
     539             :             OUString("com.sun.star.registry.SimpleRegistry key"
     540             :                      " getAsciiListValue: underlying"
     541             :                      " RegistryKey::getStringListValue() too large"),
     542           0 :             static_cast< OWeakObject * >(this));
     543             :     }
     544           0 :     css::uno::Sequence< OUString > value(static_cast< sal_Int32 >(n));
     545           0 :     for (sal_uInt32 i = 0; i < n; ++i) {
     546           0 :         char * el = list.getElement(i);
     547           0 :         sal_Int32 size = rtl_str_getLength(el);
     548           0 :         if (!rtl_convertStringToUString(
     549           0 :                 &value[static_cast< sal_Int32 >(i)].pData, el, size,
     550             :                 RTL_TEXTENCODING_UTF8,
     551             :                 (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR |
     552             :                  RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR |
     553           0 :                  RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR)))
     554             :         {
     555             :             throw css::registry::InvalidValueException(
     556             :                 OUString("com.sun.star.registry.SimpleRegistry key"
     557             :                          " getAsciiListValue: underlying RegistryKey not"
     558             :                          " UTF-8"),
     559           0 :                 static_cast< OWeakObject * >(this));
     560             :         }
     561             :     }
     562           0 :     return value;
     563             : }
     564             : 
     565           1 : void Key::setAsciiListValue(
     566             :     css::uno::Sequence< OUString > const & seqValue)
     567             :     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception)
     568             : {
     569           1 :     osl::MutexGuard guard(registry_->mutex_);
     570           2 :     std::vector< OString > list;
     571           2 :     for (sal_Int32 i = 0; i < seqValue.getLength(); ++i) {
     572           1 :         OString utf8;
     573           2 :         if (!seqValue[i].convertToString(
     574             :                 &utf8, RTL_TEXTENCODING_UTF8,
     575             :                 (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |
     576           1 :                  RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR)))
     577             :         {
     578             :             throw css::uno::RuntimeException(
     579             :                 OUString("com.sun.star.registry.SimpleRegistry key"
     580             :                          " setAsciiListValue: value not UTF-16"),
     581           0 :                 static_cast< OWeakObject * >(this));
     582             :         }
     583           1 :         list.push_back(utf8);
     584           1 :     }
     585           2 :     std::vector< char * > list2;
     586           2 :     for (std::vector< OString >::iterator i(list.begin()); i != list.end();
     587             :          ++i)
     588             :     {
     589           1 :         list2.push_back(const_cast< char * >(i->getStr()));
     590             :     }
     591             :     RegError err = key_.setStringListValue(
     592           1 :         OUString(), list2.data(), static_cast< sal_uInt32 >(list2.size()));
     593           1 :     if (err != RegError::NO_ERROR) {
     594             :         throw css::registry::InvalidRegistryException(
     595             :             (("com.sun.star.registry.SimpleRegistry key"
     596             :                       " setAsciiListValue: underlying"
     597           0 :                       " RegistryKey::setStringListValue() = ") +
     598           0 :              OUString::number(static_cast<int>(err))),
     599           0 :             static_cast< OWeakObject * >(this));
     600           1 :     }
     601           1 : }
     602             : 
     603           0 : OUString Key::getStringValue() throw (
     604             :     css::registry::InvalidRegistryException,
     605             :     css::registry::InvalidValueException, css::uno::RuntimeException, std::exception)
     606             : {
     607           0 :     osl::MutexGuard guard(registry_->mutex_);
     608             :     RegValueType type;
     609             :     sal_uInt32 size;
     610           0 :     RegError err = key_.getValueInfo(OUString(), &type, &size);
     611           0 :     if (err != RegError::NO_ERROR) {
     612             :         throw css::registry::InvalidRegistryException(
     613             :             (("com.sun.star.registry.SimpleRegistry key getStringValue:"
     614           0 :                       " underlying RegistryKey::getValueInfo() = ") +
     615           0 :              OUString::number(static_cast<int>(err))),
     616           0 :             static_cast< OWeakObject * >(this));
     617             :     }
     618           0 :     if (type != RegValueType::UNICODE) {
     619             :         throw css::registry::InvalidValueException(
     620             :             (("com.sun.star.registry.SimpleRegistry key getStringValue:"
     621           0 :                       " underlying RegistryKey type = ") +
     622           0 :              OUString::number(static_cast<int>(type))),
     623           0 :             static_cast< OWeakObject * >(this));
     624             :     }
     625             :     // size contains terminating null and is *2 (error in underlying
     626             :     // registry.cxx):
     627           0 :     if (size == 0 || (size & 1) == 1) {
     628             :         throw css::registry::InvalidValueException(
     629             :             OUString("com.sun.star.registry.SimpleRegistry key getStringValue:"
     630             :                      " underlying RegistryKey size 0 or odd cannot happen due to"
     631             :                      " design error"),
     632           0 :             static_cast< OWeakObject * >(this));
     633             :     }
     634           0 :     if (size > SAL_MAX_INT32) {
     635             :         throw css::registry::InvalidValueException(
     636             :             OUString("com.sun.star.registry.SimpleRegistry key getStringValue:"
     637             :                      " underlying RegistryKey size too large"),
     638           0 :             static_cast< OWeakObject * >(this));
     639             :     }
     640           0 :     std::vector< sal_Unicode > list(size);
     641           0 :     err = key_.getValue(OUString(), &list[0]);
     642           0 :     if (err != RegError::NO_ERROR) {
     643             :         throw css::registry::InvalidRegistryException(
     644             :             (("com.sun.star.registry.SimpleRegistry key getStringValue:"
     645           0 :                       " underlying RegistryKey::getValue() = ") +
     646           0 :              OUString::number(static_cast<int>(err))),
     647           0 :             static_cast< OWeakObject * >(this));
     648             :     }
     649           0 :     if (list[size/2 - 1] != 0) {
     650             :         throw css::registry::InvalidValueException(
     651             :             OUString("com.sun.star.registry.SimpleRegistry key getStringValue:"
     652             :                      " underlying RegistryKey value must be null-terminated due"
     653             :                      " to design error"),
     654           0 :             static_cast< OWeakObject * >(this));
     655             :     }
     656           0 :     return OUString(&list[0], static_cast< sal_Int32 >(size/2 - 1));
     657             : }
     658             : 
     659           0 : void Key::setStringValue(OUString const & value)
     660             :     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception)
     661             : {
     662           0 :     osl::MutexGuard guard(registry_->mutex_);
     663             :     RegError err = key_.setValue(
     664             :         OUString(), RegValueType::UNICODE,
     665           0 :         const_cast< sal_Unicode * >(value.getStr()),
     666           0 :         (value.getLength() + 1) * sizeof (sal_Unicode));
     667             :         // +1 for terminating null (error in underlying registry.cxx)
     668           0 :     if (err != RegError::NO_ERROR) {
     669             :         throw css::registry::InvalidRegistryException(
     670             :             (("com.sun.star.registry.SimpleRegistry key setStringValue:"
     671           0 :                       " underlying RegistryKey::setValue() = ") +
     672           0 :              OUString::number(static_cast<int>(err))),
     673           0 :             static_cast< OWeakObject * >(this));
     674           0 :     }
     675           0 : }
     676             : 
     677           0 : css::uno::Sequence< OUString > Key::getStringListValue() throw (
     678             :     css::registry::InvalidRegistryException,
     679             :     css::registry::InvalidValueException, css::uno::RuntimeException, std::exception)
     680             : {
     681           0 :     osl::MutexGuard guard(registry_->mutex_);
     682           0 :     RegistryValueList< sal_Unicode * > list;
     683           0 :     RegError err = key_.getUnicodeListValue(OUString(), list);
     684           0 :     switch (err) {
     685             :     case RegError::NO_ERROR:
     686           0 :         break;
     687             :     case RegError::VALUE_NOT_EXISTS:
     688           0 :         return css::uno::Sequence< OUString >();
     689             :     case RegError::INVALID_VALUE:
     690             :         throw css::registry::InvalidValueException(
     691             :             OUString("com.sun.star.registry.SimpleRegistry key"
     692             :                      " getStringListValue: underlying"
     693             :                      " RegistryKey::getUnicodeListValue() = RegError::INVALID_VALUE"),
     694           0 :             static_cast< OWeakObject * >(this));
     695             :     default:
     696             :         throw css::registry::InvalidRegistryException(
     697             :             (("com.sun.star.registry.SimpleRegistry key"
     698             :                       " getStringListValue: underlying"
     699           0 :                       " RegistryKey::getUnicodeListValue() = ") +
     700           0 :              OUString::number(static_cast<int>(err))),
     701           0 :             static_cast< OWeakObject * >(this));
     702             :     }
     703           0 :     sal_uInt32 n = list.getLength();
     704           0 :     if (n > SAL_MAX_INT32) {
     705             :         throw css::registry::InvalidValueException(
     706             :             OUString("com.sun.star.registry.SimpleRegistry key"
     707             :                      " getStringListValue: underlying"
     708             :                      " RegistryKey::getUnicodeListValue() too large"),
     709           0 :             static_cast< OWeakObject * >(this));
     710             :     }
     711           0 :     css::uno::Sequence< OUString > value(static_cast< sal_Int32 >(n));
     712           0 :     for (sal_uInt32 i = 0; i < n; ++i) {
     713           0 :         value[static_cast< sal_Int32 >(i)] = list.getElement(i);
     714             :     }
     715           0 :     return value;
     716             : }
     717             : 
     718           0 : void Key::setStringListValue(
     719             :     css::uno::Sequence< OUString > const & seqValue)
     720             :     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception)
     721             : {
     722           0 :     osl::MutexGuard guard(registry_->mutex_);
     723           0 :     std::vector< sal_Unicode * > list;
     724           0 :     for (sal_Int32 i = 0; i < seqValue.getLength(); ++i) {
     725           0 :         list.push_back(const_cast< sal_Unicode * >(seqValue[i].getStr()));
     726             :     }
     727             :     RegError err = key_.setUnicodeListValue(
     728           0 :         OUString(), list.data(), static_cast< sal_uInt32 >(list.size()));
     729           0 :     if (err != RegError::NO_ERROR) {
     730             :         throw css::registry::InvalidRegistryException(
     731             :             (("com.sun.star.registry.SimpleRegistry key"
     732             :                       " setStringListValue: underlying"
     733           0 :                       " RegistryKey::setUnicodeListValue() = ") +
     734           0 :              OUString::number(static_cast<int>(err))),
     735           0 :             static_cast< OWeakObject * >(this));
     736           0 :     }
     737           0 : }
     738             : 
     739           0 : css::uno::Sequence< sal_Int8 > Key::getBinaryValue()
     740             :     throw (
     741             :         css::registry::InvalidRegistryException,
     742             :         css::registry::InvalidValueException, css::uno::RuntimeException, std::exception)
     743             : {
     744           0 :     osl::MutexGuard guard(registry_->mutex_);
     745             :     RegValueType type;
     746             :     sal_uInt32 size;
     747           0 :     RegError err = key_.getValueInfo(OUString(), &type, &size);
     748           0 :     if (err != RegError::NO_ERROR) {
     749             :         throw css::registry::InvalidRegistryException(
     750             :             (("com.sun.star.registry.SimpleRegistry key getBinaryValue:"
     751           0 :                       " underlying RegistryKey::getValueInfo() = ") +
     752           0 :              OUString::number(static_cast<int>(err))),
     753           0 :             static_cast< OWeakObject * >(this));
     754             :     }
     755           0 :     if (type != RegValueType::BINARY) {
     756             :         throw css::registry::InvalidValueException(
     757             :             (("com.sun.star.registry.SimpleRegistry key getBinaryValue:"
     758           0 :                       " underlying RegistryKey type = ") +
     759           0 :              OUString::number(static_cast<int>(type))),
     760           0 :             static_cast< OWeakObject * >(this));
     761             :     }
     762           0 :     if (size > SAL_MAX_INT32) {
     763             :         throw css::registry::InvalidValueException(
     764             :             OUString("com.sun.star.registry.SimpleRegistry key getBinaryValue:"
     765             :                      " underlying RegistryKey size too large"),
     766           0 :             static_cast< OWeakObject * >(this));
     767             :     }
     768           0 :     css::uno::Sequence< sal_Int8 > value(static_cast< sal_Int32 >(size));
     769           0 :     err = key_.getValue(OUString(), value.getArray());
     770           0 :     if (err != RegError::NO_ERROR) {
     771             :         throw css::registry::InvalidRegistryException(
     772             :             (("com.sun.star.registry.SimpleRegistry key getBinaryValue:"
     773           0 :                       " underlying RegistryKey::getValue() = ") +
     774           0 :              OUString::number(static_cast<int>(err))),
     775           0 :             static_cast< OWeakObject * >(this));
     776             :     }
     777           0 :     return value;
     778             : }
     779             : 
     780           0 : void Key::setBinaryValue(css::uno::Sequence< sal_Int8 > const & value)
     781             :     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception)
     782             : {
     783           0 :     osl::MutexGuard guard(registry_->mutex_);
     784             :     RegError err = key_.setValue(
     785             :         OUString(), RegValueType::BINARY,
     786           0 :         const_cast< sal_Int8 * >(value.getConstArray()),
     787           0 :         static_cast< sal_uInt32 >(value.getLength()));
     788           0 :     if (err != RegError::NO_ERROR) {
     789             :         throw css::registry::InvalidRegistryException(
     790             :             (("com.sun.star.registry.SimpleRegistry key setBinaryValue:"
     791           0 :                       " underlying RegistryKey::setValue() = ") +
     792           0 :              OUString::number(static_cast<int>(err))),
     793           0 :             static_cast< OWeakObject * >(this));
     794           0 :     }
     795           0 : }
     796             : 
     797          19 : css::uno::Reference< css::registry::XRegistryKey > Key::openKey(
     798             :     OUString const & aKeyName)
     799             :     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception)
     800             : {
     801          19 :     osl::MutexGuard guard(registry_->mutex_);
     802          38 :     RegistryKey key;
     803          19 :     RegError err = key_.openKey(aKeyName, key);
     804          19 :     switch (err) {
     805             :     case RegError::NO_ERROR:
     806          13 :         return new Key(registry_, key);
     807             :     case RegError::KEY_NOT_EXISTS:
     808           6 :         return css::uno::Reference< css::registry::XRegistryKey >();
     809             :     default:
     810             :         throw css::registry::InvalidRegistryException(
     811             :             (("com.sun.star.registry.SimpleRegistry key openKey:"
     812           0 :                       " underlying RegistryKey::openKey() = ") +
     813           0 :              OUString::number(static_cast<int>(err))),
     814           0 :             static_cast< OWeakObject * >(this));
     815          19 :     }
     816             : }
     817             : 
     818          15 : css::uno::Reference< css::registry::XRegistryKey > Key::createKey(
     819             :     OUString const & aKeyName)
     820             :     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception)
     821             : {
     822          15 :     osl::MutexGuard guard(registry_->mutex_);
     823          30 :     RegistryKey key;
     824          15 :     RegError err = key_.createKey(aKeyName, key);
     825          15 :     switch (err) {
     826             :     case RegError::NO_ERROR:
     827          15 :         return new Key(registry_, key);
     828             :     case RegError::INVALID_KEYNAME:
     829           0 :         return css::uno::Reference< css::registry::XRegistryKey >();
     830             :     default:
     831             :         throw css::registry::InvalidRegistryException(
     832             :             (("com.sun.star.registry.SimpleRegistry key createKey:"
     833           0 :                       " underlying RegistryKey::createKey() = ") +
     834           0 :              OUString::number(static_cast<int>(err))),
     835           0 :             static_cast< OWeakObject * >(this));
     836          15 :     }
     837             : }
     838             : 
     839          20 : void Key::closeKey()
     840             :     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception)
     841             : {
     842          20 :     osl::MutexGuard guard(registry_->mutex_);
     843          20 :     RegError err = key_.closeKey();
     844          20 :     if (err != RegError::NO_ERROR) {
     845             :         throw css::registry::InvalidRegistryException(
     846             :             (("com.sun.star.registry.SimpleRegistry key closeKey:"
     847           0 :                       " underlying RegistryKey::closeKey() = ") +
     848           0 :              OUString::number(static_cast<int>(err))),
     849           0 :             static_cast< OWeakObject * >(this));
     850          20 :     }
     851          20 : }
     852             : 
     853           2 : void Key::deleteKey(OUString const & rKeyName)
     854             :     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception)
     855             : {
     856           2 :     osl::MutexGuard guard(registry_->mutex_);
     857           2 :     RegError err = key_.deleteKey(rKeyName);
     858           2 :     if (err != RegError::NO_ERROR) {
     859             :         throw css::registry::InvalidRegistryException(
     860             :             (("com.sun.star.registry.SimpleRegistry key deleteKey:"
     861           0 :                       " underlying RegistryKey::deleteKey() = ") +
     862           0 :              OUString::number(static_cast<int>(err))),
     863           0 :             static_cast< OWeakObject * >(this));
     864           2 :     }
     865           2 : }
     866             : 
     867             : css::uno::Sequence< css::uno::Reference< css::registry::XRegistryKey > >
     868           7 : Key::openKeys()
     869             :     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception)
     870             : {
     871           7 :     osl::MutexGuard guard(registry_->mutex_);
     872          14 :     RegistryKeyArray list;
     873           7 :     RegError err = key_.openSubKeys(OUString(), list);
     874           7 :     if (err != RegError::NO_ERROR) {
     875             :         throw css::registry::InvalidRegistryException(
     876             :             (("com.sun.star.registry.SimpleRegistry key openKeys:"
     877           0 :                       " underlying RegistryKey::openSubKeys() = ") +
     878           0 :              OUString::number(static_cast<int>(err))),
     879           0 :             static_cast< OWeakObject * >(this));
     880             :     }
     881           7 :     sal_uInt32 n = list.getLength();
     882           7 :     if (n > SAL_MAX_INT32) {
     883             :         throw css::registry::InvalidRegistryException(
     884             :             OUString("com.sun.star.registry.SimpleRegistry key getKeyNames:"
     885             :                      " underlying RegistryKey::getKeyNames() too large"),
     886           0 :             static_cast< OWeakObject * >(this));
     887             :     }
     888             :     css::uno::Sequence< css::uno::Reference< css::registry::XRegistryKey > >
     889           7 :         keys(static_cast< sal_Int32 >(n));
     890          15 :     for (sal_uInt32 i = 0; i < n; ++i) {
     891          24 :         keys[static_cast< sal_Int32 >(i)] = new Key(
     892          16 :             registry_, list.getElement(i));
     893             :     }
     894          14 :     return keys;
     895             : }
     896             : 
     897           8 : css::uno::Sequence< OUString > Key::getKeyNames()
     898             :     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception)
     899             : {
     900           8 :     osl::MutexGuard guard(registry_->mutex_);
     901          16 :     RegistryKeyNames list;
     902           8 :     RegError err = key_.getKeyNames(OUString(), list);
     903           8 :     if (err != RegError::NO_ERROR) {
     904             :         throw css::registry::InvalidRegistryException(
     905             :             (("com.sun.star.registry.SimpleRegistry key getKeyNames:"
     906           0 :                       " underlying RegistryKey::getKeyNames() = ") +
     907           0 :              OUString::number(static_cast<int>(err))),
     908           0 :             static_cast< OWeakObject * >(this));
     909             :     }
     910           8 :     sal_uInt32 n = list.getLength();
     911           8 :     if (n > SAL_MAX_INT32) {
     912             :         throw css::registry::InvalidRegistryException(
     913             :             OUString("com.sun.star.registry.SimpleRegistry key getKeyNames:"
     914             :                      " underlying RegistryKey::getKeyNames() too large"),
     915           0 :             static_cast< OWeakObject * >(this));
     916             :     }
     917           8 :     css::uno::Sequence< OUString > names(static_cast< sal_Int32 >(n));
     918          15 :     for (sal_uInt32 i = 0; i < n; ++i) {
     919           7 :         names[static_cast< sal_Int32 >(i)] = list.getElement(i);
     920             :     }
     921          16 :     return names;
     922             : }
     923             : 
     924           0 : sal_Bool Key::createLink(
     925             :     OUString const & aLinkName, OUString const & aLinkTarget)
     926             :     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception)
     927             : {
     928           0 :     osl::MutexGuard guard(registry_->mutex_);
     929           0 :     RegError err = key_.createLink(aLinkName, aLinkTarget);
     930           0 :     switch (err) {
     931             :     case RegError::NO_ERROR:
     932           0 :         return true;
     933             :     case RegError::INVALID_KEY:
     934             :     case RegError::DETECT_RECURSION:
     935             :         throw css::registry::InvalidRegistryException(
     936             :             (("com.sun.star.registry.SimpleRegistry key createLink:"
     937           0 :                       " underlying RegistryKey::createLink() = ") +
     938           0 :              OUString::number(static_cast<int>(err))),
     939           0 :             static_cast< OWeakObject * >(this));
     940             :     default:
     941           0 :         return false;
     942           0 :     }
     943             : }
     944             : 
     945           0 : void Key::deleteLink(OUString const & rLinkName)
     946             :     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception)
     947             : {
     948           0 :     osl::MutexGuard guard(registry_->mutex_);
     949           0 :     RegError err = key_.deleteLink(rLinkName);
     950           0 :     if (err != RegError::NO_ERROR) {
     951             :         throw css::registry::InvalidRegistryException(
     952             :             (("com.sun.star.registry.SimpleRegistry key deleteLink:"
     953           0 :                       " underlying RegistryKey::deleteLink() = ") +
     954           0 :              OUString::number(static_cast<int>(err))),
     955           0 :             static_cast< OWeakObject * >(this));
     956           0 :     }
     957           0 : }
     958             : 
     959           0 : OUString Key::getLinkTarget(OUString const & rLinkName)
     960             :     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception)
     961             : {
     962           0 :     osl::MutexGuard guard(registry_->mutex_);
     963           0 :     OUString target;
     964           0 :     RegError err = key_.getLinkTarget(rLinkName, target);
     965           0 :     if (err != RegError::NO_ERROR) {
     966             :         throw css::registry::InvalidRegistryException(
     967             :             (("com.sun.star.registry.SimpleRegistry key getLinkTarget:"
     968           0 :                       " underlying RegistryKey::getLinkTarget() = ") +
     969           0 :              OUString::number(static_cast<int>(err))),
     970           0 :             static_cast< OWeakObject * >(this));
     971             :     }
     972           0 :     return target;
     973             : }
     974             : 
     975           0 : OUString Key::getResolvedName(OUString const & aKeyName)
     976             :     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception)
     977             : {
     978           0 :     osl::MutexGuard guard(registry_->mutex_);
     979           0 :     OUString resolved;
     980           0 :     RegError err = key_.getResolvedKeyName(aKeyName, true, resolved);
     981           0 :     if (err != RegError::NO_ERROR) {
     982             :         throw css::registry::InvalidRegistryException(
     983             :             (("com.sun.star.registry.SimpleRegistry key getResolvedName:"
     984           0 :                       " underlying RegistryKey::getResolvedName() = ") +
     985           0 :              OUString::number(static_cast<int>(err))),
     986           0 :             static_cast< OWeakObject * >(this));
     987             :     }
     988           0 :     return resolved;
     989             : }
     990             : 
     991           0 : OUString SimpleRegistry::getURL() throw (css::uno::RuntimeException, std::exception) {
     992           0 :     osl::MutexGuard guard(mutex_);
     993           0 :     return registry_.getName();
     994             : }
     995             : 
     996           4 : void SimpleRegistry::open(
     997             :     OUString const & rURL, sal_Bool bReadOnly, sal_Bool bCreate)
     998             :     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception)
     999             : {
    1000           4 :     osl::MutexGuard guard(mutex_);
    1001           6 :     RegError err = (rURL.isEmpty() && bCreate)
    1002             :         ? RegError::REGISTRY_NOT_EXISTS
    1003           6 :         : registry_.open(rURL, bReadOnly ? RegAccessMode::READONLY : RegAccessMode::READWRITE);
    1004           4 :     if (err == RegError::REGISTRY_NOT_EXISTS && bCreate) {
    1005           4 :         err = registry_.create(rURL);
    1006             :     }
    1007           4 :     if (err != RegError::NO_ERROR) {
    1008             :         throw css::registry::InvalidRegistryException(
    1009           0 :             ("com.sun.star.registry.SimpleRegistry.open(" +
    1010           0 :              rURL +
    1011           0 :              "): underlying Registry::open/create() = " +
    1012           0 :              OUString::number(static_cast<int>(err))),
    1013           0 :             static_cast< OWeakObject * >(this));
    1014           4 :     }
    1015           4 : }
    1016             : 
    1017           0 : sal_Bool SimpleRegistry::isValid() throw (css::uno::RuntimeException, std::exception) {
    1018           0 :     osl::MutexGuard guard(mutex_);
    1019           0 :     return registry_.isValid();
    1020             : }
    1021             : 
    1022           2 : void SimpleRegistry::close()
    1023             :     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception)
    1024             : {
    1025           2 :     osl::MutexGuard guard(mutex_);
    1026           2 :     RegError err = registry_.close();
    1027           2 :     if (err != RegError::NO_ERROR) {
    1028             :         throw css::registry::InvalidRegistryException(
    1029             :             (("com.sun.star.registry.SimpleRegistry.close:"
    1030           0 :                       " underlying Registry::close() = ") +
    1031           0 :              OUString::number(static_cast<int>(err))),
    1032           0 :             static_cast< OWeakObject * >(this));
    1033           2 :     }
    1034           2 : }
    1035             : 
    1036           0 : void SimpleRegistry::destroy()
    1037             :     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception)
    1038             : {
    1039           0 :     osl::MutexGuard guard(mutex_);
    1040           0 :     RegError err = registry_.destroy(OUString());
    1041           0 :     if (err != RegError::NO_ERROR) {
    1042             :         throw css::registry::InvalidRegistryException(
    1043             :             (("com.sun.star.registry.SimpleRegistry.destroy:"
    1044           0 :                       " underlying Registry::destroy() = ") +
    1045           0 :              OUString::number(static_cast<int>(err))),
    1046           0 :             static_cast< OWeakObject * >(this));
    1047           0 :     }
    1048           0 : }
    1049             : 
    1050          10 : css::uno::Reference< css::registry::XRegistryKey > SimpleRegistry::getRootKey()
    1051             :     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception)
    1052             : {
    1053          10 :     osl::MutexGuard guard(mutex_);
    1054          20 :     RegistryKey root;
    1055          10 :     RegError err = registry_.openRootKey(root);
    1056          10 :     if (err != RegError::NO_ERROR) {
    1057             :         throw css::registry::InvalidRegistryException(
    1058             :             (("com.sun.star.registry.SimpleRegistry.getRootKey:"
    1059           0 :                       " underlying Registry::getRootKey() = ") +
    1060           0 :              OUString::number(static_cast<int>(err))),
    1061           0 :             static_cast< OWeakObject * >(this));
    1062             :     }
    1063          20 :     return new Key(this, root);
    1064             : }
    1065             : 
    1066           0 : sal_Bool SimpleRegistry::isReadOnly()
    1067             :     throw (css::registry::InvalidRegistryException, css::uno::RuntimeException, std::exception)
    1068             : {
    1069           0 :     osl::MutexGuard guard(mutex_);
    1070           0 :     return registry_.isReadOnly();
    1071             : }
    1072             : 
    1073           0 : void SimpleRegistry::mergeKey(
    1074             :     OUString const & aKeyName, OUString const & aUrl)
    1075             :     throw (
    1076             :         css::registry::InvalidRegistryException,
    1077             :         css::registry::MergeConflictException, css::uno::RuntimeException, std::exception)
    1078             : {
    1079           0 :     osl::MutexGuard guard(mutex_);
    1080           0 :     RegistryKey root;
    1081           0 :     RegError err = registry_.openRootKey(root);
    1082           0 :     if (err == RegError::NO_ERROR) {
    1083           0 :         err = registry_.mergeKey(root, aKeyName, aUrl, false, false);
    1084             :     }
    1085           0 :     switch (err) {
    1086             :     case RegError::NO_ERROR:
    1087             :     case RegError::MERGE_CONFLICT:
    1088           0 :         break;
    1089             :     case RegError::MERGE_ERROR:
    1090             :         throw css::registry::MergeConflictException(
    1091             :             OUString("com.sun.star.registry.SimpleRegistry.mergeKey:"
    1092             :                      " underlying Registry::mergeKey() = RegError::MERGE_ERROR"),
    1093           0 :             static_cast< cppu::OWeakObject * >(this));
    1094             :     default:
    1095             :         throw css::registry::InvalidRegistryException(
    1096             :             (("com.sun.star.registry.SimpleRegistry.mergeKey:"
    1097           0 :                       " underlying Registry::getRootKey/mergeKey() = ") +
    1098           0 :              OUString::number(static_cast<int>(err))),
    1099           0 :             static_cast< OWeakObject * >(this));
    1100           0 :     }
    1101           0 : }
    1102             : 
    1103             : }
    1104             : 
    1105             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
    1106           5 : com_sun_star_comp_stoc_SimpleRegistry_get_implementation(
    1107             :     SAL_UNUSED_PARAMETER css::uno::XComponentContext *,
    1108             :     css::uno::Sequence<css::uno::Any> const &)
    1109             : {
    1110           5 :     return cppu::acquire(new SimpleRegistry);
    1111             : }
    1112             : 
    1113             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11