From 9cf2d46b29f278e42c38b56bd3b6ac5b4adf9b42 Mon Sep 17 00:00:00 2001 From: Kohei Yoshida Date: Thu, 11 Aug 2011 11:41:11 -0400 Subject: Extracted a method that will be called from another method. --- eventattacher/source/eventattacher.cxx | 43 ++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/eventattacher/source/eventattacher.cxx b/eventattacher/source/eventattacher.cxx index 79879684fc56..7c2bdf51cca5 100644 --- a/eventattacher/source/eventattacher.cxx +++ b/eventattacher/source/eventattacher.cxx @@ -257,6 +257,15 @@ public: friend class FilterAllListenerImpl; private: + Reference attachListenerForTarget( + const Reference& xAccess, + const Reference& xInvocationAdapterFactory, + const Reference& xAllListener, + const Any& aObject, + const Any& aHelper, + const OUString& aListenerType, + const OUString& aAddListenerParam ); + Sequence< Reference > attachListeners( const Reference& xObject, const Sequence< Reference >& AllListeners, @@ -584,8 +593,6 @@ Reference< XEventListener > EventAttacherImpl::attachListener if( !xObject.is() || !AllListener.is() ) throw IllegalArgumentException(); - Reference< XEventListener > xRet = NULL; - Reference< XInvocationAdapterFactory > xInvocationAdapterFactory = getInvocationAdapterService(); if( !xInvocationAdapterFactory.is() ) throw ServiceNotRegisteredException(); @@ -600,18 +607,34 @@ Reference< XEventListener > EventAttacherImpl::attachListener // of the Introspection configurable for this purpose. Reference< XIntrospection > xIntrospection = getIntrospection(); if( !xIntrospection.is() ) - return xRet; + return Reference(); // Inspect Introspection Any aObjAny( &xObject, ::getCppuType( (const Reference< XInterface > *)0) ); Reference< XIntrospectionAccess > xAccess = xIntrospection->inspect( aObjAny ); if( !xAccess.is() ) - return xRet; + return Reference(); + + return attachListenerForTarget( + xAccess, xInvocationAdapterFactory, AllListener, aObjAny, Helper, + ListenerType, AddListenerParam); +} + +Reference EventAttacherImpl::attachListenerForTarget( + const Reference& xAccess, + const Reference& xInvocationAdapterFactory, + const Reference& xAllListener, + const Any& aObject, + const Any& aHelper, + const OUString& aListenerType, + const OUString& aAddListenerParam) +{ + Reference< XEventListener > xRet = NULL; // Construct the name of the addListener-Method. OUString aAddListenerName; - OUString aListenerName( ListenerType ); + OUString aListenerName( aListenerType ); sal_Int32 nIndex = aListenerName.lastIndexOf( '.' ); // set index to the interface name without package name if( nIndex == -1 ) @@ -648,8 +671,8 @@ Reference< XEventListener > EventAttacherImpl::attachListener xListenerType = params.getConstArray()[1]; // Request Adapter for the actual Listener type - Reference< XInterface > xAdapter = createAllListenerAdapter - ( xInvocationAdapterFactory, xListenerType, AllListener, Helper ); + Reference< XInterface > xAdapter = createAllListenerAdapter( + xInvocationAdapterFactory, xListenerType, xAllListener, aHelper ); if( !xAdapter.is() ) throw CannotCreateAdapterException(); @@ -663,7 +686,7 @@ Reference< XEventListener > EventAttacherImpl::attachListener args.getArray()[0] <<= xAdapter; try { - rxMethod->invoke( aObjAny, args ); + rxMethod->invoke( aObject, args ); } catch( InvocationTargetException& ) { @@ -680,7 +703,7 @@ Reference< XEventListener > EventAttacherImpl::attachListener Reference< XIdlClass > xParamClass = params.getConstArray()[0]; if( xParamClass->getTypeClass() == TypeClass_STRING ) { - pAnys[0] <<= AddListenerParam; + pAnys[0] <<= aAddListenerParam; } // 2nd Parameter == Listener? TODO: Test! @@ -690,7 +713,7 @@ Reference< XEventListener > EventAttacherImpl::attachListener // else try { - rxMethod->invoke( aObjAny, args ); + rxMethod->invoke( aObject, args ); } catch( InvocationTargetException& ) { -- cgit