Kaydet (Commit) 7f635eeb authored tarafından Ariel Constenla-Haile's avatar Ariel Constenla-Haile

Ensure UNO context propagation on drivers instantiation

Use a better approach than revision 1387711
üst 96bc6d61
...@@ -119,6 +119,9 @@ Any SAL_CALL ODriverEnumeration::nextElement( ) throw(NoSuchElementException, W ...@@ -119,6 +119,9 @@ Any SAL_CALL ODriverEnumeration::nextElement( ) throw(NoSuchElementException, W
/// an STL functor which ensures that a SdbcDriver described by a DriverAccess is loaded /// an STL functor which ensures that a SdbcDriver described by a DriverAccess is loaded
struct EnsureDriver : public ::std::unary_function< DriverAccess, DriverAccess > struct EnsureDriver : public ::std::unary_function< DriverAccess, DriverAccess >
{ {
EnsureDriver( const Reference< XComponentContext > &rxContext )
: mxContext( rxContext ) {}
const DriverAccess& operator()( const DriverAccess& _rDescriptor ) const const DriverAccess& operator()( const DriverAccess& _rDescriptor ) const
{ {
if ( !_rDescriptor.xDriver.is() ) if ( !_rDescriptor.xDriver.is() )
...@@ -126,9 +129,12 @@ Any SAL_CALL ODriverEnumeration::nextElement( ) throw(NoSuchElementException, W ...@@ -126,9 +129,12 @@ Any SAL_CALL ODriverEnumeration::nextElement( ) throw(NoSuchElementException, W
if ( _rDescriptor.xComponentFactory.is() ) if ( _rDescriptor.xComponentFactory.is() )
// we have a factory for it // we have a factory for it
const_cast< DriverAccess& >( _rDescriptor ).xDriver = _rDescriptor.xDriver.query( const_cast< DriverAccess& >( _rDescriptor ).xDriver = _rDescriptor.xDriver.query(
_rDescriptor.xComponentFactory->createInstanceWithContext( _rDescriptor.xUNOContext ) ); _rDescriptor.xComponentFactory->createInstanceWithContext( mxContext ) );
return _rDescriptor; return _rDescriptor;
} }
private:
Reference< XComponentContext > mxContext;
}; };
//--------------------------------------------------------------------- //---------------------------------------------------------------------
...@@ -150,7 +156,8 @@ Any SAL_CALL ODriverEnumeration::nextElement( ) throw(NoSuchElementException, W ...@@ -150,7 +156,8 @@ Any SAL_CALL ODriverEnumeration::nextElement( ) throw(NoSuchElementException, W
/// an STL functor which loads a driver described by a DriverAccess, and extracts the SdbcDriver /// an STL functor which loads a driver described by a DriverAccess, and extracts the SdbcDriver
struct ExtractAfterLoad : public ExtractAfterLoad_BASE struct ExtractAfterLoad : public ExtractAfterLoad_BASE
{ {
ExtractAfterLoad() : ExtractAfterLoad_BASE( ExtractDriverFromAccess(), EnsureDriver() ) { } ExtractAfterLoad( const Reference< XComponentContext > &rxContext )
: ExtractAfterLoad_BASE( ExtractDriverFromAccess(), EnsureDriver( rxContext ) ) {}
}; };
//--------------------------------------------------------------------- //---------------------------------------------------------------------
...@@ -338,7 +345,6 @@ void OSDBCDriverManager::bootstrapDrivers() ...@@ -338,7 +345,6 @@ void OSDBCDriverManager::bootstrapDrivers()
{ // yes -> no need to load the driver immediately (load it later when needed) { // yes -> no need to load the driver immediately (load it later when needed)
aDriverDescriptor.sImplementationName = xSI->getImplementationName(); aDriverDescriptor.sImplementationName = xSI->getImplementationName();
aDriverDescriptor.xComponentFactory = xFactory; aDriverDescriptor.xComponentFactory = xFactory;
aDriverDescriptor.xUNOContext = m_aContext.getUNOContext();
bValidDescriptor = sal_True; bValidDescriptor = sal_True;
m_aEventLogger.log( LogLevel::CONFIG, m_aEventLogger.log( LogLevel::CONFIG,
...@@ -523,7 +529,7 @@ Reference< XEnumeration > SAL_CALL OSDBCDriverManager::createEnumeration( ) thr ...@@ -523,7 +529,7 @@ Reference< XEnumeration > SAL_CALL OSDBCDriverManager::createEnumeration( ) thr
ODriverEnumeration::DriverArray aDrivers; ODriverEnumeration::DriverArray aDrivers;
// ensure that all our bootstrapped drivers are insatntiated // ensure that all our bootstrapped drivers are insatntiated
::std::for_each( m_aDriversBS.begin(), m_aDriversBS.end(), EnsureDriver() ); ::std::for_each( m_aDriversBS.begin(), m_aDriversBS.end(), EnsureDriver( m_aContext.getUNOContext() ) );
// copy the bootstrapped drivers // copy the bootstrapped drivers
::std::transform( ::std::transform(
...@@ -704,13 +710,13 @@ Reference< XDriver > OSDBCDriverManager::implGetDriverForURL(const ::rtl::OUStri ...@@ -704,13 +710,13 @@ Reference< XDriver > OSDBCDriverManager::implGetDriverForURL(const ::rtl::OUStri
aFind = ::std::find_if( aFind = ::std::find_if(
m_aDriversBS.begin(), // begin of search range m_aDriversBS.begin(), // begin of search range
m_aDriversBS.end(), // end of search range m_aDriversBS.end(), // end of search range
std::unary_compose< AcceptsURL, ExtractAfterLoad >( AcceptsURL( _rURL ), ExtractAfterLoad() ) std::unary_compose< AcceptsURL, ExtractAfterLoad >( AcceptsURL( _rURL ), ExtractAfterLoad( m_aContext.getUNOContext() ) )
// compose two functors: extract the driver from the access, then ask the resulting driver for acceptance // compose two functors: extract the driver from the access, then ask the resulting driver for acceptance
); );
} // if ( m_aDriversBS.find(sDriverFactoryName ) == m_aDriversBS.end() ) } // if ( m_aDriversBS.find(sDriverFactoryName ) == m_aDriversBS.end() )
else else
{ {
EnsureDriver aEnsure; EnsureDriver aEnsure( m_aContext.getUNOContext() );
aEnsure(*aFind); aEnsure(*aFind);
} }
......
...@@ -50,12 +50,10 @@ namespace drivermanager ...@@ -50,12 +50,10 @@ namespace drivermanager
DECLARE_STL_USTRINGACCESS_MAP( SdbcDriver, DriverCollection ); DECLARE_STL_USTRINGACCESS_MAP( SdbcDriver, DriverCollection );
typedef ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleComponentFactory > DriverFactory; typedef ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleComponentFactory > DriverFactory;
typedef ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > UNOContext;
struct DriverAccess struct DriverAccess
{ {
::rtl::OUString sImplementationName; /// the implementation name of the driver ::rtl::OUString sImplementationName; /// the implementation name of the driver
DriverFactory xComponentFactory; /// the factory to create the driver component (if not already done so) DriverFactory xComponentFactory; /// the factory to create the driver component (if not already done so)
UNOContext xUNOContext; /// ensure UNO context propagation
SdbcDriver xDriver; /// the driver itself SdbcDriver xDriver; /// the driver itself
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment