diff options
author | Noel Grandin <noel@peralex.com> | 2012-10-30 14:02:56 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2012-10-31 15:31:36 +0100 |
commit | 0ac9a10d312dc8f12a74720ce211823ce4addf7b (patch) | |
tree | 2c812432eca9315170af8b5b6b7ae5bcbf828d5b /unotools | |
parent | d27c92961b78da138d3563ab596cca416af9eb38 (diff) |
fdo#46808, Deprecate configuration::ConfigurationProvider old-style service
...in favor of existing new-style configuration::theDefaultProvider singleton.
Theoretically, ConfigurationProvider instances can be created with specific
Locale and EnableAsync arguments, but this is hardly used in practice, and thus
effectively all uses of the ConfigurationProvider service use the
theDefaultProvider instance, anyway.
theDefaultProvider is restricted to the XMultiServiceFactory interface, while
ConfigurationProvider also makes available XComponent. However, dispose must
not be called manually on theDefaultProvider singleton anyway, and calls to
add-/removeEventListener are so few (and in dubious code that should better be
cleaned up) that requiring an explicit queryInterface does not really hurt
there.
This commit originated as a patch by Noel Grandin to "Adapt
configuration::ConfigurationProvider UNO service to new style [by creating] a
merged XConfigurationProvider interface for this service to implement." It was
then modified by Stephan Bergmann by deprecating ConfigurationProvider instead
of adding XConfigurationProvider and by replacing calls to
ConfigurationProvider::create with calls to theDefaultProvider::get.
Change-Id: I9c16700afe0faff1ef6f20338a66bd7a9af990bd
Diffstat (limited to 'unotools')
-rw-r--r-- | unotools/inc/unotools/confignode.hxx | 3 | ||||
-rw-r--r-- | unotools/source/config/configmgr.cxx | 10 | ||||
-rw-r--r-- | unotools/source/config/confignode.cxx | 28 | ||||
-rw-r--r-- | unotools/source/config/fontcfg.cxx | 178 | ||||
-rw-r--r-- | unotools/source/config/itemholder1.cxx | 10 | ||||
-rw-r--r-- | unotools/source/config/lingucfg.cxx | 13 |
6 files changed, 105 insertions, 137 deletions
diff --git a/unotools/inc/unotools/confignode.hxx b/unotools/inc/unotools/confignode.hxx index f68180cf724a..1189a9b59f0c 100644 --- a/unotools/inc/unotools/confignode.hxx +++ b/unotools/inc/unotools/confignode.hxx @@ -25,6 +25,7 @@ #include <com/sun/star/container/XNameContainer.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/util/XChangesBatch.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> #include <unotools/eventlisteneradapter.hxx> namespace comphelper @@ -301,7 +302,7 @@ namespace utl the configuration could be initialized, errors in the creation of the specific node (e.g. because the given node path does not exist) are still asserted.</p> */ - static OConfigurationTreeRoot tryCreateWithServiceFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB, + static OConfigurationTreeRoot tryCreateWithServiceFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext, const ::rtl::OUString& _rPath, sal_Int32 _nDepth = -1, CREATION_MODE _eMode = CM_UPDATABLE, sal_Bool _bLazyWrite = sal_True ); /** commit all changes made on the subtree the object is the root for<p/> diff --git a/unotools/source/config/configmgr.cxx b/unotools/source/config/configmgr.cxx index 514ea959547a..a4589601e37c 100644 --- a/unotools/source/config/configmgr.cxx +++ b/unotools/source/config/configmgr.cxx @@ -24,6 +24,7 @@ #include "boost/noncopyable.hpp" #include "com/sun/star/beans/NamedValue.hpp" #include "com/sun/star/container/XHierarchicalNameAccess.hpp" +#include "com/sun/star/configuration/theDefaultProvider.hpp" #include "com/sun/star/lang/XMultiServiceFactory.hpp" #include "com/sun/star/uno/Any.hxx" #include "com/sun/star/uno/Reference.hxx" @@ -64,14 +65,7 @@ private: css::uno::Reference< css::lang::XMultiServiceFactory > getConfigurationProvider() { - return css::uno::Reference< css::lang::XMultiServiceFactory >( - (css::uno::Reference< css::lang::XMultiServiceFactory >( - comphelper::getProcessServiceFactory(), css::uno::UNO_SET_THROW)-> - createInstance( - rtl::OUString( - RTL_CONSTASCII_USTRINGPARAM( - "com.sun.star.configuration.ConfigurationProvider")))), - css::uno::UNO_QUERY_THROW); + return css::configuration::theDefaultProvider::get( comphelper::getProcessComponentContext() ); } rtl::OUString getConfigurationString( diff --git a/unotools/source/config/confignode.cxx b/unotools/source/config/confignode.cxx index e405b55d5f58..ca87f2744622 100644 --- a/unotools/source/config/confignode.cxx +++ b/unotools/source/config/confignode.cxx @@ -24,6 +24,7 @@ #include <osl/diagnose.h> #include <com/sun/star/container/XHierarchicalName.hpp> #include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/configuration/theDefaultProvider.hpp> #include <com/sun/star/lang/XSingleServiceFactory.hpp> #include <com/sun/star/lang/XComponent.hpp> #include <com/sun/star/util/XStringEscape.hpp> @@ -47,6 +48,7 @@ namespace utl using namespace ::com::sun::star::util; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::container; + using namespace ::com::sun::star::configuration; //======================================================================== //= OConfigurationNode @@ -479,14 +481,12 @@ namespace utl //======================================================================== namespace { - static const char s_sProviderServiceName[] = "com.sun.star.configuration.ConfigurationProvider"; - //-------------------------------------------------------------------- Reference< XMultiServiceFactory > lcl_getConfigProvider( const ::comphelper::ComponentContext& i_rContext ) { try { - Reference< XMultiServiceFactory > xProvider( i_rContext.createComponent(s_sProviderServiceName), UNO_QUERY_THROW ); + Reference< XMultiServiceFactory > xProvider = theDefaultProvider::get( i_rContext.getUNOContext() ); return xProvider; } catch ( const Exception& ) @@ -592,22 +592,18 @@ namespace utl } //------------------------------------------------------------------------ - OConfigurationTreeRoot OConfigurationTreeRoot::tryCreateWithServiceFactory( const Reference< XMultiServiceFactory >& _rxORB, + OConfigurationTreeRoot OConfigurationTreeRoot::tryCreateWithServiceFactory( const Reference< XComponentContext >& rxContext, const ::rtl::OUString& _rPath, sal_Int32 _nDepth , CREATION_MODE _eMode , sal_Bool _bLazyWrite ) { - OSL_ENSURE( _rxORB.is(), "OConfigurationTreeRoot::tryCreateWithServiceFactory: invalid service factory!" ); - if ( _rxORB.is() ) + OSL_ENSURE( rxContext.is(), "OConfigurationTreeRoot::tryCreateWithServiceFactory: invalid service factory!" ); + try { - try - { - Reference< XMultiServiceFactory > xConfigFactory( _rxORB->createInstance(s_sProviderServiceName), UNO_QUERY ); - if ( xConfigFactory.is() ) - return createWithProvider( xConfigFactory, _rPath, _nDepth, _eMode, _bLazyWrite ); - } - catch(const Exception&) - { - // silence this, 'cause the contract of this method states "no assertions" - } + Reference< XMultiServiceFactory > xConfigFactory = theDefaultProvider::get( rxContext ); + return createWithProvider( xConfigFactory, _rPath, _nDepth, _eMode, _bLazyWrite ); + } + catch(const Exception&) + { + // silence this, 'cause the contract of this method states "no assertions" } return OConfigurationTreeRoot(); } diff --git a/unotools/source/config/fontcfg.cxx b/unotools/source/config/fontcfg.cxx index 9a4b52c46183..314fed44faa3 100644 --- a/unotools/source/config/fontcfg.cxx +++ b/unotools/source/config/fontcfg.cxx @@ -24,6 +24,7 @@ #include <com/sun/star/uno/Any.hxx> #include <com/sun/star/uno/Sequence.hxx> #include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/configuration/theDefaultProvider.hpp> #include <unotools/configpaths.hxx> #include <unotools/syslocale.hxx> #include <rtl/ustrbuf.hxx> @@ -43,6 +44,7 @@ using namespace com::sun::star::uno; using namespace com::sun::star::lang; using namespace com::sun::star::beans; using namespace com::sun::star::container; +using namespace com::sun::star::configuration; using ::rtl::OUString; @@ -102,61 +104,51 @@ DefaultFontConfiguration::DefaultFontConfiguration() try { // get service provider - Reference< XMultiServiceFactory > xSMgr( comphelper::getProcessServiceFactory() ); + Reference< XComponentContext > xContext( comphelper::getProcessComponentContext() ); // create configuration hierachical access name - if( xSMgr.is() ) + try { - try + m_xConfigProvider = theDefaultProvider::get( xContext ); + Sequence< Any > aArgs(1); + PropertyValue aVal; + aVal.Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "nodepath" ) ); + aVal.Value <<= OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.VCL/DefaultFonts" ) ); + aArgs.getArray()[0] <<= aVal; + m_xConfigAccess = + Reference< XNameAccess >( + m_xConfigProvider->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( + "com.sun.star.configuration.ConfigurationAccess" )), + aArgs ), + UNO_QUERY ); + if( m_xConfigAccess.is() ) { - m_xConfigProvider = - Reference< XMultiServiceFactory >( - xSMgr->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( - "com.sun.star.configuration.ConfigurationProvider" ))), - UNO_QUERY ); - if( m_xConfigProvider.is() ) + Sequence< OUString > aLocales = m_xConfigAccess->getElementNames(); + // fill config hash with empty interfaces + int nLocales = aLocales.getLength(); + const OUString* pLocaleStrings = aLocales.getConstArray(); + Locale aLoc; + for( int i = 0; i < nLocales; i++ ) { - Sequence< Any > aArgs(1); - PropertyValue aVal; - aVal.Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "nodepath" ) ); - aVal.Value <<= OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.VCL/DefaultFonts" ) ); - aArgs.getArray()[0] <<= aVal; - m_xConfigAccess = - Reference< XNameAccess >( - m_xConfigProvider->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( - "com.sun.star.configuration.ConfigurationAccess" )), - aArgs ), - UNO_QUERY ); - if( m_xConfigAccess.is() ) - { - Sequence< OUString > aLocales = m_xConfigAccess->getElementNames(); - // fill config hash with empty interfaces - int nLocales = aLocales.getLength(); - const OUString* pLocaleStrings = aLocales.getConstArray(); - Locale aLoc; - for( int i = 0; i < nLocales; i++ ) - { - sal_Int32 nIndex = 0; - aLoc.Language = pLocaleStrings[i].getToken( 0, sal_Unicode('-'), nIndex ).toAsciiLowerCase(); - if( nIndex != -1 ) - aLoc.Country = pLocaleStrings[i].getToken( 0, sal_Unicode('-'), nIndex ).toAsciiUpperCase(); - else - aLoc.Country = OUString(); - if( nIndex != -1 ) - aLoc.Variant = pLocaleStrings[i].getToken( 0, sal_Unicode('-'), nIndex ).toAsciiUpperCase(); - else - aLoc.Variant = OUString(); - m_aConfig[ aLoc ] = LocaleAccess(); - m_aConfig[ aLoc ].aConfigLocaleString = pLocaleStrings[i]; - } - } + sal_Int32 nIndex = 0; + aLoc.Language = pLocaleStrings[i].getToken( 0, sal_Unicode('-'), nIndex ).toAsciiLowerCase(); + if( nIndex != -1 ) + aLoc.Country = pLocaleStrings[i].getToken( 0, sal_Unicode('-'), nIndex ).toAsciiUpperCase(); + else + aLoc.Country = OUString(); + if( nIndex != -1 ) + aLoc.Variant = pLocaleStrings[i].getToken( 0, sal_Unicode('-'), nIndex ).toAsciiUpperCase(); + else + aLoc.Variant = OUString(); + m_aConfig[ aLoc ] = LocaleAccess(); + m_aConfig[ aLoc ].aConfigLocaleString = pLocaleStrings[i]; } } - catch (const Exception&) - { - // configuration is awry - m_xConfigProvider.clear(); - m_xConfigAccess.clear(); - } + } + catch (const Exception&) + { + // configuration is awry + m_xConfigProvider.clear(); + m_xConfigAccess.clear(); } } catch (const WrappedTargetException&) @@ -380,61 +372,51 @@ FontSubstConfiguration::FontSubstConfiguration() : try { // get service provider - Reference< XMultiServiceFactory > xSMgr( comphelper::getProcessServiceFactory() ); + Reference< XComponentContext > xContext( comphelper::getProcessComponentContext() ); // create configuration hierachical access name - if( xSMgr.is() ) + try { - try + m_xConfigProvider = theDefaultProvider::get( xContext ); + Sequence< Any > aArgs(1); + PropertyValue aVal; + aVal.Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "nodepath" ) ); + aVal.Value <<= OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.VCL/FontSubstitutions" ) ); + aArgs.getArray()[0] <<= aVal; + m_xConfigAccess = + Reference< XNameAccess >( + m_xConfigProvider->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( + "com.sun.star.configuration.ConfigurationAccess" )), + aArgs ), + UNO_QUERY ); + if( m_xConfigAccess.is() ) { - m_xConfigProvider = - Reference< XMultiServiceFactory >( - xSMgr->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( - "com.sun.star.configuration.ConfigurationProvider" ))), - UNO_QUERY ); - if( m_xConfigProvider.is() ) + Sequence< OUString > aLocales = m_xConfigAccess->getElementNames(); + // fill config hash with empty interfaces + int nLocales = aLocales.getLength(); + const OUString* pLocaleStrings = aLocales.getConstArray(); + Locale aLoc; + for( int i = 0; i < nLocales; i++ ) { - Sequence< Any > aArgs(1); - PropertyValue aVal; - aVal.Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "nodepath" ) ); - aVal.Value <<= OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.VCL/FontSubstitutions" ) ); - aArgs.getArray()[0] <<= aVal; - m_xConfigAccess = - Reference< XNameAccess >( - m_xConfigProvider->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( - "com.sun.star.configuration.ConfigurationAccess" )), - aArgs ), - UNO_QUERY ); - if( m_xConfigAccess.is() ) - { - Sequence< OUString > aLocales = m_xConfigAccess->getElementNames(); - // fill config hash with empty interfaces - int nLocales = aLocales.getLength(); - const OUString* pLocaleStrings = aLocales.getConstArray(); - Locale aLoc; - for( int i = 0; i < nLocales; i++ ) - { - sal_Int32 nIndex = 0; - aLoc.Language = pLocaleStrings[i].getToken( 0, sal_Unicode('-'), nIndex ).toAsciiLowerCase(); - if( nIndex != -1 ) - aLoc.Country = pLocaleStrings[i].getToken( 0, sal_Unicode('-'), nIndex ).toAsciiUpperCase(); - else - aLoc.Country = OUString(); - if( nIndex != -1 ) - aLoc.Variant = pLocaleStrings[i].getToken( 0, sal_Unicode('-'), nIndex ).toAsciiUpperCase(); - else - aLoc.Variant = OUString(); - m_aSubst[ aLoc ] = LocaleSubst(); - m_aSubst[ aLoc ].aConfigLocaleString = pLocaleStrings[i]; - } - } + sal_Int32 nIndex = 0; + aLoc.Language = pLocaleStrings[i].getToken( 0, sal_Unicode('-'), nIndex ).toAsciiLowerCase(); + if( nIndex != -1 ) + aLoc.Country = pLocaleStrings[i].getToken( 0, sal_Unicode('-'), nIndex ).toAsciiUpperCase(); + else + aLoc.Country = OUString(); + if( nIndex != -1 ) + aLoc.Variant = pLocaleStrings[i].getToken( 0, sal_Unicode('-'), nIndex ).toAsciiUpperCase(); + else + aLoc.Variant = OUString(); + m_aSubst[ aLoc ] = LocaleSubst(); + m_aSubst[ aLoc ].aConfigLocaleString = pLocaleStrings[i]; } } - catch (const Exception&) - { - // configuration is awry - m_xConfigProvider.clear(); - m_xConfigAccess.clear(); - } + } + catch (const Exception&) + { + // configuration is awry + m_xConfigProvider.clear(); + m_xConfigAccess.clear(); } } catch (const WrappedTargetException&) diff --git a/unotools/source/config/itemholder1.cxx b/unotools/source/config/itemholder1.cxx index 1d2b90ede043..de973654dd9f 100644 --- a/unotools/source/config/itemholder1.cxx +++ b/unotools/source/config/itemholder1.cxx @@ -22,6 +22,7 @@ #include <comphelper/processfactory.hxx> #include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/configuration/theDefaultProvider.hpp> #include <unotools/misccfg.hxx> #include <unotools/useroptions.hxx> @@ -64,12 +65,11 @@ ItemHolder1::ItemHolder1() { try { - css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory(); + css::uno::Reference< css::uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext(); css::uno::Reference< css::lang::XComponent > xCfg( - xSMGR->createInstance(::rtl::OUString("com.sun.star.configuration.ConfigurationProvider")), - css::uno::UNO_QUERY); - if (xCfg.is()) - xCfg->addEventListener(static_cast< css::lang::XEventListener* >(this)); + css::configuration::theDefaultProvider::get( xContext ), + css::uno::UNO_QUERY_THROW ); + xCfg->addEventListener(static_cast< css::lang::XEventListener* >(this)); } #ifdef DBG_UTIL catch(const css::uno::Exception& rEx) diff --git a/unotools/source/config/lingucfg.cxx b/unotools/source/config/lingucfg.cxx index a291a95e3e70..7407d8289944 100644 --- a/unotools/source/config/lingucfg.cxx +++ b/unotools/source/config/lingucfg.cxx @@ -20,6 +20,7 @@ #include <com/sun/star/lang/Locale.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/lang/XSingleServiceFactory.hpp> +#include <com/sun/star/configuration/theDefaultProvider.hpp> #include <com/sun/star/container/XNameAccess.hpp> #include <com/sun/star/container/XNameContainer.hpp> #include <com/sun/star/container/XNameReplace.hpp> @@ -1115,15 +1116,9 @@ uno::Reference< util::XChangesBatch > SvtLinguConfig::GetMainUpdateAccess() cons try { // get configuration provider - uno::Reference< lang::XMultiServiceFactory > xConfigurationProvider; - uno::Reference< lang::XMultiServiceFactory > xMgr = comphelper::getProcessServiceFactory(); - if (xMgr.is()) - { - xConfigurationProvider = uno::Reference< lang::XMultiServiceFactory > ( - xMgr->createInstance(OUString(RTL_CONSTASCII_USTRINGPARAM( - "com.sun.star.configuration.ConfigurationProvider"))), - uno::UNO_QUERY_THROW ) ; - } + uno::Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext(); + uno::Reference< lang::XMultiServiceFactory > xConfigurationProvider = + configuration::theDefaultProvider::get( xContext ); // get configuration update access beans::PropertyValue aValue; |