LibreOffice Module connectivity (master) 1
NDriver.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "NDriver.hxx"
21#include "NConnection.hxx"
22#include <com/sun/star/lang/DisposedException.hpp>
25#include <com/sun/star/ucb/XContentAccess.hpp>
26#include <rtl/ref.hxx>
27#include <strings.hrc>
29
30using namespace osl;
31using namespace connectivity::evoab;
32using namespace ::com::sun::star::uno;
33using namespace ::com::sun::star::beans;
34using namespace ::com::sun::star::sdbcx;
35using namespace ::com::sun::star::sdbc;
36using namespace ::com::sun::star::lang;
37using namespace ::com::sun::star::ucb;
38
39
40OEvoabDriver::OEvoabDriver(const Reference< XComponentContext >& _rxContext) :
41 ODriver_BASE( m_aMutex ), m_xContext( _rxContext )
42{
43}
44
46{
47}
48
50{
51 ::osl::MutexGuard aGuard(m_aMutex);
52
53 // when driver will be destroyed so all our connections have to be destroyed as well
54 for (const auto& rxConnection : m_xConnections)
55 {
56 Reference< XComponent > xComp(rxConnection.get(), UNO_QUERY);
57 if (xComp.is())
58 {
59 try
60 {
61 xComp->dispose();
62 }
63 catch (const css::lang::DisposedException&)
64 {
65 xComp.clear();
66 }
67 }
68 }
69 m_xConnections.clear();
70 connectivity::OWeakRefArray().swap(m_xConnections); // this really clears
71
72 ODriver_BASE::disposing();
73}
74
75// static ServiceInfo
76
77
79{
81 // this name is referenced in the configuration and in the evoab.xml
82 // Please take care when changing it.
83}
84
85sal_Bool SAL_CALL OEvoabDriver::supportsService( const OUString& _rServiceName )
86{
87 return cppu::supportsService(this, _rServiceName);
88}
89
91{
92 // which service is supported
93 // for more information @see com.sun.star.sdbc.Driver
94 return { "com.sun.star.sdbc.Driver" };
95}
96
97
99{
100 ::osl::MutexGuard aGuard( m_aMutex );
101 if (ODriver_BASE::rBHelper.bDisposed)
102 throw DisposedException();
103
104 if ( ! acceptsURL(url) )
105 return nullptr;
106
108 pCon->construct(url,info);
109 m_xConnections.push_back(WeakReferenceHelper(*pCon));
110
111 return pCon;
112}
113
114sal_Bool SAL_CALL OEvoabDriver::acceptsURL( const OUString& url )
115{
116 return acceptsURL_Stat(url);
117}
118
119
121{
122 if ( ! acceptsURL(url) )
123 {
125 const OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
127 } // if ( ! acceptsURL(url) )
128
129 // if you have something special to say return it here :-)
131}
132
133
134sal_Int32 SAL_CALL OEvoabDriver::getMajorVersion( )
135{
136 return 1;
137}
138
139sal_Int32 SAL_CALL OEvoabDriver::getMinorVersion( )
140{
141 return 0;
142}
143
144bool OEvoabDriver::acceptsURL_Stat( std::u16string_view url )
145{
146 return ( url == u"sdbc:address:evolution:local" || url == u"sdbc:address:evolution:groupwise" || url == u"sdbc:address:evolution:ldap" ) && EApiInit();
147}
148
149
150extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
152 css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&)
153{
154 return cppu::acquire(new OEvoabDriver(context));
155}
156
157/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool EApiInit()
Definition: EApi.cxx:104
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * connectivity_OEvoabDriver_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Definition: NDriver.cxx:151
constexpr OUStringLiteral EVOAB_DRIVER_IMPL_NAME
Definition: NDriver.hxx:31
Reference< XComponentContext > m_xContext
helper class for accessing resources shared by different libraries in the connectivity module
OUString getResourceString(TranslateId pResId) const
loads a string from the shared resource file
virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL connect(const OUString &url, const css::uno::Sequence< css::beans::PropertyValue > &info) override
Definition: NDriver.cxx:98
virtual sal_Int32 SAL_CALL getMajorVersion() override
Definition: NDriver.cxx:134
virtual css::uno::Sequence< css::sdbc::DriverPropertyInfo > SAL_CALL getPropertyInfo(const OUString &url, const css::uno::Sequence< css::beans::PropertyValue > &info) override
Definition: NDriver.cxx:120
static bool acceptsURL_Stat(std::u16string_view url)
Definition: NDriver.cxx:144
connectivity::OWeakRefArray m_xConnections
Definition: NDriver.hxx:42
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: NDriver.cxx:85
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: NDriver.cxx:90
virtual ~OEvoabDriver() override
Definition: NDriver.cxx:45
virtual void SAL_CALL disposing() override
Definition: NDriver.cxx:49
virtual sal_Bool SAL_CALL acceptsURL(const OUString &url) override
Definition: NDriver.cxx:114
virtual sal_Int32 SAL_CALL getMinorVersion() override
Definition: NDriver.cxx:139
virtual OUString SAL_CALL getImplementationName() override
Definition: NDriver.cxx:78
float u
std::mutex m_aMutex
::cppu::WeakComponentImplHelper< css::sdbc::XDriver, css::lang::XServiceInfo > ODriver_BASE
Definition: NDriver.hxx:36
std::vector< css::uno::WeakReferenceHelper > OWeakRefArray
Definition: CommonTools.hxx:53
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
void throwGenericSQLException(const OUString &_rMsg, const css::uno::Reference< css::uno::XInterface > &_rxSource)
throw a generic SQLException, i.e.
OUString sMessage
unsigned char sal_Bool