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 "base.hxx" 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp" 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir using namespace com::sun::star; 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir namespace stoc_rdbtdp 38*cdf0e10cSrcweir { 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir void SingletonTypeDescriptionImpl::init() { 41*cdf0e10cSrcweir { 42*cdf0e10cSrcweir MutexGuard guard(getMutex()); 43*cdf0e10cSrcweir if (_xInterfaceTD.is() || _xServiceTD.is()) { 44*cdf0e10cSrcweir return; 45*cdf0e10cSrcweir } 46*cdf0e10cSrcweir } 47*cdf0e10cSrcweir Reference< XTypeDescription > base; 48*cdf0e10cSrcweir try { 49*cdf0e10cSrcweir base = Reference< XTypeDescription >( 50*cdf0e10cSrcweir _xTDMgr->getByHierarchicalName(_aBaseName), UNO_QUERY_THROW); 51*cdf0e10cSrcweir } catch (NoSuchElementException const & e) { 52*cdf0e10cSrcweir throw RuntimeException( 53*cdf0e10cSrcweir (OUString( 54*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( 55*cdf0e10cSrcweir "com.sun.star.container.NoSuchElementException: ")) 56*cdf0e10cSrcweir + e.Message), 57*cdf0e10cSrcweir static_cast< OWeakObject * >(this)); 58*cdf0e10cSrcweir } 59*cdf0e10cSrcweir MutexGuard guard(getMutex()); 60*cdf0e10cSrcweir if (!_xInterfaceTD.is() && !_xServiceTD.is()) { 61*cdf0e10cSrcweir if (resolveTypedefs(base)->getTypeClass() == TypeClass_INTERFACE) { 62*cdf0e10cSrcweir _xInterfaceTD = base; 63*cdf0e10cSrcweir } else if (base->getTypeClass() == TypeClass_SERVICE) { 64*cdf0e10cSrcweir _xServiceTD = Reference< XServiceTypeDescription >( 65*cdf0e10cSrcweir base, UNO_QUERY_THROW); 66*cdf0e10cSrcweir } else { 67*cdf0e10cSrcweir throw RuntimeException( 68*cdf0e10cSrcweir OUString( 69*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( 70*cdf0e10cSrcweir "Singleton is based on neither interface nor service")), 71*cdf0e10cSrcweir static_cast< OWeakObject * >(this)); 72*cdf0e10cSrcweir } 73*cdf0e10cSrcweir } 74*cdf0e10cSrcweir OSL_ASSERT(_xInterfaceTD.is() ^ _xServiceTD.is()); 75*cdf0e10cSrcweir } 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir //__________________________________________________________________________________________________ 78*cdf0e10cSrcweir // virtual 79*cdf0e10cSrcweir SingletonTypeDescriptionImpl::~SingletonTypeDescriptionImpl() 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); 82*cdf0e10cSrcweir } 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir // XTypeDescription 85*cdf0e10cSrcweir //__________________________________________________________________________________________________ 86*cdf0e10cSrcweir // virtual 87*cdf0e10cSrcweir TypeClass SingletonTypeDescriptionImpl::getTypeClass() 88*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 89*cdf0e10cSrcweir { 90*cdf0e10cSrcweir return TypeClass_SINGLETON; 91*cdf0e10cSrcweir } 92*cdf0e10cSrcweir //__________________________________________________________________________________________________ 93*cdf0e10cSrcweir // virtual 94*cdf0e10cSrcweir OUString SingletonTypeDescriptionImpl::getName() 95*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 96*cdf0e10cSrcweir { 97*cdf0e10cSrcweir return _aName; 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir // XSingletonTypeDescription 101*cdf0e10cSrcweir //__________________________________________________________________________________________________ 102*cdf0e10cSrcweir // virtual 103*cdf0e10cSrcweir Reference< XServiceTypeDescription > SAL_CALL 104*cdf0e10cSrcweir SingletonTypeDescriptionImpl::getService() 105*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir init(); 108*cdf0e10cSrcweir return _xServiceTD; 109*cdf0e10cSrcweir } 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir // XSingletonTypeDescription2 112*cdf0e10cSrcweir //______________________________________________________________________________ 113*cdf0e10cSrcweir // virtual 114*cdf0e10cSrcweir sal_Bool SAL_CALL 115*cdf0e10cSrcweir SingletonTypeDescriptionImpl::isInterfaceBased() 116*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir init(); 119*cdf0e10cSrcweir return _xInterfaceTD.is(); 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir //______________________________________________________________________________ 123*cdf0e10cSrcweir // virtual 124*cdf0e10cSrcweir Reference< XTypeDescription > SAL_CALL 125*cdf0e10cSrcweir SingletonTypeDescriptionImpl::getInterface() 126*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir init(); 129*cdf0e10cSrcweir return _xInterfaceTD; 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir } 133