1*647a425cSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*647a425cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*647a425cSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*647a425cSAndrew Rist * distributed with this work for additional information 6*647a425cSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*647a425cSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*647a425cSAndrew Rist * "License"); you may not use this file except in compliance 9*647a425cSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*647a425cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*647a425cSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*647a425cSAndrew Rist * software distributed under the License is distributed on an 15*647a425cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*647a425cSAndrew Rist * KIND, either express or implied. See the License for the 17*647a425cSAndrew Rist * specific language governing permissions and limitations 18*647a425cSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*647a425cSAndrew Rist *************************************************************/ 21*647a425cSAndrew Rist 22*647a425cSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_stoc.hxx" 26cdf0e10cSrcweir #include <cppuhelper/queryinterface.hxx> 27cdf0e10cSrcweir #ifndef _CPPUHELPER_IMPLEMENTATIONENTRY_HXX_ 28cdf0e10cSrcweir #include <cppuhelper/implementationentry.hxx> 29cdf0e10cSrcweir #endif 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp> 32cdf0e10cSrcweir #include <com/sun/star/reflection/XTypeDescription.hpp> 33cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp" 34cdf0e10cSrcweir 35cdf0e10cSrcweir using namespace com::sun::star; 36cdf0e10cSrcweir using namespace com::sun::star::lang; 37cdf0e10cSrcweir using namespace com::sun::star::registry; 38cdf0e10cSrcweir using namespace cppu; 39cdf0e10cSrcweir using namespace osl; 40cdf0e10cSrcweir using namespace rtl; 41cdf0e10cSrcweir 42cdf0e10cSrcweir #include "base.hxx" 43cdf0e10cSrcweir 44cdf0e10cSrcweir 45cdf0e10cSrcweir namespace stoc_corefl 46cdf0e10cSrcweir { 47cdf0e10cSrcweir 48cdf0e10cSrcweir static const sal_Int32 CACHE_SIZE = 256; 49cdf0e10cSrcweir 50cdf0e10cSrcweir #define SERVICENAME "com.sun.star.reflection.CoreReflection" 51cdf0e10cSrcweir #define IMPLNAME "com.sun.star.comp.stoc.CoreReflection" 52cdf0e10cSrcweir 53cdf0e10cSrcweir // can be static, as every client of the core reflection keeps a reference to the 54cdf0e10cSrcweir // core reflection, so refcounting can be done here. 55cdf0e10cSrcweir static rtl_StandardModuleCount g_moduleCount = MODULE_COUNT_INIT; 56cdf0e10cSrcweir 57cdf0e10cSrcweir static Sequence< OUString > core_getSupportedServiceNames() 58cdf0e10cSrcweir { 59cdf0e10cSrcweir static Sequence < OUString > *pNames = 0; 60cdf0e10cSrcweir if( ! pNames ) 61cdf0e10cSrcweir { 62cdf0e10cSrcweir MutexGuard guard( Mutex::getGlobalMutex() ); 63cdf0e10cSrcweir if( !pNames ) 64cdf0e10cSrcweir { 65cdf0e10cSrcweir static Sequence< OUString > seqNames(1); 66cdf0e10cSrcweir seqNames.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM(SERVICENAME) ); 67cdf0e10cSrcweir pNames = &seqNames; 68cdf0e10cSrcweir } 69cdf0e10cSrcweir } 70cdf0e10cSrcweir return *pNames; 71cdf0e10cSrcweir } 72cdf0e10cSrcweir 73cdf0e10cSrcweir static OUString core_getImplementationName() 74cdf0e10cSrcweir { 75cdf0e10cSrcweir static OUString *pImplName = 0; 76cdf0e10cSrcweir if( ! pImplName ) 77cdf0e10cSrcweir { 78cdf0e10cSrcweir MutexGuard guard( Mutex::getGlobalMutex() ); 79cdf0e10cSrcweir if( ! pImplName ) 80cdf0e10cSrcweir { 81cdf0e10cSrcweir static OUString implName( RTL_CONSTASCII_USTRINGPARAM( IMPLNAME ) ); 82cdf0e10cSrcweir pImplName = &implName; 83cdf0e10cSrcweir } 84cdf0e10cSrcweir } 85cdf0e10cSrcweir return *pImplName; 86cdf0e10cSrcweir } 87cdf0e10cSrcweir //__________________________________________________________________________________________________ 88cdf0e10cSrcweir IdlReflectionServiceImpl::IdlReflectionServiceImpl( 89cdf0e10cSrcweir const Reference< XComponentContext > & xContext ) 90cdf0e10cSrcweir : OComponentHelper( _aComponentMutex ) 91cdf0e10cSrcweir , _xMgr( xContext->getServiceManager(), UNO_QUERY ) 92cdf0e10cSrcweir , _aElements( CACHE_SIZE ) 93cdf0e10cSrcweir { 94cdf0e10cSrcweir g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); 95cdf0e10cSrcweir xContext->getValueByName( OUString( RTL_CONSTASCII_USTRINGPARAM( 96cdf0e10cSrcweir "/singletons/com.sun.star.reflection.theTypeDescriptionManager") ) ) >>= _xTDMgr; 97cdf0e10cSrcweir OSL_ENSURE( _xTDMgr.is(), "### cannot get singleton \"TypeDescriptionManager\" from context!" ); 98cdf0e10cSrcweir } 99cdf0e10cSrcweir //__________________________________________________________________________________________________ 100cdf0e10cSrcweir IdlReflectionServiceImpl::~IdlReflectionServiceImpl() 101cdf0e10cSrcweir { 102cdf0e10cSrcweir TRACE( "> IdlReflectionServiceImpl dtor <\n" ); 103cdf0e10cSrcweir g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); 104cdf0e10cSrcweir } 105cdf0e10cSrcweir 106cdf0e10cSrcweir // XInterface 107cdf0e10cSrcweir //__________________________________________________________________________________________________ 108cdf0e10cSrcweir Any IdlReflectionServiceImpl::queryInterface( const Type & rType ) 109cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 110cdf0e10cSrcweir { 111cdf0e10cSrcweir Any aRet( ::cppu::queryInterface( 112cdf0e10cSrcweir rType, 113cdf0e10cSrcweir static_cast< XIdlReflection * >( this ), 114cdf0e10cSrcweir static_cast< XHierarchicalNameAccess * >( this ), 115cdf0e10cSrcweir static_cast< XServiceInfo * >( this ) ) ); 116cdf0e10cSrcweir 117cdf0e10cSrcweir return (aRet.hasValue() ? aRet : OComponentHelper::queryInterface( rType )); 118cdf0e10cSrcweir } 119cdf0e10cSrcweir //__________________________________________________________________________________________________ 120cdf0e10cSrcweir void IdlReflectionServiceImpl::acquire() throw() 121cdf0e10cSrcweir { 122cdf0e10cSrcweir OComponentHelper::acquire(); 123cdf0e10cSrcweir } 124cdf0e10cSrcweir //__________________________________________________________________________________________________ 125cdf0e10cSrcweir void IdlReflectionServiceImpl::release() throw() 126cdf0e10cSrcweir { 127cdf0e10cSrcweir OComponentHelper::release(); 128cdf0e10cSrcweir } 129cdf0e10cSrcweir 130cdf0e10cSrcweir // XTypeProvider 131cdf0e10cSrcweir //__________________________________________________________________________________________________ 132cdf0e10cSrcweir Sequence< Type > IdlReflectionServiceImpl::getTypes() 133cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException) 134cdf0e10cSrcweir { 135cdf0e10cSrcweir static OTypeCollection * s_pTypes = 0; 136cdf0e10cSrcweir if (! s_pTypes) 137cdf0e10cSrcweir { 138cdf0e10cSrcweir MutexGuard aGuard( _aComponentMutex ); 139cdf0e10cSrcweir if (! s_pTypes) 140cdf0e10cSrcweir { 141cdf0e10cSrcweir static OTypeCollection s_aTypes( 142cdf0e10cSrcweir ::getCppuType( (const Reference< XIdlReflection > *)0 ), 143cdf0e10cSrcweir ::getCppuType( (const Reference< XHierarchicalNameAccess > *)0 ), 144cdf0e10cSrcweir ::getCppuType( (const Reference< XServiceInfo > *)0 ), 145cdf0e10cSrcweir OComponentHelper::getTypes() ); 146cdf0e10cSrcweir s_pTypes = &s_aTypes; 147cdf0e10cSrcweir } 148cdf0e10cSrcweir } 149cdf0e10cSrcweir return s_pTypes->getTypes(); 150cdf0e10cSrcweir } 151cdf0e10cSrcweir //__________________________________________________________________________________________________ 152cdf0e10cSrcweir Sequence< sal_Int8 > IdlReflectionServiceImpl::getImplementationId() 153cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException) 154cdf0e10cSrcweir { 155cdf0e10cSrcweir static OImplementationId * s_pId = 0; 156cdf0e10cSrcweir if (! s_pId) 157cdf0e10cSrcweir { 158cdf0e10cSrcweir MutexGuard aGuard( _aComponentMutex ); 159cdf0e10cSrcweir if (! s_pId) 160cdf0e10cSrcweir { 161cdf0e10cSrcweir static OImplementationId s_aId; 162cdf0e10cSrcweir s_pId = &s_aId; 163cdf0e10cSrcweir } 164cdf0e10cSrcweir } 165cdf0e10cSrcweir return s_pId->getImplementationId(); 166cdf0e10cSrcweir } 167cdf0e10cSrcweir 168cdf0e10cSrcweir // XComponent 169cdf0e10cSrcweir //__________________________________________________________________________________________________ 170cdf0e10cSrcweir void IdlReflectionServiceImpl::dispose() 171cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 172cdf0e10cSrcweir { 173cdf0e10cSrcweir TRACE( "> disposing corereflection... <" ); 174cdf0e10cSrcweir OComponentHelper::dispose(); 175cdf0e10cSrcweir 176cdf0e10cSrcweir MutexGuard aGuard( _aComponentMutex ); 177cdf0e10cSrcweir _aElements.clear(); 178cdf0e10cSrcweir #ifdef TEST_LIST_CLASSES 179cdf0e10cSrcweir OSL_ENSURE( g_aClassNames.size() == 0, "### idl classes still alive!" ); 180cdf0e10cSrcweir ClassNameList::const_iterator iPos( g_aClassNames.begin() ); 181cdf0e10cSrcweir while (iPos != g_aClassNames.end()) 182cdf0e10cSrcweir { 183cdf0e10cSrcweir OUString aName( *iPos ); 184cdf0e10cSrcweir ++iPos; 185cdf0e10cSrcweir } 186cdf0e10cSrcweir #endif 187cdf0e10cSrcweir } 188cdf0e10cSrcweir 189cdf0e10cSrcweir // XServiceInfo 190cdf0e10cSrcweir //__________________________________________________________________________________________________ 191cdf0e10cSrcweir OUString IdlReflectionServiceImpl::getImplementationName() 192cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 193cdf0e10cSrcweir { 194cdf0e10cSrcweir return core_getImplementationName(); 195cdf0e10cSrcweir } 196cdf0e10cSrcweir //__________________________________________________________________________________________________ 197cdf0e10cSrcweir sal_Bool IdlReflectionServiceImpl::supportsService( const OUString & rServiceName ) 198cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 199cdf0e10cSrcweir { 200cdf0e10cSrcweir const Sequence< OUString > & rSNL = getSupportedServiceNames(); 201cdf0e10cSrcweir const OUString * pArray = rSNL.getConstArray(); 202cdf0e10cSrcweir for ( sal_Int32 nPos = rSNL.getLength(); nPos--; ) 203cdf0e10cSrcweir { 204cdf0e10cSrcweir if (pArray[nPos] == rServiceName) 205cdf0e10cSrcweir return sal_True; 206cdf0e10cSrcweir } 207cdf0e10cSrcweir return sal_False; 208cdf0e10cSrcweir } 209cdf0e10cSrcweir //__________________________________________________________________________________________________ 210cdf0e10cSrcweir Sequence< OUString > IdlReflectionServiceImpl::getSupportedServiceNames() 211cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 212cdf0e10cSrcweir { 213cdf0e10cSrcweir return core_getSupportedServiceNames(); 214cdf0e10cSrcweir } 215cdf0e10cSrcweir 216cdf0e10cSrcweir // XIdlReflection 217cdf0e10cSrcweir //__________________________________________________________________________________________________ 218cdf0e10cSrcweir Reference< XIdlClass > IdlReflectionServiceImpl::getType( const Any & rObj ) 219cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir return (rObj.hasValue() ? forType( rObj.getValueTypeRef() ) : Reference< XIdlClass >()); 222cdf0e10cSrcweir } 223cdf0e10cSrcweir 224cdf0e10cSrcweir //__________________________________________________________________________________________________ 225cdf0e10cSrcweir inline Reference< XIdlClass > IdlReflectionServiceImpl::constructClass( 226cdf0e10cSrcweir typelib_TypeDescription * pTypeDescr ) 227cdf0e10cSrcweir { 228cdf0e10cSrcweir OSL_ENSURE( pTypeDescr->eTypeClass != typelib_TypeClass_TYPEDEF, "### unexpected typedef!" ); 229cdf0e10cSrcweir 230cdf0e10cSrcweir switch (pTypeDescr->eTypeClass) 231cdf0e10cSrcweir { 232cdf0e10cSrcweir case typelib_TypeClass_VOID: 233cdf0e10cSrcweir case typelib_TypeClass_CHAR: 234cdf0e10cSrcweir case typelib_TypeClass_BOOLEAN: 235cdf0e10cSrcweir case typelib_TypeClass_BYTE: 236cdf0e10cSrcweir case typelib_TypeClass_SHORT: 237cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_SHORT: 238cdf0e10cSrcweir case typelib_TypeClass_LONG: 239cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_LONG: 240cdf0e10cSrcweir case typelib_TypeClass_HYPER: 241cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_HYPER: 242cdf0e10cSrcweir case typelib_TypeClass_FLOAT: 243cdf0e10cSrcweir case typelib_TypeClass_DOUBLE: 244cdf0e10cSrcweir case typelib_TypeClass_STRING: 245cdf0e10cSrcweir case typelib_TypeClass_ANY: 246cdf0e10cSrcweir return new IdlClassImpl( this, pTypeDescr->pTypeName, pTypeDescr->eTypeClass, pTypeDescr ); 247cdf0e10cSrcweir 248cdf0e10cSrcweir case TypeClass_ENUM: 249cdf0e10cSrcweir return new EnumIdlClassImpl( this, pTypeDescr->pTypeName, pTypeDescr->eTypeClass, pTypeDescr ); 250cdf0e10cSrcweir 251cdf0e10cSrcweir case typelib_TypeClass_STRUCT: 252cdf0e10cSrcweir case typelib_TypeClass_UNION: 253cdf0e10cSrcweir case typelib_TypeClass_EXCEPTION: 254cdf0e10cSrcweir return new CompoundIdlClassImpl( this, pTypeDescr->pTypeName, pTypeDescr->eTypeClass, pTypeDescr ); 255cdf0e10cSrcweir 256cdf0e10cSrcweir case typelib_TypeClass_ARRAY: 257cdf0e10cSrcweir case typelib_TypeClass_SEQUENCE: 258cdf0e10cSrcweir return new ArrayIdlClassImpl( this, pTypeDescr->pTypeName, pTypeDescr->eTypeClass, pTypeDescr ); 259cdf0e10cSrcweir 260cdf0e10cSrcweir case typelib_TypeClass_INTERFACE: 261cdf0e10cSrcweir return new InterfaceIdlClassImpl( this, pTypeDescr->pTypeName, pTypeDescr->eTypeClass, pTypeDescr ); 262cdf0e10cSrcweir 263cdf0e10cSrcweir case typelib_TypeClass_TYPE: 264cdf0e10cSrcweir return new IdlClassImpl( this, pTypeDescr->pTypeName, pTypeDescr->eTypeClass, pTypeDescr ); 265cdf0e10cSrcweir 266cdf0e10cSrcweir default: 267cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 268cdf0e10cSrcweir OSL_TRACE( "### corereflection type unsupported: " ); 269cdf0e10cSrcweir OString aName( OUStringToOString( pTypeDescr->pTypeName, RTL_TEXTENCODING_ASCII_US ) ); 270cdf0e10cSrcweir OSL_TRACE( aName.getStr() ); 271cdf0e10cSrcweir OSL_TRACE( "\n" ); 272cdf0e10cSrcweir #endif 273cdf0e10cSrcweir return Reference< XIdlClass >(); 274cdf0e10cSrcweir } 275cdf0e10cSrcweir } 276cdf0e10cSrcweir //__________________________________________________________________________________________________ 277cdf0e10cSrcweir Reference< XIdlClass > IdlReflectionServiceImpl::forName( const OUString & rTypeName ) 278cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 279cdf0e10cSrcweir { 280cdf0e10cSrcweir Reference< XIdlClass > xRet; 281cdf0e10cSrcweir Any aAny( _aElements.getValue( rTypeName ) ); 282cdf0e10cSrcweir 283cdf0e10cSrcweir if (aAny.hasValue()) 284cdf0e10cSrcweir { 285cdf0e10cSrcweir if (aAny.getValueTypeClass() == TypeClass_INTERFACE) 286cdf0e10cSrcweir xRet = *(const Reference< XIdlClass > *)aAny.getValue(); 287cdf0e10cSrcweir } 288cdf0e10cSrcweir else 289cdf0e10cSrcweir { 290cdf0e10cSrcweir // try to get _type_ by name 291cdf0e10cSrcweir typelib_TypeDescription * pTD = 0; 292cdf0e10cSrcweir typelib_typedescription_getByName( &pTD, rTypeName.pData ); 293cdf0e10cSrcweir if (pTD) 294cdf0e10cSrcweir { 295cdf0e10cSrcweir if ((xRet = constructClass( pTD )).is()) 296cdf0e10cSrcweir _aElements.setValue( rTypeName, makeAny( xRet ) ); // update 297cdf0e10cSrcweir typelib_typedescription_release( pTD ); 298cdf0e10cSrcweir } 299cdf0e10cSrcweir } 300cdf0e10cSrcweir 301cdf0e10cSrcweir return xRet; 302cdf0e10cSrcweir } 303cdf0e10cSrcweir 304cdf0e10cSrcweir // XHierarchicalNameAccess 305cdf0e10cSrcweir //__________________________________________________________________________________________________ 306cdf0e10cSrcweir Any IdlReflectionServiceImpl::getByHierarchicalName( const OUString & rName ) 307cdf0e10cSrcweir throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException) 308cdf0e10cSrcweir { 309cdf0e10cSrcweir Any aRet( _aElements.getValue( rName ) ); 310cdf0e10cSrcweir if (! aRet.hasValue()) 311cdf0e10cSrcweir { 312cdf0e10cSrcweir // first look for constants exclusivly! 313cdf0e10cSrcweir aRet = _xTDMgr->getByHierarchicalName( rName ); 314cdf0e10cSrcweir if (aRet.getValueTypeClass() == TypeClass_INTERFACE) // if no constant, 315cdf0e10cSrcweir // i.e. XTypeDescription for a type 316cdf0e10cSrcweir { 317cdf0e10cSrcweir // type retrieved from tdmgr 318cdf0e10cSrcweir OSL_ASSERT( (*(Reference< XInterface > *)aRet.getValue())->queryInterface( 319cdf0e10cSrcweir ::getCppuType( (const Reference< XTypeDescription > *)0 ) ).hasValue() ); 320cdf0e10cSrcweir 321cdf0e10cSrcweir // if you are interested in a type then CALL forName()!!! 322cdf0e10cSrcweir // this way is NOT recommended for types, because this method looks for constants first 323cdf0e10cSrcweir 324cdf0e10cSrcweir // if td manager found some type, it will be in the cache (hopefully.. we just got it) 325cdf0e10cSrcweir // so the second retrieving via c typelib callback chain should succeed... 326cdf0e10cSrcweir 327cdf0e10cSrcweir // try to get _type_ by name 328cdf0e10cSrcweir typelib_TypeDescription * pTD = 0; 329cdf0e10cSrcweir typelib_typedescription_getByName( &pTD, rName.pData ); 330cdf0e10cSrcweir 331cdf0e10cSrcweir aRet.clear(); // kick XTypeDescription interface 332cdf0e10cSrcweir 333cdf0e10cSrcweir if (pTD) 334cdf0e10cSrcweir { 335cdf0e10cSrcweir Reference< XIdlClass > xIdlClass( constructClass( pTD ) ); 336cdf0e10cSrcweir aRet.setValue( &xIdlClass, ::getCppuType( (const Reference< XIdlClass > *)0 ) ); 337cdf0e10cSrcweir typelib_typedescription_release( pTD ); 338cdf0e10cSrcweir } 339cdf0e10cSrcweir } 340cdf0e10cSrcweir // else is constant 341cdf0e10cSrcweir 342cdf0e10cSrcweir // update 343cdf0e10cSrcweir if (aRet.hasValue()) 344cdf0e10cSrcweir _aElements.setValue( rName, aRet ); 345cdf0e10cSrcweir else 346cdf0e10cSrcweir { 347cdf0e10cSrcweir throw NoSuchElementException( rName, Reference< XInterface >() ); 348cdf0e10cSrcweir } 349cdf0e10cSrcweir } 350cdf0e10cSrcweir return aRet; 351cdf0e10cSrcweir } 352cdf0e10cSrcweir //__________________________________________________________________________________________________ 353cdf0e10cSrcweir sal_Bool IdlReflectionServiceImpl::hasByHierarchicalName( const OUString & rName ) 354cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 355cdf0e10cSrcweir { 356cdf0e10cSrcweir try 357cdf0e10cSrcweir { 358cdf0e10cSrcweir return getByHierarchicalName( rName ).hasValue(); 359cdf0e10cSrcweir } 360cdf0e10cSrcweir catch (NoSuchElementException &) 361cdf0e10cSrcweir { 362cdf0e10cSrcweir } 363cdf0e10cSrcweir return sal_False; 364cdf0e10cSrcweir } 365cdf0e10cSrcweir 366cdf0e10cSrcweir //__________________________________________________________________________________________________ 367cdf0e10cSrcweir Reference< XIdlClass > IdlReflectionServiceImpl::forType( typelib_TypeDescription * pTypeDescr ) 368cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 369cdf0e10cSrcweir { 370cdf0e10cSrcweir Reference< XIdlClass > xRet; 371cdf0e10cSrcweir OUString aName( pTypeDescr->pTypeName ); 372cdf0e10cSrcweir Any aAny( _aElements.getValue( aName ) ); 373cdf0e10cSrcweir 374cdf0e10cSrcweir if (aAny.hasValue()) 375cdf0e10cSrcweir { 376cdf0e10cSrcweir if (aAny.getValueTypeClass() == TypeClass_INTERFACE) 377cdf0e10cSrcweir xRet = *(const Reference< XIdlClass > *)aAny.getValue(); 378cdf0e10cSrcweir } 379cdf0e10cSrcweir else 380cdf0e10cSrcweir { 381cdf0e10cSrcweir if (pTypeDescr && (xRet = constructClass( pTypeDescr )).is()) 382cdf0e10cSrcweir _aElements.setValue( aName, makeAny( xRet ) ); // update 383cdf0e10cSrcweir } 384cdf0e10cSrcweir 385cdf0e10cSrcweir return xRet; 386cdf0e10cSrcweir } 387cdf0e10cSrcweir //__________________________________________________________________________________________________ 388cdf0e10cSrcweir Reference< XIdlClass > IdlReflectionServiceImpl::forType( typelib_TypeDescriptionReference * pRef ) 389cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 390cdf0e10cSrcweir { 391cdf0e10cSrcweir typelib_TypeDescription * pTD = 0; 392cdf0e10cSrcweir TYPELIB_DANGER_GET( &pTD, pRef ); 393cdf0e10cSrcweir if (pTD) 394cdf0e10cSrcweir { 395cdf0e10cSrcweir Reference< XIdlClass > xRet = forType( pTD ); 396cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pTD ); 397cdf0e10cSrcweir return xRet; 398cdf0e10cSrcweir } 399cdf0e10cSrcweir throw RuntimeException( 400cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("IdlReflectionServiceImpl::forType() failed!") ), 401cdf0e10cSrcweir (XWeak *)(OWeakObject *)this ); 402cdf0e10cSrcweir } 403cdf0e10cSrcweir 404cdf0e10cSrcweir //__________________________________________________________________________________________________ 405cdf0e10cSrcweir const Mapping & IdlReflectionServiceImpl::getCpp2Uno() 406cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 407cdf0e10cSrcweir { 408cdf0e10cSrcweir if (! _aCpp2Uno.is()) 409cdf0e10cSrcweir { 410cdf0e10cSrcweir MutexGuard aGuard( getMutexAccess() ); 411cdf0e10cSrcweir if (! _aCpp2Uno.is()) 412cdf0e10cSrcweir { 413cdf0e10cSrcweir _aCpp2Uno = Mapping( 414cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ), 415cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO) ) ); 416cdf0e10cSrcweir OSL_ENSURE( _aCpp2Uno.is(), "### cannot get c++ to uno mapping!" ); 417cdf0e10cSrcweir if (! _aCpp2Uno.is()) 418cdf0e10cSrcweir { 419cdf0e10cSrcweir throw RuntimeException( 420cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("cannot get c++ to uno mapping!") ), 421cdf0e10cSrcweir (XWeak *)(OWeakObject *)this ); 422cdf0e10cSrcweir } 423cdf0e10cSrcweir } 424cdf0e10cSrcweir } 425cdf0e10cSrcweir return _aCpp2Uno; 426cdf0e10cSrcweir } 427cdf0e10cSrcweir //__________________________________________________________________________________________________ 428cdf0e10cSrcweir const Mapping & IdlReflectionServiceImpl::getUno2Cpp() 429cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 430cdf0e10cSrcweir { 431cdf0e10cSrcweir if (! _aUno2Cpp.is()) 432cdf0e10cSrcweir { 433cdf0e10cSrcweir MutexGuard aGuard( getMutexAccess() ); 434cdf0e10cSrcweir if (! _aUno2Cpp.is()) 435cdf0e10cSrcweir { 436cdf0e10cSrcweir _aUno2Cpp = Mapping( 437cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO) ), 438cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ) ); 439cdf0e10cSrcweir OSL_ENSURE( _aUno2Cpp.is(), "### cannot get uno to c++ mapping!" ); 440cdf0e10cSrcweir if (! _aUno2Cpp.is()) 441cdf0e10cSrcweir { 442cdf0e10cSrcweir throw RuntimeException( 443cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("cannot get uno to c++ mapping!") ), 444cdf0e10cSrcweir (XWeak *)(OWeakObject *)this ); 445cdf0e10cSrcweir } 446cdf0e10cSrcweir } 447cdf0e10cSrcweir } 448cdf0e10cSrcweir return _aUno2Cpp; 449cdf0e10cSrcweir } 450cdf0e10cSrcweir //__________________________________________________________________________________________________ 451cdf0e10cSrcweir uno_Interface * IdlReflectionServiceImpl::mapToUno( 452cdf0e10cSrcweir const Any & rObj, typelib_InterfaceTypeDescription * pTo ) 453cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 454cdf0e10cSrcweir { 455cdf0e10cSrcweir Reference< XInterface > xObj; 456cdf0e10cSrcweir if (extract( rObj, pTo, xObj, this )) 457cdf0e10cSrcweir return (uno_Interface *)getCpp2Uno().mapInterface( xObj.get(), pTo ); 458cdf0e10cSrcweir 459cdf0e10cSrcweir throw RuntimeException( 460cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("illegal object given!") ), 461cdf0e10cSrcweir (XWeak *)(OWeakObject *)this ); 462cdf0e10cSrcweir } 463cdf0e10cSrcweir 464cdf0e10cSrcweir //================================================================================================== 465cdf0e10cSrcweir Reference< XInterface > SAL_CALL IdlReflectionServiceImpl_create( 466cdf0e10cSrcweir const Reference< XComponentContext > & xContext ) 467cdf0e10cSrcweir throw(::com::sun::star::uno::Exception) 468cdf0e10cSrcweir { 469cdf0e10cSrcweir return Reference< XInterface >( (XWeak *)(OWeakObject *)new IdlReflectionServiceImpl( xContext ) ); 470cdf0e10cSrcweir } 471cdf0e10cSrcweir 472cdf0e10cSrcweir } 473cdf0e10cSrcweir 474cdf0e10cSrcweir 475cdf0e10cSrcweir //################################################################################################## 476cdf0e10cSrcweir //################################################################################################## 477cdf0e10cSrcweir //################################################################################################## 478cdf0e10cSrcweir 479cdf0e10cSrcweir using namespace stoc_corefl; 480cdf0e10cSrcweir 481cdf0e10cSrcweir static struct ImplementationEntry g_entries[] = 482cdf0e10cSrcweir { 483cdf0e10cSrcweir { 484cdf0e10cSrcweir IdlReflectionServiceImpl_create, core_getImplementationName, 485cdf0e10cSrcweir core_getSupportedServiceNames, createSingleComponentFactory, 486cdf0e10cSrcweir &g_moduleCount.modCnt , 0 487cdf0e10cSrcweir }, 488cdf0e10cSrcweir { 0, 0, 0, 0, 0, 0 } 489cdf0e10cSrcweir }; 490cdf0e10cSrcweir 491cdf0e10cSrcweir extern "C" 492cdf0e10cSrcweir { 493cdf0e10cSrcweir sal_Bool SAL_CALL component_canUnload( TimeValue *pTime ) 494cdf0e10cSrcweir { 495cdf0e10cSrcweir return g_moduleCount.canUnload( &g_moduleCount , pTime ); 496cdf0e10cSrcweir } 497cdf0e10cSrcweir 498cdf0e10cSrcweir //================================================================================================== 499cdf0e10cSrcweir void SAL_CALL component_getImplementationEnvironment( 500cdf0e10cSrcweir const sal_Char ** ppEnvTypeName, uno_Environment ** ) 501cdf0e10cSrcweir { 502cdf0e10cSrcweir *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; 503cdf0e10cSrcweir } 504cdf0e10cSrcweir //================================================================================================== 505cdf0e10cSrcweir void * SAL_CALL component_getFactory( 506cdf0e10cSrcweir const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey ) 507cdf0e10cSrcweir { 508cdf0e10cSrcweir return component_getFactoryHelper( pImplName, pServiceManager, pRegistryKey , g_entries ); 509cdf0e10cSrcweir } 510cdf0e10cSrcweir } 511