xref: /aoo41x/main/cppuhelper/source/tdmgr.cxx (revision 9d7e27ac)
1*9d7e27acSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9d7e27acSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9d7e27acSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9d7e27acSAndrew Rist  * distributed with this work for additional information
6*9d7e27acSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9d7e27acSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9d7e27acSAndrew Rist  * "License"); you may not use this file except in compliance
9*9d7e27acSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9d7e27acSAndrew Rist  *
11*9d7e27acSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9d7e27acSAndrew Rist  *
13*9d7e27acSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9d7e27acSAndrew Rist  * software distributed under the License is distributed on an
15*9d7e27acSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9d7e27acSAndrew Rist  * KIND, either express or implied.  See the License for the
17*9d7e27acSAndrew Rist  * specific language governing permissions and limitations
18*9d7e27acSAndrew Rist  * under the License.
19*9d7e27acSAndrew Rist  *
20*9d7e27acSAndrew Rist  *************************************************************/
21*9d7e27acSAndrew Rist 
22*9d7e27acSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_cppuhelper.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "sal/config.h"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <vector>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <sal/alloca.h>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <osl/diagnose.h>
34cdf0e10cSrcweir #include <rtl/alloc.h>
35cdf0e10cSrcweir #include <rtl/ustring.hxx>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #include <uno/mapping.hxx>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include <cppuhelper/bootstrap.hxx>
40cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
41cdf0e10cSrcweir #include <typelib/typedescription.h>
42cdf0e10cSrcweir 
43cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
44cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
45cdf0e10cSrcweir #include <com/sun/star/reflection/XTypeDescription.hpp>
46cdf0e10cSrcweir #include <com/sun/star/reflection/XEnumTypeDescription.hpp>
47cdf0e10cSrcweir #include <com/sun/star/reflection/XIndirectTypeDescription.hpp>
48cdf0e10cSrcweir #include <com/sun/star/reflection/XInterfaceMemberTypeDescription.hpp>
49cdf0e10cSrcweir #include <com/sun/star/reflection/XInterfaceAttributeTypeDescription2.hpp>
50cdf0e10cSrcweir #include <com/sun/star/reflection/XMethodParameter.hpp>
51cdf0e10cSrcweir #include <com/sun/star/reflection/XInterfaceMethodTypeDescription.hpp>
52cdf0e10cSrcweir #include <com/sun/star/reflection/XInterfaceTypeDescription2.hpp>
53cdf0e10cSrcweir #include <com/sun/star/reflection/XCompoundTypeDescription.hpp>
54cdf0e10cSrcweir #include <com/sun/star/reflection/XStructTypeDescription.hpp>
55cdf0e10cSrcweir #include <com/sun/star/reflection/XUnionTypeDescription.hpp>
56cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
57cdf0e10cSrcweir 
58cdf0e10cSrcweir #include "boost/scoped_array.hpp"
59cdf0e10cSrcweir 
60cdf0e10cSrcweir using namespace ::rtl;
61cdf0e10cSrcweir using namespace ::com::sun::star;
62cdf0e10cSrcweir using namespace ::com::sun::star::uno;
63cdf0e10cSrcweir using namespace ::com::sun::star::reflection;
64cdf0e10cSrcweir 
65cdf0e10cSrcweir 
66cdf0e10cSrcweir namespace cppu
67cdf0e10cSrcweir {
68cdf0e10cSrcweir 
69cdf0e10cSrcweir static typelib_TypeDescription * createCTD(
70cdf0e10cSrcweir     Reference< container::XHierarchicalNameAccess > const & access,
71cdf0e10cSrcweir     const Reference< XTypeDescription > & xType );
72cdf0e10cSrcweir 
73cdf0e10cSrcweir //==================================================================================================
coerceToInt64(const Any & rVal)74cdf0e10cSrcweir inline static sal_Int64 coerceToInt64( const Any & rVal )
75cdf0e10cSrcweir {
76cdf0e10cSrcweir 	switch (rVal.getValueTypeClass())
77cdf0e10cSrcweir 	{
78cdf0e10cSrcweir 	case TypeClass_CHAR:
79cdf0e10cSrcweir 		return *(sal_Unicode *)rVal.getValue();
80cdf0e10cSrcweir 	case TypeClass_BOOLEAN:
81cdf0e10cSrcweir 		return (*(sal_Bool *)rVal.getValue() ? 1 : 0);
82cdf0e10cSrcweir 	case TypeClass_BYTE:
83cdf0e10cSrcweir 		return *(sal_Int8 *)rVal.getValue();
84cdf0e10cSrcweir 	case TypeClass_SHORT:
85cdf0e10cSrcweir 		return *(sal_Int16 *)rVal.getValue();
86cdf0e10cSrcweir 	case TypeClass_UNSIGNED_SHORT:
87cdf0e10cSrcweir 		return *(sal_uInt16 *)rVal.getValue();
88cdf0e10cSrcweir 	case TypeClass_LONG:
89cdf0e10cSrcweir 		return *(sal_Int32 *)rVal.getValue();
90cdf0e10cSrcweir 	case TypeClass_UNSIGNED_LONG:
91cdf0e10cSrcweir 		return *(sal_uInt32 *)rVal.getValue();
92cdf0e10cSrcweir 	case TypeClass_HYPER:
93cdf0e10cSrcweir 		return *(sal_Int64 *)rVal.getValue();
94cdf0e10cSrcweir 	case TypeClass_UNSIGNED_HYPER:
95cdf0e10cSrcweir 		return *(sal_uInt64 *)rVal.getValue();
96cdf0e10cSrcweir 	case TypeClass_ENUM:
97cdf0e10cSrcweir 		return *(int *)rVal.getValue();
98cdf0e10cSrcweir     default:
99cdf0e10cSrcweir         OSL_ASSERT(false);
100cdf0e10cSrcweir         return 0;
101cdf0e10cSrcweir 	}
102cdf0e10cSrcweir }
103cdf0e10cSrcweir //==================================================================================================
createCTD(const Reference<XUnionTypeDescription> & xType)104cdf0e10cSrcweir inline static typelib_TypeDescription * createCTD(
105cdf0e10cSrcweir 	const Reference< XUnionTypeDescription > & xType )
106cdf0e10cSrcweir {
107cdf0e10cSrcweir 	typelib_TypeDescription * pRet = 0;
108cdf0e10cSrcweir 	if (xType.is())
109cdf0e10cSrcweir 	{
110cdf0e10cSrcweir 		OUString aTypeName( xType->getName() );
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 		// discriminant type
113cdf0e10cSrcweir 		Reference< XTypeDescription > xDiscrTD( xType->getDiscriminantType() );
114cdf0e10cSrcweir 		OUString aDiscrTypeName( xDiscrTD->getName() );
115cdf0e10cSrcweir 		typelib_TypeDescriptionReference * pDiscrTypeRef = 0;
116cdf0e10cSrcweir 		typelib_typedescriptionreference_new( &pDiscrTypeRef,
117cdf0e10cSrcweir 											  (typelib_TypeClass)xDiscrTD->getTypeClass(),
118cdf0e10cSrcweir 											  aDiscrTypeName.pData );
119cdf0e10cSrcweir 		// default member type
120cdf0e10cSrcweir 		Reference< XTypeDescription > xDefaultMemberTD( xType->getDefaultMemberType() );
121cdf0e10cSrcweir 		OUString aDefMemberTypeName( xDefaultMemberTD->getName() );
122cdf0e10cSrcweir 		typelib_TypeDescriptionReference * pDefMemberTypeRef = 0;
123cdf0e10cSrcweir 		typelib_typedescriptionreference_new( &pDefMemberTypeRef,
124cdf0e10cSrcweir 											  (typelib_TypeClass)xDefaultMemberTD->getTypeClass(),
125cdf0e10cSrcweir 											  aDefMemberTypeName.pData );
126cdf0e10cSrcweir 		// init array
127cdf0e10cSrcweir 		Sequence< Any > aDiscriminants( xType->getDiscriminants() );
128cdf0e10cSrcweir 		Sequence< Reference< XTypeDescription > > aMemberTypes( xType->getMemberTypes() );
129cdf0e10cSrcweir 		Sequence< OUString > aMemberNames( xType->getMemberNames() );
130cdf0e10cSrcweir 		sal_Int32 nMembers = aDiscriminants.getLength();
131cdf0e10cSrcweir 		OSL_ASSERT( nMembers == aMemberNames.getLength() && nMembers == aMemberTypes.getLength() );
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 		const Any * pDiscriminants							= aDiscriminants.getConstArray();
134cdf0e10cSrcweir 		const Reference< XTypeDescription > * pMemberTypes	= aMemberTypes.getConstArray();
135cdf0e10cSrcweir 		const OUString * pMemberNames						= aMemberNames.getConstArray();
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 		typelib_Union_Init * pMembers = (typelib_Union_Init *)alloca( nMembers * sizeof(typelib_Union_Init) );
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 		sal_Int32 nPos;
140cdf0e10cSrcweir 		for ( nPos = nMembers; nPos--; )
141cdf0e10cSrcweir 		{
142cdf0e10cSrcweir 			typelib_Union_Init & rEntry = pMembers[nPos];
143cdf0e10cSrcweir 			// member discriminant
144cdf0e10cSrcweir 			rEntry.nDiscriminant = coerceToInt64( pDiscriminants[nPos] );
145cdf0e10cSrcweir 			// member type
146cdf0e10cSrcweir 			OUString aMemberTypeName( pMemberTypes[nPos]->getName() );
147cdf0e10cSrcweir 			rEntry.pTypeRef = 0;
148cdf0e10cSrcweir 			typelib_typedescriptionreference_new( &rEntry.pTypeRef,
149cdf0e10cSrcweir 												  (typelib_TypeClass)pMemberTypes[nPos]->getTypeClass(),
150cdf0e10cSrcweir 												  aMemberTypeName.pData );
151cdf0e10cSrcweir 			// member name
152cdf0e10cSrcweir 			rEntry.pMemberName = pMemberNames[nPos].pData;
153cdf0e10cSrcweir 		}
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 		typelib_typedescription_newUnion( &pRet, aTypeName.pData,
156cdf0e10cSrcweir 										  pDiscrTypeRef,
157cdf0e10cSrcweir 										  coerceToInt64( xType->getDefaultDiscriminant() ),
158cdf0e10cSrcweir 										  pDefMemberTypeRef,
159cdf0e10cSrcweir 										  nMembers, pMembers );
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 		for ( nPos = nMembers; nPos--; )
162cdf0e10cSrcweir 		{
163cdf0e10cSrcweir 			typelib_typedescriptionreference_release( pMembers[nPos].pTypeRef );
164cdf0e10cSrcweir 		}
165cdf0e10cSrcweir 
166cdf0e10cSrcweir 		typelib_typedescriptionreference_release( pDiscrTypeRef );
167cdf0e10cSrcweir 		typelib_typedescriptionreference_release( pDefMemberTypeRef );
168cdf0e10cSrcweir 	}
169cdf0e10cSrcweir 	return pRet;
170cdf0e10cSrcweir }
171cdf0e10cSrcweir //==================================================================================================
createCTD(const Reference<XCompoundTypeDescription> & xType)172cdf0e10cSrcweir inline static typelib_TypeDescription * createCTD(
173cdf0e10cSrcweir 	const Reference< XCompoundTypeDescription > & xType )
174cdf0e10cSrcweir {
175cdf0e10cSrcweir 	typelib_TypeDescription * pRet = 0;
176cdf0e10cSrcweir 	if (xType.is())
177cdf0e10cSrcweir 	{
178cdf0e10cSrcweir 		typelib_TypeDescription * pBaseType = createCTD(
179cdf0e10cSrcweir 			Reference< XCompoundTypeDescription >::query( xType->getBaseType() ) );
180cdf0e10cSrcweir 		if (pBaseType)
181cdf0e10cSrcweir 			typelib_typedescription_register( &pBaseType );
182cdf0e10cSrcweir 
183cdf0e10cSrcweir 		// construct member init array
184cdf0e10cSrcweir 		const Sequence<Reference< XTypeDescription > > & rMemberTypes = xType->getMemberTypes();
185cdf0e10cSrcweir 		const Sequence< OUString > & rMemberNames					  = xType->getMemberNames();
186cdf0e10cSrcweir 
187cdf0e10cSrcweir 		const Reference< XTypeDescription > * pMemberTypes = rMemberTypes.getConstArray();
188cdf0e10cSrcweir 		const OUString * pMemberNames					   = rMemberNames.getConstArray();
189cdf0e10cSrcweir 
190cdf0e10cSrcweir 		sal_Int32 nMembers = rMemberTypes.getLength();
191cdf0e10cSrcweir 		OSL_ENSURE( nMembers == rMemberNames.getLength(), "### lens differ!" );
192cdf0e10cSrcweir 
193cdf0e10cSrcweir 		OUString aTypeName( xType->getName() );
194cdf0e10cSrcweir 
195cdf0e10cSrcweir 		typelib_CompoundMember_Init * pMemberInits = (typelib_CompoundMember_Init *)alloca(
196cdf0e10cSrcweir 			sizeof(typelib_CompoundMember_Init) * nMembers );
197cdf0e10cSrcweir 
198cdf0e10cSrcweir 		sal_Int32 nPos;
199cdf0e10cSrcweir 		for ( nPos = nMembers; nPos--; )
200cdf0e10cSrcweir 		{
201cdf0e10cSrcweir 			typelib_CompoundMember_Init & rInit = pMemberInits[nPos];
202cdf0e10cSrcweir 			rInit.eTypeClass = (typelib_TypeClass)pMemberTypes[nPos]->getTypeClass();
203cdf0e10cSrcweir 
204cdf0e10cSrcweir 			OUString aMemberTypeName( pMemberTypes[nPos]->getName() );
205cdf0e10cSrcweir 			rtl_uString_acquire( rInit.pTypeName = aMemberTypeName.pData );
206cdf0e10cSrcweir 
207cdf0e10cSrcweir 			// string is held by rMemberNames
208cdf0e10cSrcweir 			rInit.pMemberName = pMemberNames[nPos].pData;
209cdf0e10cSrcweir 		}
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 		typelib_typedescription_new(
212cdf0e10cSrcweir 			&pRet,
213cdf0e10cSrcweir 			(typelib_TypeClass)xType->getTypeClass(),
214cdf0e10cSrcweir 			aTypeName.pData,
215cdf0e10cSrcweir 			(pBaseType ? pBaseType->pWeakRef : 0),
216cdf0e10cSrcweir 			nMembers, pMemberInits );
217cdf0e10cSrcweir 
218cdf0e10cSrcweir 		// cleanup
219cdf0e10cSrcweir 		for ( nPos = nMembers; nPos--; )
220cdf0e10cSrcweir 		{
221cdf0e10cSrcweir 			rtl_uString_release( pMemberInits[nPos].pTypeName );
222cdf0e10cSrcweir 		}
223cdf0e10cSrcweir 		if (pBaseType)
224cdf0e10cSrcweir 			typelib_typedescription_release( pBaseType );
225cdf0e10cSrcweir 	}
226cdf0e10cSrcweir 	return pRet;
227cdf0e10cSrcweir }
228cdf0e10cSrcweir //==================================================================================================
createCTD(Reference<container::XHierarchicalNameAccess> const & access,const Reference<XStructTypeDescription> & xType)229cdf0e10cSrcweir inline static typelib_TypeDescription * createCTD(
230cdf0e10cSrcweir     Reference< container::XHierarchicalNameAccess > const & access,
231cdf0e10cSrcweir 	const Reference< XStructTypeDescription > & xType )
232cdf0e10cSrcweir {
233cdf0e10cSrcweir 	typelib_TypeDescription * pRet = 0;
234cdf0e10cSrcweir 	if (xType.is() && xType->getTypeParameters().getLength() == 0)
235cdf0e10cSrcweir 	{
236cdf0e10cSrcweir 		typelib_TypeDescription * pBaseType = createCTD(
237cdf0e10cSrcweir             access, xType->getBaseType() );
238cdf0e10cSrcweir 		if (pBaseType)
239cdf0e10cSrcweir 			typelib_typedescription_register( &pBaseType );
240cdf0e10cSrcweir 
241cdf0e10cSrcweir 		// construct member init array
242cdf0e10cSrcweir 		const Sequence<Reference< XTypeDescription > > & rMemberTypes = xType->getMemberTypes();
243cdf0e10cSrcweir 		const Sequence< OUString > & rMemberNames					  = xType->getMemberNames();
244cdf0e10cSrcweir 
245cdf0e10cSrcweir 		const Reference< XTypeDescription > * pMemberTypes = rMemberTypes.getConstArray();
246cdf0e10cSrcweir 		const OUString * pMemberNames					   = rMemberNames.getConstArray();
247cdf0e10cSrcweir 
248cdf0e10cSrcweir 		sal_Int32 nMembers = rMemberTypes.getLength();
249cdf0e10cSrcweir 		OSL_ENSURE( nMembers == rMemberNames.getLength(), "### lens differ!" );
250cdf0e10cSrcweir 
251cdf0e10cSrcweir 		OUString aTypeName( xType->getName() );
252cdf0e10cSrcweir 
253cdf0e10cSrcweir 		typelib_StructMember_Init * pMemberInits = (typelib_StructMember_Init *)alloca(
254cdf0e10cSrcweir 			sizeof(typelib_StructMember_Init) * nMembers );
255cdf0e10cSrcweir 
256cdf0e10cSrcweir         Sequence< Reference< XTypeDescription > > templateMemberTypes;
257cdf0e10cSrcweir         sal_Int32 i = aTypeName.indexOf('<');
258cdf0e10cSrcweir         if (i >= 0) {
259cdf0e10cSrcweir             Reference< XStructTypeDescription > templateDesc(
260cdf0e10cSrcweir                 access->getByHierarchicalName(aTypeName.copy(0, i)),
261cdf0e10cSrcweir                 UNO_QUERY_THROW);
262cdf0e10cSrcweir             OSL_ASSERT(
263cdf0e10cSrcweir                 templateDesc->getTypeParameters().getLength()
264cdf0e10cSrcweir                 == xType->getTypeArguments().getLength());
265cdf0e10cSrcweir             templateMemberTypes = templateDesc->getMemberTypes();
266cdf0e10cSrcweir             OSL_ASSERT(templateMemberTypes.getLength() == nMembers);
267cdf0e10cSrcweir         }
268cdf0e10cSrcweir 
269cdf0e10cSrcweir 		sal_Int32 nPos;
270cdf0e10cSrcweir 		for ( nPos = nMembers; nPos--; )
271cdf0e10cSrcweir 		{
272cdf0e10cSrcweir 			typelib_StructMember_Init & rInit = pMemberInits[nPos];
273cdf0e10cSrcweir 			rInit.aBase.eTypeClass
274cdf0e10cSrcweir                 = (typelib_TypeClass)pMemberTypes[nPos]->getTypeClass();
275cdf0e10cSrcweir 
276cdf0e10cSrcweir 			OUString aMemberTypeName( pMemberTypes[nPos]->getName() );
277cdf0e10cSrcweir 			rtl_uString_acquire(
278cdf0e10cSrcweir                 rInit.aBase.pTypeName = aMemberTypeName.pData );
279cdf0e10cSrcweir 
280cdf0e10cSrcweir 			// string is held by rMemberNames
281cdf0e10cSrcweir 			rInit.aBase.pMemberName = pMemberNames[nPos].pData;
282cdf0e10cSrcweir 
283cdf0e10cSrcweir             rInit.bParameterizedType = templateMemberTypes.getLength() != 0
284cdf0e10cSrcweir                 && (templateMemberTypes[nPos]->getTypeClass()
285cdf0e10cSrcweir                     == TypeClass_UNKNOWN);
286cdf0e10cSrcweir 		}
287cdf0e10cSrcweir 
288cdf0e10cSrcweir 		typelib_typedescription_newStruct(
289cdf0e10cSrcweir 			&pRet,
290cdf0e10cSrcweir 			aTypeName.pData,
291cdf0e10cSrcweir 			(pBaseType ? pBaseType->pWeakRef : 0),
292cdf0e10cSrcweir 			nMembers, pMemberInits );
293cdf0e10cSrcweir 
294cdf0e10cSrcweir 		// cleanup
295cdf0e10cSrcweir 		for ( nPos = nMembers; nPos--; )
296cdf0e10cSrcweir 		{
297cdf0e10cSrcweir 			rtl_uString_release( pMemberInits[nPos].aBase.pTypeName );
298cdf0e10cSrcweir 		}
299cdf0e10cSrcweir 		if (pBaseType)
300cdf0e10cSrcweir 			typelib_typedescription_release( pBaseType );
301cdf0e10cSrcweir 	}
302cdf0e10cSrcweir 	return pRet;
303cdf0e10cSrcweir }
304cdf0e10cSrcweir //==================================================================================================
createCTD(const Reference<XInterfaceAttributeTypeDescription2> & xAttribute)305cdf0e10cSrcweir inline static typelib_TypeDescription * createCTD(
306cdf0e10cSrcweir 	const Reference< XInterfaceAttributeTypeDescription2 > & xAttribute )
307cdf0e10cSrcweir {
308cdf0e10cSrcweir 	typelib_TypeDescription * pRet = 0;
309cdf0e10cSrcweir 	if (xAttribute.is())
310cdf0e10cSrcweir 	{
311cdf0e10cSrcweir 		OUString aMemberName( xAttribute->getName() );
312cdf0e10cSrcweir 		Reference< XTypeDescription > xType( xAttribute->getType() );
313cdf0e10cSrcweir 		OUString aMemberTypeName( xType->getName() );
314cdf0e10cSrcweir         std::vector< rtl_uString * > getExc;
315cdf0e10cSrcweir         Sequence< Reference< XCompoundTypeDescription > > getExcs(
316cdf0e10cSrcweir             xAttribute->getGetExceptions() );
317cdf0e10cSrcweir         for (sal_Int32 i = 0; i != getExcs.getLength(); ++i)
318cdf0e10cSrcweir         {
319cdf0e10cSrcweir             OSL_ASSERT( getExcs[i].is() );
320cdf0e10cSrcweir             getExc.push_back( getExcs[i]->getName().pData );
321cdf0e10cSrcweir         }
322cdf0e10cSrcweir         std::vector< rtl_uString * > setExc;
323cdf0e10cSrcweir         Sequence< Reference< XCompoundTypeDescription > > setExcs(
324cdf0e10cSrcweir             xAttribute->getSetExceptions() );
325cdf0e10cSrcweir         for (sal_Int32 i = 0; i != setExcs.getLength(); ++i)
326cdf0e10cSrcweir         {
327cdf0e10cSrcweir             OSL_ASSERT( setExcs[i].is() );
328cdf0e10cSrcweir             setExc.push_back( setExcs[i]->getName().pData );
329cdf0e10cSrcweir         }
330cdf0e10cSrcweir 		typelib_typedescription_newExtendedInterfaceAttribute(
331cdf0e10cSrcweir 			(typelib_InterfaceAttributeTypeDescription **)&pRet,
332cdf0e10cSrcweir 			xAttribute->getPosition(),
333cdf0e10cSrcweir 			aMemberName.pData, // name
334cdf0e10cSrcweir 			(typelib_TypeClass)xType->getTypeClass(),
335cdf0e10cSrcweir 			aMemberTypeName.pData, // type name
336cdf0e10cSrcweir 			xAttribute->isReadOnly(),
337cdf0e10cSrcweir             getExc.size(), getExc.empty() ? 0 : &getExc[0],
338cdf0e10cSrcweir             setExc.size(), setExc.empty() ? 0 : &setExc[0] );
339cdf0e10cSrcweir 	}
340cdf0e10cSrcweir 	return pRet;
341cdf0e10cSrcweir }
342cdf0e10cSrcweir //==================================================================================================
createCTD(const Reference<XInterfaceMethodTypeDescription> & xMethod)343cdf0e10cSrcweir static typelib_TypeDescription * createCTD(
344cdf0e10cSrcweir 	const Reference< XInterfaceMethodTypeDescription > & xMethod )
345cdf0e10cSrcweir {
346cdf0e10cSrcweir 	typelib_TypeDescription * pRet = 0;
347cdf0e10cSrcweir 	if (xMethod.is())
348cdf0e10cSrcweir 	{
349cdf0e10cSrcweir 		Reference< XTypeDescription > xReturnType( xMethod->getReturnType() );
350cdf0e10cSrcweir 
351cdf0e10cSrcweir 		// init all params
352cdf0e10cSrcweir 		const Sequence<Reference< XMethodParameter > > & rParams = xMethod->getParameters();
353cdf0e10cSrcweir 		const Reference< XMethodParameter > * pParams			 = rParams.getConstArray();
354cdf0e10cSrcweir 		sal_Int32 nParams = rParams.getLength();
355cdf0e10cSrcweir 
356cdf0e10cSrcweir 		typelib_Parameter_Init * pParamInit = (typelib_Parameter_Init *)alloca(
357cdf0e10cSrcweir 			sizeof(typelib_Parameter_Init) * nParams );
358cdf0e10cSrcweir 
359cdf0e10cSrcweir 		sal_Int32 nPos;
360cdf0e10cSrcweir 		for ( nPos = nParams; nPos--; )
361cdf0e10cSrcweir 		{
362cdf0e10cSrcweir 			const Reference< XMethodParameter > & xParam = pParams[nPos];
363cdf0e10cSrcweir 			const Reference< XTypeDescription > & xType	 = xParam->getType();
364cdf0e10cSrcweir 			typelib_Parameter_Init & rInit = pParamInit[xParam->getPosition()];
365cdf0e10cSrcweir 
366cdf0e10cSrcweir 			rInit.eTypeClass = (typelib_TypeClass)xType->getTypeClass();
367cdf0e10cSrcweir 			OUString aParamTypeName( xType->getName() );
368cdf0e10cSrcweir 			rtl_uString_acquire( rInit.pTypeName = aParamTypeName.pData );
369cdf0e10cSrcweir 			OUString aParamName( xParam->getName() );
370cdf0e10cSrcweir 			rtl_uString_acquire( rInit.pParamName = aParamName.pData );
371cdf0e10cSrcweir 			rInit.bIn  = xParam->isIn();
372cdf0e10cSrcweir 			rInit.bOut = xParam->isOut();
373cdf0e10cSrcweir 		}
374cdf0e10cSrcweir 
375cdf0e10cSrcweir 		// init all exception strings
376cdf0e10cSrcweir 		const Sequence<Reference< XTypeDescription > > & rExceptions = xMethod->getExceptions();
377cdf0e10cSrcweir 		const Reference< XTypeDescription > * pExceptions = rExceptions.getConstArray();
378cdf0e10cSrcweir 		sal_Int32 nExceptions = rExceptions.getLength();
379cdf0e10cSrcweir 		rtl_uString ** ppExceptionNames = (rtl_uString **)alloca(
380cdf0e10cSrcweir 			sizeof(rtl_uString *) * nExceptions );
381cdf0e10cSrcweir 
382cdf0e10cSrcweir 		for ( nPos = nExceptions; nPos--; )
383cdf0e10cSrcweir 		{
384cdf0e10cSrcweir 			OUString aExceptionTypeName( pExceptions[nPos]->getName() );
385cdf0e10cSrcweir 			rtl_uString_acquire( ppExceptionNames[nPos] = aExceptionTypeName.pData );
386cdf0e10cSrcweir 		}
387cdf0e10cSrcweir 
388cdf0e10cSrcweir 		OUString aTypeName( xMethod->getName() );
389cdf0e10cSrcweir 		OUString aReturnTypeName( xReturnType->getName() );
390cdf0e10cSrcweir 
391cdf0e10cSrcweir 		typelib_typedescription_newInterfaceMethod(
392cdf0e10cSrcweir 			(typelib_InterfaceMethodTypeDescription **)&pRet,
393cdf0e10cSrcweir 			xMethod->getPosition(),
394cdf0e10cSrcweir 			xMethod->isOneway(),
395cdf0e10cSrcweir 			aTypeName.pData,
396cdf0e10cSrcweir 			(typelib_TypeClass)xReturnType->getTypeClass(),
397cdf0e10cSrcweir 			aReturnTypeName.pData,
398cdf0e10cSrcweir 			nParams, pParamInit,
399cdf0e10cSrcweir 			nExceptions, ppExceptionNames );
400cdf0e10cSrcweir 
401cdf0e10cSrcweir 		for ( nPos = nParams; nPos--; )
402cdf0e10cSrcweir 		{
403cdf0e10cSrcweir 			rtl_uString_release( pParamInit[nPos].pTypeName );
404cdf0e10cSrcweir 			rtl_uString_release( pParamInit[nPos].pParamName );
405cdf0e10cSrcweir 		}
406cdf0e10cSrcweir 		for ( nPos = nExceptions; nPos--; )
407cdf0e10cSrcweir 		{
408cdf0e10cSrcweir 			rtl_uString_release( ppExceptionNames[nPos] );
409cdf0e10cSrcweir 		}
410cdf0e10cSrcweir 	}
411cdf0e10cSrcweir 	return pRet;
412cdf0e10cSrcweir }
413cdf0e10cSrcweir //==================================================================================================
createCTD(Reference<container::XHierarchicalNameAccess> const & access,const Reference<XInterfaceTypeDescription2> & xType)414cdf0e10cSrcweir inline static typelib_TypeDescription * createCTD(
415cdf0e10cSrcweir     Reference< container::XHierarchicalNameAccess > const & access,
416cdf0e10cSrcweir 	const Reference< XInterfaceTypeDescription2 > & xType )
417cdf0e10cSrcweir {
418cdf0e10cSrcweir 	typelib_TypeDescription * pRet = 0;
419cdf0e10cSrcweir 	if (xType.is())
420cdf0e10cSrcweir 	{
421cdf0e10cSrcweir         Sequence< Reference< XTypeDescription > > aBases(xType->getBaseTypes());
422cdf0e10cSrcweir         sal_Int32 nBases = aBases.getLength();
423cdf0e10cSrcweir         // Exploit the fact that a typelib_TypeDescription for an interface type
424cdf0e10cSrcweir         // is also the typelib_TypeDescriptionReference for that type:
425cdf0e10cSrcweir         boost::scoped_array< typelib_TypeDescription * > aBaseTypes(
426cdf0e10cSrcweir             new typelib_TypeDescription *[nBases]);
427cdf0e10cSrcweir         {for (sal_Int32 i = 0; i < nBases; ++i) {
428cdf0e10cSrcweir             typelib_TypeDescription * p = createCTD(access, aBases[i]);
429cdf0e10cSrcweir             OSL_ASSERT(
430cdf0e10cSrcweir                 !TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(p->eTypeClass));
431cdf0e10cSrcweir             typelib_typedescription_register(&p);
432cdf0e10cSrcweir             aBaseTypes[i] = p;
433cdf0e10cSrcweir         }}
434cdf0e10cSrcweir         typelib_TypeDescriptionReference ** pBaseTypeRefs
435cdf0e10cSrcweir             = reinterpret_cast< typelib_TypeDescriptionReference ** >(
436cdf0e10cSrcweir                 aBaseTypes.get());
437cdf0e10cSrcweir 
438cdf0e10cSrcweir 		// construct all member refs
439cdf0e10cSrcweir 		const Sequence<Reference< XInterfaceMemberTypeDescription > > & rMembers = xType->getMembers();
440cdf0e10cSrcweir 		sal_Int32 nMembers = rMembers.getLength();
441cdf0e10cSrcweir 
442cdf0e10cSrcweir 		typelib_TypeDescriptionReference ** ppMemberRefs = (typelib_TypeDescriptionReference **)alloca(
443cdf0e10cSrcweir 			sizeof(typelib_TypeDescriptionReference *) * nMembers );
444cdf0e10cSrcweir 
445cdf0e10cSrcweir 		const Reference< XInterfaceMemberTypeDescription > * pMembers = rMembers.getConstArray();
446cdf0e10cSrcweir 
447cdf0e10cSrcweir 		OUString aTypeName( xType->getName() );
448cdf0e10cSrcweir 
449cdf0e10cSrcweir 		sal_Int32 nPos;
450cdf0e10cSrcweir 		for ( nPos = nMembers; nPos--; )
451cdf0e10cSrcweir 		{
452cdf0e10cSrcweir 			OUString aMemberTypeName( pMembers[nPos]->getName() );
453cdf0e10cSrcweir 			ppMemberRefs[nPos] = 0;
454cdf0e10cSrcweir 			typelib_typedescriptionreference_new(
455cdf0e10cSrcweir 				ppMemberRefs + nPos,
456cdf0e10cSrcweir 				(typelib_TypeClass)pMembers[nPos]->getTypeClass(),
457cdf0e10cSrcweir 				aMemberTypeName.pData );
458cdf0e10cSrcweir 		}
459cdf0e10cSrcweir 
460cdf0e10cSrcweir 		Uik uik = xType->getUik();
461cdf0e10cSrcweir 
462cdf0e10cSrcweir 		typelib_typedescription_newMIInterface(
463cdf0e10cSrcweir 			(typelib_InterfaceTypeDescription **)&pRet,
464cdf0e10cSrcweir 			aTypeName.pData,
465cdf0e10cSrcweir 			uik.m_Data1, uik.m_Data2, uik.m_Data3, uik.m_Data4, uik.m_Data5,
466cdf0e10cSrcweir             nBases, pBaseTypeRefs,
467cdf0e10cSrcweir 			nMembers, ppMemberRefs );
468cdf0e10cSrcweir 
469cdf0e10cSrcweir 		// cleanup refs and base type
470cdf0e10cSrcweir         {for (int i = 0; i < nBases; ++i) {
471cdf0e10cSrcweir             typelib_typedescription_release(aBaseTypes[i]);
472cdf0e10cSrcweir         }}
473cdf0e10cSrcweir 
474cdf0e10cSrcweir 		for ( nPos = nMembers; nPos--; )
475cdf0e10cSrcweir 		{
476cdf0e10cSrcweir 			typelib_typedescriptionreference_release( ppMemberRefs[nPos] );
477cdf0e10cSrcweir 		}
478cdf0e10cSrcweir 	}
479cdf0e10cSrcweir 	return pRet;
480cdf0e10cSrcweir }
481cdf0e10cSrcweir //==================================================================================================
createCTD(const Reference<XEnumTypeDescription> & xType)482cdf0e10cSrcweir inline static typelib_TypeDescription * createCTD( const Reference< XEnumTypeDescription > & xType )
483cdf0e10cSrcweir {
484cdf0e10cSrcweir 	typelib_TypeDescription * pRet = 0;
485cdf0e10cSrcweir 	if (xType.is())
486cdf0e10cSrcweir 	{
487cdf0e10cSrcweir 		OUString aTypeName( xType->getName() );
488cdf0e10cSrcweir 		Sequence< OUString > aNames( xType->getEnumNames() );
489cdf0e10cSrcweir 		OSL_ASSERT( sizeof(OUString) == sizeof(rtl_uString *) ); // !!!
490cdf0e10cSrcweir 		Sequence< sal_Int32 > aValues( xType->getEnumValues() );
491cdf0e10cSrcweir 
492cdf0e10cSrcweir 		typelib_typedescription_newEnum(
493cdf0e10cSrcweir 			&pRet, aTypeName.pData, xType->getDefaultEnumValue(),
494cdf0e10cSrcweir 			aNames.getLength(),
495cdf0e10cSrcweir 			(rtl_uString **)aNames.getConstArray(),
496cdf0e10cSrcweir 			const_cast< sal_Int32 * >( aValues.getConstArray() ) );
497cdf0e10cSrcweir 	}
498cdf0e10cSrcweir 	return pRet;
499cdf0e10cSrcweir }
500cdf0e10cSrcweir //==================================================================================================
createCTD(Reference<container::XHierarchicalNameAccess> const & access,const Reference<XIndirectTypeDescription> & xType)501cdf0e10cSrcweir inline static typelib_TypeDescription * createCTD(
502cdf0e10cSrcweir     Reference< container::XHierarchicalNameAccess > const & access,
503cdf0e10cSrcweir 	const Reference< XIndirectTypeDescription > & xType )
504cdf0e10cSrcweir {
505cdf0e10cSrcweir 	typelib_TypeDescription * pRet = 0;
506cdf0e10cSrcweir 	if (xType.is())
507cdf0e10cSrcweir 	{
508cdf0e10cSrcweir 		typelib_TypeDescription * pRefType = createCTD(
509cdf0e10cSrcweir             access, xType->getReferencedType() );
510cdf0e10cSrcweir 		typelib_typedescription_register( &pRefType );
511cdf0e10cSrcweir 
512cdf0e10cSrcweir 		OUString aTypeName( xType->getName() );
513cdf0e10cSrcweir 
514cdf0e10cSrcweir 		typelib_typedescription_new(
515cdf0e10cSrcweir 			&pRet,
516cdf0e10cSrcweir 			(typelib_TypeClass)xType->getTypeClass(),
517cdf0e10cSrcweir 			aTypeName.pData,
518cdf0e10cSrcweir 			pRefType->pWeakRef,
519cdf0e10cSrcweir 			0, 0 );
520cdf0e10cSrcweir 
521cdf0e10cSrcweir 		// cleanup
522cdf0e10cSrcweir 		if (pRefType)
523cdf0e10cSrcweir 			typelib_typedescription_release( pRefType );
524cdf0e10cSrcweir 	}
525cdf0e10cSrcweir 	return pRet;
526cdf0e10cSrcweir }
527cdf0e10cSrcweir 
528cdf0e10cSrcweir //==================================================================================================
createCTD(Reference<container::XHierarchicalNameAccess> const & access,const Reference<XTypeDescription> & xType)529cdf0e10cSrcweir static typelib_TypeDescription * createCTD(
530cdf0e10cSrcweir     Reference< container::XHierarchicalNameAccess > const & access,
531cdf0e10cSrcweir     const Reference< XTypeDescription > & xType )
532cdf0e10cSrcweir {
533cdf0e10cSrcweir 	typelib_TypeDescription * pRet = 0;
534cdf0e10cSrcweir 
535cdf0e10cSrcweir 	if (xType.is())
536cdf0e10cSrcweir 	{
537cdf0e10cSrcweir 		switch (xType->getTypeClass())
538cdf0e10cSrcweir 		{
539cdf0e10cSrcweir 			// built in types
540cdf0e10cSrcweir 		case TypeClass_VOID:
541cdf0e10cSrcweir 		{
542cdf0e10cSrcweir 			OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("void") );
543cdf0e10cSrcweir 			typelib_typedescription_new( &pRet, typelib_TypeClass_VOID, aTypeName.pData, 0, 0, 0 );
544cdf0e10cSrcweir 			break;
545cdf0e10cSrcweir 		}
546cdf0e10cSrcweir 		case TypeClass_CHAR:
547cdf0e10cSrcweir 		{
548cdf0e10cSrcweir 			OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("char") );
549cdf0e10cSrcweir 			typelib_typedescription_new( &pRet, typelib_TypeClass_CHAR, aTypeName.pData, 0, 0, 0 );
550cdf0e10cSrcweir 			break;
551cdf0e10cSrcweir 		}
552cdf0e10cSrcweir 		case TypeClass_BOOLEAN:
553cdf0e10cSrcweir 		{
554cdf0e10cSrcweir 			OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("boolean") );
555cdf0e10cSrcweir 			typelib_typedescription_new( &pRet, typelib_TypeClass_BOOLEAN, aTypeName.pData, 0, 0, 0 );
556cdf0e10cSrcweir 			break;
557cdf0e10cSrcweir 		}
558cdf0e10cSrcweir 		case TypeClass_BYTE:
559cdf0e10cSrcweir 		{
560cdf0e10cSrcweir 			OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("byte") );
561cdf0e10cSrcweir 			typelib_typedescription_new( &pRet, typelib_TypeClass_BYTE, aTypeName.pData, 0, 0, 0 );
562cdf0e10cSrcweir 			break;
563cdf0e10cSrcweir 		}
564cdf0e10cSrcweir 		case TypeClass_SHORT:
565cdf0e10cSrcweir 		{
566cdf0e10cSrcweir 			OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("short") );
567cdf0e10cSrcweir 			typelib_typedescription_new( &pRet, typelib_TypeClass_SHORT, aTypeName.pData, 0, 0, 0 );
568cdf0e10cSrcweir 			break;
569cdf0e10cSrcweir 		}
570cdf0e10cSrcweir 		case TypeClass_UNSIGNED_SHORT:
571cdf0e10cSrcweir 		{
572cdf0e10cSrcweir 			OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("unsigned short") );
573cdf0e10cSrcweir 			typelib_typedescription_new( &pRet, typelib_TypeClass_UNSIGNED_SHORT, aTypeName.pData, 0, 0, 0 );
574cdf0e10cSrcweir 			break;
575cdf0e10cSrcweir 		}
576cdf0e10cSrcweir 		case TypeClass_LONG:
577cdf0e10cSrcweir 		{
578cdf0e10cSrcweir 			OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("long") );
579cdf0e10cSrcweir 			typelib_typedescription_new( &pRet, typelib_TypeClass_LONG, aTypeName.pData, 0, 0, 0 );
580cdf0e10cSrcweir 			break;
581cdf0e10cSrcweir 		}
582cdf0e10cSrcweir 		case TypeClass_UNSIGNED_LONG:
583cdf0e10cSrcweir 		{
584cdf0e10cSrcweir 			OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("unsigned long") );
585cdf0e10cSrcweir 			typelib_typedescription_new( &pRet, typelib_TypeClass_UNSIGNED_LONG, aTypeName.pData, 0, 0, 0 );
586cdf0e10cSrcweir 			break;
587cdf0e10cSrcweir 		}
588cdf0e10cSrcweir 		case TypeClass_HYPER:
589cdf0e10cSrcweir 		{
590cdf0e10cSrcweir 			OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("hyper") );
591cdf0e10cSrcweir 			typelib_typedescription_new( &pRet, typelib_TypeClass_HYPER, aTypeName.pData, 0, 0, 0 );
592cdf0e10cSrcweir 			break;
593cdf0e10cSrcweir 		}
594cdf0e10cSrcweir 		case TypeClass_UNSIGNED_HYPER:
595cdf0e10cSrcweir 		{
596cdf0e10cSrcweir 			OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("unsigned hyper") );
597cdf0e10cSrcweir 			typelib_typedescription_new( &pRet, typelib_TypeClass_UNSIGNED_HYPER, aTypeName.pData, 0, 0, 0 );
598cdf0e10cSrcweir 			break;
599cdf0e10cSrcweir 		}
600cdf0e10cSrcweir 		case TypeClass_FLOAT:
601cdf0e10cSrcweir 		{
602cdf0e10cSrcweir 			OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("float") );
603cdf0e10cSrcweir 			typelib_typedescription_new( &pRet, typelib_TypeClass_FLOAT, aTypeName.pData, 0, 0, 0 );
604cdf0e10cSrcweir 			break;
605cdf0e10cSrcweir 		}
606cdf0e10cSrcweir 		case TypeClass_DOUBLE:
607cdf0e10cSrcweir 		{
608cdf0e10cSrcweir 			OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("double") );
609cdf0e10cSrcweir 			typelib_typedescription_new( &pRet, typelib_TypeClass_DOUBLE, aTypeName.pData, 0, 0, 0 );
610cdf0e10cSrcweir 			break;
611cdf0e10cSrcweir 		}
612cdf0e10cSrcweir 		case TypeClass_STRING:
613cdf0e10cSrcweir 		{
614cdf0e10cSrcweir 			OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("string") );
615cdf0e10cSrcweir 			typelib_typedescription_new( &pRet, typelib_TypeClass_STRING, aTypeName.pData, 0, 0, 0 );
616cdf0e10cSrcweir 			break;
617cdf0e10cSrcweir 		}
618cdf0e10cSrcweir 		case TypeClass_TYPE:
619cdf0e10cSrcweir 		{
620cdf0e10cSrcweir 			OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("type") );
621cdf0e10cSrcweir 			typelib_typedescription_new( &pRet, typelib_TypeClass_TYPE, aTypeName.pData, 0, 0, 0 );
622cdf0e10cSrcweir 			break;
623cdf0e10cSrcweir 		}
624cdf0e10cSrcweir 		case TypeClass_ANY:
625cdf0e10cSrcweir 		{
626cdf0e10cSrcweir 			OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("any") );
627cdf0e10cSrcweir 			typelib_typedescription_new( &pRet, typelib_TypeClass_ANY, aTypeName.pData, 0, 0, 0 );
628cdf0e10cSrcweir 			break;
629cdf0e10cSrcweir 		}
630cdf0e10cSrcweir 
631cdf0e10cSrcweir 		case TypeClass_UNION:
632cdf0e10cSrcweir 			pRet = createCTD( Reference< XUnionTypeDescription >::query( xType ) );
633cdf0e10cSrcweir 			break;
634cdf0e10cSrcweir 		case TypeClass_EXCEPTION:
635cdf0e10cSrcweir 			pRet = createCTD( Reference< XCompoundTypeDescription >::query( xType ) );
636cdf0e10cSrcweir 			break;
637cdf0e10cSrcweir 		case TypeClass_STRUCT:
638cdf0e10cSrcweir 			pRet = createCTD(
639cdf0e10cSrcweir                 access, Reference< XStructTypeDescription >::query( xType ) );
640cdf0e10cSrcweir 			break;
641cdf0e10cSrcweir 		case TypeClass_ENUM:
642cdf0e10cSrcweir 			pRet = createCTD( Reference< XEnumTypeDescription >::query( xType ) );
643cdf0e10cSrcweir 			break;
644cdf0e10cSrcweir 		case TypeClass_TYPEDEF:
645cdf0e10cSrcweir 		{
646cdf0e10cSrcweir 			Reference< XIndirectTypeDescription > xTypedef( xType, UNO_QUERY );
647cdf0e10cSrcweir 			if (xTypedef.is())
648cdf0e10cSrcweir 				pRet = createCTD( access, xTypedef->getReferencedType() );
649cdf0e10cSrcweir 			break;
650cdf0e10cSrcweir 		}
651cdf0e10cSrcweir 		case TypeClass_SEQUENCE:
652cdf0e10cSrcweir 			pRet = createCTD(
653cdf0e10cSrcweir                 access, Reference< XIndirectTypeDescription >::query( xType ) );
654cdf0e10cSrcweir 			break;
655cdf0e10cSrcweir 		case TypeClass_INTERFACE:
656cdf0e10cSrcweir 			pRet = createCTD(
657cdf0e10cSrcweir                 access,
658cdf0e10cSrcweir                 Reference< XInterfaceTypeDescription2 >::query( xType ) );
659cdf0e10cSrcweir 			break;
660cdf0e10cSrcweir 		case TypeClass_INTERFACE_METHOD:
661cdf0e10cSrcweir 			pRet = createCTD( Reference< XInterfaceMethodTypeDescription >::query( xType ) );
662cdf0e10cSrcweir 			break;
663cdf0e10cSrcweir 		case TypeClass_INTERFACE_ATTRIBUTE:
664cdf0e10cSrcweir 			pRet = createCTD( Reference< XInterfaceAttributeTypeDescription2 >::query( xType ) );
665cdf0e10cSrcweir 			break;
666cdf0e10cSrcweir         default:
667cdf0e10cSrcweir             break;
668cdf0e10cSrcweir 		}
669cdf0e10cSrcweir 	}
670cdf0e10cSrcweir 
671cdf0e10cSrcweir 	return pRet;
672cdf0e10cSrcweir }
673cdf0e10cSrcweir 
674cdf0e10cSrcweir 
675cdf0e10cSrcweir //==================================================================================================
676cdf0e10cSrcweir extern "C"
677cdf0e10cSrcweir {
typelib_callback(void * pContext,typelib_TypeDescription ** ppRet,rtl_uString * pTypeName)678cdf0e10cSrcweir static void SAL_CALL typelib_callback(
679cdf0e10cSrcweir     void * pContext, typelib_TypeDescription ** ppRet, rtl_uString * pTypeName )
680cdf0e10cSrcweir {
681cdf0e10cSrcweir 	OSL_ENSURE( pContext && ppRet && pTypeName, "### null ptr!" );
682cdf0e10cSrcweir 	if (ppRet)
683cdf0e10cSrcweir 	{
684cdf0e10cSrcweir 		if (*ppRet)
685cdf0e10cSrcweir 		{
686cdf0e10cSrcweir 			::typelib_typedescription_release( *ppRet );
687cdf0e10cSrcweir 			*ppRet = 0;
688cdf0e10cSrcweir 		}
689cdf0e10cSrcweir 		if (pContext && pTypeName)
690cdf0e10cSrcweir 		{
691cdf0e10cSrcweir             Reference< container::XHierarchicalNameAccess > access(
692cdf0e10cSrcweir                 reinterpret_cast< container::XHierarchicalNameAccess * >(
693cdf0e10cSrcweir                     pContext));
694cdf0e10cSrcweir 			try
695cdf0e10cSrcweir 			{
696cdf0e10cSrcweir                 OUString const & rTypeName = OUString::unacquired( &pTypeName );
697cdf0e10cSrcweir 				Reference< XTypeDescription > xTD;
698cdf0e10cSrcweir 				if (access->getByHierarchicalName(rTypeName ) >>= xTD)
699cdf0e10cSrcweir 				{
700cdf0e10cSrcweir 					*ppRet = createCTD( access, xTD );
701cdf0e10cSrcweir 				}
702cdf0e10cSrcweir 			}
703cdf0e10cSrcweir             catch (container::NoSuchElementException & exc)
704cdf0e10cSrcweir             {
705cdf0e10cSrcweir                 (void) exc; // avoid warning about unused variable
706cdf0e10cSrcweir                 OSL_TRACE(
707cdf0e10cSrcweir                     "typelibrary type not available: %s",
708cdf0e10cSrcweir                     OUStringToOString(
709cdf0e10cSrcweir                         exc.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
710cdf0e10cSrcweir             }
711cdf0e10cSrcweir 			catch (Exception & exc)
712cdf0e10cSrcweir 			{
713cdf0e10cSrcweir                 (void) exc; // avoid warning about unused variable
714cdf0e10cSrcweir                 OSL_TRACE(
715cdf0e10cSrcweir                     "%s",
716cdf0e10cSrcweir                     OUStringToOString(
717cdf0e10cSrcweir                         exc.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
718cdf0e10cSrcweir 			}
719cdf0e10cSrcweir 		}
720cdf0e10cSrcweir 	}
721cdf0e10cSrcweir }
722cdf0e10cSrcweir }
723cdf0e10cSrcweir 
724cdf0e10cSrcweir //==================================================================================================
725cdf0e10cSrcweir class EventListenerImpl
726cdf0e10cSrcweir     : public WeakImplHelper1< lang::XEventListener >
727cdf0e10cSrcweir {
728cdf0e10cSrcweir     Reference< container::XHierarchicalNameAccess > m_xTDMgr;
729cdf0e10cSrcweir 
730cdf0e10cSrcweir public:
731cdf0e10cSrcweir 	inline EventListenerImpl(
732cdf0e10cSrcweir         Reference< container::XHierarchicalNameAccess > const & xTDMgr )
733cdf0e10cSrcweir         SAL_THROW( () )
734cdf0e10cSrcweir         : m_xTDMgr( xTDMgr )
735cdf0e10cSrcweir 		{}
736cdf0e10cSrcweir 
737cdf0e10cSrcweir 	// XEventListener
738cdf0e10cSrcweir 	virtual void SAL_CALL disposing( lang::EventObject const & rEvt )
739cdf0e10cSrcweir         throw (RuntimeException);
740cdf0e10cSrcweir };
741cdf0e10cSrcweir //__________________________________________________________________________________________________
disposing(lang::EventObject const & rEvt)742cdf0e10cSrcweir void EventListenerImpl::disposing( lang::EventObject const & rEvt )
743cdf0e10cSrcweir     throw (RuntimeException)
744cdf0e10cSrcweir {
745cdf0e10cSrcweir     if (rEvt.Source != m_xTDMgr) {
746cdf0e10cSrcweir         OSL_ASSERT(false);
747cdf0e10cSrcweir     }
748cdf0e10cSrcweir 	// deregister of c typelib callback
749cdf0e10cSrcweir 	::typelib_typedescription_revokeCallback( m_xTDMgr.get(), typelib_callback );
750cdf0e10cSrcweir }
751cdf0e10cSrcweir 
752cdf0e10cSrcweir //==================================================================================================
installTypeDescriptionManager(Reference<container::XHierarchicalNameAccess> const & xTDMgr_c)753cdf0e10cSrcweir sal_Bool SAL_CALL installTypeDescriptionManager(
754cdf0e10cSrcweir     Reference< container::XHierarchicalNameAccess > const & xTDMgr_c )
755cdf0e10cSrcweir     SAL_THROW( () )
756cdf0e10cSrcweir {
757cdf0e10cSrcweir 	uno::Environment curr_env(Environment::getCurrent());
758cdf0e10cSrcweir 	uno::Environment target_env(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(CPPU_STRINGIFY(CPPU_ENV))));
759cdf0e10cSrcweir 
760cdf0e10cSrcweir 	uno::Mapping curr2target(curr_env, target_env);
761cdf0e10cSrcweir 
762cdf0e10cSrcweir 
763cdf0e10cSrcweir 	Reference<container::XHierarchicalNameAccess> xTDMgr(
764cdf0e10cSrcweir 		reinterpret_cast<container::XHierarchicalNameAccess *>(
765cdf0e10cSrcweir 			curr2target.mapInterface(xTDMgr_c.get(), ::getCppuType(&xTDMgr_c))),
766cdf0e10cSrcweir 		SAL_NO_ACQUIRE);
767cdf0e10cSrcweir 
768cdf0e10cSrcweir     Reference< lang::XComponent > xComp( xTDMgr, UNO_QUERY );
769cdf0e10cSrcweir     if (xComp.is())
770cdf0e10cSrcweir     {
771cdf0e10cSrcweir         xComp->addEventListener( new EventListenerImpl( xTDMgr ) );
772cdf0e10cSrcweir         // register c typelib callback
773cdf0e10cSrcweir         ::typelib_typedescription_registerCallback( xTDMgr.get(), typelib_callback );
774cdf0e10cSrcweir         return sal_True;
775cdf0e10cSrcweir     }
776cdf0e10cSrcweir     return sal_False;
777cdf0e10cSrcweir }
778cdf0e10cSrcweir 
779cdf0e10cSrcweir } // end namespace cppu
780cdf0e10cSrcweir 
781