1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: mdrivermanager.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
36 #include "mdrivermanager.hxx"
37 #include <com/sun/star/sdbc/XDriver.hpp>
38 #include <com/sun/star/container/XContentEnumerationAccess.hpp>
39 #include <com/sun/star/container/ElementExistException.hpp>
40 #include <com/sun/star/beans/NamedValue.hpp>
41 #include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
43 #include <tools/diagnose_ex.h>
44 #include <comphelper/extract.hxx>
45 #include <comphelper/stl_types.hxx>
46 #include <cppuhelper/implbase1.hxx>
47 #include <cppuhelper/weakref.hxx>
48 #include <osl/diagnose.h>
53 namespace drivermanager
56 using namespace ::com::sun::star::uno
;
57 using namespace ::com::sun::star::lang
;
58 using namespace ::com::sun::star::sdbc
;
59 using namespace ::com::sun::star::beans
;
60 using namespace ::com::sun::star::container
;
61 using namespace ::com::sun::star::logging
;
62 using namespace ::osl
;
64 #define SERVICE_SDBC_DRIVER ::rtl::OUString::createFromAscii("com.sun.star.sdbc.Driver")
66 void throwNoSuchElementException() throw(NoSuchElementException
)
68 throw NoSuchElementException();
71 //==========================================================================
72 //= ODriverEnumeration
73 //==========================================================================
74 class ODriverEnumeration
: public ::cppu::WeakImplHelper1
< XEnumeration
>
76 friend class OSDBCDriverManager
;
78 DECLARE_STL_VECTOR( SdbcDriver
, DriverArray
);
79 DriverArray m_aDrivers
;
80 ConstDriverArrayIterator m_aPos
;
84 virtual ~ODriverEnumeration();
86 ODriverEnumeration(const DriverArray
& _rDriverSequence
);
89 virtual sal_Bool SAL_CALL
hasMoreElements( ) throw(RuntimeException
);
90 virtual Any SAL_CALL
nextElement( ) throw(NoSuchElementException
, WrappedTargetException
, RuntimeException
);
93 //--------------------------------------------------------------------------
94 ODriverEnumeration::ODriverEnumeration(const DriverArray
& _rDriverSequence
)
95 :m_aDrivers( _rDriverSequence
)
96 ,m_aPos( m_aDrivers
.begin() )
100 //--------------------------------------------------------------------------
101 ODriverEnumeration::~ODriverEnumeration()
105 //--------------------------------------------------------------------------
106 sal_Bool SAL_CALL
ODriverEnumeration::hasMoreElements( ) throw(RuntimeException
)
108 return m_aPos
!= m_aDrivers
.end();
111 //--------------------------------------------------------------------------
112 Any SAL_CALL
ODriverEnumeration::nextElement( ) throw(NoSuchElementException
, WrappedTargetException
, RuntimeException
)
114 if ( !hasMoreElements() )
115 throwNoSuchElementException();
117 return makeAny( *m_aPos
++ );
120 //=====================================================================
122 //=====================================================================
123 //---------------------------------------------------------------------
124 //--- 24.08.01 11:27:59 -----------------------------------------------
126 /// an STL functor which ensures that a SdbcDriver described by a DriverAccess is loaded
127 struct EnsureDriver
: public ::std::unary_function
< DriverAccess
, DriverAccess
>
129 const DriverAccess
& operator()( const DriverAccess
& _rDescriptor
) const
131 if ( !_rDescriptor
.xDriver
.is() )
132 // we did not load this driver, yet
133 if ( _rDescriptor
.xComponentFactory
.is() )
134 // we have a factory for it
135 const_cast< DriverAccess
& >( _rDescriptor
).xDriver
= _rDescriptor
.xDriver
.query( _rDescriptor
.xComponentFactory
->createInstance() );
140 //---------------------------------------------------------------------
141 //--- 24.08.01 11:28:04 -----------------------------------------------
143 /// an STL functor which extracts a SdbcDriver from a DriverAccess
144 struct ExtractDriverFromAccess
: public ::std::unary_function
< DriverAccess
, SdbcDriver
>
146 SdbcDriver
operator()( const DriverAccess
& _rAccess
) const
148 return _rAccess
.xDriver
;
152 //---------------------------------------------------------------------
153 //--- 24.08.01 12:37:50 -----------------------------------------------
155 typedef ::std::unary_compose
< ExtractDriverFromAccess
, EnsureDriver
> ExtractAfterLoad_BASE
;
156 /// an STL functor which loads a driver described by a DriverAccess, and extracts the SdbcDriver
157 struct ExtractAfterLoad
: public ExtractAfterLoad_BASE
159 ExtractAfterLoad() : ExtractAfterLoad_BASE( ExtractDriverFromAccess(), EnsureDriver() ) { }
162 //---------------------------------------------------------------------
163 //--- 24.08.01 11:42:36 -----------------------------------------------
165 struct ExtractDriverFromCollectionElement
: public ::std::unary_function
< DriverCollection::value_type
, SdbcDriver
>
167 SdbcDriver
operator()( const DriverCollection::value_type
& _rElement
) const
169 return _rElement
.second
;
173 //---------------------------------------------------------------------
174 //--- 24.08.01 11:51:03 -----------------------------------------------
176 // predicate for checking whether or not a driver accepts a given URL
177 class AcceptsURL
: public ::std::unary_function
< SdbcDriver
, bool >
180 const ::rtl::OUString
& m_rURL
;
184 AcceptsURL( const ::rtl::OUString
& _rURL
) : m_rURL( _rURL
) { }
186 //.................................................................
187 bool operator()( const SdbcDriver
& _rDriver
) const
190 if ( _rDriver
.is() && _rDriver
->acceptsURL( m_rURL
) )
193 // does not accept ...
198 //---------------------------------------------------------------------
199 //--- 24.08.01 12:51:54 -----------------------------------------------
201 static sal_Int32
lcl_getDriverPrecedence( const ::comphelper::ComponentContext
& _rContext
, Sequence
< ::rtl::OUString
>& _rPrecedence
)
203 _rPrecedence
.realloc( 0 );
206 // some strings we need
207 const ::rtl::OUString sConfigurationProviderServiceName
=
208 ::rtl::OUString::createFromAscii("com.sun.star.configuration.ConfigurationProvider");
209 const ::rtl::OUString sDriverManagerConfigLocation
=
210 ::rtl::OUString::createFromAscii("org.openoffice.Office.DataAccess/DriverManager");
211 const ::rtl::OUString sDriverPreferenceLocation
=
212 ::rtl::OUString::createFromAscii("DriverPrecedence");
213 const ::rtl::OUString sNodePathArgumentName
=
214 ::rtl::OUString::createFromAscii("nodepath");
215 const ::rtl::OUString sNodeAccessServiceName
=
216 ::rtl::OUString::createFromAscii("com.sun.star.configuration.ConfigurationAccess");
218 // create a configuration provider
219 Reference
< XMultiServiceFactory
> xConfigurationProvider
;
220 if ( !_rContext
.createComponent( sConfigurationProviderServiceName
, xConfigurationProvider
) )
221 throw ServiceNotRegisteredException( sConfigurationProviderServiceName
, NULL
);
223 // one argument for creating the node access: the path to the configuration node
224 Sequence
< Any
> aCreationArgs(1);
225 aCreationArgs
[0] <<= NamedValue( sNodePathArgumentName
, makeAny( sDriverManagerConfigLocation
) );
227 // create the node access
228 Reference
< XNameAccess
> xDriverManagerNode(xConfigurationProvider
->createInstanceWithArguments(sNodeAccessServiceName
, aCreationArgs
), UNO_QUERY
);
230 OSL_ENSURE(xDriverManagerNode
.is(), "lcl_getDriverPrecedence: could not open my configuration node!");
231 if (xDriverManagerNode
.is())
233 // obtain the preference list
234 Any aPreferences
= xDriverManagerNode
->getByName(sDriverPreferenceLocation
);
235 #if OSL_DEBUG_LEVEL > 0
238 aPreferences
>>= _rPrecedence
;
239 OSL_ENSURE(bSuccess
|| !aPreferences
.hasValue(), "lcl_getDriverPrecedence: invalid value for the preferences node (no string sequence but not NULL)!");
242 catch( const Exception
& )
244 DBG_UNHANDLED_EXCEPTION();
247 return _rPrecedence
.getLength();
250 //---------------------------------------------------------------------
251 //--- 24.08.01 13:01:56 -----------------------------------------------
253 /// an STL argorithm compatible predicate comparing two DriverAccess instances by their implementation names
254 struct CompareDriverAccessByName
: public ::std::binary_function
< DriverAccess
, DriverAccess
, bool >
256 //.................................................................
257 bool operator()( const DriverAccess
& lhs
, const DriverAccess
& rhs
)
259 return lhs
.sImplementationName
< rhs
.sImplementationName
? true : false;
263 //---------------------------------------------------------------------
264 //--- 24.08.01 13:08:17 -----------------------------------------------
266 /// and STL argorithm compatible predicate comparing a DriverAccess' impl name to a string
267 struct CompareDriverAccessToName
: public ::std::binary_function
< DriverAccess
, ::rtl::OUString
, bool >
269 //.................................................................
270 bool operator()( const DriverAccess
& lhs
, const ::rtl::OUString
& rhs
)
272 return lhs
.sImplementationName
< rhs
? true : false;
274 //.................................................................
275 bool operator()( const ::rtl::OUString
& lhs
, const DriverAccess
& rhs
)
277 return lhs
< rhs
.sImplementationName
? true : false;
281 /// and STL argorithm compatible predicate comparing a DriverAccess' impl name to a string
282 struct EqualDriverAccessToName
: public ::std::binary_function
< DriverAccess
, ::rtl::OUString
, bool >
284 ::rtl::OUString m_sImplName
;
285 EqualDriverAccessToName(const ::rtl::OUString
& _sImplName
) : m_sImplName(_sImplName
){}
286 //.................................................................
287 bool operator()( const DriverAccess
& lhs
)
289 return lhs
.sImplementationName
.equals(m_sImplName
);
293 //==========================================================================
294 //= OSDBCDriverManager
295 //==========================================================================
296 //--------------------------------------------------------------------------
297 OSDBCDriverManager::OSDBCDriverManager( const Reference
< XComponentContext
>& _rxContext
)
298 :m_aContext( _rxContext
)
299 ,m_aEventLogger( _rxContext
, "org.openoffice.logging.sdbc.DriverManager" )
300 ,m_aDriverConfig(m_aContext
.getLegacyServiceFactory())
303 // bootstrap all objects supporting the .sdb.Driver service
306 // initialize the drivers order
307 initializeDriverPrecedence();
310 //---------------------------------------------------------------------
311 OSDBCDriverManager::~OSDBCDriverManager()
315 //---------------------------------------------------------------------
316 //--- 24.08.01 11:15:32 -----------------------------------------------
318 void OSDBCDriverManager::bootstrapDrivers()
320 Reference
< XContentEnumerationAccess
> xEnumAccess( m_aContext
.getLegacyServiceFactory(), UNO_QUERY
);
321 Reference
< XEnumeration
> xEnumDrivers
;
322 if (xEnumAccess
.is())
323 xEnumDrivers
= xEnumAccess
->createContentEnumeration(SERVICE_SDBC_DRIVER
);
325 OSL_ENSURE( xEnumDrivers
.is(), "OSDBCDriverManager::bootstrapDrivers: no enumeration for the drivers available!" );
326 if (xEnumDrivers
.is())
328 Reference
< XSingleServiceFactory
> xFactory
;
329 Reference
< XServiceInfo
> xSI
;
330 while (xEnumDrivers
->hasMoreElements())
332 ::cppu::extractInterface( xFactory
, xEnumDrivers
->nextElement() );
333 OSL_ENSURE( xFactory
.is(), "OSDBCDriverManager::bootstrapDrivers: no factory extracted" );
337 // we got a factory for the driver
338 DriverAccess aDriverDescriptor
;
339 sal_Bool bValidDescriptor
= sal_False
;
341 // can it tell us something about the implementation name?
342 xSI
= xSI
.query( xFactory
);
344 { // yes -> no need to load the driver immediately (load it later when needed)
345 aDriverDescriptor
.sImplementationName
= xSI
->getImplementationName();
346 aDriverDescriptor
.xComponentFactory
= xFactory
;
347 bValidDescriptor
= sal_True
;
349 m_aEventLogger
.log( LogLevel::CONFIG
,
350 "found SDBC driver $1$, no need to load it",
351 aDriverDescriptor
.sImplementationName
356 // no -> create the driver
357 Reference
< XDriver
> xDriver( xFactory
->createInstance(), UNO_QUERY
);
358 OSL_ENSURE( xDriver
.is(), "OSDBCDriverManager::bootstrapDrivers: a driver which is no driver?!" );
362 aDriverDescriptor
.xDriver
= xDriver
;
363 // and obtain it's implementation name
364 xSI
= xSI
.query( xDriver
);
365 OSL_ENSURE( xSI
.is(), "OSDBCDriverManager::bootstrapDrivers: a driver without service info?" );
368 aDriverDescriptor
.sImplementationName
= xSI
->getImplementationName();
369 bValidDescriptor
= sal_True
;
371 m_aEventLogger
.log( LogLevel::CONFIG
,
372 "found SDBC driver $1$, needed to load it",
373 aDriverDescriptor
.sImplementationName
379 if ( bValidDescriptor
)
381 m_aDriversBS
.push_back( aDriverDescriptor
);
388 //--------------------------------------------------------------------------
389 void OSDBCDriverManager::initializeDriverPrecedence()
391 if ( m_aDriversBS
.empty() )
397 // get the precedence of the drivers from the configuration
398 Sequence
< ::rtl::OUString
> aDriverOrder
;
399 if ( 0 == lcl_getDriverPrecedence( m_aContext
, aDriverOrder
) )
403 // aDriverOrder now is the list of driver implementation names in the order they should be used
405 if ( m_aEventLogger
.isLoggable( LogLevel::CONFIG
) )
407 sal_Int32 nOrderedCount
= aDriverOrder
.getLength();
408 for ( sal_Int32 i
=0; i
<nOrderedCount
; ++i
)
409 m_aEventLogger
.log( LogLevel::CONFIG
,
410 "configuration's driver order: driver $1$ of $2$: $3$",
411 (sal_Int32
)(i
+ 1), nOrderedCount
, aDriverOrder
[i
]
415 // sort our bootstrapped drivers
416 ::std::sort( m_aDriversBS
.begin(), m_aDriversBS
.end(), CompareDriverAccessByName() );
418 // loop through the names in the precedence order
419 const ::rtl::OUString
* pDriverOrder
= aDriverOrder
.getConstArray();
420 const ::rtl::OUString
* pDriverOrderEnd
= pDriverOrder
+ aDriverOrder
.getLength();
422 // the first driver for which there is no preference
423 DriverAccessArrayIterator aNoPrefDriversStart
= m_aDriversBS
.begin();
424 // at the moment this is the first of all drivers we know
426 for ( ; ( pDriverOrder
< pDriverOrderEnd
) && ( aNoPrefDriversStart
!= m_aDriversBS
.end() ); ++pDriverOrder
)
428 // look for the impl name in the DriverAccess array
429 ::std::pair
< DriverAccessArrayIterator
, DriverAccessArrayIterator
> aPos
=
430 ::std::equal_range( aNoPrefDriversStart
, m_aDriversBS
.end(), *pDriverOrder
, CompareDriverAccessToName() );
432 if ( aPos
.first
!= aPos
.second
)
433 { // we have a DriverAccess with this impl name
435 OSL_ENSURE( ::std::distance( aPos
.first
, aPos
.second
) == 1,
436 "OSDBCDriverManager::initializeDriverPrecedence: more than one driver with this impl name? How this?" );
437 // move the DriverAccess pointed to by aPos.first to the position pointed to by aNoPrefDriversStart
439 if ( aPos
.first
!= aNoPrefDriversStart
)
440 { // if this does not hold, the DriverAccess alread has the correct position
442 // rotate the range [aNoPrefDriversStart, aPos.second) right 1 element
443 ::std::rotate( aNoPrefDriversStart
, aPos
.second
- 1, aPos
.second
);
446 // next round we start searching and pos right
447 ++aNoPrefDriversStart
;
453 OSL_ENSURE(sal_False
, "OSDBCDriverManager::initializeDriverPrecedence: caught an exception while sorting the drivers!");
457 //--------------------------------------------------------------------------
458 Reference
< XConnection
> SAL_CALL
OSDBCDriverManager::getConnection( const ::rtl::OUString
& _rURL
) throw(SQLException
, RuntimeException
)
460 MutexGuard
aGuard(m_aMutex
);
462 m_aEventLogger
.log( LogLevel::INFO
,
463 "connection requested for URL $1$",
467 Reference
< XConnection
> xConnection
;
468 Reference
< XDriver
> xDriver
= implGetDriverForURL(_rURL
);
471 // TODO : handle the login timeout
472 xConnection
= xDriver
->connect(_rURL
, Sequence
< PropertyValue
>());
473 // may throw an exception
474 m_aEventLogger
.log( LogLevel::INFO
,
475 "connection retrieved for URL $1$",
483 //--------------------------------------------------------------------------
484 Reference
< XConnection
> SAL_CALL
OSDBCDriverManager::getConnectionWithInfo( const ::rtl::OUString
& _rURL
, const Sequence
< PropertyValue
>& _rInfo
) throw(SQLException
, RuntimeException
)
486 MutexGuard
aGuard(m_aMutex
);
488 m_aEventLogger
.log( LogLevel::INFO
,
489 "connection with info requested for URL $1$",
493 Reference
< XConnection
> xConnection
;
494 Reference
< XDriver
> xDriver
= implGetDriverForURL(_rURL
);
497 // TODO : handle the login timeout
498 xConnection
= xDriver
->connect(_rURL
, _rInfo
);
499 // may throw an exception
500 m_aEventLogger
.log( LogLevel::INFO
,
501 "connection with info retrieved for URL $1$",
509 //--------------------------------------------------------------------------
510 void SAL_CALL
OSDBCDriverManager::setLoginTimeout( sal_Int32 seconds
) throw(RuntimeException
)
512 MutexGuard
aGuard(m_aMutex
);
513 m_nLoginTimeout
= seconds
;
516 //--------------------------------------------------------------------------
517 sal_Int32 SAL_CALL
OSDBCDriverManager::getLoginTimeout( ) throw(RuntimeException
)
519 MutexGuard
aGuard(m_aMutex
);
520 return m_nLoginTimeout
;
523 //--------------------------------------------------------------------------
524 Reference
< XEnumeration
> SAL_CALL
OSDBCDriverManager::createEnumeration( ) throw(RuntimeException
)
526 MutexGuard
aGuard(m_aMutex
);
528 ODriverEnumeration::DriverArray aDrivers
;
530 // ensure that all our bootstrapped drivers are insatntiated
531 ::std::for_each( m_aDriversBS
.begin(), m_aDriversBS
.end(), EnsureDriver() );
533 // copy the bootstrapped drivers
535 m_aDriversBS
.begin(), // "copy from" start
536 m_aDriversBS
.end(), // "copy from" end
537 ::std::back_inserter( aDrivers
), // insert into
538 ExtractDriverFromAccess() // transformation to apply (extract a driver from a driver access)
541 // append the runtime drivers
543 m_aDriversRT
.begin(), // "copy from" start
544 m_aDriversRT
.end(), // "copy from" end
545 ::std::back_inserter( aDrivers
), // insert into
546 ExtractDriverFromCollectionElement() // transformation to apply (extract a driver from a driver access)
549 return new ODriverEnumeration( aDrivers
);
552 //--------------------------------------------------------------------------
553 ::com::sun::star::uno::Type SAL_CALL
OSDBCDriverManager::getElementType( ) throw(::com::sun::star::uno::RuntimeException
)
555 return ::getCppuType(static_cast< Reference
< XDriver
>* >(NULL
));
558 //--------------------------------------------------------------------------
559 sal_Bool SAL_CALL
OSDBCDriverManager::hasElements( ) throw(::com::sun::star::uno::RuntimeException
)
561 MutexGuard
aGuard(m_aMutex
);
562 return !(m_aDriversBS
.empty() && m_aDriversRT
.empty());
565 //--------------------------------------------------------------------------
566 ::rtl::OUString SAL_CALL
OSDBCDriverManager::getImplementationName( ) throw(RuntimeException
)
568 return getImplementationName_static();
571 //--------------------------------------------------------------------------
572 sal_Bool SAL_CALL
OSDBCDriverManager::supportsService( const ::rtl::OUString
& _rServiceName
) throw(RuntimeException
)
574 Sequence
< ::rtl::OUString
> aSupported(getSupportedServiceNames());
575 const ::rtl::OUString
* pSupported
= aSupported
.getConstArray();
576 const ::rtl::OUString
* pEnd
= pSupported
+ aSupported
.getLength();
577 for (;pSupported
!= pEnd
&& !pSupported
->equals(_rServiceName
); ++pSupported
)
580 return pSupported
!= pEnd
;
583 //--------------------------------------------------------------------------
584 Sequence
< ::rtl::OUString
> SAL_CALL
OSDBCDriverManager::getSupportedServiceNames( ) throw(RuntimeException
)
586 return getSupportedServiceNames_static();
589 //--------------------------------------------------------------------------
590 Reference
< XInterface
> SAL_CALL
OSDBCDriverManager::Create( const Reference
< XMultiServiceFactory
>& _rxFactory
)
592 ::comphelper::ComponentContext
aContext( _rxFactory
);
593 return *( new OSDBCDriverManager( aContext
.getUNOContext() ) );
596 //--------------------------------------------------------------------------
597 ::rtl::OUString SAL_CALL
OSDBCDriverManager::getImplementationName_static( ) throw(RuntimeException
)
599 return ::rtl::OUString::createFromAscii("com.sun.star.comp.sdbc.OSDBCDriverManager");
602 //--------------------------------------------------------------------------
603 Sequence
< ::rtl::OUString
> SAL_CALL
OSDBCDriverManager::getSupportedServiceNames_static( ) throw(RuntimeException
)
605 Sequence
< ::rtl::OUString
> aSupported(1);
606 aSupported
[0] = getSingletonName_static();
610 //--------------------------------------------------------------------------
611 ::rtl::OUString SAL_CALL
OSDBCDriverManager::getSingletonName_static( ) throw(RuntimeException
)
613 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdbc.DriverManager" ) );
616 //--------------------------------------------------------------------------
617 Reference
< XInterface
> SAL_CALL
OSDBCDriverManager::getRegisteredObject( const ::rtl::OUString
& _rName
) throw(Exception
, RuntimeException
)
619 MutexGuard
aGuard(m_aMutex
);
620 ConstDriverCollectionIterator aSearch
= m_aDriversRT
.find(_rName
);
621 if (aSearch
== m_aDriversRT
.end())
622 throwNoSuchElementException();
624 return aSearch
->second
.get();
627 //--------------------------------------------------------------------------
628 void SAL_CALL
OSDBCDriverManager::registerObject( const ::rtl::OUString
& _rName
, const Reference
< XInterface
>& _rxObject
) throw(Exception
, RuntimeException
)
630 MutexGuard
aGuard(m_aMutex
);
632 m_aEventLogger
.log( LogLevel::INFO
,
633 "attempt to register new driver for name $1$",
637 ConstDriverCollectionIterator aSearch
= m_aDriversRT
.find(_rName
);
638 if (aSearch
== m_aDriversRT
.end())
640 Reference
< XDriver
> xNewDriver(_rxObject
, UNO_QUERY
);
642 m_aDriversRT
.insert(DriverCollection::value_type(_rName
, xNewDriver
));
644 throw IllegalArgumentException();
647 throw ElementExistException();
649 m_aEventLogger
.log( LogLevel::INFO
,
650 "new driver registered for name $1$",
655 //--------------------------------------------------------------------------
656 void SAL_CALL
OSDBCDriverManager::revokeObject( const ::rtl::OUString
& _rName
) throw(Exception
, RuntimeException
)
658 MutexGuard
aGuard(m_aMutex
);
660 m_aEventLogger
.log( LogLevel::INFO
,
661 "attempt to revoke driver for name $1$",
665 DriverCollectionIterator aSearch
= m_aDriversRT
.find(_rName
);
666 if (aSearch
== m_aDriversRT
.end())
667 throwNoSuchElementException();
669 m_aDriversRT
.erase(aSearch
); // we already have the iterator so we could use it
671 m_aEventLogger
.log( LogLevel::INFO
,
672 "driver revoked for name $1$",
677 //--------------------------------------------------------------------------
678 Reference
< XDriver
> SAL_CALL
OSDBCDriverManager::getDriverByURL( const ::rtl::OUString
& _rURL
) throw(RuntimeException
)
680 m_aEventLogger
.log( LogLevel::INFO
,
681 "driver requested for URL $1$",
685 Reference
< XDriver
> xDriver( implGetDriverForURL( _rURL
) );
688 m_aEventLogger
.log( LogLevel::INFO
,
689 "driver obtained for URL $1$",
696 //--------------------------------------------------------------------------
697 Reference
< XDriver
> OSDBCDriverManager::implGetDriverForURL(const ::rtl::OUString
& _rURL
)
699 Reference
< XDriver
> xReturn
;
702 const ::rtl::OUString sDriverFactoryName
= m_aDriverConfig
.getDriverFactoryName(_rURL
);
704 EqualDriverAccessToName
aEqual(sDriverFactoryName
);
705 DriverAccessArray::iterator aFind
= ::std::find_if(m_aDriversBS
.begin(),m_aDriversBS
.end(),aEqual
);
706 if ( aFind
== m_aDriversBS
.end() )
708 // search all bootstrapped drivers
709 aFind
= ::std::find_if(
710 m_aDriversBS
.begin(), // begin of search range
711 m_aDriversBS
.end(), // end of search range
712 std::unary_compose
< AcceptsURL
, ExtractAfterLoad
>( AcceptsURL( _rURL
), ExtractAfterLoad() )
713 // compose two functors: extract the driver from the access, then ask the resulting driver for acceptance
715 } // if ( m_aDriversBS.find(sDriverFactoryName ) == m_aDriversBS.end() )
718 EnsureDriver aEnsure
;
723 if ( m_aDriversBS
.end() != aFind
)
724 xReturn
= aFind
->xDriver
;
729 // no -> search the runtime drivers
730 DriverCollectionIterator aPos
= ::std::find_if(
731 m_aDriversRT
.begin(), // begin of search range
732 m_aDriversRT
.end(), // end of search range
733 std::unary_compose
< AcceptsURL
, ExtractDriverFromCollectionElement
>( AcceptsURL( _rURL
), ExtractDriverFromCollectionElement() )
734 // compose two functors: extract the driver from the access, then ask the resulting driver for acceptance
737 if ( m_aDriversRT
.end() != aPos
)
738 xReturn
= aPos
->second
;
744 } // namespace drivermanager