bump product version to 4.1.6.2
[LibreOffice.git] / connectivity / source / drivers / evoab2 / NDriver.cxx
blob601a111630c58b81338a1919af26839f435de7a6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "NDriver.hxx"
21 #include "NConnection.hxx"
22 #include <com/sun/star/lang/DisposedException.hpp>
23 #include "connectivity/dbexception.hxx"
24 #include <osl/file.hxx>
25 #include "osl/security.hxx"
26 #include <comphelper/processfactory.hxx>
27 #include <com/sun/star/ucb/XContentAccess.hpp>
28 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
29 #include <ucbhelper/content.hxx>
30 #include <signal.h>
31 #include "resource/common_res.hrc"
32 #include "resource/sharedresources.hxx"
34 using namespace osl;
35 using namespace connectivity::evoab;
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::beans;
38 using namespace ::com::sun::star::sdbcx;
39 using namespace ::com::sun::star::sdbc;
40 using namespace ::com::sun::star::lang;
41 using namespace ::com::sun::star::ucb;
43 // --------------------------------------------------------------------------------
44 OEvoabDriver::OEvoabDriver(const Reference< XMultiServiceFactory >& _rxFactory) :
45 ODriver_BASE( m_aMutex ), m_xFactory( _rxFactory )
48 // -----------------------------------------------------------------------------
49 OEvoabDriver::~OEvoabDriver()
52 // -----------------------------------------------------------------------------
53 void OEvoabDriver::disposing()
55 ::osl::MutexGuard aGuard(m_aMutex);
57 // when driver will be destroied so all our connections have to be destroied as well
58 for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i)
60 Reference< XComponent > xComp(i->get(), UNO_QUERY);
61 if (xComp.is())
63 try
65 xComp->dispose();
67 catch (const com::sun::star::lang::DisposedException&)
69 xComp.clear();
73 m_xConnections.clear();
74 connectivity::OWeakRefArray().swap(m_xConnections); // this really clears
76 ODriver_BASE::disposing();
79 // static ServiceInfo
80 //------------------------------------------------------------------------------
81 OUString OEvoabDriver::getImplementationName_Static( ) throw(RuntimeException)
83 return OUString(EVOAB_DRIVER_IMPL_NAME);
84 // this name is referenced in the configuration and in the evoab.xml
85 // Please take care when changing it.
88 //------------------------------------------------------------------
89 Sequence< OUString > OEvoabDriver::getSupportedServiceNames_Static( ) throw (RuntimeException)
91 // which service is supported
92 // for more information @see com.sun.star.sdbc.Driver
93 Sequence< OUString > aSNS( 1 );
94 aSNS[0] = OUString("com.sun.star.sdbc.Driver");
95 return aSNS;
97 //------------------------------------------------------------------
98 OUString SAL_CALL OEvoabDriver::getImplementationName( ) throw(RuntimeException)
100 return getImplementationName_Static();
102 //------------------------------------------------------------------
103 sal_Bool SAL_CALL OEvoabDriver::supportsService( const OUString& _rServiceName ) throw(RuntimeException)
105 Sequence< OUString > aSupported(getSupportedServiceNames());
106 const OUString* pSupported = aSupported.getConstArray();
107 const OUString* pEnd = pSupported + aSupported.getLength();
108 for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
111 return pSupported != pEnd;
113 //------------------------------------------------------------------
114 Sequence< OUString > SAL_CALL OEvoabDriver::getSupportedServiceNames( ) throw(RuntimeException)
116 return getSupportedServiceNames_Static();
119 //------------------------------------------------------------------
120 ::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 )
122 return *(new OEvoabDriver(_rxFactory));
124 // --------------------------------------------------------------------------------
125 Reference< XConnection > SAL_CALL OEvoabDriver::connect( const OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
127 ::osl::MutexGuard aGuard( m_aMutex );
128 if (ODriver_BASE::rBHelper.bDisposed)
129 throw DisposedException();
131 if ( ! acceptsURL(url) )
132 return NULL;
134 OEvoabConnection* pCon = new OEvoabConnection( *this );
135 pCon->construct(url,info);
136 Reference< XConnection > xCon = pCon;
137 m_xConnections.push_back(WeakReferenceHelper(*pCon));
139 return xCon;
141 // --------------------------------------------------------------------------------
142 sal_Bool SAL_CALL OEvoabDriver::acceptsURL( const OUString& url )
143 throw(SQLException, RuntimeException)
145 return acceptsURL_Stat(url);
148 // --------------------------------------------------------------------------------
149 Sequence< DriverPropertyInfo > SAL_CALL OEvoabDriver::getPropertyInfo( const OUString& url, const Sequence< PropertyValue >& /*info*/ ) throw(SQLException, RuntimeException)
151 if ( ! acceptsURL(url) )
153 ::connectivity::SharedResources aResources;
154 const OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
155 ::dbtools::throwGenericSQLException(sMessage ,*this);
156 } // if ( ! acceptsURL(url) )
158 // if you have something special to say return it here :-)
159 return Sequence< DriverPropertyInfo >();
162 // --------------------------------------------------------------------------------
163 sal_Int32 SAL_CALL OEvoabDriver::getMajorVersion( ) throw(RuntimeException)
165 return 1;
167 // --------------------------------------------------------------------------------
168 sal_Int32 SAL_CALL OEvoabDriver::getMinorVersion( ) throw(RuntimeException)
170 return 0;
172 // --------------------------------------------------------------------------------
173 sal_Bool OEvoabDriver::acceptsURL_Stat( const OUString& url )
175 return ( url == "sdbc:address:evolution:local" || url == "sdbc:address:evolution:groupwise" || url == "sdbc:address:evolution:ldap" ) && EApiInit();
177 // -----------------------------------------------------------------------------
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */