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 <cppuhelper/queryinterface.hxx> 31*cdf0e10cSrcweir #include <uno/any2.h> 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include "base.hxx" 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir namespace stoc_corefl 36*cdf0e10cSrcweir { 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #ifdef TEST_LIST_CLASSES 39*cdf0e10cSrcweir ClassNameList g_aClassNames; 40*cdf0e10cSrcweir #endif 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir //-------------------------------------------------------------------------------------------------- 43*cdf0e10cSrcweir Mutex & getMutexAccess() 44*cdf0e10cSrcweir { 45*cdf0e10cSrcweir static Mutex * s_pMutex = 0; 46*cdf0e10cSrcweir if (! s_pMutex) 47*cdf0e10cSrcweir { 48*cdf0e10cSrcweir MutexGuard aGuard( Mutex::getGlobalMutex() ); 49*cdf0e10cSrcweir if (! s_pMutex) 50*cdf0e10cSrcweir { 51*cdf0e10cSrcweir static Mutex s_aMutex; 52*cdf0e10cSrcweir s_pMutex = &s_aMutex; 53*cdf0e10cSrcweir } 54*cdf0e10cSrcweir } 55*cdf0e10cSrcweir return *s_pMutex; 56*cdf0e10cSrcweir } 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir //__________________________________________________________________________________________________ 59*cdf0e10cSrcweir IdlClassImpl::IdlClassImpl( IdlReflectionServiceImpl * pReflection, 60*cdf0e10cSrcweir const OUString & rName, typelib_TypeClass eTypeClass, 61*cdf0e10cSrcweir typelib_TypeDescription * pTypeDescr ) 62*cdf0e10cSrcweir : _pReflection( pReflection ) 63*cdf0e10cSrcweir , _aName( rName ) 64*cdf0e10cSrcweir , _eTypeClass( (TypeClass)eTypeClass ) 65*cdf0e10cSrcweir , _pTypeDescr( pTypeDescr ) 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir if (_pReflection) 68*cdf0e10cSrcweir _pReflection->acquire(); 69*cdf0e10cSrcweir if (_pTypeDescr) 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir typelib_typedescription_acquire( _pTypeDescr ); 72*cdf0e10cSrcweir if (! _pTypeDescr->bComplete) 73*cdf0e10cSrcweir typelib_typedescription_complete( &_pTypeDescr ); 74*cdf0e10cSrcweir } 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir #ifdef TEST_LIST_CLASSES 77*cdf0e10cSrcweir ClassNameList::const_iterator iFind( find( g_aClassNames.begin(), g_aClassNames.end(), _aName ) ); 78*cdf0e10cSrcweir OSL_ENSURE( iFind == g_aClassNames.end(), "### idl class already exists!" ); 79*cdf0e10cSrcweir g_aClassNames.push_front( _aName ); 80*cdf0e10cSrcweir #endif 81*cdf0e10cSrcweir } 82*cdf0e10cSrcweir //__________________________________________________________________________________________________ 83*cdf0e10cSrcweir IdlClassImpl::~IdlClassImpl() 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir if (_pTypeDescr) 86*cdf0e10cSrcweir typelib_typedescription_release( _pTypeDescr ); 87*cdf0e10cSrcweir if (_pReflection) 88*cdf0e10cSrcweir _pReflection->release(); 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir #ifdef TEST_LIST_CLASSES 91*cdf0e10cSrcweir ClassNameList::iterator iFind( find( g_aClassNames.begin(), g_aClassNames.end(), _aName ) ); 92*cdf0e10cSrcweir OSL_ENSURE( iFind != g_aClassNames.end(), "### idl class does not exist!" ); 93*cdf0e10cSrcweir g_aClassNames.erase( iFind ); 94*cdf0e10cSrcweir #endif 95*cdf0e10cSrcweir } 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir // XIdlClassImpl default implementation 98*cdf0e10cSrcweir //__________________________________________________________________________________________________ 99*cdf0e10cSrcweir TypeClass IdlClassImpl::getTypeClass() 100*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir return _eTypeClass; 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir //__________________________________________________________________________________________________ 105*cdf0e10cSrcweir OUString IdlClassImpl::getName() 106*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir return _aName; 109*cdf0e10cSrcweir } 110*cdf0e10cSrcweir //__________________________________________________________________________________________________ 111*cdf0e10cSrcweir sal_Bool IdlClassImpl::equals( const Reference< XIdlClass >& xType ) 112*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir return (xType.is() && 115*cdf0e10cSrcweir (xType->getTypeClass() == _eTypeClass) && (xType->getName() == _aName)); 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir static sal_Bool s_aAssignableFromTab[11][11] = 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir /* from CH,BO,BY,SH,US,LO,UL,HY,UH,FL,DO */ 121*cdf0e10cSrcweir /* TypeClass_CHAR */ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 122*cdf0e10cSrcweir /* TypeClass_BOOLEAN */ { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 123*cdf0e10cSrcweir /* TypeClass_BYTE */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 }, 124*cdf0e10cSrcweir /* TypeClass_SHORT */ { 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0 }, 125*cdf0e10cSrcweir /* TypeClass_UNSIGNED_SHORT */ { 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0 }, 126*cdf0e10cSrcweir /* TypeClass_LONG */ { 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0 }, 127*cdf0e10cSrcweir /* TypeClass_UNSIGNED_LONG */ { 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0 }, 128*cdf0e10cSrcweir /* TypeClass_HYPER */ { 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0 }, 129*cdf0e10cSrcweir /* TypeClass_UNSIGNED_HYPER */ { 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0 }, 130*cdf0e10cSrcweir /* TypeClass_FLOAT */ { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0 }, 131*cdf0e10cSrcweir /* TypeClass_DOUBLE */ { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 } 132*cdf0e10cSrcweir }; 133*cdf0e10cSrcweir //__________________________________________________________________________________________________ 134*cdf0e10cSrcweir sal_Bool IdlClassImpl::isAssignableFrom( const Reference< XIdlClass > & xType ) 135*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 136*cdf0e10cSrcweir { 137*cdf0e10cSrcweir TypeClass eAssign = getTypeClass(); 138*cdf0e10cSrcweir if (equals( xType ) || eAssign == TypeClass_ANY) // default shot 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir return sal_True; 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir else 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir TypeClass eFrom = xType->getTypeClass(); 145*cdf0e10cSrcweir if (eAssign > TypeClass_VOID && eAssign < TypeClass_STRING && 146*cdf0e10cSrcweir eFrom > TypeClass_VOID && eFrom < TypeClass_STRING) 147*cdf0e10cSrcweir { 148*cdf0e10cSrcweir return s_aAssignableFromTab[eAssign-1][eFrom-1]; 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir return sal_False; 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir //__________________________________________________________________________________________________ 154*cdf0e10cSrcweir void IdlClassImpl::createObject( Any & rObj ) 155*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 156*cdf0e10cSrcweir { 157*cdf0e10cSrcweir rObj.clear(); 158*cdf0e10cSrcweir uno_any_destruct( &rObj, reinterpret_cast< uno_ReleaseFunc >(cpp_release) ); 159*cdf0e10cSrcweir uno_any_construct( &rObj, 0, getTypeDescr(), 0 ); 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir // what TODO ???? 163*cdf0e10cSrcweir //__________________________________________________________________________________________________ 164*cdf0e10cSrcweir Sequence< Reference< XIdlClass > > IdlClassImpl::getClasses() 165*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir OSL_ENSURE( sal_False, "### unexpected use!" ); 168*cdf0e10cSrcweir return Sequence< Reference< XIdlClass > >(); 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir //__________________________________________________________________________________________________ 171*cdf0e10cSrcweir Reference< XIdlClass > IdlClassImpl::getClass( const OUString & ) 172*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir OSL_ENSURE( sal_False, "### unexpected use!" ); 175*cdf0e10cSrcweir return Reference< XIdlClass >(); 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir //__________________________________________________________________________________________________ 178*cdf0e10cSrcweir Sequence< Reference< XIdlClass > > IdlClassImpl::getInterfaces() 179*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir // OSL_ENSURE( sal_False, "### unexpected use!" ); 182*cdf0e10cSrcweir return Sequence< Reference< XIdlClass > >(); 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir // structs, interfaces 186*cdf0e10cSrcweir //__________________________________________________________________________________________________ 187*cdf0e10cSrcweir Sequence< Reference< XIdlClass > > IdlClassImpl::getSuperclasses() throw(::com::sun::star::uno::RuntimeException) 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir return Sequence< Reference< XIdlClass > >(); 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir // structs 192*cdf0e10cSrcweir //__________________________________________________________________________________________________ 193*cdf0e10cSrcweir Reference< XIdlField > IdlClassImpl::getField( const OUString & ) 194*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 195*cdf0e10cSrcweir { 196*cdf0e10cSrcweir return Reference< XIdlField >(); 197*cdf0e10cSrcweir } 198*cdf0e10cSrcweir //__________________________________________________________________________________________________ 199*cdf0e10cSrcweir Sequence< Reference< XIdlField > > IdlClassImpl::getFields() 200*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir return Sequence< Reference< XIdlField > >(); 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir // interfaces 205*cdf0e10cSrcweir //__________________________________________________________________________________________________ 206*cdf0e10cSrcweir Uik IdlClassImpl::getUik() 207*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 208*cdf0e10cSrcweir { 209*cdf0e10cSrcweir return Uik(); 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir //__________________________________________________________________________________________________ 212*cdf0e10cSrcweir Reference< XIdlMethod > IdlClassImpl::getMethod( const OUString & ) 213*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir return Reference< XIdlMethod >(); 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir //__________________________________________________________________________________________________ 218*cdf0e10cSrcweir Sequence< Reference< XIdlMethod > > IdlClassImpl::getMethods() 219*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 220*cdf0e10cSrcweir { 221*cdf0e10cSrcweir return Sequence< Reference< XIdlMethod > >(); 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir // array 224*cdf0e10cSrcweir //__________________________________________________________________________________________________ 225*cdf0e10cSrcweir Reference< XIdlClass > IdlClassImpl::getComponentType() 226*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 227*cdf0e10cSrcweir { 228*cdf0e10cSrcweir return Reference< XIdlClass >(); 229*cdf0e10cSrcweir } 230*cdf0e10cSrcweir //__________________________________________________________________________________________________ 231*cdf0e10cSrcweir Reference< XIdlArray > IdlClassImpl::getArray() 232*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 233*cdf0e10cSrcweir { 234*cdf0e10cSrcweir return Reference< XIdlArray >(); 235*cdf0e10cSrcweir } 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir //################################################################################################## 239*cdf0e10cSrcweir //################################################################################################## 240*cdf0e10cSrcweir //################################################################################################## 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir //__________________________________________________________________________________________________ 244*cdf0e10cSrcweir IdlMemberImpl::IdlMemberImpl( IdlReflectionServiceImpl * pReflection, const OUString & rName, 245*cdf0e10cSrcweir typelib_TypeDescription * pTypeDescr, 246*cdf0e10cSrcweir typelib_TypeDescription * pDeclTypeDescr ) 247*cdf0e10cSrcweir : _pReflection( pReflection ) 248*cdf0e10cSrcweir , _aName( rName ) 249*cdf0e10cSrcweir , _pTypeDescr( pTypeDescr ) 250*cdf0e10cSrcweir , _pDeclTypeDescr( pDeclTypeDescr ) 251*cdf0e10cSrcweir { 252*cdf0e10cSrcweir _pReflection->acquire(); 253*cdf0e10cSrcweir typelib_typedescription_acquire( _pTypeDescr ); 254*cdf0e10cSrcweir if (! _pTypeDescr->bComplete) 255*cdf0e10cSrcweir typelib_typedescription_complete( &_pTypeDescr ); 256*cdf0e10cSrcweir typelib_typedescription_acquire( _pDeclTypeDescr ); 257*cdf0e10cSrcweir if (! _pDeclTypeDescr->bComplete) 258*cdf0e10cSrcweir typelib_typedescription_complete( &_pDeclTypeDescr ); 259*cdf0e10cSrcweir } 260*cdf0e10cSrcweir //__________________________________________________________________________________________________ 261*cdf0e10cSrcweir IdlMemberImpl::~IdlMemberImpl() 262*cdf0e10cSrcweir { 263*cdf0e10cSrcweir typelib_typedescription_release( _pDeclTypeDescr ); 264*cdf0e10cSrcweir typelib_typedescription_release( _pTypeDescr ); 265*cdf0e10cSrcweir _pReflection->release(); 266*cdf0e10cSrcweir } 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir // XIdlMember 269*cdf0e10cSrcweir //__________________________________________________________________________________________________ 270*cdf0e10cSrcweir Reference< XIdlClass > IdlMemberImpl::getDeclaringClass() 271*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 272*cdf0e10cSrcweir { 273*cdf0e10cSrcweir if (! _xDeclClass.is()) 274*cdf0e10cSrcweir { 275*cdf0e10cSrcweir Reference< XIdlClass > xDeclClass( getReflection()->forType( getDeclTypeDescr() ) ); 276*cdf0e10cSrcweir MutexGuard aGuard( getMutexAccess() ); 277*cdf0e10cSrcweir if (! _xDeclClass.is()) 278*cdf0e10cSrcweir _xDeclClass = xDeclClass; 279*cdf0e10cSrcweir } 280*cdf0e10cSrcweir return _xDeclClass; 281*cdf0e10cSrcweir } 282*cdf0e10cSrcweir //__________________________________________________________________________________________________ 283*cdf0e10cSrcweir OUString IdlMemberImpl::getName() 284*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 285*cdf0e10cSrcweir { 286*cdf0e10cSrcweir return _aName; 287*cdf0e10cSrcweir } 288*cdf0e10cSrcweir 289*cdf0e10cSrcweir } 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir 292