1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tdmgr.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_cppuhelper.hxx"
33 #include <sal/alloca.h>
35 #include <osl/diagnose.h>
36 #include <rtl/alloc.h>
37 #include <rtl/ustring.hxx>
39 #include <uno/mapping.hxx>
41 #include <cppuhelper/bootstrap.hxx>
42 #include <cppuhelper/implbase1.hxx>
43 #include <typelib/typedescription.h>
45 #include <com/sun/star/lang/XComponent.hpp>
46 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
47 #include <com/sun/star/reflection/XTypeDescription.hpp>
48 #include <com/sun/star/reflection/XEnumTypeDescription.hpp>
49 #include <com/sun/star/reflection/XIndirectTypeDescription.hpp>
50 #include <com/sun/star/reflection/XInterfaceMemberTypeDescription.hpp>
51 #include <com/sun/star/reflection/XInterfaceAttributeTypeDescription.hpp>
52 #include <com/sun/star/reflection/XMethodParameter.hpp>
53 #include <com/sun/star/reflection/XInterfaceMethodTypeDescription.hpp>
54 #include <com/sun/star/reflection/XInterfaceTypeDescription2.hpp>
55 #include <com/sun/star/reflection/XCompoundTypeDescription.hpp>
56 #include <com/sun/star/reflection/XStructTypeDescription.hpp>
57 #include <com/sun/star/reflection/XUnionTypeDescription.hpp>
58 #include "com/sun/star/uno/RuntimeException.hpp"
60 #include "boost/scoped_array.hpp"
62 using namespace ::rtl
;
63 using namespace ::com::sun::star
;
64 using namespace ::com::sun::star::uno
;
65 using namespace ::com::sun::star::reflection
;
71 static typelib_TypeDescription
* createCTD(
72 Reference
< container::XHierarchicalNameAccess
> const & access
,
73 const Reference
< XTypeDescription
> & xType
);
75 //==================================================================================================
76 inline static sal_Int64
coerceToInt64( const Any
& rVal
)
78 switch (rVal
.getValueTypeClass())
81 return *(sal_Unicode
*)rVal
.getValue();
82 case TypeClass_BOOLEAN
:
83 return (*(sal_Bool
*)rVal
.getValue() ? 1 : 0);
85 return *(sal_Int8
*)rVal
.getValue();
87 return *(sal_Int16
*)rVal
.getValue();
88 case TypeClass_UNSIGNED_SHORT
:
89 return *(sal_uInt16
*)rVal
.getValue();
91 return *(sal_Int32
*)rVal
.getValue();
92 case TypeClass_UNSIGNED_LONG
:
93 return *(sal_uInt32
*)rVal
.getValue();
95 return *(sal_Int64
*)rVal
.getValue();
96 case TypeClass_UNSIGNED_HYPER
:
97 return *(sal_uInt64
*)rVal
.getValue();
99 return *(int *)rVal
.getValue();
105 //==================================================================================================
106 inline static typelib_TypeDescription
* createCTD(
107 const Reference
< XUnionTypeDescription
> & xType
)
109 typelib_TypeDescription
* pRet
= 0;
112 OUString
aTypeName( xType
->getName() );
115 Reference
< XTypeDescription
> xDiscrTD( xType
->getDiscriminantType() );
116 OUString
aDiscrTypeName( xDiscrTD
->getName() );
117 typelib_TypeDescriptionReference
* pDiscrTypeRef
= 0;
118 typelib_typedescriptionreference_new( &pDiscrTypeRef
,
119 (typelib_TypeClass
)xDiscrTD
->getTypeClass(),
120 aDiscrTypeName
.pData
);
121 // default member type
122 Reference
< XTypeDescription
> xDefaultMemberTD( xType
->getDefaultMemberType() );
123 OUString
aDefMemberTypeName( xDefaultMemberTD
->getName() );
124 typelib_TypeDescriptionReference
* pDefMemberTypeRef
= 0;
125 typelib_typedescriptionreference_new( &pDefMemberTypeRef
,
126 (typelib_TypeClass
)xDefaultMemberTD
->getTypeClass(),
127 aDefMemberTypeName
.pData
);
129 Sequence
< Any
> aDiscriminants( xType
->getDiscriminants() );
130 Sequence
< Reference
< XTypeDescription
> > aMemberTypes( xType
->getMemberTypes() );
131 Sequence
< OUString
> aMemberNames( xType
->getMemberNames() );
132 sal_Int32 nMembers
= aDiscriminants
.getLength();
133 OSL_ASSERT( nMembers
== aMemberNames
.getLength() && nMembers
== aMemberTypes
.getLength() );
135 const Any
* pDiscriminants
= aDiscriminants
.getConstArray();
136 const Reference
< XTypeDescription
> * pMemberTypes
= aMemberTypes
.getConstArray();
137 const OUString
* pMemberNames
= aMemberNames
.getConstArray();
139 typelib_Union_Init
* pMembers
= (typelib_Union_Init
*)alloca( nMembers
* sizeof(typelib_Union_Init
) );
142 for ( nPos
= nMembers
; nPos
--; )
144 typelib_Union_Init
& rEntry
= pMembers
[nPos
];
145 // member discriminant
146 rEntry
.nDiscriminant
= coerceToInt64( pDiscriminants
[nPos
] );
148 OUString
aMemberTypeName( pMemberTypes
[nPos
]->getName() );
150 typelib_typedescriptionreference_new( &rEntry
.pTypeRef
,
151 (typelib_TypeClass
)pMemberTypes
[nPos
]->getTypeClass(),
152 aMemberTypeName
.pData
);
154 rEntry
.pMemberName
= pMemberNames
[nPos
].pData
;
157 typelib_typedescription_newUnion( &pRet
, aTypeName
.pData
,
159 coerceToInt64( xType
->getDefaultDiscriminant() ),
161 nMembers
, pMembers
);
163 for ( nPos
= nMembers
; nPos
--; )
165 typelib_typedescriptionreference_release( pMembers
[nPos
].pTypeRef
);
168 typelib_typedescriptionreference_release( pDiscrTypeRef
);
169 typelib_typedescriptionreference_release( pDefMemberTypeRef
);
173 //==================================================================================================
174 inline static typelib_TypeDescription
* createCTD(
175 const Reference
< XCompoundTypeDescription
> & xType
)
177 typelib_TypeDescription
* pRet
= 0;
180 typelib_TypeDescription
* pBaseType
= createCTD(
181 Reference
< XCompoundTypeDescription
>::query( xType
->getBaseType() ) );
183 typelib_typedescription_register( &pBaseType
);
185 // construct member init array
186 const Sequence
<Reference
< XTypeDescription
> > & rMemberTypes
= xType
->getMemberTypes();
187 const Sequence
< OUString
> & rMemberNames
= xType
->getMemberNames();
189 const Reference
< XTypeDescription
> * pMemberTypes
= rMemberTypes
.getConstArray();
190 const OUString
* pMemberNames
= rMemberNames
.getConstArray();
192 sal_Int32 nMembers
= rMemberTypes
.getLength();
193 OSL_ENSURE( nMembers
== rMemberNames
.getLength(), "### lens differ!" );
195 OUString
aTypeName( xType
->getName() );
197 typelib_CompoundMember_Init
* pMemberInits
= (typelib_CompoundMember_Init
*)alloca(
198 sizeof(typelib_CompoundMember_Init
) * nMembers
);
201 for ( nPos
= nMembers
; nPos
--; )
203 typelib_CompoundMember_Init
& rInit
= pMemberInits
[nPos
];
204 rInit
.eTypeClass
= (typelib_TypeClass
)pMemberTypes
[nPos
]->getTypeClass();
206 OUString
aMemberTypeName( pMemberTypes
[nPos
]->getName() );
207 rtl_uString_acquire( rInit
.pTypeName
= aMemberTypeName
.pData
);
209 // string is held by rMemberNames
210 rInit
.pMemberName
= pMemberNames
[nPos
].pData
;
213 typelib_typedescription_new(
215 (typelib_TypeClass
)xType
->getTypeClass(),
217 (pBaseType
? pBaseType
->pWeakRef
: 0),
218 nMembers
, pMemberInits
);
221 for ( nPos
= nMembers
; nPos
--; )
223 rtl_uString_release( pMemberInits
[nPos
].pTypeName
);
226 typelib_typedescription_release( pBaseType
);
230 //==================================================================================================
231 inline static typelib_TypeDescription
* createCTD(
232 Reference
< container::XHierarchicalNameAccess
> const & access
,
233 const Reference
< XStructTypeDescription
> & xType
)
235 typelib_TypeDescription
* pRet
= 0;
236 if (xType
.is() && xType
->getTypeParameters().getLength() == 0)
238 typelib_TypeDescription
* pBaseType
= createCTD(
239 access
, xType
->getBaseType() );
241 typelib_typedescription_register( &pBaseType
);
243 // construct member init array
244 const Sequence
<Reference
< XTypeDescription
> > & rMemberTypes
= xType
->getMemberTypes();
245 const Sequence
< OUString
> & rMemberNames
= xType
->getMemberNames();
247 const Reference
< XTypeDescription
> * pMemberTypes
= rMemberTypes
.getConstArray();
248 const OUString
* pMemberNames
= rMemberNames
.getConstArray();
250 sal_Int32 nMembers
= rMemberTypes
.getLength();
251 OSL_ENSURE( nMembers
== rMemberNames
.getLength(), "### lens differ!" );
253 OUString
aTypeName( xType
->getName() );
255 typelib_StructMember_Init
* pMemberInits
= (typelib_StructMember_Init
*)alloca(
256 sizeof(typelib_StructMember_Init
) * nMembers
);
258 Sequence
< Reference
< XTypeDescription
> > templateMemberTypes
;
259 sal_Int32 i
= aTypeName
.indexOf('<');
261 Reference
< XStructTypeDescription
> templateDesc(
262 access
->getByHierarchicalName(aTypeName
.copy(0, i
)),
265 templateDesc
->getTypeParameters().getLength()
266 == xType
->getTypeArguments().getLength());
267 templateMemberTypes
= templateDesc
->getMemberTypes();
268 OSL_ASSERT(templateMemberTypes
.getLength() == nMembers
);
272 for ( nPos
= nMembers
; nPos
--; )
274 typelib_StructMember_Init
& rInit
= pMemberInits
[nPos
];
275 rInit
.aBase
.eTypeClass
276 = (typelib_TypeClass
)pMemberTypes
[nPos
]->getTypeClass();
278 OUString
aMemberTypeName( pMemberTypes
[nPos
]->getName() );
280 rInit
.aBase
.pTypeName
= aMemberTypeName
.pData
);
282 // string is held by rMemberNames
283 rInit
.aBase
.pMemberName
= pMemberNames
[nPos
].pData
;
285 rInit
.bParameterizedType
= templateMemberTypes
.getLength() != 0
286 && (templateMemberTypes
[nPos
]->getTypeClass()
287 == TypeClass_UNKNOWN
);
290 typelib_typedescription_newStruct(
293 (pBaseType
? pBaseType
->pWeakRef
: 0),
294 nMembers
, pMemberInits
);
297 for ( nPos
= nMembers
; nPos
--; )
299 rtl_uString_release( pMemberInits
[nPos
].aBase
.pTypeName
);
302 typelib_typedescription_release( pBaseType
);
306 //==================================================================================================
307 inline static typelib_TypeDescription
* createCTD(
308 const Reference
< XInterfaceAttributeTypeDescription
> & xAttribute
)
310 typelib_TypeDescription
* pRet
= 0;
313 OUString
aMemberName( xAttribute
->getName() );
314 Reference
< XTypeDescription
> xType( xAttribute
->getType() );
315 OUString
aMemberTypeName( xType
->getName() );
317 typelib_typedescription_newInterfaceAttribute(
318 (typelib_InterfaceAttributeTypeDescription
**)&pRet
,
319 xAttribute
->getPosition(),
320 aMemberName
.pData
, // name
321 (typelib_TypeClass
)xType
->getTypeClass(),
322 aMemberTypeName
.pData
, // type name
323 xAttribute
->isReadOnly() );
327 //==================================================================================================
328 static typelib_TypeDescription
* createCTD(
329 const Reference
< XInterfaceMethodTypeDescription
> & xMethod
)
331 typelib_TypeDescription
* pRet
= 0;
334 Reference
< XTypeDescription
> xReturnType( xMethod
->getReturnType() );
337 const Sequence
<Reference
< XMethodParameter
> > & rParams
= xMethod
->getParameters();
338 const Reference
< XMethodParameter
> * pParams
= rParams
.getConstArray();
339 sal_Int32 nParams
= rParams
.getLength();
341 typelib_Parameter_Init
* pParamInit
= (typelib_Parameter_Init
*)alloca(
342 sizeof(typelib_Parameter_Init
) * nParams
);
345 for ( nPos
= nParams
; nPos
--; )
347 const Reference
< XMethodParameter
> & xParam
= pParams
[nPos
];
348 const Reference
< XTypeDescription
> & xType
= xParam
->getType();
349 typelib_Parameter_Init
& rInit
= pParamInit
[xParam
->getPosition()];
351 rInit
.eTypeClass
= (typelib_TypeClass
)xType
->getTypeClass();
352 OUString
aParamTypeName( xType
->getName() );
353 rtl_uString_acquire( rInit
.pTypeName
= aParamTypeName
.pData
);
354 OUString
aParamName( xParam
->getName() );
355 rtl_uString_acquire( rInit
.pParamName
= aParamName
.pData
);
356 rInit
.bIn
= xParam
->isIn();
357 rInit
.bOut
= xParam
->isOut();
360 // init all exception strings
361 const Sequence
<Reference
< XTypeDescription
> > & rExceptions
= xMethod
->getExceptions();
362 const Reference
< XTypeDescription
> * pExceptions
= rExceptions
.getConstArray();
363 sal_Int32 nExceptions
= rExceptions
.getLength();
364 rtl_uString
** ppExceptionNames
= (rtl_uString
**)alloca(
365 sizeof(rtl_uString
*) * nExceptions
);
367 for ( nPos
= nExceptions
; nPos
--; )
369 OUString
aExceptionTypeName( pExceptions
[nPos
]->getName() );
370 rtl_uString_acquire( ppExceptionNames
[nPos
] = aExceptionTypeName
.pData
);
373 OUString
aTypeName( xMethod
->getName() );
374 OUString
aReturnTypeName( xReturnType
->getName() );
376 typelib_typedescription_newInterfaceMethod(
377 (typelib_InterfaceMethodTypeDescription
**)&pRet
,
378 xMethod
->getPosition(),
381 (typelib_TypeClass
)xReturnType
->getTypeClass(),
382 aReturnTypeName
.pData
,
384 nExceptions
, ppExceptionNames
);
386 for ( nPos
= nParams
; nPos
--; )
388 rtl_uString_release( pParamInit
[nPos
].pTypeName
);
389 rtl_uString_release( pParamInit
[nPos
].pParamName
);
391 for ( nPos
= nExceptions
; nPos
--; )
393 rtl_uString_release( ppExceptionNames
[nPos
] );
398 //==================================================================================================
399 inline static typelib_TypeDescription
* createCTD(
400 Reference
< container::XHierarchicalNameAccess
> const & access
,
401 const Reference
< XInterfaceTypeDescription2
> & xType
)
403 typelib_TypeDescription
* pRet
= 0;
406 Sequence
< Reference
< XTypeDescription
> > aBases(xType
->getBaseTypes());
407 sal_Int32 nBases
= aBases
.getLength();
408 // Exploit the fact that a typelib_TypeDescription for an interface type
409 // is also the typelib_TypeDescriptionReference for that type:
410 boost::scoped_array
< typelib_TypeDescription
* > aBaseTypes(
411 new typelib_TypeDescription
*[nBases
]);
412 {for (sal_Int32 i
= 0; i
< nBases
; ++i
) {
413 typelib_TypeDescription
* p
= createCTD(access
, aBases
[i
]);
415 !TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(p
->eTypeClass
));
416 typelib_typedescription_register(&p
);
419 typelib_TypeDescriptionReference
** pBaseTypeRefs
420 = reinterpret_cast< typelib_TypeDescriptionReference
** >(
423 // construct all member refs
424 const Sequence
<Reference
< XInterfaceMemberTypeDescription
> > & rMembers
= xType
->getMembers();
425 sal_Int32 nMembers
= rMembers
.getLength();
427 typelib_TypeDescriptionReference
** ppMemberRefs
= (typelib_TypeDescriptionReference
**)alloca(
428 sizeof(typelib_TypeDescriptionReference
*) * nMembers
);
430 const Reference
< XInterfaceMemberTypeDescription
> * pMembers
= rMembers
.getConstArray();
432 OUString
aTypeName( xType
->getName() );
435 for ( nPos
= nMembers
; nPos
--; )
437 OUString
aMemberTypeName( pMembers
[nPos
]->getName() );
438 ppMemberRefs
[nPos
] = 0;
439 typelib_typedescriptionreference_new(
441 (typelib_TypeClass
)pMembers
[nPos
]->getTypeClass(),
442 aMemberTypeName
.pData
);
445 Uik uik
= xType
->getUik();
447 typelib_typedescription_newMIInterface(
448 (typelib_InterfaceTypeDescription
**)&pRet
,
450 uik
.m_Data1
, uik
.m_Data2
, uik
.m_Data3
, uik
.m_Data4
, uik
.m_Data5
,
451 nBases
, pBaseTypeRefs
,
452 nMembers
, ppMemberRefs
);
454 // cleanup refs and base type
455 {for (int i
= 0; i
< nBases
; ++i
) {
456 typelib_typedescription_release(aBaseTypes
[i
]);
459 for ( nPos
= nMembers
; nPos
--; )
461 typelib_typedescriptionreference_release( ppMemberRefs
[nPos
] );
466 //==================================================================================================
467 inline static typelib_TypeDescription
* createCTD( const Reference
< XEnumTypeDescription
> & xType
)
469 typelib_TypeDescription
* pRet
= 0;
472 OUString
aTypeName( xType
->getName() );
473 Sequence
< OUString
> aNames( xType
->getEnumNames() );
474 OSL_ASSERT( sizeof(OUString
) == sizeof(rtl_uString
*) ); // !!!
475 Sequence
< sal_Int32
> aValues( xType
->getEnumValues() );
477 typelib_typedescription_newEnum(
478 &pRet
, aTypeName
.pData
, xType
->getDefaultEnumValue(),
480 (rtl_uString
**)aNames
.getConstArray(),
481 const_cast< sal_Int32
* >( aValues
.getConstArray() ) );
485 //==================================================================================================
486 inline static typelib_TypeDescription
* createCTD(
487 Reference
< container::XHierarchicalNameAccess
> const & access
,
488 const Reference
< XIndirectTypeDescription
> & xType
)
490 typelib_TypeDescription
* pRet
= 0;
493 typelib_TypeDescription
* pRefType
= createCTD(
494 access
, xType
->getReferencedType() );
495 typelib_typedescription_register( &pRefType
);
497 OUString
aTypeName( xType
->getName() );
499 typelib_typedescription_new(
501 (typelib_TypeClass
)xType
->getTypeClass(),
508 typelib_typedescription_release( pRefType
);
513 //==================================================================================================
514 static typelib_TypeDescription
* createCTD(
515 Reference
< container::XHierarchicalNameAccess
> const & access
,
516 const Reference
< XTypeDescription
> & xType
)
518 typelib_TypeDescription
* pRet
= 0;
522 switch (xType
->getTypeClass())
527 OUString
aTypeName( RTL_CONSTASCII_USTRINGPARAM("void") );
528 typelib_typedescription_new( &pRet
, typelib_TypeClass_VOID
, aTypeName
.pData
, 0, 0, 0 );
533 OUString
aTypeName( RTL_CONSTASCII_USTRINGPARAM("char") );
534 typelib_typedescription_new( &pRet
, typelib_TypeClass_CHAR
, aTypeName
.pData
, 0, 0, 0 );
537 case TypeClass_BOOLEAN
:
539 OUString
aTypeName( RTL_CONSTASCII_USTRINGPARAM("boolean") );
540 typelib_typedescription_new( &pRet
, typelib_TypeClass_BOOLEAN
, aTypeName
.pData
, 0, 0, 0 );
545 OUString
aTypeName( RTL_CONSTASCII_USTRINGPARAM("byte") );
546 typelib_typedescription_new( &pRet
, typelib_TypeClass_BYTE
, aTypeName
.pData
, 0, 0, 0 );
549 case TypeClass_SHORT
:
551 OUString
aTypeName( RTL_CONSTASCII_USTRINGPARAM("short") );
552 typelib_typedescription_new( &pRet
, typelib_TypeClass_SHORT
, aTypeName
.pData
, 0, 0, 0 );
555 case TypeClass_UNSIGNED_SHORT
:
557 OUString
aTypeName( RTL_CONSTASCII_USTRINGPARAM("unsigned short") );
558 typelib_typedescription_new( &pRet
, typelib_TypeClass_UNSIGNED_SHORT
, aTypeName
.pData
, 0, 0, 0 );
563 OUString
aTypeName( RTL_CONSTASCII_USTRINGPARAM("long") );
564 typelib_typedescription_new( &pRet
, typelib_TypeClass_LONG
, aTypeName
.pData
, 0, 0, 0 );
567 case TypeClass_UNSIGNED_LONG
:
569 OUString
aTypeName( RTL_CONSTASCII_USTRINGPARAM("unsigned long") );
570 typelib_typedescription_new( &pRet
, typelib_TypeClass_UNSIGNED_LONG
, aTypeName
.pData
, 0, 0, 0 );
573 case TypeClass_HYPER
:
575 OUString
aTypeName( RTL_CONSTASCII_USTRINGPARAM("hyper") );
576 typelib_typedescription_new( &pRet
, typelib_TypeClass_HYPER
, aTypeName
.pData
, 0, 0, 0 );
579 case TypeClass_UNSIGNED_HYPER
:
581 OUString
aTypeName( RTL_CONSTASCII_USTRINGPARAM("unsigned hyper") );
582 typelib_typedescription_new( &pRet
, typelib_TypeClass_UNSIGNED_HYPER
, aTypeName
.pData
, 0, 0, 0 );
585 case TypeClass_FLOAT
:
587 OUString
aTypeName( RTL_CONSTASCII_USTRINGPARAM("float") );
588 typelib_typedescription_new( &pRet
, typelib_TypeClass_FLOAT
, aTypeName
.pData
, 0, 0, 0 );
591 case TypeClass_DOUBLE
:
593 OUString
aTypeName( RTL_CONSTASCII_USTRINGPARAM("double") );
594 typelib_typedescription_new( &pRet
, typelib_TypeClass_DOUBLE
, aTypeName
.pData
, 0, 0, 0 );
597 case TypeClass_STRING
:
599 OUString
aTypeName( RTL_CONSTASCII_USTRINGPARAM("string") );
600 typelib_typedescription_new( &pRet
, typelib_TypeClass_STRING
, aTypeName
.pData
, 0, 0, 0 );
605 OUString
aTypeName( RTL_CONSTASCII_USTRINGPARAM("type") );
606 typelib_typedescription_new( &pRet
, typelib_TypeClass_TYPE
, aTypeName
.pData
, 0, 0, 0 );
611 OUString
aTypeName( RTL_CONSTASCII_USTRINGPARAM("any") );
612 typelib_typedescription_new( &pRet
, typelib_TypeClass_ANY
, aTypeName
.pData
, 0, 0, 0 );
616 case TypeClass_UNION
:
617 pRet
= createCTD( Reference
< XUnionTypeDescription
>::query( xType
) );
619 case TypeClass_EXCEPTION
:
620 pRet
= createCTD( Reference
< XCompoundTypeDescription
>::query( xType
) );
622 case TypeClass_STRUCT
:
624 access
, Reference
< XStructTypeDescription
>::query( xType
) );
627 pRet
= createCTD( Reference
< XEnumTypeDescription
>::query( xType
) );
629 case TypeClass_TYPEDEF
:
631 Reference
< XIndirectTypeDescription
> xTypedef( xType
, UNO_QUERY
);
633 pRet
= createCTD( access
, xTypedef
->getReferencedType() );
636 case TypeClass_SEQUENCE
:
638 access
, Reference
< XIndirectTypeDescription
>::query( xType
) );
640 case TypeClass_INTERFACE
:
643 Reference
< XInterfaceTypeDescription2
>::query( xType
) );
645 case TypeClass_INTERFACE_METHOD
:
646 pRet
= createCTD( Reference
< XInterfaceMethodTypeDescription
>::query( xType
) );
648 case TypeClass_INTERFACE_ATTRIBUTE
:
649 pRet
= createCTD( Reference
< XInterfaceAttributeTypeDescription
>::query( xType
) );
660 //==================================================================================================
663 static void SAL_CALL
typelib_callback(
664 void * pContext
, typelib_TypeDescription
** ppRet
, rtl_uString
* pTypeName
)
666 OSL_ENSURE( pContext
&& ppRet
&& pTypeName
, "### null ptr!" );
671 ::typelib_typedescription_release( *ppRet
);
674 if (pContext
&& pTypeName
)
676 Reference
< container::XHierarchicalNameAccess
> access(
677 reinterpret_cast< container::XHierarchicalNameAccess
* >(
681 OUString
const & rTypeName
= OUString::unacquired( &pTypeName
);
682 Reference
< XTypeDescription
> xTD
;
683 if (access
->getByHierarchicalName(rTypeName
) >>= xTD
)
685 *ppRet
= createCTD( access
, xTD
);
688 catch (container::NoSuchElementException
& exc
)
690 (void) exc
; // avoid warning about unused variable
692 0, OUStringToOString(
693 OUString( RTL_CONSTASCII_USTRINGPARAM(
694 "typelibrary type not available: ") ) +
695 exc
.Message
, RTL_TEXTENCODING_UTF8
).getStr() );
697 catch (Exception
& exc
)
699 (void) exc
; // avoid warning about unused variable
701 0, OUStringToOString(
702 exc
.Message
, RTL_TEXTENCODING_UTF8
).getStr() );
709 //==================================================================================================
710 class EventListenerImpl
711 : public WeakImplHelper1
< lang::XEventListener
>
713 Reference
< container::XHierarchicalNameAccess
> m_xTDMgr
;
716 inline EventListenerImpl(
717 Reference
< container::XHierarchicalNameAccess
> const & xTDMgr
)
723 virtual void SAL_CALL
disposing( lang::EventObject
const & rEvt
)
724 throw (RuntimeException
);
726 //__________________________________________________________________________________________________
727 void EventListenerImpl::disposing( lang::EventObject
const & rEvt
)
728 throw (RuntimeException
)
730 if (rEvt
.Source
!= m_xTDMgr
) {
733 // deregister of c typelib callback
734 ::typelib_typedescription_revokeCallback( m_xTDMgr
.get(), typelib_callback
);
737 //==================================================================================================
738 sal_Bool SAL_CALL
installTypeDescriptionManager(
739 Reference
< container::XHierarchicalNameAccess
> const & xTDMgr_c
)
742 uno::Environment
curr_env(Environment::getCurrent());
743 uno::Environment
target_env(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(CPPU_STRINGIFY(CPPU_ENV
))));
745 uno::Mapping
curr2target(curr_env
, target_env
);
748 Reference
<container::XHierarchicalNameAccess
> xTDMgr(
749 reinterpret_cast<container::XHierarchicalNameAccess
*>(
750 curr2target
.mapInterface(xTDMgr_c
.get(), ::getCppuType(&xTDMgr_c
))),
753 Reference
< lang::XComponent
> xComp( xTDMgr
, UNO_QUERY
);
756 xComp
->addEventListener( new EventListenerImpl( xTDMgr
) );
757 // register c typelib callback
758 ::typelib_typedescription_registerCallback( xTDMgr
.get(), typelib_callback
);
764 } // end namespace cppu