LCOV - code coverage report
Current view: top level - stoc/source/defaultregistry - defaultregistry.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 12 556 2.2 %
Date: 2015-06-13 12:38:46 Functions: 6 59 10.2 %
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 <osl/mutex.hxx>
      21             : #include <osl/diagnose.h>
      22             : #include <cppuhelper/queryinterface.hxx>
      23             : #include <cppuhelper/weak.hxx>
      24             : #include <cppuhelper/implbase1.hxx>
      25             : #include <cppuhelper/implbase4.hxx>
      26             : #include <cppuhelper/implbase3.hxx>
      27             : #include <cppuhelper/implementationentry.hxx>
      28             : #include <cppuhelper/supportsservice.hxx>
      29             : #include <registry/registry.hxx>
      30             : #include <rtl/ref.hxx>
      31             : 
      32             : #include <com/sun/star/registry/XSimpleRegistry.hpp>
      33             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      34             : #include <com/sun/star/lang/XServiceInfo.hpp>
      35             : #include <com/sun/star/lang/XTypeProvider.hpp>
      36             : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
      37             : #include <com/sun/star/lang/XInitialization.hpp>
      38             : #include <com/sun/star/container/XEnumerationAccess.hpp>
      39             : 
      40             : using namespace css::uno;
      41             : using namespace css::registry;
      42             : using namespace css::lang;
      43             : using namespace css::container;
      44             : using namespace cppu;
      45             : using namespace osl;
      46             : 
      47             : namespace {
      48             : 
      49             : class NestedKeyImpl;
      50             : 
      51             : class NestedRegistryImpl    : public WeakAggImplHelper4 < XSimpleRegistry, XInitialization, XServiceInfo, XEnumerationAccess >
      52             : {
      53             : public:
      54             :     NestedRegistryImpl( );
      55             : 
      56             :     virtual ~NestedRegistryImpl();
      57             : 
      58             :     // XServiceInfo
      59             :     virtual OUString SAL_CALL getImplementationName(  ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
      60             :     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
      61             :     virtual Sequence< OUString > SAL_CALL getSupportedServiceNames(  ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
      62             : 
      63             :     // XInitialization
      64             :     virtual void SAL_CALL initialize( const Sequence< Any >& aArguments )
      65             :         throw(Exception, RuntimeException, std::exception) SAL_OVERRIDE;
      66             : 
      67             :     // XSimpleRegistry
      68             :     virtual OUString SAL_CALL getURL() throw(RuntimeException, std::exception) SAL_OVERRIDE;
      69             :     virtual void SAL_CALL open( const OUString& rURL, sal_Bool bReadOnly, sal_Bool bCreate ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
      70             :     virtual sal_Bool SAL_CALL isValid(  ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
      71             :     virtual void SAL_CALL close(  ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
      72             :     virtual void SAL_CALL destroy(  ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
      73             :     virtual Reference< XRegistryKey > SAL_CALL getRootKey(  ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
      74             :     virtual sal_Bool SAL_CALL isReadOnly(  ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
      75             :     virtual void SAL_CALL mergeKey( const OUString& aKeyName, const OUString& aUrl ) throw(InvalidRegistryException, MergeConflictException, RuntimeException, std::exception) SAL_OVERRIDE;
      76             : 
      77             :     // XEnumerationAccess
      78             :     virtual Reference< XEnumeration > SAL_CALL createEnumeration(  ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
      79             :     virtual Type SAL_CALL getElementType(  ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
      80             :     virtual sal_Bool SAL_CALL hasElements(  ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
      81             : 
      82             :     friend class NestedKeyImpl;
      83             : protected:
      84             :     Mutex                       m_mutex;
      85             :     sal_uInt32                  m_state;
      86             :     Reference<XSimpleRegistry>  m_localReg;
      87             :     Reference<XSimpleRegistry>  m_defaultReg;
      88             : 
      89             : };
      90             : 
      91             : 
      92             : // class NestedKeyImpl the implenetation of interface XRegistryKey
      93             : 
      94             : class NestedKeyImpl : public WeakImplHelper1< XRegistryKey >
      95             : {
      96             : public:
      97             :     NestedKeyImpl( NestedRegistryImpl* pDefaultRegistry,
      98             :                    Reference<XRegistryKey>& localKey,
      99             :                    Reference<XRegistryKey>& defaultKey);
     100             : 
     101             :     NestedKeyImpl( const OUString& aKeyName,
     102             :                     NestedKeyImpl* pKey);
     103             : 
     104             :     virtual ~NestedKeyImpl();
     105             : 
     106             :     // XRegistryKey
     107             :     virtual OUString SAL_CALL getKeyName() throw(RuntimeException, std::exception) SAL_OVERRIDE;
     108             :     virtual sal_Bool SAL_CALL isReadOnly(  ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
     109             :     virtual sal_Bool SAL_CALL isValid(  ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
     110             :     virtual RegistryKeyType SAL_CALL getKeyType( const OUString& rKeyName ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
     111             :     virtual RegistryValueType SAL_CALL getValueType(  ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
     112             :     virtual sal_Int32 SAL_CALL getLongValue(  ) throw(InvalidRegistryException, InvalidValueException, RuntimeException, std::exception) SAL_OVERRIDE;
     113             :     virtual void SAL_CALL setLongValue( sal_Int32 value ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
     114             :     virtual Sequence< sal_Int32 > SAL_CALL getLongListValue(  ) throw(InvalidRegistryException, InvalidValueException, RuntimeException, std::exception) SAL_OVERRIDE;
     115             :     virtual void SAL_CALL setLongListValue( const css::uno::Sequence< sal_Int32 >& seqValue ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
     116             :     virtual OUString SAL_CALL getAsciiValue(  ) throw(InvalidRegistryException, InvalidValueException, RuntimeException, std::exception) SAL_OVERRIDE;
     117             :     virtual void SAL_CALL setAsciiValue( const OUString& value ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
     118             :     virtual Sequence< OUString > SAL_CALL getAsciiListValue(  ) throw(InvalidRegistryException, InvalidValueException, RuntimeException, std::exception) SAL_OVERRIDE;
     119             :     virtual void SAL_CALL setAsciiListValue( const css::uno::Sequence< OUString >& seqValue ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
     120             :     virtual OUString SAL_CALL getStringValue(  ) throw(InvalidRegistryException, InvalidValueException, RuntimeException, std::exception) SAL_OVERRIDE;
     121             :     virtual void SAL_CALL setStringValue( const OUString& value ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
     122             :     virtual Sequence< OUString > SAL_CALL getStringListValue(  ) throw(InvalidRegistryException, InvalidValueException, RuntimeException, std::exception) SAL_OVERRIDE;
     123             :     virtual void SAL_CALL setStringListValue( const css::uno::Sequence< OUString >& seqValue ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
     124             :     virtual Sequence< sal_Int8 > SAL_CALL getBinaryValue(  ) throw(InvalidRegistryException, InvalidValueException, RuntimeException, std::exception) SAL_OVERRIDE;
     125             :     virtual void SAL_CALL setBinaryValue( const css::uno::Sequence< sal_Int8 >& value ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
     126             :     virtual Reference< XRegistryKey > SAL_CALL openKey( const OUString& aKeyName ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
     127             :     virtual Reference< XRegistryKey > SAL_CALL createKey( const OUString& aKeyName ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
     128             :     virtual void SAL_CALL closeKey(  ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
     129             :     virtual void SAL_CALL deleteKey( const OUString& rKeyName ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
     130             :     virtual Sequence< Reference< XRegistryKey > > SAL_CALL openKeys(  ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
     131             :     virtual Sequence< OUString > SAL_CALL getKeyNames(  ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
     132             :     virtual sal_Bool SAL_CALL createLink( const OUString& aLinkName, const OUString& aLinkTarget ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
     133             :     virtual void SAL_CALL deleteLink( const OUString& rLinkName ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
     134             :     virtual OUString SAL_CALL getLinkTarget( const OUString& rLinkName ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
     135             :     virtual OUString SAL_CALL getResolvedName( const OUString& aKeyName ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
     136             : 
     137             : protected:
     138             :     void        computeChanges();
     139             :     OUString    computeName(const OUString& name);
     140             : 
     141             :     OUString                    m_name;
     142             :     sal_uInt32                  m_state;
     143             :     NestedRegistryImpl*         m_pRegistry;
     144             :     Reference<XRegistryKey>     m_localKey;
     145             :     Reference<XRegistryKey>     m_defaultKey;
     146             : };
     147             : 
     148             : 
     149             : 
     150           0 : NestedKeyImpl::NestedKeyImpl( NestedRegistryImpl* pDefaultRegistry,
     151             :                               Reference<XRegistryKey>& localKey,
     152             :                               Reference<XRegistryKey>& defaultKey )
     153           0 :     : m_pRegistry(pDefaultRegistry)
     154             : {
     155           0 :     m_pRegistry->acquire();
     156             : 
     157           0 :     m_localKey = localKey;
     158           0 :     m_defaultKey = defaultKey;
     159             : 
     160           0 :     if (m_localKey.is())
     161             :     {
     162           0 :         m_name = m_localKey->getKeyName();
     163             :     }
     164           0 :     else if (m_defaultKey.is())
     165             :     {
     166           0 :         m_name = m_defaultKey->getKeyName();
     167             :     }
     168             : 
     169           0 :     m_state = m_pRegistry->m_state;
     170           0 : }
     171             : 
     172             : 
     173           0 : NestedKeyImpl::NestedKeyImpl( const OUString& rKeyName,
     174             :                               NestedKeyImpl* pKey)
     175           0 :     : m_pRegistry(pKey->m_pRegistry)
     176             : {
     177           0 :     m_pRegistry->acquire();
     178             : 
     179           0 :     if (pKey->m_localKey.is() && pKey->m_localKey->isValid())
     180             :     {
     181           0 :         m_localKey = pKey->m_localKey->openKey(rKeyName);
     182             :     }
     183           0 :     if (pKey->m_defaultKey.is() && pKey->m_defaultKey->isValid())
     184             :     {
     185           0 :         m_defaultKey = pKey->m_defaultKey->openKey(rKeyName);
     186             :     }
     187             : 
     188           0 :     if (m_localKey.is())
     189             :     {
     190           0 :         m_name = m_localKey->getKeyName();
     191             :     }
     192           0 :     else if (m_defaultKey.is())
     193             :     {
     194           0 :         m_name = m_defaultKey->getKeyName();
     195             :     }
     196             : 
     197           0 :     m_state = m_pRegistry->m_state;
     198           0 : }
     199             : 
     200             : 
     201           0 : NestedKeyImpl::~NestedKeyImpl()
     202             : {
     203           0 :     if ( m_pRegistry )
     204           0 :         m_pRegistry->release();
     205           0 : }
     206             : 
     207             : 
     208           0 : void NestedKeyImpl::computeChanges()
     209             : {
     210           0 :     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
     211           0 :     if ( m_state != m_pRegistry->m_state )
     212             :     {
     213           0 :         Reference<XRegistryKey> rootKey(m_pRegistry->m_localReg->getRootKey());
     214             : 
     215           0 :         Reference<XRegistryKey> tmpKey = rootKey->openKey(m_name);
     216             : 
     217           0 :         if ( tmpKey.is() )
     218             :         {
     219           0 :             m_localKey = rootKey->openKey(m_name);
     220             :         }
     221             : 
     222           0 :         m_state = m_pRegistry->m_state;
     223           0 :     }
     224           0 : }
     225             : 
     226             : 
     227             : // NestedKey_Impl::computeName()
     228             : 
     229           0 : OUString NestedKeyImpl::computeName(const OUString& name)
     230             : {
     231           0 :     OUString resLocalName, resDefaultName;
     232             : 
     233           0 :     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
     234             :     try
     235             :     {
     236           0 :         if ( m_localKey.is() && m_localKey->isValid() )
     237             :         {
     238           0 :             resLocalName = m_localKey->getResolvedName(name);
     239             :         }
     240           0 :         else if ( m_defaultKey.is() && m_defaultKey->isValid() )
     241             :         {
     242           0 :             return m_defaultKey->getResolvedName(name);
     243             :         }
     244             : 
     245           0 :         if ( !resLocalName.isEmpty() && m_pRegistry->m_defaultReg->isValid() )
     246             :         {
     247           0 :             Reference<XRegistryKey> localRoot(m_pRegistry->m_localReg->getRootKey());
     248           0 :             Reference<XRegistryKey> defaultRoot(m_pRegistry->m_defaultReg->getRootKey());
     249             : 
     250           0 :             resDefaultName = defaultRoot->getResolvedName(resLocalName);
     251             : 
     252           0 :             sal_uInt32 count = 100;
     253             : 
     254           0 :             while (resLocalName != resDefaultName && count > 0)
     255             :             {
     256           0 :                 count--;
     257             : 
     258           0 :                 if (resLocalName.isEmpty() || resDefaultName.isEmpty())
     259           0 :                     throw InvalidRegistryException();
     260             : 
     261           0 :                 resLocalName = localRoot->getResolvedName(resDefaultName);
     262           0 :                 resDefaultName = defaultRoot->getResolvedName(resLocalName);
     263           0 :             }
     264             :         }
     265             :     }
     266           0 :     catch(InvalidRegistryException& )
     267             :     {
     268             :     }
     269             : 
     270           0 :     return resLocalName;
     271             : }
     272             : 
     273             : 
     274           0 : OUString SAL_CALL NestedKeyImpl::getKeyName() throw(RuntimeException, std::exception)
     275             : {
     276           0 :     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
     277           0 :     return m_name;
     278             : }
     279             : 
     280             : 
     281           0 : sal_Bool SAL_CALL NestedKeyImpl::isReadOnly(  )
     282             :     throw(InvalidRegistryException, RuntimeException, std::exception)
     283             : {
     284           0 :     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
     285           0 :     computeChanges();
     286             : 
     287           0 :     if ( m_localKey.is() && m_localKey->isValid() )
     288           0 :            return m_localKey->isReadOnly();
     289             :     else
     290           0 :         throw InvalidRegistryException();
     291             : }
     292             : 
     293             : 
     294           0 : sal_Bool SAL_CALL NestedKeyImpl::isValid(  ) throw(RuntimeException, std::exception)
     295             : {
     296           0 :     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
     297           0 :     return ((m_localKey.is() && m_localKey->isValid()) ||
     298           0 :             (m_defaultKey.is() && m_defaultKey->isValid()) );
     299             : }
     300             : 
     301             : 
     302           0 : RegistryKeyType SAL_CALL NestedKeyImpl::getKeyType( const OUString& rKeyName )
     303             :     throw(InvalidRegistryException, RuntimeException, std::exception)
     304             : {
     305           0 :     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
     306           0 :     computeChanges();
     307             : 
     308           0 :     if ( m_localKey.is() && m_localKey->isValid() )
     309             :     {
     310           0 :         return m_localKey->getKeyType(rKeyName);
     311             :     }
     312           0 :     else if ( m_defaultKey.is() && m_defaultKey->isValid() )
     313             :     {
     314           0 :         return m_defaultKey->getKeyType(rKeyName);
     315             :     }
     316             : 
     317           0 :     return RegistryKeyType_KEY;
     318             : }
     319             : 
     320             : 
     321           0 : RegistryValueType SAL_CALL NestedKeyImpl::getValueType(  )
     322             :     throw(InvalidRegistryException, RuntimeException, std::exception)
     323             : {
     324           0 :     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
     325           0 :     computeChanges();
     326             : 
     327           0 :     if ( m_localKey.is() && m_localKey->isValid() )
     328             :     {
     329           0 :         return m_localKey->getValueType();
     330             :     }
     331           0 :     else if ( m_defaultKey.is() && m_defaultKey->isValid() )
     332             :     {
     333           0 :         return m_defaultKey->getValueType();
     334             :     }
     335             : 
     336           0 :     return RegistryValueType_NOT_DEFINED;
     337             : }
     338             : 
     339             : 
     340           0 : sal_Int32 SAL_CALL NestedKeyImpl::getLongValue(  )
     341             :     throw(InvalidRegistryException, InvalidValueException, RuntimeException, std::exception)
     342             : {
     343           0 :     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
     344           0 :     computeChanges();
     345             : 
     346           0 :     if ( m_localKey.is() && m_localKey->isValid() )
     347             :     {
     348           0 :         return m_localKey->getLongValue();
     349             :     }
     350           0 :     else if ( m_defaultKey.is() && m_defaultKey->isValid() )
     351             :     {
     352           0 :         return m_defaultKey->getLongValue();
     353             :     }
     354             :     else
     355             :     {
     356           0 :         throw InvalidRegistryException();
     357           0 :     }
     358             : }
     359             : 
     360             : 
     361           0 : void SAL_CALL NestedKeyImpl::setLongValue( sal_Int32 value )
     362             :     throw(InvalidRegistryException, RuntimeException, std::exception)
     363             : {
     364           0 :     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
     365           0 :     computeChanges();
     366             : 
     367           0 :     if ( m_localKey.is() && m_localKey->isValid() )
     368             :     {
     369           0 :         m_localKey->setLongValue(value);
     370             :     }
     371           0 :     else if ( m_defaultKey.is() && m_defaultKey->isValid() )
     372             :     {
     373           0 :         Reference<XRegistryKey> rootKey(m_pRegistry->m_localReg->getRootKey());
     374           0 :         m_localKey = rootKey->createKey(m_name);
     375           0 :         m_localKey->setLongValue(value);
     376           0 :         m_state = m_pRegistry->m_state++;
     377             :     }
     378             :     else
     379             :     {
     380           0 :         throw InvalidRegistryException();
     381           0 :     }
     382           0 : }
     383             : 
     384             : 
     385           0 : Sequence< sal_Int32 > SAL_CALL NestedKeyImpl::getLongListValue(  )
     386             :     throw(InvalidRegistryException, InvalidValueException, RuntimeException, std::exception)
     387             : {
     388           0 :     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
     389           0 :     computeChanges();
     390             : 
     391           0 :     if ( m_localKey.is() && m_localKey->isValid() )
     392             :     {
     393           0 :         return m_localKey->getLongListValue();
     394             :     }
     395           0 :     else if ( m_defaultKey.is() && m_defaultKey->isValid() )
     396             :     {
     397           0 :         return m_defaultKey->getLongListValue();
     398             :     }
     399             :     else
     400             :     {
     401           0 :         throw InvalidRegistryException();
     402           0 :     }
     403             : }
     404             : 
     405             : 
     406           0 : void SAL_CALL NestedKeyImpl::setLongListValue( const Sequence< sal_Int32 >& seqValue )
     407             :     throw(InvalidRegistryException, RuntimeException, std::exception)
     408             : {
     409           0 :     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
     410           0 :     computeChanges();
     411             : 
     412           0 :     if ( m_localKey.is() && m_localKey->isValid() )
     413             :     {
     414           0 :         m_localKey->setLongListValue(seqValue);
     415             :     }
     416           0 :     else if ( m_defaultKey.is() && m_defaultKey->isValid() )
     417             :     {
     418           0 :         Reference<XRegistryKey> rootKey(m_pRegistry->m_localReg->getRootKey());
     419           0 :         m_localKey = rootKey->createKey(m_name);
     420           0 :         m_localKey->setLongListValue(seqValue);
     421           0 :         m_state = m_pRegistry->m_state++;
     422             :     }
     423             :     else
     424             :     {
     425           0 :         throw InvalidRegistryException();
     426           0 :     }
     427           0 : }
     428             : 
     429             : 
     430           0 : OUString SAL_CALL NestedKeyImpl::getAsciiValue(  )
     431             :     throw(InvalidRegistryException, InvalidValueException, RuntimeException, std::exception)
     432             : {
     433           0 :     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
     434           0 :     computeChanges();
     435             : 
     436           0 :     if ( m_localKey.is() && m_localKey->isValid() )
     437             :     {
     438           0 :         return m_localKey->getAsciiValue();
     439             :     }
     440           0 :     else if ( m_defaultKey.is() && m_defaultKey->isValid() )
     441             :     {
     442           0 :         return m_defaultKey->getAsciiValue();
     443             :     }
     444             :     else
     445             :     {
     446           0 :         throw InvalidRegistryException();
     447           0 :     }
     448             : }
     449             : 
     450             : 
     451           0 : void SAL_CALL NestedKeyImpl::setAsciiValue( const OUString& value )
     452             :     throw(InvalidRegistryException, RuntimeException, std::exception)
     453             : {
     454           0 :     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
     455           0 :     computeChanges();
     456             : 
     457           0 :     if ( m_localKey.is() && m_localKey->isValid() )
     458             :     {
     459           0 :         m_localKey->setAsciiValue(value);
     460             :     }
     461           0 :     else if ( m_defaultKey.is() && m_defaultKey->isValid() )
     462             :     {
     463           0 :         Reference<XRegistryKey> rootKey(m_pRegistry->m_localReg->getRootKey());
     464           0 :         m_localKey = rootKey->createKey(m_name);
     465           0 :         m_localKey->setAsciiValue(value);
     466           0 :         m_state = m_pRegistry->m_state++;
     467             :     }
     468             :     else
     469             :     {
     470           0 :         throw InvalidRegistryException();
     471           0 :     }
     472           0 : }
     473             : 
     474             : 
     475           0 : Sequence< OUString > SAL_CALL NestedKeyImpl::getAsciiListValue(  )
     476             :     throw(InvalidRegistryException, InvalidValueException, RuntimeException, std::exception)
     477             : {
     478           0 :     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
     479           0 :     computeChanges();
     480             : 
     481           0 :     if ( m_localKey.is() && m_localKey->isValid() )
     482             :     {
     483           0 :         return m_localKey->getAsciiListValue();
     484             :     }
     485           0 :     else if ( m_defaultKey.is() && m_defaultKey->isValid() )
     486             :     {
     487           0 :         return m_defaultKey->getAsciiListValue();
     488             :     }
     489             :     else
     490             :     {
     491           0 :         throw InvalidRegistryException();
     492           0 :     }
     493             : }
     494             : 
     495             : 
     496           0 : void SAL_CALL NestedKeyImpl::setAsciiListValue( const Sequence< OUString >& seqValue )
     497             :     throw(InvalidRegistryException, RuntimeException, std::exception)
     498             : {
     499           0 :     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
     500           0 :     computeChanges();
     501             : 
     502           0 :     if ( m_localKey.is() && m_localKey->isValid() )
     503             :     {
     504           0 :         m_localKey->setAsciiListValue(seqValue);
     505             :     }
     506           0 :     else if ( m_defaultKey.is() && m_defaultKey->isValid() )
     507             :     {
     508           0 :         Reference<XRegistryKey> rootKey(m_pRegistry->m_localReg->getRootKey());
     509           0 :         m_localKey = rootKey->createKey(m_name);
     510           0 :         m_localKey->setAsciiListValue(seqValue);
     511           0 :         m_state = m_pRegistry->m_state++;
     512             :     }
     513             :     else
     514             :     {
     515           0 :         throw InvalidRegistryException();
     516           0 :     }
     517           0 : }
     518             : 
     519             : 
     520           0 : OUString SAL_CALL NestedKeyImpl::getStringValue(  )
     521             :     throw(InvalidRegistryException, InvalidValueException, RuntimeException, std::exception)
     522             : {
     523           0 :     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
     524           0 :     computeChanges();
     525             : 
     526           0 :     if ( m_localKey.is() && m_localKey->isValid() )
     527             :     {
     528           0 :         return m_localKey->getStringValue();
     529             :     }
     530           0 :     else if ( m_defaultKey.is() && m_defaultKey->isValid() )
     531             :     {
     532           0 :         return m_defaultKey->getStringValue();
     533             :     }
     534             :     else
     535             :     {
     536           0 :         throw InvalidRegistryException();
     537           0 :     }
     538             : }
     539             : 
     540             : 
     541           0 : void SAL_CALL NestedKeyImpl::setStringValue( const OUString& value )
     542             :     throw(InvalidRegistryException, RuntimeException, std::exception)
     543             : {
     544           0 :     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
     545           0 :     computeChanges();
     546             : 
     547           0 :     if ( m_localKey.is() && m_localKey->isValid() )
     548             :     {
     549           0 :         m_localKey->setStringValue(value);
     550             :     }
     551           0 :     else if ( m_defaultKey.is() && m_defaultKey->isValid() )
     552             :     {
     553           0 :         Reference<XRegistryKey> rootKey(m_pRegistry->m_localReg->getRootKey());
     554           0 :         m_localKey = rootKey->createKey(m_name);
     555           0 :         m_localKey->setStringValue(value);
     556           0 :         m_state = m_pRegistry->m_state++;
     557             :     }
     558             :     else
     559             :     {
     560           0 :         throw InvalidRegistryException();
     561           0 :     }
     562           0 : }
     563             : 
     564             : 
     565           0 : Sequence< OUString > SAL_CALL NestedKeyImpl::getStringListValue(  )
     566             :     throw(InvalidRegistryException, InvalidValueException, RuntimeException, std::exception)
     567             : {
     568           0 :     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
     569           0 :     computeChanges();
     570             : 
     571           0 :     if ( m_localKey.is() && m_localKey->isValid() )
     572             :     {
     573           0 :         return m_localKey->getStringListValue();
     574             :     }
     575           0 :     else if ( m_defaultKey.is() && m_defaultKey->isValid() )
     576             :     {
     577           0 :         return m_defaultKey->getStringListValue();
     578             :     }
     579             :     else
     580             :     {
     581           0 :         throw InvalidRegistryException();
     582           0 :     }
     583             : }
     584             : 
     585             : 
     586           0 : void SAL_CALL NestedKeyImpl::setStringListValue( const Sequence< OUString >& seqValue )
     587             :     throw(InvalidRegistryException, RuntimeException, std::exception)
     588             : {
     589           0 :     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
     590           0 :     computeChanges();
     591             : 
     592           0 :     if ( m_localKey.is() && m_localKey->isValid() )
     593             :     {
     594           0 :         m_localKey->setStringListValue(seqValue);
     595             :     }
     596           0 :     else if ( m_defaultKey.is() && m_defaultKey->isValid() )
     597             :     {
     598           0 :         Reference<XRegistryKey> rootKey(m_pRegistry->m_localReg->getRootKey());
     599           0 :         m_localKey = rootKey->createKey(m_name);
     600           0 :         m_localKey->setStringListValue(seqValue);
     601           0 :         m_state = m_pRegistry->m_state++;
     602             :     }
     603             :     else
     604             :     {
     605           0 :         throw InvalidRegistryException();
     606           0 :     }
     607           0 : }
     608             : 
     609             : 
     610           0 : Sequence< sal_Int8 > SAL_CALL NestedKeyImpl::getBinaryValue(  )
     611             :     throw(InvalidRegistryException, InvalidValueException, RuntimeException, std::exception)
     612             : {
     613           0 :     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
     614           0 :     computeChanges();
     615             : 
     616           0 :     if ( m_localKey.is() && m_localKey->isValid() )
     617             :     {
     618           0 :         return m_localKey->getBinaryValue();
     619             :     }
     620           0 :     else if ( m_defaultKey.is() && m_defaultKey->isValid() )
     621             :     {
     622           0 :         return m_defaultKey->getBinaryValue();
     623             :     }
     624             :     else
     625             :     {
     626           0 :         throw InvalidRegistryException();
     627           0 :     }
     628             : }
     629             : 
     630             : 
     631           0 : void SAL_CALL NestedKeyImpl::setBinaryValue( const Sequence< sal_Int8 >& value )
     632             :     throw(InvalidRegistryException, RuntimeException, std::exception)
     633             : {
     634           0 :     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
     635           0 :     computeChanges();
     636             : 
     637           0 :     if ( m_localKey.is() && m_localKey->isValid() )
     638             :     {
     639           0 :         m_localKey->setBinaryValue(value);
     640             :     }
     641           0 :     else if ( m_defaultKey.is() && m_defaultKey->isValid() )
     642             :     {
     643           0 :         Reference<XRegistryKey> rootKey(m_pRegistry->m_localReg->getRootKey());
     644           0 :         m_localKey = rootKey->createKey(m_name);
     645           0 :         m_localKey->setBinaryValue(value);
     646           0 :         m_state = m_pRegistry->m_state++;
     647             :     }
     648             :     else
     649             :     {
     650           0 :         throw InvalidRegistryException();
     651           0 :     }
     652           0 : }
     653             : 
     654             : 
     655           0 : Reference< XRegistryKey > SAL_CALL NestedKeyImpl::openKey( const OUString& aKeyName )
     656             :     throw(InvalidRegistryException, RuntimeException, std::exception)
     657             : {
     658           0 :     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
     659           0 :     if ( !m_localKey.is() && !m_defaultKey.is() )
     660             :     {
     661           0 :         throw InvalidRegistryException();
     662             :     }
     663             : 
     664           0 :     OUString resolvedName = computeName(aKeyName);
     665             : 
     666           0 :     if ( resolvedName.isEmpty() )
     667           0 :         throw InvalidRegistryException();
     668             : 
     669           0 :     Reference<XRegistryKey> localKey, defaultKey;
     670             : 
     671           0 :     if ( m_localKey.is() && m_localKey->isValid() )
     672             :     {
     673           0 :         localKey = m_pRegistry->m_localReg->getRootKey()->openKey(resolvedName);
     674             :     }
     675           0 :     if ( m_defaultKey.is() && m_defaultKey->isValid() )
     676             :     {
     677           0 :         defaultKey = m_pRegistry->m_defaultReg->getRootKey()->openKey(resolvedName);
     678             :     }
     679             : 
     680           0 :     if ( localKey.is() || defaultKey.is() )
     681             :     {
     682           0 :         return static_cast<XRegistryKey*>(new NestedKeyImpl(m_pRegistry, localKey, defaultKey));
     683             :     }
     684             :     else
     685             :     {
     686           0 :         return Reference<XRegistryKey>();
     687           0 :     }
     688             : }
     689             : 
     690             : 
     691           0 : Reference< XRegistryKey > SAL_CALL NestedKeyImpl::createKey( const OUString& aKeyName )
     692             :     throw(InvalidRegistryException, RuntimeException, std::exception)
     693             : {
     694           0 :     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
     695           0 :     if ( (!m_localKey.is() && !m_defaultKey.is()) ||
     696           0 :          (m_localKey.is() && m_localKey->isReadOnly()) )
     697             :     {
     698           0 :         throw InvalidRegistryException();
     699             :     }
     700             : 
     701           0 :     OUString resolvedName = computeName(aKeyName);
     702             : 
     703           0 :     if ( resolvedName.isEmpty() )
     704           0 :         throw InvalidRegistryException();
     705             : 
     706           0 :     if ( m_localKey.is() && m_localKey->isValid() )
     707             :     {
     708           0 :         Reference<XRegistryKey> localKey, defaultKey;
     709             : 
     710           0 :         localKey = m_pRegistry->m_localReg->getRootKey()->createKey(resolvedName);
     711           0 :         if ( localKey.is() )
     712             :         {
     713           0 :             if ( m_defaultKey.is() && m_defaultKey->isValid() )
     714             :             {
     715           0 :                 defaultKey = m_pRegistry->m_defaultReg->getRootKey()->openKey(resolvedName);
     716             :             }
     717             : 
     718           0 :             m_state = m_pRegistry->m_state++;
     719             : 
     720           0 :             return (static_cast<XRegistryKey*>(new NestedKeyImpl(m_pRegistry, localKey, defaultKey)));
     721           0 :         }
     722             :     }
     723             :     else
     724             :     {
     725           0 :         Reference<XRegistryKey> localKey, defaultKey;
     726             : 
     727           0 :         if ( m_defaultKey.is() && m_defaultKey->isValid() )
     728             :         {
     729           0 :             Reference<XRegistryKey> rootKey(m_pRegistry->m_localReg->getRootKey());
     730           0 :             m_localKey = rootKey->createKey(m_name);
     731             : 
     732           0 :             localKey = m_pRegistry->m_localReg->getRootKey()->createKey(resolvedName);
     733             : 
     734           0 :             if ( localKey.is() )
     735             :             {
     736           0 :                 defaultKey = m_pRegistry->m_defaultReg->getRootKey()->openKey(resolvedName);
     737             : 
     738           0 :                 m_state = m_pRegistry->m_state++;
     739             : 
     740           0 :                 return (static_cast<XRegistryKey*>(new NestedKeyImpl(m_pRegistry, localKey, defaultKey)));
     741           0 :             }
     742           0 :         }
     743             :     }
     744             : 
     745           0 :     return Reference<XRegistryKey>();
     746             : }
     747             : 
     748             : 
     749           0 : void SAL_CALL NestedKeyImpl::closeKey(  )
     750             :     throw(InvalidRegistryException, RuntimeException, std::exception)
     751             : {
     752           0 :     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
     753           0 :     if ( m_localKey.is() && m_localKey->isValid() )
     754             :     {
     755           0 :         m_localKey->closeKey();
     756             :     }
     757           0 :     if ( m_defaultKey.is() && m_defaultKey->isValid() )
     758             :     {
     759           0 :         m_defaultKey->closeKey();
     760           0 :     }
     761           0 : }
     762             : 
     763             : 
     764           0 : void SAL_CALL NestedKeyImpl::deleteKey( const OUString& rKeyName )
     765             :     throw(InvalidRegistryException, RuntimeException, std::exception)
     766             : {
     767           0 :     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
     768           0 :     if ( m_localKey.is() && m_localKey->isValid() &&
     769           0 :          !m_localKey->isReadOnly() )
     770             :     {
     771           0 :         OUString resolvedName = computeName(rKeyName);
     772             : 
     773           0 :         if ( resolvedName.isEmpty() )
     774             :         {
     775           0 :             throw InvalidRegistryException();
     776             :         }
     777             : 
     778           0 :         m_pRegistry->m_localReg->getRootKey()->deleteKey(resolvedName);
     779             :     }
     780             :     else
     781             :     {
     782           0 :         throw InvalidRegistryException();
     783           0 :     }
     784           0 : }
     785             : 
     786             : 
     787           0 : Sequence< Reference< XRegistryKey > > SAL_CALL NestedKeyImpl::openKeys(  )
     788             :     throw(InvalidRegistryException, RuntimeException, std::exception)
     789             : {
     790           0 :     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
     791           0 :     if ( !m_localKey.is() && !m_defaultKey.is() )
     792             :     {
     793           0 :         throw InvalidRegistryException();
     794             :     }
     795             : 
     796           0 :     Sequence<OUString> localSeq, defaultSeq;
     797             : 
     798           0 :     if ( m_localKey.is() && m_localKey->isValid() )
     799             :     {
     800           0 :         localSeq = m_localKey->getKeyNames();
     801             :     }
     802           0 :     if ( m_defaultKey.is() && m_defaultKey->isValid() )
     803             :     {
     804           0 :         defaultSeq = m_defaultKey->getKeyNames();
     805             :     }
     806             : 
     807           0 :     sal_uInt32 local = localSeq.getLength();
     808           0 :     sal_uInt32 def = defaultSeq.getLength();
     809           0 :     sal_uInt32 len = 0;
     810             : 
     811             :     sal_uInt32 i, j;
     812           0 :     for (i=0; i < local; i++)
     813             :     {
     814           0 :         for (j=0 ; j < def; j++)
     815             :         {
     816           0 :             if ( localSeq.getConstArray()[i] == defaultSeq.getConstArray()[j] )
     817             :             {
     818           0 :                 len++;
     819           0 :                 break;
     820             :             }
     821             :         }
     822             :     }
     823             : 
     824           0 :     Sequence< Reference<XRegistryKey> > retSeq(local + def - len);
     825           0 :     OUString                            name;
     826             :     sal_Int32                           lastIndex;
     827             : 
     828           0 :     for (i=0; i < local; i++)
     829             :     {
     830           0 :         name = localSeq.getConstArray()[i];
     831           0 :         lastIndex = name.lastIndexOf('/');
     832           0 :         name = name.copy(lastIndex);
     833           0 :         retSeq.getArray()[i] =
     834           0 :             static_cast<XRegistryKey*>(new NestedKeyImpl(name, this));
     835             :     }
     836             : 
     837           0 :     sal_uInt32 k = local;
     838           0 :     for (i=0; i < def; i++)
     839             :     {
     840           0 :         bool insert = true;
     841             : 
     842           0 :         for (j=0 ; j < local; j++)
     843             :         {
     844           0 :             if ( retSeq.getConstArray()[j]->getKeyName()
     845           0 :                     == defaultSeq.getConstArray()[i] )
     846             :             {
     847           0 :                 insert = false;
     848           0 :                 break;
     849             :             }
     850             :         }
     851             : 
     852           0 :         if ( insert )
     853             :         {
     854           0 :             name = defaultSeq.getConstArray()[i];
     855           0 :             lastIndex = name.lastIndexOf('/');
     856           0 :             name = name.copy(lastIndex);
     857           0 :             retSeq.getArray()[k++] =
     858           0 :                 static_cast<XRegistryKey*>(new NestedKeyImpl(name, this));
     859             :         }
     860             :     }
     861             : 
     862           0 :     return retSeq;
     863             : }
     864             : 
     865             : 
     866           0 : Sequence< OUString > SAL_CALL NestedKeyImpl::getKeyNames(  )
     867             :     throw(InvalidRegistryException, RuntimeException, std::exception)
     868             : {
     869           0 :     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
     870           0 :     if ( !m_localKey.is() && !m_defaultKey.is() )
     871             :     {
     872           0 :         throw InvalidRegistryException();
     873             :     }
     874             : 
     875           0 :     Sequence<OUString> localSeq, defaultSeq;
     876             : 
     877           0 :     if ( m_localKey.is() && m_localKey->isValid() )
     878             :     {
     879           0 :         localSeq = m_localKey->getKeyNames();
     880             :     }
     881           0 :     if ( m_defaultKey.is() && m_defaultKey->isValid() )
     882             :     {
     883           0 :         defaultSeq = m_defaultKey->getKeyNames();
     884             :     }
     885             : 
     886           0 :     sal_uInt32 local = localSeq.getLength();
     887           0 :     sal_uInt32 def = defaultSeq.getLength();
     888           0 :     sal_uInt32 len = 0;
     889             : 
     890             :     sal_uInt32 i, j;
     891           0 :     for (i=0; i < local; i++)
     892             :     {
     893           0 :         for (j=0 ; j < def; j++)
     894             :         {
     895           0 :             if ( localSeq.getConstArray()[i] == defaultSeq.getConstArray()[j] )
     896             :             {
     897           0 :                 len++;
     898           0 :                 break;
     899             :             }
     900             :         }
     901             :     }
     902             : 
     903           0 :     Sequence<OUString>  retSeq(local + def - len);
     904             : 
     905           0 :     for (i=0; i < local; i++)
     906             :     {
     907           0 :         retSeq.getArray()[i] = localSeq.getConstArray()[i];
     908             :     }
     909             : 
     910           0 :     sal_uInt32 k = local;
     911           0 :     for (i=0; i < def; i++)
     912             :     {
     913           0 :         bool insert = true;
     914             : 
     915           0 :         for (j=0 ; j < local; j++)
     916             :         {
     917           0 :             if ( retSeq.getConstArray()[j] == defaultSeq.getConstArray()[i] )
     918             :             {
     919           0 :                 insert = false;
     920           0 :                 break;
     921             :             }
     922             :         }
     923             : 
     924           0 :         if ( insert )
     925           0 :             retSeq.getArray()[k++] = defaultSeq.getConstArray()[i];
     926             :     }
     927             : 
     928           0 :     return retSeq;
     929             : }
     930             : 
     931             : 
     932           0 : sal_Bool SAL_CALL NestedKeyImpl::createLink( const OUString& aLinkName, const OUString& aLinkTarget )
     933             :     throw(InvalidRegistryException, RuntimeException, std::exception)
     934             : {
     935           0 :     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
     936             : 
     937           0 :     bool isCreated = false;
     938           0 :     if ( !m_localKey.is() && !m_defaultKey.is() )
     939             :     {
     940           0 :         throw InvalidRegistryException();
     941             :     }
     942             : 
     943           0 :     OUString    linkName;
     944           0 :     OUString    resolvedName;
     945           0 :     sal_Int32   lastIndex = aLinkName.lastIndexOf('/');
     946             : 
     947           0 :     if ( lastIndex > 0 )
     948             :     {
     949           0 :         linkName = aLinkName.copy(0, lastIndex);
     950             : 
     951           0 :         resolvedName = computeName(linkName);
     952             : 
     953           0 :         if ( resolvedName.isEmpty() )
     954             :         {
     955           0 :             throw InvalidRegistryException();
     956             :         }
     957             : 
     958           0 :         resolvedName = resolvedName + aLinkName.copy(lastIndex);
     959             :     }
     960             :     else
     961             :     {
     962           0 :         if ( lastIndex == 0 )
     963           0 :             resolvedName = m_name + aLinkName;
     964             :         else
     965           0 :             resolvedName = m_name + "/" + aLinkName;
     966             :     }
     967             : 
     968           0 :     if ( m_localKey.is() && m_localKey->isValid() )
     969             :     {
     970           0 :         isCreated = m_pRegistry->m_localReg->getRootKey()->createLink(resolvedName, aLinkTarget);
     971             :     }
     972             :     else
     973             :     {
     974           0 :         if ( m_defaultKey.is() && m_defaultKey->isValid() )
     975             :         {
     976           0 :             Reference<XRegistryKey> rootKey(m_pRegistry->m_localReg->getRootKey());
     977           0 :             m_localKey = rootKey->createKey(m_name);
     978             : 
     979           0 :             isCreated = m_pRegistry->m_localReg->getRootKey()->createLink(resolvedName, aLinkTarget);
     980             :         }
     981             :     }
     982             : 
     983           0 :     if ( isCreated )
     984           0 :         m_state = m_pRegistry->m_state++;
     985             : 
     986           0 :     return isCreated;
     987             : }
     988             : 
     989             : 
     990           0 : void SAL_CALL NestedKeyImpl::deleteLink( const OUString& rLinkName )
     991             :     throw(InvalidRegistryException, RuntimeException, std::exception)
     992             : {
     993           0 :     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
     994           0 :     if ( !m_localKey.is() && !m_defaultKey.is() )
     995             :     {
     996           0 :         throw InvalidRegistryException();
     997             :     }
     998             : 
     999           0 :     OUString    linkName;
    1000           0 :     OUString    resolvedName;
    1001           0 :     sal_Int32   lastIndex = rLinkName.lastIndexOf('/');
    1002             : 
    1003           0 :     if ( lastIndex > 0 )
    1004             :     {
    1005           0 :         linkName = rLinkName.copy(0, lastIndex);
    1006             : 
    1007           0 :         resolvedName = computeName(linkName);
    1008             : 
    1009           0 :         if ( resolvedName.isEmpty() )
    1010             :         {
    1011           0 :             throw InvalidRegistryException();
    1012             :         }
    1013             : 
    1014           0 :         resolvedName = resolvedName + rLinkName.copy(lastIndex);
    1015             :     }
    1016             :     else
    1017             :     {
    1018           0 :         if ( lastIndex == 0 )
    1019           0 :             resolvedName = m_name + rLinkName;
    1020             :         else
    1021           0 :             resolvedName = m_name + "/" + rLinkName;
    1022             :     }
    1023             : 
    1024           0 :     if ( m_localKey.is() && m_localKey->isValid() &&
    1025           0 :          !m_localKey->isReadOnly() )
    1026             :     {
    1027           0 :         m_pRegistry->m_localReg->getRootKey()->deleteLink(resolvedName);
    1028             :     }
    1029             :     else
    1030             :     {
    1031           0 :         throw InvalidRegistryException();
    1032           0 :     }
    1033           0 : }
    1034             : 
    1035             : 
    1036           0 : OUString SAL_CALL NestedKeyImpl::getLinkTarget( const OUString& rLinkName )
    1037             :     throw(InvalidRegistryException, RuntimeException, std::exception)
    1038             : {
    1039           0 :     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
    1040           0 :     if ( !m_localKey.is() && !m_defaultKey.is() )
    1041             :     {
    1042           0 :         throw InvalidRegistryException();
    1043             :     }
    1044             : 
    1045           0 :     OUString    linkName;
    1046           0 :     OUString    resolvedName;
    1047           0 :     sal_Int32   lastIndex = rLinkName.lastIndexOf('/');
    1048             : 
    1049           0 :     if ( lastIndex > 0 )
    1050             :     {
    1051           0 :         linkName = rLinkName.copy(0, lastIndex);
    1052             : 
    1053           0 :         resolvedName = computeName(linkName);
    1054             : 
    1055           0 :         if ( resolvedName.isEmpty() )
    1056             :         {
    1057           0 :             throw InvalidRegistryException();
    1058             :         }
    1059             : 
    1060           0 :         resolvedName = resolvedName + rLinkName.copy(lastIndex);
    1061             :     }
    1062             :     else
    1063             :     {
    1064           0 :         if ( lastIndex == 0 )
    1065           0 :             resolvedName = m_name + rLinkName;
    1066             :         else
    1067           0 :             resolvedName = m_name + "/" + rLinkName;
    1068             :     }
    1069             : 
    1070           0 :     OUString linkTarget;
    1071           0 :     if ( m_localKey.is() && m_localKey->isValid() )
    1072             :     {
    1073             :         try
    1074             :         {
    1075           0 :             linkTarget = m_pRegistry->m_localReg->getRootKey()->getLinkTarget(resolvedName);
    1076           0 :             return linkTarget;
    1077             :         }
    1078           0 :         catch(InvalidRegistryException& )
    1079             :         {
    1080             :         }
    1081             :     }
    1082             : 
    1083           0 :     if ( m_defaultKey.is() && m_defaultKey->isValid() )
    1084           0 :         linkTarget = m_pRegistry->m_defaultReg->getRootKey()->getLinkTarget(resolvedName);
    1085             : 
    1086           0 :     return linkTarget;
    1087             : }
    1088             : 
    1089             : 
    1090           0 : OUString SAL_CALL NestedKeyImpl::getResolvedName( const OUString& aKeyName )
    1091             :     throw(InvalidRegistryException, RuntimeException, std::exception)
    1092             : {
    1093           0 :     Guard< Mutex > aGuard( m_pRegistry->m_mutex );
    1094           0 :     if ( !m_localKey.is() && !m_defaultKey.is() )
    1095             :     {
    1096           0 :         throw InvalidRegistryException();
    1097             :     }
    1098             : 
    1099           0 :     OUString resolvedName = computeName(aKeyName);
    1100             : 
    1101           0 :     if ( resolvedName.isEmpty() )
    1102             :     {
    1103           0 :         throw InvalidRegistryException();
    1104             :     }
    1105             : 
    1106           0 :     return resolvedName;
    1107             : }
    1108             : 
    1109             : 
    1110             : 
    1111             : // DefaultRegistry Implementation
    1112             : 
    1113             : 
    1114           1 : NestedRegistryImpl::NestedRegistryImpl( )
    1115           1 :     : m_state(0)
    1116           1 : {}
    1117             : 
    1118             : 
    1119           2 : NestedRegistryImpl::~NestedRegistryImpl() {}
    1120             : 
    1121           0 : class RegistryEnumueration : public WeakImplHelper1< XEnumeration >
    1122             : {
    1123             : public:
    1124           0 :     RegistryEnumueration(
    1125             :         const Reference< XSimpleRegistry > &r1,
    1126             :         const Reference< XSimpleRegistry > &r2 )
    1127           0 :         : m_xReg1( r1 ) , m_xReg2( r2 )
    1128           0 :         {}
    1129             : public:
    1130             :     virtual sal_Bool SAL_CALL hasMoreElements(  ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
    1131             :     virtual Any SAL_CALL nextElement(  ) throw (NoSuchElementException, WrappedTargetException, RuntimeException, std::exception) SAL_OVERRIDE;
    1132             : 
    1133             : private:
    1134             :     Reference< XSimpleRegistry > m_xReg1;
    1135             :     Reference< XSimpleRegistry > m_xReg2;
    1136             : };
    1137             : 
    1138           0 : sal_Bool RegistryEnumueration::hasMoreElements(  ) throw (RuntimeException, std::exception)
    1139             : {
    1140           0 :     return m_xReg1.is() || m_xReg2.is();
    1141             : }
    1142             : 
    1143           0 : Any RegistryEnumueration::nextElement(  )
    1144             :     throw (NoSuchElementException, WrappedTargetException, RuntimeException, std::exception)
    1145             : {
    1146           0 :     Any a;
    1147           0 :     if( m_xReg1.is() )
    1148             :     {
    1149           0 :         a <<= m_xReg1;
    1150           0 :         m_xReg1.clear();
    1151             :     }
    1152           0 :     else if( m_xReg2.is() )
    1153             :     {
    1154           0 :         a <<= m_xReg2;
    1155           0 :         m_xReg2.clear();
    1156             :     }
    1157             :     else
    1158             :     {
    1159           0 :         throw NoSuchElementException( "NestedRegistry: no nextElement() !" );
    1160             :     }
    1161           0 :     return a;
    1162             : }
    1163             : 
    1164             : 
    1165           0 : Reference< XEnumeration > NestedRegistryImpl::createEnumeration(  ) throw (RuntimeException, std::exception)
    1166             : {
    1167           0 :     MutexGuard guard( m_mutex );
    1168           0 :     return new RegistryEnumueration( m_localReg, m_defaultReg );
    1169             : }
    1170             : 
    1171           0 : Type NestedRegistryImpl::getElementType(  ) throw (RuntimeException, std::exception)
    1172             : {
    1173           0 :     return cppu::UnoType<decltype(m_localReg)>::get();
    1174             : }
    1175             : 
    1176           0 : sal_Bool SAL_CALL NestedRegistryImpl::hasElements(  ) throw (RuntimeException, std::exception)
    1177             : {
    1178           0 :     MutexGuard guard( m_mutex );
    1179           0 :     return m_localReg.is() || m_defaultReg.is();
    1180             : }
    1181             : 
    1182             : 
    1183             : 
    1184             : 
    1185           1 : OUString SAL_CALL NestedRegistryImpl::getImplementationName(  )
    1186             :     throw(RuntimeException, std::exception)
    1187             : {
    1188           1 :     return OUString("com.sun.star.comp.stoc.NestedRegistry");
    1189             : }
    1190             : 
    1191           0 : sal_Bool SAL_CALL NestedRegistryImpl::supportsService( const OUString& ServiceName )
    1192             :     throw(RuntimeException, std::exception)
    1193             : {
    1194           0 :     return cppu::supportsService(this, ServiceName);
    1195             : }
    1196             : 
    1197           1 : Sequence<OUString> SAL_CALL NestedRegistryImpl::getSupportedServiceNames(  )
    1198             :     throw(RuntimeException, std::exception)
    1199             : {
    1200           1 :     Sequence< OUString > seqNames(1);
    1201           1 :     seqNames[0] = "com.sun.star.registry.NestedRegistry";
    1202           1 :     return seqNames;
    1203             : }
    1204             : 
    1205             : 
    1206           0 : void SAL_CALL NestedRegistryImpl::initialize( const Sequence< Any >& aArguments )
    1207             :     throw( Exception, RuntimeException, std::exception )
    1208             : {
    1209           0 :     Guard< Mutex > aGuard( m_mutex );
    1210           0 :     if ( (aArguments.getLength() == 2) &&
    1211           0 :          (aArguments[0].getValueType().getTypeClass() == TypeClass_INTERFACE) &&
    1212           0 :          (aArguments[1].getValueType().getTypeClass() == TypeClass_INTERFACE) )
    1213             :     {
    1214           0 :         aArguments[0] >>= m_localReg;
    1215           0 :         aArguments[1] >>= m_defaultReg;
    1216           0 :         if ( m_localReg == m_defaultReg )
    1217           0 :             m_defaultReg.clear();
    1218           0 :     }
    1219           0 : }
    1220             : 
    1221             : 
    1222           0 : OUString SAL_CALL NestedRegistryImpl::getURL() throw(RuntimeException, std::exception)
    1223             : {
    1224           0 :     Guard< Mutex > aGuard( m_mutex );
    1225             :     try
    1226             :     {
    1227           0 :         if ( m_localReg.is() && m_localReg->isValid() )
    1228           0 :             return m_localReg->getURL();
    1229             :     }
    1230           0 :     catch(InvalidRegistryException& )
    1231             :     {
    1232             :     }
    1233             : 
    1234           0 :     return OUString();
    1235             : }
    1236             : 
    1237             : 
    1238           0 : void SAL_CALL NestedRegistryImpl::open( const OUString&, sal_Bool, sal_Bool )
    1239             :     throw(InvalidRegistryException, RuntimeException, std::exception)
    1240             : {
    1241             :     throw InvalidRegistryException(
    1242           0 :             "the 'open' method is not specified for a nested registry" );
    1243             : }
    1244             : 
    1245             : 
    1246           0 : sal_Bool SAL_CALL NestedRegistryImpl::isValid(  ) throw(RuntimeException, std::exception)
    1247             : {
    1248           0 :     Guard< Mutex > aGuard( m_mutex );
    1249             :     try
    1250             :     {
    1251           0 :         if ( (m_localReg.is() && m_localReg->isValid()) ||
    1252           0 :              (m_defaultReg.is() && m_defaultReg->isValid()) )
    1253           0 :             return sal_True;
    1254             :     }
    1255           0 :     catch(InvalidRegistryException& )
    1256             :     {
    1257             :     }
    1258             : 
    1259           0 :     return sal_False;
    1260             : }
    1261             : 
    1262             : 
    1263           0 : void SAL_CALL NestedRegistryImpl::close(  )
    1264             :     throw(InvalidRegistryException, RuntimeException, std::exception)
    1265             : {
    1266           0 :     Guard< Mutex > aGuard( m_mutex );
    1267           0 :     if ( m_localReg.is() && m_localReg->isValid() )
    1268             :     {
    1269           0 :         m_localReg->close();
    1270             :     }
    1271           0 :     if ( m_defaultReg.is() && m_defaultReg->isValid() )
    1272             :     {
    1273           0 :         m_defaultReg->close();
    1274           0 :     }
    1275           0 : }
    1276             : 
    1277             : 
    1278           0 : void SAL_CALL NestedRegistryImpl::destroy(  )
    1279             :     throw(InvalidRegistryException, RuntimeException, std::exception)
    1280             : {
    1281             :     throw InvalidRegistryException(
    1282           0 :             "the 'destroy' method is not specified for a nested registry" );
    1283             : }
    1284             : 
    1285             : 
    1286           0 : Reference< XRegistryKey > SAL_CALL NestedRegistryImpl::getRootKey(  )
    1287             :     throw(InvalidRegistryException, RuntimeException, std::exception)
    1288             : {
    1289           0 :     Reference<XRegistryKey> tmpKey;
    1290             : 
    1291           0 :     Guard< Mutex > aGuard( m_mutex );
    1292           0 :     if ( m_localReg.is() && m_localReg->isValid() )
    1293             :     {
    1294           0 :         Reference<XRegistryKey> localKey, defaultKey;
    1295             : 
    1296           0 :         localKey = m_localReg->getRootKey();
    1297             : 
    1298           0 :         if ( localKey.is() )
    1299             :         {
    1300           0 :             if ( m_defaultReg.is() && m_defaultReg->isValid() )
    1301             :             {
    1302           0 :                 defaultKey = m_defaultReg->getRootKey();
    1303             :             }
    1304             : 
    1305           0 :             return (static_cast<XRegistryKey*>(new NestedKeyImpl(this, localKey, defaultKey)));
    1306           0 :         }
    1307             :     }
    1308             :     else
    1309             :     {
    1310           0 :         throw InvalidRegistryException();
    1311             :     }
    1312             : 
    1313           0 :     return Reference<XRegistryKey>();
    1314             : }
    1315             : 
    1316             : 
    1317           0 : sal_Bool SAL_CALL NestedRegistryImpl::isReadOnly(  )
    1318             :     throw(InvalidRegistryException, RuntimeException, std::exception)
    1319             : {
    1320           0 :     Guard< Mutex > aGuard( m_mutex );
    1321             :     try
    1322             :     {
    1323           0 :         if ( m_localReg.is() && m_localReg->isValid() )
    1324           0 :             return m_localReg->isReadOnly();
    1325             :     }
    1326           0 :     catch(InvalidRegistryException& )
    1327             :     {
    1328             :     }
    1329             : 
    1330           0 :     return sal_False;
    1331             : }
    1332             : 
    1333             : 
    1334           0 : void SAL_CALL NestedRegistryImpl::mergeKey( const OUString& aKeyName, const OUString& aUrl )
    1335             :     throw(InvalidRegistryException, MergeConflictException, RuntimeException, std::exception)
    1336             : {
    1337           0 :     Guard< Mutex > aGuard( m_mutex );
    1338           0 :     if ( m_localReg.is() && m_localReg->isValid() )
    1339             :     {
    1340           0 :         m_localReg->mergeKey(aKeyName, aUrl);
    1341             : 
    1342           0 :         m_state++;
    1343           0 :     }
    1344           0 : }
    1345             : 
    1346             : } // namespace
    1347             : 
    1348             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
    1349           1 : com_sun_star_comp_stoc_NestedRegistry_get_implementation(
    1350             :     SAL_UNUSED_PARAMETER css::uno::XComponentContext *,
    1351             :     css::uno::Sequence<css::uno::Any> const &)
    1352             : {
    1353           1 :     return cppu::acquire(new NestedRegistryImpl);
    1354             : }
    1355             : 
    1356             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11