1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <osl/diagnose.h>
23 #include "com/sun/star/uno/RuntimeException.hpp"
25 using namespace com::sun::star
;
30 void SingletonTypeDescriptionImpl::init() {
32 MutexGuard
guard(getMutex());
33 if (_xInterfaceTD
.is() || _xServiceTD
.is()) {
37 Reference
< XTypeDescription
> base
;
39 base
= Reference
< XTypeDescription
>(
40 _xTDMgr
->getByHierarchicalName(_aBaseName
), UNO_QUERY_THROW
);
41 } catch (NoSuchElementException
const & e
) {
42 throw RuntimeException(
44 "com.sun.star.container.NoSuchElementException: ")
46 static_cast< OWeakObject
* >(this));
48 MutexGuard
guard(getMutex());
49 if (!_xInterfaceTD
.is() && !_xServiceTD
.is()) {
50 if (resolveTypedefs(base
)->getTypeClass() == TypeClass_INTERFACE
) {
52 } else if (base
->getTypeClass() == TypeClass_SERVICE
) {
53 _xServiceTD
= Reference
< XServiceTypeDescription
>(
54 base
, UNO_QUERY_THROW
);
56 throw RuntimeException(
58 "Singleton is based on neither interface nor service"),
59 static_cast< OWeakObject
* >(this));
62 OSL_ASSERT(_xInterfaceTD
.is() ^ _xServiceTD
.is());
65 //__________________________________________________________________________________________________
67 SingletonTypeDescriptionImpl::~SingletonTypeDescriptionImpl() {}
70 //__________________________________________________________________________________________________
72 TypeClass
SingletonTypeDescriptionImpl::getTypeClass()
73 throw(::com::sun::star::uno::RuntimeException
)
75 return TypeClass_SINGLETON
;
77 //__________________________________________________________________________________________________
79 OUString
SingletonTypeDescriptionImpl::getName()
80 throw(::com::sun::star::uno::RuntimeException
)
85 // XSingletonTypeDescription
86 //__________________________________________________________________________________________________
88 Reference
< XServiceTypeDescription
> SAL_CALL
89 SingletonTypeDescriptionImpl::getService()
90 throw(::com::sun::star::uno::RuntimeException
)
96 // XSingletonTypeDescription2
97 //______________________________________________________________________________
100 SingletonTypeDescriptionImpl::isInterfaceBased()
101 throw(::com::sun::star::uno::RuntimeException
)
104 return _xInterfaceTD
.is();
107 //______________________________________________________________________________
109 Reference
< XTypeDescription
> SAL_CALL
110 SingletonTypeDescriptionImpl::getInterface()
111 throw(::com::sun::star::uno::RuntimeException
)
114 return _xInterfaceTD
;
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */