diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2012-09-29 17:20:22 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2012-09-29 18:18:28 +0200 |
commit | c2ca6fabd1afc3fc07001721c2069d3c8db7000a (patch) | |
tree | 350741d6d19564bcaf00506bd7d22b4c644e0fdc /basic | |
parent | Some clean up (diff) | |
download | core-c2ca6fabd1afc3fc07001721c2069d3c8db7000a.tar.gz core-c2ca6fabd1afc3fc07001721c2069d3c8db7000a.zip |
Use comphelper::getComponentContext
...and some further clean up.
Change-Id: Id294c0f38fe0041646fc86cacbd2e19734c746a9
Diffstat (limited to 'basic')
-rw-r--r-- | basic/source/classes/eventatt.cxx | 33 | ||||
-rw-r--r-- | basic/source/classes/sbunoobj.cxx | 96 | ||||
-rw-r--r-- | basic/source/classes/sbxmod.cxx | 10 | ||||
-rw-r--r-- | basic/source/uno/dlgcont.cxx | 28 | ||||
-rw-r--r-- | basic/source/uno/namecont.cxx | 55 |
5 files changed, 70 insertions, 152 deletions
diff --git a/basic/source/classes/eventatt.cxx b/basic/source/classes/eventatt.cxx index 1c111e2d2eda..79e2c3b707ee 100644 --- a/basic/source/classes/eventatt.cxx +++ b/basic/source/classes/eventatt.cxx @@ -94,23 +94,18 @@ void SFURL_firing_impl( const ScriptEvent& aScriptEvent, Any* pRet, const Refere } else { - Reference< XComponentContext > xContext; - Reference< XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), UNO_QUERY ); - OSL_ASSERT( xProps.is() ); - OSL_VERIFY( xProps->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext")) ) >>= xContext ); - if ( xContext.is() ) - { - Reference< provider::XScriptProviderFactory > xFactory( - xContext->getValueByName( + Reference< XComponentContext > xContext( + comphelper::getProcessComponentContext() ); + Reference< provider::XScriptProviderFactory > xFactory( + xContext->getValueByName( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/singletons/com.sun.star.script.provider.theMasterScriptProviderFactory")) ), - UNO_QUERY ); - OSL_ENSURE( xFactory.is(), "SFURL_firing_impl: failed to get master script provider factory" ); - if ( xFactory.is() ) - { - Any aCtx; - aCtx <<= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("user")); - xScriptProvider.set( xFactory->createScriptProvider( aCtx ), UNO_QUERY ); - } + UNO_QUERY ); + OSL_ENSURE( xFactory.is(), "SFURL_firing_impl: failed to get master script provider factory" ); + if ( xFactory.is() ) + { + Any aCtx; + aCtx <<= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("user")); + xScriptProvider.set( xFactory->createScriptProvider( aCtx ), UNO_QUERY ); } } @@ -469,10 +464,8 @@ void RTL_Impl_CreateUnoDialog( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrit if( !xISP.is() ) return; - Reference< XComponentContext > xContext; - Reference< XPropertySet > xProps( xMSF, UNO_QUERY ); - OSL_ASSERT( xProps.is() ); - OSL_VERIFY( xProps->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext")) ) >>= xContext ); + Reference< XComponentContext > xContext( + comphelper::getComponentContext( xMSF ) ); // Import the DialogModel Reference< XInputStream > xInput( xISP->createInputStream() ); diff --git a/basic/source/classes/sbunoobj.cxx b/basic/source/classes/sbunoobj.cxx index c79263493714..6735dfe6299c 100644 --- a/basic/source/classes/sbunoobj.cxx +++ b/basic/source/classes/sbunoobj.cxx @@ -162,26 +162,6 @@ void SetSbUnoObjectDfltPropName( SbxObject* pObj ) } } -Reference< XComponentContext > getComponentContext_Impl( void ) -{ - static Reference< XComponentContext > xContext; - - // Do we have already CoreReflection; if not obtain it - if( !xContext.is() ) - { - Reference< XMultiServiceFactory > xFactory = comphelper::getProcessServiceFactory(); - Reference< XPropertySet > xProps( xFactory, UNO_QUERY ); - OSL_ASSERT( xProps.is() ); - if (xProps.is()) - { - xProps->getPropertyValue( - ::rtl::OUString( "DefaultContext" ) ) >>= xContext; - OSL_ASSERT( xContext.is() ); - } - } - return xContext; -} - // save CoreReflection statically Reference< XIdlReflection > getCoreReflection_Impl( void ) { @@ -190,7 +170,8 @@ Reference< XIdlReflection > getCoreReflection_Impl( void ) // Do we have already CoreReflection; if not obtain it if( !xCoreReflection.is() ) { - Reference< XComponentContext > xContext = getComponentContext_Impl(); + Reference< XComponentContext > xContext( + comphelper::getProcessComponentContext() ); if( xContext.is() ) { xContext->getValueByName( @@ -233,7 +214,8 @@ Reference< XHierarchicalNameAccess > getTypeProvider_Impl( void ) // Do we have already CoreReflection; if not obtain it if( !xAccess.is() ) { - Reference< XComponentContext > xContext = getComponentContext_Impl(); + Reference< XComponentContext > xContext( + comphelper::getProcessComponentContext() ); if( xContext.is() ) { xContext->getValueByName( @@ -260,7 +242,8 @@ Reference< XTypeConverter > getTypeConverter_Impl( void ) // Do we have already CoreReflection; if not obtain it if( !xTypeConverter.is() ) { - Reference< XComponentContext > xContext = getComponentContext_Impl(); + Reference< XComponentContext > xContext( + comphelper::getProcessComponentContext() ); if( xContext.is() ) { xTypeConverter = Converter::create(xContext); @@ -287,7 +270,8 @@ SbUnoObject* createOLEObject_Impl( const ::rtl::OUString& aType ) { bNeedsInit = false; - Reference< XComponentContext > xContext = getComponentContext_Impl(); + Reference< XComponentContext > xContext( + comphelper::getProcessComponentContext() ); if( xContext.is() ) { Reference<XMultiComponentFactory> xSMgr = xContext->getServiceManager(); @@ -3694,33 +3678,24 @@ void SbUnoService::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType, } // "Call" ctor using createInstanceWithArgumentsAndContext - Reference < XComponentContext > xContext; - if( xFirstParamContext.is() ) - { - xContext = xFirstParamContext; - } - else - { - Reference < XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), UNO_QUERY_THROW ); - xContext.set( xProps->getPropertyValue( rtl::OUString( "DefaultContext" ) ), UNO_QUERY_THROW ); - } + Reference < XComponentContext > xContext( + xFirstParamContext.is() + ? xFirstParamContext + : comphelper::getProcessComponentContext() ); Reference< XMultiComponentFactory > xServiceMgr( xContext->getServiceManager() ); Any aRetAny; - if( xServiceMgr.is() ) + ::rtl::OUString aServiceName = GetName(); + Reference < XInterface > xRet; + try { - ::rtl::OUString aServiceName = GetName(); - Reference < XInterface > xRet; - try - { - xRet = xServiceMgr->createInstanceWithArgumentsAndContext( aServiceName, args, xContext ); - } - catch( const Exception& ) - { - implHandleAnyException( ::cppu::getCaughtException() ); - } - aRetAny <<= xRet; + xRet = xServiceMgr->createInstanceWithArgumentsAndContext( aServiceName, args, xContext ); + } + catch( const Exception& ) + { + implHandleAnyException( ::cppu::getCaughtException() ); } + aRetAny <<= xRet; unoToSbxValue( pVar, aRetAny ); // Copy back out parameters? @@ -3835,8 +3810,7 @@ void SbUnoSingleton::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType, if( !xContextToUse.is() ) { - Reference < XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), UNO_QUERY_THROW ); - xContextToUse.set( xProps->getPropertyValue( rtl::OUString( "DefaultContext" ) ), UNO_QUERY_THROW ); + xContextToUse = comphelper::getProcessComponentContext(); --nAllowedParamCount; } @@ -4205,22 +4179,12 @@ void RTL_Impl_GetDefaultContext( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWr SbxVariableRef refVar = rPar.Get(0); - Reference< XMultiServiceFactory > xFactory = comphelper::getProcessServiceFactory(); - Reference< XPropertySet> xPSMPropertySet( xFactory, UNO_QUERY ); - if( xPSMPropertySet.is() ) - { - Any aContextAny = xPSMPropertySet->getPropertyValue( - ::rtl::OUString( "DefaultContext" ) ); + Any aContextAny( comphelper::getProcessComponentContext() ); - SbUnoObjectRef xUnoObj = new SbUnoObject - ( ::rtl::OUString( "DefaultContext" ), - aContextAny ); - refVar->PutObject( (SbUnoObject*)xUnoObj ); - } - else - { - refVar->PutObject( NULL ); - } + SbUnoObjectRef xUnoObj = new SbUnoObject + ( ::rtl::OUString( "DefaultContext" ), + aContextAny ); + refVar->PutObject( (SbUnoObject*)xUnoObj ); } //======================================================================== @@ -4544,7 +4508,8 @@ Reference< XInterface > createComListener( const Any& aControlAny, const ::rtl:: { Reference< XInterface > xRet; - Reference< XComponentContext > xContext = getComponentContext_Impl(); + Reference< XComponentContext > xContext( + comphelper::getProcessComponentContext() ); Reference< XMultiComponentFactory > xServiceMgr( xContext->getServiceManager() ); Reference< XInvocation > xProxy = new ModuleInvocationProxy( aPrefix, xScopeObj ); @@ -4665,7 +4630,8 @@ bool SbModule::createCOMWrapperForIface( Any& o_rRetAny, SbClassModuleObject* pP // For now: Take first interface that allows to instantiate COM wrapper // TODO: Check if support for multiple interfaces is needed - Reference< XComponentContext > xContext = getComponentContext_Impl(); + Reference< XComponentContext > xContext( + comphelper::getProcessComponentContext() ); Reference< XMultiComponentFactory > xServiceMgr( xContext->getServiceManager() ); Reference< XSingleServiceFactory > xComImplementsFactory ( diff --git a/basic/source/classes/sbxmod.cxx b/basic/source/classes/sbxmod.cxx index 3257a4ad5214..759b9b25f74b 100644 --- a/basic/source/classes/sbxmod.cxx +++ b/basic/source/classes/sbxmod.cxx @@ -139,7 +139,6 @@ DocObjectWrapper::DocObjectWrapper( SbModule* pVar ) : m_pMod( pVar ), mName( pV { if ( pMod->GetModuleType() == ModuleType::DOCUMENT ) { - Reference< XMultiServiceFactory > xFactory = comphelper::getProcessServiceFactory(); // Use proxy factory service to create aggregatable proxy. SbUnoObject* pUnoObj = PTR_CAST(SbUnoObject,pMod->GetObject() ); Reference< XInterface > xIf; @@ -157,11 +156,10 @@ DocObjectWrapper::DocObjectWrapper( SbModule* pVar ) : m_pMod( pVar ), mName( pV { try { - Reference< XMultiComponentFactory > xMFac( xFactory, UNO_QUERY_THROW ); - Reference< XPropertySet> xPSMPropertySet( xMFac, UNO_QUERY_THROW ); - Reference< XComponentContext > xCtx; - xPSMPropertySet->getPropertyValue( - String( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) >>= xCtx; + Reference< XComponentContext > xCtx( + comphelper::getProcessComponentContext() ); + Reference< XMultiComponentFactory > xMFac( + xCtx->getServiceManager() ); Reference< XProxyFactory > xProxyFac( xMFac->createInstanceWithContext( rtl::OUString( "com.sun.star.reflection.ProxyFactory" ), xCtx ), UNO_QUERY_THROW ); m_xAggProxy = xProxyFac->createProxy( xIf ); } diff --git a/basic/source/uno/dlgcont.cxx b/basic/source/uno/dlgcont.cxx index 3f1101c4eac0..2cfe035a21b7 100644 --- a/basic/source/uno/dlgcont.cxx +++ b/basic/source/uno/dlgcont.cxx @@ -24,7 +24,6 @@ #include <com/sun/star/io/XInputStream.hpp> #include <com/sun/star/embed/ElementModes.hpp> #include <com/sun/star/ucb/XSimpleFileAccess2.hpp> -#include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/io/XActiveDataSource.hpp> #include <com/sun/star/xml/sax/XDocumentHandler.hpp> #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp> @@ -117,23 +116,12 @@ bool SAL_CALL SfxDialogLibraryContainer::isLibraryElementValid( Any aElement ) c bool writeOasis2OOoLibraryElement( Reference< XInputStream > xInput, Reference< XOutputStream > xOutput ) { - Reference< XMultiServiceFactory > xMSF( - comphelper::getProcessServiceFactory() ); - - Reference< XComponentContext > xContext; - Reference< beans::XPropertySet > xProps( xMSF, UNO_QUERY ); - OSL_ASSERT( xProps.is() ); - OSL_VERIFY( xProps->getPropertyValue( - OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext")) ) >>= xContext ); + Reference< XComponentContext > xContext( + comphelper::getProcessComponentContext() ); Reference< lang::XMultiComponentFactory > xSMgr( xContext->getServiceManager() ); - if (! xSMgr.is()) - { - return sal_False; - } - Reference< xml::sax::XParser > xParser( xSMgr->createInstanceWithContext( OUString( RTL_CONSTASCII_USTRINGPARAM( @@ -267,10 +255,8 @@ void SfxDialogLibraryContainer::storeLibrariesToStorage( const uno::Reference< e Reference< io::XInputStream > xInput( xISP->createInputStream() ); Reference< XNameContainer > xDialogModel( mxMSF->createInstance ( OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlDialogModel" ) ) ), UNO_QUERY ); - Reference< XComponentContext > xContext; - Reference< beans::XPropertySet > xProps( mxMSF, UNO_QUERY ); - OSL_ASSERT( xProps.is() ); - OSL_VERIFY( xProps->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext")) ) >>= xContext ); + Reference< XComponentContext > xContext( + comphelper::getComponentContext( mxMSF ) ); ::xmlscript::importDialogModel( xInput, xDialogModel, xContext, mxOwnerDocument ); std::vector< rtl::OUString > vEmbeddedImageURLs; GraphicObject::InspectForGraphicObjectImageURL( Reference< XInterface >( xDialogModel, UNO_QUERY ), vEmbeddedImageURLs ); @@ -351,10 +337,8 @@ Any SAL_CALL SfxDialogLibraryContainer::importLibraryElement if( !xInput.is() ) return aRetAny; - Reference< XComponentContext > xContext; - Reference< beans::XPropertySet > xProps( mxMSF, UNO_QUERY ); - OSL_ASSERT( xProps.is() ); - OSL_VERIFY( xProps->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext")) ) >>= xContext ); + Reference< XComponentContext > xContext( + comphelper::getComponentContext( mxMSF ) ); InputSource source; source.aInputStream = xInput; diff --git a/basic/source/uno/namecont.cxx b/basic/source/uno/namecont.cxx index f8d946edd69c..77ced57a2eec 100644 --- a/basic/source/uno/namecont.cxx +++ b/basic/source/uno/namecont.cxx @@ -2725,29 +2725,20 @@ OUString SfxLibraryContainer::expand_url( const OUString& url ) { if( !mxMacroExpander.is() ) { - Reference< XPropertySet > xProps( mxMSF, UNO_QUERY_THROW ); - if( xProps.is() ) + Reference< XComponentContext > xContext( + comphelper::getComponentContext( mxMSF ) ); + Reference< util::XMacroExpander > xExpander; + xContext->getValueByName( + OUSTR("/singletons/com.sun.star.util.theMacroExpander") ) >>= xExpander; + if(! xExpander.is()) { - Reference< XComponentContext > xContext; - xProps->getPropertyValue( - OUString( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) >>= xContext; - SAL_WARN_IF(!xContext.is(), "basic", "no DefaultContext"); - if( xContext.is() ) - { - Reference< util::XMacroExpander > xExpander; - xContext->getValueByName( - OUSTR("/singletons/com.sun.star.util.theMacroExpander") ) >>= xExpander; - if(! xExpander.is()) - { - throw uno::DeploymentException( - OUSTR("no macro expander singleton available!"), Reference< XInterface >() ); - } - MutexGuard guard( Mutex::getGlobalMutex() ); - if( !mxMacroExpander.is() ) - { - mxMacroExpander = xExpander; - } - } + throw uno::DeploymentException( + OUSTR("no macro expander singleton available!"), Reference< XInterface >() ); + } + MutexGuard guard( Mutex::getGlobalMutex() ); + if( !mxMacroExpander.is() ) + { + mxMacroExpander = xExpander; } } @@ -3172,7 +3163,8 @@ void SAL_CALL SfxLibrary::removeChangesListener( const Reference< XChangesListen #define sDialogLibMediaType "application/vnd.sun.star.dialog-library" ScriptExtensionIterator::ScriptExtensionIterator( void ) - : m_eState( USER_EXTENSIONS ) + : m_xContext( comphelper::getProcessComponentContext() ) + , m_eState( USER_EXTENSIONS ) , m_bUserPackagesLoaded( false ) , m_bSharedPackagesLoaded( false ) , m_bBundledPackagesLoaded( false ) @@ -3180,22 +3172,7 @@ ScriptExtensionIterator::ScriptExtensionIterator( void ) , m_iSharedPackage( 0 ) , m_iBundledPackage( 0 ) , m_pScriptSubPackageIterator( NULL ) -{ - Reference< XMultiServiceFactory > xFactory = comphelper::getProcessServiceFactory(); - Reference< XPropertySet > xProps( xFactory, UNO_QUERY_THROW ); - if (xProps.is()) - { - xProps->getPropertyValue( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) >>= m_xContext; - SAL_WARN_IF(!m_xContext.is(), "basic", "no DefaultContext"); - } - if( !m_xContext.is() ) - { - throw RuntimeException( - ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ScriptExtensionIterator::init(), no XComponentContext")), - Reference< XInterface >() ); - } -} +{} rtl::OUString ScriptExtensionIterator::nextBasicOrDialogLibrary( bool& rbPureDialogLib ) { |