1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "sal/config.h"
25 #include <sal/alloca.h>
27 #include <osl/diagnose.h>
28 #include <rtl/alloc.h>
29 #include <rtl/ustring.hxx>
31 #include <uno/mapping.hxx>
33 #include <cppuhelper/bootstrap.hxx>
34 #include <cppuhelper/implbase1.hxx>
35 #include <typelib/typedescription.h>
37 #include <com/sun/star/lang/XComponent.hpp>
38 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
39 #include <com/sun/star/reflection/XTypeDescription.hpp>
40 #include <com/sun/star/reflection/XEnumTypeDescription.hpp>
41 #include <com/sun/star/reflection/XIndirectTypeDescription.hpp>
42 #include <com/sun/star/reflection/XInterfaceMemberTypeDescription.hpp>
43 #include <com/sun/star/reflection/XInterfaceAttributeTypeDescription2.hpp>
44 #include <com/sun/star/reflection/XMethodParameter.hpp>
45 #include <com/sun/star/reflection/XInterfaceMethodTypeDescription.hpp>
46 #include <com/sun/star/reflection/XInterfaceTypeDescription2.hpp>
47 #include <com/sun/star/reflection/XCompoundTypeDescription.hpp>
48 #include <com/sun/star/reflection/XStructTypeDescription.hpp>
49 #include <com/sun/star/reflection/XUnionTypeDescription.hpp>
50 #include "com/sun/star/uno/RuntimeException.hpp"
52 #include "boost/scoped_array.hpp"
54 using namespace ::rtl
;
55 using namespace ::com::sun::star
;
56 using namespace ::com::sun::star::uno
;
57 using namespace ::com::sun::star::reflection
;
63 static typelib_TypeDescription
* createCTD(
64 Reference
< container::XHierarchicalNameAccess
> const & access
,
65 const Reference
< XTypeDescription
> & xType
);
67 //==================================================================================================
68 inline static sal_Int64
coerceToInt64( const Any
& rVal
)
70 switch (rVal
.getValueTypeClass())
73 return *(sal_Unicode
*)rVal
.getValue();
74 case TypeClass_BOOLEAN
:
75 return (*(sal_Bool
*)rVal
.getValue() ? 1 : 0);
77 return *(sal_Int8
*)rVal
.getValue();
79 return *(sal_Int16
*)rVal
.getValue();
80 case TypeClass_UNSIGNED_SHORT
:
81 return *(sal_uInt16
*)rVal
.getValue();
83 return *(sal_Int32
*)rVal
.getValue();
84 case TypeClass_UNSIGNED_LONG
:
85 return *(sal_uInt32
*)rVal
.getValue();
87 return *(sal_Int64
*)rVal
.getValue();
88 case TypeClass_UNSIGNED_HYPER
:
89 return *(sal_uInt64
*)rVal
.getValue();
91 return *(int *)rVal
.getValue();
97 //==================================================================================================
98 inline static typelib_TypeDescription
* createCTD(
99 const Reference
< XUnionTypeDescription
> & xType
)
101 typelib_TypeDescription
* pRet
= 0;
104 OUString
aTypeName( xType
->getName() );
107 Reference
< XTypeDescription
> xDiscrTD( xType
->getDiscriminantType() );
108 OUString
aDiscrTypeName( xDiscrTD
->getName() );
109 typelib_TypeDescriptionReference
* pDiscrTypeRef
= 0;
110 typelib_typedescriptionreference_new( &pDiscrTypeRef
,
111 (typelib_TypeClass
)xDiscrTD
->getTypeClass(),
112 aDiscrTypeName
.pData
);
113 // default member type
114 Reference
< XTypeDescription
> xDefaultMemberTD( xType
->getDefaultMemberType() );
115 OUString
aDefMemberTypeName( xDefaultMemberTD
->getName() );
116 typelib_TypeDescriptionReference
* pDefMemberTypeRef
= 0;
117 typelib_typedescriptionreference_new( &pDefMemberTypeRef
,
118 (typelib_TypeClass
)xDefaultMemberTD
->getTypeClass(),
119 aDefMemberTypeName
.pData
);
121 Sequence
< Any
> aDiscriminants( xType
->getDiscriminants() );
122 Sequence
< Reference
< XTypeDescription
> > aMemberTypes( xType
->getMemberTypes() );
123 Sequence
< OUString
> aMemberNames( xType
->getMemberNames() );
124 sal_Int32 nMembers
= aDiscriminants
.getLength();
125 OSL_ASSERT( nMembers
== aMemberNames
.getLength() && nMembers
== aMemberTypes
.getLength() );
127 const Any
* pDiscriminants
= aDiscriminants
.getConstArray();
128 const Reference
< XTypeDescription
> * pMemberTypes
= aMemberTypes
.getConstArray();
129 const OUString
* pMemberNames
= aMemberNames
.getConstArray();
131 typelib_Union_Init
* pMembers
= (typelib_Union_Init
*)alloca( nMembers
* sizeof(typelib_Union_Init
) );
134 for ( nPos
= nMembers
; nPos
--; )
136 typelib_Union_Init
& rEntry
= pMembers
[nPos
];
137 // member discriminant
138 rEntry
.nDiscriminant
= coerceToInt64( pDiscriminants
[nPos
] );
140 OUString
aMemberTypeName( pMemberTypes
[nPos
]->getName() );
142 typelib_typedescriptionreference_new( &rEntry
.pTypeRef
,
143 (typelib_TypeClass
)pMemberTypes
[nPos
]->getTypeClass(),
144 aMemberTypeName
.pData
);
146 rEntry
.pMemberName
= pMemberNames
[nPos
].pData
;
149 typelib_typedescription_newUnion( &pRet
, aTypeName
.pData
,
151 coerceToInt64( xType
->getDefaultDiscriminant() ),
153 nMembers
, pMembers
);
155 for ( nPos
= nMembers
; nPos
--; )
157 typelib_typedescriptionreference_release( pMembers
[nPos
].pTypeRef
);
160 typelib_typedescriptionreference_release( pDiscrTypeRef
);
161 typelib_typedescriptionreference_release( pDefMemberTypeRef
);
165 //==================================================================================================
166 inline static typelib_TypeDescription
* createCTD(
167 const Reference
< XCompoundTypeDescription
> & xType
)
169 typelib_TypeDescription
* pRet
= 0;
172 typelib_TypeDescription
* pBaseType
= createCTD(
173 Reference
< XCompoundTypeDescription
>::query( xType
->getBaseType() ) );
175 typelib_typedescription_register( &pBaseType
);
177 // construct member init array
178 const Sequence
<Reference
< XTypeDescription
> > & rMemberTypes
= xType
->getMemberTypes();
179 const Sequence
< OUString
> & rMemberNames
= xType
->getMemberNames();
181 const Reference
< XTypeDescription
> * pMemberTypes
= rMemberTypes
.getConstArray();
182 const OUString
* pMemberNames
= rMemberNames
.getConstArray();
184 sal_Int32 nMembers
= rMemberTypes
.getLength();
185 OSL_ENSURE( nMembers
== rMemberNames
.getLength(), "### lens differ!" );
187 OUString
aTypeName( xType
->getName() );
189 typelib_CompoundMember_Init
* pMemberInits
= (typelib_CompoundMember_Init
*)alloca(
190 sizeof(typelib_CompoundMember_Init
) * nMembers
);
193 for ( nPos
= nMembers
; nPos
--; )
195 typelib_CompoundMember_Init
& rInit
= pMemberInits
[nPos
];
196 rInit
.eTypeClass
= (typelib_TypeClass
)pMemberTypes
[nPos
]->getTypeClass();
198 OUString
aMemberTypeName( pMemberTypes
[nPos
]->getName() );
199 rtl_uString_acquire( rInit
.pTypeName
= aMemberTypeName
.pData
);
201 // string is held by rMemberNames
202 rInit
.pMemberName
= pMemberNames
[nPos
].pData
;
205 typelib_typedescription_new(
207 (typelib_TypeClass
)xType
->getTypeClass(),
209 (pBaseType
? pBaseType
->pWeakRef
: 0),
210 nMembers
, pMemberInits
);
213 for ( nPos
= nMembers
; nPos
--; )
215 rtl_uString_release( pMemberInits
[nPos
].pTypeName
);
218 typelib_typedescription_release( pBaseType
);
222 //==================================================================================================
223 inline static typelib_TypeDescription
* createCTD(
224 Reference
< container::XHierarchicalNameAccess
> const & access
,
225 const Reference
< XStructTypeDescription
> & xType
)
227 typelib_TypeDescription
* pRet
= 0;
228 if (xType
.is() && xType
->getTypeParameters().getLength() == 0)
230 typelib_TypeDescription
* pBaseType
= createCTD(
231 access
, xType
->getBaseType() );
233 typelib_typedescription_register( &pBaseType
);
235 // construct member init array
236 const Sequence
<Reference
< XTypeDescription
> > & rMemberTypes
= xType
->getMemberTypes();
237 const Sequence
< OUString
> & rMemberNames
= xType
->getMemberNames();
239 const Reference
< XTypeDescription
> * pMemberTypes
= rMemberTypes
.getConstArray();
240 const OUString
* pMemberNames
= rMemberNames
.getConstArray();
242 sal_Int32 nMembers
= rMemberTypes
.getLength();
243 OSL_ENSURE( nMembers
== rMemberNames
.getLength(), "### lens differ!" );
245 OUString
aTypeName( xType
->getName() );
247 typelib_StructMember_Init
* pMemberInits
= (typelib_StructMember_Init
*)alloca(
248 sizeof(typelib_StructMember_Init
) * nMembers
);
250 Sequence
< Reference
< XTypeDescription
> > templateMemberTypes
;
251 sal_Int32 i
= aTypeName
.indexOf('<');
253 Reference
< XStructTypeDescription
> templateDesc(
254 access
->getByHierarchicalName(aTypeName
.copy(0, i
)),
257 templateDesc
->getTypeParameters().getLength()
258 == xType
->getTypeArguments().getLength());
259 templateMemberTypes
= templateDesc
->getMemberTypes();
260 OSL_ASSERT(templateMemberTypes
.getLength() == nMembers
);
264 for ( nPos
= nMembers
; nPos
--; )
266 typelib_StructMember_Init
& rInit
= pMemberInits
[nPos
];
267 rInit
.aBase
.eTypeClass
268 = (typelib_TypeClass
)pMemberTypes
[nPos
]->getTypeClass();
270 OUString
aMemberTypeName( pMemberTypes
[nPos
]->getName() );
272 rInit
.aBase
.pTypeName
= aMemberTypeName
.pData
);
274 // string is held by rMemberNames
275 rInit
.aBase
.pMemberName
= pMemberNames
[nPos
].pData
;
277 rInit
.bParameterizedType
= templateMemberTypes
.getLength() != 0
278 && (templateMemberTypes
[nPos
]->getTypeClass()
279 == TypeClass_UNKNOWN
);
282 typelib_typedescription_newStruct(
285 (pBaseType
? pBaseType
->pWeakRef
: 0),
286 nMembers
, pMemberInits
);
289 for ( nPos
= nMembers
; nPos
--; )
291 rtl_uString_release( pMemberInits
[nPos
].aBase
.pTypeName
);
294 typelib_typedescription_release( pBaseType
);
298 //==================================================================================================
299 inline static typelib_TypeDescription
* createCTD(
300 const Reference
< XInterfaceAttributeTypeDescription2
> & xAttribute
)
302 typelib_TypeDescription
* pRet
= 0;
305 OUString
aMemberName( xAttribute
->getName() );
306 Reference
< XTypeDescription
> xType( xAttribute
->getType() );
307 OUString
aMemberTypeName( xType
->getName() );
308 std::vector
< rtl_uString
* > getExc
;
309 Sequence
< Reference
< XCompoundTypeDescription
> > getExcs(
310 xAttribute
->getGetExceptions() );
311 for (sal_Int32 i
= 0; i
!= getExcs
.getLength(); ++i
)
313 OSL_ASSERT( getExcs
[i
].is() );
314 getExc
.push_back( getExcs
[i
]->getName().pData
);
316 std::vector
< rtl_uString
* > setExc
;
317 Sequence
< Reference
< XCompoundTypeDescription
> > setExcs(
318 xAttribute
->getSetExceptions() );
319 for (sal_Int32 i
= 0; i
!= setExcs
.getLength(); ++i
)
321 OSL_ASSERT( setExcs
[i
].is() );
322 setExc
.push_back( setExcs
[i
]->getName().pData
);
324 typelib_typedescription_newExtendedInterfaceAttribute(
325 (typelib_InterfaceAttributeTypeDescription
**)&pRet
,
326 xAttribute
->getPosition(),
327 aMemberName
.pData
, // name
328 (typelib_TypeClass
)xType
->getTypeClass(),
329 aMemberTypeName
.pData
, // type name
330 xAttribute
->isReadOnly(),
331 getExc
.size(), getExc
.empty() ? 0 : &getExc
[0],
332 setExc
.size(), setExc
.empty() ? 0 : &setExc
[0] );
336 //==================================================================================================
337 static typelib_TypeDescription
* createCTD(
338 const Reference
< XInterfaceMethodTypeDescription
> & xMethod
)
340 typelib_TypeDescription
* pRet
= 0;
343 Reference
< XTypeDescription
> xReturnType( xMethod
->getReturnType() );
346 const Sequence
<Reference
< XMethodParameter
> > & rParams
= xMethod
->getParameters();
347 const Reference
< XMethodParameter
> * pParams
= rParams
.getConstArray();
348 sal_Int32 nParams
= rParams
.getLength();
350 typelib_Parameter_Init
* pParamInit
= (typelib_Parameter_Init
*)alloca(
351 sizeof(typelib_Parameter_Init
) * nParams
);
354 for ( nPos
= nParams
; nPos
--; )
356 const Reference
< XMethodParameter
> & xParam
= pParams
[nPos
];
357 const Reference
< XTypeDescription
> & xType
= xParam
->getType();
358 typelib_Parameter_Init
& rInit
= pParamInit
[xParam
->getPosition()];
360 rInit
.eTypeClass
= (typelib_TypeClass
)xType
->getTypeClass();
361 OUString
aParamTypeName( xType
->getName() );
362 rtl_uString_acquire( rInit
.pTypeName
= aParamTypeName
.pData
);
363 OUString
aParamName( xParam
->getName() );
364 rtl_uString_acquire( rInit
.pParamName
= aParamName
.pData
);
365 rInit
.bIn
= xParam
->isIn();
366 rInit
.bOut
= xParam
->isOut();
369 // init all exception strings
370 const Sequence
<Reference
< XTypeDescription
> > & rExceptions
= xMethod
->getExceptions();
371 const Reference
< XTypeDescription
> * pExceptions
= rExceptions
.getConstArray();
372 sal_Int32 nExceptions
= rExceptions
.getLength();
373 rtl_uString
** ppExceptionNames
= (rtl_uString
**)alloca(
374 sizeof(rtl_uString
*) * nExceptions
);
376 for ( nPos
= nExceptions
; nPos
--; )
378 OUString
aExceptionTypeName( pExceptions
[nPos
]->getName() );
379 rtl_uString_acquire( ppExceptionNames
[nPos
] = aExceptionTypeName
.pData
);
382 OUString
aTypeName( xMethod
->getName() );
383 OUString
aReturnTypeName( xReturnType
->getName() );
385 typelib_typedescription_newInterfaceMethod(
386 (typelib_InterfaceMethodTypeDescription
**)&pRet
,
387 xMethod
->getPosition(),
390 (typelib_TypeClass
)xReturnType
->getTypeClass(),
391 aReturnTypeName
.pData
,
393 nExceptions
, ppExceptionNames
);
395 for ( nPos
= nParams
; nPos
--; )
397 rtl_uString_release( pParamInit
[nPos
].pTypeName
);
398 rtl_uString_release( pParamInit
[nPos
].pParamName
);
400 for ( nPos
= nExceptions
; nPos
--; )
402 rtl_uString_release( ppExceptionNames
[nPos
] );
407 //==================================================================================================
408 inline static typelib_TypeDescription
* createCTD(
409 Reference
< container::XHierarchicalNameAccess
> const & access
,
410 const Reference
< XInterfaceTypeDescription2
> & xType
)
412 typelib_TypeDescription
* pRet
= 0;
415 Sequence
< Reference
< XTypeDescription
> > aBases(xType
->getBaseTypes());
416 sal_Int32 nBases
= aBases
.getLength();
417 // Exploit the fact that a typelib_TypeDescription for an interface type
418 // is also the typelib_TypeDescriptionReference for that type:
419 boost::scoped_array
< typelib_TypeDescription
* > aBaseTypes(
420 new typelib_TypeDescription
*[nBases
]);
421 for (sal_Int32 i
= 0; i
< nBases
; ++i
) {
422 typelib_TypeDescription
* p
= createCTD(access
, aBases
[i
]);
424 !TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(p
->eTypeClass
));
425 typelib_typedescription_register(&p
);
428 typelib_TypeDescriptionReference
** pBaseTypeRefs
429 = reinterpret_cast< typelib_TypeDescriptionReference
** >(
432 // construct all member refs
433 const Sequence
<Reference
< XInterfaceMemberTypeDescription
> > & rMembers
= xType
->getMembers();
434 sal_Int32 nMembers
= rMembers
.getLength();
436 typelib_TypeDescriptionReference
** ppMemberRefs
= (typelib_TypeDescriptionReference
**)alloca(
437 sizeof(typelib_TypeDescriptionReference
*) * nMembers
);
439 const Reference
< XInterfaceMemberTypeDescription
> * pMembers
= rMembers
.getConstArray();
441 OUString
aTypeName( xType
->getName() );
444 for ( nPos
= nMembers
; nPos
--; )
446 OUString
aMemberTypeName( pMembers
[nPos
]->getName() );
447 ppMemberRefs
[nPos
] = 0;
448 typelib_typedescriptionreference_new(
450 (typelib_TypeClass
)pMembers
[nPos
]->getTypeClass(),
451 aMemberTypeName
.pData
);
454 Uik uik
= xType
->getUik();
456 typelib_typedescription_newMIInterface(
457 (typelib_InterfaceTypeDescription
**)&pRet
,
459 uik
.m_Data1
, uik
.m_Data2
, uik
.m_Data3
, uik
.m_Data4
, uik
.m_Data5
,
460 nBases
, pBaseTypeRefs
,
461 nMembers
, ppMemberRefs
);
463 // cleanup refs and base type
464 for (int i
= 0; i
< nBases
; ++i
) {
465 typelib_typedescription_release(aBaseTypes
[i
]);
468 for ( nPos
= nMembers
; nPos
--; )
470 typelib_typedescriptionreference_release( ppMemberRefs
[nPos
] );
475 //==================================================================================================
476 inline static typelib_TypeDescription
* createCTD( const Reference
< XEnumTypeDescription
> & xType
)
478 typelib_TypeDescription
* pRet
= 0;
481 OUString
aTypeName( xType
->getName() );
482 Sequence
< OUString
> aNames( xType
->getEnumNames() );
483 OSL_ASSERT( sizeof(OUString
) == sizeof(rtl_uString
*) ); // !!!
484 Sequence
< sal_Int32
> aValues( xType
->getEnumValues() );
486 typelib_typedescription_newEnum(
487 &pRet
, aTypeName
.pData
, xType
->getDefaultEnumValue(),
489 (rtl_uString
**)aNames
.getConstArray(),
490 const_cast< sal_Int32
* >( aValues
.getConstArray() ) );
494 //==================================================================================================
495 inline static typelib_TypeDescription
* createCTD(
496 Reference
< container::XHierarchicalNameAccess
> const & access
,
497 const Reference
< XIndirectTypeDescription
> & xType
)
499 typelib_TypeDescription
* pRet
= 0;
502 typelib_TypeDescription
* pRefType
= createCTD(
503 access
, xType
->getReferencedType() );
504 typelib_typedescription_register( &pRefType
);
506 OUString
aTypeName( xType
->getName() );
508 typelib_typedescription_new(
510 (typelib_TypeClass
)xType
->getTypeClass(),
516 typelib_typedescription_release( pRefType
);
521 //==================================================================================================
522 static typelib_TypeDescription
* createCTD(
523 Reference
< container::XHierarchicalNameAccess
> const & access
,
524 const Reference
< XTypeDescription
> & xType
)
526 typelib_TypeDescription
* pRet
= 0;
530 switch (xType
->getTypeClass())
535 OUString
aTypeName("void");
536 typelib_typedescription_new( &pRet
, typelib_TypeClass_VOID
, aTypeName
.pData
, 0, 0, 0 );
541 OUString
aTypeName("char");
542 typelib_typedescription_new( &pRet
, typelib_TypeClass_CHAR
, aTypeName
.pData
, 0, 0, 0 );
545 case TypeClass_BOOLEAN
:
547 OUString
aTypeName("boolean");
548 typelib_typedescription_new( &pRet
, typelib_TypeClass_BOOLEAN
, aTypeName
.pData
, 0, 0, 0 );
553 OUString
aTypeName("byte");
554 typelib_typedescription_new( &pRet
, typelib_TypeClass_BYTE
, aTypeName
.pData
, 0, 0, 0 );
557 case TypeClass_SHORT
:
559 OUString
aTypeName("short");
560 typelib_typedescription_new( &pRet
, typelib_TypeClass_SHORT
, aTypeName
.pData
, 0, 0, 0 );
563 case TypeClass_UNSIGNED_SHORT
:
565 OUString
aTypeName("unsigned short");
566 typelib_typedescription_new( &pRet
, typelib_TypeClass_UNSIGNED_SHORT
, aTypeName
.pData
, 0, 0, 0 );
571 OUString
aTypeName("long");
572 typelib_typedescription_new( &pRet
, typelib_TypeClass_LONG
, aTypeName
.pData
, 0, 0, 0 );
575 case TypeClass_UNSIGNED_LONG
:
577 OUString
aTypeName("unsigned long");
578 typelib_typedescription_new( &pRet
, typelib_TypeClass_UNSIGNED_LONG
, aTypeName
.pData
, 0, 0, 0 );
581 case TypeClass_HYPER
:
583 OUString
aTypeName("hyper");
584 typelib_typedescription_new( &pRet
, typelib_TypeClass_HYPER
, aTypeName
.pData
, 0, 0, 0 );
587 case TypeClass_UNSIGNED_HYPER
:
589 OUString
aTypeName("unsigned hyper");
590 typelib_typedescription_new( &pRet
, typelib_TypeClass_UNSIGNED_HYPER
, aTypeName
.pData
, 0, 0, 0 );
593 case TypeClass_FLOAT
:
595 OUString
aTypeName("float");
596 typelib_typedescription_new( &pRet
, typelib_TypeClass_FLOAT
, aTypeName
.pData
, 0, 0, 0 );
599 case TypeClass_DOUBLE
:
601 OUString
aTypeName("double");
602 typelib_typedescription_new( &pRet
, typelib_TypeClass_DOUBLE
, aTypeName
.pData
, 0, 0, 0 );
605 case TypeClass_STRING
:
607 OUString
aTypeName("string");
608 typelib_typedescription_new( &pRet
, typelib_TypeClass_STRING
, aTypeName
.pData
, 0, 0, 0 );
613 OUString
aTypeName("type");
614 typelib_typedescription_new( &pRet
, typelib_TypeClass_TYPE
, aTypeName
.pData
, 0, 0, 0 );
619 OUString
aTypeName("any");
620 typelib_typedescription_new( &pRet
, typelib_TypeClass_ANY
, aTypeName
.pData
, 0, 0, 0 );
624 case TypeClass_UNION
:
625 pRet
= createCTD( Reference
< XUnionTypeDescription
>::query( xType
) );
627 case TypeClass_EXCEPTION
:
628 pRet
= createCTD( Reference
< XCompoundTypeDescription
>::query( xType
) );
630 case TypeClass_STRUCT
:
632 access
, Reference
< XStructTypeDescription
>::query( xType
) );
635 pRet
= createCTD( Reference
< XEnumTypeDescription
>::query( xType
) );
637 case TypeClass_TYPEDEF
:
639 Reference
< XIndirectTypeDescription
> xTypedef( xType
, UNO_QUERY
);
641 pRet
= createCTD( access
, xTypedef
->getReferencedType() );
644 case TypeClass_SEQUENCE
:
646 access
, Reference
< XIndirectTypeDescription
>::query( xType
) );
648 case TypeClass_INTERFACE
:
651 Reference
< XInterfaceTypeDescription2
>::query( xType
) );
653 case TypeClass_INTERFACE_METHOD
:
654 pRet
= createCTD( Reference
< XInterfaceMethodTypeDescription
>::query( xType
) );
656 case TypeClass_INTERFACE_ATTRIBUTE
:
657 pRet
= createCTD( Reference
< XInterfaceAttributeTypeDescription2
>::query( xType
) );
668 //==================================================================================================
671 static void SAL_CALL
typelib_callback(
672 void * pContext
, typelib_TypeDescription
** ppRet
, rtl_uString
* pTypeName
)
674 OSL_ENSURE( pContext
&& ppRet
&& pTypeName
, "### null ptr!" );
679 ::typelib_typedescription_release( *ppRet
);
682 if (pContext
&& pTypeName
)
684 Reference
< container::XHierarchicalNameAccess
> access(
685 reinterpret_cast< container::XHierarchicalNameAccess
* >(
689 OUString
const & rTypeName
= OUString::unacquired( &pTypeName
);
690 Reference
< XTypeDescription
> xTD
;
691 if (access
->getByHierarchicalName(rTypeName
) >>= xTD
)
693 *ppRet
= createCTD( access
, xTD
);
696 catch (container::NoSuchElementException
& exc
)
698 (void) exc
; // avoid warning about unused variable
700 "typelibrary type not available: %s",
702 exc
.Message
, RTL_TEXTENCODING_UTF8
).getStr() );
704 catch (Exception
& exc
)
706 (void) exc
; // avoid warning about unused variable
710 exc
.Message
, RTL_TEXTENCODING_UTF8
).getStr() );
717 //==================================================================================================
718 class EventListenerImpl
719 : public WeakImplHelper1
< lang::XEventListener
>
721 Reference
< container::XHierarchicalNameAccess
> m_xTDMgr
;
724 inline EventListenerImpl(
725 Reference
< container::XHierarchicalNameAccess
> const & xTDMgr
)
731 virtual void SAL_CALL
disposing( lang::EventObject
const & rEvt
)
732 throw (RuntimeException
);
734 //__________________________________________________________________________________________________
735 void EventListenerImpl::disposing( lang::EventObject
const & rEvt
)
736 throw (RuntimeException
)
738 if (rEvt
.Source
!= m_xTDMgr
) {
741 // deregister of c typelib callback
742 ::typelib_typedescription_revokeCallback( m_xTDMgr
.get(), typelib_callback
);
745 //==================================================================================================
746 sal_Bool SAL_CALL
installTypeDescriptionManager(
747 Reference
< container::XHierarchicalNameAccess
> const & xTDMgr_c
)
750 uno::Environment
curr_env(Environment::getCurrent());
751 uno::Environment
target_env(rtl::OUString(CPPU_STRINGIFY(CPPU_ENV
)));
753 uno::Mapping
curr2target(curr_env
, target_env
);
756 Reference
<container::XHierarchicalNameAccess
> xTDMgr(
757 reinterpret_cast<container::XHierarchicalNameAccess
*>(
758 curr2target
.mapInterface(xTDMgr_c
.get(), ::getCppuType(&xTDMgr_c
))),
761 Reference
< lang::XComponent
> xComp( xTDMgr
, UNO_QUERY
);
764 xComp
->addEventListener( new EventListenerImpl( xTDMgr
) );
765 // register c typelib callback
766 ::typelib_typedescription_registerCallback( xTDMgr
.get(), typelib_callback
);
772 } // end namespace cppu
774 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */