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