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