fdo#46808, Convert singleton theMasterScriptProviderFactory

Change-Id: I647a02e552acdd354463fc46c13c5a73b1c90d09
This commit is contained in:
Noel Grandin 2013-02-27 15:16:02 +02:00
parent cd8ea20aa4
commit a3bb733ec6
13 changed files with 115 additions and 116 deletions

View File

@ -22,30 +22,29 @@
#include <comphelper/processfactory.hxx>
#include <comphelper/string.hxx>
#include <com/sun/star/awt/XControlContainer.hpp>
#include <com/sun/star/awt/XControlModel.hpp>
#include <com/sun/star/awt/XControl.hpp>
#include <com/sun/star/awt/XDialog.hpp>
#include <com/sun/star/awt/XWindow.hpp>
#include <com/sun/star/awt/XDialogProvider.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/container/XEnumerationAccess.hpp>
#include <com/sun/star/container/XNameContainer.hpp>
#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/resource/XStringResourceSupplier.hpp>
#include <com/sun/star/resource/XStringResourceManager.hpp>
#include <com/sun/star/script/XEventAttacher.hpp>
#include <com/sun/star/script/XAllListener.hpp>
#include <com/sun/star/script/XScriptEventsSupplier.hpp>
#include <com/sun/star/script/XScriptEventsAttacher.hpp>
#include <com/sun/star/script/ScriptEventDescriptor.hpp>
#include <com/sun/star/script/XLibraryContainer.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/container/XNameContainer.hpp>
#include <com/sun/star/resource/XStringResourceSupplier.hpp>
#include <com/sun/star/resource/XStringResourceManager.hpp>
#include <com/sun/star/awt/XControlContainer.hpp>
#include <com/sun/star/awt/XControlModel.hpp>
#include <com/sun/star/awt/XControl.hpp>
#include <com/sun/star/awt/XDialog.hpp>
#include <com/sun/star/awt/XWindow.hpp>
#include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
#include <com/sun/star/script/provider/theMasterScriptProviderFactory.hpp>
#include <com/sun/star/script/provider/XScriptProviderSupplier.hpp>
#include <com/sun/star/script/provider/XScriptProvider.hpp>
#include <com/sun/star/awt/XDialogProvider.hpp>
#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/container/XEnumerationAccess.hpp>
#include <basic/basicmanagerrepository.hxx>
#include <basic/basmgr.hxx>
//==================================================================================================
@ -93,16 +92,12 @@ void SFURL_firing_impl( const ScriptEvent& aScriptEvent, Any* pRet, const Refere
{
Reference< XComponentContext > xContext(
comphelper::getProcessComponentContext() );
Reference< provider::XScriptProviderFactory > xFactory(
xContext->getValueByName(
OUString("/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 <<= OUString("user");
xScriptProvider.set( xFactory->createScriptProvider( aCtx ), UNO_QUERY );
}
Reference< provider::XScriptProviderFactory > xFactory =
provider::theMasterScriptProviderFactory::get( xContext );
Any aCtx;
aCtx <<= OUString("user");
xScriptProvider.set( xFactory->createScriptProvider( aCtx ), UNO_QUERY );
}
if ( !xScriptProvider.is() )

View File

@ -45,7 +45,7 @@
#include <com/sun/star/io/XSeekable.hpp>
#include <com/sun/star/io/XOutputStream.hpp>
#include <com/sun/star/io/XTruncate.hpp>
#include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
#include <com/sun/star/script/provider/theMasterScriptProviderFactory.hpp>
#include <com/sun/star/sdb/DatabaseContext.hpp>
#include <com/sun/star/sdb/application/XDatabaseDocumentUI.hpp>
#include <com/sun/star/task/ErrorCodeIOException.hpp>
@ -1968,8 +1968,8 @@ Reference< provider::XScriptProvider > SAL_CALL ODatabaseDocument::getScriptProv
Reference< XScriptProvider > xScriptProvider( m_xScriptProvider );
if ( !xScriptProvider.is() )
{
Reference < XScriptProviderFactory > xFactory(
m_pImpl->m_aContext.getSingleton( "com.sun.star.script.provider.theMasterScriptProviderFactory" ), UNO_QUERY_THROW );
Reference < XScriptProviderFactory > xFactory =
theMasterScriptProviderFactory::get( m_pImpl->m_aContext.getUNOContext() );
Any aScriptProviderContext;
if ( m_bAllowDocumentScripting )

View File

@ -27,7 +27,7 @@
#include "comphelper/servicedecl.hxx"
#include "svl/inettype.hxx"
#include <com/sun/star/container/XNameContainer.hpp>
#include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
#include <com/sun/star/script/provider/theMasterScriptProviderFactory.hpp>
#include <com/sun/star/xml/sax/Parser.hpp>
#include <memory>
@ -304,17 +304,13 @@ void BackendImpl::PackageImpl:: initPackageHandler()
// NOT supported at the momemtn // TODO
}
Reference< provider::XScriptProviderFactory > xFac(
that->getComponentContext()->getValueByName(
"/singletons/com.sun.star.script.provider.theMasterScriptProviderFactory"), UNO_QUERY );
Reference< provider::XScriptProviderFactory > xFac =
provider::theMasterScriptProviderFactory::get( that->getComponentContext() );
if ( xFac.is() )
Reference< container::XNameContainer > xName( xFac->createScriptProvider( aContext ), UNO_QUERY );
if ( xName.is() )
{
Reference< container::XNameContainer > xName( xFac->createScriptProvider( aContext ), UNO_QUERY );
if ( xName.is() )
{
m_xNameCntrPkgHandler.set( xName );
}
m_xNameCntrPkgHandler.set( xName );
}
// TODO what happens if above fails??
}

View File

@ -268,6 +268,8 @@ $(eval $(call gb_UnoApi_add_idlfiles_nohdl,offapi,offapi/com/sun/star/script,\
DocumentScriptLibraryContainer \
))
$(eval $(call gb_UnoApi_add_idlfiles_nohdl,offapi,offapi/com/sun/star/script/provider,\
theMasterScriptProviderFactory \
MasterScriptProviderFactory \
ScriptURIHelper \
))
$(eval $(call gb_UnoApi_add_idlfiles_nohdl,offapi,offapi/com/sun/star/script/vba,\
@ -989,7 +991,6 @@ $(eval $(call gb_UnoApi_add_idlfiles_noheader,offapi,offapi/com/sun/star/script/
$(eval $(call gb_UnoApi_add_idlfiles_noheader,offapi,offapi/com/sun/star/script/provider,\
LanguageScriptProvider \
MasterScriptProvider \
MasterScriptProviderFactory \
ScriptProvider \
ScriptProviderForBasic \
ScriptProviderForBeanShell \

View File

@ -29,25 +29,10 @@ module com { module sun { module star { module script { module provider {
This service is used to create MasterScriptProviders.
Note: You shouldn't ever instantiate the MasterScriptProvider
service directly, you should always use this service.
@deprecated rather use the singleton service theMasterScriptProviderFactory
*/
service MasterScriptProviderFactory
{
interface XScriptProviderFactory;
};
/**
The one and only MasterScriptProviderFactory
To get the singleton call getValueByName on the component context
<pre>
/singletons/com.sun.star.script.provider.theMasterScriptProviderFactory
</pre>
*/
singleton theMasterScriptProviderFactory
{
service MasterScriptProviderFactory;
};
service MasterScriptProviderFactory : XScriptProviderFactory;
}; }; }; }; };

View File

@ -0,0 +1,43 @@
/* -*- 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 __com_sun_star_script_provider_theMasterScriptProviderFactory_idl__
#define __com_sun_star_script_provider_theMasterScriptProviderFactory_idl__
#include <com/sun/star/script/provider/XScriptProviderFactory.idl>
module com { module sun { module star { module script { module provider {
/**
The one and only MasterScriptProviderFactory
To get the singleton call getValueByName on the component context
<pre>
/singletons/com.sun.star.script.provider.theMasterScriptProviderFactory
</pre>
*/
singleton theMasterScriptProviderFactory : XScriptProviderFactory;
}; }; }; }; };
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -34,7 +34,7 @@
#include <com/sun/star/script/ScriptEventDescriptor.hpp>
#include <com/sun/star/script/XScriptEventsSupplier.hpp>
#include <com/sun/star/script/provider/XScriptProvider.hpp>
#include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
#include <com/sun/star/script/provider/theMasterScriptProviderFactory.hpp>
#include <com/sun/star/script/provider/XScriptProviderSupplier.hpp>
#include <com/sun/star/script/vba/XVBACompatibility.hpp>
#include <com/sun/star/lang/NoSuchMethodException.hpp>
@ -485,17 +485,12 @@ namespace dlgprov
OSL_ASSERT( m_xContext.is() );
if ( m_xContext.is() )
{
Reference< provider::XScriptProviderFactory > xFactory(
m_xContext->getValueByName(
::rtl::OUString("/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("user");
xScriptProvider.set( xFactory->createScriptProvider( aCtx ), UNO_QUERY );
}
Reference< provider::XScriptProviderFactory > xFactory =
provider::theMasterScriptProviderFactory::get( m_xContext );
Any aCtx;
aCtx <<= ::rtl::OUString("user");
xScriptProvider.set( xFactory->createScriptProvider( aCtx ), UNO_QUERY );
}
}

View File

@ -32,7 +32,7 @@
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
#include <com/sun/star/script/provider/XScriptProviderSupplier.hpp>
#include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
#include <com/sun/star/script/provider/theMasterScriptProviderFactory.hpp>
#include <com/sun/star/script/provider/ScriptFrameworkErrorType.hpp>
#include <sfx2/objsh.hxx>
@ -88,7 +88,7 @@ void SAL_CALL ScriptProtocolHandler::initialize(
throw RuntimeException( temp, Reference< XInterface >() );
}
ENSURE_OR_THROW( m_xFactory.is(), "ScriptProtocolHandler::initialize: No Service Manager available" );
ENSURE_OR_THROW( m_xContext.is(), "ScriptProtocolHandler::initialize: No Service Manager available" );
m_bInitialised = true;
}
@ -102,7 +102,7 @@ Reference< XDispatch > SAL_CALL ScriptProtocolHandler::queryDispatch(
Reference< XDispatch > xDispatcher;
// get scheme of url
Reference< uri::XUriReferenceFactory > xFac = uri::UriReferenceFactory::create( comphelper::getComponentContext(m_xFactory) );
Reference< uri::XUriReferenceFactory > xFac = uri::UriReferenceFactory::create( m_xContext );
Reference< uri::XUriReference > uriRef(
xFac->parse( aURL.Complete ), UNO_QUERY );
if ( uriRef.is() )
@ -378,14 +378,8 @@ void ScriptProtocolHandler::createScriptProvider()
// if nothing of this is successful, use the master script provider
if ( !m_xScriptProvider.is() )
{
Reference< XComponentContext > xCtx(
comphelper::getComponentContext( m_xFactory ) );
::rtl::OUString tmspf(
"/singletons/com.sun.star.script.provider.theMasterScriptProviderFactory");
Reference< provider::XScriptProviderFactory > xFac(
xCtx->getValueByName( tmspf ), UNO_QUERY_THROW );
Reference< provider::XScriptProviderFactory > xFac =
provider::theMasterScriptProviderFactory::get( m_xContext );
Any aContext;
if ( getScriptInvocation() )
@ -406,9 +400,8 @@ void ScriptProtocolHandler::createScriptProvider()
}
}
ScriptProtocolHandler::ScriptProtocolHandler(
Reference< css::lang::XMultiServiceFactory > const& rFact ) :
m_bInitialised( false ), m_xFactory( rFact )
ScriptProtocolHandler::ScriptProtocolHandler( const Reference< css::uno::XComponentContext > & xContext )
: m_bInitialised( false ), m_xContext( xContext )
{
}
@ -469,7 +462,7 @@ Reference< XInterface > SAL_CALL ScriptProtocolHandler::impl_createInstance(
const Reference< css::lang::XMultiServiceFactory >& xServiceManager )
throw( RuntimeException )
{
return Reference< XInterface > ( *new ScriptProtocolHandler( xServiceManager ) );
return Reference< XInterface > ( *new ScriptProtocolHandler( comphelper::getComponentContext(xServiceManager) ) );
}
/* Factory for registration */

View File

@ -40,6 +40,7 @@ namespace com { namespace sun { namespace star {
}
namespace uno {
class Any;
class XComponentContext;
}
namespace lang {
class XMultiServiceFactory;
@ -69,7 +70,7 @@ public ::cppu::WeakImplHelper4< css::frame::XDispatchProvider,
{
private:
bool m_bInitialised;
css::uno::Reference < css::lang::XMultiServiceFactory > m_xFactory;
css::uno::Reference < css::uno::XComponentContext > m_xContext;
css::uno::Reference < css::frame::XFrame > m_xFrame;
css::uno::Reference < css::script::provider::XScriptProvider > m_xScriptProvider;
css::uno::Reference< css::document::XScriptInvocationContext > m_xScriptInvocation;
@ -78,8 +79,7 @@ private:
bool getScriptInvocation();
public:
ScriptProtocolHandler( const css::uno::Reference <
css::lang::XMultiServiceFactory >& xFactory );
ScriptProtocolHandler( const css::uno::Reference < css::uno::XComponentContext >& xContext );
virtual ~ScriptProtocolHandler();
/* XServiceInfo */

View File

@ -29,7 +29,7 @@
#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/reflection/ProxyFactory.hpp>
#include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
#include <com/sun/star/script/provider/theMasterScriptProviderFactory.hpp>
#include <com/sun/star/script/browse/BrowseNodeFactoryViewTypes.hpp>
#include <com/sun/star/document/XScriptInvocationContext.hpp>
@ -297,9 +297,6 @@ namespace
Sequence< Reference< browse::XBrowseNode > > getAllBrowseNodes( const Reference< XComponentContext >& xCtx )
{
Reference< lang::XMultiComponentFactory > mcf =
xCtx->getServiceManager();
Sequence< ::rtl::OUString > openDocs =
MiscUtils::allOpenTDocUrls( xCtx );
@ -310,9 +307,7 @@ Sequence< Reference< browse::XBrowseNode > > getAllBrowseNodes( const Reference<
Sequence < Reference < browse::XBrowseNode > > locnBNs( initialSize );
try
{
xFac.set(
xCtx->getValueByName(
"/singletons/com.sun.star.script.provider.theMasterScriptProviderFactory" ), UNO_QUERY_THROW );
xFac = provider::theMasterScriptProviderFactory::get( xCtx );
locnBNs[ mspIndex++ ] = Reference< browse::XBrowseNode >( xFac->createScriptProvider( makeAny( ::rtl::OUString("user") ) ), UNO_QUERY_THROW );
locnBNs[ mspIndex++ ] = Reference< browse::XBrowseNode >( xFac->createScriptProvider( makeAny( ::rtl::OUString("share") ) ), UNO_QUERY_THROW );

View File

@ -36,7 +36,7 @@
#include <com/sun/star/deployment/XPackage.hpp>
#include <com/sun/star/script/browse/BrowseNodeTypes.hpp>
#include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
#include <com/sun/star/script/provider/theMasterScriptProviderFactory.hpp>
#include <com/sun/star/script/provider/ScriptFrameworkErrorType.hpp>
#include <util/scriptingconstants.hxx>
@ -224,9 +224,8 @@ void MasterScriptProvider::createPkgProvider()
::rtl::OUString sPkgCtx = m_sCtxString.concat( ":uno_packages" );
location <<= sPkgCtx;
Reference< provider::XScriptProviderFactory > xFac(
m_xContext->getValueByName(
"/singletons/com.sun.star.script.provider.theMasterScriptProviderFactory" ), UNO_QUERY_THROW );
Reference< provider::XScriptProviderFactory > xFac =
provider::theMasterScriptProviderFactory::get( m_xContext );
m_xMSPPkg.set(
xFac->createScriptProvider( location ), UNO_QUERY_THROW );
@ -362,9 +361,8 @@ throw ( provider::ScriptFrameworkErrorException,
}
else
{
Reference< provider::XScriptProviderFactory > xFac_(
m_xContext->getValueByName(
"/singletons/com.sun.star.script.provider.theMasterScriptProviderFactory" ), UNO_QUERY_THROW );
Reference< provider::XScriptProviderFactory > xFac_ =
provider::theMasterScriptProviderFactory::get( m_xContext );
Reference< provider::XScriptProvider > xSP(
xFac_->createScriptProvider( makeAny( location ) ), UNO_QUERY_THROW );

View File

@ -27,12 +27,16 @@
#include <osl/mutex.hxx>
#include <cppuhelper/exc_hlp.hxx>
#include <com/sun/star/container/XChild.hpp>
#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
#include <com/sun/star/document/XDocumentProperties.hpp>
#include <com/sun/star/document/UpdateDocMode.hpp>
#include <com/sun/star/document/MacroExecMode.hpp>
#include <com/sun/star/document/XScriptInvocationContext.hpp>
#include <com/sun/star/embed/EmbedStates.hpp>
#include <com/sun/star/embed/XEmbedPersist.hpp>
#include <com/sun/star/logging/DocumentIOLogRing.hpp>
#include <com/sun/star/script/XTypeConverter.hpp>
#include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
#include <com/sun/star/script/FinishEngineEvent.hpp>
#include <com/sun/star/script/InterruptReason.hpp>
#include <com/sun/star/script/XEngineListener.hpp>
@ -43,16 +47,12 @@
#include <com/sun/star/script/XEngine.hpp>
#include <com/sun/star/script/InterruptEngineEvent.hpp>
#include <com/sun/star/script/XLibraryAccess.hpp>
#include <com/sun/star/document/MacroExecMode.hpp>
#include <com/sun/star/document/XScriptInvocationContext.hpp>
#include <com/sun/star/embed/EmbedStates.hpp>
#include <com/sun/star/embed/XEmbedPersist.hpp>
#include <com/sun/star/util/XModifiable.hpp>
#include <com/sun/star/container/XChild.hpp>
#include <com/sun/star/ucb/SimpleFileAccess.hpp>
#include <com/sun/star/script/provider/theMasterScriptProviderFactory.hpp>
#include <com/sun/star/script/provider/XScript.hpp>
#include <com/sun/star/script/provider/XScriptProvider.hpp>
#include <com/sun/star/script/provider/XScriptProviderSupplier.hpp>
#include <com/sun/star/ucb/SimpleFileAccess.hpp>
#include <com/sun/star/util/XModifiable.hpp>
#include <toolkit/unohlp.hxx>
@ -1541,9 +1541,8 @@ ErrCode SfxObjectShell::CallXScript( const Reference< XInterface >& _rxScriptCon
if ( !xScriptProvider.is() )
{
::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
Reference< provider::XScriptProviderFactory > xScriptProviderFactory(
aContext.getSingleton( "com.sun.star.script.provider.theMasterScriptProviderFactory" ), UNO_QUERY_THROW );
Reference< provider::XScriptProviderFactory > xScriptProviderFactory =
provider::theMasterScriptProviderFactory::get( ::comphelper::getProcessComponentContext() );
xScriptProvider.set( xScriptProviderFactory->createScriptProvider( makeAny( _rxScriptContext ) ), UNO_SET_THROW );
}

View File

@ -39,7 +39,7 @@
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/beans/XPropertySetInfo.hpp>
#include <com/sun/star/container/XIndexContainer.hpp>
#include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
#include <com/sun/star/script/provider/theMasterScriptProviderFactory.hpp>
#include <com/sun/star/script/provider/XScriptProvider.hpp>
#include <com/sun/star/ui/UIConfigurationManager.hpp>
#include <com/sun/star/embed/ElementModes.hpp>
@ -3403,9 +3403,8 @@ uno::Reference< script::provider::XScriptProvider > SAL_CALL SfxBaseModel::getSc
uno::Reference< script::provider::XScriptProvider > xScriptProvider;
::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
Reference< script::provider::XScriptProviderFactory > xScriptProviderFactory(
aContext.getSingleton( "com.sun.star.script.provider.theMasterScriptProviderFactory" ), uno::UNO_QUERY_THROW );
Reference< script::provider::XScriptProviderFactory > xScriptProviderFactory =
script::provider::theMasterScriptProviderFactory::get( ::comphelper::getProcessComponentContext() );
try
{