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 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_stoc.hxx" 30*cdf0e10cSrcweir #include <osl/diagnose.h> 31*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 32*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp> 33*cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp" 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include "registry/reader.hxx" 36*cdf0e10cSrcweir #include "registry/version.h" 37*cdf0e10cSrcweir #include "base.hxx" 38*cdf0e10cSrcweir #include "methoddescription.hxx" 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir #include <memory> 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir using namespace com::sun::star; 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir namespace { 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir class Constructor: 47*cdf0e10cSrcweir public cppu::WeakImplHelper1< XServiceConstructorDescription > 48*cdf0e10cSrcweir { 49*cdf0e10cSrcweir public: 50*cdf0e10cSrcweir Constructor( 51*cdf0e10cSrcweir Reference< XHierarchicalNameAccess > const & manager, 52*cdf0e10cSrcweir rtl::OUString const & name, Sequence< sal_Int8 > const & bytes, 53*cdf0e10cSrcweir sal_uInt16 index): 54*cdf0e10cSrcweir m_desc(manager, name, bytes, index) {} 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir virtual ~Constructor() {} 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir virtual sal_Bool SAL_CALL isDefaultConstructor() throw (RuntimeException) 59*cdf0e10cSrcweir { return m_desc.getName().getLength() == 0; } 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir virtual rtl::OUString SAL_CALL getName() throw (RuntimeException) 62*cdf0e10cSrcweir { return m_desc.getName(); } 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir virtual Sequence< Reference< XParameter > > SAL_CALL getParameters() 65*cdf0e10cSrcweir throw (RuntimeException) 66*cdf0e10cSrcweir { return m_desc.getParameters(); } 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir virtual Sequence< Reference<XCompoundTypeDescription > > SAL_CALL 69*cdf0e10cSrcweir getExceptions() throw (RuntimeException) 70*cdf0e10cSrcweir { return m_desc.getExceptions(); } 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir private: 73*cdf0e10cSrcweir Constructor(Constructor &); // not implemented 74*cdf0e10cSrcweir void operator =(Constructor); // not implemented 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir stoc::registry_tdprovider::MethodDescription m_desc; 77*cdf0e10cSrcweir }; 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir } 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir namespace stoc_rdbtdp 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir //================================================================================================== 85*cdf0e10cSrcweir // 86*cdf0e10cSrcweir // class PropertyTypeDescriptionImpl 87*cdf0e10cSrcweir // 88*cdf0e10cSrcweir //================================================================================================== 89*cdf0e10cSrcweir class PropertyTypeDescriptionImpl : public WeakImplHelper1< XPropertyTypeDescription > 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir OUString _aName; 92*cdf0e10cSrcweir Reference< XTypeDescription > _xTD; 93*cdf0e10cSrcweir sal_Int16 _nFlags; 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir public: 96*cdf0e10cSrcweir PropertyTypeDescriptionImpl( const OUString & rName, 97*cdf0e10cSrcweir const Reference< XTypeDescription > & xTD, 98*cdf0e10cSrcweir sal_Int16 nFlags ) 99*cdf0e10cSrcweir : _aName( rName ), _xTD( xTD ), _nFlags( nFlags ) 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir virtual ~PropertyTypeDescriptionImpl(); 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir // XTypeDescription 106*cdf0e10cSrcweir virtual TypeClass SAL_CALL getTypeClass() 107*cdf0e10cSrcweir throw( RuntimeException ); 108*cdf0e10cSrcweir virtual OUString SAL_CALL getName() 109*cdf0e10cSrcweir throw( RuntimeException ); 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir // XPropertyTypeDescription 112*cdf0e10cSrcweir virtual sal_Int16 SAL_CALL getPropertyFlags() 113*cdf0e10cSrcweir throw ( RuntimeException ); 114*cdf0e10cSrcweir virtual Reference< XTypeDescription > SAL_CALL getPropertyTypeDescription() 115*cdf0e10cSrcweir throw ( RuntimeException ); 116*cdf0e10cSrcweir }; 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir //__________________________________________________________________________________________________ 119*cdf0e10cSrcweir // virtual 120*cdf0e10cSrcweir PropertyTypeDescriptionImpl::~PropertyTypeDescriptionImpl() 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir // XTypeDescription 126*cdf0e10cSrcweir //__________________________________________________________________________________________________ 127*cdf0e10cSrcweir // virtual 128*cdf0e10cSrcweir TypeClass PropertyTypeDescriptionImpl::getTypeClass() 129*cdf0e10cSrcweir throw ( RuntimeException ) 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir return TypeClass_PROPERTY; 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir //__________________________________________________________________________________________________ 134*cdf0e10cSrcweir // virtual 135*cdf0e10cSrcweir OUString PropertyTypeDescriptionImpl::getName() 136*cdf0e10cSrcweir throw ( RuntimeException ) 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir return _aName; 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir // XPropertyTypeDescription 142*cdf0e10cSrcweir //__________________________________________________________________________________________________ 143*cdf0e10cSrcweir // virtual 144*cdf0e10cSrcweir sal_Int16 SAL_CALL PropertyTypeDescriptionImpl::getPropertyFlags() 145*cdf0e10cSrcweir throw ( RuntimeException ) 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir return _nFlags; 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir //__________________________________________________________________________________________________ 151*cdf0e10cSrcweir // virtual 152*cdf0e10cSrcweir Reference< XTypeDescription > SAL_CALL 153*cdf0e10cSrcweir PropertyTypeDescriptionImpl::getPropertyTypeDescription() 154*cdf0e10cSrcweir throw ( RuntimeException ) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir return _xTD; 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir //================================================================================================== 160*cdf0e10cSrcweir // 161*cdf0e10cSrcweir // ServiceTypeDescriptionImpl implementation 162*cdf0e10cSrcweir // 163*cdf0e10cSrcweir //================================================================================================== 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir //__________________________________________________________________________________________________ 166*cdf0e10cSrcweir // virtual 167*cdf0e10cSrcweir ServiceTypeDescriptionImpl::~ServiceTypeDescriptionImpl() 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir // XTypeDescription 173*cdf0e10cSrcweir //__________________________________________________________________________________________________ 174*cdf0e10cSrcweir // virtual 175*cdf0e10cSrcweir TypeClass ServiceTypeDescriptionImpl::getTypeClass() 176*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir return TypeClass_SERVICE; 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir //__________________________________________________________________________________________________ 181*cdf0e10cSrcweir // virtual 182*cdf0e10cSrcweir OUString ServiceTypeDescriptionImpl::getName() 183*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir return _aName; 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir // XServiceTypeDescription 189*cdf0e10cSrcweir //__________________________________________________________________________________________________ 190*cdf0e10cSrcweir // virtual 191*cdf0e10cSrcweir Sequence< Reference< XServiceTypeDescription > > SAL_CALL 192*cdf0e10cSrcweir ServiceTypeDescriptionImpl::getMandatoryServices() 193*cdf0e10cSrcweir throw ( RuntimeException ) 194*cdf0e10cSrcweir { 195*cdf0e10cSrcweir getReferences(); 196*cdf0e10cSrcweir return _aMandatoryServices; 197*cdf0e10cSrcweir } 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir //__________________________________________________________________________________________________ 200*cdf0e10cSrcweir // virtual 201*cdf0e10cSrcweir Sequence< Reference< XServiceTypeDescription > > SAL_CALL 202*cdf0e10cSrcweir ServiceTypeDescriptionImpl::getOptionalServices() 203*cdf0e10cSrcweir throw ( RuntimeException ) 204*cdf0e10cSrcweir { 205*cdf0e10cSrcweir getReferences(); 206*cdf0e10cSrcweir return _aOptionalServices; 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir //__________________________________________________________________________________________________ 210*cdf0e10cSrcweir // virtual 211*cdf0e10cSrcweir Sequence< Reference< XInterfaceTypeDescription > > SAL_CALL 212*cdf0e10cSrcweir ServiceTypeDescriptionImpl::getMandatoryInterfaces() 213*cdf0e10cSrcweir throw ( RuntimeException ) 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir getReferences(); 216*cdf0e10cSrcweir return _aMandatoryInterfaces; 217*cdf0e10cSrcweir } 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir //__________________________________________________________________________________________________ 220*cdf0e10cSrcweir // virtual 221*cdf0e10cSrcweir Sequence< Reference< XInterfaceTypeDescription > > SAL_CALL 222*cdf0e10cSrcweir ServiceTypeDescriptionImpl::getOptionalInterfaces() 223*cdf0e10cSrcweir throw ( RuntimeException ) 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir getReferences(); 226*cdf0e10cSrcweir return _aOptionalInterfaces; 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir //__________________________________________________________________________________________________ 230*cdf0e10cSrcweir // virtual 231*cdf0e10cSrcweir Sequence< Reference< XPropertyTypeDescription > > SAL_CALL 232*cdf0e10cSrcweir ServiceTypeDescriptionImpl::getProperties() 233*cdf0e10cSrcweir throw ( RuntimeException ) 234*cdf0e10cSrcweir { 235*cdf0e10cSrcweir { 236*cdf0e10cSrcweir MutexGuard guard(getMutex()); 237*cdf0e10cSrcweir if (_pProps.get() != 0) { 238*cdf0e10cSrcweir return *_pProps; 239*cdf0e10cSrcweir } 240*cdf0e10cSrcweir } 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir typereg::Reader aReader( 243*cdf0e10cSrcweir _aBytes.getConstArray(), _aBytes.getLength(), false, TYPEREG_VERSION_1); 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir sal_uInt16 nFields = (sal_uInt16)aReader.getFieldCount(); 246*cdf0e10cSrcweir std::auto_ptr< Sequence< Reference< XPropertyTypeDescription > > > 247*cdf0e10cSrcweir pTempProps( 248*cdf0e10cSrcweir new Sequence< Reference< XPropertyTypeDescription > >(nFields)); 249*cdf0e10cSrcweir Reference< XPropertyTypeDescription > * pProps = pTempProps->getArray(); 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir while ( nFields-- ) 252*cdf0e10cSrcweir { 253*cdf0e10cSrcweir // name 254*cdf0e10cSrcweir OUStringBuffer aName( _aName ); 255*cdf0e10cSrcweir aName.appendAscii( "." ); 256*cdf0e10cSrcweir aName.append( aReader.getFieldName( nFields ) ); 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir // type description 259*cdf0e10cSrcweir Reference< XTypeDescription > xTD; 260*cdf0e10cSrcweir try 261*cdf0e10cSrcweir { 262*cdf0e10cSrcweir _xTDMgr->getByHierarchicalName( 263*cdf0e10cSrcweir aReader.getFieldTypeName( nFields ).replace( '/', '.' ) ) 264*cdf0e10cSrcweir >>= xTD; 265*cdf0e10cSrcweir } 266*cdf0e10cSrcweir catch ( NoSuchElementException const & ) 267*cdf0e10cSrcweir { 268*cdf0e10cSrcweir } 269*cdf0e10cSrcweir OSL_ENSURE( xTD.is(), "### no type description for property!" ); 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir // flags 272*cdf0e10cSrcweir RTFieldAccess nFlags = aReader.getFieldFlags( nFields ); 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir sal_Int16 nAttribs = 0; 275*cdf0e10cSrcweir if ( nFlags & RT_ACCESS_READONLY ) 276*cdf0e10cSrcweir nAttribs |= beans::PropertyAttribute::READONLY; 277*cdf0e10cSrcweir if ( nFlags & RT_ACCESS_OPTIONAL ) 278*cdf0e10cSrcweir nAttribs |= beans::PropertyAttribute::OPTIONAL; 279*cdf0e10cSrcweir if ( nFlags & RT_ACCESS_MAYBEVOID ) 280*cdf0e10cSrcweir nAttribs |= beans::PropertyAttribute::MAYBEVOID; 281*cdf0e10cSrcweir if ( nFlags & RT_ACCESS_BOUND ) 282*cdf0e10cSrcweir nAttribs |= beans::PropertyAttribute::BOUND; 283*cdf0e10cSrcweir if ( nFlags & RT_ACCESS_CONSTRAINED ) 284*cdf0e10cSrcweir nAttribs |= beans::PropertyAttribute::CONSTRAINED; 285*cdf0e10cSrcweir if ( nFlags & RT_ACCESS_TRANSIENT ) 286*cdf0e10cSrcweir nAttribs |= beans::PropertyAttribute::TRANSIENT; 287*cdf0e10cSrcweir if ( nFlags & RT_ACCESS_MAYBEAMBIGUOUS ) 288*cdf0e10cSrcweir nAttribs |= beans::PropertyAttribute::MAYBEAMBIGUOUS; 289*cdf0e10cSrcweir if ( nFlags & RT_ACCESS_MAYBEDEFAULT ) 290*cdf0e10cSrcweir nAttribs |= beans::PropertyAttribute::MAYBEDEFAULT; 291*cdf0e10cSrcweir if ( nFlags & RT_ACCESS_REMOVEABLE ) 292*cdf0e10cSrcweir nAttribs |= beans::PropertyAttribute::REMOVEABLE; 293*cdf0e10cSrcweir 294*cdf0e10cSrcweir OSL_ENSURE( !(nFlags & RT_ACCESS_PROPERTY), 295*cdf0e10cSrcweir "### RT_ACCESS_PROPERTY is unexpected here!" ); 296*cdf0e10cSrcweir OSL_ENSURE( !(nFlags & RT_ACCESS_ATTRIBUTE), 297*cdf0e10cSrcweir "### RT_ACCESS_ATTRIBUTE is unexpected here!" ); 298*cdf0e10cSrcweir OSL_ENSURE( !(nFlags & RT_ACCESS_CONST), 299*cdf0e10cSrcweir "### RT_ACCESS_CONST is unexpected here!" ); 300*cdf0e10cSrcweir // always set, unless RT_ACCESS_READONLY is set. 301*cdf0e10cSrcweir //OSL_ENSURE( !(nFlags & RT_ACCESS_READWRITE), 302*cdf0e10cSrcweir // "### RT_ACCESS_READWRITE is unexpected here" ); 303*cdf0e10cSrcweir OSL_ENSURE( !(nFlags & RT_ACCESS_DEFAULT), 304*cdf0e10cSrcweir "### RT_ACCESS_DEAFAULT is unexpected here" ); 305*cdf0e10cSrcweir 306*cdf0e10cSrcweir pProps[ nFields ] 307*cdf0e10cSrcweir = new PropertyTypeDescriptionImpl( aName.makeStringAndClear(), 308*cdf0e10cSrcweir xTD, 309*cdf0e10cSrcweir nAttribs ); 310*cdf0e10cSrcweir } 311*cdf0e10cSrcweir 312*cdf0e10cSrcweir MutexGuard guard(getMutex()); 313*cdf0e10cSrcweir if (_pProps.get() == 0) { 314*cdf0e10cSrcweir _pProps = pTempProps; 315*cdf0e10cSrcweir } 316*cdf0e10cSrcweir return *_pProps; 317*cdf0e10cSrcweir } 318*cdf0e10cSrcweir 319*cdf0e10cSrcweir sal_Bool ServiceTypeDescriptionImpl::isSingleInterfaceBased() 320*cdf0e10cSrcweir throw (RuntimeException) 321*cdf0e10cSrcweir { 322*cdf0e10cSrcweir getReferences(); 323*cdf0e10cSrcweir return _xInterfaceTD.is(); 324*cdf0e10cSrcweir } 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir Reference< XTypeDescription > ServiceTypeDescriptionImpl::getInterface() 327*cdf0e10cSrcweir throw (RuntimeException) 328*cdf0e10cSrcweir { 329*cdf0e10cSrcweir getReferences(); 330*cdf0e10cSrcweir return _xInterfaceTD; 331*cdf0e10cSrcweir } 332*cdf0e10cSrcweir 333*cdf0e10cSrcweir Sequence< Reference< XServiceConstructorDescription > > 334*cdf0e10cSrcweir ServiceTypeDescriptionImpl::getConstructors() throw (RuntimeException) { 335*cdf0e10cSrcweir MutexGuard guard(getMutex()); 336*cdf0e10cSrcweir if (_pCtors.get() == 0) { 337*cdf0e10cSrcweir typereg::Reader reader( 338*cdf0e10cSrcweir _aBytes.getConstArray(), _aBytes.getLength(), false, 339*cdf0e10cSrcweir TYPEREG_VERSION_1); 340*cdf0e10cSrcweir sal_uInt16 ctorCount = reader.getMethodCount(); 341*cdf0e10cSrcweir std::auto_ptr< Sequence< Reference< XServiceConstructorDescription > > > 342*cdf0e10cSrcweir ctors( 343*cdf0e10cSrcweir new Sequence< Reference< XServiceConstructorDescription > >( 344*cdf0e10cSrcweir ctorCount)); 345*cdf0e10cSrcweir for (sal_uInt16 i = 0; i < ctorCount; ++i) { 346*cdf0e10cSrcweir rtl::OUString name(reader.getMethodName(i)); 347*cdf0e10cSrcweir if (reader.getMethodFlags(i) != RT_MODE_TWOWAY 348*cdf0e10cSrcweir || (!reader.getMethodReturnTypeName(i).equalsAsciiL( 349*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("void"))) 350*cdf0e10cSrcweir || (name.getLength() == 0 351*cdf0e10cSrcweir && (ctorCount != 1 || reader.getMethodParameterCount(i) != 0 352*cdf0e10cSrcweir || reader.getMethodExceptionCount(i) != 0))) 353*cdf0e10cSrcweir { 354*cdf0e10cSrcweir throw RuntimeException( 355*cdf0e10cSrcweir rtl::OUString( 356*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( 357*cdf0e10cSrcweir "Service has bad constructors")), 358*cdf0e10cSrcweir static_cast< OWeakObject * >(this)); 359*cdf0e10cSrcweir } 360*cdf0e10cSrcweir (*ctors)[i] = new Constructor( 361*cdf0e10cSrcweir _xTDMgr, reader.getMethodName(i), _aBytes, i); 362*cdf0e10cSrcweir } 363*cdf0e10cSrcweir _pCtors = ctors; 364*cdf0e10cSrcweir } 365*cdf0e10cSrcweir return *_pCtors; 366*cdf0e10cSrcweir } 367*cdf0e10cSrcweir 368*cdf0e10cSrcweir //__________________________________________________________________________________________________ 369*cdf0e10cSrcweir void ServiceTypeDescriptionImpl::getReferences() 370*cdf0e10cSrcweir throw ( RuntimeException ) 371*cdf0e10cSrcweir { 372*cdf0e10cSrcweir { 373*cdf0e10cSrcweir MutexGuard guard(getMutex()); 374*cdf0e10cSrcweir if (_bInitReferences) { 375*cdf0e10cSrcweir return; 376*cdf0e10cSrcweir } 377*cdf0e10cSrcweir } 378*cdf0e10cSrcweir typereg::Reader aReader( 379*cdf0e10cSrcweir _aBytes.getConstArray(), _aBytes.getLength(), false, TYPEREG_VERSION_1); 380*cdf0e10cSrcweir sal_uInt16 superTypes = aReader.getSuperTypeCount(); 381*cdf0e10cSrcweir if (superTypes > 1) { 382*cdf0e10cSrcweir throw RuntimeException( 383*cdf0e10cSrcweir rtl::OUString( 384*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( 385*cdf0e10cSrcweir "Service has more than one supertype")), 386*cdf0e10cSrcweir static_cast< OWeakObject * >(this)); 387*cdf0e10cSrcweir } 388*cdf0e10cSrcweir if (superTypes == 1) { 389*cdf0e10cSrcweir OUString aBaseName( aReader.getSuperTypeName(0).replace( '/', '.' ) ); 390*cdf0e10cSrcweir if ( aReader.getReferenceCount() != 0 391*cdf0e10cSrcweir || aReader.getFieldCount() != 0 ) 392*cdf0e10cSrcweir throw RuntimeException( 393*cdf0e10cSrcweir OUString( 394*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( 395*cdf0e10cSrcweir "Service is single-interface--based but also has" 396*cdf0e10cSrcweir " references and/or properties" ) ), 397*cdf0e10cSrcweir static_cast< OWeakObject * >( this ) ); 398*cdf0e10cSrcweir Reference< XTypeDescription > ifc; 399*cdf0e10cSrcweir try 400*cdf0e10cSrcweir { 401*cdf0e10cSrcweir _xTDMgr->getByHierarchicalName( aBaseName ) >>= ifc; 402*cdf0e10cSrcweir } 403*cdf0e10cSrcweir catch ( NoSuchElementException const & e ) 404*cdf0e10cSrcweir { 405*cdf0e10cSrcweir throw RuntimeException( 406*cdf0e10cSrcweir OUString( 407*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( 408*cdf0e10cSrcweir "com.sun.star.container.NoSuchElementException: " ) ) 409*cdf0e10cSrcweir + e.Message, 410*cdf0e10cSrcweir static_cast< OWeakObject * >( this ) ); 411*cdf0e10cSrcweir } 412*cdf0e10cSrcweir OSL_ASSERT(ifc.is()); 413*cdf0e10cSrcweir if (resolveTypedefs(ifc)->getTypeClass() != TypeClass_INTERFACE) { 414*cdf0e10cSrcweir throw RuntimeException( 415*cdf0e10cSrcweir OUString( 416*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( 417*cdf0e10cSrcweir "Single-interface--based service is not based on" 418*cdf0e10cSrcweir " interface type" ) ), 419*cdf0e10cSrcweir static_cast< OWeakObject * >( this ) ); 420*cdf0e10cSrcweir } 421*cdf0e10cSrcweir MutexGuard guard(getMutex()); 422*cdf0e10cSrcweir if (!_bInitReferences) { 423*cdf0e10cSrcweir _xInterfaceTD = ifc; 424*cdf0e10cSrcweir _bInitReferences = true; 425*cdf0e10cSrcweir } 426*cdf0e10cSrcweir } 427*cdf0e10cSrcweir else 428*cdf0e10cSrcweir { 429*cdf0e10cSrcweir sal_uInt16 nRefs = aReader.getReferenceCount(); 430*cdf0e10cSrcweir Sequence< Reference< XServiceTypeDescription > > aMandatoryServices( 431*cdf0e10cSrcweir nRefs); 432*cdf0e10cSrcweir Sequence< Reference< XServiceTypeDescription > > aOptionalServices( 433*cdf0e10cSrcweir nRefs); 434*cdf0e10cSrcweir Sequence< Reference< XInterfaceTypeDescription > > aMandatoryInterfaces( 435*cdf0e10cSrcweir nRefs); 436*cdf0e10cSrcweir Sequence< Reference< XInterfaceTypeDescription > > aOptionalInterfaces( 437*cdf0e10cSrcweir nRefs); 438*cdf0e10cSrcweir sal_uInt32 nMS = 0; 439*cdf0e10cSrcweir sal_uInt32 nOS = 0; 440*cdf0e10cSrcweir sal_uInt32 nMI = 0; 441*cdf0e10cSrcweir sal_uInt32 nOI = 0; 442*cdf0e10cSrcweir 443*cdf0e10cSrcweir for ( sal_uInt16 nPos = 0; nPos < nRefs; ++nPos ) 444*cdf0e10cSrcweir { 445*cdf0e10cSrcweir RTReferenceType eType = aReader.getReferenceSort( nPos ); 446*cdf0e10cSrcweir switch ( eType ) 447*cdf0e10cSrcweir { 448*cdf0e10cSrcweir case RT_REF_EXPORTS: // service 449*cdf0e10cSrcweir { 450*cdf0e10cSrcweir uno::Any aTypeDesc; 451*cdf0e10cSrcweir try 452*cdf0e10cSrcweir { 453*cdf0e10cSrcweir aTypeDesc = _xTDMgr->getByHierarchicalName( 454*cdf0e10cSrcweir aReader.getReferenceTypeName( nPos ).replace( 455*cdf0e10cSrcweir '/', '.' ) ); 456*cdf0e10cSrcweir } 457*cdf0e10cSrcweir catch ( NoSuchElementException const & e ) 458*cdf0e10cSrcweir { 459*cdf0e10cSrcweir throw RuntimeException( 460*cdf0e10cSrcweir OUString( 461*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( 462*cdf0e10cSrcweir "com.sun.star.container." 463*cdf0e10cSrcweir "NoSuchElementException: " ) ) 464*cdf0e10cSrcweir + e.Message, 465*cdf0e10cSrcweir static_cast< OWeakObject * >( this ) ); 466*cdf0e10cSrcweir } 467*cdf0e10cSrcweir 468*cdf0e10cSrcweir RTFieldAccess nAccess = aReader.getReferenceFlags( nPos ); 469*cdf0e10cSrcweir if ( nAccess & RT_ACCESS_OPTIONAL ) 470*cdf0e10cSrcweir { 471*cdf0e10cSrcweir // optional service 472*cdf0e10cSrcweir if ( !( aTypeDesc >>= aOptionalServices[ nOS ] ) ) 473*cdf0e10cSrcweir throw RuntimeException( 474*cdf0e10cSrcweir OUString( 475*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( 476*cdf0e10cSrcweir "Service 'export' is not a service" ) ), 477*cdf0e10cSrcweir static_cast< OWeakObject * >( this ) ); 478*cdf0e10cSrcweir nOS++; 479*cdf0e10cSrcweir } 480*cdf0e10cSrcweir else 481*cdf0e10cSrcweir { 482*cdf0e10cSrcweir // mandatory service 483*cdf0e10cSrcweir if ( !( aTypeDesc >>= aMandatoryServices[ nMS ] ) ) 484*cdf0e10cSrcweir throw RuntimeException( 485*cdf0e10cSrcweir OUString( 486*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( 487*cdf0e10cSrcweir "Service 'export' is not a service" ) ), 488*cdf0e10cSrcweir static_cast< OWeakObject * >( this ) ); 489*cdf0e10cSrcweir nMS++; 490*cdf0e10cSrcweir } 491*cdf0e10cSrcweir break; 492*cdf0e10cSrcweir } 493*cdf0e10cSrcweir case RT_REF_SUPPORTS: // interface 494*cdf0e10cSrcweir { 495*cdf0e10cSrcweir uno::Any aTypeDesc; 496*cdf0e10cSrcweir try 497*cdf0e10cSrcweir { 498*cdf0e10cSrcweir aTypeDesc = _xTDMgr->getByHierarchicalName( 499*cdf0e10cSrcweir aReader.getReferenceTypeName( nPos ).replace( 500*cdf0e10cSrcweir '/', '.' ) ); 501*cdf0e10cSrcweir } 502*cdf0e10cSrcweir catch ( NoSuchElementException const & e ) 503*cdf0e10cSrcweir { 504*cdf0e10cSrcweir throw RuntimeException( 505*cdf0e10cSrcweir OUString( 506*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( 507*cdf0e10cSrcweir "com.sun.star.container." 508*cdf0e10cSrcweir "NoSuchElementException: " ) ) 509*cdf0e10cSrcweir + e.Message, 510*cdf0e10cSrcweir static_cast< OWeakObject * >( this ) ); 511*cdf0e10cSrcweir } 512*cdf0e10cSrcweir 513*cdf0e10cSrcweir RTFieldAccess nAccess = aReader.getReferenceFlags( nPos ); 514*cdf0e10cSrcweir if ( nAccess & RT_ACCESS_OPTIONAL ) 515*cdf0e10cSrcweir { 516*cdf0e10cSrcweir // optional interface 517*cdf0e10cSrcweir if ( !( aTypeDesc >>= aOptionalInterfaces[ nOI ] ) ) 518*cdf0e10cSrcweir throw RuntimeException( 519*cdf0e10cSrcweir OUString( 520*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( 521*cdf0e10cSrcweir "Service 'supports' is not an" 522*cdf0e10cSrcweir " interface" ) ), 523*cdf0e10cSrcweir static_cast< OWeakObject * >( this ) ); 524*cdf0e10cSrcweir nOI++; 525*cdf0e10cSrcweir } 526*cdf0e10cSrcweir else 527*cdf0e10cSrcweir { 528*cdf0e10cSrcweir // mandatory interface 529*cdf0e10cSrcweir if ( !( aTypeDesc >>= aMandatoryInterfaces[ nMI ] ) ) 530*cdf0e10cSrcweir throw RuntimeException( 531*cdf0e10cSrcweir OUString( 532*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( 533*cdf0e10cSrcweir "Service 'supports' is not an" 534*cdf0e10cSrcweir " interface" ) ), 535*cdf0e10cSrcweir static_cast< OWeakObject * >( this ) ); 536*cdf0e10cSrcweir nMI++; 537*cdf0e10cSrcweir } 538*cdf0e10cSrcweir break; 539*cdf0e10cSrcweir } 540*cdf0e10cSrcweir case RT_REF_OBSERVES: 541*cdf0e10cSrcweir case RT_REF_NEEDS: 542*cdf0e10cSrcweir break; 543*cdf0e10cSrcweir default: 544*cdf0e10cSrcweir OSL_ENSURE( sal_False, "### unsupported reference type!" ); 545*cdf0e10cSrcweir break; 546*cdf0e10cSrcweir } 547*cdf0e10cSrcweir } 548*cdf0e10cSrcweir aMandatoryServices.realloc( nMS ); 549*cdf0e10cSrcweir aOptionalServices.realloc( nOS ); 550*cdf0e10cSrcweir aMandatoryInterfaces.realloc( nMI ); 551*cdf0e10cSrcweir aOptionalInterfaces.realloc( nOI ); 552*cdf0e10cSrcweir 553*cdf0e10cSrcweir MutexGuard guard(getMutex()); 554*cdf0e10cSrcweir if (!_bInitReferences) { 555*cdf0e10cSrcweir _aMandatoryServices = aMandatoryServices; 556*cdf0e10cSrcweir _aOptionalServices = aOptionalServices; 557*cdf0e10cSrcweir _aMandatoryInterfaces = aMandatoryInterfaces; 558*cdf0e10cSrcweir _aOptionalInterfaces = aOptionalInterfaces; 559*cdf0e10cSrcweir _bInitReferences = true; 560*cdf0e10cSrcweir } 561*cdf0e10cSrcweir } 562*cdf0e10cSrcweir } 563*cdf0e10cSrcweir 564*cdf0e10cSrcweir 565*cdf0e10cSrcweir } 566