1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tdsingleton.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_stoc.hxx"
33 #include <osl/diagnose.h>
36 #include "com/sun/star/uno/RuntimeException.hpp"
38 using namespace com::sun::star
;
43 void SingletonTypeDescriptionImpl::init() {
45 MutexGuard
guard(getMutex());
46 if (_xInterfaceTD
.is() || _xServiceTD
.is()) {
50 Reference
< XTypeDescription
> base
;
52 base
= Reference
< XTypeDescription
>(
53 _xTDMgr
->getByHierarchicalName(_aBaseName
), UNO_QUERY_THROW
);
54 } catch (NoSuchElementException
const & e
) {
55 throw RuntimeException(
57 RTL_CONSTASCII_USTRINGPARAM(
58 "com.sun.star.container.NoSuchElementException: "))
60 static_cast< OWeakObject
* >(this));
62 MutexGuard
guard(getMutex());
63 if (!_xInterfaceTD
.is() && !_xServiceTD
.is()) {
64 if (resolveTypedefs(base
)->getTypeClass() == TypeClass_INTERFACE
) {
66 } else if (base
->getTypeClass() == TypeClass_SERVICE
) {
67 _xServiceTD
= Reference
< XServiceTypeDescription
>(
68 base
, UNO_QUERY_THROW
);
70 throw RuntimeException(
72 RTL_CONSTASCII_USTRINGPARAM(
73 "Singleton is based on neither interface nor service")),
74 static_cast< OWeakObject
* >(this));
77 OSL_ASSERT(_xInterfaceTD
.is() ^ _xServiceTD
.is());
80 //__________________________________________________________________________________________________
82 SingletonTypeDescriptionImpl::~SingletonTypeDescriptionImpl()
84 g_moduleCount
.modCnt
.release( &g_moduleCount
.modCnt
);
88 //__________________________________________________________________________________________________
90 TypeClass
SingletonTypeDescriptionImpl::getTypeClass()
91 throw(::com::sun::star::uno::RuntimeException
)
93 return TypeClass_SINGLETON
;
95 //__________________________________________________________________________________________________
97 OUString
SingletonTypeDescriptionImpl::getName()
98 throw(::com::sun::star::uno::RuntimeException
)
103 // XSingletonTypeDescription
104 //__________________________________________________________________________________________________
106 Reference
< XServiceTypeDescription
> SAL_CALL
107 SingletonTypeDescriptionImpl::getService()
108 throw(::com::sun::star::uno::RuntimeException
)
114 // XSingletonTypeDescription2
115 //______________________________________________________________________________
118 SingletonTypeDescriptionImpl::isInterfaceBased()
119 throw(::com::sun::star::uno::RuntimeException
)
122 return _xInterfaceTD
.is();
125 //______________________________________________________________________________
127 Reference
< XTypeDescription
> SAL_CALL
128 SingletonTypeDescriptionImpl::getInterface()
129 throw(::com::sun::star::uno::RuntimeException
)
132 return _xInterfaceTD
;