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::sdbc
;
35 using namespace ::com::sun::star::lang
;
38 OEvoabDriver::OEvoabDriver(const Reference
< XComponentContext
>& _rxContext
) :
39 ODriver_BASE( m_aMutex
), m_xContext( _rxContext
)
43 OEvoabDriver::~OEvoabDriver()
47 void OEvoabDriver::disposing()
49 ::osl::MutexGuard
aGuard(m_aMutex
);
51 // when driver will be destroyed so all our connections have to be destroyed as well
52 for (const auto& rxConnection
: m_xConnections
)
54 Reference
< XComponent
> xComp(rxConnection
.get(), UNO_QUERY
);
61 catch (const css::lang::DisposedException
&)
67 m_xConnections
.clear();
68 connectivity::OWeakRefArray().swap(m_xConnections
); // this really clears
70 ODriver_BASE::disposing();
76 OUString SAL_CALL
OEvoabDriver::getImplementationName( )
78 return EVOAB_DRIVER_IMPL_NAME
;
79 // this name is referenced in the configuration and in the evoab.xml
80 // Please take care when changing it.
83 sal_Bool SAL_CALL
OEvoabDriver::supportsService( const OUString
& _rServiceName
)
85 return cppu::supportsService(this, _rServiceName
);
88 Sequence
< OUString
> SAL_CALL
OEvoabDriver::getSupportedServiceNames( )
90 // which service is supported
91 // for more information @see com.sun.star.sdbc.Driver
92 return { u
"com.sun.star.sdbc.Driver"_ustr
};
96 Reference
< XConnection
> SAL_CALL
OEvoabDriver::connect( const OUString
& url
, const Sequence
< PropertyValue
>& info
)
98 ::osl::MutexGuard
aGuard( m_aMutex
);
99 if (ODriver_BASE::rBHelper
.bDisposed
)
100 throw DisposedException();
102 if ( ! acceptsURL(url
) )
105 rtl::Reference
<OEvoabConnection
> pCon
= new OEvoabConnection( *this );
106 pCon
->construct(url
,info
);
107 m_xConnections
.push_back(WeakReferenceHelper(*pCon
));
112 sal_Bool SAL_CALL
OEvoabDriver::acceptsURL( const OUString
& url
)
114 return acceptsURL_Stat(url
);
118 Sequence
< DriverPropertyInfo
> SAL_CALL
OEvoabDriver::getPropertyInfo( const OUString
& url
, const Sequence
< PropertyValue
>& /*info*/ )
120 if ( ! acceptsURL(url
) )
122 ::connectivity::SharedResources aResources
;
123 const OUString sMessage
= aResources
.getResourceString(STR_URI_SYNTAX_ERROR
);
124 ::dbtools::throwGenericSQLException(sMessage
,*this);
125 } // if ( ! acceptsURL(url) )
127 // if you have something special to say return it here :-)
128 return Sequence
< DriverPropertyInfo
>();
132 sal_Int32 SAL_CALL
OEvoabDriver::getMajorVersion( )
137 sal_Int32 SAL_CALL
OEvoabDriver::getMinorVersion( )
142 bool OEvoabDriver::acceptsURL_Stat( std::u16string_view url
)
144 return ( url
== u
"sdbc:address:evolution:local" || url
== u
"sdbc:address:evolution:groupwise" || url
== u
"sdbc:address:evolution:ldap" ) && EApiInit();
148 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
149 connectivity_OEvoabDriver_get_implementation(
150 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const&)
152 return cppu::acquire(new OEvoabDriver(context
));
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */