1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <cppuhelper/supportsservice.hxx>
25 #include <com/sun/star/ucb/XContentAccess.hpp>
26 #include <rtl/ref.hxx>
27 #include <strings.hrc>
28 #include <resource/sharedresources.hxx>
31 using namespace connectivity::evoab
;
32 using namespace ::com::sun::star::uno
;
33 using namespace ::com::sun::star::beans
;
34 using namespace ::com::sun::star::sdbcx
;
35 using namespace ::com::sun::star::sdbc
;
36 using namespace ::com::sun::star::lang
;
37 using namespace ::com::sun::star::ucb
;
40 OEvoabDriver::OEvoabDriver(const Reference
< XComponentContext
>& _rxContext
) :
41 ODriver_BASE( m_aMutex
), m_xContext( _rxContext
)
45 OEvoabDriver::~OEvoabDriver()
49 void OEvoabDriver::disposing()
51 ::osl::MutexGuard
aGuard(m_aMutex
);
53 // when driver will be destroyed so all our connections have to be destroyed as well
54 for (const auto& rxConnection
: m_xConnections
)
56 Reference
< XComponent
> xComp(rxConnection
.get(), UNO_QUERY
);
63 catch (const css::lang::DisposedException
&)
69 m_xConnections
.clear();
70 connectivity::OWeakRefArray().swap(m_xConnections
); // this really clears
72 ODriver_BASE::disposing();
78 OUString SAL_CALL
OEvoabDriver::getImplementationName( )
80 return EVOAB_DRIVER_IMPL_NAME
;
81 // this name is referenced in the configuration and in the evoab.xml
82 // Please take care when changing it.
85 sal_Bool SAL_CALL
OEvoabDriver::supportsService( const OUString
& _rServiceName
)
87 return cppu::supportsService(this, _rServiceName
);
90 Sequence
< OUString
> SAL_CALL
OEvoabDriver::getSupportedServiceNames( )
92 // which service is supported
93 // for more information @see com.sun.star.sdbc.Driver
94 return { "com.sun.star.sdbc.Driver" };
98 Reference
< XConnection
> SAL_CALL
OEvoabDriver::connect( const OUString
& url
, const Sequence
< PropertyValue
>& info
)
100 ::osl::MutexGuard
aGuard( m_aMutex
);
101 if (ODriver_BASE::rBHelper
.bDisposed
)
102 throw DisposedException();
104 if ( ! acceptsURL(url
) )
107 rtl::Reference
<OEvoabConnection
> pCon
= new OEvoabConnection( *this );
108 pCon
->construct(url
,info
);
109 m_xConnections
.push_back(WeakReferenceHelper(*pCon
));
114 sal_Bool SAL_CALL
OEvoabDriver::acceptsURL( const OUString
& url
)
116 return acceptsURL_Stat(url
);
120 Sequence
< DriverPropertyInfo
> SAL_CALL
OEvoabDriver::getPropertyInfo( const OUString
& url
, const Sequence
< PropertyValue
>& /*info*/ )
122 if ( ! acceptsURL(url
) )
124 ::connectivity::SharedResources aResources
;
125 const OUString sMessage
= aResources
.getResourceString(STR_URI_SYNTAX_ERROR
);
126 ::dbtools::throwGenericSQLException(sMessage
,*this);
127 } // if ( ! acceptsURL(url) )
129 // if you have something special to say return it here :-)
130 return Sequence
< DriverPropertyInfo
>();
134 sal_Int32 SAL_CALL
OEvoabDriver::getMajorVersion( )
139 sal_Int32 SAL_CALL
OEvoabDriver::getMinorVersion( )
144 bool OEvoabDriver::acceptsURL_Stat( std::u16string_view url
)
146 return ( url
== u
"sdbc:address:evolution:local" || url
== u
"sdbc:address:evolution:groupwise" || url
== u
"sdbc:address:evolution:ldap" ) && EApiInit();
150 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
151 connectivity_OEvoabDriver_get_implementation(
152 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const&)
154 return cppu::acquire(new OEvoabDriver(context
));
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */