Kaydet (Commit) b679a2a0 authored tarafından Noel Grandin's avatar Noel Grandin Kaydeden (comit) Stephan Bergmann

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
üst 3bb22684
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#endif #endif
#include <osl/mutex.hxx> #include <osl/mutex.hxx>
#include <osl/diagnose.h> #include <osl/diagnose.h>
#include <comphelper/componentcontext.hxx>
#include <comphelper/eventattachermgr.hxx> #include <comphelper/eventattachermgr.hxx>
#include <com/sun/star/beans/XIntrospection.hpp> #include <com/sun/star/beans/XIntrospection.hpp>
#include <com/sun/star/io/XObjectInputStream.hpp> #include <com/sun/star/io/XObjectInputStream.hpp>
...@@ -31,6 +32,7 @@ ...@@ -31,6 +32,7 @@
#include <com/sun/star/io/XMarkableStream.hpp> #include <com/sun/star/io/XMarkableStream.hpp>
#include <com/sun/star/lang/XInitialization.hpp> #include <com/sun/star/lang/XInitialization.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/reflection/theCoreReflection.hpp>
#include <com/sun/star/reflection/XIdlClass.hpp> #include <com/sun/star/reflection/XIdlClass.hpp>
#include <com/sun/star/reflection/XIdlReflection.hpp> #include <com/sun/star/reflection/XIdlReflection.hpp>
#include <com/sun/star/reflection/XIdlMethod.hpp> #include <com/sun/star/reflection/XIdlMethod.hpp>
...@@ -94,14 +96,14 @@ class ImplEventAttacherManager ...@@ -94,14 +96,14 @@ class ImplEventAttacherManager
OInterfaceContainerHelper aScriptListeners; OInterfaceContainerHelper aScriptListeners;
// Instance of EventAttacher // Instance of EventAttacher
Reference< XEventAttacher2 > xAttacher; Reference< XEventAttacher2 > xAttacher;
Reference< XMultiServiceFactory > mxSMgr; Reference< XComponentContext > mxContext;
Reference< XIdlReflection > mxCoreReflection; Reference< XIdlReflection > mxCoreReflection;
Reference< XIntrospection > mxIntrospection; Reference< XIntrospection > mxIntrospection;
Reference< XTypeConverter > xConverter; Reference< XTypeConverter > xConverter;
sal_Int16 nVersion; sal_Int16 nVersion;
public: public:
ImplEventAttacherManager( const Reference< XIntrospection > & rIntrospection, ImplEventAttacherManager( const Reference< XIntrospection > & rIntrospection,
const Reference< XMultiServiceFactory > rSMgr ); const Reference< XComponentContext > xContext );
~ImplEventAttacherManager(); ~ImplEventAttacherManager();
// Methods of XEventAttacherManager // Methods of XEventAttacherManager
...@@ -361,7 +363,7 @@ Reference< XEventAttacherManager > createEventAttacherManager( const Reference< ...@@ -361,7 +363,7 @@ Reference< XEventAttacherManager > createEventAttacherManager( const Reference<
if ( xIFace.is() ) if ( xIFace.is() )
{ {
Reference< XIntrospection > xIntrospection( xIFace, UNO_QUERY); 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< ...@@ -370,19 +372,20 @@ Reference< XEventAttacherManager > createEventAttacherManager( const Reference<
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
ImplEventAttacherManager::ImplEventAttacherManager( const Reference< XIntrospection > & rIntrospection, ImplEventAttacherManager::ImplEventAttacherManager( const Reference< XIntrospection > & rIntrospection,
const Reference< XMultiServiceFactory > rSMgr ) const Reference< XComponentContext > xContext )
: aScriptListeners( aLock ) : aScriptListeners( aLock )
, mxSMgr( rSMgr ) , mxContext( xContext )
, mxIntrospection( rIntrospection ) , 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() ) if ( xIFace.is() )
{ {
xAttacher = Reference< XEventAttacher2 >::query( xIFace ); xAttacher = Reference< XEventAttacher2 >::query( xIFace );
} }
xConverter = Converter::create(comphelper::ComponentContext(rSMgr).getUNOContext()); xConverter = Converter::create(xContext);
} }
Reference< XInitialization > xInit( xAttacher, UNO_QUERY ); Reference< XInitialization > xInit( xAttacher, UNO_QUERY );
...@@ -405,8 +408,7 @@ Reference< XIdlReflection > ImplEventAttacherManager::getReflection() throw( Exc ...@@ -405,8 +408,7 @@ Reference< XIdlReflection > ImplEventAttacherManager::getReflection() throw( Exc
// Do we already have a service? If not, create one. // Do we already have a service? If not, create one.
if( !mxCoreReflection.is() ) if( !mxCoreReflection.is() )
{ {
Reference< XInterface > xIFace( mxSMgr->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.reflection.CoreReflection" )) ) ); mxCoreReflection = theCoreReflection::get(mxContext);
mxCoreReflection = Reference< XIdlReflection >( xIFace, UNO_QUERY);
} }
return mxCoreReflection; return mxCoreReflection;
} }
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <com/sun/star/script/Converter.hpp> #include <com/sun/star/script/Converter.hpp>
#include <com/sun/star/script/XAllListener.hpp> #include <com/sun/star/script/XAllListener.hpp>
#include <com/sun/star/script/XInvocationAdapterFactory.hpp> #include <com/sun/star/script/XInvocationAdapterFactory.hpp>
#include <com/sun/star/reflection/theCoreReflection.hpp>
#include <com/sun/star/reflection/XIdlReflection.hpp> #include <com/sun/star/reflection/XIdlReflection.hpp>
// InvocationToAllListenerMapper // InvocationToAllListenerMapper
...@@ -407,8 +408,7 @@ Reference< XIdlReflection > EventAttacherImpl::getReflection() throw( Exception ...@@ -407,8 +408,7 @@ Reference< XIdlReflection > EventAttacherImpl::getReflection() throw( Exception
Guard< Mutex > aGuard( m_aMutex ); Guard< Mutex > aGuard( m_aMutex );
if( !m_xReflection.is() ) if( !m_xReflection.is() )
{ {
Reference< XInterface > xIFace( m_xSMgr->createInstance( rtl::OUString("com.sun.star.reflection.CoreReflection") ) ); m_xReflection = theCoreReflection::get(comphelper::ComponentContext(m_xSMgr).getUNOContext());
m_xReflection = Reference< XIdlReflection >( xIFace, UNO_QUERY);
} }
return m_xReflection; return m_xReflection;
} }
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include <com/sun/star/beans/MethodConcept.hpp> #include <com/sun/star/beans/MethodConcept.hpp>
#include <com/sun/star/beans/PropertyConcept.hpp> #include <com/sun/star/beans/PropertyConcept.hpp>
#include <com/sun/star/script/FailReason.hpp> #include <com/sun/star/script/FailReason.hpp>
#include <com/sun/star/reflection/theCoreReflection.hpp>
#include <com/sun/star/reflection/ParamInfo.hpp> #include <com/sun/star/reflection/ParamInfo.hpp>
#include <com/sun/star/beans/XExactName.hpp> #include <com/sun/star/beans/XExactName.hpp>
#include <com/sun/star/container/NoSuchElementException.hpp> #include <com/sun/star/container/NoSuchElementException.hpp>
...@@ -53,6 +54,7 @@ ...@@ -53,6 +54,7 @@
#include <com/sun/star/reflection/XIdlReflection.hpp> #include <com/sun/star/reflection/XIdlReflection.hpp>
#include <osl/interlck.h> #include <osl/interlck.h>
#include <com/sun/star/uno/genfunc.h> #include <com/sun/star/uno/genfunc.h>
#include <comphelper/componentcontext.hxx>
#include <cppuhelper/implbase1.hxx> #include <cppuhelper/implbase1.hxx>
#include "comifaces.hxx" #include "comifaces.hxx"
...@@ -1120,10 +1122,7 @@ HRESULT InterfaceOleWrapper_Impl::InvokeGeneral( DISPID dispidMember, unsigned s ...@@ -1120,10 +1122,7 @@ HRESULT InterfaceOleWrapper_Impl::InvokeGeneral( DISPID dispidMember, unsigned s
sal_Bool bStruct= sal_False; sal_Bool bStruct= sal_False;
Reference<XInterface> xIntCore= m_smgr->createInstance( OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.reflection.CoreReflection"))); Reference<XIdlReflection> xRefl = theCoreReflection::get(comphelper::ComponentContext(m_smgr).getUNOContext());
Reference<XIdlReflection> xRefl( xIntCore, UNO_QUERY);
if( xRefl.is() )
{
// the first parameter is in DISPPARAMS rgvargs contains the name of the struct. // the first parameter is in DISPPARAMS rgvargs contains the name of the struct.
CComVariant arg; CComVariant arg;
if( pdispparams->cArgs == 1 && SUCCEEDED( arg.ChangeType( VT_BSTR, &pdispparams->rgvarg[0])) ) if( pdispparams->cArgs == 1 && SUCCEEDED( arg.ChangeType( VT_BSTR, &pdispparams->rgvarg[0])) )
...@@ -1143,7 +1142,6 @@ HRESULT InterfaceOleWrapper_Impl::InvokeGeneral( DISPID dispidMember, unsigned s ...@@ -1143,7 +1142,6 @@ HRESULT InterfaceOleWrapper_Impl::InvokeGeneral( DISPID dispidMember, unsigned s
} }
} }
} }
}
ret= bStruct == sal_True ? S_OK : DISP_E_EXCEPTION; ret= bStruct == sal_True ? S_OK : DISP_E_EXCEPTION;
} }
else if (dispidMember == DISPID_CREATE_TYPE_FUNC) else if (dispidMember == DISPID_CREATE_TYPE_FUNC)
......
...@@ -33,12 +33,14 @@ ...@@ -33,12 +33,14 @@
#include <com/sun/star/registry/XRegistryKey.hpp> #include <com/sun/star/registry/XRegistryKey.hpp>
#include <osl/diagnose.h> #include <osl/diagnose.h>
#include <uno/environment.h> #include <uno/environment.h>
#include <comphelper/componentcontext.hxx>
#include <cppuhelper/factory.hxx> #include <cppuhelper/factory.hxx>
// OPTIONAL is a constant in com.sun.star.beans.PropertyAttributes but it must be // OPTIONAL is a constant in com.sun.star.beans.PropertyAttributes but it must be
// undef'd in some header files // undef'd in some header files
#define OPTIONAL OPTIONAL #define OPTIONAL OPTIONAL
#include <com/sun/star/beans/PropertyAttribute.hpp> #include <com/sun/star/beans/PropertyAttribute.hpp>
#include <com/sun/star/script/XInvocation.hpp> #include <com/sun/star/script/XInvocation.hpp>
#include <com/sun/star/reflection/theCoreReflection.hpp>
#include <com/sun/star/reflection/XIdlReflection.hpp> #include <com/sun/star/reflection/XIdlReflection.hpp>
#include <com/sun/star/lang/XEventListener.hpp> #include <com/sun/star/lang/XEventListener.hpp>
...@@ -1491,9 +1493,7 @@ void SAL_CALL OComponent::testInterface( const Reference< XCallback >& xCallbac ...@@ -1491,9 +1493,7 @@ void SAL_CALL OComponent::testInterface( const Reference< XCallback >& xCallbac
} }
case 101: case 101:
{ {
Reference<XIdlReflection> xRefl( m_rFactory->createInstance(L"com.sun.star.reflection.CoreReflection"), UNO_QUERY); Reference<XIdlReflection> xRefl( theCoreReflection::get(comphelper::ComponentContext(m_rFactory).getUNOContext()) );
if( xRefl.is())
{
Reference<XIdlClass> xClass= xRefl->forName(L"oletest.SimpleStruct"); Reference<XIdlClass> xClass= xRefl->forName(L"oletest.SimpleStruct");
Any any; Any any;
if( xClass.is()) if( xClass.is())
...@@ -1511,7 +1511,6 @@ void SAL_CALL OComponent::testInterface( const Reference< XCallback >& xCallbac ...@@ -1511,7 +1511,6 @@ void SAL_CALL OComponent::testInterface( const Reference< XCallback >& xCallbac
MessageBox( NULL, W2T(aStruct.message), _T("OleTest in out parameter"), MB_OK); MessageBox( NULL, W2T(aStruct.message), _T("OleTest in out parameter"), MB_OK);
} }
}
break; break;
} }
case 102: case 102:
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <com/sun/star/beans/XMaterialHolder.hpp> #include <com/sun/star/beans/XMaterialHolder.hpp>
#include <com/sun/star/script/Converter.hpp> #include <com/sun/star/script/Converter.hpp>
#include <com/sun/star/reflection/theCoreReflection.hpp>
using rtl::OUString; using rtl::OUString;
using rtl::OUStringToOString; using rtl::OUStringToOString;
...@@ -45,11 +46,13 @@ using com::sun::star::uno::TypeDescription; ...@@ -45,11 +46,13 @@ using com::sun::star::uno::TypeDescription;
using com::sun::star::uno::Sequence; using com::sun::star::uno::Sequence;
using com::sun::star::uno::Type; using com::sun::star::uno::Type;
using com::sun::star::uno::UNO_QUERY; 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::Exception;
using com::sun::star::uno::RuntimeException; using com::sun::star::uno::RuntimeException;
using com::sun::star::uno::XComponentContext; using com::sun::star::uno::XComponentContext;
using com::sun::star::lang::XSingleServiceFactory; using com::sun::star::lang::XSingleServiceFactory;
using com::sun::star::lang::XUnoTunnel; using com::sun::star::lang::XUnoTunnel;
using com::sun::star::reflection::theCoreReflection;
using com::sun::star::reflection::XIdlReflection; using com::sun::star::reflection::XIdlReflection;
using com::sun::star::script::Converter; using com::sun::star::script::Converter;
using com::sun::star::script::XTypeConverter; using com::sun::star::script::XTypeConverter;
...@@ -264,15 +267,7 @@ PyRef stRuntimeImpl::create( const Reference< XComponentContext > &ctx ) ...@@ -264,15 +267,7 @@ PyRef stRuntimeImpl::create( const Reference< XComponentContext > &ctx )
OUString( "pyuno: couldn't instantiate typeconverter service" ), OUString( "pyuno: couldn't instantiate typeconverter service" ),
Reference< XInterface > () ); Reference< XInterface > () );
c->xCoreReflection = Reference< XIdlReflection > ( c->xCoreReflection = theCoreReflection::get(ctx);
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->xAdapterFactory = Reference< XInvocationAdapterFactory2 > ( c->xAdapterFactory = Reference< XInvocationAdapterFactory2 > (
ctx->getServiceManager()->createInstanceWithContext( ctx->getServiceManager()->createInstanceWithContext(
......
...@@ -143,6 +143,9 @@ $(eval $(call gb_UnoApi_add_idlfiles_nohdl,udkapi,udkapi/com/sun/star/io,\ ...@@ -143,6 +143,9 @@ $(eval $(call gb_UnoApi_add_idlfiles_nohdl,udkapi,udkapi/com/sun/star/io,\
SequenceOutputStream \ SequenceOutputStream \
TempFile \ 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,\ $(eval $(call gb_UnoApi_add_idlfiles_nohdl,udkapi,udkapi/com/sun/star/registry,\
ImplementationRegistration \ ImplementationRegistration \
SimpleRegistry \ SimpleRegistry \
......
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
/** This service is the implementation of the reflection API. /** This service is the implementation of the reflection API.
You can obtain information about types, modify values of reflected types You can obtain information about types, modify values of reflected types
and call on objects. and call on objects.
@deprecated Rather use the 'theCoreReflection' singleton.
*/ */
published service CoreReflection published service CoreReflection
{ {
...@@ -42,14 +44,6 @@ published service CoreReflection ...@@ -42,14 +44,6 @@ published service CoreReflection
[optional] interface com::sun::star::lang::XComponent; [optional] interface com::sun::star::lang::XComponent;
}; };
/** Accessable singleton to CoreReflection instance.
singleton theCoreReflection
{
service CoreReflection;
};
*/
}; }; }; }; }; }; }; };
#endif #endif
......
/* -*- 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 <com/sun/star/reflection/XIdlReflection.idl>
module com { module sun { module star { module reflection {
singleton theCoreReflection : com::sun::star::reflection::XIdlReflection;
}; }; }; };
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment