update dev300-m58
[ooovba.git] / stoc / source / registry_tdprovider / tdsingleton.cxx
blob3b4ce1899680aedd20630c89e4184f5b81148b7f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tdsingleton.cxx,v $
10 * $Revision: 1.7 $
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>
34 #include "base.hxx"
36 #include "com/sun/star/uno/RuntimeException.hpp"
38 using namespace com::sun::star;
40 namespace stoc_rdbtdp
43 void SingletonTypeDescriptionImpl::init() {
45 MutexGuard guard(getMutex());
46 if (_xInterfaceTD.is() || _xServiceTD.is()) {
47 return;
50 Reference< XTypeDescription > base;
51 try {
52 base = Reference< XTypeDescription >(
53 _xTDMgr->getByHierarchicalName(_aBaseName), UNO_QUERY_THROW);
54 } catch (NoSuchElementException const & e) {
55 throw RuntimeException(
56 (OUString(
57 RTL_CONSTASCII_USTRINGPARAM(
58 "com.sun.star.container.NoSuchElementException: "))
59 + e.Message),
60 static_cast< OWeakObject * >(this));
62 MutexGuard guard(getMutex());
63 if (!_xInterfaceTD.is() && !_xServiceTD.is()) {
64 if (resolveTypedefs(base)->getTypeClass() == TypeClass_INTERFACE) {
65 _xInterfaceTD = base;
66 } else if (base->getTypeClass() == TypeClass_SERVICE) {
67 _xServiceTD = Reference< XServiceTypeDescription >(
68 base, UNO_QUERY_THROW);
69 } else {
70 throw RuntimeException(
71 OUString(
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 //__________________________________________________________________________________________________
81 // virtual
82 SingletonTypeDescriptionImpl::~SingletonTypeDescriptionImpl()
84 g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
87 // XTypeDescription
88 //__________________________________________________________________________________________________
89 // virtual
90 TypeClass SingletonTypeDescriptionImpl::getTypeClass()
91 throw(::com::sun::star::uno::RuntimeException)
93 return TypeClass_SINGLETON;
95 //__________________________________________________________________________________________________
96 // virtual
97 OUString SingletonTypeDescriptionImpl::getName()
98 throw(::com::sun::star::uno::RuntimeException)
100 return _aName;
103 // XSingletonTypeDescription
104 //__________________________________________________________________________________________________
105 // virtual
106 Reference< XServiceTypeDescription > SAL_CALL
107 SingletonTypeDescriptionImpl::getService()
108 throw(::com::sun::star::uno::RuntimeException)
110 init();
111 return _xServiceTD;
114 // XSingletonTypeDescription2
115 //______________________________________________________________________________
116 // virtual
117 sal_Bool SAL_CALL
118 SingletonTypeDescriptionImpl::isInterfaceBased()
119 throw(::com::sun::star::uno::RuntimeException)
121 init();
122 return _xInterfaceTD.is();
125 //______________________________________________________________________________
126 // virtual
127 Reference< XTypeDescription > SAL_CALL
128 SingletonTypeDescriptionImpl::getInterface()
129 throw(::com::sun::star::uno::RuntimeException)
131 init();
132 return _xInterfaceTD;