1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_stoc.hxx"
26 #include <osl/diagnose.h>
27 #include "base.hxx"
28 
29 #include "com/sun/star/uno/RuntimeException.hpp"
30 
31 using namespace com::sun::star;
32 
33 namespace stoc_rdbtdp
34 {
35 
init()36 void SingletonTypeDescriptionImpl::init() {
37     {
38         MutexGuard guard(getMutex());
39         if (_xInterfaceTD.is() || _xServiceTD.is()) {
40             return;
41         }
42     }
43     Reference< XTypeDescription > base;
44     try {
45         base = Reference< XTypeDescription >(
46             _xTDMgr->getByHierarchicalName(_aBaseName), UNO_QUERY_THROW);
47     } catch (NoSuchElementException const & e) {
48         throw RuntimeException(
49             (OUString(
50                 RTL_CONSTASCII_USTRINGPARAM(
51                     "com.sun.star.container.NoSuchElementException: "))
52              + e.Message),
53             static_cast< OWeakObject * >(this));
54     }
55     MutexGuard guard(getMutex());
56     if (!_xInterfaceTD.is() && !_xServiceTD.is()) {
57         if (resolveTypedefs(base)->getTypeClass() == TypeClass_INTERFACE) {
58             _xInterfaceTD = base;
59         } else if (base->getTypeClass() == TypeClass_SERVICE) {
60             _xServiceTD = Reference< XServiceTypeDescription >(
61                 base, UNO_QUERY_THROW);
62         } else {
63             throw RuntimeException(
64                 OUString(
65                     RTL_CONSTASCII_USTRINGPARAM(
66                         "Singleton is based on neither interface nor service")),
67                 static_cast< OWeakObject * >(this));
68         }
69     }
70     OSL_ASSERT(_xInterfaceTD.is() ^ _xServiceTD.is());
71 }
72 
73 //__________________________________________________________________________________________________
74 // virtual
~SingletonTypeDescriptionImpl()75 SingletonTypeDescriptionImpl::~SingletonTypeDescriptionImpl()
76 {
77     g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
78 }
79 
80 // XTypeDescription
81 //__________________________________________________________________________________________________
82 // virtual
getTypeClass()83 TypeClass SingletonTypeDescriptionImpl::getTypeClass()
84     throw(::com::sun::star::uno::RuntimeException)
85 {
86     return TypeClass_SINGLETON;
87 }
88 //__________________________________________________________________________________________________
89 // virtual
getName()90 OUString SingletonTypeDescriptionImpl::getName()
91     throw(::com::sun::star::uno::RuntimeException)
92 {
93     return _aName;
94 }
95 
96 // XSingletonTypeDescription
97 //__________________________________________________________________________________________________
98 // virtual
99 Reference< XServiceTypeDescription > SAL_CALL
getService()100 SingletonTypeDescriptionImpl::getService()
101     throw(::com::sun::star::uno::RuntimeException)
102 {
103     init();
104     return _xServiceTD;
105 }
106 
107 // XSingletonTypeDescription2
108 //______________________________________________________________________________
109 // virtual
110 sal_Bool SAL_CALL
isInterfaceBased()111 SingletonTypeDescriptionImpl::isInterfaceBased()
112     throw(::com::sun::star::uno::RuntimeException)
113 {
114     init();
115     return _xInterfaceTD.is();
116 }
117 
118 //______________________________________________________________________________
119 // virtual
120 Reference< XTypeDescription > SAL_CALL
getInterface()121 SingletonTypeDescriptionImpl::getInterface()
122     throw(::com::sun::star::uno::RuntimeException)
123 {
124     init();
125     return _xInterfaceTD;
126 }
127 
128 }
129