From b679a2a02180c017bd8b596fb2e4f283bad93b75 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Tue, 4 Sep 2012 16:12:17 +0200 Subject: fdo#46808, Adapt reflection::CoreReflection UNO service to new style The XComponent part of the interface made no sense for a singleton, so it was removed. Explicitly document the 'theCoreReflection' singleton and move it into it's own file. Deprecated the now old CoreReflection service. Change-Id: Ib8befa87c7da7eb53a2f587948fd54a64c082472 --- .../source/eventattachermgr/eventattachermgr.cxx | 22 +++++++------- eventattacher/source/eventattacher.cxx | 4 +-- extensions/source/ole/unoobjw.cxx | 34 ++++++++++----------- extensions/test/ole/cpnt/cpnt.cxx | 35 +++++++++++----------- pyuno/source/module/pyuno_runtime.cxx | 13 +++----- udkapi/UnoApi_udkapi.mk | 3 ++ udkapi/com/sun/star/reflection/CoreReflection.idl | 10 ++----- .../com/sun/star/reflection/theCoreReflection.idl | 35 ++++++++++++++++++++++ 8 files changed, 91 insertions(+), 65 deletions(-) create mode 100644 udkapi/com/sun/star/reflection/theCoreReflection.idl diff --git a/comphelper/source/eventattachermgr/eventattachermgr.cxx b/comphelper/source/eventattachermgr/eventattachermgr.cxx index 644d2d9a54ef..9b2402604b7c 100644 --- a/comphelper/source/eventattachermgr/eventattachermgr.cxx +++ b/comphelper/source/eventattachermgr/eventattachermgr.cxx @@ -23,6 +23,7 @@ #endif #include #include +#include #include #include #include @@ -31,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -94,14 +96,14 @@ class ImplEventAttacherManager OInterfaceContainerHelper aScriptListeners; // Instance of EventAttacher Reference< XEventAttacher2 > xAttacher; - Reference< XMultiServiceFactory > mxSMgr; + Reference< XComponentContext > mxContext; Reference< XIdlReflection > mxCoreReflection; Reference< XIntrospection > mxIntrospection; Reference< XTypeConverter > xConverter; sal_Int16 nVersion; public: ImplEventAttacherManager( const Reference< XIntrospection > & rIntrospection, - const Reference< XMultiServiceFactory > rSMgr ); + const Reference< XComponentContext > xContext ); ~ImplEventAttacherManager(); // Methods of XEventAttacherManager @@ -361,7 +363,7 @@ Reference< XEventAttacherManager > createEventAttacherManager( const Reference< if ( xIFace.is() ) { Reference< XIntrospection > xIntrospection( xIFace, UNO_QUERY); - return new ImplEventAttacherManager( xIntrospection, rSMgr ); + return new ImplEventAttacherManager( xIntrospection, comphelper::ComponentContext(rSMgr).getUNOContext() ); } } @@ -370,19 +372,20 @@ Reference< XEventAttacherManager > createEventAttacherManager( const Reference< //----------------------------------------------------------------------------- ImplEventAttacherManager::ImplEventAttacherManager( const Reference< XIntrospection > & rIntrospection, - const Reference< XMultiServiceFactory > rSMgr ) + const Reference< XComponentContext > xContext ) : aScriptListeners( aLock ) - , mxSMgr( rSMgr ) + , mxContext( xContext ) , mxIntrospection( rIntrospection ) { - if ( rSMgr.is() ) + if ( xContext.is() ) { - Reference< XInterface > xIFace( rSMgr->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.script.EventAttacher" )) ) ); + Reference< XInterface > xIFace( xContext->getServiceManager()->createInstanceWithContext( + OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.script.EventAttacher" )), xContext) ); if ( xIFace.is() ) { xAttacher = Reference< XEventAttacher2 >::query( xIFace ); } - xConverter = Converter::create(comphelper::ComponentContext(rSMgr).getUNOContext()); + xConverter = Converter::create(xContext); } Reference< XInitialization > xInit( xAttacher, UNO_QUERY ); @@ -405,8 +408,7 @@ Reference< XIdlReflection > ImplEventAttacherManager::getReflection() throw( Exc // Do we already have a service? If not, create one. if( !mxCoreReflection.is() ) { - Reference< XInterface > xIFace( mxSMgr->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.reflection.CoreReflection" )) ) ); - mxCoreReflection = Reference< XIdlReflection >( xIFace, UNO_QUERY); + mxCoreReflection = theCoreReflection::get(mxContext); } return mxCoreReflection; } diff --git a/eventattacher/source/eventattacher.cxx b/eventattacher/source/eventattacher.cxx index 06764fefb994..0d04048ffca2 100644 --- a/eventattacher/source/eventattacher.cxx +++ b/eventattacher/source/eventattacher.cxx @@ -28,6 +28,7 @@ #include #include #include +#include #include // InvocationToAllListenerMapper @@ -407,8 +408,7 @@ Reference< XIdlReflection > EventAttacherImpl::getReflection() throw( Exception Guard< Mutex > aGuard( m_aMutex ); if( !m_xReflection.is() ) { - Reference< XInterface > xIFace( m_xSMgr->createInstance( rtl::OUString("com.sun.star.reflection.CoreReflection") ) ); - m_xReflection = Reference< XIdlReflection >( xIFace, UNO_QUERY); + m_xReflection = theCoreReflection::get(comphelper::ComponentContext(m_xSMgr).getUNOContext()); } return m_xReflection; } diff --git a/extensions/source/ole/unoobjw.cxx b/extensions/source/ole/unoobjw.cxx index 641e643234dc..cb0c40839c6d 100644 --- a/extensions/source/ole/unoobjw.cxx +++ b/extensions/source/ole/unoobjw.cxx @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -53,6 +54,7 @@ #include #include #include +#include #include #include "comifaces.hxx" @@ -1120,27 +1122,23 @@ HRESULT InterfaceOleWrapper_Impl::InvokeGeneral( DISPID dispidMember, unsigned s sal_Bool bStruct= sal_False; - Reference xIntCore= m_smgr->createInstance( OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.reflection.CoreReflection"))); - Reference xRefl( xIntCore, UNO_QUERY); - if( xRefl.is() ) + Reference xRefl = theCoreReflection::get(comphelper::ComponentContext(m_smgr).getUNOContext()); + // the first parameter is in DISPPARAMS rgvargs contains the name of the struct. + CComVariant arg; + if( pdispparams->cArgs == 1 && SUCCEEDED( arg.ChangeType( VT_BSTR, &pdispparams->rgvarg[0])) ) { - // the first parameter is in DISPPARAMS rgvargs contains the name of the struct. - CComVariant arg; - if( pdispparams->cArgs == 1 && SUCCEEDED( arg.ChangeType( VT_BSTR, &pdispparams->rgvarg[0])) ) + Reference classStruct= xRefl->forName( reinterpret_cast(arg.bstrVal)); + if( classStruct.is()) { - Reference classStruct= xRefl->forName( reinterpret_cast(arg.bstrVal)); - if( classStruct.is()) - { - Any anyStruct; - classStruct->createObject( anyStruct); - CComVariant var; - anyToVariant( &var, anyStruct ); + Any anyStruct; + classStruct->createObject( anyStruct); + CComVariant var; + anyToVariant( &var, anyStruct ); - if( var.vt == VT_DISPATCH) - { - VariantCopy( pvarResult, & var); - bStruct= sal_True; - } + if( var.vt == VT_DISPATCH) + { + VariantCopy( pvarResult, & var); + bStruct= sal_True; } } } diff --git a/extensions/test/ole/cpnt/cpnt.cxx b/extensions/test/ole/cpnt/cpnt.cxx index b20795ecf003..0f9448815f95 100644 --- a/extensions/test/ole/cpnt/cpnt.cxx +++ b/extensions/test/ole/cpnt/cpnt.cxx @@ -33,12 +33,14 @@ #include #include #include +#include #include // OPTIONAL is a constant in com.sun.star.beans.PropertyAttributes but it must be // undef'd in some header files #define OPTIONAL OPTIONAL #include #include +#include #include #include @@ -1491,27 +1493,24 @@ void SAL_CALL OComponent::testInterface( const Reference< XCallback >& xCallbac } case 101: { - Reference xRefl( m_rFactory->createInstance(L"com.sun.star.reflection.CoreReflection"), UNO_QUERY); - if( xRefl.is()) - { - Reference xClass= xRefl->forName(L"oletest.SimpleStruct"); - Any any; - if( xClass.is()) - xClass->createObject( any); - - if( any.getValueTypeClass() == TypeClass_STRUCT) - { - SimpleStruct* pStruct= ( SimpleStruct*) any.getValue(); - pStruct->message= OUString(RTL_CONSTASCII_USTRINGPARAM("This struct was created in OleTest")); + Reference xRefl( theCoreReflection::get(comphelper::ComponentContext(m_rFactory).getUNOContext()) ); + Reference xClass= xRefl->forName(L"oletest.SimpleStruct"); + Any any; + if( xClass.is()) + xClass->createObject( any); - SimpleStruct aStruct; - any >>= aStruct; - xCallback->inoutStruct( aStruct); - // a Struct should now contain a different message - MessageBox( NULL, W2T(aStruct.message), _T("OleTest in out parameter"), MB_OK); - } + if( any.getValueTypeClass() == TypeClass_STRUCT) + { + SimpleStruct* pStruct= ( SimpleStruct*) any.getValue(); + pStruct->message= OUString(RTL_CONSTASCII_USTRINGPARAM("This struct was created in OleTest")); + SimpleStruct aStruct; + any >>= aStruct; + xCallback->inoutStruct( aStruct); + // a Struct should now contain a different message + MessageBox( NULL, W2T(aStruct.message), _T("OleTest in out parameter"), MB_OK); } + break; } case 102: diff --git a/pyuno/source/module/pyuno_runtime.cxx b/pyuno/source/module/pyuno_runtime.cxx index 3196be6e399f..a89b1822cbbc 100644 --- a/pyuno/source/module/pyuno_runtime.cxx +++ b/pyuno/source/module/pyuno_runtime.cxx @@ -31,6 +31,7 @@ #include #include +#include using rtl::OUString; using rtl::OUStringToOString; @@ -45,11 +46,13 @@ using com::sun::star::uno::TypeDescription; using com::sun::star::uno::Sequence; using com::sun::star::uno::Type; using com::sun::star::uno::UNO_QUERY; +using com::sun::star::uno::UNO_QUERY_THROW; using com::sun::star::uno::Exception; using com::sun::star::uno::RuntimeException; using com::sun::star::uno::XComponentContext; using com::sun::star::lang::XSingleServiceFactory; using com::sun::star::lang::XUnoTunnel; +using com::sun::star::reflection::theCoreReflection; using com::sun::star::reflection::XIdlReflection; using com::sun::star::script::Converter; using com::sun::star::script::XTypeConverter; @@ -264,15 +267,7 @@ PyRef stRuntimeImpl::create( const Reference< XComponentContext > &ctx ) OUString( "pyuno: couldn't instantiate typeconverter service" ), Reference< XInterface > () ); - c->xCoreReflection = Reference< XIdlReflection > ( - ctx->getServiceManager()->createInstanceWithContext( - OUString( "com.sun.star.reflection.CoreReflection" ), - ctx ), - UNO_QUERY ); - if( ! c->xCoreReflection.is() ) - throw RuntimeException( - OUString( "pyuno: couldn't instantiate corereflection service" ), - Reference< XInterface > () ); + c->xCoreReflection = theCoreReflection::get(ctx); c->xAdapterFactory = Reference< XInvocationAdapterFactory2 > ( ctx->getServiceManager()->createInstanceWithContext( diff --git a/udkapi/UnoApi_udkapi.mk b/udkapi/UnoApi_udkapi.mk index d909fb62972e..cdffbda1dd7c 100644 --- a/udkapi/UnoApi_udkapi.mk +++ b/udkapi/UnoApi_udkapi.mk @@ -143,6 +143,9 @@ $(eval $(call gb_UnoApi_add_idlfiles_nohdl,udkapi,udkapi/com/sun/star/io,\ SequenceOutputStream \ TempFile \ )) +$(eval $(call gb_UnoApi_add_idlfiles_nohdl,udkapi,udkapi/com/sun/star/reflection,\ + theCoreReflection \ +)) $(eval $(call gb_UnoApi_add_idlfiles_nohdl,udkapi,udkapi/com/sun/star/registry,\ ImplementationRegistration \ SimpleRegistry \ diff --git a/udkapi/com/sun/star/reflection/CoreReflection.idl b/udkapi/com/sun/star/reflection/CoreReflection.idl index 8dc78a331aac..7d2cddee3eaa 100644 --- a/udkapi/com/sun/star/reflection/CoreReflection.idl +++ b/udkapi/com/sun/star/reflection/CoreReflection.idl @@ -30,6 +30,8 @@ /** This service is the implementation of the reflection API. You can obtain information about types, modify values of reflected types and call on objects. + + @deprecated Rather use the 'theCoreReflection' singleton. */ published service CoreReflection { @@ -42,14 +44,6 @@ published service CoreReflection [optional] interface com::sun::star::lang::XComponent; }; -/** Accessable singleton to CoreReflection instance. -singleton theCoreReflection -{ - service CoreReflection; -}; -*/ - - }; }; }; }; #endif diff --git a/udkapi/com/sun/star/reflection/theCoreReflection.idl b/udkapi/com/sun/star/reflection/theCoreReflection.idl new file mode 100644 index 000000000000..f60914e1c8fd --- /dev/null +++ b/udkapi/com/sun/star/reflection/theCoreReflection.idl @@ -0,0 +1,35 @@ +/* -*- 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_reflection_theCoreReflection_idl__ +#define __com_sun_star_reflection_theCoreReflection_idl__ + +#include + + +module com { module sun { module star { module reflection { + + +singleton theCoreReflection : com::sun::star::reflection::XIdlReflection; + + +}; }; }; }; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3