connectivity: create instances with uno constructors

See tdf#74608 for motivation.

Change-Id: Id678e4c51459429dd3953c0e54558d2c36e85eee
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98562
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
diff --git a/connectivity/Library_calc.mk b/connectivity/Library_calc.mk
index 1741d01..b751ce1 100644
--- a/connectivity/Library_calc.mk
+++ b/connectivity/Library_calc.mk
@@ -44,7 +44,6 @@ $(eval $(call gb_Library_add_exception_objects,calc,\
	connectivity/source/drivers/calc/CTable \
	connectivity/source/drivers/calc/CTables \
	connectivity/source/drivers/calc/CConnection \
	connectivity/source/drivers/calc/Cservices \
	connectivity/source/drivers/calc/CDriver \
))

diff --git a/connectivity/Library_dbase.mk b/connectivity/Library_dbase.mk
index 6f89739..ff1d703 100644
--- a/connectivity/Library_dbase.mk
+++ b/connectivity/Library_dbase.mk
@@ -54,7 +54,6 @@ $(eval $(call gb_Library_add_exception_objects,dbase,\
	connectivity/source/drivers/dbase/DIndexes \
	connectivity/source/drivers/dbase/DTables \
	connectivity/source/drivers/dbase/DConnection \
	connectivity/source/drivers/dbase/Dservices \
	connectivity/source/drivers/dbase/DDriver \
	connectivity/source/drivers/dbase/DTable \
))
diff --git a/connectivity/Library_flat.mk b/connectivity/Library_flat.mk
index c37b6ae..77e2dee 100644
--- a/connectivity/Library_flat.mk
+++ b/connectivity/Library_flat.mk
@@ -49,7 +49,6 @@ $(eval $(call gb_Library_add_exception_objects,flat,\
	connectivity/source/drivers/flat/EColumns \
	connectivity/source/drivers/flat/ETables \
	connectivity/source/drivers/flat/EConnection \
	connectivity/source/drivers/flat/Eservices \
	connectivity/source/drivers/flat/EDriver \
))

diff --git a/connectivity/Library_writer.mk b/connectivity/Library_writer.mk
index d07f572..242d684 100644
--- a/connectivity/Library_writer.mk
+++ b/connectivity/Library_writer.mk
@@ -43,7 +43,6 @@ $(eval $(call gb_Library_add_exception_objects,writer,\
	connectivity/source/drivers/writer/WDriver \
	connectivity/source/drivers/writer/WTable \
	connectivity/source/drivers/writer/WTables \
	connectivity/source/drivers/writer/Wservices \
))

# vim: set noet sw=4 ts=4:
diff --git a/connectivity/source/drivers/calc/CDriver.cxx b/connectivity/source/drivers/calc/CDriver.cxx
index 3b53ebc..5a59515b 100644
--- a/connectivity/source/drivers/calc/CDriver.cxx
+++ b/connectivity/source/drivers/calc/CDriver.cxx
@@ -34,28 +34,31 @@ using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::lang;


// static ServiceInfo
// ServiceInfo

OUString ODriver::getImplementationName_Static(  )
OUString SAL_CALL ODriver::getImplementationName(  )
{
    return "com.sun.star.comp.sdbc.calc.ODriver";
}

OUString SAL_CALL ODriver::getImplementationName(  )
{
    return getImplementationName_Static();
}

// service names from file::OFileDriver


css::uno::Reference< css::uno::XInterface >
    connectivity::calc::ODriver_CreateInstance(const css::uno::Reference<
        css::lang::XMultiServiceFactory >& _rxFactory)
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
connectivity_calc_ODriver(
    css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
{
    return *(new ODriver( comphelper::getComponentContext(_rxFactory) ));
    rtl::Reference<ODriver> ret;
    try {
        ret = new ODriver(context);
    } catch (...) {
    }
    if (ret)
        ret->acquire();
    return static_cast<cppu::OWeakObject*>(ret.get());
}



Reference< XConnection > SAL_CALL ODriver::connect( const OUString& url,
    const Sequence< PropertyValue >& info )
{
diff --git a/connectivity/source/drivers/calc/Cservices.cxx b/connectivity/source/drivers/calc/Cservices.cxx
deleted file mode 100644
index 06a516d..0000000
--- a/connectivity/source/drivers/calc/Cservices.cxx
+++ /dev/null
@@ -1,106 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <calc/CDriver.hxx>
#include <cppuhelper/factory.hxx>
#include <com/sun/star/lang/XSingleServiceFactory.hpp>

using namespace connectivity::calc;
using ::com::sun::star::uno::Reference;
using ::com::sun::star::uno::Sequence;
using ::com::sun::star::lang::XSingleServiceFactory;
using ::com::sun::star::lang::XMultiServiceFactory;

typedef Reference< XSingleServiceFactory > (*createFactoryFunc)
        (
            const Reference< XMultiServiceFactory > & rServiceManager,
            const OUString & rComponentName,
            ::cppu::ComponentInstantiation pCreateFunction,
            const Sequence< OUString > & rServiceNames,
            rtl_ModuleCount*
        );

namespace {

struct ProviderRequest
{
    Reference< XSingleServiceFactory > xRet;
    Reference< XMultiServiceFactory > const xServiceManager;
    OUString const sImplementationName;

    ProviderRequest(
        void* pServiceManager,
        char const* pImplementationName
    )
    : xServiceManager(static_cast<XMultiServiceFactory*>(pServiceManager))
    , sImplementationName(OUString::createFromAscii(pImplementationName))
    {
    }

    bool CREATE_PROVIDER(
                const OUString& Implname,
                const Sequence< OUString > & Services,
                ::cppu::ComponentInstantiation Factory,
                createFactoryFunc creator
            )
    {
        if (!xRet.is() && (Implname == sImplementationName))
        {
            try
            {
                xRet = creator( xServiceManager, sImplementationName,Factory, Services,nullptr);
            }
            catch(...)
            {
            }
        }
        return xRet.is();
    }

    void* getProvider() const { return xRet.get(); }
};

}

extern "C" SAL_DLLPUBLIC_EXPORT void* connectivity_calc_component_getFactory(
                    const char* pImplementationName,
                    void* pServiceManager,
                    void* /*pRegistryKey*/)
{
    void* pRet = nullptr;
    if (pServiceManager)
    {
        ProviderRequest aReq(pServiceManager,pImplementationName);

        aReq.CREATE_PROVIDER(
            ODriver::getImplementationName_Static(),
            ODriver::getSupportedServiceNames_Static(),
            ODriver_CreateInstance, ::cppu::createSingleFactory)
        ;

        if(aReq.xRet.is())
            aReq.xRet->acquire();

        pRet = aReq.getProvider();
    }

    return pRet;
};

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/connectivity/source/drivers/calc/calc.component b/connectivity/source/drivers/calc/calc.component
index ffbddfa3..a4fc7d8 100644
--- a/connectivity/source/drivers/calc/calc.component
+++ b/connectivity/source/drivers/calc/calc.component
@@ -18,9 +18,9 @@
 -->

<component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@"
    prefix="connectivity_calc"
    xmlns="http://openoffice.org/2010/uno-components">
  <implementation name="com.sun.star.comp.sdbc.calc.ODriver">
  <implementation name="com.sun.star.comp.sdbc.calc.ODriver"
      constructor="connectivity_calc_ODriver">
    <service name="com.sun.star.sdbc.Driver"/>
    <service name="com.sun.star.sdbcx.Driver"/>
  </implementation>
diff --git a/connectivity/source/drivers/dbase/DDriver.cxx b/connectivity/source/drivers/dbase/DDriver.cxx
index ab2d524..6d3af17 100644
--- a/connectivity/source/drivers/dbase/DDriver.cxx
+++ b/connectivity/source/drivers/dbase/DDriver.cxx
@@ -33,25 +33,29 @@ using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::lang;


// static ServiceInfo
// XServiceInfo

OUString ODriver::getImplementationName_Static(  )
OUString SAL_CALL ODriver::getImplementationName(  )
{
    return "com.sun.star.comp.sdbc.dbase.ODriver";
}


OUString SAL_CALL ODriver::getImplementationName(  )
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
connectivity_dbase_ODriver(
    css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
{
    return getImplementationName_Static();
    rtl::Reference<ODriver> ret;
    try {
        ret = new ODriver(context);
    } catch (...) {
    }
    if (ret)
        ret->acquire();
    return static_cast<cppu::OWeakObject*>(ret.get());
}


css::uno::Reference< css::uno::XInterface > connectivity::dbase::ODriver_CreateInstance(const css::uno::Reference< css::lang::XMultiServiceFactory >& _rxFactory)
{
    return *(new ODriver( comphelper::getComponentContext(_rxFactory) ));
}

Reference< XConnection > SAL_CALL ODriver::connect( const OUString& url, const Sequence< PropertyValue >& info )
{
    ::osl::MutexGuard aGuard( m_aMutex );
diff --git a/connectivity/source/drivers/dbase/Dservices.cxx b/connectivity/source/drivers/dbase/Dservices.cxx
deleted file mode 100644
index e2d09d6..0000000
--- a/connectivity/source/drivers/dbase/Dservices.cxx
+++ /dev/null
@@ -1,106 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <dbase/DDriver.hxx>
#include <cppuhelper/factory.hxx>
#include <com/sun/star/lang/XSingleServiceFactory.hpp>

using namespace connectivity::dbase;
using ::com::sun::star::uno::Reference;
using ::com::sun::star::uno::Sequence;
using ::com::sun::star::lang::XSingleServiceFactory;
using ::com::sun::star::lang::XMultiServiceFactory;

typedef Reference< XSingleServiceFactory > (*createFactoryFunc)
        (
            const Reference< XMultiServiceFactory > & rServiceManager,
            const OUString & rComponentName,
            ::cppu::ComponentInstantiation pCreateFunction,
            const Sequence< OUString > & rServiceNames,
            rtl_ModuleCount*
        );

namespace {

struct ProviderRequest
{
    Reference< XSingleServiceFactory > xRet;
    Reference< XMultiServiceFactory > const xServiceManager;
    OUString const sImplementationName;

    ProviderRequest(
        void* pServiceManager,
        char const* pImplementationName
    )
    : xServiceManager(static_cast<XMultiServiceFactory*>(pServiceManager))
    , sImplementationName(OUString::createFromAscii(pImplementationName))
    {
    }

    bool CREATE_PROVIDER(
                const OUString& Implname,
                const Sequence< OUString > & Services,
                ::cppu::ComponentInstantiation Factory,
                createFactoryFunc creator
            )
    {
        if (!xRet.is() && (Implname == sImplementationName))
        {
            try
            {
                xRet = creator( xServiceManager, sImplementationName,Factory, Services,nullptr);
            }
            catch(...)
            {
            }
        }
        return xRet.is();
    }

    void* getProvider() const { return xRet.get(); }
};

}

extern "C" SAL_DLLPUBLIC_EXPORT void* dbase_component_getFactory(
                    const char* pImplementationName,
                    void* pServiceManager,
                    void* /*pRegistryKey*/)
{
    void* pRet = nullptr;
    if (pServiceManager)
    {
        ProviderRequest aReq(pServiceManager,pImplementationName);

        aReq.CREATE_PROVIDER(
            ODriver::getImplementationName_Static(),
            ODriver::getSupportedServiceNames_Static(),
            ODriver_CreateInstance, ::cppu::createSingleFactory)
        ;

        if(aReq.xRet.is())
            aReq.xRet->acquire();

        pRet = aReq.getProvider();
    }

    return pRet;
};

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/connectivity/source/drivers/dbase/dbase.component b/connectivity/source/drivers/dbase/dbase.component
index 3f2cea6..b078a76 100644
--- a/connectivity/source/drivers/dbase/dbase.component
+++ b/connectivity/source/drivers/dbase/dbase.component
@@ -18,8 +18,9 @@
 -->

<component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@"
    prefix="dbase" xmlns="http://openoffice.org/2010/uno-components">
  <implementation name="com.sun.star.comp.sdbc.dbase.ODriver">
    xmlns="http://openoffice.org/2010/uno-components">
  <implementation name="com.sun.star.comp.sdbc.dbase.ODriver"
    constructor="connectivity_dbase_ODriver">
    <service name="com.sun.star.sdbc.Driver"/>
    <service name="com.sun.star.sdbcx.Driver"/>
  </implementation>
diff --git a/connectivity/source/drivers/file/FDriver.cxx b/connectivity/source/drivers/file/FDriver.cxx
index c2956ad..16cf60e 100644
--- a/connectivity/source/drivers/file/FDriver.cxx
+++ b/connectivity/source/drivers/file/FDriver.cxx
@@ -57,22 +57,11 @@ void OFileDriver::disposing()
    ODriver_BASE::disposing();
}

// static ServiceInfo

OUString OFileDriver::getImplementationName_Static(  )
{
    return "com.sun.star.sdbc.driver.file.Driver";
}

Sequence< OUString > OFileDriver::getSupportedServiceNames_Static(  )
{
    return { "com.sun.star.sdbc.Driver", "com.sun.star.sdbcx.Driver" };
}

// XServiceInfo

OUString SAL_CALL OFileDriver::getImplementationName(  )
{
    return getImplementationName_Static();
    return "com.sun.star.sdbc.driver.file.Driver";
}

sal_Bool SAL_CALL OFileDriver::supportsService( const OUString& _rServiceName )
@@ -83,7 +72,7 @@ sal_Bool SAL_CALL OFileDriver::supportsService( const OUString& _rServiceName )

Sequence< OUString > SAL_CALL OFileDriver::getSupportedServiceNames(  )
{
    return getSupportedServiceNames_Static();
    return { "com.sun.star.sdbc.Driver", "com.sun.star.sdbcx.Driver" };
}


diff --git a/connectivity/source/drivers/flat/EDriver.cxx b/connectivity/source/drivers/flat/EDriver.cxx
index e10f29d..0e17678 100644
--- a/connectivity/source/drivers/flat/EDriver.cxx
+++ b/connectivity/source/drivers/flat/EDriver.cxx
@@ -36,23 +36,26 @@ using namespace css::sdbc;
using namespace css::lang;


// static ServiceInfo
// XServiceInfo

OUString ODriver::getImplementationName_Static(  )
OUString SAL_CALL ODriver::getImplementationName(  )
{
    return "com.sun.star.comp.sdbc.flat.ODriver";
}


OUString SAL_CALL ODriver::getImplementationName(  )
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
connectivity_flat_ODriver(
    css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
{
    return getImplementationName_Static();
}


css::uno::Reference< css::uno::XInterface > connectivity::flat::ODriver_CreateInstance(const css::uno::Reference< css::lang::XMultiServiceFactory >& _rxFactory)
{
    return *(new ODriver( comphelper::getComponentContext(_rxFactory) ));
    rtl::Reference<ODriver> ret;
    try {
        ret = new ODriver(context);
    } catch (...) {
    }
    if (ret)
        ret->acquire();
    return static_cast<cppu::OWeakObject*>(ret.get());
}

Reference< XConnection > SAL_CALL ODriver::connect( const OUString& url, const Sequence< PropertyValue >& info )
diff --git a/connectivity/source/drivers/flat/Eservices.cxx b/connectivity/source/drivers/flat/Eservices.cxx
deleted file mode 100644
index e74db87..0000000
--- a/connectivity/source/drivers/flat/Eservices.cxx
+++ /dev/null
@@ -1,106 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <flat/EDriver.hxx>
#include <cppuhelper/factory.hxx>
#include <com/sun/star/lang/XSingleServiceFactory.hpp>

using namespace connectivity::flat;
using ::com::sun::star::uno::Reference;
using ::com::sun::star::uno::Sequence;
using ::com::sun::star::lang::XSingleServiceFactory;
using ::com::sun::star::lang::XMultiServiceFactory;

typedef Reference< XSingleServiceFactory > (*createFactoryFunc)
        (
            const Reference< XMultiServiceFactory > & rServiceManager,
            const OUString & rComponentName,
            ::cppu::ComponentInstantiation pCreateFunction,
            const Sequence< OUString > & rServiceNames,
            rtl_ModuleCount*
        );

namespace {

struct ProviderRequest
{
    Reference< XSingleServiceFactory > xRet;
    Reference< XMultiServiceFactory > const xServiceManager;
    OUString const sImplementationName;

    ProviderRequest(
        void* pServiceManager,
        char const* pImplementationName
    )
    : xServiceManager(static_cast<XMultiServiceFactory*>(pServiceManager))
    , sImplementationName(OUString::createFromAscii(pImplementationName))
    {
    }

    bool CREATE_PROVIDER(
                const OUString& Implname,
                const Sequence< OUString > & Services,
                ::cppu::ComponentInstantiation Factory,
                createFactoryFunc creator
            )
    {
        if (!xRet.is() && (Implname == sImplementationName))
        {
            try
            {
                xRet = creator( xServiceManager, sImplementationName,Factory, Services,nullptr);
            }
            catch(...)
            {
            }
        }
        return xRet.is();
    }

    void* getProvider() const { return xRet.get(); }
};

}

extern "C" SAL_DLLPUBLIC_EXPORT void* flat_component_getFactory(
                    const char* pImplementationName,
                    void* pServiceManager,
                    void* /*pRegistryKey*/)
{
    void* pRet = nullptr;
    if (pServiceManager)
    {
        ProviderRequest aReq(pServiceManager,pImplementationName);

        aReq.CREATE_PROVIDER(
            ODriver::getImplementationName_Static(),
            ODriver::getSupportedServiceNames_Static(),
            ODriver_CreateInstance, ::cppu::createSingleFactory)
        ;

        if(aReq.xRet.is())
            aReq.xRet->acquire();

        pRet = aReq.getProvider();
    }

    return pRet;
};

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/connectivity/source/drivers/flat/flat.component b/connectivity/source/drivers/flat/flat.component
index 6fa7fb8..715fbec 100644
--- a/connectivity/source/drivers/flat/flat.component
+++ b/connectivity/source/drivers/flat/flat.component
@@ -18,8 +18,9 @@
 -->

<component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@"
    prefix="flat" xmlns="http://openoffice.org/2010/uno-components">
  <implementation name="com.sun.star.comp.sdbc.flat.ODriver">
    xmlns="http://openoffice.org/2010/uno-components">
  <implementation name="com.sun.star.comp.sdbc.flat.ODriver"
    constructor="connectivity_flat_ODriver">
    <service name="com.sun.star.sdbc.Driver"/>
    <service name="com.sun.star.sdbcx.Driver"/>
  </implementation>
diff --git a/connectivity/source/drivers/writer/WDriver.cxx b/connectivity/source/drivers/writer/WDriver.cxx
index 63dc1f3..3d30c00 100644
--- a/connectivity/source/drivers/writer/WDriver.cxx
+++ b/connectivity/source/drivers/writer/WDriver.cxx
@@ -30,14 +30,26 @@ using namespace ::com::sun::star;

namespace connectivity::writer
{
OUString ODriver::getImplementationName_Static() { return "com.sun.star.comp.sdbc.writer.ODriver"; }

OUString SAL_CALL ODriver::getImplementationName() { return getImplementationName_Static(); }

uno::Reference<css::uno::XInterface>
ODriver_CreateInstance(const uno::Reference<lang::XMultiServiceFactory>& _rxFactory)
OUString SAL_CALL ODriver::getImplementationName()
{
    return *(new ODriver(comphelper::getComponentContext(_rxFactory)));
    return "com.sun.star.comp.sdbc.writer.ODriver";
}

extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
connectivity_writer_ODriver(css::uno::XComponentContext* context,
                            css::uno::Sequence<css::uno::Any> const&)
{
    rtl::Reference<ODriver> ret;
    try
    {
        ret = new ODriver(context);
    }
    catch (...)
    {
    }
    if (ret)
        ret->acquire();
    return static_cast<cppu::OWeakObject*>(ret.get());
}

uno::Reference<sdbc::XConnection>
diff --git a/connectivity/source/drivers/writer/Wservices.cxx b/connectivity/source/drivers/writer/Wservices.cxx
deleted file mode 100644
index 7f997d7..0000000
--- a/connectivity/source/drivers/writer/Wservices.cxx
+++ /dev/null
@@ -1,90 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <writer/WDriver.hxx>
#include <cppuhelper/factory.hxx>
#include <com/sun/star/lang/XSingleServiceFactory.hpp>

using namespace com::sun::star;

using createFactoryFunc = uno::Reference<lang::XSingleServiceFactory> (*)(
    const uno::Reference<lang::XMultiServiceFactory>& rServiceManager,
    const OUString& rComponentName, ::cppu::ComponentInstantiation pCreateFunction,
    const uno::Sequence<OUString>& rServiceNames, rtl_ModuleCount*);

namespace
{
struct ProviderRequest
{
private:
    uno::Reference<lang::XSingleServiceFactory> xRet;
    uno::Reference<lang::XMultiServiceFactory> const xServiceManager;
    OUString const sImplementationName;

public:
    ProviderRequest(void* pServiceManager, char const* pImplementationName)
        : xServiceManager(static_cast<lang::XMultiServiceFactory*>(pServiceManager))
        , sImplementationName(OUString::createFromAscii(pImplementationName))
    {
    }

    bool CREATE_PROVIDER(const OUString& Implname, const uno::Sequence<OUString>& Services,
                         ::cppu::ComponentInstantiation Factory, createFactoryFunc creator)
    {
        if (!xRet.is() && (Implname == sImplementationName))
        {
            try
            {
                xRet = creator(xServiceManager, sImplementationName, Factory, Services, nullptr);
            }
            catch (...)
            {
            }
        }
        return xRet.is();
    }

    uno::XInterface* getProvider() const { return xRet.get(); }
};
}

extern "C" SAL_DLLPUBLIC_EXPORT void*
connectivity_writer_component_getFactory(const char* pImplementationName, void* pServiceManager,
                                         void* /*pRegistryKey*/)
{
    void* pRet = nullptr;
    if (pServiceManager)
    {
        ProviderRequest aReq(pServiceManager, pImplementationName);

        aReq.CREATE_PROVIDER(connectivity::writer::ODriver::getImplementationName_Static(),
                             connectivity::writer::ODriver::getSupportedServiceNames_Static(),
                             connectivity::writer::ODriver_CreateInstance,
                             ::cppu::createSingleFactory);

        if (aReq.getProvider())
            aReq.getProvider()->acquire();

        pRet = aReq.getProvider();
    }

    return pRet;
};

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/connectivity/source/drivers/writer/writer.component b/connectivity/source/drivers/writer/writer.component
index 3bf9d6e..3a04324 100644
--- a/connectivity/source/drivers/writer/writer.component
+++ b/connectivity/source/drivers/writer/writer.component
@@ -8,9 +8,9 @@
 -->

<component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@"
    prefix="connectivity_writer"
    xmlns="http://openoffice.org/2010/uno-components">
  <implementation name="com.sun.star.comp.sdbc.writer.ODriver">
  <implementation name="com.sun.star.comp.sdbc.writer.ODriver"
    constructor="connectivity_writer_ODriver">
    <service name="com.sun.star.sdbc.Driver"/>
    <service name="com.sun.star.sdbcx.Driver"/>
  </implementation>
diff --git a/connectivity/source/inc/file/FDriver.hxx b/connectivity/source/inc/file/FDriver.hxx
index efff202..6103735 100644
--- a/connectivity/source/inc/file/FDriver.hxx
+++ b/connectivity/source/inc/file/FDriver.hxx
@@ -49,11 +49,6 @@ namespace connectivity

            // OComponentHelper
            virtual void SAL_CALL disposing() override;
            // XInterface
            /// @throws css::uno::DeploymentException
            static OUString getImplementationName_Static(  );
            /// @throws css::uno::DeploymentException
            static css::uno::Sequence< OUString > getSupportedServiceNames_Static(  );

            // XServiceInfo
            virtual OUString SAL_CALL getImplementationName(  ) override;
diff --git a/connectivity/source/inc/writer/WDriver.hxx b/connectivity/source/inc/writer/WDriver.hxx
index aa164df..d719111 100644
--- a/connectivity/source/inc/writer/WDriver.hxx
+++ b/connectivity/source/inc/writer/WDriver.hxx
@@ -40,10 +40,6 @@ namespace connectivity
{
namespace writer
{
/// @throws css::uno::Exception
css::uno::Reference<css::uno::XInterface>
ODriver_CreateInstance(const css::uno::Reference<css::lang::XMultiServiceFactory>& _rxFactory);

class ODriver : public file::OFileDriver
{
public:
@@ -53,7 +49,6 @@ public:
    }

    /// @throws css::uno::RuntimeException
    static OUString getImplementationName_Static();
    OUString SAL_CALL getImplementationName() override;

    // XDriver