xref: /trunk/main/stoc/source/registry_tdprovider/tdsingleton.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 {
85     return TypeClass_SINGLETON;
86 }
87 //__________________________________________________________________________________________________
88 // virtual
getName()89 OUString SingletonTypeDescriptionImpl::getName()
90 {
91     return _aName;
92 }
93 
94 // XSingletonTypeDescription
95 //__________________________________________________________________________________________________
96 // virtual
97 Reference< XServiceTypeDescription > SAL_CALL
getService()98 SingletonTypeDescriptionImpl::getService()
99 {
100     init();
101     return _xServiceTD;
102 }
103 
104 // XSingletonTypeDescription2
105 //______________________________________________________________________________
106 // virtual
107 sal_Bool SAL_CALL
isInterfaceBased()108 SingletonTypeDescriptionImpl::isInterfaceBased()
109 {
110     init();
111     return _xInterfaceTD.is();
112 }
113 
114 //______________________________________________________________________________
115 // virtual
116 Reference< XTypeDescription > SAL_CALL
getInterface()117 SingletonTypeDescriptionImpl::getInterface()
118 {
119     init();
120     return _xInterfaceTD;
121 }
122 
123 }
124