xref: /aoo41x/main/stoc/source/tdmanager/tdmgr.cxx (revision cdf0e10c)
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 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_stoc.hxx"
30*cdf0e10cSrcweir #include <osl/diagnose.h>
31*cdf0e10cSrcweir #include <osl/mutex.hxx>
32*cdf0e10cSrcweir #include "rtl/ustrbuf.hxx"
33*cdf0e10cSrcweir #include <cppuhelper/factory.hxx>
34*cdf0e10cSrcweir #ifndef _CPPUHELPER_IMPLBASE5_HXX_
35*cdf0e10cSrcweir #include <cppuhelper/compbase5.hxx>
36*cdf0e10cSrcweir #endif
37*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
38*cdf0e10cSrcweir #ifndef _CPPUHELPER_IMPLEMENTATIONENTRY_HXX_
39*cdf0e10cSrcweir #include <cppuhelper/implementationentry.hxx>
40*cdf0e10cSrcweir #endif
41*cdf0e10cSrcweir #include "tdmgr_common.hxx"
42*cdf0e10cSrcweir #include "tdmgr_tdenumeration.hxx"
43*cdf0e10cSrcweir #include "lrucache.hxx"
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/lang/XEventListener.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/lang/XTypeProvider.hpp>
49*cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
50*cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
51*cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
52*cdf0e10cSrcweir #include <com/sun/star/container/XSet.hpp>
53*cdf0e10cSrcweir #include <com/sun/star/container/XContentEnumerationAccess.hpp>
54*cdf0e10cSrcweir #include <com/sun/star/reflection/XTypeDescription.hpp>
55*cdf0e10cSrcweir #include <com/sun/star/reflection/XArrayTypeDescription.hpp>
56*cdf0e10cSrcweir #include <com/sun/star/reflection/XIndirectTypeDescription.hpp>
57*cdf0e10cSrcweir #include <com/sun/star/reflection/XInterfaceTypeDescription.hpp>
58*cdf0e10cSrcweir #include "com/sun/star/reflection/XStructTypeDescription.hpp"
59*cdf0e10cSrcweir #include <com/sun/star/reflection/XTypeDescriptionEnumerationAccess.hpp>
60*cdf0e10cSrcweir #include <com/sun/star/registry/XRegistryKey.hpp>
61*cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir #include <algorithm>
64*cdf0e10cSrcweir #include <vector>
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir using namespace std;
67*cdf0e10cSrcweir using namespace cppu;
68*cdf0e10cSrcweir using namespace rtl;
69*cdf0e10cSrcweir using namespace osl;
70*cdf0e10cSrcweir using namespace com::sun::star;
71*cdf0e10cSrcweir using namespace com::sun::star::uno;
72*cdf0e10cSrcweir using namespace com::sun::star::lang;
73*cdf0e10cSrcweir using namespace com::sun::star::reflection;
74*cdf0e10cSrcweir using namespace com::sun::star::container;
75*cdf0e10cSrcweir using namespace com::sun::star::registry;
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir static const sal_Int32 CACHE_SIZE = 512;
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir #define SERVICENAME "com.sun.star.reflection.TypeDescriptionManager"
82*cdf0e10cSrcweir #define IMPLNAME	"com.sun.star.comp.stoc.TypeDescriptionManager"
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
85*cdf0e10cSrcweir // exported via tdmgr_common.hxx
86*cdf0e10cSrcweir extern rtl_StandardModuleCount g_moduleCount;
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir namespace stoc_bootstrap
89*cdf0e10cSrcweir {
90*cdf0e10cSrcweir Sequence< OUString > SAL_CALL tdmgr_getSupportedServiceNames()
91*cdf0e10cSrcweir {
92*cdf0e10cSrcweir 	static Sequence < OUString > *pNames = 0;
93*cdf0e10cSrcweir 	if( ! pNames )
94*cdf0e10cSrcweir 	{
95*cdf0e10cSrcweir 		MutexGuard guard( Mutex::getGlobalMutex() );
96*cdf0e10cSrcweir 		if( !pNames )
97*cdf0e10cSrcweir 		{
98*cdf0e10cSrcweir 			static Sequence< OUString > seqNames(1);
99*cdf0e10cSrcweir 			seqNames.getArray()[0] = OUString(RTL_CONSTASCII_USTRINGPARAM(SERVICENAME));
100*cdf0e10cSrcweir 			pNames = &seqNames;
101*cdf0e10cSrcweir 		}
102*cdf0e10cSrcweir 	}
103*cdf0e10cSrcweir 	return *pNames;
104*cdf0e10cSrcweir }
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir OUString SAL_CALL tdmgr_getImplementationName()
107*cdf0e10cSrcweir {
108*cdf0e10cSrcweir 	static OUString *pImplName = 0;
109*cdf0e10cSrcweir 	if( ! pImplName )
110*cdf0e10cSrcweir 	{
111*cdf0e10cSrcweir 		MutexGuard guard( Mutex::getGlobalMutex() );
112*cdf0e10cSrcweir 		if( ! pImplName )
113*cdf0e10cSrcweir 		{
114*cdf0e10cSrcweir 			static OUString implName( RTL_CONSTASCII_USTRINGPARAM( IMPLNAME ) );
115*cdf0e10cSrcweir 			pImplName = &implName;
116*cdf0e10cSrcweir 		}
117*cdf0e10cSrcweir 	}
118*cdf0e10cSrcweir 	return *pImplName;
119*cdf0e10cSrcweir }
120*cdf0e10cSrcweir }
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir namespace stoc_tdmgr
123*cdf0e10cSrcweir {
124*cdf0e10cSrcweir typedef vector< Reference< XHierarchicalNameAccess > > ProviderVector;
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir class EnumerationImpl;
127*cdf0e10cSrcweir class ManagerImpl;
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir //==================================================================================================
130*cdf0e10cSrcweir class EventListenerImpl : public ImplHelper1< XEventListener >
131*cdf0e10cSrcweir {
132*cdf0e10cSrcweir 	ManagerImpl *		_pMgr;
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir public:
135*cdf0e10cSrcweir 	EventListenerImpl( ManagerImpl * pMgr )
136*cdf0e10cSrcweir 		: _pMgr( pMgr )
137*cdf0e10cSrcweir 		{
138*cdf0e10cSrcweir 			::g_moduleCount.modCnt.acquire( &::g_moduleCount.modCnt );
139*cdf0e10cSrcweir 		}
140*cdf0e10cSrcweir 	virtual ~EventListenerImpl();
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir 	// lifetime delegated to manager
143*cdf0e10cSrcweir 	virtual void SAL_CALL acquire() throw();
144*cdf0e10cSrcweir 	virtual void SAL_CALL release() throw();
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir 	// XEventListener
147*cdf0e10cSrcweir 	virtual void SAL_CALL disposing( const EventObject & rEvt ) throw(::com::sun::star::uno::RuntimeException);
148*cdf0e10cSrcweir };
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir EventListenerImpl::~EventListenerImpl()
151*cdf0e10cSrcweir {
152*cdf0e10cSrcweir 	::g_moduleCount.modCnt.release( &::g_moduleCount.modCnt );
153*cdf0e10cSrcweir }
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir //==================================================================================================
156*cdf0e10cSrcweir class ManagerImpl
157*cdf0e10cSrcweir     : public WeakComponentImplHelper5< XServiceInfo,
158*cdf0e10cSrcweir                                        XSet,
159*cdf0e10cSrcweir                                        XHierarchicalNameAccess,
160*cdf0e10cSrcweir                                        XTypeDescriptionEnumerationAccess,
161*cdf0e10cSrcweir                                        XInitialization >
162*cdf0e10cSrcweir {
163*cdf0e10cSrcweir 	friend class EnumerationImpl;
164*cdf0e10cSrcweir 	friend class EventListenerImpl;
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir 	Mutex								_aComponentMutex;
167*cdf0e10cSrcweir 	Reference< XComponentContext >      _xContext;
168*cdf0e10cSrcweir 	EventListenerImpl					_aEventListener;
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir 	// elements
171*cdf0e10cSrcweir 	sal_Bool							_bCaching;
172*cdf0e10cSrcweir 	LRU_CacheAnyByOUString				_aElements;
173*cdf0e10cSrcweir 	// provider chain
174*cdf0e10cSrcweir 	ProviderVector						_aProviders;
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir 	inline Any getSimpleType( const OUString & rName );
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir     Reference< XTypeDescription > getInstantiatedStruct(OUString const & name);
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir protected:
181*cdf0e10cSrcweir 	virtual void SAL_CALL disposing();
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir public:
184*cdf0e10cSrcweir 	ManagerImpl( Reference< XComponentContext > const & xContext, sal_Int32 nCacheSize );
185*cdf0e10cSrcweir 	virtual ~ManagerImpl();
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir     // XInitialization
188*cdf0e10cSrcweir     virtual void SAL_CALL initialize( const Sequence< Any > & args ) throw (Exception, RuntimeException);
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir 	// XServiceInfo
191*cdf0e10cSrcweir 	virtual OUString SAL_CALL getImplementationName() throw(::com::sun::star::uno::RuntimeException);
192*cdf0e10cSrcweir 	virtual sal_Bool SAL_CALL supportsService( const OUString & rServiceName ) throw(::com::sun::star::uno::RuntimeException);
193*cdf0e10cSrcweir 	virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException);
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir 	// XElementAccess
196*cdf0e10cSrcweir     virtual Type SAL_CALL getElementType() throw(::com::sun::star::uno::RuntimeException);
197*cdf0e10cSrcweir     virtual sal_Bool SAL_CALL hasElements() throw(::com::sun::star::uno::RuntimeException);
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir 	// XEnumerationAccess
200*cdf0e10cSrcweir     virtual Reference< XEnumeration > SAL_CALL createEnumeration() throw(::com::sun::star::uno::RuntimeException);
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir 	// XSet
203*cdf0e10cSrcweir     virtual sal_Bool SAL_CALL has( const Any & rElement ) throw(::com::sun::star::uno::RuntimeException);
204*cdf0e10cSrcweir     virtual void SAL_CALL insert( const Any & rElement ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException);
205*cdf0e10cSrcweir     virtual void SAL_CALL remove( const Any & rElement ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException);
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir 	// XHierarchicalNameAccess
208*cdf0e10cSrcweir 	virtual Any SAL_CALL getByHierarchicalName( const OUString & rName ) throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException);
209*cdf0e10cSrcweir 	virtual sal_Bool SAL_CALL hasByHierarchicalName( const OUString & rName ) throw(::com::sun::star::uno::RuntimeException);
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir     // XTypeDescriptionEnumerationAccess
212*cdf0e10cSrcweir     virtual ::com::sun::star::uno::Reference<
213*cdf0e10cSrcweir         ::com::sun::star::reflection::XTypeDescriptionEnumeration > SAL_CALL
214*cdf0e10cSrcweir     createTypeDescriptionEnumeration(
215*cdf0e10cSrcweir         const ::rtl::OUString& moduleName,
216*cdf0e10cSrcweir         const ::com::sun::star::uno::Sequence<
217*cdf0e10cSrcweir             ::com::sun::star::uno::TypeClass >& types,
218*cdf0e10cSrcweir         ::com::sun::star::reflection::TypeDescriptionSearchDepth depth )
219*cdf0e10cSrcweir             throw ( ::com::sun::star::reflection::NoSuchTypeNameException,
220*cdf0e10cSrcweir                     ::com::sun::star::reflection::InvalidTypeNameException,
221*cdf0e10cSrcweir                     ::com::sun::star::uno::RuntimeException );
222*cdf0e10cSrcweir };
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir //==================================================================================================
225*cdf0e10cSrcweir class EnumerationImpl
226*cdf0e10cSrcweir 	: public WeakImplHelper1< XEnumeration >
227*cdf0e10cSrcweir {
228*cdf0e10cSrcweir 	ManagerImpl *		_pMgr;
229*cdf0e10cSrcweir 	size_t				_nPos;
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir public:
232*cdf0e10cSrcweir 	EnumerationImpl( ManagerImpl * pManager );
233*cdf0e10cSrcweir 	virtual ~EnumerationImpl();
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir 	// XEnumeration
236*cdf0e10cSrcweir 	virtual sal_Bool SAL_CALL hasMoreElements() throw(::com::sun::star::uno::RuntimeException);
237*cdf0e10cSrcweir 	virtual Any SAL_CALL nextElement() throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
238*cdf0e10cSrcweir };
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir //##################################################################################################
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir // lifetime delegated to manager
243*cdf0e10cSrcweir //__________________________________________________________________________________________________
244*cdf0e10cSrcweir void EventListenerImpl::acquire() throw()
245*cdf0e10cSrcweir {
246*cdf0e10cSrcweir 	_pMgr->acquire();
247*cdf0e10cSrcweir }
248*cdf0e10cSrcweir //__________________________________________________________________________________________________
249*cdf0e10cSrcweir void EventListenerImpl::release() throw()
250*cdf0e10cSrcweir {
251*cdf0e10cSrcweir 	_pMgr->release();
252*cdf0e10cSrcweir }
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir // XEventListener
255*cdf0e10cSrcweir //__________________________________________________________________________________________________
256*cdf0e10cSrcweir void EventListenerImpl::disposing( const EventObject & rEvt )
257*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
258*cdf0e10cSrcweir {
259*cdf0e10cSrcweir     _pMgr->remove( makeAny( rEvt.Source ) );
260*cdf0e10cSrcweir }
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir //##################################################################################################
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir //__________________________________________________________________________________________________
265*cdf0e10cSrcweir EnumerationImpl::EnumerationImpl( ManagerImpl * pManager )
266*cdf0e10cSrcweir 	: _pMgr( pManager )
267*cdf0e10cSrcweir 	, _nPos( 0 )
268*cdf0e10cSrcweir {
269*cdf0e10cSrcweir 	_pMgr->acquire();
270*cdf0e10cSrcweir }
271*cdf0e10cSrcweir //__________________________________________________________________________________________________
272*cdf0e10cSrcweir EnumerationImpl::~EnumerationImpl()
273*cdf0e10cSrcweir {
274*cdf0e10cSrcweir 	_pMgr->release();
275*cdf0e10cSrcweir }
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir // XEnumeration
278*cdf0e10cSrcweir //__________________________________________________________________________________________________
279*cdf0e10cSrcweir sal_Bool EnumerationImpl::hasMoreElements()
280*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
281*cdf0e10cSrcweir {
282*cdf0e10cSrcweir 	MutexGuard aGuard( _pMgr->_aComponentMutex );
283*cdf0e10cSrcweir 	return (_nPos < _pMgr->_aProviders.size());
284*cdf0e10cSrcweir }
285*cdf0e10cSrcweir //__________________________________________________________________________________________________
286*cdf0e10cSrcweir Any EnumerationImpl::nextElement()
287*cdf0e10cSrcweir 	throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
288*cdf0e10cSrcweir {
289*cdf0e10cSrcweir 	MutexGuard aGuard( _pMgr->_aComponentMutex );
290*cdf0e10cSrcweir 	if (_nPos >= _pMgr->_aProviders.size())
291*cdf0e10cSrcweir 	{
292*cdf0e10cSrcweir 		throw NoSuchElementException(
293*cdf0e10cSrcweir 			OUString( RTL_CONSTASCII_USTRINGPARAM("there is no further element!") ),
294*cdf0e10cSrcweir 			(XWeak *)(OWeakObject *)this );
295*cdf0e10cSrcweir 	}
296*cdf0e10cSrcweir 	return makeAny( _pMgr->_aProviders[_nPos++] );
297*cdf0e10cSrcweir }
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir //##################################################################################################
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir //__________________________________________________________________________________________________
302*cdf0e10cSrcweir ManagerImpl::ManagerImpl(
303*cdf0e10cSrcweir     Reference< XComponentContext > const & xContext, sal_Int32 nCacheSize )
304*cdf0e10cSrcweir     : WeakComponentImplHelper5<
305*cdf0e10cSrcweir         XServiceInfo, XSet, XHierarchicalNameAccess,
306*cdf0e10cSrcweir         XTypeDescriptionEnumerationAccess, XInitialization >( _aComponentMutex )
307*cdf0e10cSrcweir     , _xContext( xContext )
308*cdf0e10cSrcweir 	, _aEventListener( this )
309*cdf0e10cSrcweir 	, _bCaching( sal_True )
310*cdf0e10cSrcweir 	, _aElements( nCacheSize )
311*cdf0e10cSrcweir {
312*cdf0e10cSrcweir 	::g_moduleCount.modCnt.acquire( &::g_moduleCount.modCnt );
313*cdf0e10cSrcweir }
314*cdf0e10cSrcweir //__________________________________________________________________________________________________
315*cdf0e10cSrcweir ManagerImpl::~ManagerImpl()
316*cdf0e10cSrcweir {
317*cdf0e10cSrcweir 	OSL_ENSURE( _aProviders.size() == 0, "### still providers left!" );
318*cdf0e10cSrcweir 	OSL_TRACE( "> TypeDescriptionManager shut down. <\n" );
319*cdf0e10cSrcweir 	::g_moduleCount.modCnt.release( &::g_moduleCount.modCnt );
320*cdf0e10cSrcweir }
321*cdf0e10cSrcweir //__________________________________________________________________________________________________
322*cdf0e10cSrcweir void ManagerImpl::disposing()
323*cdf0e10cSrcweir {
324*cdf0e10cSrcweir     // called on disposing the tdmgr instance (supposedly from context)
325*cdf0e10cSrcweir     _bCaching = sal_False;
326*cdf0e10cSrcweir     _aElements.clear();
327*cdf0e10cSrcweir     _xContext.clear();
328*cdf0e10cSrcweir 	_aProviders.clear();
329*cdf0e10cSrcweir }
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir // XInitialization
332*cdf0e10cSrcweir //__________________________________________________________________________________________________
333*cdf0e10cSrcweir void ManagerImpl::initialize(
334*cdf0e10cSrcweir     const Sequence< Any > & args )
335*cdf0e10cSrcweir     throw (Exception, RuntimeException)
336*cdf0e10cSrcweir {
337*cdf0e10cSrcweir 	// additional providers
338*cdf0e10cSrcweir     Any const * pProviders = args.getConstArray();
339*cdf0e10cSrcweir     for ( sal_Int32 nPos = 0; nPos < args.getLength(); ++nPos )
340*cdf0e10cSrcweir     {
341*cdf0e10cSrcweir         Reference< XHierarchicalNameAccess > xHA( pProviders[ nPos ], UNO_QUERY );
342*cdf0e10cSrcweir         OSL_ENSURE( xHA.is(), "### no td provider!" );
343*cdf0e10cSrcweir 
344*cdf0e10cSrcweir         if (xHA.is())
345*cdf0e10cSrcweir         {
346*cdf0e10cSrcweir             try
347*cdf0e10cSrcweir             {
348*cdf0e10cSrcweir                 insert( makeAny( xHA ) );
349*cdf0e10cSrcweir             }
350*cdf0e10cSrcweir             catch (IllegalArgumentException &)
351*cdf0e10cSrcweir             {
352*cdf0e10cSrcweir             }
353*cdf0e10cSrcweir             catch (ElementExistException &)
354*cdf0e10cSrcweir             {
355*cdf0e10cSrcweir             }
356*cdf0e10cSrcweir         }
357*cdf0e10cSrcweir     }
358*cdf0e10cSrcweir }
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir // XServiceInfo
361*cdf0e10cSrcweir //__________________________________________________________________________________________________
362*cdf0e10cSrcweir OUString ManagerImpl::getImplementationName()
363*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
364*cdf0e10cSrcweir {
365*cdf0e10cSrcweir 	return stoc_bootstrap::tdmgr_getImplementationName();
366*cdf0e10cSrcweir }
367*cdf0e10cSrcweir //__________________________________________________________________________________________________
368*cdf0e10cSrcweir sal_Bool ManagerImpl::supportsService( const OUString & rServiceName )
369*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
370*cdf0e10cSrcweir {
371*cdf0e10cSrcweir 	const Sequence< OUString > & rSNL = getSupportedServiceNames();
372*cdf0e10cSrcweir 	const OUString * pArray = rSNL.getConstArray();
373*cdf0e10cSrcweir 	for ( sal_Int32 nPos = rSNL.getLength(); nPos--; )
374*cdf0e10cSrcweir 	{
375*cdf0e10cSrcweir 		if (pArray[nPos] == rServiceName)
376*cdf0e10cSrcweir 			return sal_True;
377*cdf0e10cSrcweir 	}
378*cdf0e10cSrcweir 	return sal_False;
379*cdf0e10cSrcweir }
380*cdf0e10cSrcweir //__________________________________________________________________________________________________
381*cdf0e10cSrcweir Sequence< OUString > ManagerImpl::getSupportedServiceNames()
382*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
383*cdf0e10cSrcweir {
384*cdf0e10cSrcweir 	return stoc_bootstrap::tdmgr_getSupportedServiceNames();
385*cdf0e10cSrcweir }
386*cdf0e10cSrcweir 
387*cdf0e10cSrcweir // XElementAccess
388*cdf0e10cSrcweir //__________________________________________________________________________________________________
389*cdf0e10cSrcweir Type ManagerImpl::getElementType()
390*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
391*cdf0e10cSrcweir {
392*cdf0e10cSrcweir 	return ::getCppuType( (const Reference< XHierarchicalNameAccess > *)0 );
393*cdf0e10cSrcweir }
394*cdf0e10cSrcweir //__________________________________________________________________________________________________
395*cdf0e10cSrcweir sal_Bool ManagerImpl::hasElements()
396*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
397*cdf0e10cSrcweir {
398*cdf0e10cSrcweir 	MutexGuard aGuard( _aComponentMutex );
399*cdf0e10cSrcweir 	return (_aProviders.size() > 0);
400*cdf0e10cSrcweir }
401*cdf0e10cSrcweir 
402*cdf0e10cSrcweir // XEnumerationAccess
403*cdf0e10cSrcweir //__________________________________________________________________________________________________
404*cdf0e10cSrcweir Reference< XEnumeration > ManagerImpl::createEnumeration()
405*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
406*cdf0e10cSrcweir {
407*cdf0e10cSrcweir 	return new EnumerationImpl( this );
408*cdf0e10cSrcweir }
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir // XSet
411*cdf0e10cSrcweir //__________________________________________________________________________________________________
412*cdf0e10cSrcweir sal_Bool SAL_CALL ManagerImpl::has( const Any & rElement )
413*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
414*cdf0e10cSrcweir {
415*cdf0e10cSrcweir 	Reference< XHierarchicalNameAccess > xElem;
416*cdf0e10cSrcweir 	if (rElement >>= xElem)
417*cdf0e10cSrcweir 	{
418*cdf0e10cSrcweir 		MutexGuard aGuard( _aComponentMutex );
419*cdf0e10cSrcweir 		return (find( _aProviders.begin(), _aProviders.end(), xElem ) != _aProviders.end());
420*cdf0e10cSrcweir 	}
421*cdf0e10cSrcweir 	return sal_False;
422*cdf0e10cSrcweir }
423*cdf0e10cSrcweir 
424*cdf0e10cSrcweir //__________________________________________________________________________________________________
425*cdf0e10cSrcweir void SAL_CALL ManagerImpl::insert( const Any & rElement )
426*cdf0e10cSrcweir 	throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException)
427*cdf0e10cSrcweir {
428*cdf0e10cSrcweir 	Reference< XHierarchicalNameAccess > xElem;
429*cdf0e10cSrcweir 	if (! (rElement >>= xElem) || !xElem.is())
430*cdf0e10cSrcweir 	{
431*cdf0e10cSrcweir 		throw IllegalArgumentException(
432*cdf0e10cSrcweir 			OUString( RTL_CONSTASCII_USTRINGPARAM("no valid type description provider given!") ),
433*cdf0e10cSrcweir 			(XWeak *)(OWeakObject *)this, 0 );
434*cdf0e10cSrcweir 	}
435*cdf0e10cSrcweir 
436*cdf0e10cSrcweir 	MutexGuard aGuard( _aComponentMutex );
437*cdf0e10cSrcweir 	if (find( _aProviders.begin(), _aProviders.end(), xElem ) != _aProviders.end())
438*cdf0e10cSrcweir 	{
439*cdf0e10cSrcweir 		throw ElementExistException(
440*cdf0e10cSrcweir 			OUString( RTL_CONSTASCII_USTRINGPARAM("provider already inserted!") ),
441*cdf0e10cSrcweir 			(XWeak *)(OWeakObject *)this );
442*cdf0e10cSrcweir 	}
443*cdf0e10cSrcweir 
444*cdf0e10cSrcweir     if (! _aProviders.empty())
445*cdf0e10cSrcweir     {
446*cdf0e10cSrcweir         // check whether all types are compatible, if possible:
447*cdf0e10cSrcweir         Reference<reflection::XTypeDescriptionEnumerationAccess> xTDEnumAccess(
448*cdf0e10cSrcweir             xElem, UNO_QUERY );
449*cdf0e10cSrcweir         OSL_ENSURE( xTDEnumAccess.is(),
450*cdf0e10cSrcweir                     "### providers ought to implement "
451*cdf0e10cSrcweir                     "reflection::XTypeDescriptionEnumerationAccess!" );
452*cdf0e10cSrcweir         if (xTDEnumAccess.is())
453*cdf0e10cSrcweir         {
454*cdf0e10cSrcweir             try
455*cdf0e10cSrcweir             {
456*cdf0e10cSrcweir                 TypeClass ar [] = {
457*cdf0e10cSrcweir                     TypeClass_ENUM, TypeClass_TYPEDEF, TypeClass_SEQUENCE,
458*cdf0e10cSrcweir                     TypeClass_STRUCT, TypeClass_EXCEPTION,
459*cdf0e10cSrcweir                     /* TypeClass_UNION, TypeClass_ARRAY not supported */
460*cdf0e10cSrcweir                     TypeClass_INTERFACE,
461*cdf0e10cSrcweir                     TypeClass_SERVICE,
462*cdf0e10cSrcweir                     TypeClass_INTERFACE_METHOD, TypeClass_INTERFACE_ATTRIBUTE,
463*cdf0e10cSrcweir                     TypeClass_PROPERTY, TypeClass_CONSTANT, TypeClass_CONSTANTS,
464*cdf0e10cSrcweir                     TypeClass_SINGLETON
465*cdf0e10cSrcweir                 };
466*cdf0e10cSrcweir                 Reference<reflection::XTypeDescriptionEnumeration> xTDEnum(
467*cdf0e10cSrcweir                     xTDEnumAccess->createTypeDescriptionEnumeration(
468*cdf0e10cSrcweir                         OUString() /* all modules */,
469*cdf0e10cSrcweir                         Sequence<TypeClass>( ar, ARLEN(ar) ),
470*cdf0e10cSrcweir                         reflection::TypeDescriptionSearchDepth_INFINITE ) );
471*cdf0e10cSrcweir 
472*cdf0e10cSrcweir                 while (xTDEnum->hasMoreElements())
473*cdf0e10cSrcweir                 {
474*cdf0e10cSrcweir                     Reference<reflection::XTypeDescription> xNewTD;
475*cdf0e10cSrcweir                     try
476*cdf0e10cSrcweir                     {
477*cdf0e10cSrcweir                         xNewTD = xTDEnum->nextTypeDescription();
478*cdf0e10cSrcweir                     }
479*cdf0e10cSrcweir                     catch (container::NoSuchElementException & exc)
480*cdf0e10cSrcweir                     {
481*cdf0e10cSrcweir                         throw lang::IllegalArgumentException(
482*cdf0e10cSrcweir                             OUSTR("NoSuchElementException occured: ") +
483*cdf0e10cSrcweir                             exc.Message, static_cast<OWeakObject *>(this),
484*cdf0e10cSrcweir                             -1 /* unknown */ );
485*cdf0e10cSrcweir                     }
486*cdf0e10cSrcweir 
487*cdf0e10cSrcweir                     try
488*cdf0e10cSrcweir                     {
489*cdf0e10cSrcweir                         OUString newName( xNewTD->getName() );
490*cdf0e10cSrcweir                         Reference<reflection::XTypeDescription> xExistingTD(
491*cdf0e10cSrcweir                             getByHierarchicalName( newName ), UNO_QUERY );
492*cdf0e10cSrcweir                         OSL_ASSERT( xExistingTD.is() );
493*cdf0e10cSrcweir                         // existing, check whether compatible:
494*cdf0e10cSrcweir                         if (xExistingTD.is())
495*cdf0e10cSrcweir                         {
496*cdf0e10cSrcweir                             try
497*cdf0e10cSrcweir                             {
498*cdf0e10cSrcweir                                 check( xNewTD, xExistingTD );
499*cdf0e10cSrcweir                             }
500*cdf0e10cSrcweir                             catch (IncompatibleTypeException & exc)
501*cdf0e10cSrcweir                             {
502*cdf0e10cSrcweir                                 throw lang::IllegalArgumentException(
503*cdf0e10cSrcweir                                     OUSTR("Rejecting types due to "
504*cdf0e10cSrcweir                                           "incompatibility!  ") + exc.m_cause,
505*cdf0e10cSrcweir                                     static_cast<OWeakObject *>(this), 0 );
506*cdf0e10cSrcweir                             }
507*cdf0e10cSrcweir                         }
508*cdf0e10cSrcweir                     }
509*cdf0e10cSrcweir                     catch (container::NoSuchElementException &)
510*cdf0e10cSrcweir                     {
511*cdf0e10cSrcweir                         // type not in: ok
512*cdf0e10cSrcweir                     }
513*cdf0e10cSrcweir                 }
514*cdf0e10cSrcweir             }
515*cdf0e10cSrcweir             catch (reflection::NoSuchTypeNameException & exc)
516*cdf0e10cSrcweir             {
517*cdf0e10cSrcweir                 throw lang::IllegalArgumentException(
518*cdf0e10cSrcweir                     OUSTR("NoSuchTypeNameException occured: ") + exc.Message,
519*cdf0e10cSrcweir                     static_cast<OWeakObject *>(this), -1 /* unknown */ );
520*cdf0e10cSrcweir             }
521*cdf0e10cSrcweir             catch (reflection::InvalidTypeNameException & exc)
522*cdf0e10cSrcweir             {
523*cdf0e10cSrcweir                 throw lang::IllegalArgumentException(
524*cdf0e10cSrcweir                     OUSTR("InvalidTypeNameException occured: ") + exc.Message,
525*cdf0e10cSrcweir                     static_cast<OWeakObject *>(this), -1 /* unknown */ );
526*cdf0e10cSrcweir             }
527*cdf0e10cSrcweir         }
528*cdf0e10cSrcweir     }
529*cdf0e10cSrcweir 
530*cdf0e10cSrcweir 	_aProviders.push_back( xElem );
531*cdf0e10cSrcweir 	Reference< XComponent > xComp( xElem, UNO_QUERY );
532*cdf0e10cSrcweir 	if (xComp.is())
533*cdf0e10cSrcweir 		xComp->addEventListener( &_aEventListener );
534*cdf0e10cSrcweir }
535*cdf0e10cSrcweir //__________________________________________________________________________________________________
536*cdf0e10cSrcweir void SAL_CALL ManagerImpl::remove( const Any & rElement )
537*cdf0e10cSrcweir 	throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException)
538*cdf0e10cSrcweir {
539*cdf0e10cSrcweir 	if (!rBHelper.bDisposed && !rBHelper.bInDispose)
540*cdf0e10cSrcweir 	{
541*cdf0e10cSrcweir 		Reference< XHierarchicalNameAccess > xElem;
542*cdf0e10cSrcweir 		if (! (rElement >>= xElem))
543*cdf0e10cSrcweir 		{
544*cdf0e10cSrcweir 			throw IllegalArgumentException(
545*cdf0e10cSrcweir 				OUString( RTL_CONSTASCII_USTRINGPARAM("no type description provider given!") ),
546*cdf0e10cSrcweir 				(XWeak *)(OWeakObject *)this, 0 );
547*cdf0e10cSrcweir 		}
548*cdf0e10cSrcweir 
549*cdf0e10cSrcweir 		MutexGuard aGuard( _aComponentMutex );
550*cdf0e10cSrcweir 		ProviderVector::iterator iFind( find( _aProviders.begin(), _aProviders.end(), xElem ) );
551*cdf0e10cSrcweir 		if (iFind == _aProviders.end())
552*cdf0e10cSrcweir 		{
553*cdf0e10cSrcweir 			throw NoSuchElementException(
554*cdf0e10cSrcweir 				OUString( RTL_CONSTASCII_USTRINGPARAM("provider not found!") ),
555*cdf0e10cSrcweir 				(XWeak *)(OWeakObject *)this );
556*cdf0e10cSrcweir 		}
557*cdf0e10cSrcweir 		_aProviders.erase( iFind );
558*cdf0e10cSrcweir 	}
559*cdf0e10cSrcweir 
560*cdf0e10cSrcweir 	Reference< XComponent > xComp;
561*cdf0e10cSrcweir 	if (rElement >>= xComp)
562*cdf0e10cSrcweir 		xComp->removeEventListener( &_aEventListener );
563*cdf0e10cSrcweir }
564*cdf0e10cSrcweir 
565*cdf0e10cSrcweir // XTypeDescriptionEnumerationAccess
566*cdf0e10cSrcweir //__________________________________________________________________________________________________
567*cdf0e10cSrcweir // virtual
568*cdf0e10cSrcweir Reference< XTypeDescriptionEnumeration > SAL_CALL
569*cdf0e10cSrcweir ManagerImpl::createTypeDescriptionEnumeration(
570*cdf0e10cSrcweir         const OUString & moduleName,
571*cdf0e10cSrcweir         const Sequence< TypeClass > & types,
572*cdf0e10cSrcweir         TypeDescriptionSearchDepth depth )
573*cdf0e10cSrcweir     throw ( NoSuchTypeNameException,
574*cdf0e10cSrcweir             InvalidTypeNameException,
575*cdf0e10cSrcweir             RuntimeException )
576*cdf0e10cSrcweir {
577*cdf0e10cSrcweir     MutexGuard aGuard( _aComponentMutex );
578*cdf0e10cSrcweir 
579*cdf0e10cSrcweir     TDEnumerationAccessStack aStack;
580*cdf0e10cSrcweir     ProviderVector::const_iterator it = _aProviders.begin();
581*cdf0e10cSrcweir     const ProviderVector::const_iterator end = _aProviders.end();
582*cdf0e10cSrcweir     while ( it != end )
583*cdf0e10cSrcweir     {
584*cdf0e10cSrcweir         Reference< XTypeDescriptionEnumerationAccess >xEnumAccess(
585*cdf0e10cSrcweir             (*it), UNO_QUERY );
586*cdf0e10cSrcweir         OSL_ENSURE( xEnumAccess.is(),
587*cdf0e10cSrcweir                     "### no XTypeDescriptionEnumerationAccess!" );
588*cdf0e10cSrcweir         if ( xEnumAccess.is() )
589*cdf0e10cSrcweir             aStack.push( xEnumAccess );
590*cdf0e10cSrcweir 
591*cdf0e10cSrcweir         it++;
592*cdf0e10cSrcweir     }
593*cdf0e10cSrcweir 
594*cdf0e10cSrcweir     return Reference< XTypeDescriptionEnumeration >(
595*cdf0e10cSrcweir         new TypeDescriptionEnumerationImpl( moduleName,
596*cdf0e10cSrcweir                                             types,
597*cdf0e10cSrcweir                                             depth,
598*cdf0e10cSrcweir                                             aStack ) );
599*cdf0e10cSrcweir }
600*cdf0e10cSrcweir 
601*cdf0e10cSrcweir 
602*cdf0e10cSrcweir //##################################################################################################
603*cdf0e10cSrcweir //##################################################################################################
604*cdf0e10cSrcweir //##################################################################################################
605*cdf0e10cSrcweir 
606*cdf0e10cSrcweir 
607*cdf0e10cSrcweir //==================================================================================================
608*cdf0e10cSrcweir class SimpleTypeDescriptionImpl
609*cdf0e10cSrcweir     : public WeakImplHelper1< XTypeDescription >
610*cdf0e10cSrcweir {
611*cdf0e10cSrcweir 	TypeClass _eTC;
612*cdf0e10cSrcweir 	OUString  _aName;
613*cdf0e10cSrcweir 
614*cdf0e10cSrcweir public:
615*cdf0e10cSrcweir 	SimpleTypeDescriptionImpl( TypeClass eTC, const OUString & rName )
616*cdf0e10cSrcweir 		: _eTC( eTC )
617*cdf0e10cSrcweir 		, _aName( rName )
618*cdf0e10cSrcweir 		{}
619*cdf0e10cSrcweir 
620*cdf0e10cSrcweir 	// XTypeDescription
621*cdf0e10cSrcweir 	virtual TypeClass SAL_CALL getTypeClass() throw(::com::sun::star::uno::RuntimeException);
622*cdf0e10cSrcweir 	virtual OUString SAL_CALL getName() throw(::com::sun::star::uno::RuntimeException);
623*cdf0e10cSrcweir };
624*cdf0e10cSrcweir 
625*cdf0e10cSrcweir // XTypeDescription
626*cdf0e10cSrcweir //__________________________________________________________________________________________________
627*cdf0e10cSrcweir TypeClass SimpleTypeDescriptionImpl::getTypeClass()
628*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
629*cdf0e10cSrcweir {
630*cdf0e10cSrcweir 	return _eTC;
631*cdf0e10cSrcweir }
632*cdf0e10cSrcweir //__________________________________________________________________________________________________
633*cdf0e10cSrcweir OUString SimpleTypeDescriptionImpl::getName()
634*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
635*cdf0e10cSrcweir {
636*cdf0e10cSrcweir 	return _aName;
637*cdf0e10cSrcweir }
638*cdf0e10cSrcweir 
639*cdf0e10cSrcweir //==================================================================================================
640*cdf0e10cSrcweir class SequenceTypeDescriptionImpl
641*cdf0e10cSrcweir     : public WeakImplHelper1< XIndirectTypeDescription >
642*cdf0e10cSrcweir {
643*cdf0e10cSrcweir 	Reference< XTypeDescription > _xElementTD;
644*cdf0e10cSrcweir 
645*cdf0e10cSrcweir public:
646*cdf0e10cSrcweir 	SequenceTypeDescriptionImpl( const Reference< XTypeDescription > & xElementTD )
647*cdf0e10cSrcweir 		: _xElementTD( xElementTD )
648*cdf0e10cSrcweir 		{}
649*cdf0e10cSrcweir 
650*cdf0e10cSrcweir 	// XTypeDescription
651*cdf0e10cSrcweir 	virtual TypeClass SAL_CALL getTypeClass() throw(::com::sun::star::uno::RuntimeException);
652*cdf0e10cSrcweir 	virtual OUString SAL_CALL getName() throw(::com::sun::star::uno::RuntimeException);
653*cdf0e10cSrcweir 
654*cdf0e10cSrcweir 	// XIndirectTypeDescription
655*cdf0e10cSrcweir     virtual Reference< XTypeDescription > SAL_CALL getReferencedType() throw(::com::sun::star::uno::RuntimeException);
656*cdf0e10cSrcweir };
657*cdf0e10cSrcweir 
658*cdf0e10cSrcweir // XTypeDescription
659*cdf0e10cSrcweir //__________________________________________________________________________________________________
660*cdf0e10cSrcweir TypeClass SequenceTypeDescriptionImpl::getTypeClass()
661*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
662*cdf0e10cSrcweir {
663*cdf0e10cSrcweir 	return TypeClass_SEQUENCE;
664*cdf0e10cSrcweir }
665*cdf0e10cSrcweir //__________________________________________________________________________________________________
666*cdf0e10cSrcweir OUString SequenceTypeDescriptionImpl::getName()
667*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
668*cdf0e10cSrcweir {
669*cdf0e10cSrcweir 	return (OUString( RTL_CONSTASCII_USTRINGPARAM("[]") ) + _xElementTD->getName());
670*cdf0e10cSrcweir }
671*cdf0e10cSrcweir 
672*cdf0e10cSrcweir // XIndirectTypeDescription
673*cdf0e10cSrcweir //__________________________________________________________________________________________________
674*cdf0e10cSrcweir Reference< XTypeDescription > SequenceTypeDescriptionImpl::getReferencedType()
675*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
676*cdf0e10cSrcweir {
677*cdf0e10cSrcweir 	return _xElementTD;
678*cdf0e10cSrcweir }
679*cdf0e10cSrcweir 
680*cdf0e10cSrcweir //==================================================================================================
681*cdf0e10cSrcweir class ArrayTypeDescriptionImpl
682*cdf0e10cSrcweir     : public WeakImplHelper1< XArrayTypeDescription >
683*cdf0e10cSrcweir {
684*cdf0e10cSrcweir 	Reference< XTypeDescription > _xElementTD;
685*cdf0e10cSrcweir 	Mutex	 					  _aDimensionMutex;
686*cdf0e10cSrcweir 	sal_Int32					  _nDimensions;
687*cdf0e10cSrcweir 	Sequence< sal_Int32 >		  _seqDimensions;
688*cdf0e10cSrcweir 	OUString					  _sDimensions;
689*cdf0e10cSrcweir 
690*cdf0e10cSrcweir 	void initDimensions(const OUString& rSDimensions);
691*cdf0e10cSrcweir public:
692*cdf0e10cSrcweir 	ArrayTypeDescriptionImpl( const Reference< XTypeDescription > & xElementTD,
693*cdf0e10cSrcweir 							  sal_Int32 nDimensions, const OUString& rSDimensions )
694*cdf0e10cSrcweir 		: _xElementTD( xElementTD )
695*cdf0e10cSrcweir 		, _nDimensions( nDimensions )
696*cdf0e10cSrcweir 		, _seqDimensions( Sequence< sal_Int32 >(nDimensions) )
697*cdf0e10cSrcweir 		, _sDimensions( rSDimensions )
698*cdf0e10cSrcweir 		{
699*cdf0e10cSrcweir 			initDimensions( rSDimensions );
700*cdf0e10cSrcweir 		}
701*cdf0e10cSrcweir 	virtual ~ArrayTypeDescriptionImpl() {}
702*cdf0e10cSrcweir 
703*cdf0e10cSrcweir 	// XTypeDescription
704*cdf0e10cSrcweir 	virtual TypeClass SAL_CALL getTypeClass() throw(::com::sun::star::uno::RuntimeException);
705*cdf0e10cSrcweir 	virtual OUString SAL_CALL getName() throw(::com::sun::star::uno::RuntimeException);
706*cdf0e10cSrcweir 
707*cdf0e10cSrcweir 	// XArrayTypeDescription
708*cdf0e10cSrcweir     virtual Reference< XTypeDescription > SAL_CALL getType() throw(::com::sun::star::uno::RuntimeException);
709*cdf0e10cSrcweir     virtual sal_Int32 SAL_CALL getNumberOfDimensions() throw(::com::sun::star::uno::RuntimeException);
710*cdf0e10cSrcweir     virtual Sequence< sal_Int32 > SAL_CALL getDimensions() throw(::com::sun::star::uno::RuntimeException);
711*cdf0e10cSrcweir };
712*cdf0e10cSrcweir //__________________________________________________________________________________________________
713*cdf0e10cSrcweir static sal_Int32 unicodeToInteger( sal_Int8 base, const sal_Unicode *s )
714*cdf0e10cSrcweir {
715*cdf0e10cSrcweir 	sal_Int32    r = 0;
716*cdf0e10cSrcweir 	sal_Int32    negative = 0;
717*cdf0e10cSrcweir 
718*cdf0e10cSrcweir 	if (*s == '-')
719*cdf0e10cSrcweir    	{
720*cdf0e10cSrcweir     	negative = 1;
721*cdf0e10cSrcweir       	s++;
722*cdf0e10cSrcweir    	}
723*cdf0e10cSrcweir    	if (base == 8 && *s == '0')
724*cdf0e10cSrcweir 		s++;
725*cdf0e10cSrcweir    	else if (base == 16 && *s == '0' && (*(s + 1) == 'x' || *(s + 1) == 'X'))
726*cdf0e10cSrcweir     	s += 2;
727*cdf0e10cSrcweir 
728*cdf0e10cSrcweir    	for (; *s; s++)
729*cdf0e10cSrcweir    	{
730*cdf0e10cSrcweir    		if (*s <= '9' && *s >= '0')
731*cdf0e10cSrcweir         	r = (r * base) + (*s - '0');
732*cdf0e10cSrcweir       	else if (base > 10 && *s <= 'f' && *s >= 'a')
733*cdf0e10cSrcweir         	r = (r * base) + (*s - 'a' + 10);
734*cdf0e10cSrcweir       	else if (base > 10 && *s <= 'F' && *s >= 'A')
735*cdf0e10cSrcweir         	r = (r * base) + (*s - 'A' + 10);
736*cdf0e10cSrcweir        	else
737*cdf0e10cSrcweir         	break;
738*cdf0e10cSrcweir 	}
739*cdf0e10cSrcweir    	if (negative) r *= -1;
740*cdf0e10cSrcweir 	return r;
741*cdf0e10cSrcweir }
742*cdf0e10cSrcweir //__________________________________________________________________________________________________
743*cdf0e10cSrcweir void ArrayTypeDescriptionImpl::initDimensions(const OUString& rSDimensions)
744*cdf0e10cSrcweir {
745*cdf0e10cSrcweir 	MutexGuard aGuard( _aDimensionMutex );
746*cdf0e10cSrcweir 
747*cdf0e10cSrcweir 	sal_Int32 *	 pDimensions = _seqDimensions.getArray();
748*cdf0e10cSrcweir 	OUString tmp(rSDimensions);
749*cdf0e10cSrcweir 	sal_Unicode* p = (sal_Unicode*)tmp.getStr()+1;
750*cdf0e10cSrcweir 	sal_Unicode* pOffset = p;
751*cdf0e10cSrcweir 	sal_Int32 len = tmp.getLength() - 1 ;
752*cdf0e10cSrcweir 	sal_Int32 i = 0;
753*cdf0e10cSrcweir 
754*cdf0e10cSrcweir 	while ( len > 0)
755*cdf0e10cSrcweir 	{
756*cdf0e10cSrcweir 		pOffset++;
757*cdf0e10cSrcweir 		if (*pOffset == ']')
758*cdf0e10cSrcweir 		{
759*cdf0e10cSrcweir 			*pOffset = '\0';
760*cdf0e10cSrcweir 			pOffset += 2;
761*cdf0e10cSrcweir 			len -= 3;
762*cdf0e10cSrcweir 			pDimensions[i++] = unicodeToInteger(10, p);
763*cdf0e10cSrcweir 			p = pOffset;
764*cdf0e10cSrcweir 		} else
765*cdf0e10cSrcweir 			len--;
766*cdf0e10cSrcweir 	}
767*cdf0e10cSrcweir }
768*cdf0e10cSrcweir 
769*cdf0e10cSrcweir // XTypeDescription
770*cdf0e10cSrcweir //__________________________________________________________________________________________________
771*cdf0e10cSrcweir TypeClass ArrayTypeDescriptionImpl::getTypeClass()
772*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
773*cdf0e10cSrcweir {
774*cdf0e10cSrcweir 	return TypeClass_ARRAY;
775*cdf0e10cSrcweir }
776*cdf0e10cSrcweir //__________________________________________________________________________________________________
777*cdf0e10cSrcweir OUString ArrayTypeDescriptionImpl::getName()
778*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
779*cdf0e10cSrcweir {
780*cdf0e10cSrcweir 	return (_xElementTD->getName() + _sDimensions);
781*cdf0e10cSrcweir }
782*cdf0e10cSrcweir 
783*cdf0e10cSrcweir // XArrayTypeDescription
784*cdf0e10cSrcweir //__________________________________________________________________________________________________
785*cdf0e10cSrcweir Reference< XTypeDescription > ArrayTypeDescriptionImpl::getType()
786*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
787*cdf0e10cSrcweir {
788*cdf0e10cSrcweir 	return _xElementTD;
789*cdf0e10cSrcweir }
790*cdf0e10cSrcweir 
791*cdf0e10cSrcweir //__________________________________________________________________________________________________
792*cdf0e10cSrcweir sal_Int32 ArrayTypeDescriptionImpl::getNumberOfDimensions()
793*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
794*cdf0e10cSrcweir {
795*cdf0e10cSrcweir 	return _nDimensions;
796*cdf0e10cSrcweir }
797*cdf0e10cSrcweir 
798*cdf0e10cSrcweir //__________________________________________________________________________________________________
799*cdf0e10cSrcweir Sequence< sal_Int32 > ArrayTypeDescriptionImpl::getDimensions()
800*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
801*cdf0e10cSrcweir {
802*cdf0e10cSrcweir 	return _seqDimensions;
803*cdf0e10cSrcweir }
804*cdf0e10cSrcweir 
805*cdf0e10cSrcweir //##################################################################################################
806*cdf0e10cSrcweir //##################################################################################################
807*cdf0e10cSrcweir //##################################################################################################
808*cdf0e10cSrcweir 
809*cdf0e10cSrcweir 
810*cdf0e10cSrcweir //__________________________________________________________________________________________________
811*cdf0e10cSrcweir inline Any ManagerImpl::getSimpleType( const OUString & rName )
812*cdf0e10cSrcweir {
813*cdf0e10cSrcweir 	Any aRet;
814*cdf0e10cSrcweir 
815*cdf0e10cSrcweir 	if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("string") ))
816*cdf0e10cSrcweir 		aRet <<= Reference< XTypeDescription >( new SimpleTypeDescriptionImpl( TypeClass_STRING, rName ) );
817*cdf0e10cSrcweir 	else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("long") ))
818*cdf0e10cSrcweir 		aRet <<= Reference< XTypeDescription >( new SimpleTypeDescriptionImpl( TypeClass_LONG, rName ) );
819*cdf0e10cSrcweir 	else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("unsigned long") ))
820*cdf0e10cSrcweir 		aRet <<= Reference< XTypeDescription >( new SimpleTypeDescriptionImpl( TypeClass_UNSIGNED_LONG, rName ) );
821*cdf0e10cSrcweir 	else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("boolean") ))
822*cdf0e10cSrcweir 		aRet <<= Reference< XTypeDescription >( new SimpleTypeDescriptionImpl( TypeClass_BOOLEAN, rName ) );
823*cdf0e10cSrcweir 	else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("char") ))
824*cdf0e10cSrcweir 		aRet <<= Reference< XTypeDescription >( new SimpleTypeDescriptionImpl( TypeClass_CHAR, rName ) );
825*cdf0e10cSrcweir 	else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("byte") ))
826*cdf0e10cSrcweir 		aRet <<= Reference< XTypeDescription >( new SimpleTypeDescriptionImpl( TypeClass_BYTE, rName ) );
827*cdf0e10cSrcweir 	else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("short") ))
828*cdf0e10cSrcweir 		aRet <<= Reference< XTypeDescription >( new SimpleTypeDescriptionImpl( TypeClass_SHORT, rName ) );
829*cdf0e10cSrcweir 	else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("unsigned short") ))
830*cdf0e10cSrcweir 		aRet <<= Reference< XTypeDescription >( new SimpleTypeDescriptionImpl( TypeClass_UNSIGNED_SHORT, rName ) );
831*cdf0e10cSrcweir 	else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("hyper") ))
832*cdf0e10cSrcweir 		aRet <<= Reference< XTypeDescription >( new SimpleTypeDescriptionImpl( TypeClass_HYPER, rName ) );
833*cdf0e10cSrcweir 	else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("unsigned hyper") ))
834*cdf0e10cSrcweir 		aRet <<= Reference< XTypeDescription >( new SimpleTypeDescriptionImpl( TypeClass_UNSIGNED_HYPER, rName ) );
835*cdf0e10cSrcweir 	else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("float") ))
836*cdf0e10cSrcweir 		aRet <<= Reference< XTypeDescription >( new SimpleTypeDescriptionImpl( TypeClass_FLOAT, rName ) );
837*cdf0e10cSrcweir 	else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("double") ))
838*cdf0e10cSrcweir 		aRet <<= Reference< XTypeDescription >( new SimpleTypeDescriptionImpl( TypeClass_DOUBLE, rName ) );
839*cdf0e10cSrcweir 	else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("any") ))
840*cdf0e10cSrcweir 		aRet <<= Reference< XTypeDescription >( new SimpleTypeDescriptionImpl( TypeClass_ANY, rName ) );
841*cdf0e10cSrcweir 	else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("void") ))
842*cdf0e10cSrcweir 		aRet <<= Reference< XTypeDescription >( new SimpleTypeDescriptionImpl( TypeClass_VOID, rName ) );
843*cdf0e10cSrcweir 	else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("type") ))
844*cdf0e10cSrcweir 		aRet <<= Reference< XTypeDescription >( new SimpleTypeDescriptionImpl( TypeClass_TYPE, rName ) );
845*cdf0e10cSrcweir 
846*cdf0e10cSrcweir 	return aRet;
847*cdf0e10cSrcweir }
848*cdf0e10cSrcweir 
849*cdf0e10cSrcweir namespace {
850*cdf0e10cSrcweir 
851*cdf0e10cSrcweir Reference< XTypeDescription > resolveTypedefs(
852*cdf0e10cSrcweir     Reference< XTypeDescription > const & type)
853*cdf0e10cSrcweir {
854*cdf0e10cSrcweir     Reference< XTypeDescription > resolved(type);
855*cdf0e10cSrcweir     while (resolved->getTypeClass() == TypeClass_TYPEDEF) {
856*cdf0e10cSrcweir         resolved = Reference< XIndirectTypeDescription >(
857*cdf0e10cSrcweir             type, UNO_QUERY_THROW)->getReferencedType();
858*cdf0e10cSrcweir     }
859*cdf0e10cSrcweir     return resolved;
860*cdf0e10cSrcweir }
861*cdf0e10cSrcweir 
862*cdf0e10cSrcweir bool isNonVoidNonExceptionType(Reference< XTypeDescription > const & type) {
863*cdf0e10cSrcweir     switch (type->getTypeClass()) {
864*cdf0e10cSrcweir     case TypeClass_BOOLEAN:
865*cdf0e10cSrcweir     case TypeClass_BYTE:
866*cdf0e10cSrcweir     case TypeClass_SHORT:
867*cdf0e10cSrcweir     case TypeClass_UNSIGNED_SHORT:
868*cdf0e10cSrcweir     case TypeClass_LONG:
869*cdf0e10cSrcweir     case TypeClass_UNSIGNED_LONG:
870*cdf0e10cSrcweir     case TypeClass_HYPER:
871*cdf0e10cSrcweir     case TypeClass_UNSIGNED_HYPER:
872*cdf0e10cSrcweir     case TypeClass_FLOAT:
873*cdf0e10cSrcweir     case TypeClass_DOUBLE:
874*cdf0e10cSrcweir     case TypeClass_CHAR:
875*cdf0e10cSrcweir     case TypeClass_STRING:
876*cdf0e10cSrcweir     case TypeClass_TYPE:
877*cdf0e10cSrcweir     case TypeClass_ANY:
878*cdf0e10cSrcweir     case TypeClass_SEQUENCE:
879*cdf0e10cSrcweir     case TypeClass_ENUM:
880*cdf0e10cSrcweir     case TypeClass_STRUCT:
881*cdf0e10cSrcweir     case TypeClass_INTERFACE:
882*cdf0e10cSrcweir         return true;
883*cdf0e10cSrcweir 
884*cdf0e10cSrcweir     default:
885*cdf0e10cSrcweir         return false;
886*cdf0e10cSrcweir     }
887*cdf0e10cSrcweir }
888*cdf0e10cSrcweir 
889*cdf0e10cSrcweir class InstantiatedStruct: public WeakImplHelper1< XStructTypeDescription > {
890*cdf0e10cSrcweir public:
891*cdf0e10cSrcweir     InstantiatedStruct(
892*cdf0e10cSrcweir         Reference< XStructTypeDescription > const & structType,
893*cdf0e10cSrcweir         std::vector< Reference< XTypeDescription > > const & arguments);
894*cdf0e10cSrcweir 
895*cdf0e10cSrcweir     virtual TypeClass SAL_CALL getTypeClass() throw (RuntimeException)
896*cdf0e10cSrcweir     { return TypeClass_STRUCT; }
897*cdf0e10cSrcweir 
898*cdf0e10cSrcweir     virtual OUString SAL_CALL getName() throw (RuntimeException);
899*cdf0e10cSrcweir 
900*cdf0e10cSrcweir     virtual Reference< XTypeDescription > SAL_CALL getBaseType()
901*cdf0e10cSrcweir         throw (RuntimeException)
902*cdf0e10cSrcweir     { return m_struct->getBaseType(); }
903*cdf0e10cSrcweir 
904*cdf0e10cSrcweir     virtual Sequence< Reference< XTypeDescription > > SAL_CALL getMemberTypes()
905*cdf0e10cSrcweir         throw (RuntimeException);
906*cdf0e10cSrcweir 
907*cdf0e10cSrcweir     virtual Sequence< OUString > SAL_CALL getMemberNames()
908*cdf0e10cSrcweir         throw (RuntimeException)
909*cdf0e10cSrcweir     { return m_struct->getMemberNames(); }
910*cdf0e10cSrcweir 
911*cdf0e10cSrcweir     virtual Sequence< OUString > SAL_CALL getTypeParameters()
912*cdf0e10cSrcweir         throw (RuntimeException)
913*cdf0e10cSrcweir     { return Sequence< OUString >(); }
914*cdf0e10cSrcweir 
915*cdf0e10cSrcweir     virtual Sequence< Reference< XTypeDescription > > SAL_CALL
916*cdf0e10cSrcweir     getTypeArguments() throw (RuntimeException)
917*cdf0e10cSrcweir     { return m_arguments; }
918*cdf0e10cSrcweir 
919*cdf0e10cSrcweir private:
920*cdf0e10cSrcweir     Reference< XStructTypeDescription > m_struct;
921*cdf0e10cSrcweir     Sequence< Reference< XTypeDescription > > m_arguments;
922*cdf0e10cSrcweir };
923*cdf0e10cSrcweir 
924*cdf0e10cSrcweir InstantiatedStruct::InstantiatedStruct(
925*cdf0e10cSrcweir     Reference< XStructTypeDescription > const & structType,
926*cdf0e10cSrcweir     std::vector< Reference< XTypeDescription > > const & arguments):
927*cdf0e10cSrcweir     m_struct(structType),
928*cdf0e10cSrcweir     m_arguments(static_cast< sal_Int32 >(arguments.size()))
929*cdf0e10cSrcweir {
930*cdf0e10cSrcweir     for (std::vector< Reference< XTypeDescription > >::size_type i = 0;
931*cdf0e10cSrcweir          i < arguments.size(); ++i)
932*cdf0e10cSrcweir     {
933*cdf0e10cSrcweir         m_arguments[static_cast< sal_Int32 >(i)] = arguments[i];
934*cdf0e10cSrcweir     }
935*cdf0e10cSrcweir }
936*cdf0e10cSrcweir 
937*cdf0e10cSrcweir OUString InstantiatedStruct::getName() throw (RuntimeException) {
938*cdf0e10cSrcweir     OUStringBuffer buf(m_struct->getName());
939*cdf0e10cSrcweir     buf.append(static_cast< sal_Unicode >('<'));
940*cdf0e10cSrcweir     for (sal_Int32 i = 0; i < m_arguments.getLength(); ++i) {
941*cdf0e10cSrcweir         if (i != 0) {
942*cdf0e10cSrcweir             buf.append(static_cast< sal_Unicode >(','));
943*cdf0e10cSrcweir         }
944*cdf0e10cSrcweir         buf.append(m_arguments[i]->getName());
945*cdf0e10cSrcweir     }
946*cdf0e10cSrcweir     buf.append(static_cast< sal_Unicode >('>'));
947*cdf0e10cSrcweir     return buf.makeStringAndClear();
948*cdf0e10cSrcweir }
949*cdf0e10cSrcweir 
950*cdf0e10cSrcweir Sequence< Reference< XTypeDescription > > InstantiatedStruct::getMemberTypes()
951*cdf0e10cSrcweir     throw (RuntimeException)
952*cdf0e10cSrcweir {
953*cdf0e10cSrcweir     Sequence< Reference< XTypeDescription > > types(m_struct->getMemberTypes());
954*cdf0e10cSrcweir     for (sal_Int32 i = 0; i < types.getLength(); ++i) {
955*cdf0e10cSrcweir         if (types[i]->getTypeClass() == TypeClass_UNKNOWN) {
956*cdf0e10cSrcweir             Sequence< OUString > parameters(m_struct->getTypeParameters());
957*cdf0e10cSrcweir             OSL_ASSERT(parameters.getLength() == m_arguments.getLength());
958*cdf0e10cSrcweir             for (sal_Int32 j = 0; j < parameters.getLength(); ++j) {
959*cdf0e10cSrcweir                 if (parameters[j] == types[i]->getName()) {
960*cdf0e10cSrcweir                     types[i] = m_arguments[j];
961*cdf0e10cSrcweir                     break;
962*cdf0e10cSrcweir                 }
963*cdf0e10cSrcweir             }
964*cdf0e10cSrcweir         }
965*cdf0e10cSrcweir     }
966*cdf0e10cSrcweir     return types;
967*cdf0e10cSrcweir }
968*cdf0e10cSrcweir 
969*cdf0e10cSrcweir }
970*cdf0e10cSrcweir 
971*cdf0e10cSrcweir Reference< XTypeDescription > ManagerImpl::getInstantiatedStruct(
972*cdf0e10cSrcweir     OUString const & name)
973*cdf0e10cSrcweir {
974*cdf0e10cSrcweir     sal_Int32 i = name.indexOf('<');
975*cdf0e10cSrcweir     OSL_ASSERT(i >= 0);
976*cdf0e10cSrcweir     Reference< XStructTypeDescription > structType(
977*cdf0e10cSrcweir         getByHierarchicalName(name.copy(0, i)), UNO_QUERY);
978*cdf0e10cSrcweir     std::vector< Reference< XTypeDescription > > args;
979*cdf0e10cSrcweir     bool good = structType.is();
980*cdf0e10cSrcweir     if (good) {
981*cdf0e10cSrcweir         do {
982*cdf0e10cSrcweir             ++i; // skip '<' or ','
983*cdf0e10cSrcweir             sal_Int32 j = i;
984*cdf0e10cSrcweir             for (sal_Int32 level = 0; j != name.getLength(); ++j) {
985*cdf0e10cSrcweir                 sal_Unicode c = name[j];
986*cdf0e10cSrcweir                 if (c == ',') {
987*cdf0e10cSrcweir                     if (level == 0) {
988*cdf0e10cSrcweir                         break;
989*cdf0e10cSrcweir                     }
990*cdf0e10cSrcweir                 } else if (c == '<') {
991*cdf0e10cSrcweir                     ++level;
992*cdf0e10cSrcweir                 } else if (c == '>') {
993*cdf0e10cSrcweir                     if (level == 0) {
994*cdf0e10cSrcweir                         break;
995*cdf0e10cSrcweir                     }
996*cdf0e10cSrcweir                     --level;
997*cdf0e10cSrcweir                 }
998*cdf0e10cSrcweir             }
999*cdf0e10cSrcweir             if (j != name.getLength()) {
1000*cdf0e10cSrcweir                 Reference< XTypeDescription > type(
1001*cdf0e10cSrcweir                     getByHierarchicalName(name.copy(i, j - i)), UNO_QUERY);
1002*cdf0e10cSrcweir                 if (isNonVoidNonExceptionType(resolveTypedefs(type))) {
1003*cdf0e10cSrcweir                     args.push_back(type);
1004*cdf0e10cSrcweir                 } else {
1005*cdf0e10cSrcweir                     good = false;
1006*cdf0e10cSrcweir                     break;
1007*cdf0e10cSrcweir                 }
1008*cdf0e10cSrcweir             }
1009*cdf0e10cSrcweir             i = j;
1010*cdf0e10cSrcweir         } while (i != name.getLength() && name[i] != '>');
1011*cdf0e10cSrcweir         good = good && i == name.getLength() - 1
1012*cdf0e10cSrcweir             && name[i] == '>' && !args.empty();
1013*cdf0e10cSrcweir     }
1014*cdf0e10cSrcweir     // args.size() cannot exceed SAL_MAX_INT32, as each argument consumes at
1015*cdf0e10cSrcweir     // least one position within an rtl::OUString (which is no longer than
1016*cdf0e10cSrcweir     // SAL_MAX_INT32):
1017*cdf0e10cSrcweir     if (!good
1018*cdf0e10cSrcweir         || (args.size()
1019*cdf0e10cSrcweir             != sal::static_int_cast< sal_uInt32 >(
1020*cdf0e10cSrcweir                 structType->getTypeParameters().getLength())))
1021*cdf0e10cSrcweir     {
1022*cdf0e10cSrcweir         throw NoSuchElementException(name, static_cast< OWeakObject * >(this));
1023*cdf0e10cSrcweir     }
1024*cdf0e10cSrcweir     return new InstantiatedStruct(structType, args);
1025*cdf0e10cSrcweir }
1026*cdf0e10cSrcweir 
1027*cdf0e10cSrcweir // XHierarchicalNameAccess
1028*cdf0e10cSrcweir //__________________________________________________________________________________________________
1029*cdf0e10cSrcweir Any ManagerImpl::getByHierarchicalName( const OUString & rName )
1030*cdf0e10cSrcweir 	throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException)
1031*cdf0e10cSrcweir {
1032*cdf0e10cSrcweir 	Any aRet;
1033*cdf0e10cSrcweir 	if (_bCaching)
1034*cdf0e10cSrcweir 		aRet = _aElements.getValue( rName );
1035*cdf0e10cSrcweir 	if (rName.getLength() && !aRet.hasValue())
1036*cdf0e10cSrcweir 	{
1037*cdf0e10cSrcweir 		sal_Int32 nIndex;
1038*cdf0e10cSrcweir 		if (rName[0] == '[') // test for sequence
1039*cdf0e10cSrcweir 		{
1040*cdf0e10cSrcweir 			Reference< XTypeDescription > xElemType(
1041*cdf0e10cSrcweir                 getByHierarchicalName( rName.copy( 2 ) ),
1042*cdf0e10cSrcweir                 UNO_QUERY_THROW );
1043*cdf0e10cSrcweir             aRet <<= Reference< XTypeDescription >(
1044*cdf0e10cSrcweir                 new SequenceTypeDescriptionImpl( xElemType ) );
1045*cdf0e10cSrcweir 		}
1046*cdf0e10cSrcweir 		else if (rName[rName.getLength()-1] == ']') // test for array
1047*cdf0e10cSrcweir 		{
1048*cdf0e10cSrcweir             sal_Int32 nIndex2 = 0, nTokens = 0;
1049*cdf0e10cSrcweir             do { rName.getToken( 0, '[', nIndex2 ); nTokens++; } while( nIndex2 != -1 );
1050*cdf0e10cSrcweir 			sal_Int32 nDims = nTokens - 1;
1051*cdf0e10cSrcweir 			sal_Int32 dimOffset = rName.indexOf('[');
1052*cdf0e10cSrcweir 			Reference< XTypeDescription > xElemType(
1053*cdf0e10cSrcweir                 getByHierarchicalName( rName.copy( 0, dimOffset ) ),
1054*cdf0e10cSrcweir                 UNO_QUERY_THROW );
1055*cdf0e10cSrcweir             aRet <<= Reference< XTypeDescription >(
1056*cdf0e10cSrcweir                 new ArrayTypeDescriptionImpl(
1057*cdf0e10cSrcweir                     xElemType, nDims, rName.copy(dimOffset) ) );
1058*cdf0e10cSrcweir 		}
1059*cdf0e10cSrcweir         // test for interface member names:
1060*cdf0e10cSrcweir 		else if ((nIndex = rName.indexOf( ':' )) >= 0)
1061*cdf0e10cSrcweir 		{
1062*cdf0e10cSrcweir 			Reference< XInterfaceTypeDescription > xIfaceTD(
1063*cdf0e10cSrcweir                 getByHierarchicalName( rName.copy( 0, nIndex ) ),
1064*cdf0e10cSrcweir                 UNO_QUERY_THROW );
1065*cdf0e10cSrcweir             const Sequence< Reference< XInterfaceMemberTypeDescription > > &
1066*cdf0e10cSrcweir                 rMembers = xIfaceTD->getMembers();
1067*cdf0e10cSrcweir             const Reference< XInterfaceMemberTypeDescription > * pMembers =
1068*cdf0e10cSrcweir                 rMembers.getConstArray();
1069*cdf0e10cSrcweir 
1070*cdf0e10cSrcweir             for ( sal_Int32 nPos = rMembers.getLength(); nPos--; )
1071*cdf0e10cSrcweir             {
1072*cdf0e10cSrcweir                 if (rName == pMembers[nPos]->getName())
1073*cdf0e10cSrcweir                 {
1074*cdf0e10cSrcweir                     aRet <<= Reference< XTypeDescription >(
1075*cdf0e10cSrcweir                         pMembers[nPos], UNO_QUERY_THROW );
1076*cdf0e10cSrcweir                     break;
1077*cdf0e10cSrcweir                 }
1078*cdf0e10cSrcweir             }
1079*cdf0e10cSrcweir             if (! aRet.hasValue())
1080*cdf0e10cSrcweir             {
1081*cdf0e10cSrcweir                 // member not found:
1082*cdf0e10cSrcweir                 throw NoSuchElementException(
1083*cdf0e10cSrcweir                     rName, static_cast< OWeakObject * >(this) );
1084*cdf0e10cSrcweir             }
1085*cdf0e10cSrcweir 		}
1086*cdf0e10cSrcweir         // test for instantiated polymorphic struct types:
1087*cdf0e10cSrcweir         else if (rName.indexOf('<') >= 0)
1088*cdf0e10cSrcweir         {
1089*cdf0e10cSrcweir             aRet <<= getInstantiatedStruct(rName);
1090*cdf0e10cSrcweir         }
1091*cdf0e10cSrcweir 		else if (rName.indexOf( '.' ) < 0) // test for simple/ build in types
1092*cdf0e10cSrcweir 		{
1093*cdf0e10cSrcweir 			aRet = getSimpleType( rName );
1094*cdf0e10cSrcweir 		}
1095*cdf0e10cSrcweir 
1096*cdf0e10cSrcweir 		if (! aRet.hasValue())
1097*cdf0e10cSrcweir 		{
1098*cdf0e10cSrcweir 			// last, try callback chain
1099*cdf0e10cSrcweir 			for ( ProviderVector::const_iterator iPos( _aProviders.begin() );
1100*cdf0e10cSrcweir 				  iPos != _aProviders.end(); ++iPos )
1101*cdf0e10cSrcweir 			{
1102*cdf0e10cSrcweir 				try
1103*cdf0e10cSrcweir 				{
1104*cdf0e10cSrcweir 					if ((aRet = (*iPos)->getByHierarchicalName(
1105*cdf0e10cSrcweir                              rName )).hasValue())
1106*cdf0e10cSrcweir                     {
1107*cdf0e10cSrcweir 						break;
1108*cdf0e10cSrcweir                     }
1109*cdf0e10cSrcweir 				}
1110*cdf0e10cSrcweir 				catch (NoSuchElementException &)
1111*cdf0e10cSrcweir 				{
1112*cdf0e10cSrcweir 				}
1113*cdf0e10cSrcweir 			}
1114*cdf0e10cSrcweir 		}
1115*cdf0e10cSrcweir 
1116*cdf0e10cSrcweir 		// update cache
1117*cdf0e10cSrcweir 		if (_bCaching && aRet.hasValue())
1118*cdf0e10cSrcweir 			_aElements.setValue( rName, aRet );
1119*cdf0e10cSrcweir 	}
1120*cdf0e10cSrcweir 
1121*cdf0e10cSrcweir 	if (! aRet.hasValue())
1122*cdf0e10cSrcweir 	{
1123*cdf0e10cSrcweir 		throw NoSuchElementException(
1124*cdf0e10cSrcweir             rName, static_cast< OWeakObject * >(this) );
1125*cdf0e10cSrcweir 	}
1126*cdf0e10cSrcweir 	return aRet;
1127*cdf0e10cSrcweir }
1128*cdf0e10cSrcweir //__________________________________________________________________________________________________
1129*cdf0e10cSrcweir sal_Bool ManagerImpl::hasByHierarchicalName( const OUString & rName )
1130*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
1131*cdf0e10cSrcweir {
1132*cdf0e10cSrcweir 	try
1133*cdf0e10cSrcweir 	{
1134*cdf0e10cSrcweir 		return getByHierarchicalName( rName ).hasValue();
1135*cdf0e10cSrcweir 	}
1136*cdf0e10cSrcweir 	catch (NoSuchElementException &)
1137*cdf0e10cSrcweir 	{
1138*cdf0e10cSrcweir 	}
1139*cdf0e10cSrcweir 	return sal_False;
1140*cdf0e10cSrcweir }
1141*cdf0e10cSrcweir }
1142*cdf0e10cSrcweir 
1143*cdf0e10cSrcweir namespace stoc_bootstrap
1144*cdf0e10cSrcweir {
1145*cdf0e10cSrcweir //==================================================================================================
1146*cdf0e10cSrcweir Reference< XInterface > SAL_CALL ManagerImpl_create(
1147*cdf0e10cSrcweir     Reference< XComponentContext > const & xContext )
1148*cdf0e10cSrcweir 	SAL_THROW( (::com::sun::star::uno::Exception) )
1149*cdf0e10cSrcweir {
1150*cdf0e10cSrcweir     sal_Int32 nCacheSize = CACHE_SIZE;
1151*cdf0e10cSrcweir     if (xContext.is()) {
1152*cdf0e10cSrcweir         xContext->getValueByName(
1153*cdf0e10cSrcweir             OUString(
1154*cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
1155*cdf0e10cSrcweir                     "/implementations/" IMPLNAME "/CacheSize"))) >>=
1156*cdf0e10cSrcweir             nCacheSize;
1157*cdf0e10cSrcweir     }
1158*cdf0e10cSrcweir 
1159*cdf0e10cSrcweir 	return Reference< XInterface >( *new stoc_tdmgr::ManagerImpl( xContext, nCacheSize ) );
1160*cdf0e10cSrcweir }
1161*cdf0e10cSrcweir 
1162*cdf0e10cSrcweir }
1163*cdf0e10cSrcweir 
1164