1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_connectivity.hxx" 30 #include "NDriver.hxx" 31 #include "NConnection.hxx" 32 #include <com/sun/star/lang/DisposedException.hpp> 33 #include "connectivity/dbexception.hxx" 34 //#ifndef _CONNECTIVITY_EVOAB_CONFIGACCESS_HXX_ 35 //#include "LConfigAccess.hxx" 36 //#endif 37 #include <osl/file.hxx> 38 #include "osl/security.hxx" 39 #include <comphelper/processfactory.hxx> 40 #include <com/sun/star/ucb/XContentAccess.hpp> 41 #include <com/sun/star/ucb/XCommandEnvironment.hpp> 42 #include <ucbhelper/content.hxx> 43 #include <tools/debug.hxx> 44 #include "NDebug.hxx" 45 #include <signal.h> 46 #include "resource/common_res.hrc" 47 #include "resource/sharedresources.hxx" 48 49 using namespace osl; 50 using namespace connectivity::evoab; 51 //using namespace connectivity::file; 52 using namespace ::com::sun::star::uno; 53 using namespace ::com::sun::star::beans; 54 using namespace ::com::sun::star::sdbcx; 55 using namespace ::com::sun::star::sdbc; 56 using namespace ::com::sun::star::lang; 57 using namespace ::com::sun::star::ucb; 58 59 // -------------------------------------------------------------------------------- 60 OEvoabDriver::OEvoabDriver(const Reference< XMultiServiceFactory >& _rxFactory) : 61 ODriver_BASE( m_aMutex ), m_xFactory( _rxFactory ) 62 { 63 } 64 // ----------------------------------------------------------------------------- 65 OEvoabDriver::~OEvoabDriver() 66 { 67 } 68 // ----------------------------------------------------------------------------- 69 void OEvoabDriver::disposing() 70 { 71 ::osl::MutexGuard aGuard(m_aMutex); 72 73 // when driver will be destroied so all our connections have to be destroied as well 74 for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i) 75 { 76 Reference< XComponent > xComp(i->get(), UNO_QUERY); 77 if (xComp.is()) { 78 try { 79 xComp->dispose(); 80 } 81 catch (com::sun::star::lang::DisposedException e) { 82 xComp.clear(); 83 } 84 } 85 } 86 m_xConnections.clear(); 87 connectivity::OWeakRefArray().swap(m_xConnections); // this really clears 88 89 ODriver_BASE::disposing(); 90 } 91 92 // static ServiceInfo 93 //------------------------------------------------------------------------------ 94 rtl::OUString OEvoabDriver::getImplementationName_Static( ) throw(RuntimeException) 95 { 96 return rtl::OUString::createFromAscii(EVOAB_DRIVER_IMPL_NAME); 97 // this name is referenced in the configuration and in the evoab.xml 98 // Please take care when changing it. 99 } 100 101 //------------------------------------------------------------------ 102 Sequence< ::rtl::OUString > OEvoabDriver::getSupportedServiceNames_Static( ) throw (RuntimeException) 103 { 104 // which service is supported 105 // for more information @see com.sun.star.sdbc.Driver 106 Sequence< ::rtl::OUString > aSNS( 1 ); 107 aSNS[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.Driver"); 108 return aSNS; 109 } 110 //------------------------------------------------------------------ 111 ::rtl::OUString SAL_CALL OEvoabDriver::getImplementationName( ) throw(RuntimeException) 112 { 113 return getImplementationName_Static(); 114 } 115 //------------------------------------------------------------------ 116 sal_Bool SAL_CALL OEvoabDriver::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException) 117 { 118 Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames()); 119 const ::rtl::OUString* pSupported = aSupported.getConstArray(); 120 const ::rtl::OUString* pEnd = pSupported + aSupported.getLength(); 121 for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported) 122 ; 123 124 return pSupported != pEnd; 125 } 126 //------------------------------------------------------------------ 127 Sequence< ::rtl::OUString > SAL_CALL OEvoabDriver::getSupportedServiceNames( ) throw(RuntimeException) 128 { 129 return getSupportedServiceNames_Static(); 130 } 131 132 //------------------------------------------------------------------ 133 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL connectivity::evoab::OEvoabDriver_CreateInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) throw( ::com::sun::star::uno::Exception ) 134 { 135 return *(new OEvoabDriver(_rxFactory)); 136 } 137 // -------------------------------------------------------------------------------- 138 Reference< XConnection > SAL_CALL OEvoabDriver::connect( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException) 139 { 140 ::osl::MutexGuard aGuard( m_aMutex ); 141 if (ODriver_BASE::rBHelper.bDisposed) 142 throw DisposedException(); 143 144 if ( ! acceptsURL(url) ) 145 return NULL; 146 147 OEvoabConnection* pCon = new OEvoabConnection( *this ); 148 pCon->construct(url,info); 149 Reference< XConnection > xCon = pCon; 150 m_xConnections.push_back(WeakReferenceHelper(*pCon)); 151 152 return xCon; 153 } 154 // -------------------------------------------------------------------------------- 155 sal_Bool SAL_CALL OEvoabDriver::acceptsURL( const ::rtl::OUString& url ) 156 throw(SQLException, RuntimeException) 157 { 158 return acceptsURL_Stat(url); 159 } 160 161 // -------------------------------------------------------------------------------- 162 Sequence< DriverPropertyInfo > SAL_CALL OEvoabDriver::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& /*info*/ ) throw(SQLException, RuntimeException) 163 { 164 if ( ! acceptsURL(url) ) 165 { 166 ::connectivity::SharedResources aResources; 167 const ::rtl::OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR); 168 ::dbtools::throwGenericSQLException(sMessage ,*this); 169 } // if ( ! acceptsURL(url) ) 170 171 // if you have somthing special to say return it here :-) 172 return Sequence< DriverPropertyInfo >(); 173 } 174 175 // -------------------------------------------------------------------------------- 176 sal_Int32 SAL_CALL OEvoabDriver::getMajorVersion( ) throw(RuntimeException) 177 { 178 return 1; 179 } 180 // -------------------------------------------------------------------------------- 181 sal_Int32 SAL_CALL OEvoabDriver::getMinorVersion( ) throw(RuntimeException) 182 { 183 return 0; 184 } 185 // -------------------------------------------------------------------------------- 186 sal_Bool OEvoabDriver::acceptsURL_Stat( const ::rtl::OUString& url ) 187 { 188 return (url.equalsAscii("sdbc:address:evolution:local") || url.equalsAscii("sdbc:address:evolution:groupwise")||url.equalsAscii("sdbc:address:evolution:ldap"))&& EApiInit(); 189 } 190 // ----------------------------------------------------------------------------- 191