xref: /AOO41X/main/connectivity/source/drivers/kab/KDriver.cxx (revision 9b5730f6ddef7eb82608ca4d31dc0d7678e652cf)
1*9b5730f6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9b5730f6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9b5730f6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9b5730f6SAndrew Rist  * distributed with this work for additional information
6*9b5730f6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9b5730f6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9b5730f6SAndrew Rist  * "License"); you may not use this file except in compliance
9*9b5730f6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*9b5730f6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*9b5730f6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9b5730f6SAndrew Rist  * software distributed under the License is distributed on an
15*9b5730f6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9b5730f6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9b5730f6SAndrew Rist  * specific language governing permissions and limitations
18*9b5730f6SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*9b5730f6SAndrew Rist  *************************************************************/
21*9b5730f6SAndrew Rist 
22*9b5730f6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "KDriver.hxx"
28cdf0e10cSrcweir #include "KDEInit.h"
29cdf0e10cSrcweir #include "KConnection.hxx"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir /** === begin UNO includes === **/
32cdf0e10cSrcweir #include <com/sun/star/sdb/SQLContext.hpp>
33cdf0e10cSrcweir #include <com/sun/star/lang/NullPointerException.hpp>
34cdf0e10cSrcweir #include <com/sun/star/frame/XDesktop.hpp>
35cdf0e10cSrcweir /** === end UNO includes === **/
36cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
37cdf0e10cSrcweir #include <tools/diagnose_ex.h>
38cdf0e10cSrcweir #include "resource/kab_res.hrc"
39cdf0e10cSrcweir #include "resource/sharedresources.hxx"
40cdf0e10cSrcweir 
41cdf0e10cSrcweir using namespace com::sun::star::uno;
42cdf0e10cSrcweir using namespace com::sun::star::lang;
43cdf0e10cSrcweir using namespace com::sun::star::beans;
44cdf0e10cSrcweir using namespace com::sun::star::sdbc;
45cdf0e10cSrcweir using namespace com::sun::star::sdb;
46cdf0e10cSrcweir using namespace com::sun::star::frame;
47cdf0e10cSrcweir using namespace connectivity::kab;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir // =======================================================================
50cdf0e10cSrcweir // = KabImplModule
51cdf0e10cSrcweir // =======================================================================
52cdf0e10cSrcweir // --------------------------------------------------------------------------------
KabImplModule(const Reference<XMultiServiceFactory> & _rxFactory)53cdf0e10cSrcweir KabImplModule::KabImplModule( const Reference< XMultiServiceFactory >& _rxFactory )
54cdf0e10cSrcweir     :m_xORB(_rxFactory)
55cdf0e10cSrcweir     ,m_bAttemptedLoadModule(false)
56cdf0e10cSrcweir     ,m_bAttemptedInitialize(false)
57cdf0e10cSrcweir     ,m_hConnectorModule(NULL)
58cdf0e10cSrcweir     ,m_pConnectionFactoryFunc(NULL)
59cdf0e10cSrcweir     ,m_pApplicationInitFunc(NULL)
60cdf0e10cSrcweir     ,m_pApplicationShutdownFunc(NULL)
61cdf0e10cSrcweir     ,m_pKDEVersionCheckFunc(NULL)
62cdf0e10cSrcweir {
63cdf0e10cSrcweir     if ( !m_xORB.is() )
64cdf0e10cSrcweir         throw NullPointerException();
65cdf0e10cSrcweir }
66cdf0e10cSrcweir 
67cdf0e10cSrcweir // --------------------------------------------------------------------------------
isKDEPresent()68cdf0e10cSrcweir bool KabImplModule::isKDEPresent()
69cdf0e10cSrcweir {
70cdf0e10cSrcweir     if ( !impl_loadModule() )
71cdf0e10cSrcweir         return false;
72cdf0e10cSrcweir 
73cdf0e10cSrcweir     return true;
74cdf0e10cSrcweir }
75cdf0e10cSrcweir 
76cdf0e10cSrcweir // --------------------------------------------------------------------------------
matchKDEVersion()77cdf0e10cSrcweir KabImplModule::KDEVersionType KabImplModule::matchKDEVersion()
78cdf0e10cSrcweir {
79cdf0e10cSrcweir     OSL_PRECOND( m_pKDEVersionCheckFunc, "KabImplModule::matchKDEVersion: module not loaded!" );
80cdf0e10cSrcweir 
81cdf0e10cSrcweir     int nVersionInfo = (*m_pKDEVersionCheckFunc)();
82cdf0e10cSrcweir     if ( nVersionInfo < 0 )
83cdf0e10cSrcweir         return eTooOld;
84cdf0e10cSrcweir     if ( nVersionInfo > 0 )
85cdf0e10cSrcweir         return eToNew;
86cdf0e10cSrcweir     return eSupported;
87cdf0e10cSrcweir }
88cdf0e10cSrcweir 
89cdf0e10cSrcweir // --------------------------------------------------------------------------------
90cdf0e10cSrcweir namespace
91cdf0e10cSrcweir {
92cdf0e10cSrcweir     template< typename FUNCTION >
lcl_getFunctionFromModuleOrUnload(oslModule & _rModule,const sal_Char * _pAsciiSymbolName,FUNCTION & _rFunction)93cdf0e10cSrcweir     void lcl_getFunctionFromModuleOrUnload( oslModule& _rModule, const sal_Char* _pAsciiSymbolName, FUNCTION& _rFunction )
94cdf0e10cSrcweir     {
95cdf0e10cSrcweir         _rFunction = NULL;
96cdf0e10cSrcweir         if ( _rModule )
97cdf0e10cSrcweir         {
98cdf0e10cSrcweir             //
99cdf0e10cSrcweir             const ::rtl::OUString sSymbolName = ::rtl::OUString::createFromAscii( _pAsciiSymbolName );
100cdf0e10cSrcweir             _rFunction = (FUNCTION)( osl_getSymbol( _rModule, sSymbolName.pData ) );
101cdf0e10cSrcweir 
102cdf0e10cSrcweir             if ( !_rFunction )
103cdf0e10cSrcweir             {   // did not find the symbol
104cdf0e10cSrcweir                 OSL_ENSURE( false, ::rtl::OString( "lcl_getFunctionFromModuleOrUnload: could not find the symbol " ) + ::rtl::OString( _pAsciiSymbolName ) );
105cdf0e10cSrcweir                 osl_unloadModule( _rModule );
106cdf0e10cSrcweir                 _rModule = NULL;
107cdf0e10cSrcweir             }
108cdf0e10cSrcweir         }
109cdf0e10cSrcweir     }
110cdf0e10cSrcweir }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir // --------------------------------------------------------------------------------
thisModule()113cdf0e10cSrcweir extern "C" { void SAL_CALL thisModule() {} }
114cdf0e10cSrcweir 
impl_loadModule()115cdf0e10cSrcweir bool KabImplModule::impl_loadModule()
116cdf0e10cSrcweir {
117cdf0e10cSrcweir     if ( m_bAttemptedLoadModule )
118cdf0e10cSrcweir         return ( m_hConnectorModule != NULL );
119cdf0e10cSrcweir     m_bAttemptedLoadModule = true;
120cdf0e10cSrcweir 
121cdf0e10cSrcweir     OSL_ENSURE( !m_hConnectorModule && !m_pConnectionFactoryFunc && !m_pApplicationInitFunc && !m_pApplicationShutdownFunc && !m_pKDEVersionCheckFunc,
122cdf0e10cSrcweir         "KabImplModule::impl_loadModule: inconsistence: inconsistency (never attempted load before, but some values already set)!");
123cdf0e10cSrcweir 
124cdf0e10cSrcweir     const ::rtl::OUString sModuleName = ::rtl::OUString::createFromAscii( SAL_MODULENAME( "kabdrv1" ) );
125cdf0e10cSrcweir     m_hConnectorModule = osl_loadModuleRelative( &thisModule, sModuleName.pData, SAL_LOADMODULE_NOW );   // LAZY! #i61335#
126cdf0e10cSrcweir     OSL_ENSURE( m_hConnectorModule, "KabImplModule::impl_loadModule: could not load the implementation library!" );
127cdf0e10cSrcweir     if ( !m_hConnectorModule )
128cdf0e10cSrcweir         return false;
129cdf0e10cSrcweir 
130cdf0e10cSrcweir     lcl_getFunctionFromModuleOrUnload( m_hConnectorModule, "createKabConnection",   m_pConnectionFactoryFunc );
131cdf0e10cSrcweir     lcl_getFunctionFromModuleOrUnload( m_hConnectorModule, "initKApplication",      m_pApplicationInitFunc );
132cdf0e10cSrcweir     lcl_getFunctionFromModuleOrUnload( m_hConnectorModule, "shutdownKApplication",  m_pApplicationShutdownFunc );
133cdf0e10cSrcweir     lcl_getFunctionFromModuleOrUnload( m_hConnectorModule, "matchKDEVersion",       m_pKDEVersionCheckFunc );
134cdf0e10cSrcweir 
135cdf0e10cSrcweir     if ( !m_hConnectorModule )
136cdf0e10cSrcweir         // one of the symbols did not exist
137cdf0e10cSrcweir         throw RuntimeException();
138cdf0e10cSrcweir 
139cdf0e10cSrcweir     return true;
140cdf0e10cSrcweir }
141cdf0e10cSrcweir 
142cdf0e10cSrcweir // --------------------------------------------------------------------------------
impl_unloadModule()143cdf0e10cSrcweir void KabImplModule::impl_unloadModule()
144cdf0e10cSrcweir {
145cdf0e10cSrcweir     OSL_PRECOND( m_hConnectorModule != NULL, "KabImplModule::impl_unloadModule: no module!" );
146cdf0e10cSrcweir 
147cdf0e10cSrcweir     osl_unloadModule( m_hConnectorModule );
148cdf0e10cSrcweir     m_hConnectorModule = NULL;
149cdf0e10cSrcweir 
150cdf0e10cSrcweir     m_pConnectionFactoryFunc = NULL;
151cdf0e10cSrcweir     m_pApplicationInitFunc = NULL;
152cdf0e10cSrcweir     m_pApplicationShutdownFunc = NULL;
153cdf0e10cSrcweir     m_pKDEVersionCheckFunc = NULL;
154cdf0e10cSrcweir 
155cdf0e10cSrcweir     m_bAttemptedLoadModule = false;
156cdf0e10cSrcweir }
157cdf0e10cSrcweir 
158cdf0e10cSrcweir // --------------------------------------------------------------------------------
init()159cdf0e10cSrcweir void KabImplModule::init()
160cdf0e10cSrcweir {
161cdf0e10cSrcweir     if ( !impl_loadModule() )
162cdf0e10cSrcweir         impl_throwNoKdeException();
163cdf0e10cSrcweir 
164cdf0e10cSrcweir     // if we're not running on a supported version, throw
165cdf0e10cSrcweir     KabImplModule::KDEVersionType eKDEVersion = matchKDEVersion();
166cdf0e10cSrcweir 
167cdf0e10cSrcweir     if ( eKDEVersion == eTooOld )
168cdf0e10cSrcweir         impl_throwKdeTooOldException();
169cdf0e10cSrcweir 
170cdf0e10cSrcweir     if ( ( eKDEVersion == eToNew ) && !impl_doAllowNewKDEVersion() )
171cdf0e10cSrcweir         impl_throwKdeTooNewException();
172cdf0e10cSrcweir 
173cdf0e10cSrcweir     if ( !m_bAttemptedInitialize )
174cdf0e10cSrcweir     {
175cdf0e10cSrcweir         m_bAttemptedInitialize = true;
176cdf0e10cSrcweir         (*m_pApplicationInitFunc)();
177cdf0e10cSrcweir     }
178cdf0e10cSrcweir }
179cdf0e10cSrcweir 
180cdf0e10cSrcweir // --------------------------------------------------------------------------------
impl_doAllowNewKDEVersion()181cdf0e10cSrcweir bool KabImplModule::impl_doAllowNewKDEVersion()
182cdf0e10cSrcweir {
183cdf0e10cSrcweir     try
184cdf0e10cSrcweir     {
185cdf0e10cSrcweir         Reference< XMultiServiceFactory > xConfigProvider(
186cdf0e10cSrcweir             m_xORB->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationProvider" ) ) ),
187cdf0e10cSrcweir             UNO_QUERY_THROW );
188cdf0e10cSrcweir         Sequence< Any > aCreationArgs(1);
189cdf0e10cSrcweir         aCreationArgs[0] <<= PropertyValue(
190cdf0e10cSrcweir                                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "nodepath" ) ),
191cdf0e10cSrcweir                                 0,
192cdf0e10cSrcweir                                 makeAny( KabDriver::impl_getConfigurationSettingsPath() ),
193cdf0e10cSrcweir                                 PropertyState_DIRECT_VALUE );
194cdf0e10cSrcweir         Reference< XPropertySet > xSettings( xConfigProvider->createInstanceWithArguments(
195cdf0e10cSrcweir                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationAccess" ) ),
196cdf0e10cSrcweir                 aCreationArgs ),
197cdf0e10cSrcweir             UNO_QUERY_THROW );
198cdf0e10cSrcweir 
199cdf0e10cSrcweir         sal_Bool bDisableCheck = sal_False;
200cdf0e10cSrcweir         xSettings->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DisableKDEMaximumVersionCheck" ) ) ) >>= bDisableCheck;
201cdf0e10cSrcweir 
202cdf0e10cSrcweir         return bDisableCheck != sal_False;
203cdf0e10cSrcweir     }
204cdf0e10cSrcweir     catch( const Exception& )
205cdf0e10cSrcweir     {
206cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
207cdf0e10cSrcweir     }
208cdf0e10cSrcweir     return false;
209cdf0e10cSrcweir }
210cdf0e10cSrcweir 
211cdf0e10cSrcweir // --------------------------------------------------------------------------------
impl_throwNoKdeException()212cdf0e10cSrcweir void KabImplModule::impl_throwNoKdeException()
213cdf0e10cSrcweir {
214cdf0e10cSrcweir     ::connectivity::SharedResources aResources;
215cdf0e10cSrcweir     const ::rtl::OUString sError( aResources.getResourceString(
216cdf0e10cSrcweir             STR_NO_KDE_INST
217cdf0e10cSrcweir          ) );
218cdf0e10cSrcweir     impl_throwGenericSQLException( sError );
219cdf0e10cSrcweir }
220cdf0e10cSrcweir 
221cdf0e10cSrcweir // --------------------------------------------------------------------------------
impl_throwKdeTooOldException()222cdf0e10cSrcweir void KabImplModule::impl_throwKdeTooOldException()
223cdf0e10cSrcweir {
224cdf0e10cSrcweir     ::connectivity::SharedResources aResources;
225cdf0e10cSrcweir     const ::rtl::OUString sError( aResources.getResourceStringWithSubstitution(
226cdf0e10cSrcweir             STR_KDE_VERSION_TOO_OLD,
227cdf0e10cSrcweir             "$major$",::rtl::OUString::valueOf((sal_Int32)MIN_KDE_VERSION_MAJOR),
228cdf0e10cSrcweir             "$minor$",::rtl::OUString::valueOf((sal_Int32)MIN_KDE_VERSION_MINOR)
229cdf0e10cSrcweir          ) );
230cdf0e10cSrcweir     impl_throwGenericSQLException( sError );
231cdf0e10cSrcweir }
232cdf0e10cSrcweir 
233cdf0e10cSrcweir // --------------------------------------------------------------------------------
impl_throwGenericSQLException(const::rtl::OUString & _rMessage)234cdf0e10cSrcweir void KabImplModule::impl_throwGenericSQLException( const ::rtl::OUString& _rMessage )
235cdf0e10cSrcweir {
236cdf0e10cSrcweir     SQLException aError;
237cdf0e10cSrcweir     aError.Message = _rMessage;
238cdf0e10cSrcweir     aError.SQLState = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "S1000" ) );
239cdf0e10cSrcweir     aError.ErrorCode = 0;
240cdf0e10cSrcweir     throw aError;
241cdf0e10cSrcweir }
242cdf0e10cSrcweir 
243cdf0e10cSrcweir // --------------------------------------------------------------------------------
impl_throwKdeTooNewException()244cdf0e10cSrcweir void KabImplModule::impl_throwKdeTooNewException()
245cdf0e10cSrcweir {
246cdf0e10cSrcweir     ::connectivity::SharedResources aResources;
247cdf0e10cSrcweir 
248cdf0e10cSrcweir     SQLException aError;
249cdf0e10cSrcweir     aError.Message = aResources.getResourceStringWithSubstitution(
250cdf0e10cSrcweir             STR_KDE_VERSION_TOO_NEW,
251cdf0e10cSrcweir             "$major$",::rtl::OUString::valueOf((sal_Int32)MIN_KDE_VERSION_MAJOR),
252cdf0e10cSrcweir             "$minor$",::rtl::OUString::valueOf((sal_Int32)MIN_KDE_VERSION_MINOR)
253cdf0e10cSrcweir          );
254cdf0e10cSrcweir     aError.SQLState = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "S1000" ) );
255cdf0e10cSrcweir     aError.ErrorCode = 0;
256cdf0e10cSrcweir 
257cdf0e10cSrcweir     SQLContext aDetails;
258cdf0e10cSrcweir     ::rtl::OUStringBuffer aMessage;
259cdf0e10cSrcweir     aMessage.append( aResources.getResourceString(STR_KDE_VERSION_TOO_NEW_WORK_AROUND) );
260cdf0e10cSrcweir 
261cdf0e10cSrcweir     aMessage.appendAscii( "Sub disableKDEMaxVersionCheck\n" );
262cdf0e10cSrcweir     aMessage.appendAscii( "  BasicLibraries.LoadLibrary( \"Tools\" )\n" );
263cdf0e10cSrcweir 
264cdf0e10cSrcweir     aMessage.appendAscii( "  Dim configNode as Object\n" );
265cdf0e10cSrcweir     aMessage.appendAscii( "  configNode = GetRegistryKeyContent( \"" );
266cdf0e10cSrcweir     aMessage.append( KabDriver::impl_getConfigurationSettingsPath() );
267cdf0e10cSrcweir     aMessage.appendAscii( "\", true )\n" );
268cdf0e10cSrcweir 
269cdf0e10cSrcweir     aMessage.appendAscii( "  configNode.DisableKDEMaximumVersionCheck = TRUE\n" );
270cdf0e10cSrcweir     aMessage.appendAscii( "  configNode.commitChanges\n" );
271cdf0e10cSrcweir     aMessage.appendAscii( "End Sub\n" );
272cdf0e10cSrcweir 
273cdf0e10cSrcweir     aDetails.Message = aMessage.makeStringAndClear();
274cdf0e10cSrcweir 
275cdf0e10cSrcweir     aError.NextException <<= aDetails;
276cdf0e10cSrcweir 
277cdf0e10cSrcweir     throw aError;
278cdf0e10cSrcweir }
279cdf0e10cSrcweir 
280cdf0e10cSrcweir // --------------------------------------------------------------------------------
createConnection(KabDriver * _pDriver) const281cdf0e10cSrcweir KabConnection* KabImplModule::createConnection( KabDriver* _pDriver ) const
282cdf0e10cSrcweir {
283cdf0e10cSrcweir     OSL_PRECOND( m_hConnectorModule, "KabImplModule::createConnection: not initialized!" );
284cdf0e10cSrcweir 
285cdf0e10cSrcweir     void* pUntypedConnection = (*m_pConnectionFactoryFunc)( _pDriver );
286cdf0e10cSrcweir     if ( !pUntypedConnection )
287cdf0e10cSrcweir         throw RuntimeException();
288cdf0e10cSrcweir 
289cdf0e10cSrcweir     return static_cast< KabConnection* >( pUntypedConnection );
290cdf0e10cSrcweir }
291cdf0e10cSrcweir 
292cdf0e10cSrcweir // --------------------------------------------------------------------------------
shutdown()293cdf0e10cSrcweir void KabImplModule::shutdown()
294cdf0e10cSrcweir {
295cdf0e10cSrcweir     if ( !m_hConnectorModule )
296cdf0e10cSrcweir         return;
297cdf0e10cSrcweir 
298cdf0e10cSrcweir     (*m_pApplicationShutdownFunc)();
299cdf0e10cSrcweir     m_bAttemptedInitialize = false;
300cdf0e10cSrcweir 
301cdf0e10cSrcweir     impl_unloadModule();
302cdf0e10cSrcweir }
303cdf0e10cSrcweir 
304cdf0e10cSrcweir // =======================================================================
305cdf0e10cSrcweir // = KabDriver
306cdf0e10cSrcweir // =======================================================================
KabDriver(const Reference<::com::sun::star::lang::XMultiServiceFactory> & _rxFactory)307cdf0e10cSrcweir KabDriver::KabDriver(
308cdf0e10cSrcweir 	const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory)
309cdf0e10cSrcweir 	: KDriver_BASE(m_aMutex),
310cdf0e10cSrcweir 	  m_xMSFactory(_rxFactory),
311cdf0e10cSrcweir       m_aImplModule(_rxFactory)
312cdf0e10cSrcweir {
313cdf0e10cSrcweir     if ( !m_xMSFactory.is() )
314cdf0e10cSrcweir         throw NullPointerException();
315cdf0e10cSrcweir 
316cdf0e10cSrcweir     osl_incrementInterlockedCount( &m_refCount );
317cdf0e10cSrcweir     try
318cdf0e10cSrcweir     {
319cdf0e10cSrcweir         Reference< XDesktop > xDesktop(
320cdf0e10cSrcweir             m_xMSFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" ) ) ),
321cdf0e10cSrcweir             UNO_QUERY_THROW );
322cdf0e10cSrcweir         xDesktop->addTerminateListener( this );
323cdf0e10cSrcweir     }
324cdf0e10cSrcweir     catch( const Exception& )
325cdf0e10cSrcweir     {
326cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
327cdf0e10cSrcweir     }
328cdf0e10cSrcweir     osl_decrementInterlockedCount( &m_refCount );
329cdf0e10cSrcweir }
330cdf0e10cSrcweir // --------------------------------------------------------------------------------
disposing()331cdf0e10cSrcweir void KabDriver::disposing()
332cdf0e10cSrcweir {
333cdf0e10cSrcweir 	::osl::MutexGuard aGuard(m_aMutex);
334cdf0e10cSrcweir 
335cdf0e10cSrcweir 	// when driver will be destroied so all our connections have to be destroied as well
336cdf0e10cSrcweir 	for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i)
337cdf0e10cSrcweir 	{
338cdf0e10cSrcweir 		Reference< XComponent > xComp(i->get(), UNO_QUERY);
339cdf0e10cSrcweir 		if (xComp.is())
340cdf0e10cSrcweir 			xComp->dispose();
341cdf0e10cSrcweir 	}
342cdf0e10cSrcweir 	m_xConnections.clear();
343cdf0e10cSrcweir 
344cdf0e10cSrcweir 	WeakComponentImplHelperBase::disposing();
345cdf0e10cSrcweir }
346cdf0e10cSrcweir // static ServiceInfo
347cdf0e10cSrcweir //------------------------------------------------------------------------------
getImplementationName_Static()348cdf0e10cSrcweir rtl::OUString KabDriver::getImplementationName_Static(  ) throw(RuntimeException)
349cdf0e10cSrcweir {
350cdf0e10cSrcweir     return rtl::OUString::createFromAscii( impl_getAsciiImplementationName() );
351cdf0e10cSrcweir }
352cdf0e10cSrcweir //------------------------------------------------------------------------------
getSupportedServiceNames_Static()353cdf0e10cSrcweir Sequence< ::rtl::OUString > KabDriver::getSupportedServiceNames_Static(  ) throw (RuntimeException)
354cdf0e10cSrcweir {
355cdf0e10cSrcweir 	// which service is supported
356cdf0e10cSrcweir 	// for more information @see com.sun.star.sdbc.Driver
357cdf0e10cSrcweir 	Sequence< ::rtl::OUString > aSNS( 1 );
358cdf0e10cSrcweir 	aSNS[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.Driver");
359cdf0e10cSrcweir 
360cdf0e10cSrcweir 	return aSNS;
361cdf0e10cSrcweir }
362cdf0e10cSrcweir //------------------------------------------------------------------
getImplementationName()363cdf0e10cSrcweir ::rtl::OUString SAL_CALL KabDriver::getImplementationName(  ) throw(RuntimeException)
364cdf0e10cSrcweir {
365cdf0e10cSrcweir 	return getImplementationName_Static();
366cdf0e10cSrcweir }
367cdf0e10cSrcweir //------------------------------------------------------------------
supportsService(const::rtl::OUString & _rServiceName)368cdf0e10cSrcweir sal_Bool SAL_CALL KabDriver::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
369cdf0e10cSrcweir {
370cdf0e10cSrcweir 	Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
371cdf0e10cSrcweir 	const ::rtl::OUString* pSupported = aSupported.getConstArray();
372cdf0e10cSrcweir 	const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
373cdf0e10cSrcweir 
374cdf0e10cSrcweir 	while (pSupported != pEnd && !pSupported->equals(_rServiceName))
375cdf0e10cSrcweir 		++pSupported;
376cdf0e10cSrcweir 	return pSupported != pEnd;
377cdf0e10cSrcweir }
378cdf0e10cSrcweir //------------------------------------------------------------------
getSupportedServiceNames()379cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL KabDriver::getSupportedServiceNames(  ) throw(RuntimeException)
380cdf0e10cSrcweir {
381cdf0e10cSrcweir 	return getSupportedServiceNames_Static();
382cdf0e10cSrcweir }
383cdf0e10cSrcweir // --------------------------------------------------------------------------------
connect(const::rtl::OUString & url,const Sequence<PropertyValue> & info)384cdf0e10cSrcweir Reference< XConnection > SAL_CALL KabDriver::connect( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
385cdf0e10cSrcweir {
386cdf0e10cSrcweir     ::osl::MutexGuard aGuard(m_aMutex);
387cdf0e10cSrcweir 
388cdf0e10cSrcweir     m_aImplModule.init();
389cdf0e10cSrcweir 
390cdf0e10cSrcweir     // create a new connection with the given properties and append it to our vector
391cdf0e10cSrcweir     KabConnection* pConnection = m_aImplModule.createConnection( this );
392cdf0e10cSrcweir     OSL_POSTCOND( pConnection, "KabDriver::connect: no connection has been created by the factory!" );
393cdf0e10cSrcweir 
394cdf0e10cSrcweir     // by definition, the factory function returned an object which was acquired once
395cdf0e10cSrcweir     Reference< XConnection > xConnection = pConnection;
396cdf0e10cSrcweir     pConnection->release();
397cdf0e10cSrcweir 
398cdf0e10cSrcweir     // late constructor call which can throw exception and allows a correct dtor call when so
399cdf0e10cSrcweir     pConnection->construct( url, info );
400cdf0e10cSrcweir 
401cdf0e10cSrcweir     // remember it
402cdf0e10cSrcweir     m_xConnections.push_back( WeakReferenceHelper( *pConnection ) );
403cdf0e10cSrcweir 
404cdf0e10cSrcweir     return xConnection;
405cdf0e10cSrcweir }
406cdf0e10cSrcweir // --------------------------------------------------------------------------------
acceptsURL(const::rtl::OUString & url)407cdf0e10cSrcweir sal_Bool SAL_CALL KabDriver::acceptsURL( const ::rtl::OUString& url )
408cdf0e10cSrcweir 		throw(SQLException, RuntimeException)
409cdf0e10cSrcweir {
410cdf0e10cSrcweir     ::osl::MutexGuard aGuard(m_aMutex);
411cdf0e10cSrcweir 
412cdf0e10cSrcweir     if ( !m_aImplModule.isKDEPresent() )
413cdf0e10cSrcweir         return sal_False;
414cdf0e10cSrcweir 
415cdf0e10cSrcweir 	// here we have to look whether we support this URL format
416cdf0e10cSrcweir 	return (!url.compareTo(::rtl::OUString::createFromAscii("sdbc:address:kab:"), 16));
417cdf0e10cSrcweir }
418cdf0e10cSrcweir // --------------------------------------------------------------------------------
getPropertyInfo(const::rtl::OUString &,const Sequence<PropertyValue> &)419cdf0e10cSrcweir Sequence< DriverPropertyInfo > SAL_CALL KabDriver::getPropertyInfo( const ::rtl::OUString&, const Sequence< PropertyValue >& ) throw(SQLException, RuntimeException)
420cdf0e10cSrcweir {
421cdf0e10cSrcweir 	// if you have something special to say, return it here :-)
422cdf0e10cSrcweir 	return Sequence< DriverPropertyInfo >();
423cdf0e10cSrcweir }
424cdf0e10cSrcweir // --------------------------------------------------------------------------------
getMajorVersion()425cdf0e10cSrcweir sal_Int32 SAL_CALL KabDriver::getMajorVersion(  ) throw(RuntimeException)
426cdf0e10cSrcweir {
427cdf0e10cSrcweir 	return KAB_DRIVER_VERSION_MAJOR;
428cdf0e10cSrcweir }
429cdf0e10cSrcweir // --------------------------------------------------------------------------------
getMinorVersion()430cdf0e10cSrcweir sal_Int32 SAL_CALL KabDriver::getMinorVersion(  ) throw(RuntimeException)
431cdf0e10cSrcweir {
432cdf0e10cSrcweir 	return KAB_DRIVER_VERSION_MINOR;
433cdf0e10cSrcweir }
434cdf0e10cSrcweir // --------------------------------------------------------------------------------
queryTermination(const EventObject &)435cdf0e10cSrcweir void SAL_CALL KabDriver::queryTermination( const EventObject& ) throw (TerminationVetoException, RuntimeException)
436cdf0e10cSrcweir {
437cdf0e10cSrcweir     // nothing to do, nothing to veto
438cdf0e10cSrcweir }
439cdf0e10cSrcweir // --------------------------------------------------------------------------------
notifyTermination(const EventObject &)440cdf0e10cSrcweir void SAL_CALL KabDriver::notifyTermination( const EventObject& ) throw (RuntimeException)
441cdf0e10cSrcweir {
442cdf0e10cSrcweir     m_aImplModule.shutdown();
443cdf0e10cSrcweir }
444cdf0e10cSrcweir // --------------------------------------------------------------------------------
disposing(const EventObject &)445cdf0e10cSrcweir void SAL_CALL KabDriver::disposing( const EventObject& ) throw (RuntimeException)
446cdf0e10cSrcweir {
447cdf0e10cSrcweir     // not interested in (this is the disposing of the desktop, if any)
448cdf0e10cSrcweir }
449cdf0e10cSrcweir // --------------------------------------------------------------------------------
impl_getAsciiImplementationName()450cdf0e10cSrcweir const sal_Char* KabDriver::impl_getAsciiImplementationName()
451cdf0e10cSrcweir {
452cdf0e10cSrcweir 	return "com.sun.star.comp.sdbc.kab.Driver";
453cdf0e10cSrcweir 		// this name is referenced in the configuration and in the kab.xml
454cdf0e10cSrcweir 		// Please be careful when changing it.
455cdf0e10cSrcweir }
456cdf0e10cSrcweir // --------------------------------------------------------------------------------
impl_getConfigurationSettingsPath()457cdf0e10cSrcweir ::rtl::OUString KabDriver::impl_getConfigurationSettingsPath()
458cdf0e10cSrcweir {
459cdf0e10cSrcweir     ::rtl::OUStringBuffer aPath;
460cdf0e10cSrcweir     aPath.appendAscii( "/org.openoffice.Office.DataAccess/DriverSettings/" );
461cdf0e10cSrcweir     aPath.appendAscii( "com.sun.star.comp.sdbc.kab.Driver" );
462cdf0e10cSrcweir     return aPath.makeStringAndClear();
463cdf0e10cSrcweir }
464cdf0e10cSrcweir // --------------------------------------------------------------------------------
Create(const Reference<XMultiServiceFactory> & _rxFactory)465cdf0e10cSrcweir Reference< XInterface >  SAL_CALL KabDriver::Create( const Reference< XMultiServiceFactory >& _rxFactory ) throw( Exception )
466cdf0e10cSrcweir {
467cdf0e10cSrcweir     return *(new KabDriver(_rxFactory));
468cdf0e10cSrcweir }
469cdf0e10cSrcweir 
470