1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir #include <osl/diagnose.h> 28*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 29*cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp> 30*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 31*cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp> 32*cdf0e10cSrcweir #include <com/sun/star/registry/XRegistryKey.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/beans/XIntrospection.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/beans/MethodConcept.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/script/XEventAttacher.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/script/XTypeConverter.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/script/XAllListener.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/script/XInvocationAdapterFactory.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/reflection/XIdlReflection.hpp> 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir // InvocationToAllListenerMapper 42*cdf0e10cSrcweir #include <com/sun/star/script/XInvocation.hpp> 43*cdf0e10cSrcweir #include <cppuhelper/weak.hxx> 44*cdf0e10cSrcweir #include <cppuhelper/factory.hxx> 45*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 46*cdf0e10cSrcweir #include <cppuhelper/implbase3.hxx> 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir using namespace com::sun::star::uno; 49*cdf0e10cSrcweir using namespace com::sun::star::registry; 50*cdf0e10cSrcweir using namespace com::sun::star::lang; 51*cdf0e10cSrcweir using namespace com::sun::star::beans; 52*cdf0e10cSrcweir using namespace com::sun::star::script; 53*cdf0e10cSrcweir using namespace com::sun::star::reflection; 54*cdf0e10cSrcweir using namespace cppu; 55*cdf0e10cSrcweir using namespace osl; 56*cdf0e10cSrcweir using namespace rtl; 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir #define SERVICENAME "com.sun.star.script.EventAttacher" 60*cdf0e10cSrcweir #define IMPLNAME "com.sun.star.comp.EventAttacher" 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir namespace comp_EventAttacher { 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir //************************************************************************* 65*cdf0e10cSrcweir // class InvocationToAllListenerMapper 66*cdf0e10cSrcweir // helper class to map XInvocation to XAllListener 67*cdf0e10cSrcweir //************************************************************************* 68*cdf0e10cSrcweir class InvocationToAllListenerMapper : public WeakImplHelper1< XInvocation > 69*cdf0e10cSrcweir { 70*cdf0e10cSrcweir public: 71*cdf0e10cSrcweir InvocationToAllListenerMapper( const Reference< XIdlClass >& ListenerType, 72*cdf0e10cSrcweir const Reference< XAllListener >& AllListener, const Any& Helper ); 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir // XInvocation 75*cdf0e10cSrcweir virtual Reference< XIntrospectionAccess > SAL_CALL getIntrospection(void) throw( RuntimeException ); 76*cdf0e10cSrcweir virtual Any SAL_CALL invoke(const OUString& FunctionName, const Sequence< Any >& Params, Sequence< sal_Int16 >& OutParamIndex, Sequence< Any >& OutParam) 77*cdf0e10cSrcweir throw( IllegalArgumentException, CannotConvertException, InvocationTargetException, RuntimeException ); 78*cdf0e10cSrcweir virtual void SAL_CALL setValue(const OUString& PropertyName, const Any& Value) 79*cdf0e10cSrcweir throw( UnknownPropertyException, CannotConvertException, InvocationTargetException, RuntimeException ); 80*cdf0e10cSrcweir virtual Any SAL_CALL getValue(const OUString& PropertyName) throw( UnknownPropertyException, RuntimeException ); 81*cdf0e10cSrcweir virtual sal_Bool SAL_CALL hasMethod(const OUString& Name) throw( RuntimeException ); 82*cdf0e10cSrcweir virtual sal_Bool SAL_CALL hasProperty(const OUString& Name) throw( RuntimeException ); 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir private: 85*cdf0e10cSrcweir Reference< XIdlReflection > m_xCoreReflection; 86*cdf0e10cSrcweir Reference< XAllListener > m_xAllListener; 87*cdf0e10cSrcweir Reference< XIdlClass > m_xListenerType; 88*cdf0e10cSrcweir Any m_Helper; 89*cdf0e10cSrcweir }; 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir // Function to replace AllListenerAdapterService::createAllListerAdapter 93*cdf0e10cSrcweir Reference< XInterface > createAllListenerAdapter 94*cdf0e10cSrcweir ( 95*cdf0e10cSrcweir const Reference< XInvocationAdapterFactory >& xInvocationAdapterFactory, 96*cdf0e10cSrcweir const Reference< XIdlClass >& xListenerType, 97*cdf0e10cSrcweir const Reference< XAllListener >& xListener, 98*cdf0e10cSrcweir const Any& Helper 99*cdf0e10cSrcweir ) 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir Reference< XInterface > xAdapter; 102*cdf0e10cSrcweir if( xInvocationAdapterFactory.is() && xListenerType.is() && xListener.is() ) 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir Reference< XInvocation > xInvocationToAllListenerMapper = 105*cdf0e10cSrcweir (XInvocation*)new InvocationToAllListenerMapper( xListenerType, xListener, Helper ); 106*cdf0e10cSrcweir Type aListenerType( xListenerType->getTypeClass(), xListenerType->getName()); 107*cdf0e10cSrcweir xAdapter = xInvocationAdapterFactory->createAdapter( xInvocationToAllListenerMapper, aListenerType ); 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir return xAdapter; 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir //-------------------------------------------------------------------------------------------------- 114*cdf0e10cSrcweir // InvocationToAllListenerMapper 115*cdf0e10cSrcweir InvocationToAllListenerMapper::InvocationToAllListenerMapper 116*cdf0e10cSrcweir ( const Reference< XIdlClass >& ListenerType, const Reference< XAllListener >& AllListener, const Any& Helper ) 117*cdf0e10cSrcweir : m_xAllListener( AllListener ) 118*cdf0e10cSrcweir , m_xListenerType( ListenerType ) 119*cdf0e10cSrcweir , m_Helper( Helper ) 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir } 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir //************************************************************************* 124*cdf0e10cSrcweir Reference< XIntrospectionAccess > SAL_CALL InvocationToAllListenerMapper::getIntrospection(void) 125*cdf0e10cSrcweir throw( RuntimeException ) 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir return Reference< XIntrospectionAccess >(); 128*cdf0e10cSrcweir } 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir //************************************************************************* 131*cdf0e10cSrcweir Any SAL_CALL InvocationToAllListenerMapper::invoke(const OUString& FunctionName, const Sequence< Any >& Params, 132*cdf0e10cSrcweir Sequence< sal_Int16 >& , Sequence< Any >& ) 133*cdf0e10cSrcweir throw( IllegalArgumentException, CannotConvertException, 134*cdf0e10cSrcweir InvocationTargetException, RuntimeException ) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir Any aRet; 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir // Check if to firing or approveFiring has to be called 139*cdf0e10cSrcweir Reference< XIdlMethod > xMethod = m_xListenerType->getMethod( FunctionName ); 140*cdf0e10cSrcweir sal_Bool bApproveFiring = sal_False; 141*cdf0e10cSrcweir if( !xMethod.is() ) 142*cdf0e10cSrcweir return aRet; 143*cdf0e10cSrcweir Reference< XIdlClass > xReturnType = xMethod->getReturnType(); 144*cdf0e10cSrcweir Sequence< Reference< XIdlClass > > aExceptionSeq = xMethod->getExceptionTypes(); 145*cdf0e10cSrcweir if( ( xReturnType.is() && xReturnType->getTypeClass() != TypeClass_VOID ) || 146*cdf0e10cSrcweir aExceptionSeq.getLength() > 0 ) 147*cdf0e10cSrcweir { 148*cdf0e10cSrcweir bApproveFiring = sal_True; 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir else 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir Sequence< ParamInfo > aParamSeq = xMethod->getParameterInfos(); 153*cdf0e10cSrcweir sal_uInt32 nParamCount = aParamSeq.getLength(); 154*cdf0e10cSrcweir if( nParamCount > 1 ) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir const ParamInfo* pInfos = aParamSeq.getConstArray(); 157*cdf0e10cSrcweir for( sal_uInt32 i = 0 ; i < nParamCount ; i++ ) 158*cdf0e10cSrcweir { 159*cdf0e10cSrcweir if( pInfos[ i ].aMode != ParamMode_IN ) 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir bApproveFiring = sal_True; 162*cdf0e10cSrcweir break; 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir AllEventObject aAllEvent; 169*cdf0e10cSrcweir aAllEvent.Source = (OWeakObject*) this; 170*cdf0e10cSrcweir aAllEvent.Helper = m_Helper; 171*cdf0e10cSrcweir aAllEvent.ListenerType = Type(m_xListenerType->getTypeClass(), m_xListenerType->getName()); 172*cdf0e10cSrcweir aAllEvent.MethodName = FunctionName; 173*cdf0e10cSrcweir aAllEvent.Arguments = Params; 174*cdf0e10cSrcweir if( bApproveFiring ) 175*cdf0e10cSrcweir aRet = m_xAllListener->approveFiring( aAllEvent ); 176*cdf0e10cSrcweir else 177*cdf0e10cSrcweir m_xAllListener->firing( aAllEvent ); 178*cdf0e10cSrcweir return aRet; 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir //************************************************************************* 182*cdf0e10cSrcweir void SAL_CALL InvocationToAllListenerMapper::setValue(const OUString& , const Any& ) 183*cdf0e10cSrcweir throw( UnknownPropertyException, CannotConvertException, 184*cdf0e10cSrcweir InvocationTargetException, RuntimeException ) 185*cdf0e10cSrcweir { 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir //************************************************************************* 189*cdf0e10cSrcweir Any SAL_CALL InvocationToAllListenerMapper::getValue(const OUString& ) 190*cdf0e10cSrcweir throw( UnknownPropertyException, RuntimeException ) 191*cdf0e10cSrcweir { 192*cdf0e10cSrcweir return Any(); 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir //************************************************************************* 196*cdf0e10cSrcweir sal_Bool SAL_CALL InvocationToAllListenerMapper::hasMethod(const OUString& Name) 197*cdf0e10cSrcweir throw( RuntimeException ) 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir Reference< XIdlMethod > xMethod = m_xListenerType->getMethod( Name ); 200*cdf0e10cSrcweir return xMethod.is(); 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir //************************************************************************* 204*cdf0e10cSrcweir sal_Bool SAL_CALL InvocationToAllListenerMapper::hasProperty(const OUString& Name) 205*cdf0e10cSrcweir throw( RuntimeException ) 206*cdf0e10cSrcweir { 207*cdf0e10cSrcweir Reference< XIdlField > xField = m_xListenerType->getField( Name ); 208*cdf0e10cSrcweir return xField.is(); 209*cdf0e10cSrcweir } 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir //************************************************************************* 212*cdf0e10cSrcweir // class EventAttacherImpl 213*cdf0e10cSrcweir // represents an implementation of the EventAttacher service 214*cdf0e10cSrcweir //************************************************************************* 215*cdf0e10cSrcweir class EventAttacherImpl : public WeakImplHelper3 < XEventAttacher, XInitialization, XServiceInfo > 216*cdf0e10cSrcweir { 217*cdf0e10cSrcweir public: 218*cdf0e10cSrcweir EventAttacherImpl( const Reference< XMultiServiceFactory >& ); 219*cdf0e10cSrcweir ~EventAttacherImpl(); 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir // XServiceInfo 222*cdf0e10cSrcweir virtual OUString SAL_CALL getImplementationName( ) throw(RuntimeException); 223*cdf0e10cSrcweir virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(RuntimeException); 224*cdf0e10cSrcweir virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw(RuntimeException); 225*cdf0e10cSrcweir static OUString SAL_CALL getImplementationName_Static( ); 226*cdf0e10cSrcweir static Sequence< OUString > SAL_CALL getSupportedServiceNames_Static( ); 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir // XInitialization 229*cdf0e10cSrcweir virtual void SAL_CALL initialize( const Sequence< Any >& aArguments ) 230*cdf0e10cSrcweir throw( Exception, RuntimeException); 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir // Methoden von XEventAttacher 233*cdf0e10cSrcweir virtual Reference< XEventListener > SAL_CALL attachListener(const Reference< XInterface >& xObject, 234*cdf0e10cSrcweir const Reference< XAllListener >& AllListener, const Any& Helper, 235*cdf0e10cSrcweir const OUString& ListenerType, const OUString& AddListenerParam) 236*cdf0e10cSrcweir throw( IllegalArgumentException, ServiceNotRegisteredException, CannotCreateAdapterException, IntrospectionException, RuntimeException ); 237*cdf0e10cSrcweir virtual Reference< XEventListener > SAL_CALL attachSingleEventListener(const Reference< XInterface >& xObject, 238*cdf0e10cSrcweir const Reference< XAllListener >& AllListener, const Any& Helper, 239*cdf0e10cSrcweir const OUString& ListenerType, const OUString& AddListenerParam, 240*cdf0e10cSrcweir const OUString& EventMethod) 241*cdf0e10cSrcweir throw( IllegalArgumentException, ServiceNotRegisteredException, CannotCreateAdapterException, IntrospectionException, RuntimeException ); 242*cdf0e10cSrcweir virtual void SAL_CALL removeListener(const Reference< XInterface >& xObject, 243*cdf0e10cSrcweir const OUString& ListenerType, const OUString& AddListenerParam, 244*cdf0e10cSrcweir const Reference< XEventListener >& aToRemoveListener) 245*cdf0e10cSrcweir throw( IllegalArgumentException, IntrospectionException, RuntimeException ); 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir // used by FilterAllListener_Impl 248*cdf0e10cSrcweir Reference< XTypeConverter > getConverter() throw( Exception ); 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir friend class FilterAllListenerImpl; 251*cdf0e10cSrcweir private: 252*cdf0e10cSrcweir Mutex m_aMutex; 253*cdf0e10cSrcweir Reference< XMultiServiceFactory > m_xSMgr; 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir // Services merken 256*cdf0e10cSrcweir Reference< XIntrospection > m_xIntrospection; 257*cdf0e10cSrcweir Reference< XIdlReflection > m_xReflection; 258*cdf0e10cSrcweir Reference< XTypeConverter > m_xConverter; 259*cdf0e10cSrcweir Reference< XInvocationAdapterFactory > m_xInvocationAdapterFactory; 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir // needed services 262*cdf0e10cSrcweir Reference< XIntrospection > getIntrospection() throw( Exception ); 263*cdf0e10cSrcweir Reference< XIdlReflection > getReflection() throw( Exception ); 264*cdf0e10cSrcweir Reference< XInvocationAdapterFactory > getInvocationAdapterService() throw( Exception ); 265*cdf0e10cSrcweir }; 266*cdf0e10cSrcweir 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir //************************************************************************* 269*cdf0e10cSrcweir EventAttacherImpl::EventAttacherImpl( const Reference< XMultiServiceFactory >& rSMgr ) 270*cdf0e10cSrcweir : m_xSMgr( rSMgr ) 271*cdf0e10cSrcweir { 272*cdf0e10cSrcweir } 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir //************************************************************************* 275*cdf0e10cSrcweir EventAttacherImpl::~EventAttacherImpl() 276*cdf0e10cSrcweir { 277*cdf0e10cSrcweir } 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir //************************************************************************* 280*cdf0e10cSrcweir Reference< XInterface > SAL_CALL EventAttacherImpl_CreateInstance( const Reference< XMultiServiceFactory >& rSMgr ) throw( Exception ) 281*cdf0e10cSrcweir { 282*cdf0e10cSrcweir Reference< XInterface > xRet; 283*cdf0e10cSrcweir XEventAttacher *pEventAttacher = (XEventAttacher*) new EventAttacherImpl(rSMgr); 284*cdf0e10cSrcweir 285*cdf0e10cSrcweir if (pEventAttacher) 286*cdf0e10cSrcweir { 287*cdf0e10cSrcweir xRet = Reference<XInterface>::query(pEventAttacher); 288*cdf0e10cSrcweir } 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir return xRet; 291*cdf0e10cSrcweir } 292*cdf0e10cSrcweir 293*cdf0e10cSrcweir //************************************************************************* 294*cdf0e10cSrcweir OUString SAL_CALL EventAttacherImpl::getImplementationName( ) 295*cdf0e10cSrcweir throw(RuntimeException) 296*cdf0e10cSrcweir { 297*cdf0e10cSrcweir return OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLNAME ) ); 298*cdf0e10cSrcweir } 299*cdf0e10cSrcweir 300*cdf0e10cSrcweir //************************************************************************* 301*cdf0e10cSrcweir sal_Bool SAL_CALL EventAttacherImpl::supportsService( const OUString& ServiceName ) 302*cdf0e10cSrcweir throw(RuntimeException) 303*cdf0e10cSrcweir { 304*cdf0e10cSrcweir Sequence< OUString > aSNL = getSupportedServiceNames(); 305*cdf0e10cSrcweir const OUString * pArray = aSNL.getArray(); 306*cdf0e10cSrcweir for( sal_Int32 i = 0; i < aSNL.getLength(); i++ ) 307*cdf0e10cSrcweir if( pArray[i] == ServiceName ) 308*cdf0e10cSrcweir return sal_True; 309*cdf0e10cSrcweir return sal_False; 310*cdf0e10cSrcweir } 311*cdf0e10cSrcweir 312*cdf0e10cSrcweir //************************************************************************* 313*cdf0e10cSrcweir Sequence<OUString> SAL_CALL EventAttacherImpl::getSupportedServiceNames( ) 314*cdf0e10cSrcweir throw(RuntimeException) 315*cdf0e10cSrcweir { 316*cdf0e10cSrcweir return getSupportedServiceNames_Static(); 317*cdf0e10cSrcweir } 318*cdf0e10cSrcweir 319*cdf0e10cSrcweir //************************************************************************* 320*cdf0e10cSrcweir Sequence<OUString> SAL_CALL EventAttacherImpl::getSupportedServiceNames_Static( ) 321*cdf0e10cSrcweir { 322*cdf0e10cSrcweir OUString aStr( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME ) ); 323*cdf0e10cSrcweir return Sequence< OUString >( &aStr, 1 ); 324*cdf0e10cSrcweir } 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir //************************************************************************* 327*cdf0e10cSrcweir void SAL_CALL EventAttacherImpl::initialize(const Sequence< Any >& Arguments) throw( Exception, RuntimeException ) 328*cdf0e10cSrcweir { 329*cdf0e10cSrcweir // get services from the argument list 330*cdf0e10cSrcweir const Any * pArray = Arguments.getConstArray(); 331*cdf0e10cSrcweir for( sal_Int32 i = 0; i < Arguments.getLength(); i++ ) 332*cdf0e10cSrcweir { 333*cdf0e10cSrcweir if( pArray[i].getValueType().getTypeClass() != TypeClass_INTERFACE ) 334*cdf0e10cSrcweir throw IllegalArgumentException(); 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir // InvocationAdapter service ? 337*cdf0e10cSrcweir Reference< XInvocationAdapterFactory > xALAS; 338*cdf0e10cSrcweir pArray[i] >>= xALAS; 339*cdf0e10cSrcweir if( xALAS.is() ) 340*cdf0e10cSrcweir { 341*cdf0e10cSrcweir Guard< Mutex > aGuard( m_aMutex ); 342*cdf0e10cSrcweir m_xInvocationAdapterFactory = xALAS; 343*cdf0e10cSrcweir } 344*cdf0e10cSrcweir // Introspection service ? 345*cdf0e10cSrcweir Reference< XIntrospection > xI; 346*cdf0e10cSrcweir pArray[i] >>= xI; 347*cdf0e10cSrcweir if( xI.is() ) 348*cdf0e10cSrcweir { 349*cdf0e10cSrcweir Guard< Mutex > aGuard( m_aMutex ); 350*cdf0e10cSrcweir m_xIntrospection = xI; 351*cdf0e10cSrcweir } 352*cdf0e10cSrcweir // Reflection service ? 353*cdf0e10cSrcweir Reference< XIdlReflection > xIdlR; 354*cdf0e10cSrcweir pArray[i] >>= xIdlR; 355*cdf0e10cSrcweir if( xIdlR.is() ) 356*cdf0e10cSrcweir { 357*cdf0e10cSrcweir Guard< Mutex > aGuard( m_aMutex ); 358*cdf0e10cSrcweir m_xReflection = xIdlR; 359*cdf0e10cSrcweir } 360*cdf0e10cSrcweir // Converter Service ? 361*cdf0e10cSrcweir Reference< XTypeConverter > xC; 362*cdf0e10cSrcweir pArray[i] >>= xC; 363*cdf0e10cSrcweir if( xC.is() ) 364*cdf0e10cSrcweir { 365*cdf0e10cSrcweir Guard< Mutex > aGuard( m_aMutex ); 366*cdf0e10cSrcweir m_xConverter = xC; 367*cdf0e10cSrcweir } 368*cdf0e10cSrcweir 369*cdf0e10cSrcweir // no right interface 370*cdf0e10cSrcweir if( !xALAS.is() && !xI.is() && !xIdlR.is() && !xC.is() ) 371*cdf0e10cSrcweir throw IllegalArgumentException(); 372*cdf0e10cSrcweir } 373*cdf0e10cSrcweir } 374*cdf0e10cSrcweir 375*cdf0e10cSrcweir //************************************************************************* 376*cdf0e10cSrcweir //*** Private Hilfs-Methoden *** 377*cdf0e10cSrcweir Reference< XIntrospection > EventAttacherImpl::getIntrospection() throw( Exception ) 378*cdf0e10cSrcweir { 379*cdf0e10cSrcweir Guard< Mutex > aGuard( m_aMutex ); 380*cdf0e10cSrcweir // Haben wir den Service schon? Sonst anlegen 381*cdf0e10cSrcweir if( !m_xIntrospection.is() ) 382*cdf0e10cSrcweir { 383*cdf0e10cSrcweir Reference< XInterface > xIFace( m_xSMgr->createInstance( rtl::OUString::createFromAscii("com.sun.star.beans.Introspection") ) ); 384*cdf0e10cSrcweir m_xIntrospection = Reference< XIntrospection >( xIFace, UNO_QUERY ); 385*cdf0e10cSrcweir } 386*cdf0e10cSrcweir return m_xIntrospection; 387*cdf0e10cSrcweir } 388*cdf0e10cSrcweir 389*cdf0e10cSrcweir //************************************************************************* 390*cdf0e10cSrcweir //*** Private Hilfs-Methoden *** 391*cdf0e10cSrcweir Reference< XIdlReflection > EventAttacherImpl::getReflection() throw( Exception ) 392*cdf0e10cSrcweir { 393*cdf0e10cSrcweir Guard< Mutex > aGuard( m_aMutex ); 394*cdf0e10cSrcweir // Haben wir den Service schon? Sonst anlegen 395*cdf0e10cSrcweir if( !m_xReflection.is() ) 396*cdf0e10cSrcweir { 397*cdf0e10cSrcweir Reference< XInterface > xIFace( m_xSMgr->createInstance( rtl::OUString::createFromAscii("com.sun.star.reflection.CoreReflection") ) ); 398*cdf0e10cSrcweir m_xReflection = Reference< XIdlReflection >( xIFace, UNO_QUERY); 399*cdf0e10cSrcweir } 400*cdf0e10cSrcweir return m_xReflection; 401*cdf0e10cSrcweir } 402*cdf0e10cSrcweir 403*cdf0e10cSrcweir //************************************************************************* 404*cdf0e10cSrcweir //*** Private Hilfs-Methoden *** 405*cdf0e10cSrcweir Reference< XInvocationAdapterFactory > EventAttacherImpl::getInvocationAdapterService() throw( Exception ) 406*cdf0e10cSrcweir { 407*cdf0e10cSrcweir Guard< Mutex > aGuard( m_aMutex ); 408*cdf0e10cSrcweir // Haben wir den Service schon? Sonst anlegen 409*cdf0e10cSrcweir if( !m_xInvocationAdapterFactory.is() ) 410*cdf0e10cSrcweir { 411*cdf0e10cSrcweir Reference< XInterface > xIFace( m_xSMgr->createInstance( rtl::OUString::createFromAscii("com.sun.star.script.InvocationAdapterFactory") ) ); 412*cdf0e10cSrcweir m_xInvocationAdapterFactory = Reference< XInvocationAdapterFactory >( xIFace, UNO_QUERY ); 413*cdf0e10cSrcweir } 414*cdf0e10cSrcweir return m_xInvocationAdapterFactory; 415*cdf0e10cSrcweir } 416*cdf0e10cSrcweir 417*cdf0e10cSrcweir 418*cdf0e10cSrcweir //************************************************************************* 419*cdf0e10cSrcweir //*** Private Hilfs-Methoden *** 420*cdf0e10cSrcweir Reference< XTypeConverter > EventAttacherImpl::getConverter() throw( Exception ) 421*cdf0e10cSrcweir { 422*cdf0e10cSrcweir Guard< Mutex > aGuard( m_aMutex ); 423*cdf0e10cSrcweir // Haben wir den Service schon? Sonst anlegen 424*cdf0e10cSrcweir if( !m_xConverter.is() ) 425*cdf0e10cSrcweir { 426*cdf0e10cSrcweir Reference< XInterface > xIFace( m_xSMgr->createInstance( rtl::OUString::createFromAscii("com.sun.star.script.Converter") ) ); 427*cdf0e10cSrcweir m_xConverter = Reference< XTypeConverter >( xIFace, UNO_QUERY ); 428*cdf0e10cSrcweir } 429*cdf0e10cSrcweir return m_xConverter; 430*cdf0e10cSrcweir } 431*cdf0e10cSrcweir 432*cdf0e10cSrcweir //------------------------------------------------------------------------ 433*cdf0e10cSrcweir //------------------------------------------------------------------------ 434*cdf0e10cSrcweir //------------------------------------------------------------------------ 435*cdf0e10cSrcweir // Implementation eines EventAttacher-bezogenen AllListeners, der 436*cdf0e10cSrcweir // nur einzelne Events an einen allgemeinen AllListener weiterleitet 437*cdf0e10cSrcweir class FilterAllListenerImpl : public WeakImplHelper1< XAllListener > 438*cdf0e10cSrcweir { 439*cdf0e10cSrcweir public: 440*cdf0e10cSrcweir FilterAllListenerImpl( EventAttacherImpl * pEA_, const OUString& EventMethod_, 441*cdf0e10cSrcweir const Reference< XAllListener >& AllListener_ ); 442*cdf0e10cSrcweir 443*cdf0e10cSrcweir // XAllListener 444*cdf0e10cSrcweir virtual void SAL_CALL firing(const AllEventObject& Event) throw( RuntimeException ); 445*cdf0e10cSrcweir virtual Any SAL_CALL approveFiring(const AllEventObject& Event) throw( InvocationTargetException, RuntimeException ); 446*cdf0e10cSrcweir 447*cdf0e10cSrcweir // XEventListener 448*cdf0e10cSrcweir virtual void SAL_CALL disposing(const EventObject& Source) throw( RuntimeException ); 449*cdf0e10cSrcweir 450*cdf0e10cSrcweir private: 451*cdf0e10cSrcweir // convert 452*cdf0e10cSrcweir void convertToEventReturn( Any & rRet, const Type& rRetType ) 453*cdf0e10cSrcweir throw( CannotConvertException ); 454*cdf0e10cSrcweir 455*cdf0e10cSrcweir EventAttacherImpl * m_pEA; 456*cdf0e10cSrcweir Reference< XInterface > m_xEAHold; 457*cdf0e10cSrcweir OUString m_EventMethod; 458*cdf0e10cSrcweir Reference< XAllListener > m_AllListener; 459*cdf0e10cSrcweir }; 460*cdf0e10cSrcweir 461*cdf0e10cSrcweir //************************************************************************* 462*cdf0e10cSrcweir FilterAllListenerImpl::FilterAllListenerImpl( EventAttacherImpl * pEA_, const OUString& EventMethod_, 463*cdf0e10cSrcweir const Reference< XAllListener >& AllListener_ ) 464*cdf0e10cSrcweir : m_pEA( pEA_ ) 465*cdf0e10cSrcweir , m_xEAHold( *pEA_ ) 466*cdf0e10cSrcweir , m_EventMethod( EventMethod_ ) 467*cdf0e10cSrcweir , m_AllListener( AllListener_ ) 468*cdf0e10cSrcweir { 469*cdf0e10cSrcweir } 470*cdf0e10cSrcweir 471*cdf0e10cSrcweir //************************************************************************* 472*cdf0e10cSrcweir void SAL_CALL FilterAllListenerImpl::firing(const AllEventObject& Event) 473*cdf0e10cSrcweir throw( RuntimeException ) 474*cdf0e10cSrcweir { 475*cdf0e10cSrcweir // Nur durchreichen, wenn es die richtige Methode ist 476*cdf0e10cSrcweir if( Event.MethodName == m_EventMethod && m_AllListener.is() ) 477*cdf0e10cSrcweir m_AllListener->firing( Event ); 478*cdf0e10cSrcweir } 479*cdf0e10cSrcweir 480*cdf0e10cSrcweir //************************************************************************* 481*cdf0e10cSrcweir // Convert to the standard event return 482*cdf0e10cSrcweir void FilterAllListenerImpl::convertToEventReturn( Any & rRet, const Type & rRetType ) 483*cdf0e10cSrcweir throw( CannotConvertException ) 484*cdf0e10cSrcweir { 485*cdf0e10cSrcweir // no return value? Set to the specified values 486*cdf0e10cSrcweir if( rRet.getValueType().getTypeClass() == TypeClass_VOID ) 487*cdf0e10cSrcweir { 488*cdf0e10cSrcweir switch( rRetType.getTypeClass() ) 489*cdf0e10cSrcweir { 490*cdf0e10cSrcweir case TypeClass_INTERFACE: 491*cdf0e10cSrcweir { 492*cdf0e10cSrcweir rRet <<= Reference< XInterface >(); 493*cdf0e10cSrcweir } 494*cdf0e10cSrcweir break; 495*cdf0e10cSrcweir 496*cdf0e10cSrcweir case TypeClass_BOOLEAN: 497*cdf0e10cSrcweir rRet <<= sal_True; 498*cdf0e10cSrcweir break; 499*cdf0e10cSrcweir 500*cdf0e10cSrcweir case TypeClass_STRING: 501*cdf0e10cSrcweir rRet <<= OUString(); 502*cdf0e10cSrcweir break; 503*cdf0e10cSrcweir 504*cdf0e10cSrcweir case TypeClass_FLOAT: rRet <<= float(0); break; 505*cdf0e10cSrcweir case TypeClass_DOUBLE: rRet <<= double(0.0); break; 506*cdf0e10cSrcweir case TypeClass_BYTE: rRet <<= sal_uInt8( 0 ); break; 507*cdf0e10cSrcweir case TypeClass_SHORT: rRet <<= sal_Int16( 0 ); break; 508*cdf0e10cSrcweir case TypeClass_LONG: rRet <<= sal_Int32( 0 ); break; 509*cdf0e10cSrcweir case TypeClass_UNSIGNED_SHORT: rRet <<= sal_uInt16( 0 ); break; 510*cdf0e10cSrcweir case TypeClass_UNSIGNED_LONG: rRet <<= sal_uInt32( 0 ); break; 511*cdf0e10cSrcweir default: 512*cdf0e10cSrcweir break; 513*cdf0e10cSrcweir } 514*cdf0e10cSrcweir } 515*cdf0e10cSrcweir else if( !rRet.getValueType().equals( rRetType ) ) 516*cdf0e10cSrcweir { 517*cdf0e10cSrcweir Reference< XTypeConverter > xConverter = m_pEA->getConverter(); 518*cdf0e10cSrcweir if( xConverter.is() ) 519*cdf0e10cSrcweir rRet = xConverter->convertTo( rRet, rRetType ); 520*cdf0e10cSrcweir else 521*cdf0e10cSrcweir throw CannotConvertException(); // TODO TypeConversionException 522*cdf0e10cSrcweir } 523*cdf0e10cSrcweir } 524*cdf0e10cSrcweir 525*cdf0e10cSrcweir //************************************************************************* 526*cdf0e10cSrcweir Any SAL_CALL FilterAllListenerImpl::approveFiring( const AllEventObject& Event ) 527*cdf0e10cSrcweir throw( InvocationTargetException, RuntimeException ) 528*cdf0e10cSrcweir { 529*cdf0e10cSrcweir Any aRet; 530*cdf0e10cSrcweir 531*cdf0e10cSrcweir // Nur durchreichen, wenn es die richtige Methode ist 532*cdf0e10cSrcweir if( Event.MethodName == m_EventMethod && m_AllListener.is() ) 533*cdf0e10cSrcweir aRet = m_AllListener->approveFiring( Event ); 534*cdf0e10cSrcweir else 535*cdf0e10cSrcweir { 536*cdf0e10cSrcweir // Convert to the standard event return 537*cdf0e10cSrcweir try 538*cdf0e10cSrcweir { 539*cdf0e10cSrcweir Reference< XIdlClass > xListenerType = m_pEA->getReflection()-> 540*cdf0e10cSrcweir forName( Event.ListenerType.getTypeName() ); 541*cdf0e10cSrcweir Reference< XIdlMethod > xMeth = xListenerType->getMethod( Event.MethodName ); 542*cdf0e10cSrcweir if( xMeth.is() ) 543*cdf0e10cSrcweir { 544*cdf0e10cSrcweir Reference< XIdlClass > xRetType = xMeth->getReturnType(); 545*cdf0e10cSrcweir Type aRetType( xRetType->getTypeClass(), xRetType->getName() ); 546*cdf0e10cSrcweir convertToEventReturn( aRet, aRetType ); 547*cdf0e10cSrcweir } 548*cdf0e10cSrcweir } 549*cdf0e10cSrcweir catch( CannotConvertException& e ) 550*cdf0e10cSrcweir { 551*cdf0e10cSrcweir throw InvocationTargetException( OUString(), Reference< XInterface >(), Any(&e, ::getCppuType( (CannotConvertException*)0)) ); 552*cdf0e10cSrcweir } 553*cdf0e10cSrcweir } 554*cdf0e10cSrcweir return aRet; 555*cdf0e10cSrcweir } 556*cdf0e10cSrcweir 557*cdf0e10cSrcweir //************************************************************************* 558*cdf0e10cSrcweir void FilterAllListenerImpl::disposing(const EventObject& ) 559*cdf0e10cSrcweir throw( RuntimeException ) 560*cdf0e10cSrcweir { 561*cdf0e10cSrcweir // TODO: ??? 562*cdf0e10cSrcweir } 563*cdf0e10cSrcweir 564*cdf0e10cSrcweir 565*cdf0e10cSrcweir //************************************************************************* 566*cdf0e10cSrcweir Reference< XEventListener > EventAttacherImpl::attachListener 567*cdf0e10cSrcweir ( 568*cdf0e10cSrcweir const Reference< XInterface >& xObject, 569*cdf0e10cSrcweir const Reference< XAllListener >& AllListener, 570*cdf0e10cSrcweir const Any& Helper, 571*cdf0e10cSrcweir const OUString& ListenerType, 572*cdf0e10cSrcweir const OUString& AddListenerParam 573*cdf0e10cSrcweir ) 574*cdf0e10cSrcweir throw( IllegalArgumentException, ServiceNotRegisteredException, CannotCreateAdapterException, IntrospectionException, RuntimeException ) 575*cdf0e10cSrcweir { 576*cdf0e10cSrcweir if( !xObject.is() || !AllListener.is() ) 577*cdf0e10cSrcweir throw IllegalArgumentException(); 578*cdf0e10cSrcweir 579*cdf0e10cSrcweir Reference< XEventListener > xRet = NULL; 580*cdf0e10cSrcweir 581*cdf0e10cSrcweir // InvocationAdapterService holen 582*cdf0e10cSrcweir Reference< XInvocationAdapterFactory > xInvocationAdapterFactory = getInvocationAdapterService(); 583*cdf0e10cSrcweir if( !xInvocationAdapterFactory.is() ) 584*cdf0e10cSrcweir throw ServiceNotRegisteredException(); 585*cdf0e10cSrcweir 586*cdf0e10cSrcweir // Listener-Klasse per Reflection besorgen 587*cdf0e10cSrcweir Reference< XIdlReflection > xReflection = getReflection(); 588*cdf0e10cSrcweir if( !xReflection.is() ) 589*cdf0e10cSrcweir throw ServiceNotRegisteredException(); 590*cdf0e10cSrcweir 591*cdf0e10cSrcweir // Anmelden, dazu passende addListener-Methode aufrufen 592*cdf0e10cSrcweir // Zunaechst ueber Introspection gehen, da die Methoden in der gleichen 593*cdf0e10cSrcweir // Weise analysiert werden koennen. Fuer bessere Performance entweder 594*cdf0e10cSrcweir // hier nochmal implementieren oder die Impl-Methode der Introspection 595*cdf0e10cSrcweir // fuer diesen Zweck konfigurierbar machen. 596*cdf0e10cSrcweir 597*cdf0e10cSrcweir // Introspection-Service holen 598*cdf0e10cSrcweir Reference< XIntrospection > xIntrospection = getIntrospection(); 599*cdf0e10cSrcweir if( !xIntrospection.is() ) 600*cdf0e10cSrcweir return xRet; 601*cdf0e10cSrcweir 602*cdf0e10cSrcweir // und unspecten 603*cdf0e10cSrcweir Any aObjAny( &xObject, ::getCppuType( (const Reference< XInterface > *)0) ); 604*cdf0e10cSrcweir 605*cdf0e10cSrcweir Reference< XIntrospectionAccess > xAccess = xIntrospection->inspect( aObjAny ); 606*cdf0e10cSrcweir if( !xAccess.is() ) 607*cdf0e10cSrcweir return xRet; 608*cdf0e10cSrcweir 609*cdf0e10cSrcweir // Name der addListener-Methode zusammenbasteln 610*cdf0e10cSrcweir OUString aAddListenerName; 611*cdf0e10cSrcweir OUString aListenerName( ListenerType ); 612*cdf0e10cSrcweir sal_Int32 nIndex = aListenerName.lastIndexOf( '.' ); 613*cdf0e10cSrcweir // set index to the interface name without package name 614*cdf0e10cSrcweir if( nIndex == -1 ) 615*cdf0e10cSrcweir // not found 616*cdf0e10cSrcweir nIndex = 0; 617*cdf0e10cSrcweir else 618*cdf0e10cSrcweir nIndex++; 619*cdf0e10cSrcweir if( aListenerName[nIndex] == 'X' ) 620*cdf0e10cSrcweir // erase X from the interface name 621*cdf0e10cSrcweir aListenerName = aListenerName.copy( nIndex +1 ); 622*cdf0e10cSrcweir aAddListenerName = OUString( RTL_CONSTASCII_USTRINGPARAM( "add" ) ) + aListenerName; 623*cdf0e10cSrcweir 624*cdf0e10cSrcweir // Methoden nach der passenden addListener-Methode durchsuchen 625*cdf0e10cSrcweir Sequence< Reference< XIdlMethod > > aMethodSeq = xAccess->getMethods( MethodConcept::LISTENER ); 626*cdf0e10cSrcweir sal_uInt32 i, nLen = aMethodSeq.getLength(); 627*cdf0e10cSrcweir const Reference< XIdlMethod >* pMethods = aMethodSeq.getConstArray(); 628*cdf0e10cSrcweir 629*cdf0e10cSrcweir for( i = 0 ; i < nLen ; i++ ) 630*cdf0e10cSrcweir { 631*cdf0e10cSrcweir // Methode ansprechen 632*cdf0e10cSrcweir const Reference< XIdlMethod >& rxMethod = pMethods[i]; 633*cdf0e10cSrcweir 634*cdf0e10cSrcweir // Ist es die richtige Methode? 635*cdf0e10cSrcweir OUString aMethName = rxMethod->getName(); 636*cdf0e10cSrcweir 637*cdf0e10cSrcweir if( aAddListenerName == aMethName ) 638*cdf0e10cSrcweir { 639*cdf0e10cSrcweir Sequence< Reference< XIdlClass > > params = rxMethod->getParameterTypes(); 640*cdf0e10cSrcweir sal_uInt32 nParamCount = params.getLength(); 641*cdf0e10cSrcweir 642*cdf0e10cSrcweir Reference< XIdlClass > xListenerType; 643*cdf0e10cSrcweir if( nParamCount == 1 ) 644*cdf0e10cSrcweir xListenerType = params.getConstArray()[0]; 645*cdf0e10cSrcweir else if( nParamCount == 2 ) 646*cdf0e10cSrcweir xListenerType = params.getConstArray()[1]; 647*cdf0e10cSrcweir 648*cdf0e10cSrcweir // Adapter zum eigentlichen Listener-Typ anfordern 649*cdf0e10cSrcweir Reference< XInterface > xAdapter = createAllListenerAdapter 650*cdf0e10cSrcweir ( xInvocationAdapterFactory, xListenerType, AllListener, Helper ); 651*cdf0e10cSrcweir 652*cdf0e10cSrcweir if( !xAdapter.is() ) 653*cdf0e10cSrcweir throw CannotCreateAdapterException(); 654*cdf0e10cSrcweir xRet = Reference< XEventListener >( xAdapter, UNO_QUERY ); 655*cdf0e10cSrcweir 656*cdf0e10cSrcweir 657*cdf0e10cSrcweir // Nur der Listener als Parameter? 658*cdf0e10cSrcweir if( nParamCount == 1 ) 659*cdf0e10cSrcweir { 660*cdf0e10cSrcweir Sequence< Any > args( 1 ); 661*cdf0e10cSrcweir args.getArray()[0] <<= xAdapter; 662*cdf0e10cSrcweir try 663*cdf0e10cSrcweir { 664*cdf0e10cSrcweir rxMethod->invoke( aObjAny, args ); 665*cdf0e10cSrcweir } 666*cdf0e10cSrcweir catch( InvocationTargetException& ) 667*cdf0e10cSrcweir { 668*cdf0e10cSrcweir throw IntrospectionException(); 669*cdf0e10cSrcweir } 670*cdf0e10cSrcweir } 671*cdf0e10cSrcweir // Sonst den Zusatzparameter mit uebergeben 672*cdf0e10cSrcweir else if( nParamCount == 2 ) 673*cdf0e10cSrcweir { 674*cdf0e10cSrcweir Sequence< Any > args( 2 ); 675*cdf0e10cSrcweir Any* pAnys = args.getArray(); 676*cdf0e10cSrcweir 677*cdf0e10cSrcweir // Typ des 1. Parameters pruefen 678*cdf0e10cSrcweir Reference< XIdlClass > xParamClass = params.getConstArray()[0]; 679*cdf0e10cSrcweir if( xParamClass->getTypeClass() == TypeClass_STRING ) 680*cdf0e10cSrcweir { 681*cdf0e10cSrcweir pAnys[0] <<= AddListenerParam; 682*cdf0e10cSrcweir } 683*cdf0e10cSrcweir 684*cdf0e10cSrcweir // 2. Parameter == Listener? TODO: Pruefen! 685*cdf0e10cSrcweir pAnys[1] <<= xAdapter; 686*cdf0e10cSrcweir 687*cdf0e10cSrcweir // TODO: Konvertierung String -> ? 688*cdf0e10cSrcweir // else 689*cdf0e10cSrcweir try 690*cdf0e10cSrcweir { 691*cdf0e10cSrcweir rxMethod->invoke( aObjAny, args ); 692*cdf0e10cSrcweir } 693*cdf0e10cSrcweir catch( InvocationTargetException& ) 694*cdf0e10cSrcweir { 695*cdf0e10cSrcweir throw IntrospectionException(); 696*cdf0e10cSrcweir } 697*cdf0e10cSrcweir } 698*cdf0e10cSrcweir break; 699*cdf0e10cSrcweir // else... 700*cdf0e10cSrcweir // Alles andere wird nicht unterstuetzt 701*cdf0e10cSrcweir } 702*cdf0e10cSrcweir } 703*cdf0e10cSrcweir 704*cdf0e10cSrcweir return xRet; 705*cdf0e10cSrcweir } 706*cdf0e10cSrcweir 707*cdf0e10cSrcweir // XEventAttacher 708*cdf0e10cSrcweir Reference< XEventListener > EventAttacherImpl::attachSingleEventListener 709*cdf0e10cSrcweir ( 710*cdf0e10cSrcweir const Reference< XInterface >& xObject, 711*cdf0e10cSrcweir const Reference< XAllListener >& AllListener, 712*cdf0e10cSrcweir const Any& Helper, 713*cdf0e10cSrcweir const OUString& ListenerType, 714*cdf0e10cSrcweir const OUString& AddListenerParam, 715*cdf0e10cSrcweir const OUString& EventMethod 716*cdf0e10cSrcweir ) 717*cdf0e10cSrcweir throw( IllegalArgumentException, ServiceNotRegisteredException, CannotCreateAdapterException, IntrospectionException, RuntimeException ) 718*cdf0e10cSrcweir { 719*cdf0e10cSrcweir // FilterListener anmelden 720*cdf0e10cSrcweir Reference< XAllListener > aFilterListener = (XAllListener*) 721*cdf0e10cSrcweir new FilterAllListenerImpl( this, EventMethod, AllListener ); 722*cdf0e10cSrcweir return attachListener( xObject, aFilterListener, Helper, ListenerType, AddListenerParam); 723*cdf0e10cSrcweir } 724*cdf0e10cSrcweir 725*cdf0e10cSrcweir // XEventAttacher 726*cdf0e10cSrcweir void EventAttacherImpl::removeListener 727*cdf0e10cSrcweir ( 728*cdf0e10cSrcweir const Reference< XInterface >& xObject, 729*cdf0e10cSrcweir const OUString& ListenerType, 730*cdf0e10cSrcweir const OUString& AddListenerParam, 731*cdf0e10cSrcweir const Reference< XEventListener >& aToRemoveListener 732*cdf0e10cSrcweir ) 733*cdf0e10cSrcweir throw( IllegalArgumentException, IntrospectionException, RuntimeException ) 734*cdf0e10cSrcweir { 735*cdf0e10cSrcweir if( !xObject.is() || !aToRemoveListener.is() ) 736*cdf0e10cSrcweir throw IllegalArgumentException(); 737*cdf0e10cSrcweir 738*cdf0e10cSrcweir // Listener-Klasse per Reflection besorgen 739*cdf0e10cSrcweir Reference< XIdlReflection > xReflection = getReflection(); 740*cdf0e10cSrcweir if( !xReflection.is() ) 741*cdf0e10cSrcweir throw IntrospectionException(); 742*cdf0e10cSrcweir 743*cdf0e10cSrcweir // Abmelden, dazu passende removeListener-Methode aufrufen 744*cdf0e10cSrcweir // Zunaechst ueber Introspection gehen, da die Methoden in der gleichen 745*cdf0e10cSrcweir // Weise analysiert werden koennen. Fuer bessere Performance entweder 746*cdf0e10cSrcweir // hier nochmal implementieren oder die Impl-Methode der Introspection 747*cdf0e10cSrcweir // fuer diesen Zweck konfigurierbar machen. 748*cdf0e10cSrcweir 749*cdf0e10cSrcweir // Introspection-Service holen 750*cdf0e10cSrcweir Reference< XIntrospection > xIntrospection = getIntrospection(); 751*cdf0e10cSrcweir if( !xIntrospection.is() ) 752*cdf0e10cSrcweir throw IntrospectionException(); 753*cdf0e10cSrcweir 754*cdf0e10cSrcweir // und inspecten 755*cdf0e10cSrcweir Any aObjAny( &xObject, ::getCppuType( (const Reference< XInterface > *)0) ); 756*cdf0e10cSrcweir Reference< XIntrospectionAccess > xAccess = xIntrospection->inspect( aObjAny ); 757*cdf0e10cSrcweir if( !xAccess.is() ) 758*cdf0e10cSrcweir throw IntrospectionException(); 759*cdf0e10cSrcweir 760*cdf0e10cSrcweir // Name der removeListener-Methode zusammenbasteln 761*cdf0e10cSrcweir OUString aRemoveListenerName; 762*cdf0e10cSrcweir OUString aListenerName( ListenerType ); 763*cdf0e10cSrcweir sal_Int32 nIndex = aListenerName.lastIndexOf( '.' ); 764*cdf0e10cSrcweir // set index to the interface name without package name 765*cdf0e10cSrcweir if( nIndex == -1 ) 766*cdf0e10cSrcweir // not found 767*cdf0e10cSrcweir nIndex = 0; 768*cdf0e10cSrcweir else 769*cdf0e10cSrcweir nIndex++; 770*cdf0e10cSrcweir if( aListenerName[nIndex] == 'X' ) 771*cdf0e10cSrcweir // erase X from the interface name 772*cdf0e10cSrcweir aListenerName = aListenerName.copy( nIndex +1 ); 773*cdf0e10cSrcweir aRemoveListenerName = OUString( RTL_CONSTASCII_USTRINGPARAM("remove") ) + aListenerName; 774*cdf0e10cSrcweir 775*cdf0e10cSrcweir // Methoden nach der passenden addListener-Methode durchsuchen 776*cdf0e10cSrcweir Sequence< Reference< XIdlMethod > > aMethodSeq = xAccess->getMethods( MethodConcept::LISTENER ); 777*cdf0e10cSrcweir sal_uInt32 i, nLen = aMethodSeq.getLength(); 778*cdf0e10cSrcweir const Reference< XIdlMethod >* pMethods = aMethodSeq.getConstArray(); 779*cdf0e10cSrcweir for( i = 0 ; i < nLen ; i++ ) 780*cdf0e10cSrcweir { 781*cdf0e10cSrcweir // Methode ansprechen 782*cdf0e10cSrcweir const Reference< XIdlMethod >& rxMethod = pMethods[i]; 783*cdf0e10cSrcweir 784*cdf0e10cSrcweir // Ist es die richtige Methode? 785*cdf0e10cSrcweir if( aRemoveListenerName == rxMethod->getName() ) 786*cdf0e10cSrcweir { 787*cdf0e10cSrcweir Sequence< Reference< XIdlClass > > params = rxMethod->getParameterTypes(); 788*cdf0e10cSrcweir sal_uInt32 nParamCount = params.getLength(); 789*cdf0e10cSrcweir 790*cdf0e10cSrcweir // Nur der Listener als Parameter? 791*cdf0e10cSrcweir if( nParamCount == 1 ) 792*cdf0e10cSrcweir { 793*cdf0e10cSrcweir Sequence< Any > args( 1 ); 794*cdf0e10cSrcweir args.getArray()[0] <<= aToRemoveListener; 795*cdf0e10cSrcweir try 796*cdf0e10cSrcweir { 797*cdf0e10cSrcweir rxMethod->invoke( aObjAny, args ); 798*cdf0e10cSrcweir } 799*cdf0e10cSrcweir catch( InvocationTargetException& ) 800*cdf0e10cSrcweir { 801*cdf0e10cSrcweir throw IntrospectionException(); 802*cdf0e10cSrcweir } 803*cdf0e10cSrcweir } 804*cdf0e10cSrcweir // Sonst den Zusatzparameter mit uebergeben 805*cdf0e10cSrcweir else if( nParamCount == 2 ) 806*cdf0e10cSrcweir { 807*cdf0e10cSrcweir Sequence< Any > args( 2 ); 808*cdf0e10cSrcweir Any* pAnys = args.getArray(); 809*cdf0e10cSrcweir 810*cdf0e10cSrcweir // Typ des 1. Parameters pruefen 811*cdf0e10cSrcweir Reference< XIdlClass > xParamClass = params.getConstArray()[0]; 812*cdf0e10cSrcweir if( xParamClass->getTypeClass() == TypeClass_STRING ) 813*cdf0e10cSrcweir pAnys[0] <<= AddListenerParam; 814*cdf0e10cSrcweir 815*cdf0e10cSrcweir // 2. Parameter == Listener? TODO: Pruefen! 816*cdf0e10cSrcweir pAnys[1] <<= aToRemoveListener; 817*cdf0e10cSrcweir 818*cdf0e10cSrcweir // TODO: Konvertierung String -> ? 819*cdf0e10cSrcweir // else 820*cdf0e10cSrcweir try 821*cdf0e10cSrcweir { 822*cdf0e10cSrcweir rxMethod->invoke( aObjAny, args ); 823*cdf0e10cSrcweir } 824*cdf0e10cSrcweir catch( InvocationTargetException& ) 825*cdf0e10cSrcweir { 826*cdf0e10cSrcweir throw IntrospectionException(); 827*cdf0e10cSrcweir } 828*cdf0e10cSrcweir } 829*cdf0e10cSrcweir break; 830*cdf0e10cSrcweir } 831*cdf0e10cSrcweir } 832*cdf0e10cSrcweir } 833*cdf0e10cSrcweir 834*cdf0e10cSrcweir } 835*cdf0e10cSrcweir 836*cdf0e10cSrcweir extern "C" 837*cdf0e10cSrcweir { 838*cdf0e10cSrcweir //================================================================================================== 839*cdf0e10cSrcweir void SAL_CALL component_getImplementationEnvironment( 840*cdf0e10cSrcweir const sal_Char ** ppEnvTypeName, uno_Environment ** ) 841*cdf0e10cSrcweir { 842*cdf0e10cSrcweir *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; 843*cdf0e10cSrcweir } 844*cdf0e10cSrcweir //================================================================================================== 845*cdf0e10cSrcweir void * SAL_CALL component_getFactory( 846*cdf0e10cSrcweir const sal_Char * pImplName, void * pServiceManager, void * ) 847*cdf0e10cSrcweir { 848*cdf0e10cSrcweir void * pRet = 0; 849*cdf0e10cSrcweir 850*cdf0e10cSrcweir if (pServiceManager && rtl_str_compare( pImplName, IMPLNAME ) == 0) 851*cdf0e10cSrcweir { 852*cdf0e10cSrcweir Reference< XSingleServiceFactory > xFactory( createOneInstanceFactory( 853*cdf0e10cSrcweir reinterpret_cast< XMultiServiceFactory * >( pServiceManager ), 854*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLNAME ) ), 855*cdf0e10cSrcweir ::comp_EventAttacher::EventAttacherImpl_CreateInstance, 856*cdf0e10cSrcweir ::comp_EventAttacher::EventAttacherImpl::getSupportedServiceNames_Static() ) ); 857*cdf0e10cSrcweir 858*cdf0e10cSrcweir if (xFactory.is()) 859*cdf0e10cSrcweir { 860*cdf0e10cSrcweir xFactory->acquire(); 861*cdf0e10cSrcweir pRet = xFactory.get(); 862*cdf0e10cSrcweir } 863*cdf0e10cSrcweir } 864*cdf0e10cSrcweir 865*cdf0e10cSrcweir return pRet; 866*cdf0e10cSrcweir } 867*cdf0e10cSrcweir } 868*cdf0e10cSrcweir 869*cdf0e10cSrcweir 870*cdf0e10cSrcweir 871