1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_stoc.hxx"
30 #include <osl/diagnose.h>
31 #include "base.hxx"
32 
33 #include "com/sun/star/uno/RuntimeException.hpp"
34 
35 using namespace com::sun::star;
36 
37 namespace stoc_rdbtdp
38 {
39 
40 void SingletonTypeDescriptionImpl::init() {
41     {
42         MutexGuard guard(getMutex());
43         if (_xInterfaceTD.is() || _xServiceTD.is()) {
44             return;
45         }
46     }
47     Reference< XTypeDescription > base;
48     try {
49         base = Reference< XTypeDescription >(
50             _xTDMgr->getByHierarchicalName(_aBaseName), UNO_QUERY_THROW);
51     } catch (NoSuchElementException const & e) {
52         throw RuntimeException(
53             (OUString(
54                 RTL_CONSTASCII_USTRINGPARAM(
55                     "com.sun.star.container.NoSuchElementException: "))
56              + e.Message),
57             static_cast< OWeakObject * >(this));
58     }
59     MutexGuard guard(getMutex());
60     if (!_xInterfaceTD.is() && !_xServiceTD.is()) {
61         if (resolveTypedefs(base)->getTypeClass() == TypeClass_INTERFACE) {
62             _xInterfaceTD = base;
63         } else if (base->getTypeClass() == TypeClass_SERVICE) {
64             _xServiceTD = Reference< XServiceTypeDescription >(
65                 base, UNO_QUERY_THROW);
66         } else {
67             throw RuntimeException(
68                 OUString(
69                     RTL_CONSTASCII_USTRINGPARAM(
70                         "Singleton is based on neither interface nor service")),
71                 static_cast< OWeakObject * >(this));
72         }
73     }
74     OSL_ASSERT(_xInterfaceTD.is() ^ _xServiceTD.is());
75 }
76 
77 //__________________________________________________________________________________________________
78 // virtual
79 SingletonTypeDescriptionImpl::~SingletonTypeDescriptionImpl()
80 {
81     g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
82 }
83 
84 // XTypeDescription
85 //__________________________________________________________________________________________________
86 // virtual
87 TypeClass SingletonTypeDescriptionImpl::getTypeClass()
88     throw(::com::sun::star::uno::RuntimeException)
89 {
90     return TypeClass_SINGLETON;
91 }
92 //__________________________________________________________________________________________________
93 // virtual
94 OUString SingletonTypeDescriptionImpl::getName()
95     throw(::com::sun::star::uno::RuntimeException)
96 {
97     return _aName;
98 }
99 
100 // XSingletonTypeDescription
101 //__________________________________________________________________________________________________
102 // virtual
103 Reference< XServiceTypeDescription > SAL_CALL
104 SingletonTypeDescriptionImpl::getService()
105     throw(::com::sun::star::uno::RuntimeException)
106 {
107     init();
108     return _xServiceTD;
109 }
110 
111 // XSingletonTypeDescription2
112 //______________________________________________________________________________
113 // virtual
114 sal_Bool SAL_CALL
115 SingletonTypeDescriptionImpl::isInterfaceBased()
116     throw(::com::sun::star::uno::RuntimeException)
117 {
118     init();
119     return _xInterfaceTD.is();
120 }
121 
122 //______________________________________________________________________________
123 // virtual
124 Reference< XTypeDescription > SAL_CALL
125 SingletonTypeDescriptionImpl::getInterface()
126     throw(::com::sun::star::uno::RuntimeException)
127 {
128     init();
129     return _xInterfaceTD;
130 }
131 
132 }
133