1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir //  #define TEST_LIST_CLASSES
28*cdf0e10cSrcweir //  #define TRACE(x) OSL_TRACE(x)
29*cdf0e10cSrcweir #define TRACE(x)
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <osl/diagnose.h>
32*cdf0e10cSrcweir #include <osl/mutex.hxx>
33*cdf0e10cSrcweir #include <uno/mapping.hxx>
34*cdf0e10cSrcweir #include <uno/dispatcher.h>
35*cdf0e10cSrcweir #include <cppuhelper/weak.hxx>
36*cdf0e10cSrcweir #include <cppuhelper/factory.hxx>
37*cdf0e10cSrcweir #include <cppuhelper/component.hxx>
38*cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #include "lrucache.hxx"
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir #ifdef TEST_LIST_CLASSES
43*cdf0e10cSrcweir #include <list>
44*cdf0e10cSrcweir #include <algorithm>
45*cdf0e10cSrcweir #endif
46*cdf0e10cSrcweir #include <hash_map>
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp>
49*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
50*cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir #include <com/sun/star/reflection/XIdlClass.hpp>
53*cdf0e10cSrcweir #include <com/sun/star/reflection/XIdlReflection.hpp>
54*cdf0e10cSrcweir #include <com/sun/star/reflection/XIdlField.hpp>
55*cdf0e10cSrcweir #include <com/sun/star/reflection/XIdlField2.hpp>
56*cdf0e10cSrcweir #include <com/sun/star/reflection/XIdlMethod.hpp>
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir using namespace std;
59*cdf0e10cSrcweir using namespace osl;
60*cdf0e10cSrcweir using namespace rtl;
61*cdf0e10cSrcweir using namespace cppu;
62*cdf0e10cSrcweir using namespace com::sun::star::uno;
63*cdf0e10cSrcweir using namespace com::sun::star::lang;
64*cdf0e10cSrcweir using namespace com::sun::star::reflection;
65*cdf0e10cSrcweir using namespace com::sun::star::container;
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir namespace stoc_corefl
69*cdf0e10cSrcweir {
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir #ifdef TEST_LIST_CLASSES
72*cdf0e10cSrcweir typedef list< OUString > ClassNameList;
73*cdf0e10cSrcweir extern ClassNameList g_aClassNames;
74*cdf0e10cSrcweir #endif
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
77*cdf0e10cSrcweir Mutex & getMutexAccess();
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
80*cdf0e10cSrcweir inline bool td_equals( typelib_TypeDescription * pTD, typelib_TypeDescriptionReference * pType )
81*cdf0e10cSrcweir {
82*cdf0e10cSrcweir 	return (pTD->pWeakRef == pType ||
83*cdf0e10cSrcweir 			(pTD->pTypeName->length == pType->pTypeName->length &&
84*cdf0e10cSrcweir 			 rtl_ustr_compare( pTD->pTypeName->buffer, pType->pTypeName->buffer ) == 0));
85*cdf0e10cSrcweir }
86*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
87*cdf0e10cSrcweir inline typelib_TypeDescription * getTypeByName( const OUString & rName )
88*cdf0e10cSrcweir {
89*cdf0e10cSrcweir 	typelib_TypeDescription * pTypeDescr = 0;
90*cdf0e10cSrcweir 	typelib_typedescription_getByName( &pTypeDescr, rName.pData );
91*cdf0e10cSrcweir 	if (! pTypeDescr->bComplete)
92*cdf0e10cSrcweir 		typelib_typedescription_complete( &pTypeDescr );
93*cdf0e10cSrcweir 	return pTypeDescr;
94*cdf0e10cSrcweir }
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir typedef std::hash_map< OUString, WeakReference< XIdlField >,
97*cdf0e10cSrcweir 	FctHashOUString, equal_to< OUString > > OUString2Field;
98*cdf0e10cSrcweir typedef std::hash_map< OUString, WeakReference< XIdlMethod >,
99*cdf0e10cSrcweir 	FctHashOUString, equal_to< OUString > > OUString2Method;
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir //==================================================================================================
102*cdf0e10cSrcweir class IdlReflectionServiceImpl
103*cdf0e10cSrcweir 	: public OComponentHelper
104*cdf0e10cSrcweir 	, public XIdlReflection
105*cdf0e10cSrcweir 	, public XHierarchicalNameAccess
106*cdf0e10cSrcweir 	, public XServiceInfo
107*cdf0e10cSrcweir {
108*cdf0e10cSrcweir 	Mutex									_aComponentMutex;
109*cdf0e10cSrcweir 	Reference< XMultiServiceFactory >		_xMgr;
110*cdf0e10cSrcweir 	Reference< XHierarchicalNameAccess >	_xTDMgr;
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir 	// caching
113*cdf0e10cSrcweir 	LRU_CacheAnyByOUString					_aElements;
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir     Mapping						_aCpp2Uno;
116*cdf0e10cSrcweir 	Mapping						_aUno2Cpp;
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir 	inline Reference< XIdlClass > constructClass( typelib_TypeDescription * pTypeDescr );
119*cdf0e10cSrcweir public:
120*cdf0e10cSrcweir 	Reference< XHierarchicalNameAccess > getTDMgr() const
121*cdf0e10cSrcweir 		{ return _xTDMgr; }
122*cdf0e10cSrcweir 	Reference< XMultiServiceFactory > getSMgr() const
123*cdf0e10cSrcweir 		{ return _xMgr; }
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir     const Mapping & getCpp2Uno() throw(::com::sun::star::uno::RuntimeException);
126*cdf0e10cSrcweir 	const Mapping & getUno2Cpp() throw(::com::sun::star::uno::RuntimeException);
127*cdf0e10cSrcweir 	uno_Interface * mapToUno( const Any & rObj, typelib_InterfaceTypeDescription * pTo ) throw(::com::sun::star::uno::RuntimeException);
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir 	// ctor/ dtor
130*cdf0e10cSrcweir 	IdlReflectionServiceImpl( const Reference< XComponentContext > & xContext );
131*cdf0e10cSrcweir 	virtual ~IdlReflectionServiceImpl();
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir 	// XInterface
134*cdf0e10cSrcweir 	virtual Any SAL_CALL queryInterface( const Type & rType ) throw(::com::sun::star::uno::RuntimeException);
135*cdf0e10cSrcweir 	virtual void SAL_CALL acquire() throw();
136*cdf0e10cSrcweir 	virtual void SAL_CALL release() throw();
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir 	// some XComponent part from OComponentHelper
139*cdf0e10cSrcweir 	virtual void SAL_CALL dispose() throw(::com::sun::star::uno::RuntimeException);
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir 	// XServiceInfo
142*cdf0e10cSrcweir 	virtual OUString SAL_CALL getImplementationName() throw(::com::sun::star::uno::RuntimeException);
143*cdf0e10cSrcweir 	virtual sal_Bool SAL_CALL supportsService( const OUString & rServiceName ) throw(::com::sun::star::uno::RuntimeException);
144*cdf0e10cSrcweir 	virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException);
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir 	// XTypeProvider
147*cdf0e10cSrcweir 	virtual Sequence< Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException);
148*cdf0e10cSrcweir 	virtual Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (::com::sun::star::uno::RuntimeException);
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir 	// XIdlReflection
151*cdf0e10cSrcweir 	virtual Reference< XIdlClass > SAL_CALL forName( const OUString & rTypeName ) throw(::com::sun::star::uno::RuntimeException);
152*cdf0e10cSrcweir 	virtual Reference< XIdlClass > SAL_CALL getType( const Any & rObj ) throw(::com::sun::star::uno::RuntimeException);
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir 	// XHierarchicalNameAccess
155*cdf0e10cSrcweir 	virtual Any SAL_CALL getByHierarchicalName( const OUString & rName ) throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException);
156*cdf0e10cSrcweir 	virtual sal_Bool SAL_CALL hasByHierarchicalName( const OUString & rName ) throw(::com::sun::star::uno::RuntimeException);
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir 	Reference< XIdlClass > forType( typelib_TypeDescription * pTypeDescr ) throw(::com::sun::star::uno::RuntimeException);
159*cdf0e10cSrcweir 	Reference< XIdlClass > forType( typelib_TypeDescriptionReference * pRef ) throw(::com::sun::star::uno::RuntimeException);
160*cdf0e10cSrcweir };
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir //==================================================================================================
163*cdf0e10cSrcweir class IdlClassImpl
164*cdf0e10cSrcweir 	: public WeakImplHelper1< XIdlClass >
165*cdf0e10cSrcweir {
166*cdf0e10cSrcweir 	IdlReflectionServiceImpl *	_pReflection;
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir 	OUString					_aName;
169*cdf0e10cSrcweir 	TypeClass					_eTypeClass;
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir 	typelib_TypeDescription *	_pTypeDescr;
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir public:
174*cdf0e10cSrcweir 	typelib_TypeDescription *	getTypeDescr() const
175*cdf0e10cSrcweir 		{ return _pTypeDescr; }
176*cdf0e10cSrcweir 	IdlReflectionServiceImpl *	getReflection() const
177*cdf0e10cSrcweir 		{ return _pReflection; }
178*cdf0e10cSrcweir 	Reference< XMultiServiceFactory > getSMgr() const
179*cdf0e10cSrcweir 		{ return _pReflection->getSMgr(); }
180*cdf0e10cSrcweir 	Reference< XHierarchicalNameAccess > getTDMgr() const
181*cdf0e10cSrcweir 		{ return getReflection()->getTDMgr(); }
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir 	// Ctor
184*cdf0e10cSrcweir 	IdlClassImpl( IdlReflectionServiceImpl * pReflection,
185*cdf0e10cSrcweir 				  const OUString & rName, typelib_TypeClass eTypeClass,
186*cdf0e10cSrcweir 				  typelib_TypeDescription * pTypeDescr );
187*cdf0e10cSrcweir 	virtual ~IdlClassImpl();
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir 	// XIdlClassImpl default implementation
190*cdf0e10cSrcweir     virtual TypeClass SAL_CALL getTypeClass() throw(::com::sun::star::uno::RuntimeException);
191*cdf0e10cSrcweir     virtual OUString SAL_CALL getName() throw(::com::sun::star::uno::RuntimeException);
192*cdf0e10cSrcweir     virtual sal_Bool SAL_CALL equals( const Reference< XIdlClass >& xType ) throw(::com::sun::star::uno::RuntimeException);
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir     virtual sal_Bool SAL_CALL isAssignableFrom( const Reference< XIdlClass > & xType ) throw(::com::sun::star::uno::RuntimeException);
195*cdf0e10cSrcweir     virtual void SAL_CALL createObject( Any & rObj ) throw(::com::sun::star::uno::RuntimeException);
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir 	// def impl ????
198*cdf0e10cSrcweir     virtual Sequence< Reference< XIdlClass > > SAL_CALL getClasses() throw(::com::sun::star::uno::RuntimeException);
199*cdf0e10cSrcweir     virtual Reference< XIdlClass > SAL_CALL getClass( const OUString & rName ) throw(::com::sun::star::uno::RuntimeException);
200*cdf0e10cSrcweir     virtual Sequence< Reference< XIdlClass > > SAL_CALL getInterfaces() throw(::com::sun::star::uno::RuntimeException);
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir 	// structs, interfaces
203*cdf0e10cSrcweir     virtual Sequence< Reference< XIdlClass > > SAL_CALL getSuperclasses() throw(::com::sun::star::uno::RuntimeException);
204*cdf0e10cSrcweir 	// structs
205*cdf0e10cSrcweir     virtual Reference< XIdlField > SAL_CALL getField( const OUString & rName ) throw(::com::sun::star::uno::RuntimeException);
206*cdf0e10cSrcweir     virtual Sequence< Reference< XIdlField > > SAL_CALL getFields() throw(::com::sun::star::uno::RuntimeException);
207*cdf0e10cSrcweir 	// interfaces
208*cdf0e10cSrcweir     virtual Uik SAL_CALL getUik() throw(::com::sun::star::uno::RuntimeException);
209*cdf0e10cSrcweir     virtual Reference< XIdlMethod > SAL_CALL getMethod( const OUString & rName ) throw(::com::sun::star::uno::RuntimeException);
210*cdf0e10cSrcweir     virtual Sequence< Reference< XIdlMethod > > SAL_CALL getMethods() throw(::com::sun::star::uno::RuntimeException);
211*cdf0e10cSrcweir 	// array
212*cdf0e10cSrcweir     virtual Reference< XIdlClass > SAL_CALL getComponentType() throw(::com::sun::star::uno::RuntimeException);
213*cdf0e10cSrcweir     virtual Reference< XIdlArray > SAL_CALL getArray() throw(::com::sun::star::uno::RuntimeException);
214*cdf0e10cSrcweir };
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir //==================================================================================================
217*cdf0e10cSrcweir class InterfaceIdlClassImpl
218*cdf0e10cSrcweir 	: public IdlClassImpl
219*cdf0e10cSrcweir {
220*cdf0e10cSrcweir 	typedef pair< OUString, typelib_TypeDescription * > MemberInit;
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir 	Sequence< Reference< XIdlClass > >		_xSuperClasses;
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir 	MemberInit *							_pSortedMemberInit; // first methods, then attributes
225*cdf0e10cSrcweir 	OUString2Field							_aName2Field;
226*cdf0e10cSrcweir 	OUString2Method							_aName2Method;
227*cdf0e10cSrcweir 	sal_Int32								_nMethods;
228*cdf0e10cSrcweir 	sal_Int32								_nAttributes;
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir 	void initMembers();
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir public:
233*cdf0e10cSrcweir 	typelib_InterfaceTypeDescription * getTypeDescr() const
234*cdf0e10cSrcweir 		{ return (typelib_InterfaceTypeDescription *)IdlClassImpl::getTypeDescr(); }
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir 	// ctor/ dtor
237*cdf0e10cSrcweir 	InterfaceIdlClassImpl( IdlReflectionServiceImpl * pReflection,
238*cdf0e10cSrcweir 						   const OUString & rName, typelib_TypeClass eTypeClass,
239*cdf0e10cSrcweir 						   typelib_TypeDescription * pTypeDescr )
240*cdf0e10cSrcweir 		: IdlClassImpl( pReflection, rName, eTypeClass, pTypeDescr )
241*cdf0e10cSrcweir 		, _pSortedMemberInit( 0 )
242*cdf0e10cSrcweir 		, _nMethods( 0 )
243*cdf0e10cSrcweir 		, _nAttributes( 0 )
244*cdf0e10cSrcweir 		{}
245*cdf0e10cSrcweir 	virtual ~InterfaceIdlClassImpl();
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir 	// IdlClassImpl modifications
248*cdf0e10cSrcweir     virtual sal_Bool SAL_CALL isAssignableFrom( const Reference< XIdlClass > & xType ) throw(::com::sun::star::uno::RuntimeException);
249*cdf0e10cSrcweir     virtual Sequence< Reference< XIdlClass > > SAL_CALL getSuperclasses() throw(::com::sun::star::uno::RuntimeException);
250*cdf0e10cSrcweir     virtual Uik SAL_CALL getUik() throw(::com::sun::star::uno::RuntimeException);
251*cdf0e10cSrcweir     virtual Reference< XIdlMethod > SAL_CALL getMethod( const OUString & rName ) throw(::com::sun::star::uno::RuntimeException);
252*cdf0e10cSrcweir     virtual Sequence< Reference< XIdlMethod > > SAL_CALL getMethods() throw(::com::sun::star::uno::RuntimeException);
253*cdf0e10cSrcweir     virtual Reference< XIdlField > SAL_CALL getField( const OUString & rName ) throw(::com::sun::star::uno::RuntimeException);
254*cdf0e10cSrcweir     virtual Sequence< Reference< XIdlField > > SAL_CALL getFields() throw(::com::sun::star::uno::RuntimeException);
255*cdf0e10cSrcweir     virtual void SAL_CALL createObject( Any & rObj ) throw(::com::sun::star::uno::RuntimeException);
256*cdf0e10cSrcweir };
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir //==================================================================================================
259*cdf0e10cSrcweir class CompoundIdlClassImpl
260*cdf0e10cSrcweir 	: public IdlClassImpl
261*cdf0e10cSrcweir {
262*cdf0e10cSrcweir 	Reference< XIdlClass >					_xSuperClass;
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir 	Sequence< Reference< XIdlField > > *	_pFields;
265*cdf0e10cSrcweir 	OUString2Field							_aName2Field;
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir public:
268*cdf0e10cSrcweir 	typelib_CompoundTypeDescription * getTypeDescr() const
269*cdf0e10cSrcweir 		{ return (typelib_CompoundTypeDescription *)IdlClassImpl::getTypeDescr(); }
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir 	// ctor/ dtor
272*cdf0e10cSrcweir 	CompoundIdlClassImpl( IdlReflectionServiceImpl * pReflection,
273*cdf0e10cSrcweir 						  const OUString & rName, typelib_TypeClass eTypeClass,
274*cdf0e10cSrcweir 						  typelib_TypeDescription * pTypeDescr )
275*cdf0e10cSrcweir 		: IdlClassImpl( pReflection, rName, eTypeClass, pTypeDescr )
276*cdf0e10cSrcweir 		, _pFields( 0 )
277*cdf0e10cSrcweir 		{}
278*cdf0e10cSrcweir 	virtual ~CompoundIdlClassImpl();
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir 	// IdlClassImpl modifications
281*cdf0e10cSrcweir     virtual sal_Bool SAL_CALL isAssignableFrom( const Reference< XIdlClass > & xType ) throw(::com::sun::star::uno::RuntimeException);
282*cdf0e10cSrcweir     virtual Sequence< Reference< XIdlClass > > SAL_CALL getSuperclasses() throw(::com::sun::star::uno::RuntimeException);
283*cdf0e10cSrcweir     virtual Reference< XIdlField > SAL_CALL getField( const OUString & rName ) throw(::com::sun::star::uno::RuntimeException);
284*cdf0e10cSrcweir     virtual Sequence< Reference< XIdlField > > SAL_CALL getFields() throw(::com::sun::star::uno::RuntimeException);
285*cdf0e10cSrcweir };
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir //==================================================================================================
288*cdf0e10cSrcweir class ArrayIdlClassImpl
289*cdf0e10cSrcweir 	: public IdlClassImpl
290*cdf0e10cSrcweir 	, public XIdlArray
291*cdf0e10cSrcweir {
292*cdf0e10cSrcweir public:
293*cdf0e10cSrcweir 	typelib_IndirectTypeDescription * getTypeDescr() const
294*cdf0e10cSrcweir 		{ return (typelib_IndirectTypeDescription *)IdlClassImpl::getTypeDescr(); }
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir 	// ctor
297*cdf0e10cSrcweir 	ArrayIdlClassImpl( IdlReflectionServiceImpl * pReflection,
298*cdf0e10cSrcweir 					   const OUString & rName, typelib_TypeClass eTypeClass,
299*cdf0e10cSrcweir 					   typelib_TypeDescription * pTypeDescr )
300*cdf0e10cSrcweir 		: IdlClassImpl( pReflection, rName, eTypeClass, pTypeDescr )
301*cdf0e10cSrcweir 		{}
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir 	virtual Any SAL_CALL queryInterface( const Type & rType ) throw(::com::sun::star::uno::RuntimeException);
304*cdf0e10cSrcweir 	virtual void SAL_CALL acquire() throw();
305*cdf0e10cSrcweir 	virtual void SAL_CALL release() throw();
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir 	// XTypeProvider
308*cdf0e10cSrcweir 	virtual Sequence< Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException);
309*cdf0e10cSrcweir 	virtual Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (::com::sun::star::uno::RuntimeException);
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir 	// IdlClassImpl modifications
312*cdf0e10cSrcweir     virtual sal_Bool SAL_CALL isAssignableFrom( const Reference< XIdlClass > & xType ) throw(::com::sun::star::uno::RuntimeException);
313*cdf0e10cSrcweir     virtual Reference< XIdlClass > SAL_CALL getComponentType() throw(::com::sun::star::uno::RuntimeException);
314*cdf0e10cSrcweir     virtual Reference< XIdlArray > SAL_CALL getArray() throw(::com::sun::star::uno::RuntimeException);
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir 	// XIdlArray
317*cdf0e10cSrcweir     virtual void SAL_CALL realloc( Any & rArray, sal_Int32 nLen ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
318*cdf0e10cSrcweir     virtual sal_Int32 SAL_CALL getLen( const Any & rArray ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
319*cdf0e10cSrcweir     virtual Any SAL_CALL get( const Any & rArray, sal_Int32 nIndex ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::ArrayIndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
320*cdf0e10cSrcweir     virtual void SAL_CALL set( Any & rArray, sal_Int32 nIndex, const Any & rNewValue ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::ArrayIndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
321*cdf0e10cSrcweir };
322*cdf0e10cSrcweir 
323*cdf0e10cSrcweir //==================================================================================================
324*cdf0e10cSrcweir class EnumIdlClassImpl
325*cdf0e10cSrcweir 	: public IdlClassImpl
326*cdf0e10cSrcweir {
327*cdf0e10cSrcweir 	Sequence< Reference< XIdlField > > * _pFields;
328*cdf0e10cSrcweir 	OUString2Field						 _aName2Field;
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir public:
331*cdf0e10cSrcweir 	typelib_EnumTypeDescription * getTypeDescr() const
332*cdf0e10cSrcweir 		{ return (typelib_EnumTypeDescription *)IdlClassImpl::getTypeDescr(); }
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir 	// ctor/ dtor
335*cdf0e10cSrcweir 	EnumIdlClassImpl( IdlReflectionServiceImpl * pReflection,
336*cdf0e10cSrcweir 					  const OUString & rName, typelib_TypeClass eTypeClass,
337*cdf0e10cSrcweir 					  typelib_TypeDescription * pTypeDescr )
338*cdf0e10cSrcweir 		: IdlClassImpl( pReflection, rName, eTypeClass, pTypeDescr )
339*cdf0e10cSrcweir 		, _pFields( 0 )
340*cdf0e10cSrcweir 		{}
341*cdf0e10cSrcweir 	virtual ~EnumIdlClassImpl();
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir 	// IdlClassImpl modifications
344*cdf0e10cSrcweir     virtual Reference< XIdlField > SAL_CALL getField( const OUString & rName ) throw(::com::sun::star::uno::RuntimeException);
345*cdf0e10cSrcweir     virtual Sequence< Reference< XIdlField > > SAL_CALL getFields() throw(::com::sun::star::uno::RuntimeException);
346*cdf0e10cSrcweir     virtual void SAL_CALL createObject( Any & rObj ) throw(::com::sun::star::uno::RuntimeException);
347*cdf0e10cSrcweir };
348*cdf0e10cSrcweir 
349*cdf0e10cSrcweir //==================================================================================================
350*cdf0e10cSrcweir class IdlMemberImpl
351*cdf0e10cSrcweir 	: public WeakImplHelper1< XIdlMember >
352*cdf0e10cSrcweir {
353*cdf0e10cSrcweir 	IdlReflectionServiceImpl *	_pReflection;
354*cdf0e10cSrcweir 	OUString					_aName;
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir 	typelib_TypeDescription *	_pTypeDescr;
357*cdf0e10cSrcweir 	typelib_TypeDescription *	_pDeclTypeDescr;
358*cdf0e10cSrcweir 
359*cdf0e10cSrcweir protected:
360*cdf0e10cSrcweir 	Reference< XIdlClass >		_xDeclClass;
361*cdf0e10cSrcweir 
362*cdf0e10cSrcweir public:
363*cdf0e10cSrcweir 	IdlReflectionServiceImpl *	getReflection() const
364*cdf0e10cSrcweir 		{ return _pReflection; }
365*cdf0e10cSrcweir 	Reference< XMultiServiceFactory > getSMgr() const
366*cdf0e10cSrcweir 		{ return _pReflection->getSMgr(); }
367*cdf0e10cSrcweir 	typelib_TypeDescription *	getTypeDescr() const
368*cdf0e10cSrcweir 		{ return _pTypeDescr; }
369*cdf0e10cSrcweir 	typelib_TypeDescription *	getDeclTypeDescr() const
370*cdf0e10cSrcweir 		{ return _pDeclTypeDescr; }
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir 	// ctor/ dtor
373*cdf0e10cSrcweir 	IdlMemberImpl( IdlReflectionServiceImpl * pReflection, const OUString & rName,
374*cdf0e10cSrcweir 				   typelib_TypeDescription * pTypeDescr, typelib_TypeDescription * pDeclTypeDescr );
375*cdf0e10cSrcweir 	virtual ~IdlMemberImpl();
376*cdf0e10cSrcweir 
377*cdf0e10cSrcweir 	// XIdlMember
378*cdf0e10cSrcweir     virtual Reference< XIdlClass > SAL_CALL getDeclaringClass() throw(::com::sun::star::uno::RuntimeException);
379*cdf0e10cSrcweir     virtual OUString SAL_CALL getName() throw(::com::sun::star::uno::RuntimeException);
380*cdf0e10cSrcweir };
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
383*cdf0e10cSrcweir // coerces to type descr pTo else queries for it: the interface pointer is returned via rDest
384*cdf0e10cSrcweir // ## type to XidlClass coercion possible
385*cdf0e10cSrcweir inline sal_Bool extract(
386*cdf0e10cSrcweir 	const Any & rObj, typelib_InterfaceTypeDescription * pTo,
387*cdf0e10cSrcweir 	Reference< XInterface > & rDest,
388*cdf0e10cSrcweir 	IdlReflectionServiceImpl * pRefl )
389*cdf0e10cSrcweir {
390*cdf0e10cSrcweir 	rDest.clear();
391*cdf0e10cSrcweir 	if (0 != pTo)
392*cdf0e10cSrcweir 	{
393*cdf0e10cSrcweir         if (! rObj.hasValue())
394*cdf0e10cSrcweir             return sal_True;
395*cdf0e10cSrcweir 		if (rObj.getValueTypeClass() == TypeClass_INTERFACE)
396*cdf0e10cSrcweir 		{
397*cdf0e10cSrcweir 			return ::uno_type_assignData(
398*cdf0e10cSrcweir 				&rDest, ((typelib_TypeDescription *)pTo)->pWeakRef,
399*cdf0e10cSrcweir 				const_cast< void * >( rObj.getValue() ), rObj.getValueTypeRef(),
400*cdf0e10cSrcweir 				reinterpret_cast< uno_QueryInterfaceFunc >(cpp_queryInterface),
401*cdf0e10cSrcweir                 reinterpret_cast< uno_AcquireFunc >(cpp_acquire),
402*cdf0e10cSrcweir                 reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
403*cdf0e10cSrcweir 		}
404*cdf0e10cSrcweir 		else if (rObj.getValueTypeClass() == TypeClass_TYPE)
405*cdf0e10cSrcweir 		{
406*cdf0e10cSrcweir 			rDest = pRefl->forType( reinterpret_cast< const Type * >( rObj.getValue() )->getTypeLibType() );
407*cdf0e10cSrcweir 			return rDest.is();
408*cdf0e10cSrcweir 		}
409*cdf0e10cSrcweir 	}
410*cdf0e10cSrcweir 	return sal_False;
411*cdf0e10cSrcweir }
412*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
413*cdf0e10cSrcweir inline sal_Bool coerce_assign(
414*cdf0e10cSrcweir 	void * pDest, typelib_TypeDescription * pTD, const Any & rSource,
415*cdf0e10cSrcweir 	IdlReflectionServiceImpl * pRefl )
416*cdf0e10cSrcweir {
417*cdf0e10cSrcweir     if (pTD->eTypeClass == typelib_TypeClass_INTERFACE)
418*cdf0e10cSrcweir     {
419*cdf0e10cSrcweir         Reference< XInterface > xVal;
420*cdf0e10cSrcweir         if (extract( rSource, (typelib_InterfaceTypeDescription *)pTD, xVal, pRefl ))
421*cdf0e10cSrcweir         {
422*cdf0e10cSrcweir             if (*(XInterface **)pDest)
423*cdf0e10cSrcweir                 (*(XInterface **)pDest)->release();
424*cdf0e10cSrcweir             *(XInterface **)pDest = xVal.get();
425*cdf0e10cSrcweir             if (*(XInterface **)pDest)
426*cdf0e10cSrcweir                 (*(XInterface **)pDest)->acquire();
427*cdf0e10cSrcweir             return sal_True;
428*cdf0e10cSrcweir         }
429*cdf0e10cSrcweir         return sal_False;
430*cdf0e10cSrcweir     }
431*cdf0e10cSrcweir     else if (pTD->eTypeClass == typelib_TypeClass_ANY)
432*cdf0e10cSrcweir     {
433*cdf0e10cSrcweir         return uno_assignData(
434*cdf0e10cSrcweir             pDest, pTD,
435*cdf0e10cSrcweir             (void *)&rSource, pTD,
436*cdf0e10cSrcweir             reinterpret_cast< uno_QueryInterfaceFunc >(cpp_queryInterface),
437*cdf0e10cSrcweir             reinterpret_cast< uno_AcquireFunc >(cpp_acquire),
438*cdf0e10cSrcweir             reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
439*cdf0e10cSrcweir     }
440*cdf0e10cSrcweir     else
441*cdf0e10cSrcweir     {
442*cdf0e10cSrcweir         return uno_type_assignData(
443*cdf0e10cSrcweir             pDest, pTD->pWeakRef,
444*cdf0e10cSrcweir             (void *)rSource.getValue(), rSource.getValueTypeRef(),
445*cdf0e10cSrcweir             reinterpret_cast< uno_QueryInterfaceFunc >(cpp_queryInterface),
446*cdf0e10cSrcweir             reinterpret_cast< uno_AcquireFunc >(cpp_acquire),
447*cdf0e10cSrcweir             reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
448*cdf0e10cSrcweir     }
449*cdf0e10cSrcweir }
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir }
452*cdf0e10cSrcweir 
453*cdf0e10cSrcweir 
454