LCOV - code coverage report
Current view: top level - libreoffice/ucb/source/ucp/hierarchy - hierarchydatasource.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 243 0.0 %
Date: 2012-12-17 Functions: 0 57 0.0 %
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             : 
      21             : /**************************************************************************
      22             :                                 TODO
      23             :  **************************************************************************
      24             : 
      25             :  Note: Configuration Management classes do not support XAggregation.
      26             :        So I have to wrap the interesting interfaces manually.
      27             : 
      28             :  *************************************************************************/
      29             : #include "hierarchydatasource.hxx"
      30             : #include <osl/diagnose.h>
      31             : 
      32             : #include "osl/doublecheckedlocking.h"
      33             : #include <comphelper/processfactory.hxx>
      34             : #include <cppuhelper/interfacecontainer.hxx>
      35             : #include <com/sun/star/beans/PropertyValue.hpp>
      36             : #include <com/sun/star/configuration/theDefaultProvider.hpp>
      37             : #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
      38             : #include <com/sun/star/container/XNameContainer.hpp>
      39             : #include <com/sun/star/util/XChangesBatch.hpp>
      40             : #include <com/sun/star/util/XChangesNotifier.hpp>
      41             : 
      42             : using namespace com::sun::star;
      43             : using namespace hierarchy_ucp;
      44             : 
      45             : //=========================================================================
      46             : 
      47             : // describe path of cfg entry
      48             : #define CFGPROPERTY_NODEPATH    "nodepath"
      49             : // true->async. update; false->sync. update
      50             : #define CFGPROPERTY_LAZYWRITE   "lazywrite"
      51             : 
      52             : #define READ_SERVICE_NAME      "com.sun.star.ucb.HierarchyDataReadAccess"
      53             : #define READWRITE_SERVICE_NAME "com.sun.star.ucb.HierarchyDataReadWriteAccess"
      54             : 
      55             : #define CONFIG_READ_SERVICE_NAME      \
      56             :                         "com.sun.star.configuration.ConfigurationAccess"
      57             : #define CONFIG_READWRITE_SERVICE_NAME \
      58             :                         "com.sun.star.configuration.ConfigurationUpdateAccess"
      59             : #define CONFIG_DATA_ROOT_KEY          \
      60             :                         "/org.openoffice.ucb.Hierarchy/Root"
      61             : 
      62             : //=========================================================================
      63             : 
      64             : namespace hcp_impl
      65             : {
      66             : 
      67             : //=========================================================================
      68             : //
      69             : // HierarchyDataReadAccess Implementation.
      70             : //
      71             : //=========================================================================
      72             : 
      73             : class HierarchyDataAccess : public cppu::OWeakObject,
      74             :                             public lang::XServiceInfo,
      75             :                             public lang::XTypeProvider,
      76             :                             public lang::XComponent,
      77             :                             public lang::XSingleServiceFactory,
      78             :                             public container::XHierarchicalNameAccess,
      79             :                             public container::XNameContainer,
      80             :                             public util::XChangesNotifier,
      81             :                             public util::XChangesBatch
      82             : {
      83             :     osl::Mutex m_aMutex;
      84             :     uno::Reference< uno::XInterface > m_xConfigAccess;
      85             :     uno::Reference< lang::XComponent >                   m_xCfgC;
      86             :     uno::Reference< lang::XSingleServiceFactory >        m_xCfgSSF;
      87             :     uno::Reference< container::XHierarchicalNameAccess > m_xCfgHNA;
      88             :     uno::Reference< container::XNameContainer >          m_xCfgNC;
      89             :     uno::Reference< container::XNameReplace >            m_xCfgNR;
      90             :     uno::Reference< container::XNameAccess >             m_xCfgNA;
      91             :     uno::Reference< container::XElementAccess >          m_xCfgEA;
      92             :     uno::Reference< util::XChangesNotifier >             m_xCfgCN;
      93             :     uno::Reference< util::XChangesBatch >                m_xCfgCB;
      94             :     bool m_bReadOnly;
      95             : 
      96             : public:
      97             :     HierarchyDataAccess( const uno::Reference<
      98             :                                         uno::XInterface > & xConfigAccess,
      99             :                          bool bReadOnly );
     100             :     virtual ~HierarchyDataAccess();
     101             : 
     102             :     // XInterface
     103             :     XINTERFACE_DECL()
     104             : 
     105             :     // XServiceInfo
     106             :     XSERVICEINFO_DECL()
     107             : 
     108             :     // XTypeProvider
     109             :     XTYPEPROVIDER_DECL()
     110             : 
     111             :     // XComponent
     112             :     virtual void SAL_CALL
     113             :     dispose()
     114             :         throw ( uno::RuntimeException );
     115             :     virtual void SAL_CALL
     116             :     addEventListener( const uno::Reference< lang::XEventListener > & xListener )
     117             :         throw ( uno::RuntimeException );
     118             :     virtual void SAL_CALL
     119             :     removeEventListener( const uno::Reference<
     120             :                             lang::XEventListener > & aListener )
     121             :         throw ( uno::RuntimeException );
     122             : 
     123             :     // XSingleServiceFactory
     124             :     virtual uno::Reference< uno::XInterface > SAL_CALL
     125             :     createInstance()
     126             :         throw ( uno::Exception, uno::RuntimeException );
     127             :     virtual uno::Reference< uno::XInterface > SAL_CALL
     128             :     createInstanceWithArguments( const uno::Sequence< uno::Any > & aArguments )
     129             :         throw ( uno::Exception, uno::RuntimeException );
     130             : 
     131             :     // XHierarchicalNameAccess
     132             :     virtual uno::Any SAL_CALL
     133             :     getByHierarchicalName( const rtl::OUString & aName )
     134             :         throw ( container::NoSuchElementException, uno::RuntimeException );
     135             :     virtual sal_Bool SAL_CALL
     136             :     hasByHierarchicalName( const rtl::OUString & aName )
     137             :         throw ( uno::RuntimeException );
     138             : 
     139             :     // XNameContainer
     140             :     virtual void SAL_CALL
     141             :     insertByName( const rtl::OUString & aName, const uno::Any & aElement )
     142             :         throw ( lang::IllegalArgumentException,
     143             :                 container::ElementExistException,
     144             :                 lang::WrappedTargetException,
     145             :                 uno::RuntimeException );
     146             :     virtual void SAL_CALL
     147             :     removeByName( const rtl::OUString & Name )
     148             :         throw ( container::NoSuchElementException,
     149             :                 lang::WrappedTargetException,
     150             :                 uno::RuntimeException );
     151             : 
     152             :     // XNameReplace ( base of XNameContainer )
     153             :     virtual void SAL_CALL
     154             :     replaceByName( const rtl::OUString & aName, const uno::Any & aElement )
     155             :         throw ( lang::IllegalArgumentException,
     156             :                 container::NoSuchElementException,
     157             :                 lang::WrappedTargetException,
     158             :                 uno::RuntimeException );
     159             : 
     160             :     // XNameAccess ( base of XNameReplace )
     161             :     virtual uno::Any SAL_CALL
     162             :     getByName( const rtl::OUString & aName )
     163             :         throw ( container::NoSuchElementException,
     164             :                 lang::WrappedTargetException,
     165             :                 uno::RuntimeException );
     166             :     virtual uno::Sequence< rtl::OUString > SAL_CALL
     167             :     getElementNames()
     168             :         throw ( uno::RuntimeException );
     169             :     virtual sal_Bool SAL_CALL
     170             :     hasByName( const rtl::OUString & aName )
     171             :         throw ( uno::RuntimeException );
     172             : 
     173             :     // XElementAccess ( base of XNameAccess )
     174             :     virtual uno::Type SAL_CALL
     175             :     getElementType()
     176             :         throw ( uno::RuntimeException );
     177             :     virtual sal_Bool SAL_CALL
     178             :     hasElements()
     179             :         throw ( uno::RuntimeException );
     180             : 
     181             :     // XChangesNotifier
     182             :     virtual void SAL_CALL
     183             :     addChangesListener( const uno::Reference<
     184             :                             util::XChangesListener > & aListener )
     185             :         throw ( uno::RuntimeException );
     186             :     virtual void SAL_CALL
     187             :     removeChangesListener( const uno::Reference<
     188             :                             util::XChangesListener > & aListener )
     189             :         throw ( uno::RuntimeException );
     190             : 
     191             :     // XChangesBatch
     192             :     virtual void SAL_CALL
     193             :     commitChanges()
     194             :         throw ( lang::WrappedTargetException, uno::RuntimeException );
     195             :     virtual sal_Bool SAL_CALL
     196             :     hasPendingChanges()
     197             :         throw ( uno::RuntimeException );
     198             :     virtual uno::Sequence< util::ElementChange > SAL_CALL
     199             :     getPendingChanges()
     200             :         throw ( uno::RuntimeException );
     201             : };
     202             : 
     203             : } // namespace hcp_impl
     204             : 
     205             : using namespace hcp_impl;
     206             : 
     207             : //=========================================================================
     208             : //=========================================================================
     209             : //
     210             : // HierarchyDataSource Implementation.
     211             : //
     212             : //=========================================================================
     213             : //=========================================================================
     214             : 
     215           0 : HierarchyDataSource::HierarchyDataSource(
     216             :         const uno::Reference< uno::XComponentContext > & rxContext )
     217             : : m_xContext( rxContext ),
     218           0 :   m_pDisposeEventListeners( 0 )
     219             : {
     220           0 : }
     221             : 
     222             : //=========================================================================
     223             : // virtual
     224           0 : HierarchyDataSource::~HierarchyDataSource()
     225             : {
     226           0 :     delete m_pDisposeEventListeners;
     227           0 : }
     228             : 
     229             : //=========================================================================
     230             : //
     231             : // XInterface methods.
     232             : //
     233             : //=========================================================================
     234             : 
     235           0 : XINTERFACE_IMPL_4( HierarchyDataSource,
     236             :                    lang::XTypeProvider,
     237             :                    lang::XServiceInfo,
     238             :                    lang::XComponent,
     239             :                    lang::XMultiServiceFactory );
     240             : 
     241             : //=========================================================================
     242             : //
     243             : // XTypeProvider methods.
     244             : //
     245             : //=========================================================================
     246             : 
     247           0 : XTYPEPROVIDER_IMPL_4( HierarchyDataSource,
     248             :                       lang::XTypeProvider,
     249             :                       lang::XServiceInfo,
     250             :                       lang::XComponent,
     251             :                       lang::XMultiServiceFactory );
     252             : 
     253             : //=========================================================================
     254             : //
     255             : // XServiceInfo methods.
     256             : //
     257             : //=========================================================================
     258             : 
     259           0 : XSERVICEINFO_IMPL_0_CTX( HierarchyDataSource,
     260           0 :                      rtl::OUString( "com.sun.star.comp.ucb.HierarchyDataSource" ) )
     261             : {
     262           0 :     uno::Sequence< rtl::OUString > aSNS( 2 );
     263           0 :     aSNS[ 0 ] = rtl::OUString( "com.sun.star.ucb.DefaultHierarchyDataSource" );
     264           0 :     aSNS[ 1 ] = rtl::OUString( "com.sun.star.ucb.HierarchyDataSource" );
     265           0 :     return aSNS;
     266             : }
     267             : 
     268           0 : ONE_INSTANCE_SERVICE_FACTORY_IMPL( HierarchyDataSource );
     269             : 
     270             : //=========================================================================
     271             : //
     272             : // XComponent methods.
     273             : //
     274             : //=========================================================================
     275             : 
     276             : // virtual
     277           0 : void SAL_CALL HierarchyDataSource::dispose()
     278             :     throw( uno::RuntimeException )
     279             : {
     280           0 :     osl::Guard< osl::Mutex > aGuard( m_aMutex );
     281             : 
     282           0 :     if ( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() )
     283             :     {
     284           0 :         lang::EventObject aEvt;
     285           0 :         aEvt.Source = static_cast< lang::XComponent * >( this );
     286           0 :         m_pDisposeEventListeners->disposeAndClear( aEvt );
     287           0 :     }
     288           0 : }
     289             : 
     290             : //=========================================================================
     291             : // virtual
     292           0 : void SAL_CALL HierarchyDataSource::addEventListener(
     293             :                     const uno::Reference< lang::XEventListener > & Listener )
     294             :     throw( uno::RuntimeException )
     295             : {
     296           0 :     osl::Guard< osl::Mutex > aGuard( m_aMutex );
     297             : 
     298           0 :     if ( !m_pDisposeEventListeners )
     299             :         m_pDisposeEventListeners
     300           0 :             = new cppu::OInterfaceContainerHelper( m_aMutex );
     301             : 
     302           0 :     m_pDisposeEventListeners->addInterface( Listener );
     303           0 : }
     304             : 
     305             : //=========================================================================
     306             : // virtual
     307           0 : void SAL_CALL HierarchyDataSource::removeEventListener(
     308             :                     const uno::Reference< lang::XEventListener > & Listener )
     309             :     throw( uno::RuntimeException )
     310             : {
     311           0 :     osl::Guard< osl::Mutex > aGuard( m_aMutex );
     312             : 
     313           0 :     if ( m_pDisposeEventListeners )
     314           0 :         m_pDisposeEventListeners->removeInterface( Listener );
     315           0 : }
     316             : 
     317             : //=========================================================================
     318             : //
     319             : // XMultiServiceFactory methods.
     320             : //
     321             : //=========================================================================
     322             : 
     323             : // virtual
     324             : uno::Reference< uno::XInterface > SAL_CALL
     325           0 : HierarchyDataSource::createInstance( const rtl::OUString & aServiceSpecifier )
     326             :     throw ( uno::Exception, uno::RuntimeException )
     327             : {
     328             :     // Create view to root node.
     329             : 
     330           0 :     beans::PropertyValue aProp;
     331           0 :     aProp.Name = rtl::OUString( CFGPROPERTY_NODEPATH  );
     332           0 :     aProp.Value <<= rtl::OUString( CONFIG_DATA_ROOT_KEY  );
     333             : 
     334           0 :     uno::Sequence< uno::Any > aArguments( 1 );
     335           0 :     aArguments[ 0 ] <<= aProp;
     336             : 
     337           0 :     return createInstanceWithArguments( aServiceSpecifier, aArguments, false );
     338             : }
     339             : 
     340             : //=========================================================================
     341             : // virtual
     342             : uno::Reference< uno::XInterface > SAL_CALL
     343           0 : HierarchyDataSource::createInstanceWithArguments(
     344             :                                 const rtl::OUString & ServiceSpecifier,
     345             :                                 const uno::Sequence< uno::Any > & Arguments )
     346             :     throw ( uno::Exception, uno::RuntimeException )
     347             : {
     348           0 :     return createInstanceWithArguments( ServiceSpecifier, Arguments, true );
     349             : }
     350             : 
     351             : //=========================================================================
     352             : // virtual
     353             : uno::Sequence< rtl::OUString > SAL_CALL
     354           0 : HierarchyDataSource::getAvailableServiceNames()
     355             :     throw ( uno::RuntimeException )
     356             : {
     357           0 :     uno::Sequence< rtl::OUString > aNames( 2 );
     358           0 :     aNames[ 0 ] = rtl::OUString( READ_SERVICE_NAME  );
     359           0 :     aNames[ 1 ] = rtl::OUString( READWRITE_SERVICE_NAME  );
     360           0 :     return aNames;
     361             : }
     362             : 
     363             : //=========================================================================
     364             : //
     365             : // Non-interface methods
     366             : //
     367             : //=========================================================================
     368             : 
     369             : uno::Reference< uno::XInterface > SAL_CALL
     370           0 : HierarchyDataSource::createInstanceWithArguments(
     371             :                                 const rtl::OUString & ServiceSpecifier,
     372             :                                 const uno::Sequence< uno::Any > & Arguments,
     373             :                                 bool bCheckArgs )
     374             :     throw ( uno::Exception, uno::RuntimeException )
     375             : {
     376           0 :     osl::Guard< osl::Mutex > aGuard( m_aMutex );
     377             : 
     378             :     // Check service specifier.
     379           0 :     bool bReadOnly  = ServiceSpecifier == READ_SERVICE_NAME;
     380           0 :     bool bReadWrite = !bReadOnly && ServiceSpecifier == READWRITE_SERVICE_NAME;
     381             : 
     382           0 :     if ( !bReadOnly && !bReadWrite )
     383             :     {
     384             :         OSL_FAIL( "HierarchyDataSource::createInstanceWithArguments - "
     385             :                     "Unsupported service specifier!" );
     386           0 :         return uno::Reference< uno::XInterface >();
     387             :     }
     388             : 
     389           0 :     uno::Sequence< uno::Any > aNewArgs( Arguments );
     390             : 
     391           0 :     bool bHasLazyWriteProp = bReadOnly; // property must be added only if
     392             :                                         // a writable view is requested.
     393           0 :     if ( bCheckArgs )
     394             :     {
     395             :         // Check arguments.
     396           0 :         bool bHasNodePath = false;
     397           0 :         sal_Int32 nCount = Arguments.getLength();
     398           0 :         for ( sal_Int32 n = 0; n < nCount; ++n )
     399             :         {
     400           0 :             beans::PropertyValue aProp;
     401           0 :             if ( Arguments[ n ] >>= aProp )
     402             :             {
     403           0 :                 if ( aProp.Name == CFGPROPERTY_NODEPATH )
     404             :                 {
     405           0 :                     rtl::OUString aPath;
     406           0 :                     if ( aProp.Value >>= aPath )
     407             :                     {
     408           0 :                         bHasNodePath = true;
     409             : 
     410             :                         // Create path to data inside the configuration.
     411           0 :                         rtl::OUString aConfigPath;
     412           0 :                         if ( !createConfigPath( aPath, aConfigPath ) )
     413             :                         {
     414             :                             OSL_FAIL( "HierarchyDataSource::"
     415             :                                 "createInstanceWithArguments - "
     416             :                                 "Invalid node path!" );
     417           0 :                             return uno::Reference< uno::XInterface >();
     418             :                         }
     419             : 
     420           0 :                         aProp.Value <<= aConfigPath;
     421             : 
     422             :                         // Set new path in arguments.
     423           0 :                         aNewArgs[ n ] <<= aProp;
     424             : 
     425           0 :                         if ( bHasLazyWriteProp )
     426           0 :                             break;
     427             :                     }
     428             :                     else
     429             :                     {
     430             :                         OSL_FAIL( "HierarchyDataSource::createInstanceWithArguments - "
     431             :                             "Invalid type for property 'nodepath'!" );
     432           0 :                         return uno::Reference< uno::XInterface >();
     433           0 :                     }
     434             :                 }
     435           0 :                 else if ( aProp.Name == CFGPROPERTY_LAZYWRITE )
     436             :                 {
     437           0 :                     if ( aProp.Value.getValueType() == getCppuBooleanType() )
     438             :                     {
     439           0 :                         bHasLazyWriteProp = true;
     440             : 
     441           0 :                         if ( bHasNodePath )
     442             :                             break;
     443             :                     }
     444             :                     else
     445             :                     {
     446             :                         OSL_FAIL( "HierarchyDataSource::createInstanceWithArguments - "
     447             :                             "Invalid type for property 'lazywrite'!" );
     448           0 :                         return uno::Reference< uno::XInterface >();
     449             :                     }
     450             :                 }
     451             :             }
     452           0 :         }
     453             : 
     454           0 :         if ( !bHasNodePath )
     455             :         {
     456             :             OSL_FAIL( "HierarchyDataSource::createInstanceWithArguments - "
     457             :                         "No 'nodepath' property!" );
     458           0 :             return uno::Reference< uno::XInterface >();
     459             :         }
     460             :     }
     461             : 
     462             :     // Create Configuration Provider.
     463           0 :     uno::Reference< lang::XMultiServiceFactory > xProv = getConfigProvider();
     464           0 :     if ( !xProv.is() )
     465           0 :         return uno::Reference< uno::XInterface >();
     466             : 
     467           0 :     uno::Reference< uno::XInterface > xConfigAccess;
     468             :     try
     469             :     {
     470           0 :         if ( bReadOnly )
     471             :         {
     472             :             // Create configuration read-only access object.
     473           0 :             xConfigAccess = xProv->createInstanceWithArguments(
     474             :                                 rtl::OUString( CONFIG_READ_SERVICE_NAME  ),
     475           0 :                                 aNewArgs );
     476             :         }
     477             :         else
     478             :         {
     479             :             // Append 'lazywrite' property value, if not already present.
     480           0 :             if ( !bHasLazyWriteProp )
     481             :             {
     482           0 :                 sal_Int32 nLen = aNewArgs.getLength();
     483           0 :                 aNewArgs.realloc( nLen + 1 );
     484             : 
     485           0 :                 beans::PropertyValue aProp;
     486           0 :                 aProp.Name = rtl::OUString( CFGPROPERTY_LAZYWRITE  );
     487           0 :                 aProp.Value <<= sal_True;
     488           0 :                 aNewArgs[ nLen ] <<= aProp;
     489             :             }
     490             : 
     491             :             // Create configuration read-write access object.
     492           0 :             xConfigAccess = xProv->createInstanceWithArguments(
     493             :                                 rtl::OUString( CONFIG_READWRITE_SERVICE_NAME  ),
     494           0 :                                 aNewArgs );
     495             :         }
     496             :     }
     497           0 :     catch ( uno::Exception const & )
     498             :     {
     499             :         OSL_FAIL( "HierarchyDataSource::createInstanceWithArguments - "
     500             :                     "Cannot instanciate configuration access!" );
     501           0 :         throw;
     502             :     }
     503             : 
     504           0 :     if ( !xConfigAccess.is() )
     505             :     {
     506             :         OSL_FAIL( "HierarchyDataSource::createInstanceWithArguments - "
     507             :                     "Cannot instanciate configuration access!" );
     508           0 :         return xConfigAccess;
     509             :     }
     510             : 
     511             :     return uno::Reference< uno::XInterface >(
     512             :                 static_cast< cppu::OWeakObject * >(
     513           0 :                     new HierarchyDataAccess( xConfigAccess, bReadOnly ) ) );
     514             : }
     515             : 
     516             : //=========================================================================
     517             : uno::Reference< lang::XMultiServiceFactory >
     518           0 : HierarchyDataSource::getConfigProvider()
     519             : {
     520           0 :     if ( !m_xConfigProvider.is() )
     521             :     {
     522           0 :         osl::Guard< osl::Mutex > aGuard( m_aMutex );
     523           0 :         if ( !m_xConfigProvider.is() )
     524             :         {
     525             :             try
     526             :             {
     527           0 :                 m_xConfigProvider = configuration::theDefaultProvider::get( m_xContext );
     528             :             }
     529           0 :             catch ( uno::Exception const & )
     530             :             {
     531             :                 OSL_FAIL( "HierarchyDataSource::getConfigProvider - "
     532             :                                "caught exception!" );
     533             :             }
     534           0 :         }
     535             :     }
     536             : 
     537           0 :     return m_xConfigProvider;
     538             : }
     539             : 
     540             : //=========================================================================
     541           0 : bool HierarchyDataSource::createConfigPath(
     542             :                 const rtl::OUString & rInPath, rtl::OUString & rOutPath )
     543             : {
     544           0 :     if ( !rInPath.isEmpty() )
     545             :     {
     546           0 :         if ( rInPath.indexOf( '/' ) == 0 )
     547             :         {
     548             :             OSL_FAIL( "HierarchyDataSource::createConfigPath - "
     549             :                         "Leading slash in node path!" );
     550           0 :             return false;
     551             :         }
     552             : 
     553           0 :         if ( rInPath.lastIndexOf( '/' ) == rInPath.getLength() - 1 )
     554             :         {
     555             :             OSL_FAIL( "HierarchyDataSource::createConfigPath - "
     556             :                         "Trailing slash in node path!" );
     557           0 :             return false;
     558             :         }
     559             : 
     560             :         rtl::OUString aOutPath(
     561           0 :                  CONFIG_DATA_ROOT_KEY "/"  );
     562           0 :         aOutPath += rInPath;
     563           0 :         rOutPath = aOutPath;
     564             :     }
     565             :     else
     566             :     {
     567           0 :         rOutPath = rtl::OUString( CONFIG_DATA_ROOT_KEY  );
     568             :     }
     569             : 
     570           0 :     return true;
     571             : }
     572             : 
     573             : //=========================================================================
     574             : //=========================================================================
     575             : //
     576             : // HierarchyDataAccess Implementation.
     577             : //
     578             : //=========================================================================
     579             : //=========================================================================
     580             : 
     581             : #define ENSURE_ORIG_INTERFACE( interface_name, member_name )    \
     582             :     m_xCfg##member_name;                                        \
     583             :     if ( !m_xCfg##member_name.is() )                            \
     584             :     {                                                           \
     585             :         osl::Guard< osl::Mutex > aGuard( m_aMutex );            \
     586             :         if ( !m_xCfg##member_name.is() )                        \
     587             :             m_xCfg##member_name                                 \
     588             :                 = uno::Reference< interface_name >(             \
     589             :                     m_xConfigAccess, uno::UNO_QUERY );          \
     590             :         xOrig = m_xCfg##member_name;                            \
     591             :     }
     592             : 
     593             : //=========================================================================
     594           0 : HierarchyDataAccess::HierarchyDataAccess( const uno::Reference<
     595             :                                             uno::XInterface > & xConfigAccess,
     596             :                                           bool bReadOnly )
     597             : : m_xConfigAccess( xConfigAccess ),
     598           0 :   m_bReadOnly( bReadOnly )
     599             : {
     600           0 : }
     601             : 
     602             : //=========================================================================
     603             : // virtual
     604           0 : HierarchyDataAccess::~HierarchyDataAccess()
     605             : {
     606           0 : }
     607             : 
     608             : //=========================================================================
     609             : //
     610             : // XInterface methods.
     611             : //
     612             : //=========================================================================
     613             : 
     614           0 : XINTERFACE_COMMON_IMPL( HierarchyDataAccess );
     615             : 
     616             : //=========================================================================
     617             : // virtual
     618           0 : uno::Any SAL_CALL HierarchyDataAccess::queryInterface( const uno::Type & aType )
     619             :     throw ( uno::RuntimeException )
     620             : {
     621             :     // Interfaces supported in read-only and read-write mode.
     622             :     uno::Any aRet = cppu::queryInterface( aType,
     623             :                 static_cast< lang::XTypeProvider * >( this ),
     624             :                 static_cast< lang::XServiceInfo * >( this ),
     625             :                 static_cast< lang::XComponent * >( this ),
     626             :                 static_cast< container::XHierarchicalNameAccess * >( this ),
     627             :                 static_cast< container::XNameAccess * >( this ),
     628             :                 static_cast< container::XElementAccess * >( this ),
     629           0 :                 static_cast< util::XChangesNotifier * >( this ) );
     630             : 
     631             :     // Interfaces supported only in read-write mode.
     632           0 :     if ( !aRet.hasValue() && !m_bReadOnly )
     633             :     {
     634             :         aRet = cppu::queryInterface( aType,
     635             :                 static_cast< lang::XSingleServiceFactory * >( this ),
     636             :                 static_cast< container::XNameContainer * >( this ),
     637             :                 static_cast< container::XNameReplace * >( this ),
     638           0 :                 static_cast< util::XChangesBatch * >( this ) );
     639             :     }
     640             : 
     641           0 :     return aRet.hasValue() ? aRet : OWeakObject::queryInterface( aType );
     642             : }
     643             : 
     644             : //=========================================================================
     645             : //
     646             : // XTypeProvider methods.
     647             : //
     648             : //=========================================================================
     649             : 
     650           0 : XTYPEPROVIDER_COMMON_IMPL( HierarchyDataAccess );
     651             : 
     652             : //=========================================================================
     653             : // virtual
     654           0 : uno::Sequence< uno::Type > SAL_CALL HierarchyDataAccess::getTypes()
     655             :     throw( uno::RuntimeException )
     656             : {
     657           0 :     cppu::OTypeCollection * pCollection = 0;
     658             : 
     659           0 :     if ( m_bReadOnly )
     660             :     {
     661             :         static cppu::OTypeCollection* pReadOnlyTypes = 0;
     662             : 
     663           0 :         pCollection = pReadOnlyTypes;
     664           0 :         if ( !pCollection )
     665             :         {
     666           0 :             osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
     667             : 
     668           0 :             pCollection = pReadOnlyTypes;
     669           0 :             if ( !pCollection )
     670             :             {
     671             :                 static cppu::OTypeCollection aCollection(
     672           0 :                     CPPU_TYPE_REF( lang::XTypeProvider ),
     673           0 :                     CPPU_TYPE_REF( lang::XServiceInfo ),
     674           0 :                     CPPU_TYPE_REF( lang::XComponent ),
     675           0 :                     CPPU_TYPE_REF( container::XHierarchicalNameAccess ),
     676           0 :                     CPPU_TYPE_REF( container::XNameAccess ),
     677           0 :                     CPPU_TYPE_REF( util::XChangesNotifier ) );
     678           0 :                 pCollection = &aCollection;
     679             :                 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
     680           0 :                 pReadOnlyTypes = pCollection;
     681           0 :             }
     682             :         }
     683             :         else {
     684             :             OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
     685             :         }
     686             :     }
     687             :     else
     688             :     {
     689             :         static cppu::OTypeCollection* pReadWriteTypes = 0;
     690             : 
     691           0 :         pCollection = pReadWriteTypes;
     692           0 :         if ( !pCollection )
     693             :         {
     694           0 :             osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
     695             : 
     696           0 :             pCollection = pReadWriteTypes;
     697           0 :             if ( !pCollection )
     698             :             {
     699             :                 static cppu::OTypeCollection aCollection(
     700           0 :                     CPPU_TYPE_REF( lang::XTypeProvider ),
     701           0 :                     CPPU_TYPE_REF( lang::XServiceInfo ),
     702           0 :                     CPPU_TYPE_REF( lang::XComponent ),
     703           0 :                     CPPU_TYPE_REF( lang::XSingleServiceFactory ),
     704           0 :                     CPPU_TYPE_REF( container::XHierarchicalNameAccess ),
     705           0 :                     CPPU_TYPE_REF( container::XNameContainer ),
     706           0 :                     CPPU_TYPE_REF( util::XChangesBatch ),
     707           0 :                     CPPU_TYPE_REF( util::XChangesNotifier ) );
     708           0 :                 pCollection = &aCollection;
     709             :                 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
     710           0 :                 pReadWriteTypes = pCollection;
     711           0 :             }
     712             :         }
     713             :         else {
     714             :             OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
     715             :         }
     716             :     }
     717             : 
     718           0 :     return (*pCollection).getTypes();
     719             : }
     720             : 
     721             : //=========================================================================
     722             : //
     723             : // XServiceInfo methods.
     724             : //
     725             : //=========================================================================
     726             : 
     727           0 : XSERVICEINFO_NOFACTORY_IMPL_0(
     728             :         HierarchyDataAccess,
     729             :         rtl::OUString( "com.sun.star.comp.ucb.HierarchyDataAccess"  ) )
     730             : {
     731           0 :     uno::Sequence< rtl::OUString > aSNS( 2 );
     732           0 :     aSNS[ 0 ] = rtl::OUString( READ_SERVICE_NAME  );
     733           0 :     aSNS[ 1 ] = rtl::OUString( READWRITE_SERVICE_NAME  );
     734           0 :     return aSNS;
     735             : }
     736             : 
     737             : //=========================================================================
     738             : //
     739             : // XComponent methods.
     740             : //
     741             : //=========================================================================
     742             : 
     743             : // virtual
     744           0 : void SAL_CALL HierarchyDataAccess::dispose()
     745             :     throw ( uno::RuntimeException )
     746             : {
     747             :     uno::Reference< lang::XComponent > xOrig
     748           0 :         = ENSURE_ORIG_INTERFACE( lang::XComponent, C );
     749             : 
     750             :     OSL_ENSURE( xOrig.is(),
     751             :                 "HierarchyDataAccess : Data source is not an XComponent!" );
     752           0 :     xOrig->dispose();
     753           0 : }
     754             : 
     755             : //=========================================================================
     756             : // virtual
     757           0 : void SAL_CALL HierarchyDataAccess::addEventListener(
     758             :                     const uno::Reference< lang::XEventListener > & xListener )
     759             :     throw ( uno::RuntimeException )
     760             : {
     761             :     uno::Reference< lang::XComponent > xOrig
     762           0 :         = ENSURE_ORIG_INTERFACE( lang::XComponent, C );
     763             : 
     764             :     OSL_ENSURE( xOrig.is(),
     765             :                 "HierarchyDataAccess : Data source is not an XComponent!" );
     766           0 :     xOrig->addEventListener( xListener );
     767           0 : }
     768             : 
     769             : //=========================================================================
     770             : // virtual
     771           0 : void SAL_CALL HierarchyDataAccess::removeEventListener(
     772             :                     const uno::Reference< lang::XEventListener > & aListener )
     773             :     throw ( uno::RuntimeException )
     774             : {
     775             :     uno::Reference< lang::XComponent > xOrig
     776           0 :         = ENSURE_ORIG_INTERFACE( lang::XComponent, C );
     777             : 
     778             :     OSL_ENSURE( xOrig.is(),
     779             :                 "HierarchyDataAccess : Data source is not an XComponent!" );
     780           0 :     xOrig->removeEventListener( aListener );
     781           0 : }
     782             : 
     783             : //=========================================================================
     784             : //
     785             : // XHierarchicalNameAccess methods.
     786             : //
     787             : //=========================================================================
     788             : 
     789             : // virtual
     790           0 : uno::Any SAL_CALL HierarchyDataAccess::getByHierarchicalName(
     791             :                                                 const rtl::OUString & aName )
     792             :     throw ( container::NoSuchElementException, uno::RuntimeException )
     793             : {
     794             :     uno::Reference< container::XHierarchicalNameAccess > xOrig
     795           0 :         = ENSURE_ORIG_INTERFACE( container::XHierarchicalNameAccess, HNA );
     796             : 
     797             :     OSL_ENSURE( xOrig.is(),
     798             :                 "HierarchyDataAccess : "
     799             :                 "Data source is not an XHierarchicalNameAccess!" );
     800           0 :     return xOrig->getByHierarchicalName( aName );
     801             : }
     802             : 
     803             : //=========================================================================
     804             : // virtual
     805           0 : sal_Bool SAL_CALL HierarchyDataAccess::hasByHierarchicalName(
     806             :                                                 const rtl::OUString & aName )
     807             :     throw ( uno::RuntimeException )
     808             : {
     809             :     uno::Reference< container::XHierarchicalNameAccess > xOrig
     810           0 :         = ENSURE_ORIG_INTERFACE( container::XHierarchicalNameAccess, HNA );
     811             : 
     812             :     OSL_ENSURE( xOrig.is(),
     813             :                 "HierarchyDataAccess : "
     814             :                 "Data source is not an XHierarchicalNameAccess!" );
     815           0 :     return xOrig->hasByHierarchicalName( aName );
     816             : }
     817             : 
     818             : //=========================================================================
     819             : //
     820             : // XNameAccess methods.
     821             : //
     822             : //=========================================================================
     823             : 
     824             : // virtual
     825           0 : uno::Any SAL_CALL HierarchyDataAccess::getByName( const rtl::OUString & aName )
     826             :     throw ( container::NoSuchElementException,
     827             :             lang::WrappedTargetException,
     828             :             uno::RuntimeException )
     829             : {
     830             :     uno::Reference< container::XNameAccess > xOrig
     831           0 :         = ENSURE_ORIG_INTERFACE( container::XNameAccess, NA );
     832             : 
     833             :     OSL_ENSURE( xOrig.is(),
     834             :                 "HierarchyDataAccess : Data source is not an XNameAccess!" );
     835           0 :     return xOrig->getByName( aName );
     836             : }
     837             : 
     838             : //=========================================================================
     839             : // virtual
     840           0 : uno::Sequence< rtl::OUString > SAL_CALL HierarchyDataAccess::getElementNames()
     841             :     throw ( uno::RuntimeException )
     842             : {
     843             :     uno::Reference< container::XNameAccess > xOrig
     844           0 :         = ENSURE_ORIG_INTERFACE( container::XNameAccess, NA );
     845             : 
     846             :     OSL_ENSURE( xOrig.is(),
     847             :                 "HierarchyDataAccess : Data source is not an XNameAccess!" );
     848           0 :     return xOrig->getElementNames();
     849             : }
     850             : 
     851             : //=========================================================================
     852             : // virtual
     853           0 : sal_Bool SAL_CALL HierarchyDataAccess::hasByName( const rtl::OUString & aName )
     854             :     throw ( uno::RuntimeException )
     855             : {
     856             :     uno::Reference< container::XNameAccess > xOrig
     857           0 :         = ENSURE_ORIG_INTERFACE( container::XNameAccess, NA );
     858             : 
     859             :     OSL_ENSURE( xOrig.is(),
     860             :                 "HierarchyDataAccess : Data source is not an XNameAccess!" );
     861           0 :     return xOrig->hasByName( aName );
     862             : }
     863             : 
     864             : //=========================================================================
     865             : //
     866             : // XElementAccess methods.
     867             : //
     868             : //=========================================================================
     869             : 
     870             : // virtual
     871           0 : uno::Type SAL_CALL HierarchyDataAccess::getElementType()
     872             :     throw ( uno::RuntimeException )
     873             : {
     874             :     uno::Reference< container::XElementAccess > xOrig
     875           0 :         = ENSURE_ORIG_INTERFACE( container::XElementAccess, EA );
     876             : 
     877             :     OSL_ENSURE( xOrig.is(),
     878             :                 "HierarchyDataAccess : Data source is not an XElementAccess!" );
     879           0 :     return xOrig->getElementType();
     880             : }
     881             : 
     882             : //=========================================================================
     883             : // virtual
     884           0 : sal_Bool SAL_CALL HierarchyDataAccess::hasElements()
     885             :     throw ( uno::RuntimeException )
     886             : {
     887             :     uno::Reference< container::XElementAccess > xOrig
     888           0 :         = ENSURE_ORIG_INTERFACE( container::XElementAccess, EA );
     889             : 
     890             :     OSL_ENSURE( xOrig.is(),
     891             :                 "HierarchyDataAccess : Data source is not an XElementAccess!" );
     892           0 :     return xOrig->hasElements();
     893             : }
     894             : 
     895             : //=========================================================================
     896             : //
     897             : // XChangesNotifier methods.
     898             : //
     899             : //=========================================================================
     900             : 
     901             : // virtual
     902           0 : void SAL_CALL HierarchyDataAccess::addChangesListener(
     903             :                 const uno::Reference< util::XChangesListener > & aListener )
     904             :     throw ( uno::RuntimeException )
     905             : {
     906             :     uno::Reference< util::XChangesNotifier > xOrig
     907           0 :         = ENSURE_ORIG_INTERFACE( util::XChangesNotifier, CN );
     908             : 
     909             :     OSL_ENSURE( xOrig.is(),
     910             :             "HierarchyDataAccess : Data source is not an XChangesNotifier!" );
     911           0 :     xOrig->addChangesListener( aListener );
     912           0 : }
     913             : 
     914             : //=========================================================================
     915             : // virtual
     916           0 : void SAL_CALL HierarchyDataAccess::removeChangesListener(
     917             :                 const uno::Reference< util::XChangesListener > & aListener )
     918             :     throw ( uno::RuntimeException )
     919             : {
     920             :     uno::Reference< util::XChangesNotifier > xOrig
     921           0 :         = ENSURE_ORIG_INTERFACE( util::XChangesNotifier, CN );
     922             : 
     923             :     OSL_ENSURE( xOrig.is(),
     924             :             "HierarchyDataAccess : Data source is not an XChangesNotifier!" );
     925           0 :     xOrig->removeChangesListener( aListener );
     926           0 : }
     927             : 
     928             : //=========================================================================
     929             : //
     930             : // XSingleServiceFactory methods.
     931             : //
     932             : //=========================================================================
     933             : 
     934             : // virtual
     935           0 : uno::Reference< uno::XInterface > SAL_CALL HierarchyDataAccess::createInstance()
     936             :     throw ( uno::Exception, uno::RuntimeException )
     937             : {
     938             :     uno::Reference< lang::XSingleServiceFactory > xOrig
     939           0 :         = ENSURE_ORIG_INTERFACE( lang::XSingleServiceFactory, SSF );
     940             : 
     941             :     OSL_ENSURE( xOrig.is(),
     942             :         "HierarchyDataAccess : Data source is not an XSingleServiceFactory!" );
     943           0 :     return xOrig->createInstance();
     944             : }
     945             : 
     946             : //=========================================================================
     947             : // virtual
     948             : uno::Reference< uno::XInterface > SAL_CALL
     949           0 : HierarchyDataAccess::createInstanceWithArguments(
     950             :                             const uno::Sequence< uno::Any > & aArguments )
     951             :     throw ( uno::Exception, uno::RuntimeException )
     952             : {
     953             :     uno::Reference< lang::XSingleServiceFactory > xOrig
     954           0 :         = ENSURE_ORIG_INTERFACE( lang::XSingleServiceFactory, SSF );
     955             : 
     956             :     OSL_ENSURE( xOrig.is(),
     957             :         "HierarchyDataAccess : Data source is not an XSingleServiceFactory!" );
     958           0 :     return xOrig->createInstanceWithArguments( aArguments );
     959             : }
     960             : 
     961             : //=========================================================================
     962             : //
     963             : // XNameContainer methods.
     964             : //
     965             : //=========================================================================
     966             : 
     967             : // virtual
     968             : void SAL_CALL
     969           0 : HierarchyDataAccess::insertByName( const rtl::OUString & aName,
     970             :                                    const uno::Any & aElement )
     971             :     throw ( lang::IllegalArgumentException,
     972             :             container::ElementExistException,
     973             :             lang::WrappedTargetException,
     974             :             uno::RuntimeException )
     975             : {
     976             :     uno::Reference< container::XNameContainer > xOrig
     977           0 :         = ENSURE_ORIG_INTERFACE( container::XNameContainer, NC );
     978             : 
     979             :     OSL_ENSURE( xOrig.is(),
     980             :         "HierarchyDataAccess : Data source is not an XNameContainer!" );
     981           0 :     xOrig->insertByName( aName, aElement );
     982           0 : }
     983             : 
     984             : //=========================================================================
     985             : // virtual
     986             : void SAL_CALL
     987           0 : HierarchyDataAccess::removeByName( const rtl::OUString & Name )
     988             :     throw ( container::NoSuchElementException,
     989             :             lang::WrappedTargetException,
     990             :             uno::RuntimeException )
     991             : {
     992             :     uno::Reference< container::XNameContainer > xOrig
     993           0 :         = ENSURE_ORIG_INTERFACE( container::XNameContainer, NC );
     994             : 
     995             :     OSL_ENSURE( xOrig.is(),
     996             :         "HierarchyDataAccess : Data source is not an XNameContainer!" );
     997           0 :     xOrig->removeByName( Name );
     998           0 : }
     999             : 
    1000             : //=========================================================================
    1001             : //
    1002             : // XNameReplace methods.
    1003             : //
    1004             : //=========================================================================
    1005             : 
    1006             : // virtual
    1007           0 : void SAL_CALL HierarchyDataAccess::replaceByName( const rtl::OUString & aName,
    1008             :                                                   const uno::Any & aElement )
    1009             :     throw ( lang::IllegalArgumentException,
    1010             :             container::NoSuchElementException,
    1011             :             lang::WrappedTargetException,
    1012             :             uno::RuntimeException )
    1013             : {
    1014             :     uno::Reference< container::XNameReplace > xOrig
    1015           0 :         = ENSURE_ORIG_INTERFACE( container::XNameReplace, NR );
    1016             : 
    1017             :     OSL_ENSURE( xOrig.is(),
    1018             :         "HierarchyDataAccess : Data source is not an XNameReplace!" );
    1019           0 :     xOrig->replaceByName( aName, aElement );
    1020           0 : }
    1021             : 
    1022             : //=========================================================================
    1023             : //
    1024             : // XChangesBatch methods.
    1025             : //
    1026             : //=========================================================================
    1027             : 
    1028             : // virtual
    1029           0 : void SAL_CALL HierarchyDataAccess::commitChanges()
    1030             :     throw ( lang::WrappedTargetException, uno::RuntimeException )
    1031             : {
    1032             :     uno::Reference< util::XChangesBatch > xOrig
    1033           0 :         = ENSURE_ORIG_INTERFACE( util::XChangesBatch, CB );
    1034             : 
    1035             :     OSL_ENSURE( xOrig.is(),
    1036             :         "HierarchyDataAccess : Data source is not an XChangesBatch!" );
    1037           0 :     xOrig->commitChanges();
    1038           0 : }
    1039             : 
    1040             : //=========================================================================
    1041             : // virtual
    1042           0 : sal_Bool SAL_CALL HierarchyDataAccess::hasPendingChanges()
    1043             :     throw ( uno::RuntimeException )
    1044             : {
    1045             :     uno::Reference< util::XChangesBatch > xOrig
    1046           0 :         = ENSURE_ORIG_INTERFACE( util::XChangesBatch, CB );
    1047             : 
    1048             :     OSL_ENSURE( xOrig.is(),
    1049             :         "HierarchyDataAccess : Data source is not an XChangesBatch!" );
    1050           0 :     return xOrig->hasPendingChanges();
    1051             : }
    1052             : 
    1053             : //=========================================================================
    1054             : // virtual
    1055             : uno::Sequence< util::ElementChange > SAL_CALL
    1056           0 : HierarchyDataAccess::getPendingChanges()
    1057             :     throw ( uno::RuntimeException )
    1058             : {
    1059             :     uno::Reference< util::XChangesBatch > xOrig
    1060           0 :         = ENSURE_ORIG_INTERFACE( util::XChangesBatch, CB );
    1061             : 
    1062             :     OSL_ENSURE( xOrig.is(),
    1063             :         "HierarchyDataAccess : Data source is not an XChangesBatch!" );
    1064           0 :     return xOrig->getPendingChanges();
    1065             : }
    1066             : 
    1067             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10