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 @@
#endif
#include <osl/mutex.hxx>
#include <osl/diagnose.h>
#include <comphelper/componentcontext.hxx>
#include <comphelper/eventattachermgr.hxx>
#include <com/sun/star/beans/XIntrospection.hpp>
#include <com/sun/star/io/XObjectInputStream.hpp>
......@@ -31,6 +32,7 @@
#include <com/sun/star/io/XMarkableStream.hpp>
#include <com/sun/star/lang/XInitialization.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/XIdlReflection.hpp>
#include <com/sun/star/reflection/XIdlMethod.hpp>
......@@ -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;
}
......
......@@ -28,6 +28,7 @@
#include <com/sun/star/script/Converter.hpp>
#include <com/sun/star/script/XAllListener.hpp>
#include <com/sun/star/script/XInvocationAdapterFactory.hpp>
#include <com/sun/star/reflection/theCoreReflection.hpp>
#include <com/sun/star/reflection/XIdlReflection.hpp>
// 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;
}
......
......@@ -43,6 +43,7 @@
#include <com/sun/star/beans/MethodConcept.hpp>
#include <com/sun/star/beans/PropertyConcept.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/beans/XExactName.hpp>
#include <com/sun/star/container/NoSuchElementException.hpp>
......@@ -53,6 +54,7 @@
#include <com/sun/star/reflection/XIdlReflection.hpp>
#include <osl/interlck.h>
#include <com/sun/star/uno/genfunc.h>
#include <comphelper/componentcontext.hxx>
#include <cppuhelper/implbase1.hxx>
#include "comifaces.hxx"
......@@ -1120,27 +1122,23 @@ HRESULT InterfaceOleWrapper_Impl::InvokeGeneral( DISPID dispidMember, unsigned s
sal_Bool bStruct= sal_False;
Reference<XInterface> xIntCore= m_smgr->createInstance( OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.reflection.CoreReflection")));
Reference<XIdlReflection> xRefl( xIntCore, UNO_QUERY);
if( xRefl.is() )
Reference<XIdlReflection> 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<XIdlClass> classStruct= xRefl->forName( reinterpret_cast<const sal_Unicode*>(arg.bstrVal));
if( classStruct.is())
{
Reference<XIdlClass> classStruct= xRefl->forName( reinterpret_cast<const sal_Unicode*>(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;
}
}
}
......
......@@ -33,12 +33,14 @@
#include <com/sun/star/registry/XRegistryKey.hpp>
#include <osl/diagnose.h>
#include <uno/environment.h>
#include <comphelper/componentcontext.hxx>
#include <cppuhelper/factory.hxx>
// OPTIONAL is a constant in com.sun.star.beans.PropertyAttributes but it must be
// undef'd in some header files
#define OPTIONAL OPTIONAL
#include <com/sun/star/beans/PropertyAttribute.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/lang/XEventListener.hpp>
......@@ -1491,27 +1493,24 @@ void SAL_CALL OComponent::testInterface( const Reference< XCallback >& xCallbac
}
case 101:
{
Reference<XIdlReflection> xRefl( m_rFactory->createInstance(L"com.sun.star.reflection.CoreReflection"), UNO_QUERY);
if( xRefl.is())
{
Reference<XIdlClass> 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<XIdlReflection> xRefl( theCoreReflection::get(comphelper::ComponentContext(m_rFactory).getUNOContext()) );
Reference<XIdlClass> 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:
......
......@@ -31,6 +31,7 @@
#include <com/sun/star/beans/XMaterialHolder.hpp>
#include <com/sun/star/script/Converter.hpp>
#include <com/sun/star/reflection/theCoreReflection.hpp>
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(
......
......@@ -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 \
......
......@@ -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
......
/* -*- 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