diff options
author | Matúš Kukan <matus.kukan@gmail.com> | 2015-11-21 01:32:49 +0100 |
---|---|---|
committer | Matúš Kukan <matus.kukan@gmail.com> | 2015-12-12 17:23:34 +0100 |
commit | 1ded035f853ba62f02958175046948d2b47b8075 (patch) | |
tree | d8b9bc9d8e2e2d60797857a7b0472f5fad37c80c /dbaccess | |
parent | 8227e8bef1c8c6c95627daf5023fe927605d50d2 (diff) |
tdf#74608 dbaccess: Constructor for singleton DataAccessDescriptorFactory
Change-Id: Id1453e3cf1c8aef22536b4e0797cca7e654316c0
Diffstat (limited to 'dbaccess')
-rw-r--r-- | dbaccess/source/core/dataaccess/dataaccessdescriptor.cxx | 78 | ||||
-rw-r--r-- | dbaccess/source/core/inc/services.hxx | 31 | ||||
-rw-r--r-- | dbaccess/source/core/misc/services.cxx | 25 | ||||
-rw-r--r-- | dbaccess/util/dba.component | 3 |
4 files changed, 31 insertions, 106 deletions
diff --git a/dbaccess/source/core/dataaccess/dataaccessdescriptor.cxx b/dbaccess/source/core/dataaccess/dataaccessdescriptor.cxx index 567e2312cafd..e351d2921752 100644 --- a/dbaccess/source/core/dataaccess/dataaccessdescriptor.cxx +++ b/dbaccess/source/core/dataaccess/dataaccessdescriptor.cxx @@ -18,8 +18,6 @@ */ #include "dbastrings.hrc" -#include "module_dba.hxx" -#include "services.hxx" #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/beans/PropertyAttribute.hpp> @@ -28,6 +26,7 @@ #include <com/sun/star/sdbc/XConnection.hpp> #include <com/sun/star/sdbc/XResultSet.hpp> #include <com/sun/star/sdb/XDataAccessDescriptorFactory.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> #include <comphelper/broadcasthelper.hxx> #include <comphelper/proparrhlp.hxx> @@ -36,28 +35,20 @@ #include <cppuhelper/implbase.hxx> #include <cppuhelper/supportsservice.hxx> -namespace dbaccess +namespace { using ::com::sun::star::uno::Reference; - using ::com::sun::star::uno::XInterface; - using ::com::sun::star::uno::UNO_QUERY; - using ::com::sun::star::uno::UNO_QUERY_THROW; - using ::com::sun::star::uno::UNO_SET_THROW; - using ::com::sun::star::uno::Exception; using ::com::sun::star::uno::RuntimeException; using ::com::sun::star::uno::Any; - using ::com::sun::star::uno::makeAny; using ::com::sun::star::uno::Sequence; + using ::com::sun::star::uno::XComponentContext; using ::com::sun::star::lang::XServiceInfo; - using ::com::sun::star::lang::XMultiServiceFactory; using ::com::sun::star::beans::XPropertySetInfo; using ::com::sun::star::beans::Property; using ::com::sun::star::sdbc::XConnection; using ::com::sun::star::sdbc::XResultSet; - using ::com::sun::star::sdb::XDataAccessDescriptorFactory; using ::com::sun::star::beans::XPropertySet; - using ::com::sun::star::uno::XComponentContext; using ::com::sun::star::beans::PropertyValue; namespace PropertyAttribute = ::com::sun::star::beans::PropertyAttribute; @@ -211,10 +202,7 @@ namespace dbaccess } // DataAccessDescriptorFactory - typedef ::cppu::WeakImplHelper< XServiceInfo - , XDataAccessDescriptorFactory - > DataAccessDescriptorFactory_Base; - class DataAccessDescriptorFactory : public DataAccessDescriptorFactory_Base + class DataAccessDescriptorFactory: public ::cppu::WeakImplHelper<XServiceInfo, css::sdb::XDataAccessDescriptorFactory> { public: // XServiceInfo @@ -222,16 +210,9 @@ namespace dbaccess virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (RuntimeException, std::exception) override; virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (RuntimeException, std::exception) override; - // XServiceInfo - static versions - static Sequence< OUString > getSupportedServiceNames_static() throw( RuntimeException ); - static OUString getImplementationName_static() throw( RuntimeException ); - static Reference< XInterface > Create(const Reference< XComponentContext >& _rxContext); - static OUString getSingletonName_static(); - // XDataAccessDescriptorFactory virtual Reference< XPropertySet > SAL_CALL createDataAccessDescriptor( ) throw (RuntimeException, std::exception) override; - protected: explicit DataAccessDescriptorFactory( const Reference< XComponentContext >& _rxContext ); virtual ~DataAccessDescriptorFactory(); @@ -248,30 +229,9 @@ namespace dbaccess { } - OUString DataAccessDescriptorFactory::getSingletonName_static() - { - return OUString( "com.sun.star.sdb.DataAccessDescriptorFactory" ); - } - - Sequence< OUString > DataAccessDescriptorFactory::getSupportedServiceNames_static() throw( RuntimeException ) - { - Sequence< OUString > aServices { getSingletonName_static() }; - return aServices; - } - - OUString DataAccessDescriptorFactory::getImplementationName_static() throw( RuntimeException ) - { - return OUString( "com.sun.star.comp.dba.DataAccessDescriptorFactory" ); - } - - Reference< XInterface > DataAccessDescriptorFactory::Create( const Reference< XComponentContext >& _rxContext ) - { - return *( new DataAccessDescriptorFactory( _rxContext ) ); - } - OUString SAL_CALL DataAccessDescriptorFactory::getImplementationName() throw (RuntimeException, std::exception) { - return getImplementationName_static(); + return OUString( "com.sun.star.comp.dba.DataAccessDescriptorFactory" ); } sal_Bool SAL_CALL DataAccessDescriptorFactory::supportsService( const OUString& rServiceName ) throw (RuntimeException, std::exception) @@ -279,9 +239,10 @@ namespace dbaccess return cppu::supportsService(this, rServiceName); } - Sequence< OUString > SAL_CALL DataAccessDescriptorFactory::getSupportedServiceNames( ) throw (RuntimeException, std::exception) + Sequence< OUString > SAL_CALL DataAccessDescriptorFactory::getSupportedServiceNames() throw (RuntimeException, std::exception) { - return getSupportedServiceNames_static(); + Sequence< OUString > aServices { "com.sun.star.sdb.DataAccessDescriptorFactory" }; + return aServices; } Reference< XPropertySet > SAL_CALL DataAccessDescriptorFactory::createDataAccessDescriptor( ) throw (RuntimeException, std::exception) @@ -289,11 +250,28 @@ namespace dbaccess return new DataAccessDescriptor( m_xContext ); } -} // namespace dbaccess +struct Instance { + explicit Instance( + css::uno::Reference<css::uno::XComponentContext> const & context): + instance(new DataAccessDescriptorFactory(context)) + {} + + css::uno::Reference<cppu::OWeakObject> instance; +}; + +struct Singleton: + public rtl::StaticWithArg< + Instance, css::uno::Reference<css::uno::XComponentContext>, Singleton> +{}; + +} -extern "C" void SAL_CALL createRegistryInfo_DataAccessDescriptorFactory() +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL +com_sun_star_comp_dba_DataAccessDescriptorFactory( + css::uno::XComponentContext *context, + css::uno::Sequence<css::uno::Any> const &) { - static ::dba::OSingletonRegistration< ::dbaccess::DataAccessDescriptorFactory > aAutoRegistration; + return cppu::acquire(Singleton::get(context).instance.get()); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/core/inc/services.hxx b/dbaccess/source/core/inc/services.hxx deleted file mode 100644 index 4e40c488d66d..000000000000 --- a/dbaccess/source/core/inc/services.hxx +++ /dev/null @@ -1,31 +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 . - */ - -#ifndef INCLUDED_DBACCESS_SOURCE_CORE_INC_SERVICES_HXX -#define INCLUDED_DBACCESS_SOURCE_CORE_INC_SERVICES_HXX - -#include <sal/config.h> - -#include <sal/types.h> - -extern "C" void SAL_CALL createRegistryInfo_DataAccessDescriptorFactory(); - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/core/misc/services.cxx b/dbaccess/source/core/misc/services.cxx index 36242257c13c..60c877afcfa2 100644 --- a/dbaccess/source/core/misc/services.cxx +++ b/dbaccess/source/core/misc/services.cxx @@ -19,13 +19,11 @@ #include <cppuhelper/factory.hxx> #include <cppuhelper/implementationentry.hxx> -#include "module_dba.hxx" #include <osl/diagnose.h> #include "DatabaseDataProvider.hxx" #include "dbadllapi.hxx" #include <../dataaccess/databasecontext.hxx> -#include <services.hxx> using namespace ::com::sun::star::uno; using namespace ::com::sun::star::lang; @@ -51,34 +49,13 @@ namespace dba{ }; } -// The prescribed C api must be complied with -// It consists of three functions which must be exported by the module. -extern "C" void SAL_CALL createRegistryInfo_DBA() -{ - static bool bInit = false; - if (!bInit) - { - createRegistryInfo_DataAccessDescriptorFactory(); - bInit = true; - } -} - extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL dba_component_getFactory( const sal_Char* pImplementationName, void* pServiceManager, void* pRegistryKey) { - createRegistryInfo_DBA(); - - Reference<XInterface> xRet(::dba::DbaModule::getInstance().getComponentFactory( - OUString::createFromAscii(pImplementationName))); - - if (xRet.is()) - xRet->acquire(); - else - return cppu::component_getFactoryHelper( + return cppu::component_getFactoryHelper( pImplementationName, pServiceManager, pRegistryKey, dba::entries); - return xRet.get(); }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/util/dba.component b/dbaccess/util/dba.component index 3a4ac355d889..90ba9e3ba7e9 100644 --- a/dbaccess/util/dba.component +++ b/dbaccess/util/dba.component @@ -22,7 +22,8 @@ <implementation name="com.sun.star.comp.dbaccess.DatabaseDataProvider"> <service name="com.sun.star.chart2.data.DatabaseDataProvider"/> </implementation> - <implementation name="com.sun.star.comp.dba.DataAccessDescriptorFactory"> + <implementation name="com.sun.star.comp.dba.DataAccessDescriptorFactory" + constructor="com_sun_star_comp_dba_DataAccessDescriptorFactory"> <singleton name="com.sun.star.sdb.DataAccessDescriptorFactory"/> </implementation> <implementation name="com.sun.star.comp.dba.OCommandDefinition" |