xref: /AOO41X/main/stoc/source/registry_tdprovider/tdiface.cxx (revision 647a425c57429e1e89af1c7acf2de6af6f1bb730)
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
10cdf0e10cSrcweir  *
11*647a425cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
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.
19cdf0e10cSrcweir  *
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 <rtl/ustrbuf.hxx>
28cdf0e10cSrcweir #include "registry/reader.hxx"
29cdf0e10cSrcweir #include "registry/version.h"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <com/sun/star/reflection/XInterfaceMemberTypeDescription.hpp>
32cdf0e10cSrcweir #include <com/sun/star/reflection/XInterfaceAttributeTypeDescription2.hpp>
33cdf0e10cSrcweir #include <com/sun/star/reflection/XInterfaceMethodTypeDescription.hpp>
34cdf0e10cSrcweir #include <com/sun/star/reflection/XMethodParameter.hpp>
35cdf0e10cSrcweir #include <com/sun/star/reflection/XParameter.hpp>
36cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
37cdf0e10cSrcweir #include "base.hxx"
38cdf0e10cSrcweir #include "functiondescription.hxx"
39cdf0e10cSrcweir #include "methoddescription.hxx"
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #include <memory>
42cdf0e10cSrcweir #include <set>
43cdf0e10cSrcweir 
44cdf0e10cSrcweir namespace stoc_rdbtdp
45cdf0e10cSrcweir {
46cdf0e10cSrcweir 
47cdf0e10cSrcweir //==================================================================================================
48cdf0e10cSrcweir class InterfaceMethodImpl : public WeakImplHelper1< XInterfaceMethodTypeDescription >
49cdf0e10cSrcweir {
50cdf0e10cSrcweir     stoc::registry_tdprovider::MethodDescription _desc;
51cdf0e10cSrcweir 
52cdf0e10cSrcweir 	Reference< XHierarchicalNameAccess >  _xTDMgr;
53cdf0e10cSrcweir 
54cdf0e10cSrcweir 	OUString							  _aTypeName;
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 	OUString							  _aReturnType;
57cdf0e10cSrcweir 	Reference< XTypeDescription >		  _xReturnTD;
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 	sal_Bool							  _bIsOneWay;
60cdf0e10cSrcweir 	sal_Int32							  _nPosition;
61cdf0e10cSrcweir 
62cdf0e10cSrcweir public:
InterfaceMethodImpl(const Reference<XHierarchicalNameAccess> & xTDMgr,const OUString & rTypeName,const OUString & rMemberName,const OUString & rReturnType,const Sequence<sal_Int8> & rBytes,sal_uInt16 nMethodIndex,sal_Bool bIsOneWay,sal_Int32 nPosition)63cdf0e10cSrcweir 	InterfaceMethodImpl( const Reference< XHierarchicalNameAccess > & xTDMgr,
64cdf0e10cSrcweir 						 const OUString & rTypeName,
65cdf0e10cSrcweir 						 const OUString & rMemberName,
66cdf0e10cSrcweir 						 const OUString & rReturnType,
67cdf0e10cSrcweir 						 const Sequence< sal_Int8 > & rBytes,
68cdf0e10cSrcweir 						 sal_uInt16 nMethodIndex,
69cdf0e10cSrcweir 						 sal_Bool bIsOneWay,
70cdf0e10cSrcweir 						 sal_Int32 nPosition )
71cdf0e10cSrcweir 		: _desc(xTDMgr, rMemberName, rBytes, nMethodIndex)
72cdf0e10cSrcweir         , _xTDMgr( xTDMgr )
73cdf0e10cSrcweir 		, _aTypeName( rTypeName )
74cdf0e10cSrcweir 		, _aReturnType( rReturnType )
75cdf0e10cSrcweir 		, _bIsOneWay( bIsOneWay )
76cdf0e10cSrcweir 		, _nPosition( nPosition )
77cdf0e10cSrcweir 		{
78cdf0e10cSrcweir 			g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
79cdf0e10cSrcweir 		}
80cdf0e10cSrcweir 	virtual ~InterfaceMethodImpl();
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 	// XTypeDescription
83cdf0e10cSrcweir     virtual TypeClass SAL_CALL getTypeClass() throw(::com::sun::star::uno::RuntimeException);
84cdf0e10cSrcweir     virtual OUString SAL_CALL getName() throw(::com::sun::star::uno::RuntimeException);
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 	// XInterfaceMemberTypeDescription
getMemberName()87cdf0e10cSrcweir     virtual OUString SAL_CALL getMemberName() throw(::com::sun::star::uno::RuntimeException)
88cdf0e10cSrcweir     { return _desc.getName(); }
89cdf0e10cSrcweir     virtual sal_Int32 SAL_CALL getPosition() throw(::com::sun::star::uno::RuntimeException);
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 	// XInterfaceMethodTypeDescription
92cdf0e10cSrcweir 	virtual Reference< XTypeDescription > SAL_CALL getReturnType() throw(::com::sun::star::uno::RuntimeException);
93cdf0e10cSrcweir     virtual sal_Bool SAL_CALL isOneway() throw(::com::sun::star::uno::RuntimeException);
94cdf0e10cSrcweir     virtual Sequence< Reference< XMethodParameter > > SAL_CALL getParameters() throw(::com::sun::star::uno::RuntimeException);
95cdf0e10cSrcweir     virtual Sequence< Reference< XTypeDescription > > SAL_CALL getExceptions() throw(::com::sun::star::uno::RuntimeException);
96cdf0e10cSrcweir };
97cdf0e10cSrcweir //__________________________________________________________________________________________________
~InterfaceMethodImpl()98cdf0e10cSrcweir InterfaceMethodImpl::~InterfaceMethodImpl()
99cdf0e10cSrcweir {
100cdf0e10cSrcweir 	g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
101cdf0e10cSrcweir }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir // XTypeDescription
104cdf0e10cSrcweir //__________________________________________________________________________________________________
getTypeClass()105cdf0e10cSrcweir TypeClass InterfaceMethodImpl::getTypeClass()
106cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
107cdf0e10cSrcweir {
108cdf0e10cSrcweir 	return TypeClass_INTERFACE_METHOD;
109cdf0e10cSrcweir }
110cdf0e10cSrcweir //__________________________________________________________________________________________________
getName()111cdf0e10cSrcweir OUString InterfaceMethodImpl::getName()
112cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
113cdf0e10cSrcweir {
114cdf0e10cSrcweir 	return _aTypeName;
115cdf0e10cSrcweir }
116cdf0e10cSrcweir 
117cdf0e10cSrcweir // XInterfaceMemberTypeDescription
118cdf0e10cSrcweir //__________________________________________________________________________________________________
getPosition()119cdf0e10cSrcweir sal_Int32 InterfaceMethodImpl::getPosition()
120cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
121cdf0e10cSrcweir {
122cdf0e10cSrcweir 	return _nPosition;
123cdf0e10cSrcweir }
124cdf0e10cSrcweir 
125cdf0e10cSrcweir // XInterfaceMethodTypeDescription
126cdf0e10cSrcweir //__________________________________________________________________________________________________
getReturnType()127cdf0e10cSrcweir Reference<XTypeDescription > InterfaceMethodImpl::getReturnType()
128cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
129cdf0e10cSrcweir {
130cdf0e10cSrcweir 	if (!_xReturnTD.is() && _aReturnType.getLength())
131cdf0e10cSrcweir 	{
132cdf0e10cSrcweir         try
133cdf0e10cSrcweir         {
134cdf0e10cSrcweir             Reference< XTypeDescription > xReturnTD;
135cdf0e10cSrcweir             if (_xTDMgr->getByHierarchicalName( _aReturnType ) >>= xReturnTD)
136cdf0e10cSrcweir             {
137cdf0e10cSrcweir                 MutexGuard aGuard( getMutex() );
138cdf0e10cSrcweir                 if (! _xReturnTD.is())
139cdf0e10cSrcweir                     _xReturnTD = xReturnTD;
140cdf0e10cSrcweir                 return _xReturnTD;
141cdf0e10cSrcweir             }
142cdf0e10cSrcweir         }
143cdf0e10cSrcweir         catch (NoSuchElementException &)
144cdf0e10cSrcweir         {
145cdf0e10cSrcweir         }
146cdf0e10cSrcweir         // never try again, if no td was found
147cdf0e10cSrcweir         _aReturnType = OUString();
148cdf0e10cSrcweir 	}
149cdf0e10cSrcweir 	return _xReturnTD;
150cdf0e10cSrcweir }
151cdf0e10cSrcweir //__________________________________________________________________________________________________
isOneway()152cdf0e10cSrcweir sal_Bool InterfaceMethodImpl::isOneway()
153cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
154cdf0e10cSrcweir {
155cdf0e10cSrcweir 	return _bIsOneWay;
156cdf0e10cSrcweir }
157cdf0e10cSrcweir //__________________________________________________________________________________________________
getParameters()158cdf0e10cSrcweir Sequence<Reference<XMethodParameter > > InterfaceMethodImpl::getParameters()
159cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
160cdf0e10cSrcweir {
161cdf0e10cSrcweir     Sequence< Reference< XParameter > > s1(_desc.getParameters());
162cdf0e10cSrcweir     Sequence< Reference< XMethodParameter > > s2(s1.getLength());
163cdf0e10cSrcweir     for (sal_Int32 i = 0; i < s1.getLength(); ++i) {
164cdf0e10cSrcweir         s2[i] = s1[i].get();
165cdf0e10cSrcweir     }
166cdf0e10cSrcweir     return s2;
167cdf0e10cSrcweir }
168cdf0e10cSrcweir //__________________________________________________________________________________________________
getExceptions()169cdf0e10cSrcweir Sequence<Reference<XTypeDescription > > InterfaceMethodImpl::getExceptions()
170cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
171cdf0e10cSrcweir {
172cdf0e10cSrcweir     Sequence< Reference< XCompoundTypeDescription > > s1(
173cdf0e10cSrcweir         _desc.getExceptions());
174cdf0e10cSrcweir     Sequence< Reference< XTypeDescription > > s2(s1.getLength());
175cdf0e10cSrcweir     for (sal_Int32 i = 0; i < s1.getLength(); ++i) {
176cdf0e10cSrcweir         s2[i] = s1[i].get();
177cdf0e10cSrcweir     }
178cdf0e10cSrcweir     return s2;
179cdf0e10cSrcweir }
180cdf0e10cSrcweir 
181cdf0e10cSrcweir 
182cdf0e10cSrcweir //##################################################################################################
183cdf0e10cSrcweir //##################################################################################################
184cdf0e10cSrcweir //##################################################################################################
185cdf0e10cSrcweir 
186cdf0e10cSrcweir 
187cdf0e10cSrcweir //==================================================================================================
188cdf0e10cSrcweir class InterfaceAttributeImpl : public WeakImplHelper1< XInterfaceAttributeTypeDescription2 >
189cdf0e10cSrcweir {
190cdf0e10cSrcweir 	Reference< XHierarchicalNameAccess >  _xTDMgr;
191cdf0e10cSrcweir 
192cdf0e10cSrcweir 	OUString							  _aTypeName;
193cdf0e10cSrcweir 	OUString							  _aMemberName;
194cdf0e10cSrcweir 
195cdf0e10cSrcweir 	OUString							  _aMemberTypeName;
196cdf0e10cSrcweir 	Reference< XTypeDescription >		  _xMemberTD;
197cdf0e10cSrcweir 
198cdf0e10cSrcweir 	sal_Bool							  _bReadOnly;
199cdf0e10cSrcweir 	sal_Bool							  _bBound;
200cdf0e10cSrcweir 	sal_Int32							  _nPosition;
201cdf0e10cSrcweir 
202cdf0e10cSrcweir     std::auto_ptr< stoc::registry_tdprovider::FunctionDescription > _getter;
203cdf0e10cSrcweir     std::auto_ptr< stoc::registry_tdprovider::FunctionDescription > _setter;
204cdf0e10cSrcweir 
205cdf0e10cSrcweir public:
InterfaceAttributeImpl(const Reference<XHierarchicalNameAccess> & xTDMgr,const OUString & rTypeName,const OUString & rMemberName,const OUString & rMemberTypeName,sal_Bool bReadOnly,sal_Bool bBound,std::auto_ptr<stoc::registry_tdprovider::FunctionDescription> & getter,std::auto_ptr<stoc::registry_tdprovider::FunctionDescription> & setter,sal_Int32 nPosition)206cdf0e10cSrcweir 	InterfaceAttributeImpl(
207cdf0e10cSrcweir         const Reference< XHierarchicalNameAccess > & xTDMgr,
208cdf0e10cSrcweir         const OUString & rTypeName,
209cdf0e10cSrcweir         const OUString & rMemberName,
210cdf0e10cSrcweir         const OUString & rMemberTypeName,
211cdf0e10cSrcweir         sal_Bool bReadOnly,
212cdf0e10cSrcweir         sal_Bool bBound,
213cdf0e10cSrcweir         std::auto_ptr< stoc::registry_tdprovider::FunctionDescription > &
214cdf0e10cSrcweir             getter,
215cdf0e10cSrcweir         std::auto_ptr< stoc::registry_tdprovider::FunctionDescription > &
216cdf0e10cSrcweir             setter,
217cdf0e10cSrcweir         sal_Int32 nPosition )
218cdf0e10cSrcweir 		: _xTDMgr( xTDMgr )
219cdf0e10cSrcweir 		, _aTypeName( rTypeName )
220cdf0e10cSrcweir 		, _aMemberName( rMemberName )
221cdf0e10cSrcweir 		, _aMemberTypeName( rMemberTypeName )
222cdf0e10cSrcweir 		, _bReadOnly( bReadOnly )
223cdf0e10cSrcweir 		, _bBound( bBound )
224cdf0e10cSrcweir 		, _nPosition( nPosition )
225cdf0e10cSrcweir         , _getter( getter )
226cdf0e10cSrcweir         , _setter( setter )
227cdf0e10cSrcweir 		{
228cdf0e10cSrcweir 			g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
229cdf0e10cSrcweir 		}
230cdf0e10cSrcweir 	virtual ~InterfaceAttributeImpl();
231cdf0e10cSrcweir 
232cdf0e10cSrcweir 	// XTypeDescription
233cdf0e10cSrcweir     virtual TypeClass SAL_CALL getTypeClass() throw(::com::sun::star::uno::RuntimeException);
234cdf0e10cSrcweir     virtual OUString SAL_CALL getName() throw(::com::sun::star::uno::RuntimeException);
235cdf0e10cSrcweir 
236cdf0e10cSrcweir 	// XInterfaceMemberTypeDescription
237cdf0e10cSrcweir     virtual OUString SAL_CALL getMemberName() throw(::com::sun::star::uno::RuntimeException);
238cdf0e10cSrcweir     virtual sal_Int32 SAL_CALL getPosition() throw(::com::sun::star::uno::RuntimeException);
239cdf0e10cSrcweir 
240cdf0e10cSrcweir 	// XInterfaceAttributeTypeDescription2
241cdf0e10cSrcweir 	virtual sal_Bool SAL_CALL isReadOnly() throw(::com::sun::star::uno::RuntimeException);
242cdf0e10cSrcweir 	virtual Reference< XTypeDescription > SAL_CALL getType() throw(::com::sun::star::uno::RuntimeException);
243cdf0e10cSrcweir 
isBound()244cdf0e10cSrcweir     virtual sal_Bool SAL_CALL isBound() throw (RuntimeException)
245cdf0e10cSrcweir     { return _bBound; }
246cdf0e10cSrcweir 
247cdf0e10cSrcweir     virtual Sequence< Reference< XCompoundTypeDescription > > SAL_CALL
getGetExceptions()248cdf0e10cSrcweir     getGetExceptions() throw (RuntimeException)
249cdf0e10cSrcweir     {
250cdf0e10cSrcweir         if (_getter.get() != 0) {
251cdf0e10cSrcweir             return _getter->getExceptions();
252cdf0e10cSrcweir         } else {
253cdf0e10cSrcweir             return Sequence< Reference< XCompoundTypeDescription > >();
254cdf0e10cSrcweir         }
255cdf0e10cSrcweir     }
256cdf0e10cSrcweir 
257cdf0e10cSrcweir     virtual Sequence< Reference< XCompoundTypeDescription > > SAL_CALL
getSetExceptions()258cdf0e10cSrcweir     getSetExceptions() throw (RuntimeException)
259cdf0e10cSrcweir     {
260cdf0e10cSrcweir         if (_setter.get() != 0) {
261cdf0e10cSrcweir             return _setter->getExceptions();
262cdf0e10cSrcweir         } else {
263cdf0e10cSrcweir             return Sequence< Reference< XCompoundTypeDescription > >();
264cdf0e10cSrcweir         }
265cdf0e10cSrcweir     }
266cdf0e10cSrcweir };
267cdf0e10cSrcweir 
~InterfaceAttributeImpl()268cdf0e10cSrcweir InterfaceAttributeImpl::~InterfaceAttributeImpl()
269cdf0e10cSrcweir {
270cdf0e10cSrcweir 	g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
271cdf0e10cSrcweir }
272cdf0e10cSrcweir // XTypeDescription
273cdf0e10cSrcweir //__________________________________________________________________________________________________
getTypeClass()274cdf0e10cSrcweir TypeClass InterfaceAttributeImpl::getTypeClass()
275cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
276cdf0e10cSrcweir {
277cdf0e10cSrcweir 	return TypeClass_INTERFACE_ATTRIBUTE;
278cdf0e10cSrcweir }
279cdf0e10cSrcweir //__________________________________________________________________________________________________
getName()280cdf0e10cSrcweir OUString InterfaceAttributeImpl::getName()
281cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
282cdf0e10cSrcweir {
283cdf0e10cSrcweir 	return _aTypeName;
284cdf0e10cSrcweir }
285cdf0e10cSrcweir 
286cdf0e10cSrcweir // XInterfaceMemberTypeDescription
287cdf0e10cSrcweir //__________________________________________________________________________________________________
getMemberName()288cdf0e10cSrcweir OUString InterfaceAttributeImpl::getMemberName()
289cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
290cdf0e10cSrcweir {
291cdf0e10cSrcweir 	return _aMemberName;
292cdf0e10cSrcweir }
293cdf0e10cSrcweir //__________________________________________________________________________________________________
getPosition()294cdf0e10cSrcweir sal_Int32 InterfaceAttributeImpl::getPosition()
295cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
296cdf0e10cSrcweir {
297cdf0e10cSrcweir 	return _nPosition;
298cdf0e10cSrcweir }
299cdf0e10cSrcweir 
300cdf0e10cSrcweir // XInterfaceAttributeTypeDescription2
301cdf0e10cSrcweir //__________________________________________________________________________________________________
isReadOnly()302cdf0e10cSrcweir sal_Bool InterfaceAttributeImpl::isReadOnly()
303cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
304cdf0e10cSrcweir {
305cdf0e10cSrcweir 	return _bReadOnly;
306cdf0e10cSrcweir }
307cdf0e10cSrcweir //__________________________________________________________________________________________________
getType()308cdf0e10cSrcweir Reference<XTypeDescription > InterfaceAttributeImpl::getType()
309cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
310cdf0e10cSrcweir {
311cdf0e10cSrcweir 	if (!_xMemberTD.is() && _aMemberTypeName.getLength())
312cdf0e10cSrcweir 	{
313cdf0e10cSrcweir         try
314cdf0e10cSrcweir         {
315cdf0e10cSrcweir             Reference< XTypeDescription > xMemberTD;
316cdf0e10cSrcweir             if (_xTDMgr->getByHierarchicalName( _aMemberTypeName ) >>= xMemberTD)
317cdf0e10cSrcweir             {
318cdf0e10cSrcweir                 MutexGuard aGuard( getMutex() );
319cdf0e10cSrcweir                 if (! _xMemberTD.is())
320cdf0e10cSrcweir                     _xMemberTD = xMemberTD;
321cdf0e10cSrcweir                 return _xMemberTD;
322cdf0e10cSrcweir             }
323cdf0e10cSrcweir         }
324cdf0e10cSrcweir         catch (NoSuchElementException &)
325cdf0e10cSrcweir         {
326cdf0e10cSrcweir         }
327cdf0e10cSrcweir         // never try again, if no td was found
328cdf0e10cSrcweir         _aMemberTypeName = OUString();
329cdf0e10cSrcweir     }
330cdf0e10cSrcweir 	return _xMemberTD;
331cdf0e10cSrcweir }
332cdf0e10cSrcweir 
333cdf0e10cSrcweir 
334cdf0e10cSrcweir //##################################################################################################
335cdf0e10cSrcweir //##################################################################################################
336cdf0e10cSrcweir //##################################################################################################
337cdf0e10cSrcweir 
checkInterfaceType(Reference<XTypeDescription> const & type)338cdf0e10cSrcweir void InterfaceTypeDescriptionImpl::checkInterfaceType(
339cdf0e10cSrcweir     Reference< XTypeDescription > const & type)
340cdf0e10cSrcweir {
341cdf0e10cSrcweir     if (resolveTypedefs(type)->getTypeClass() != TypeClass_INTERFACE) {
342cdf0e10cSrcweir         throw RuntimeException(
343cdf0e10cSrcweir             OUString(
344cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
345cdf0e10cSrcweir                     "Interface base is not an interface type")),
346cdf0e10cSrcweir             static_cast< OWeakObject * >(this));
347cdf0e10cSrcweir     }
348cdf0e10cSrcweir }
349cdf0e10cSrcweir 
350cdf0e10cSrcweir namespace {
351cdf0e10cSrcweir 
352cdf0e10cSrcweir class BaseOffset {
353cdf0e10cSrcweir public:
354cdf0e10cSrcweir     BaseOffset(Reference< XInterfaceTypeDescription2 > const & desc);
355cdf0e10cSrcweir 
get() const356cdf0e10cSrcweir     sal_Int32 get() const { return offset; }
357cdf0e10cSrcweir 
358cdf0e10cSrcweir private:
359cdf0e10cSrcweir     void calculateBases(Reference< XInterfaceTypeDescription2 > const & desc);
360cdf0e10cSrcweir 
361cdf0e10cSrcweir     void calculate(Reference< XInterfaceTypeDescription2 > const & desc);
362cdf0e10cSrcweir 
363cdf0e10cSrcweir     std::set< rtl::OUString > set;
364cdf0e10cSrcweir     sal_Int32 offset;
365cdf0e10cSrcweir };
366cdf0e10cSrcweir 
BaseOffset(Reference<XInterfaceTypeDescription2> const & desc)367cdf0e10cSrcweir BaseOffset::BaseOffset(Reference< XInterfaceTypeDescription2 > const & desc) {
368cdf0e10cSrcweir     offset = 0;
369cdf0e10cSrcweir     calculateBases(desc);
370cdf0e10cSrcweir }
371cdf0e10cSrcweir 
calculateBases(Reference<XInterfaceTypeDescription2> const & desc)372cdf0e10cSrcweir void BaseOffset::calculateBases(
373cdf0e10cSrcweir     Reference< XInterfaceTypeDescription2 > const & desc)
374cdf0e10cSrcweir {
375cdf0e10cSrcweir     Sequence< Reference < XTypeDescription > > bases(desc->getBaseTypes());
376cdf0e10cSrcweir     for (sal_Int32 i = 0; i < bases.getLength(); ++i) {
377cdf0e10cSrcweir         calculate(
378cdf0e10cSrcweir             Reference< XInterfaceTypeDescription2 >(
379cdf0e10cSrcweir                 resolveTypedefs(bases[i]), UNO_QUERY_THROW));
380cdf0e10cSrcweir     }
381cdf0e10cSrcweir }
382cdf0e10cSrcweir 
calculate(Reference<XInterfaceTypeDescription2> const & desc)383cdf0e10cSrcweir void BaseOffset::calculate(Reference< XInterfaceTypeDescription2 > const & desc)
384cdf0e10cSrcweir {
385cdf0e10cSrcweir     if (set.insert(desc->getName()).second) {
386cdf0e10cSrcweir         calculateBases(desc);
387cdf0e10cSrcweir         offset += desc->getMembers().getLength();
388cdf0e10cSrcweir     }
389cdf0e10cSrcweir }
390cdf0e10cSrcweir 
391cdf0e10cSrcweir }
392cdf0e10cSrcweir 
393cdf0e10cSrcweir //__________________________________________________________________________________________________
InterfaceTypeDescriptionImpl(const Reference<XHierarchicalNameAccess> & xTDMgr,const OUString & rName,const Sequence<OUString> & rBaseTypes,const Sequence<OUString> & rOptionalBaseTypes,const Sequence<sal_Int8> & rBytes,bool published)394cdf0e10cSrcweir InterfaceTypeDescriptionImpl::InterfaceTypeDescriptionImpl(
395cdf0e10cSrcweir 	const Reference< XHierarchicalNameAccess > & xTDMgr,
396cdf0e10cSrcweir 	const OUString & rName, const Sequence< OUString > & rBaseTypes,
397cdf0e10cSrcweir     const Sequence< OUString > & rOptionalBaseTypes,
398cdf0e10cSrcweir 	const Sequence< sal_Int8 > & rBytes, bool published )
399cdf0e10cSrcweir 	: _xTDMgr( xTDMgr )
400cdf0e10cSrcweir 	, _aBytes( rBytes )
401cdf0e10cSrcweir 	, _aName( rName )
402cdf0e10cSrcweir 	, _aBaseTypes( rBaseTypes )
403cdf0e10cSrcweir 	, _aOptionalBaseTypes( rOptionalBaseTypes )
404cdf0e10cSrcweir 	, _membersInit( false )
405cdf0e10cSrcweir     , _published( published )
406cdf0e10cSrcweir {
407cdf0e10cSrcweir 	g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
408cdf0e10cSrcweir }
409cdf0e10cSrcweir //__________________________________________________________________________________________________
~InterfaceTypeDescriptionImpl()410cdf0e10cSrcweir InterfaceTypeDescriptionImpl::~InterfaceTypeDescriptionImpl()
411cdf0e10cSrcweir {
412cdf0e10cSrcweir 	g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
413cdf0e10cSrcweir }
414cdf0e10cSrcweir 
415cdf0e10cSrcweir // XTypeDescription
416cdf0e10cSrcweir //__________________________________________________________________________________________________
getTypeClass()417cdf0e10cSrcweir TypeClass InterfaceTypeDescriptionImpl::getTypeClass()
418cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
419cdf0e10cSrcweir {
420cdf0e10cSrcweir 	return TypeClass_INTERFACE;
421cdf0e10cSrcweir }
422cdf0e10cSrcweir //__________________________________________________________________________________________________
getName()423cdf0e10cSrcweir OUString InterfaceTypeDescriptionImpl::getName()
424cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
425cdf0e10cSrcweir {
426cdf0e10cSrcweir 	return _aName;
427cdf0e10cSrcweir }
428cdf0e10cSrcweir 
429cdf0e10cSrcweir // XInterfaceTypeDescription2
430cdf0e10cSrcweir //__________________________________________________________________________________________________
getBaseType()431cdf0e10cSrcweir Reference< XTypeDescription > InterfaceTypeDescriptionImpl::getBaseType()
432cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
433cdf0e10cSrcweir {
434cdf0e10cSrcweir     Sequence< Reference< XTypeDescription > > aBaseTypes(getBaseTypes());
435cdf0e10cSrcweir     return aBaseTypes.getLength() >= 1 ? aBaseTypes[0] : 0;
436cdf0e10cSrcweir }
437cdf0e10cSrcweir //__________________________________________________________________________________________________
getUik()438cdf0e10cSrcweir Uik SAL_CALL InterfaceTypeDescriptionImpl::getUik()
439cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
440cdf0e10cSrcweir {
441cdf0e10cSrcweir 	return Uik();
442cdf0e10cSrcweir }
443cdf0e10cSrcweir //__________________________________________________________________________________________________
getMembers()444cdf0e10cSrcweir Sequence< Reference< XInterfaceMemberTypeDescription > > InterfaceTypeDescriptionImpl::getMembers()
445cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
446cdf0e10cSrcweir {
447cdf0e10cSrcweir     osl::MutexGuard guard(getMutex());
448cdf0e10cSrcweir     if (!_membersInit) {
449cdf0e10cSrcweir         _nBaseOffset = BaseOffset(this).get();
450cdf0e10cSrcweir         typereg::Reader reader(
451cdf0e10cSrcweir             _aBytes.getConstArray(), _aBytes.getLength(), false,
452cdf0e10cSrcweir             TYPEREG_VERSION_1);
453cdf0e10cSrcweir         sal_Int32 count = 0;
454cdf0e10cSrcweir         sal_uInt16 methodCount = reader.getMethodCount();
455cdf0e10cSrcweir         {for (sal_uInt16 i = 0; i < methodCount; ++i) {
456cdf0e10cSrcweir             RTMethodMode flags = reader.getMethodFlags(i);
457cdf0e10cSrcweir             if (flags != RT_MODE_ATTRIBUTE_GET
458cdf0e10cSrcweir                 && flags != RT_MODE_ATTRIBUTE_SET)
459cdf0e10cSrcweir             {
460cdf0e10cSrcweir                 ++count;
461cdf0e10cSrcweir             }
462cdf0e10cSrcweir         }}
463cdf0e10cSrcweir         sal_uInt16 fieldCount = reader.getFieldCount();
464cdf0e10cSrcweir         count += fieldCount;
465cdf0e10cSrcweir         _members.realloc(count);
466cdf0e10cSrcweir         sal_Int32 index = 0;
467cdf0e10cSrcweir         {for (sal_uInt16 i = 0; i < fieldCount; ++i) {
468cdf0e10cSrcweir             rtl::OUString name(reader.getFieldName(i));
469cdf0e10cSrcweir             rtl::OUStringBuffer typeName(getName());
470cdf0e10cSrcweir             typeName.appendAscii(RTL_CONSTASCII_STRINGPARAM("::"));
471cdf0e10cSrcweir             typeName.append(name);
472cdf0e10cSrcweir             RTFieldAccess flags = reader.getFieldFlags(i);
473cdf0e10cSrcweir             std::auto_ptr< stoc::registry_tdprovider::FunctionDescription >
474cdf0e10cSrcweir                 getter;
475cdf0e10cSrcweir             std::auto_ptr< stoc::registry_tdprovider::FunctionDescription >
476cdf0e10cSrcweir                 setter;
477cdf0e10cSrcweir             for (sal_uInt16 j = 0; j < methodCount; ++j) {
478cdf0e10cSrcweir                 if (reader.getMethodName(j) == name) {
479cdf0e10cSrcweir                     switch (reader.getMethodFlags(j)) {
480cdf0e10cSrcweir                     case RT_MODE_ATTRIBUTE_GET:
481cdf0e10cSrcweir                         OSL_ASSERT(getter.get() == 0);
482cdf0e10cSrcweir                         getter.reset(
483cdf0e10cSrcweir                             new stoc::registry_tdprovider::FunctionDescription(
484cdf0e10cSrcweir                                 _xTDMgr, _aBytes, j));
485cdf0e10cSrcweir                         break;
486cdf0e10cSrcweir 
487cdf0e10cSrcweir                     case RT_MODE_ATTRIBUTE_SET:
488cdf0e10cSrcweir                         OSL_ASSERT(setter.get() == 0);
489cdf0e10cSrcweir                         setter.reset(
490cdf0e10cSrcweir                             new stoc::registry_tdprovider::FunctionDescription(
491cdf0e10cSrcweir                                 _xTDMgr, _aBytes, j));
492cdf0e10cSrcweir                         break;
493cdf0e10cSrcweir 
494cdf0e10cSrcweir                     default:
495cdf0e10cSrcweir                         OSL_ASSERT(false);
496cdf0e10cSrcweir                         break;
497cdf0e10cSrcweir                     }
498cdf0e10cSrcweir                 }
499cdf0e10cSrcweir             }
500cdf0e10cSrcweir             _members[index] = new InterfaceAttributeImpl(
501cdf0e10cSrcweir                 _xTDMgr, typeName.makeStringAndClear(), name,
502cdf0e10cSrcweir                 reader.getFieldTypeName(i).replace('/', '.'),
503cdf0e10cSrcweir                 (flags & RT_ACCESS_READONLY) != 0,
504cdf0e10cSrcweir                 (flags & RT_ACCESS_BOUND) != 0, getter, setter,
505cdf0e10cSrcweir                 _nBaseOffset + index);
506cdf0e10cSrcweir             ++index;
507cdf0e10cSrcweir         }}
508cdf0e10cSrcweir         {for (sal_uInt16 i = 0; i < methodCount; ++i) {
509cdf0e10cSrcweir             RTMethodMode flags = reader.getMethodFlags(i);
510cdf0e10cSrcweir             if (flags != RT_MODE_ATTRIBUTE_GET
511cdf0e10cSrcweir                 && flags != RT_MODE_ATTRIBUTE_SET)
512cdf0e10cSrcweir             {
513cdf0e10cSrcweir                 rtl::OUString name(reader.getMethodName(i));
514cdf0e10cSrcweir                 rtl::OUStringBuffer typeName(getName());
515cdf0e10cSrcweir                 typeName.appendAscii(RTL_CONSTASCII_STRINGPARAM("::"));
516cdf0e10cSrcweir                 typeName.append(name);
517cdf0e10cSrcweir                 _members[index] = new InterfaceMethodImpl(
518cdf0e10cSrcweir                     _xTDMgr, typeName.makeStringAndClear(), name,
519cdf0e10cSrcweir                     reader.getMethodReturnTypeName(i).replace('/', '.'),
520cdf0e10cSrcweir                     _aBytes, i, flags == RT_MODE_ONEWAY, _nBaseOffset + index);
521cdf0e10cSrcweir                 ++index;
522cdf0e10cSrcweir             }
523cdf0e10cSrcweir         }}
524cdf0e10cSrcweir         _membersInit = true;
525cdf0e10cSrcweir     }
526cdf0e10cSrcweir     return _members;
527cdf0e10cSrcweir }
528cdf0e10cSrcweir 
529cdf0e10cSrcweir Sequence< Reference< XTypeDescription > >
getBaseTypes()530cdf0e10cSrcweir InterfaceTypeDescriptionImpl::getBaseTypes() throw (RuntimeException) {
531cdf0e10cSrcweir     MutexGuard guard(getMutex());
532cdf0e10cSrcweir     if (_xBaseTDs.getLength() == 0 && _aBaseTypes.getLength() != 0) {
533cdf0e10cSrcweir         Sequence< Reference< XTypeDescription > > tds(_aBaseTypes.getLength());
534cdf0e10cSrcweir         for (sal_Int32 i = 0; i < _aBaseTypes.getLength(); ++i) {
535cdf0e10cSrcweir             try {
536cdf0e10cSrcweir                 _xTDMgr->getByHierarchicalName(_aBaseTypes[i]) >>= tds[i];
537cdf0e10cSrcweir             } catch (NoSuchElementException & e) {
538cdf0e10cSrcweir                 throw RuntimeException(
539cdf0e10cSrcweir                     (OUString(
540cdf0e10cSrcweir                         RTL_CONSTASCII_USTRINGPARAM(
541cdf0e10cSrcweir                             "com.sun.star.container.NoSuchElementException: "))
542cdf0e10cSrcweir                      + e.Message),
543cdf0e10cSrcweir                     static_cast< OWeakObject * >(this));
544cdf0e10cSrcweir             }
545cdf0e10cSrcweir             OSL_ASSERT(tds[i].is());
546cdf0e10cSrcweir             checkInterfaceType(tds[i]);
547cdf0e10cSrcweir         }
548cdf0e10cSrcweir         _xBaseTDs = tds;
549cdf0e10cSrcweir     }
550cdf0e10cSrcweir     return _xBaseTDs;
551cdf0e10cSrcweir }
552cdf0e10cSrcweir 
553cdf0e10cSrcweir Sequence< Reference< XTypeDescription > >
getOptionalBaseTypes()554cdf0e10cSrcweir InterfaceTypeDescriptionImpl::getOptionalBaseTypes() throw (RuntimeException) {
555cdf0e10cSrcweir     MutexGuard guard(getMutex());
556cdf0e10cSrcweir     if (_xOptionalBaseTDs.getLength() == 0
557cdf0e10cSrcweir         && _aOptionalBaseTypes.getLength() != 0)
558cdf0e10cSrcweir     {
559cdf0e10cSrcweir         Sequence< Reference< XTypeDescription > > tds(
560cdf0e10cSrcweir             _aOptionalBaseTypes.getLength());
561cdf0e10cSrcweir         for (sal_Int32 i = 0; i < _aOptionalBaseTypes.getLength(); ++i) {
562cdf0e10cSrcweir             try {
563cdf0e10cSrcweir                 _xTDMgr->getByHierarchicalName(_aOptionalBaseTypes[i])
564cdf0e10cSrcweir                     >>= tds[i];
565cdf0e10cSrcweir             } catch (NoSuchElementException & e) {
566cdf0e10cSrcweir                 throw RuntimeException(
567cdf0e10cSrcweir                     (OUString(
568cdf0e10cSrcweir                         RTL_CONSTASCII_USTRINGPARAM(
569cdf0e10cSrcweir                             "com.sun.star.container.NoSuchElementException: "))
570cdf0e10cSrcweir                      + e.Message),
571cdf0e10cSrcweir                     static_cast< OWeakObject * >(this));
572cdf0e10cSrcweir             }
573cdf0e10cSrcweir             OSL_ASSERT(tds[i].is());
574cdf0e10cSrcweir             checkInterfaceType(tds[i]);
575cdf0e10cSrcweir         }
576cdf0e10cSrcweir         _xOptionalBaseTDs = tds;
577cdf0e10cSrcweir     }
578cdf0e10cSrcweir     return _xOptionalBaseTDs;
579cdf0e10cSrcweir }
580cdf0e10cSrcweir 
581cdf0e10cSrcweir }
582