summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2012-09-04 16:12:17 +0200
committerStephan Bergmann <sbergman@redhat.com>2012-09-05 15:46:55 +0200
commitb679a2a02180c017bd8b596fb2e4f283bad93b75 (patch)
treedecf939bbd22a2507e8cd9e6c2e41ded49352aa3
parent3bb22684c3e0e865f1635ba52ea84630ff766b8c (diff)
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
-rw-r--r--comphelper/source/eventattachermgr/eventattachermgr.cxx22
-rw-r--r--eventattacher/source/eventattacher.cxx4
-rw-r--r--extensions/source/ole/unoobjw.cxx34
-rw-r--r--extensions/test/ole/cpnt/cpnt.cxx35
-rw-r--r--pyuno/source/module/pyuno_runtime.cxx13
-rw-r--r--udkapi/UnoApi_udkapi.mk3
-rw-r--r--udkapi/com/sun/star/reflection/CoreReflection.idl10
-rw-r--r--udkapi/com/sun/star/reflection/theCoreReflection.idl35
8 files changed, 91 insertions, 65 deletions
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 <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;
}
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 <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;
}
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 <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;
}
}
}
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 <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:
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 <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(
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 <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: */