diff options
author | Kai Sommerfeld <kso@openoffice.org> | 2000-12-10 14:13:51 +0000 |
---|---|---|
committer | Kai Sommerfeld <kso@openoffice.org> | 2000-12-10 14:13:51 +0000 |
commit | e29ea0257f8d60ffa782ba5cdc5da5c3a626384a (patch) | |
tree | 8b5cf778f69b303bf13fb6bd44c4fc92a876dcc4 /ucb/source | |
parent | 2a4f3dd27bde0e7ba59a64e3b9f3b4647c0aff5d (diff) |
#81540# Service initialization with alternative configuration provider.
Diffstat (limited to 'ucb/source')
-rw-r--r-- | ucb/source/core/ucbstore.cxx | 180 | ||||
-rw-r--r-- | ucb/source/core/ucbstore.hxx | 24 | ||||
-rw-r--r-- | ucb/source/ucp/hierarchy/hierarchycontent.cxx | 30 | ||||
-rw-r--r-- | ucb/source/ucp/hierarchy/hierarchydata.cxx | 86 | ||||
-rw-r--r-- | ucb/source/ucp/hierarchy/hierarchydata.hxx | 10 | ||||
-rw-r--r-- | ucb/source/ucp/hierarchy/hierarchydatasupplier.cxx | 7 | ||||
-rw-r--r-- | ucb/source/ucp/hierarchy/hierarchyprovider.cxx | 102 | ||||
-rw-r--r-- | ucb/source/ucp/hierarchy/hierarchyprovider.hxx | 23 |
8 files changed, 318 insertions, 144 deletions
diff --git a/ucb/source/core/ucbstore.cxx b/ucb/source/core/ucbstore.cxx index 936d0102fab8..d74b236a74e1 100644 --- a/ucb/source/core/ucbstore.cxx +++ b/ucb/source/core/ucbstore.cxx @@ -2,9 +2,9 @@ * * $RCSfile: ucbstore.cxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: kso $ $Date: 2000-12-08 12:24:09 $ + * last change: $Author: kso $ $Date: 2000-12-10 15:13:04 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -191,6 +191,7 @@ public: struct UcbStore_Impl { osl::Mutex m_aMutex; + Sequence< Any > m_aInitArgs; Reference< XPropertySetRegistry > m_xTheRegistry; }; @@ -223,10 +224,11 @@ UcbStore::~UcbStore() // //========================================================================= -XINTERFACE_IMPL_3( UcbStore, +XINTERFACE_IMPL_4( UcbStore, XTypeProvider, XServiceInfo, - XPropertySetRegistryFactory ); + XPropertySetRegistryFactory, + XInitialization ); //========================================================================= // @@ -234,10 +236,11 @@ XINTERFACE_IMPL_3( UcbStore, // //========================================================================= -XTYPEPROVIDER_IMPL_3( UcbStore, +XTYPEPROVIDER_IMPL_4( UcbStore, XTypeProvider, XServiceInfo, - XPropertySetRegistryFactory ); + XPropertySetRegistryFactory, + XInitialization ); //========================================================================= // @@ -282,6 +285,20 @@ UcbStore::createPropertySetRegistry( const OUString& URL ) //========================================================================= // +// XInitialization methods. +// +//========================================================================= + +// virtual +void SAL_CALL UcbStore::initialize( const Sequence< Any >& aArguments ) + throw( Exception, RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + m_pImpl->m_aInitArgs = aArguments; +} + +//========================================================================= +// // New methods. // //========================================================================= @@ -297,6 +314,12 @@ void UcbStore::removeRegistry( const OUString& URL ) } //========================================================================= +const Sequence< Any >& UcbStore::getInitArgs() const +{ + return m_pImpl->m_aInitArgs; +} + +//========================================================================= // // PropertySetRegistry_Impl. // @@ -308,6 +331,7 @@ struct PropertySetRegistry_Impl PropertySetMap_Impl m_aPropSets; Reference< XMultiServiceFactory > m_xConfigProvider; Reference< XInterface > m_xRootReadAccess; + Reference< XInterface > m_xRootWriteAccess; osl::Mutex m_aMutex; PropertySetRegistry_Impl( UcbStore& rCreator ) @@ -1214,6 +1238,56 @@ void PropertySetRegistry::renamePropertySet( const OUString& rOldKey, } //========================================================================= +Reference< XMultiServiceFactory > PropertySetRegistry::getConfigProvider() +{ + if ( !m_pImpl->m_xConfigProvider.is() ) + { + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + if ( !m_pImpl->m_xConfigProvider.is() ) + { + const Sequence< Any >& rInitArgs + = m_pImpl->m_pCreator->getInitArgs(); + + if ( rInitArgs.getLength() > 0 ) + { + // Extract config provider from service init args. + rInitArgs[ 0 ] >>= m_pImpl->m_xConfigProvider; + + OSL_ENSURE( m_pImpl->m_xConfigProvider.is(), + "PropertySetRegistry::getConfigProvider - " + "No config provider!" ); + } + else + { + try + { + m_pImpl->m_xConfigProvider + = Reference< XMultiServiceFactory >( + m_xSMgr->createInstance( + OUString::createFromAscii( + "com.sun.star.configuration." + "ConfigurationProvider" ) ), + UNO_QUERY ); + + OSL_ENSURE( m_pImpl->m_xConfigProvider.is(), + "PropertySetRegistry::getConfigProvider - " + "No config provider!" ); + + } + catch ( Exception& ) + { + OSL_ENSURE( sal_False, + "PropertySetRegistry::getConfigProvider - " + "caught exception!" ); + } + } + } + } + + return m_pImpl->m_xConfigProvider; +} + +//========================================================================= Reference< XInterface > PropertySetRegistry::getRootConfigReadAccess() { try @@ -1222,12 +1296,7 @@ Reference< XInterface > PropertySetRegistry::getRootConfigReadAccess() if ( !m_pImpl->m_xRootReadAccess.is() ) { - if ( !m_pImpl->m_xConfigProvider.is() ) - m_pImpl->m_xConfigProvider = Reference< XMultiServiceFactory >( - m_xSMgr->createInstance( - OUString::createFromAscii( - "com.sun.star.configuration.ConfigurationProvider" ) ), - UNO_QUERY ); + getConfigProvider(); if ( m_pImpl->m_xConfigProvider.is() ) { @@ -1274,48 +1343,67 @@ Reference< XInterface > PropertySetRegistry::getConfigWriteAccess( { osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); - if ( !m_pImpl->m_xConfigProvider.is() ) - m_pImpl->m_xConfigProvider = Reference< XMultiServiceFactory >( - m_xSMgr->createInstance( - OUString::createFromAscii( - "com.sun.star.configuration.ConfigurationProvider" ) ), - UNO_QUERY ); - - if ( m_pImpl->m_xConfigProvider.is() ) + if ( !m_pImpl->m_xRootWriteAccess.is() ) { - OUString aConfigPath - = OUString::createFromAscii( STORE_CONTENTPROPERTIES_KEY ); - if ( rPath.getLength() ) + getConfigProvider(); + + if ( m_pImpl->m_xConfigProvider.is() ) { - if ( rPath.compareToAscii( "/", 1 ) != 0 ) - aConfigPath += OUString::createFromAscii( "/" ); + Sequence< Any > aArguments( 1 ); + aArguments[ 0 ] <<= OUString::createFromAscii( + STORE_CONTENTPROPERTIES_KEY ); - aConfigPath += rPath; - } + m_pImpl->m_xRootWriteAccess = + m_pImpl->m_xConfigProvider->createInstanceWithArguments( + OUString::createFromAscii( + "com.sun.star.configuration.ConfigurationUpdateAccess" ), + aArguments ); - Sequence< Any > aArguments( 1 ); - aArguments[ 0 ] <<= aConfigPath; + OSL_ENSURE( m_pImpl->m_xRootWriteAccess.is(), + "PropertySetRegistry::getConfigWriteAccess - " + "No config update access!" ); + } + } - Reference< XInterface > xInterface( - m_pImpl->m_xConfigProvider->createInstanceWithArguments( - OUString::createFromAscii( - "com.sun.star.configuration.ConfigurationUpdateAccess" ), - aArguments ) ); + if ( m_pImpl->m_xRootWriteAccess.is() ) + { + if ( rPath.getLength() ) + { + Reference< XHierarchicalNameAccess > xNA( + m_pImpl->m_xRootWriteAccess, UNO_QUERY ); + if ( xNA.is() ) + { + Reference< XInterface > xInterface; + xNA->getByHierarchicalName( rPath ) >>= xInterface; - if ( xInterface.is() ) - return xInterface; + if ( xInterface.is() ) + return xInterface; + } + } + else + return m_pImpl->m_xRootWriteAccess; } } catch ( RuntimeException& ) { throw; } + catch ( NoSuchElementException& ) + { + // getByHierarchicalName + + OSL_ENSURE( sal_False, + "PropertySetRegistry::getConfigWriteAccess - " + "caught NoSuchElementException!" ); + return Reference< XInterface >(); + } catch ( Exception& ) { // createInstance, createInstanceWithArguments OSL_ENSURE( sal_False, - "PropertySetRegistry::getConfigWriteAccess - caught Exception!" ); + "PropertySetRegistry::getConfigWriteAccess - " + "caught Exception!" ); return Reference< XInterface >(); } @@ -1562,7 +1650,9 @@ void SAL_CALL PersistentPropertySet::setPropertyValue( Reference< XNameReplace > xNameReplace( m_pImpl->m_pCreator->getConfigWriteAccess( aFullPropName ), UNO_QUERY ); - Reference< XChangesBatch > xBatch( xNameReplace, UNO_QUERY ); + Reference< XChangesBatch > xBatch( + m_pImpl->m_pCreator->getConfigWriteAccess( + OUString() ), UNO_QUERY ); if ( xNameReplace.is() && xBatch.is() ) { @@ -1836,8 +1926,10 @@ void SAL_CALL PersistentPropertySet::addProperty( Reference< XSingleServiceFactory > xFac( m_pImpl->m_pCreator->getConfigWriteAccess( aFullValuesName ), UNO_QUERY ); - Reference< XChangesBatch > xBatch( xFac, UNO_QUERY ); Reference< XNameContainer > xContainer( xFac, UNO_QUERY ); + Reference< XChangesBatch > xBatch( + m_pImpl->m_pCreator->getConfigWriteAccess( OUString() ), + UNO_QUERY ); OSL_ENSURE( xFac.is(), "PersistentPropertySet::addProperty - No factory!" ); @@ -2012,10 +2104,12 @@ void SAL_CALL PersistentPropertySet::removeProperty( const OUString& Name ) // Remove property... - Reference< XChangesBatch > xBatch( + Reference< XNameContainer > xContainer( m_pImpl->m_pCreator->getConfigWriteAccess( aFullValuesName ), UNO_QUERY ); - Reference< XNameContainer > xContainer( xBatch, UNO_QUERY ); + Reference< XChangesBatch > xBatch( + m_pImpl->m_pCreator->getConfigWriteAccess( OUString() ), + UNO_QUERY ); OSL_ENSURE( xBatch.is(), "PersistentPropertySet::removeProperty - No batch!" ); @@ -2325,7 +2419,9 @@ void SAL_CALL PersistentPropertySet::setPropertyValues( Reference< XNameReplace > xNameReplace( m_pImpl->m_pCreator->getConfigWriteAccess( aFullPropName ), UNO_QUERY ); - Reference< XChangesBatch > xBatch( xNameReplace, UNO_QUERY ); + Reference< XChangesBatch > xBatch( + m_pImpl->m_pCreator->getConfigWriteAccess( + OUString() ), UNO_QUERY ); if ( xNameReplace.is() && xBatch.is() ) { diff --git a/ucb/source/core/ucbstore.hxx b/ucb/source/core/ucbstore.hxx index 460a695448c8..500a57ccb464 100644 --- a/ucb/source/core/ucbstore.hxx +++ b/ucb/source/core/ucbstore.hxx @@ -2,9 +2,9 @@ * * $RCSfile: ucbstore.hxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: kso $ $Date: 2000-10-25 06:32:48 $ + * last change: $Author: kso $ $Date: 2000-12-10 15:13:04 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -98,6 +98,9 @@ #ifndef _COM_SUN_STAR_LANG_XCOMPONENT_HPP_ #include <com/sun/star/lang/XComponent.hpp> #endif +#ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_ +#include <com/sun/star/lang/XInitialization.hpp> +#endif #ifndef _CPPUHELPER_WEAK_HXX_ #include <cppuhelper/weak.hxx> @@ -121,7 +124,8 @@ class UcbStore : public cppu::OWeakObject, public com::sun::star::lang::XTypeProvider, public com::sun::star::lang::XServiceInfo, - public com::sun::star::ucb::XPropertySetRegistryFactory + public com::sun::star::ucb::XPropertySetRegistryFactory, + public com::sun::star::lang::XInitialization { com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > m_xSMgr; @@ -148,8 +152,18 @@ public: createPropertySetRegistry( const rtl::OUString& URL ) throw( com::sun::star::uno::RuntimeException ); + // XInitialization + virtual void SAL_CALL + initialize( const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Any >& aArguments ) + throw( ::com::sun::star::uno::Exception, + ::com::sun::star::uno::RuntimeException ); + // New void removeRegistry( const rtl::OUString& URL ); + + const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& + getInitArgs() const; }; //========================================================================= @@ -170,6 +184,9 @@ class PropertySetRegistry : PropertySetRegistry_Impl* m_pImpl; private: + com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > + getConfigProvider(); + void add ( PersistentPropertySet* pSet ); void remove( PersistentPropertySet* pSet ); @@ -227,7 +244,6 @@ public: getRootConfigReadAccess(); com::sun::star::uno::Reference< com::sun::star::uno::XInterface > getConfigWriteAccess( const rtl::OUString& rPath ); - }; //========================================================================= diff --git a/ucb/source/ucp/hierarchy/hierarchycontent.cxx b/ucb/source/ucp/hierarchy/hierarchycontent.cxx index 605929672a5b..20eda31e42f3 100644 --- a/ucb/source/ucp/hierarchy/hierarchycontent.cxx +++ b/ucb/source/ucp/hierarchy/hierarchycontent.cxx @@ -2,9 +2,9 @@ * * $RCSfile: hierarchycontent.cxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: kso $ $Date: 2000-12-08 19:45:23 $ + * last change: $Author: kso $ $Date: 2000-12-10 15:13:51 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -709,8 +709,7 @@ sal_Bool HierarchyContent::hasData( return sal_True; } - HierarchyEntry aEntry( - rxSMgr, pProvider->getRootConfigReadNameAccess(), aURL ); + HierarchyEntry aEntry( rxSMgr, pProvider, aURL ); HierarchyEntryData aData; return aEntry.hasData(); @@ -748,8 +747,7 @@ sal_Bool HierarchyContent::loadData( } else { - HierarchyEntry aEntry( - rxSMgr, pProvider->getRootConfigReadNameAccess(), aURL ); + HierarchyEntry aEntry( rxSMgr, pProvider, aURL ); if ( !aEntry.getData( rProps ) ) return sal_False; @@ -774,9 +772,8 @@ sal_Bool HierarchyContent::loadData( //========================================================================= sal_Bool HierarchyContent::storeData() { - HierarchyEntry aEntry( m_xSMgr, - m_pProvider->getRootConfigReadNameAccess(), - m_xIdentifier->getContentIdentifier() ); + HierarchyEntry aEntry( + m_xSMgr, m_pProvider, m_xIdentifier->getContentIdentifier() ); return aEntry.setData( m_aProps, sal_True ); } @@ -785,18 +782,16 @@ sal_Bool HierarchyContent::renameData( const Reference< XContentIdentifier >& xOldId, const Reference< XContentIdentifier >& xNewId ) { - HierarchyEntry aEntry( m_xSMgr, - m_pProvider->getRootConfigReadNameAccess(), - xOldId->getContentIdentifier() ); + HierarchyEntry aEntry( + m_xSMgr, m_pProvider, xOldId->getContentIdentifier() ); return aEntry.move( xNewId->getContentIdentifier() ); } //========================================================================= sal_Bool HierarchyContent::removeData() { - HierarchyEntry aEntry( m_xSMgr, - m_pProvider->getRootConfigReadNameAccess(), - m_xIdentifier->getContentIdentifier() ); + HierarchyEntry aEntry( + m_xSMgr, m_pProvider, m_xIdentifier->getContentIdentifier() ); return aEntry.remove(); } @@ -1596,9 +1591,8 @@ void HierarchyContent::transfer( const TransferInfo& rInfo ) if ( xSource->isFolder() ) { - HierarchyEntry aFolder( m_xSMgr, - m_pProvider->getRootConfigReadNameAccess(), - xId->getContentIdentifier() ); + HierarchyEntry aFolder( + m_xSMgr, m_pProvider, xId->getContentIdentifier() ); HierarchyEntry::iterator it; while ( aFolder.next( it ) ) diff --git a/ucb/source/ucp/hierarchy/hierarchydata.cxx b/ucb/source/ucp/hierarchy/hierarchydata.cxx index 56f5721c60f6..736e4230e68d 100644 --- a/ucb/source/ucp/hierarchy/hierarchydata.cxx +++ b/ucb/source/ucp/hierarchy/hierarchydata.cxx @@ -2,9 +2,9 @@ * * $RCSfile: hierarchydata.cxx,v $ * - * $Revision: 1.10 $ + * $Revision: 1.11 $ * - * last change: $Author: kso $ $Date: 2000-12-08 19:45:23 $ + * last change: $Author: kso $ $Date: 2000-12-10 15:13:51 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -137,11 +137,16 @@ struct HierarchyEntry::iterator_Impl //========================================================================= HierarchyEntry::HierarchyEntry( const Reference< XMultiServiceFactory >& rSMgr, - const Reference< XHierarchicalNameAccess >& rRootReadAccess, + HierarchyContentProvider* pProvider, const OUString& rURL ) -: m_xSMgr( rSMgr ), - m_xRootReadAccess( rRootReadAccess ) +: m_xSMgr( rSMgr ) { + if ( pProvider ) + { + m_xConfigProvider = pProvider->getConfigProvider(); + m_xRootReadAccess = pProvider->getRootConfigReadNameAccess(); + } + // Note: do not init m_aPath in init list. createPathFromHierarchyURL // needs m_xSMgr and m_aMutex. m_aPath = createPathFromHierarchyURL( rURL ); @@ -1028,53 +1033,52 @@ OUString HierarchyEntry::createPathFromHierarchyURL( const OUString& rURL ) //========================================================================= Reference< XHierarchicalNameAccess > HierarchyEntry::getRootReadAccess() { -#if 0 - - // always set in ctor. - - try + if ( !m_xRootReadAccess.is() ) { osl::Guard< osl::Mutex > aGuard( m_aMutex ); - if ( !m_xRootReadAccess.is() ) { - if ( !m_xConfigProvider.is() ) - m_xConfigProvider = Reference< XMultiServiceFactory >( - m_xSMgr->createInstance( - OUString::createFromAscii( - "com.sun.star.configuration.ConfigurationProvider" ) ), - UNO_QUERY ); - - if ( m_xConfigProvider.is() ) + try { - // Create Root object. + if ( !m_xConfigProvider.is() ) + m_xConfigProvider = Reference< XMultiServiceFactory >( + m_xSMgr->createInstance( + OUString::createFromAscii( + "com.sun.star.configuration." + "ConfigurationProvider" ) ), + UNO_QUERY ); + + if ( m_xConfigProvider.is() ) + { + // Create Root object. - Sequence< Any > aArguments( 1 ); - aArguments[ 0 ] + Sequence< Any > aArguments( 1 ); + aArguments[ 0 ] <<= OUString::createFromAscii( HIERARCHY_ROOT_DB_KEY ); - m_xRootReadAccess = Reference< XHierarchicalNameAccess >( - m_xConfigProvider->createInstanceWithArguments( - OUString::createFromAscii( - "com.sun.star.configuration.ConfigurationAccess" ), - aArguments ), - UNO_QUERY ); + m_xRootReadAccess = Reference< XHierarchicalNameAccess >( + m_xConfigProvider->createInstanceWithArguments( + OUString::createFromAscii( + "com.sun.star.configuration." + "ConfigurationAccess" ), + aArguments ), + UNO_QUERY ); + } } - } - } - catch ( RuntimeException& ) - { - throw; - } - catch ( Exception& ) - { - // createInstance, createInstanceWithArguments + catch ( RuntimeException& ) + { + throw; + } + catch ( Exception& ) + { + // createInstance, createInstanceWithArguments - VOS_ENSURE( sal_False, - "HierarchyEntry::getRootReadAccess - " - "caught Exception!" ); + VOS_ENSURE( sal_False, + "HierarchyEntry::getRootReadAccess - " + "caught Exception!" ); + } + } } -#endif return m_xRootReadAccess; } diff --git a/ucb/source/ucp/hierarchy/hierarchydata.hxx b/ucb/source/ucp/hierarchy/hierarchydata.hxx index e3ed6036b882..68f73492ddc8 100644 --- a/ucb/source/ucp/hierarchy/hierarchydata.hxx +++ b/ucb/source/ucp/hierarchy/hierarchydata.hxx @@ -2,9 +2,9 @@ * * $RCSfile: hierarchydata.hxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: kso $ $Date: 2000-12-08 19:45:23 $ + * last change: $Author: kso $ $Date: 2000-12-10 15:13:51 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -102,6 +102,8 @@ struct HierarchyEntryData //========================================================================= +class HierarchyContentProvider; + class HierarchyEntry { ::rtl::OUString m_aName; @@ -124,9 +126,7 @@ private: public: HierarchyEntry( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rSMgr, - const ::com::sun::star::uno::Reference< - ::com::sun::star::container::XHierarchicalNameAccess >& - rRootReadAccess, + HierarchyContentProvider* pProvider, const ::rtl::OUString& rURL ); sal_Bool hasData(); diff --git a/ucb/source/ucp/hierarchy/hierarchydatasupplier.cxx b/ucb/source/ucp/hierarchy/hierarchydatasupplier.cxx index 0ae536900444..f4cce3e2ae70 100644 --- a/ucb/source/ucp/hierarchy/hierarchydatasupplier.cxx +++ b/ucb/source/ucp/hierarchy/hierarchydatasupplier.cxx @@ -2,9 +2,9 @@ * * $RCSfile: hierarchydatasupplier.cxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: kso $ $Date: 2000-12-08 19:45:23 $ + * last change: $Author: kso $ $Date: 2000-12-10 15:13:51 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -141,8 +141,7 @@ struct DataSupplier_Impl : m_xContent( rContent ), m_xSMgr( rxSMgr ), m_aFolder( rxSMgr, static_cast< HierarchyContentProvider * >( - rContent->getProvider().getBodyPtr() ) - ->getRootConfigReadNameAccess(), + rContent->getProvider().getBodyPtr() ), rContent->getIdentifier()->getContentIdentifier() ), m_nOpenMode( nOpenMode ), m_bCountFinal( sal_False ) {} ~DataSupplier_Impl(); diff --git a/ucb/source/ucp/hierarchy/hierarchyprovider.cxx b/ucb/source/ucp/hierarchy/hierarchyprovider.cxx index 1369e5167b00..1e8de1f93f68 100644 --- a/ucb/source/ucp/hierarchy/hierarchyprovider.cxx +++ b/ucb/source/ucp/hierarchy/hierarchyprovider.cxx @@ -2,9 +2,9 @@ * * $RCSfile: hierarchyprovider.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: kso $ $Date: 2000-12-08 16:57:39 $ + * last change: $Author: kso $ $Date: 2000-12-10 15:13:51 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -116,10 +116,11 @@ HierarchyContentProvider::~HierarchyContentProvider() // //========================================================================= -XINTERFACE_IMPL_3( HierarchyContentProvider, +XINTERFACE_IMPL_4( HierarchyContentProvider, XTypeProvider, XServiceInfo, - XContentProvider ); + XContentProvider, + XInitialization ); //========================================================================= // @@ -127,10 +128,11 @@ XINTERFACE_IMPL_3( HierarchyContentProvider, // //========================================================================= -XTYPEPROVIDER_IMPL_3( HierarchyContentProvider, +XTYPEPROVIDER_IMPL_4( HierarchyContentProvider, XTypeProvider, XServiceInfo, - XContentProvider ); + XContentProvider, + XInitialization ); //========================================================================= // @@ -200,10 +202,64 @@ Reference< XContent > SAL_CALL HierarchyContentProvider::queryContent( //========================================================================= // +// XInitialization methods. +// +//========================================================================= + +// virtual +void SAL_CALL HierarchyContentProvider::initialize( + const Sequence< Any >& aArguments ) + throw( Exception, RuntimeException ) +{ + if ( aArguments.getLength() > 0 ) + { + // Extract config provider from service init args. + aArguments[ 0 ] >>= m_xConfigProvider; + + VOS_ENSURE( m_xConfigProvider.is(), + "HierarchyContentProvider::initialize - " + "No config provider!" ); + } +} + +//========================================================================= +// // Non-interface methods. // //========================================================================= +Reference< XMultiServiceFactory > HierarchyContentProvider::getConfigProvider() +{ + if ( !m_xConfigProvider.is() ) + { + vos::OGuard aGuard( m_aMutex ); + if ( !m_xConfigProvider.is() ) + { + try + { + m_xConfigProvider = Reference< XMultiServiceFactory >( + m_xSMgr->createInstance( + OUString::createFromAscii( "com.sun.star.configuration." + "ConfigurationProvider" ) ), + UNO_QUERY ); + + VOS_ENSURE( m_xConfigProvider.is(), + "HierarchyContentProvider::getConfigProvider - " + "No config provider!" ); + } + catch ( Exception& ) + { + VOS_ENSURE( sal_False, + "HierarchyContentProvider::getConfigProvider - " + "caught exception!" ); + } + } + } + + return m_xConfigProvider; +} + +//========================================================================= Reference< XHierarchicalNameAccess > HierarchyContentProvider::getRootConfigReadNameAccess() { @@ -214,31 +270,23 @@ HierarchyContentProvider::getRootConfigReadNameAccess() { try { - Reference< XMultiServiceFactory > xConfigProvider( - m_xSMgr->createInstance( - OUString::createFromAscii( - "com.sun.star.configuration.ConfigurationProvider" ) ), - UNO_QUERY ); + getConfigProvider(); - if ( !xConfigProvider.is() ) + if ( m_xConfigProvider.is() ) { - VOS_ENSURE( sal_False, - "HierarchyContentProvider::getRootConfigReadNameAccess - " - "No config provider!" ); - return Reference< XHierarchicalNameAccess >(); - } - - Sequence< Any > aArguments( 1 ); - aArguments[ 0 ] <<= OUString::createFromAscii( + Sequence< Any > aArguments( 1 ); + aArguments[ 0 ] <<= OUString::createFromAscii( "/org.openoffice.ucb.Hierarchy/Root" ); - m_xRootConfigReadNameAccess - = Reference< XHierarchicalNameAccess >( - xConfigProvider->createInstanceWithArguments( - OUString::createFromAscii( - "com.sun.star.configuration.ConfigurationAccess" ), - aArguments ), - UNO_QUERY ); + m_xRootConfigReadNameAccess + = Reference< XHierarchicalNameAccess >( + m_xConfigProvider->createInstanceWithArguments( + OUString::createFromAscii( + "com.sun.star.configuration." + "ConfigurationAccess" ), + aArguments ), + UNO_QUERY ); + } } catch ( RuntimeException& ) { diff --git a/ucb/source/ucp/hierarchy/hierarchyprovider.hxx b/ucb/source/ucp/hierarchy/hierarchyprovider.hxx index 3a7f9f026446..11396f012616 100644 --- a/ucb/source/ucp/hierarchy/hierarchyprovider.hxx +++ b/ucb/source/ucp/hierarchy/hierarchyprovider.hxx @@ -2,9 +2,9 @@ * * $RCSfile: hierarchyprovider.hxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: kso $ $Date: 2000-12-08 16:57:39 $ + * last change: $Author: kso $ $Date: 2000-12-10 15:13:51 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -65,6 +65,9 @@ #ifndef _UCBHELPER_PROVIDERHELPER_HXX #include <ucbhelper/providerhelper.hxx> #endif +#ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_ +#include <com/sun/star/lang/XInitialization.hpp> +#endif namespace com { namespace sun { namespace star { namespace container { class XHierarchicalNameAccess; @@ -93,9 +96,13 @@ namespace hierarchy_ucp { //========================================================================= -class HierarchyContentProvider : public ::ucb::ContentProviderImplHelper +class HierarchyContentProvider : public ::ucb::ContentProviderImplHelper, + public com::sun::star::lang::XInitialization { com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory > + m_xConfigProvider; + com::sun::star::uno::Reference< com::sun::star::container::XHierarchicalNameAccess > m_xRootConfigReadNameAccess; @@ -122,12 +129,22 @@ public: throw( com::sun::star::ucb::IllegalIdentifierException, com::sun::star::uno::RuntimeException ); + // XInitialization + virtual void SAL_CALL + initialize( const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Any >& aArguments ) + throw( ::com::sun::star::uno::Exception, + ::com::sun::star::uno::RuntimeException ); + // Non-Interface methods static rtl::OUString encodeURL( const rtl::OUString& rURL ); static rtl::OUString encodeSegment( const rtl::OUString& rSegment ); static rtl::OUString decodeSegment( const rtl::OUString& rSegment ); com::sun::star::uno::Reference< + com::sun::star::lang::XMultiServiceFactory > + getConfigProvider(); + com::sun::star::uno::Reference< com::sun::star::container::XHierarchicalNameAccess > getRootConfigReadNameAccess(); }; |