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: base.hxx,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 #ifndef _STOC_RDBTDP_BASE_HXX
32 #define _STOC_RDBTDP_BASE_HXX
34 #include <osl/diagnose.h>
35 #include <osl/mutex.hxx>
36 #include <cppuhelper/weak.hxx>
37 #include <cppuhelper/implbase1.hxx>
38 #include <cppuhelper/implbase2.hxx>
39 #ifndef _CPPUHELPER_IMPLEMENTATIONENTRY_HXX_
40 #include <cppuhelper/implementationentry.hxx>
43 #include "registry/refltype.hxx"
49 #include <com/sun/star/reflection/XTypeDescription.hpp>
50 #include <com/sun/star/reflection/XTypeDescriptionEnumerationAccess.hpp>
51 #include <com/sun/star/reflection/XInterfaceTypeDescription.hpp>
52 #include <com/sun/star/reflection/XInterfaceTypeDescription2.hpp>
53 #include <com/sun/star/reflection/XCompoundTypeDescription.hpp>
54 #include <com/sun/star/reflection/XConstantTypeDescription.hpp>
55 #include <com/sun/star/reflection/XConstantsTypeDescription.hpp>
56 #include <com/sun/star/reflection/XEnumTypeDescription.hpp>
57 #include <com/sun/star/reflection/XIndirectTypeDescription.hpp>
58 #include <com/sun/star/reflection/XServiceConstructorDescription.hpp>
59 #include <com/sun/star/reflection/XServiceTypeDescription.hpp>
60 #include <com/sun/star/reflection/XServiceTypeDescription2.hpp>
61 #include <com/sun/star/reflection/XSingletonTypeDescription2.hpp>
62 #include <com/sun/star/reflection/XModuleTypeDescription.hpp>
63 #include <com/sun/star/reflection/XPublished.hpp>
64 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
65 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
66 #include <com/sun/star/registry/XRegistryKey.hpp>
72 using namespace com::sun::star::uno
;
73 using namespace com::sun::star::lang
;
74 using namespace com::sun::star::container
;
75 using namespace com::sun::star::reflection
;
77 //--------------------------------------------------------------------------------------------------
79 extern rtl_StandardModuleCount g_moduleCount
;
84 com::sun::star::uno::Reference
< XTypeDescription
> resolveTypedefs(
85 com::sun::star::uno::Reference
< XTypeDescription
> const & type
);
88 ::osl::Mutex
& getMutex();
90 //--------------------------------------------------------------------------------------------------
92 typedef ::std::list
< ::com::sun::star::uno::Reference
<
93 ::com::sun::star::registry::XRegistryKey
> > RegistryKeyList
;
95 //--------------------------------------------------------------------------------------------------
97 class RegistryKeyCloser
100 RegistryKeyCloser( const ::com::sun::star::uno::Reference
<
101 ::com::sun::star::registry::XRegistryKey
> & xKey
)
104 { if ( m_xKey
.is() ) { try { if ( m_xKey
->isValid() ) m_xKey
->closeKey(); } catch (...) {} } }
106 void reset() { m_xKey
.clear(); }
108 ::com::sun::star::uno::Reference
<
109 ::com::sun::star::registry::XRegistryKey
> m_xKey
;
112 //--------------------------------------------------------------------------------------------------
114 // helper to create XTypeDescription instances using typereg::Reader
115 // (used from Type Provider and Type Description Enumeration implementation)
116 ::com::sun::star::uno::Reference
<
117 ::com::sun::star::reflection::XTypeDescription
>
118 createTypeDescription(
119 const ::com::sun::star::uno::Sequence
< sal_Int8
> & rData
,
120 const ::com::sun::star::uno::Reference
<
121 ::com::sun::star::container::XHierarchicalNameAccess
> & xNameAccess
,
122 bool bReturnEmptyRefForUnknownType
);
125 //--------------------------------------------------------------------------------------------------
126 inline sal_Int32
getRTValueAsInt32( const RTConstValue
& rVal
)
131 return rVal
.m_value
.aByte
;
133 return rVal
.m_value
.aShort
;
135 return rVal
.m_value
.aUShort
;
137 return rVal
.m_value
.aLong
;
139 return rVal
.m_value
.aULong
;
141 OSL_ENSURE( sal_False
, "### unexpected value type!" );
145 //--------------------------------------------------------------------------------------------------
146 inline Any
getRTValue( const RTConstValue
& rVal
)
151 return Any( &rVal
.m_value
.aBool
, ::getCppuBooleanType() );
153 return Any( &rVal
.m_value
.aByte
, ::getCppuType( (const sal_Int8
*)0 ) );
155 return Any( &rVal
.m_value
.aShort
, ::getCppuType( (const sal_Int16
*)0 ) );
157 return Any( &rVal
.m_value
.aUShort
, ::getCppuType( (const sal_uInt16
*)0 ) );
159 return Any( &rVal
.m_value
.aLong
, ::getCppuType( (const sal_Int32
*)0 ) );
161 return Any( &rVal
.m_value
.aULong
, ::getCppuType( (const sal_uInt32
*)0 ) );
163 return Any( &rVal
.m_value
.aHyper
, ::getCppuType( (const sal_Int64
*)0 ) );
165 return Any( &rVal
.m_value
.aUHyper
, ::getCppuType( (const sal_uInt64
*)0 ) );
167 return Any( &rVal
.m_value
.aFloat
, ::getCppuType( (const float *)0 ) );
169 return Any( &rVal
.m_value
.aDouble
, ::getCppuType( (const double *)0 ) );
172 OUString
aStr( rVal
.m_value
.aString
);
173 return Any( &aStr
, ::getCppuType( (const OUString
*)0 ) );
176 OSL_ENSURE( sal_False
, "### unexpected RTValue!" );
181 //==================================================================================================
182 class TypeDescriptionImpl
: public WeakImplHelper1
< XTypeDescription
>
184 TypeClass _eTypeClass
;
188 TypeDescriptionImpl( TypeClass eTypeClass
, const OUString
& rName
)
189 : _eTypeClass( eTypeClass
)
192 g_moduleCount
.modCnt
.acquire( &g_moduleCount
.modCnt
);
194 virtual ~TypeDescriptionImpl();
197 virtual TypeClass SAL_CALL
getTypeClass() throw(::com::sun::star::uno::RuntimeException
);
198 virtual OUString SAL_CALL
getName() throw(::com::sun::star::uno::RuntimeException
);
201 //==================================================================================================
202 class InterfaceTypeDescriptionImpl
:
203 public WeakImplHelper2
< XInterfaceTypeDescription2
, XPublished
>
205 com::sun::star::uno::Reference
< XHierarchicalNameAccess
> _xTDMgr
;
206 Sequence
< sal_Int8
> _aBytes
;
210 Sequence
< OUString
> _aBaseTypes
;
211 Sequence
< com::sun::star::uno::Reference
< XTypeDescription
> > _xBaseTDs
;
212 Sequence
< OUString
> _aOptionalBaseTypes
;
213 Sequence
< com::sun::star::uno::Reference
< XTypeDescription
> >
216 sal_Int32 _nBaseOffset
;
218 com::sun::star::uno::Reference
< XInterfaceMemberTypeDescription
> >
224 void checkInterfaceType(
225 com::sun::star::uno::Reference
< XTypeDescription
> const & type
);
228 InterfaceTypeDescriptionImpl(
229 const com::sun::star::uno::Reference
< XHierarchicalNameAccess
> &
231 const OUString
& rName
, const Sequence
< OUString
> & rBaseTypes
,
232 const Sequence
< OUString
> & rOptionalBaseTypes
,
233 const Sequence
< sal_Int8
> & rBytes
, bool published
);
234 virtual ~InterfaceTypeDescriptionImpl();
237 virtual TypeClass SAL_CALL
getTypeClass() throw(::com::sun::star::uno::RuntimeException
);
238 virtual OUString SAL_CALL
getName() throw(::com::sun::star::uno::RuntimeException
);
240 // XInterfaceTypeDescription2
241 virtual Uik SAL_CALL
getUik() throw(::com::sun::star::uno::RuntimeException
);
242 virtual com::sun::star::uno::Reference
< XTypeDescription
> SAL_CALL
243 getBaseType() throw(::com::sun::star::uno::RuntimeException
);
246 com::sun::star::uno::Reference
< XInterfaceMemberTypeDescription
> >
247 SAL_CALL
getMembers() throw(::com::sun::star::uno::RuntimeException
);
249 virtual Sequence
< com::sun::star::uno::Reference
< XTypeDescription
> >
250 SAL_CALL
getBaseTypes() throw (RuntimeException
);
252 virtual Sequence
< com::sun::star::uno::Reference
< XTypeDescription
> >
253 SAL_CALL
getOptionalBaseTypes() throw (RuntimeException
);
255 virtual sal_Bool SAL_CALL
isPublished()
256 throw (::com::sun::star::uno::RuntimeException
)
257 { return _published
; }
260 //==================================================================================================
261 class CompoundTypeDescriptionImpl
:
262 public WeakImplHelper2
< XCompoundTypeDescription
, XPublished
>
264 com::sun::star::uno::Reference
< XHierarchicalNameAccess
> _xTDMgr
;
265 TypeClass _eTypeClass
;
266 Sequence
< sal_Int8
> _aBytes
;
270 com::sun::star::uno::Reference
< XTypeDescription
> _xBaseTD
;
272 Sequence
< com::sun::star::uno::Reference
< XTypeDescription
> > * _pMembers
;
273 Sequence
< OUString
> * _pMemberNames
;
278 CompoundTypeDescriptionImpl(
279 const com::sun::star::uno::Reference
< XHierarchicalNameAccess
> &
281 TypeClass eTypeClass
,
282 const OUString
& rName
, const OUString
& rBaseName
,
283 const Sequence
< sal_Int8
> & rBytes
,
286 , _eTypeClass( eTypeClass
)
289 , _aBaseType( rBaseName
)
292 , _published( published
)
294 g_moduleCount
.modCnt
.acquire( &g_moduleCount
.modCnt
);
296 virtual ~CompoundTypeDescriptionImpl();
299 virtual TypeClass SAL_CALL
getTypeClass() throw(::com::sun::star::uno::RuntimeException
);
300 virtual OUString SAL_CALL
getName() throw(::com::sun::star::uno::RuntimeException
);
302 // XCompoundTypeDescription
303 virtual com::sun::star::uno::Reference
< XTypeDescription
> SAL_CALL
304 getBaseType() throw(::com::sun::star::uno::RuntimeException
);
305 virtual Sequence
< com::sun::star::uno::Reference
< XTypeDescription
> >
306 SAL_CALL
getMemberTypes() throw(::com::sun::star::uno::RuntimeException
);
307 virtual Sequence
< OUString
> SAL_CALL
getMemberNames() throw(::com::sun::star::uno::RuntimeException
);
309 virtual sal_Bool SAL_CALL
isPublished()
310 throw (::com::sun::star::uno::RuntimeException
)
311 { return _published
; }
314 //==================================================================================================
315 class EnumTypeDescriptionImpl
:
316 public WeakImplHelper2
< XEnumTypeDescription
, XPublished
>
318 com::sun::star::uno::Reference
< XHierarchicalNameAccess
> _xTDMgr
;
319 Sequence
< sal_Int8
> _aBytes
;
322 sal_Int32 _nDefaultValue
;
324 Sequence
< OUString
> * _pEnumNames
;
325 Sequence
< sal_Int32
> * _pEnumValues
;
330 EnumTypeDescriptionImpl(
331 const com::sun::star::uno::Reference
< XHierarchicalNameAccess
> &
333 const OUString
& rName
, sal_Int32 nDefaultValue
,
334 const Sequence
< sal_Int8
> & rBytes
, bool published
)
338 , _nDefaultValue( nDefaultValue
)
341 , _published( published
)
343 g_moduleCount
.modCnt
.acquire( &g_moduleCount
.modCnt
);
345 virtual ~EnumTypeDescriptionImpl();
348 virtual TypeClass SAL_CALL
getTypeClass() throw(::com::sun::star::uno::RuntimeException
);
349 virtual OUString SAL_CALL
getName() throw(::com::sun::star::uno::RuntimeException
);
351 // XEnumTypeDescription
352 virtual sal_Int32 SAL_CALL
getDefaultEnumValue() throw(::com::sun::star::uno::RuntimeException
);
353 virtual Sequence
< OUString
> SAL_CALL
getEnumNames() throw(::com::sun::star::uno::RuntimeException
);
354 virtual Sequence
< sal_Int32
> SAL_CALL
getEnumValues() throw(::com::sun::star::uno::RuntimeException
);
356 virtual sal_Bool SAL_CALL
isPublished()
357 throw (::com::sun::star::uno::RuntimeException
)
358 { return _published
; }
361 //==================================================================================================
362 class TypedefTypeDescriptionImpl
:
363 public WeakImplHelper2
< XIndirectTypeDescription
, XPublished
>
365 com::sun::star::uno::Reference
< XHierarchicalNameAccess
> _xTDMgr
;
369 com::sun::star::uno::Reference
< XTypeDescription
> _xRefTD
;
374 TypedefTypeDescriptionImpl(
375 const com::sun::star::uno::Reference
< XHierarchicalNameAccess
> &
377 const OUString
& rName
, const OUString
& rRefName
, bool published
)
380 , _aRefName( rRefName
)
381 , _published( published
)
383 g_moduleCount
.modCnt
.acquire( &g_moduleCount
.modCnt
);
385 virtual ~TypedefTypeDescriptionImpl();
388 virtual TypeClass SAL_CALL
getTypeClass() throw(::com::sun::star::uno::RuntimeException
);
389 virtual OUString SAL_CALL
getName() throw(::com::sun::star::uno::RuntimeException
);
391 // XIndirectTypeDescription
392 virtual com::sun::star::uno::Reference
< XTypeDescription
> SAL_CALL
393 getReferencedType() throw(::com::sun::star::uno::RuntimeException
);
395 virtual sal_Bool SAL_CALL
isPublished()
396 throw (::com::sun::star::uno::RuntimeException
)
397 { return _published
; }
400 //==================================================================================================
401 class ServiceTypeDescriptionImpl
:
402 public WeakImplHelper2
< XServiceTypeDescription2
, XPublished
>
405 Sequence
< sal_Int8
> _aBytes
;
406 com::sun::star::uno::Reference
< XHierarchicalNameAccess
> _xTDMgr
;
407 bool _bInitReferences
;
409 com::sun::star::uno::Reference
< XTypeDescription
> _xInterfaceTD
;
412 com::sun::star::uno::Reference
< XServiceConstructorDescription
> > >
414 Sequence
< com::sun::star::uno::Reference
< XServiceTypeDescription
> >
416 Sequence
< com::sun::star::uno::Reference
< XServiceTypeDescription
> >
418 Sequence
< com::sun::star::uno::Reference
< XInterfaceTypeDescription
> >
419 _aMandatoryInterfaces
;
420 Sequence
< com::sun::star::uno::Reference
< XInterfaceTypeDescription
> >
421 _aOptionalInterfaces
;
423 Sequence
< com::sun::star::uno::Reference
< XPropertyTypeDescription
> > >
429 ServiceTypeDescriptionImpl(
430 const com::sun::star::uno::Reference
< XHierarchicalNameAccess
> &
432 const OUString
& rName
, const Sequence
< sal_Int8
> & rBytes
,
434 : _aName( rName
), _aBytes( rBytes
), _xTDMgr( xTDMgr
),
435 _bInitReferences( false ), _published( published
)
437 g_moduleCount
.modCnt
.acquire( &g_moduleCount
.modCnt
);
439 virtual ~ServiceTypeDescriptionImpl();
442 virtual TypeClass SAL_CALL
444 throw(::com::sun::star::uno::RuntimeException
);
445 virtual OUString SAL_CALL
447 throw(::com::sun::star::uno::RuntimeException
);
449 // XServiceTypeDescription
450 virtual ::com::sun::star::uno::Sequence
<
451 ::com::sun::star::uno::Reference
<
452 ::com::sun::star::reflection::XServiceTypeDescription
> > SAL_CALL
453 getMandatoryServices()
454 throw (::com::sun::star::uno::RuntimeException
);
455 virtual ::com::sun::star::uno::Sequence
<
456 ::com::sun::star::uno::Reference
<
457 ::com::sun::star::reflection::XServiceTypeDescription
> > SAL_CALL
458 getOptionalServices()
459 throw (::com::sun::star::uno::RuntimeException
);
460 virtual ::com::sun::star::uno::Sequence
<
461 ::com::sun::star::uno::Reference
<
462 ::com::sun::star::reflection::XInterfaceTypeDescription
> > SAL_CALL
463 getMandatoryInterfaces()
464 throw (::com::sun::star::uno::RuntimeException
);
465 virtual ::com::sun::star::uno::Sequence
<
466 ::com::sun::star::uno::Reference
<
467 ::com::sun::star::reflection::XInterfaceTypeDescription
> > SAL_CALL
468 getOptionalInterfaces()
469 throw (::com::sun::star::uno::RuntimeException
);
470 virtual ::com::sun::star::uno::Sequence
<
471 ::com::sun::star::uno::Reference
<
472 ::com::sun::star::reflection::XPropertyTypeDescription
> > SAL_CALL
474 throw (::com::sun::star::uno::RuntimeException
);
476 // XServiceTypeDescription2
477 virtual sal_Bool SAL_CALL
isSingleInterfaceBased()
478 throw (::com::sun::star::uno::RuntimeException
);
479 virtual ::com::sun::star::uno::Reference
< XTypeDescription
> SAL_CALL
480 getInterface() throw (::com::sun::star::uno::RuntimeException
);
481 virtual ::com::sun::star::uno::Sequence
<
482 ::com::sun::star::uno::Reference
<
483 ::com::sun::star::reflection::XServiceConstructorDescription
> >
484 SAL_CALL
getConstructors()
485 throw (::com::sun::star::uno::RuntimeException
);
487 virtual sal_Bool SAL_CALL
isPublished()
488 throw (::com::sun::star::uno::RuntimeException
)
489 { return _published
; }
493 throw (::com::sun::star::uno::RuntimeException
);
496 //==================================================================================================
497 class ModuleTypeDescriptionImpl
: public WeakImplHelper1
< XModuleTypeDescription
>
500 com::sun::star::uno::Reference
< XTypeDescriptionEnumerationAccess
> _xTDMgr
;
502 Sequence
< com::sun::star::uno::Reference
< XTypeDescription
> > * _pMembers
;
505 ModuleTypeDescriptionImpl(
506 const com::sun::star::uno::Reference
<
507 XTypeDescriptionEnumerationAccess
> & xTDMgr
,
508 const OUString
& rName
)
509 : _aName( rName
), _xTDMgr( xTDMgr
), _pMembers( 0 )
511 g_moduleCount
.modCnt
.acquire( &g_moduleCount
.modCnt
);
513 virtual ~ModuleTypeDescriptionImpl();
516 virtual TypeClass SAL_CALL
518 throw( ::com::sun::star::uno::RuntimeException
);
519 virtual OUString SAL_CALL
521 throw( ::com::sun::star::uno::RuntimeException
);
523 // XModuleTypeDescription
524 virtual ::com::sun::star::uno::Sequence
<
525 ::com::sun::star::uno::Reference
<
526 ::com::sun::star::reflection::XTypeDescription
> > SAL_CALL
528 throw ( ::com::sun::star::uno::RuntimeException
);
531 //==================================================================================================
532 class ConstantTypeDescriptionImpl
: public WeakImplHelper1
< XConstantTypeDescription
>
538 ConstantTypeDescriptionImpl( const OUString
& rName
,
540 : _aName( rName
), _aValue( rValue
)
542 g_moduleCount
.modCnt
.acquire( &g_moduleCount
.modCnt
);
544 virtual ~ConstantTypeDescriptionImpl();
547 virtual TypeClass SAL_CALL
549 throw( ::com::sun::star::uno::RuntimeException
);
550 virtual OUString SAL_CALL
552 throw( ::com::sun::star::uno::RuntimeException
);
554 // XConstantTypeDescription
555 virtual ::com::sun::star::uno::Any SAL_CALL
557 throw ( ::com::sun::star::uno::RuntimeException
);
560 //==================================================================================================
561 class ConstantsTypeDescriptionImpl
:
562 public WeakImplHelper2
< XConstantsTypeDescription
, XPublished
>
565 Sequence
< sal_Int8
> _aBytes
;
566 Sequence
< com::sun::star::uno::Reference
< XConstantTypeDescription
> > *
572 ConstantsTypeDescriptionImpl( const OUString
& rName
,
573 const Sequence
< sal_Int8
> & rBytes
,
575 : _aName( rName
), _aBytes( rBytes
), _pMembers( 0 ), _published( published
)
577 g_moduleCount
.modCnt
.acquire( &g_moduleCount
.modCnt
);
579 virtual ~ConstantsTypeDescriptionImpl();
582 virtual TypeClass SAL_CALL
584 throw( ::com::sun::star::uno::RuntimeException
);
585 virtual OUString SAL_CALL
587 throw( ::com::sun::star::uno::RuntimeException
);
589 // XConstantsTypeDescription
591 Sequence
< com::sun::star::uno::Reference
< XConstantTypeDescription
> >
592 SAL_CALL
getConstants() throw ( RuntimeException
);
594 virtual sal_Bool SAL_CALL
isPublished()
595 throw (::com::sun::star::uno::RuntimeException
)
596 { return _published
; }
599 //==================================================================================================
600 class SingletonTypeDescriptionImpl
:
601 public WeakImplHelper2
< XSingletonTypeDescription2
, XPublished
>
605 com::sun::star::uno::Reference
< XHierarchicalNameAccess
> _xTDMgr
;
606 com::sun::star::uno::Reference
< XTypeDescription
> _xInterfaceTD
;
607 com::sun::star::uno::Reference
< XServiceTypeDescription
> _xServiceTD
;
614 SingletonTypeDescriptionImpl(
615 const com::sun::star::uno::Reference
< XHierarchicalNameAccess
> &
617 const OUString
& rName
, const OUString
& rBaseName
, bool published
)
618 : _aName( rName
), _aBaseName( rBaseName
), _xTDMgr( xTDMgr
),
619 _published( published
)
621 g_moduleCount
.modCnt
.acquire( &g_moduleCount
.modCnt
);
623 virtual ~SingletonTypeDescriptionImpl();
626 virtual TypeClass SAL_CALL
628 throw( ::com::sun::star::uno::RuntimeException
);
629 virtual OUString SAL_CALL
631 throw( ::com::sun::star::uno::RuntimeException
);
633 // XSingletonTypeDescription
634 virtual com::sun::star::uno::Reference
< XServiceTypeDescription
> SAL_CALL
635 getService() throw ( ::com::sun::star::uno::RuntimeException
);
637 // XSingletonTypeDescription2
638 virtual sal_Bool SAL_CALL
isInterfaceBased()
639 throw (::com::sun::star::uno::RuntimeException
);
640 virtual com::sun::star::uno::Reference
< XTypeDescription
> SAL_CALL
641 getInterface() throw (::com::sun::star::uno::RuntimeException
);
643 virtual sal_Bool SAL_CALL
isPublished()
644 throw (::com::sun::star::uno::RuntimeException
)
645 { return _published
; }
650 #endif /* _STOC_RDBTDP_BASE_HXX */