xref: /AOO41X/main/stoc/source/corereflection/crefl.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 <cppuhelper/queryinterface.hxx>
31*cdf0e10cSrcweir #ifndef _CPPUHELPER_IMPLEMENTATIONENTRY_HXX_
32*cdf0e10cSrcweir #include <cppuhelper/implementationentry.hxx>
33*cdf0e10cSrcweir #endif
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/reflection/XTypeDescription.hpp>
37*cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir using namespace com::sun::star;
40*cdf0e10cSrcweir using namespace com::sun::star::lang;
41*cdf0e10cSrcweir using namespace com::sun::star::registry;
42*cdf0e10cSrcweir using namespace cppu;
43*cdf0e10cSrcweir using namespace osl;
44*cdf0e10cSrcweir using namespace rtl;
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir #include "base.hxx"
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir namespace stoc_corefl
50*cdf0e10cSrcweir {
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir static const sal_Int32 CACHE_SIZE = 256;
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir #define SERVICENAME "com.sun.star.reflection.CoreReflection"
55*cdf0e10cSrcweir #define IMPLNAME	"com.sun.star.comp.stoc.CoreReflection"
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir // can be static, as every client of the core reflection keeps a reference to the
58*cdf0e10cSrcweir // core reflection, so refcounting can be done here.
59*cdf0e10cSrcweir static rtl_StandardModuleCount g_moduleCount = MODULE_COUNT_INIT;
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir static Sequence< OUString > core_getSupportedServiceNames()
62*cdf0e10cSrcweir {
63*cdf0e10cSrcweir 	static Sequence < OUString > *pNames = 0;
64*cdf0e10cSrcweir 	if( ! pNames )
65*cdf0e10cSrcweir 	{
66*cdf0e10cSrcweir 		MutexGuard guard( Mutex::getGlobalMutex() );
67*cdf0e10cSrcweir 		if( !pNames )
68*cdf0e10cSrcweir 		{
69*cdf0e10cSrcweir 			static Sequence< OUString > seqNames(1);
70*cdf0e10cSrcweir 			seqNames.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM(SERVICENAME) );
71*cdf0e10cSrcweir 			pNames = &seqNames;
72*cdf0e10cSrcweir 		}
73*cdf0e10cSrcweir 	}
74*cdf0e10cSrcweir 	return *pNames;
75*cdf0e10cSrcweir }
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir static OUString core_getImplementationName()
78*cdf0e10cSrcweir {
79*cdf0e10cSrcweir 	static OUString *pImplName = 0;
80*cdf0e10cSrcweir 	if( ! pImplName )
81*cdf0e10cSrcweir 	{
82*cdf0e10cSrcweir 		MutexGuard guard( Mutex::getGlobalMutex() );
83*cdf0e10cSrcweir 		if( ! pImplName )
84*cdf0e10cSrcweir 		{
85*cdf0e10cSrcweir 			static OUString implName( RTL_CONSTASCII_USTRINGPARAM( IMPLNAME ) );
86*cdf0e10cSrcweir 			pImplName = &implName;
87*cdf0e10cSrcweir 		}
88*cdf0e10cSrcweir 	}
89*cdf0e10cSrcweir 	return *pImplName;
90*cdf0e10cSrcweir }
91*cdf0e10cSrcweir //__________________________________________________________________________________________________
92*cdf0e10cSrcweir IdlReflectionServiceImpl::IdlReflectionServiceImpl(
93*cdf0e10cSrcweir     const Reference< XComponentContext > & xContext )
94*cdf0e10cSrcweir 	: OComponentHelper( _aComponentMutex )
95*cdf0e10cSrcweir 	, _xMgr( xContext->getServiceManager(), UNO_QUERY )
96*cdf0e10cSrcweir 	, _aElements( CACHE_SIZE )
97*cdf0e10cSrcweir {
98*cdf0e10cSrcweir 	g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
99*cdf0e10cSrcweir     xContext->getValueByName( OUString( RTL_CONSTASCII_USTRINGPARAM(
100*cdf0e10cSrcweir         "/singletons/com.sun.star.reflection.theTypeDescriptionManager") ) ) >>= _xTDMgr;
101*cdf0e10cSrcweir 	OSL_ENSURE( _xTDMgr.is(), "### cannot get singleton \"TypeDescriptionManager\" from context!" );
102*cdf0e10cSrcweir }
103*cdf0e10cSrcweir //__________________________________________________________________________________________________
104*cdf0e10cSrcweir IdlReflectionServiceImpl::~IdlReflectionServiceImpl()
105*cdf0e10cSrcweir {
106*cdf0e10cSrcweir 	TRACE( "> IdlReflectionServiceImpl dtor <\n" );
107*cdf0e10cSrcweir 	g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
108*cdf0e10cSrcweir }
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir // XInterface
111*cdf0e10cSrcweir //__________________________________________________________________________________________________
112*cdf0e10cSrcweir Any IdlReflectionServiceImpl::queryInterface( const Type & rType )
113*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
114*cdf0e10cSrcweir {
115*cdf0e10cSrcweir 	Any aRet( ::cppu::queryInterface(
116*cdf0e10cSrcweir 		rType,
117*cdf0e10cSrcweir 		static_cast< XIdlReflection * >( this ),
118*cdf0e10cSrcweir 		static_cast< XHierarchicalNameAccess * >( this ),
119*cdf0e10cSrcweir 		static_cast< XServiceInfo * >( this ) ) );
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir 	return (aRet.hasValue() ? aRet : OComponentHelper::queryInterface( rType ));
122*cdf0e10cSrcweir }
123*cdf0e10cSrcweir //__________________________________________________________________________________________________
124*cdf0e10cSrcweir void IdlReflectionServiceImpl::acquire() throw()
125*cdf0e10cSrcweir {
126*cdf0e10cSrcweir 	OComponentHelper::acquire();
127*cdf0e10cSrcweir }
128*cdf0e10cSrcweir //__________________________________________________________________________________________________
129*cdf0e10cSrcweir void IdlReflectionServiceImpl::release() throw()
130*cdf0e10cSrcweir {
131*cdf0e10cSrcweir 	OComponentHelper::release();
132*cdf0e10cSrcweir }
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir // XTypeProvider
135*cdf0e10cSrcweir //__________________________________________________________________________________________________
136*cdf0e10cSrcweir Sequence< Type > IdlReflectionServiceImpl::getTypes()
137*cdf0e10cSrcweir 	throw (::com::sun::star::uno::RuntimeException)
138*cdf0e10cSrcweir {
139*cdf0e10cSrcweir 	static OTypeCollection * s_pTypes = 0;
140*cdf0e10cSrcweir 	if (! s_pTypes)
141*cdf0e10cSrcweir 	{
142*cdf0e10cSrcweir 		MutexGuard aGuard( _aComponentMutex );
143*cdf0e10cSrcweir 		if (! s_pTypes)
144*cdf0e10cSrcweir 		{
145*cdf0e10cSrcweir 			static OTypeCollection s_aTypes(
146*cdf0e10cSrcweir 				::getCppuType( (const Reference< XIdlReflection > *)0 ),
147*cdf0e10cSrcweir 				::getCppuType( (const Reference< XHierarchicalNameAccess > *)0 ),
148*cdf0e10cSrcweir 				::getCppuType( (const Reference< XServiceInfo > *)0 ),
149*cdf0e10cSrcweir 				OComponentHelper::getTypes() );
150*cdf0e10cSrcweir 			s_pTypes = &s_aTypes;
151*cdf0e10cSrcweir 		}
152*cdf0e10cSrcweir 	}
153*cdf0e10cSrcweir 	return s_pTypes->getTypes();
154*cdf0e10cSrcweir }
155*cdf0e10cSrcweir //__________________________________________________________________________________________________
156*cdf0e10cSrcweir Sequence< sal_Int8 > IdlReflectionServiceImpl::getImplementationId()
157*cdf0e10cSrcweir 	throw (::com::sun::star::uno::RuntimeException)
158*cdf0e10cSrcweir {
159*cdf0e10cSrcweir 	static OImplementationId * s_pId = 0;
160*cdf0e10cSrcweir 	if (! s_pId)
161*cdf0e10cSrcweir 	{
162*cdf0e10cSrcweir 		MutexGuard aGuard( _aComponentMutex );
163*cdf0e10cSrcweir 		if (! s_pId)
164*cdf0e10cSrcweir 		{
165*cdf0e10cSrcweir 			static OImplementationId s_aId;
166*cdf0e10cSrcweir 			s_pId = &s_aId;
167*cdf0e10cSrcweir 		}
168*cdf0e10cSrcweir 	}
169*cdf0e10cSrcweir 	return s_pId->getImplementationId();
170*cdf0e10cSrcweir }
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir // XComponent
173*cdf0e10cSrcweir //__________________________________________________________________________________________________
174*cdf0e10cSrcweir void IdlReflectionServiceImpl::dispose()
175*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
176*cdf0e10cSrcweir {
177*cdf0e10cSrcweir 	TRACE( "> disposing corereflection... <" );
178*cdf0e10cSrcweir 	OComponentHelper::dispose();
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir 	MutexGuard aGuard( _aComponentMutex );
181*cdf0e10cSrcweir 	_aElements.clear();
182*cdf0e10cSrcweir #ifdef TEST_LIST_CLASSES
183*cdf0e10cSrcweir 	OSL_ENSURE( g_aClassNames.size() == 0, "### idl classes still alive!" );
184*cdf0e10cSrcweir 	ClassNameList::const_iterator iPos( g_aClassNames.begin() );
185*cdf0e10cSrcweir 	while (iPos != g_aClassNames.end())
186*cdf0e10cSrcweir 	{
187*cdf0e10cSrcweir 		OUString aName( *iPos );
188*cdf0e10cSrcweir 		++iPos;
189*cdf0e10cSrcweir 	}
190*cdf0e10cSrcweir #endif
191*cdf0e10cSrcweir }
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir // XServiceInfo
194*cdf0e10cSrcweir //__________________________________________________________________________________________________
195*cdf0e10cSrcweir OUString IdlReflectionServiceImpl::getImplementationName()
196*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
197*cdf0e10cSrcweir {
198*cdf0e10cSrcweir 	return core_getImplementationName();
199*cdf0e10cSrcweir }
200*cdf0e10cSrcweir //__________________________________________________________________________________________________
201*cdf0e10cSrcweir sal_Bool IdlReflectionServiceImpl::supportsService( const OUString & rServiceName )
202*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
203*cdf0e10cSrcweir {
204*cdf0e10cSrcweir 	const Sequence< OUString > & rSNL = getSupportedServiceNames();
205*cdf0e10cSrcweir 	const OUString * pArray = rSNL.getConstArray();
206*cdf0e10cSrcweir 	for ( sal_Int32 nPos = rSNL.getLength(); nPos--; )
207*cdf0e10cSrcweir 	{
208*cdf0e10cSrcweir 		if (pArray[nPos] == rServiceName)
209*cdf0e10cSrcweir 			return sal_True;
210*cdf0e10cSrcweir 	}
211*cdf0e10cSrcweir 	return sal_False;
212*cdf0e10cSrcweir }
213*cdf0e10cSrcweir //__________________________________________________________________________________________________
214*cdf0e10cSrcweir Sequence< OUString > IdlReflectionServiceImpl::getSupportedServiceNames()
215*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
216*cdf0e10cSrcweir {
217*cdf0e10cSrcweir 	return core_getSupportedServiceNames();
218*cdf0e10cSrcweir }
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir // XIdlReflection
221*cdf0e10cSrcweir //__________________________________________________________________________________________________
222*cdf0e10cSrcweir Reference< XIdlClass > IdlReflectionServiceImpl::getType( const Any & rObj )
223*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
224*cdf0e10cSrcweir {
225*cdf0e10cSrcweir 	return (rObj.hasValue() ? forType( rObj.getValueTypeRef() ) : Reference< XIdlClass >());
226*cdf0e10cSrcweir }
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir //__________________________________________________________________________________________________
229*cdf0e10cSrcweir inline Reference< XIdlClass > IdlReflectionServiceImpl::constructClass(
230*cdf0e10cSrcweir 	typelib_TypeDescription * pTypeDescr )
231*cdf0e10cSrcweir {
232*cdf0e10cSrcweir 	OSL_ENSURE( pTypeDescr->eTypeClass != typelib_TypeClass_TYPEDEF, "### unexpected typedef!" );
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir 	switch (pTypeDescr->eTypeClass)
235*cdf0e10cSrcweir 	{
236*cdf0e10cSrcweir 	case typelib_TypeClass_VOID:
237*cdf0e10cSrcweir 	case typelib_TypeClass_CHAR:
238*cdf0e10cSrcweir 	case typelib_TypeClass_BOOLEAN:
239*cdf0e10cSrcweir 	case typelib_TypeClass_BYTE:
240*cdf0e10cSrcweir 	case typelib_TypeClass_SHORT:
241*cdf0e10cSrcweir 	case typelib_TypeClass_UNSIGNED_SHORT:
242*cdf0e10cSrcweir 	case typelib_TypeClass_LONG:
243*cdf0e10cSrcweir 	case typelib_TypeClass_UNSIGNED_LONG:
244*cdf0e10cSrcweir 	case typelib_TypeClass_HYPER:
245*cdf0e10cSrcweir 	case typelib_TypeClass_UNSIGNED_HYPER:
246*cdf0e10cSrcweir 	case typelib_TypeClass_FLOAT:
247*cdf0e10cSrcweir 	case typelib_TypeClass_DOUBLE:
248*cdf0e10cSrcweir 	case typelib_TypeClass_STRING:
249*cdf0e10cSrcweir 	case typelib_TypeClass_ANY:
250*cdf0e10cSrcweir 		return new IdlClassImpl( this, pTypeDescr->pTypeName, pTypeDescr->eTypeClass, pTypeDescr );
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir 	case TypeClass_ENUM:
253*cdf0e10cSrcweir 		return new EnumIdlClassImpl( this, pTypeDescr->pTypeName, pTypeDescr->eTypeClass, pTypeDescr );
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir 	case typelib_TypeClass_STRUCT:
256*cdf0e10cSrcweir 	case typelib_TypeClass_UNION:
257*cdf0e10cSrcweir 	case typelib_TypeClass_EXCEPTION:
258*cdf0e10cSrcweir 		return new CompoundIdlClassImpl( this, pTypeDescr->pTypeName, pTypeDescr->eTypeClass, pTypeDescr );
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir 	case typelib_TypeClass_ARRAY:
261*cdf0e10cSrcweir 	case typelib_TypeClass_SEQUENCE:
262*cdf0e10cSrcweir 		return new ArrayIdlClassImpl( this, pTypeDescr->pTypeName, pTypeDescr->eTypeClass, pTypeDescr );
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir 	case typelib_TypeClass_INTERFACE:
265*cdf0e10cSrcweir 		return new InterfaceIdlClassImpl( this, pTypeDescr->pTypeName, pTypeDescr->eTypeClass, pTypeDescr );
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir 	case typelib_TypeClass_TYPE:
268*cdf0e10cSrcweir 		return new IdlClassImpl( this, pTypeDescr->pTypeName, pTypeDescr->eTypeClass, pTypeDescr );
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir 	default:
271*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
272*cdf0e10cSrcweir 		OSL_TRACE( "### corereflection type unsupported: " );
273*cdf0e10cSrcweir 		OString aName( OUStringToOString( pTypeDescr->pTypeName, RTL_TEXTENCODING_ASCII_US ) );
274*cdf0e10cSrcweir 		OSL_TRACE( aName.getStr() );
275*cdf0e10cSrcweir 		OSL_TRACE( "\n" );
276*cdf0e10cSrcweir #endif
277*cdf0e10cSrcweir         return Reference< XIdlClass >();
278*cdf0e10cSrcweir 	}
279*cdf0e10cSrcweir }
280*cdf0e10cSrcweir //__________________________________________________________________________________________________
281*cdf0e10cSrcweir Reference< XIdlClass > IdlReflectionServiceImpl::forName( const OUString & rTypeName )
282*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
283*cdf0e10cSrcweir {
284*cdf0e10cSrcweir 	Reference< XIdlClass > xRet;
285*cdf0e10cSrcweir 	Any aAny( _aElements.getValue( rTypeName ) );
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir 	if (aAny.hasValue())
288*cdf0e10cSrcweir 	{
289*cdf0e10cSrcweir 		if (aAny.getValueTypeClass() == TypeClass_INTERFACE)
290*cdf0e10cSrcweir 			xRet = *(const Reference< XIdlClass > *)aAny.getValue();
291*cdf0e10cSrcweir 	}
292*cdf0e10cSrcweir 	else
293*cdf0e10cSrcweir 	{
294*cdf0e10cSrcweir 		// try to get _type_ by name
295*cdf0e10cSrcweir 		typelib_TypeDescription * pTD = 0;
296*cdf0e10cSrcweir 		typelib_typedescription_getByName( &pTD, rTypeName.pData );
297*cdf0e10cSrcweir 		if (pTD)
298*cdf0e10cSrcweir 		{
299*cdf0e10cSrcweir 			if ((xRet = constructClass( pTD )).is())
300*cdf0e10cSrcweir 				_aElements.setValue( rTypeName, makeAny( xRet ) ); // update
301*cdf0e10cSrcweir 			typelib_typedescription_release( pTD );
302*cdf0e10cSrcweir 		}
303*cdf0e10cSrcweir 	}
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir 	return xRet;
306*cdf0e10cSrcweir }
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir // XHierarchicalNameAccess
309*cdf0e10cSrcweir //__________________________________________________________________________________________________
310*cdf0e10cSrcweir Any IdlReflectionServiceImpl::getByHierarchicalName( const OUString & rName )
311*cdf0e10cSrcweir 	throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException)
312*cdf0e10cSrcweir {
313*cdf0e10cSrcweir 	Any aRet( _aElements.getValue( rName ) );
314*cdf0e10cSrcweir 	if (! aRet.hasValue())
315*cdf0e10cSrcweir 	{
316*cdf0e10cSrcweir 		// first look for constants exclusivly!
317*cdf0e10cSrcweir 		aRet = _xTDMgr->getByHierarchicalName( rName );
318*cdf0e10cSrcweir 		if (aRet.getValueTypeClass() == TypeClass_INTERFACE) // if no constant,
319*cdf0e10cSrcweir 															 // i.e. XTypeDescription for a type
320*cdf0e10cSrcweir 		{
321*cdf0e10cSrcweir 			// type retrieved from tdmgr
322*cdf0e10cSrcweir 			OSL_ASSERT( (*(Reference< XInterface > *)aRet.getValue())->queryInterface(
323*cdf0e10cSrcweir 				::getCppuType( (const Reference< XTypeDescription > *)0 ) ).hasValue() );
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir 			// if you are interested in a type then CALL forName()!!!
326*cdf0e10cSrcweir 			// this way is NOT recommended for types, because this method looks for constants first
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir 			// if td manager found some type, it will be in the cache (hopefully.. we just got it)
329*cdf0e10cSrcweir 			// so the second retrieving via c typelib callback chain should succeed...
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir 			// try to get _type_ by name
332*cdf0e10cSrcweir 			typelib_TypeDescription * pTD = 0;
333*cdf0e10cSrcweir 			typelib_typedescription_getByName( &pTD, rName.pData );
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir 			aRet.clear(); // kick XTypeDescription interface
336*cdf0e10cSrcweir 
337*cdf0e10cSrcweir 			if (pTD)
338*cdf0e10cSrcweir 			{
339*cdf0e10cSrcweir 				Reference< XIdlClass > xIdlClass( constructClass( pTD ) );
340*cdf0e10cSrcweir 				aRet.setValue( &xIdlClass, ::getCppuType( (const Reference< XIdlClass > *)0 ) );
341*cdf0e10cSrcweir 				typelib_typedescription_release( pTD );
342*cdf0e10cSrcweir 			}
343*cdf0e10cSrcweir 		}
344*cdf0e10cSrcweir 		// else is constant
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir 		// update
347*cdf0e10cSrcweir 		if (aRet.hasValue())
348*cdf0e10cSrcweir 			_aElements.setValue( rName, aRet );
349*cdf0e10cSrcweir 		else
350*cdf0e10cSrcweir 		{
351*cdf0e10cSrcweir 			throw NoSuchElementException( rName, Reference< XInterface >() );
352*cdf0e10cSrcweir 		}
353*cdf0e10cSrcweir 	}
354*cdf0e10cSrcweir 	return aRet;
355*cdf0e10cSrcweir }
356*cdf0e10cSrcweir //__________________________________________________________________________________________________
357*cdf0e10cSrcweir sal_Bool IdlReflectionServiceImpl::hasByHierarchicalName( const OUString & rName )
358*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
359*cdf0e10cSrcweir {
360*cdf0e10cSrcweir 	try
361*cdf0e10cSrcweir 	{
362*cdf0e10cSrcweir 		return getByHierarchicalName( rName ).hasValue();
363*cdf0e10cSrcweir 	}
364*cdf0e10cSrcweir 	catch (NoSuchElementException &)
365*cdf0e10cSrcweir 	{
366*cdf0e10cSrcweir 	}
367*cdf0e10cSrcweir 	return sal_False;
368*cdf0e10cSrcweir }
369*cdf0e10cSrcweir 
370*cdf0e10cSrcweir //__________________________________________________________________________________________________
371*cdf0e10cSrcweir Reference< XIdlClass > IdlReflectionServiceImpl::forType( typelib_TypeDescription * pTypeDescr )
372*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
373*cdf0e10cSrcweir {
374*cdf0e10cSrcweir 	Reference< XIdlClass > xRet;
375*cdf0e10cSrcweir 	OUString aName( pTypeDescr->pTypeName );
376*cdf0e10cSrcweir 	Any aAny( _aElements.getValue( aName ) );
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir 	if (aAny.hasValue())
379*cdf0e10cSrcweir 	{
380*cdf0e10cSrcweir 		if (aAny.getValueTypeClass() == TypeClass_INTERFACE)
381*cdf0e10cSrcweir 			xRet = *(const Reference< XIdlClass > *)aAny.getValue();
382*cdf0e10cSrcweir 	}
383*cdf0e10cSrcweir 	else
384*cdf0e10cSrcweir 	{
385*cdf0e10cSrcweir 		if (pTypeDescr && (xRet = constructClass( pTypeDescr )).is())
386*cdf0e10cSrcweir 			_aElements.setValue( aName, makeAny( xRet ) ); // update
387*cdf0e10cSrcweir 	}
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir 	return xRet;
390*cdf0e10cSrcweir }
391*cdf0e10cSrcweir //__________________________________________________________________________________________________
392*cdf0e10cSrcweir Reference< XIdlClass > IdlReflectionServiceImpl::forType( typelib_TypeDescriptionReference * pRef )
393*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
394*cdf0e10cSrcweir {
395*cdf0e10cSrcweir 	typelib_TypeDescription * pTD = 0;
396*cdf0e10cSrcweir 	TYPELIB_DANGER_GET( &pTD, pRef );
397*cdf0e10cSrcweir 	if (pTD)
398*cdf0e10cSrcweir 	{
399*cdf0e10cSrcweir 		Reference< XIdlClass > xRet = forType( pTD );
400*cdf0e10cSrcweir 		TYPELIB_DANGER_RELEASE( pTD );
401*cdf0e10cSrcweir 		return xRet;
402*cdf0e10cSrcweir 	}
403*cdf0e10cSrcweir 	throw RuntimeException(
404*cdf0e10cSrcweir 		OUString( RTL_CONSTASCII_USTRINGPARAM("IdlReflectionServiceImpl::forType() failed!") ),
405*cdf0e10cSrcweir 		(XWeak *)(OWeakObject *)this );
406*cdf0e10cSrcweir }
407*cdf0e10cSrcweir 
408*cdf0e10cSrcweir //__________________________________________________________________________________________________
409*cdf0e10cSrcweir const Mapping & IdlReflectionServiceImpl::getCpp2Uno()
410*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
411*cdf0e10cSrcweir {
412*cdf0e10cSrcweir 	if (! _aCpp2Uno.is())
413*cdf0e10cSrcweir 	{
414*cdf0e10cSrcweir 		MutexGuard aGuard( getMutexAccess() );
415*cdf0e10cSrcweir 		if (! _aCpp2Uno.is())
416*cdf0e10cSrcweir 		{
417*cdf0e10cSrcweir 			_aCpp2Uno = Mapping(
418*cdf0e10cSrcweir                 OUString( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ),
419*cdf0e10cSrcweir                 OUString( RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO) ) );
420*cdf0e10cSrcweir 			OSL_ENSURE( _aCpp2Uno.is(), "### cannot get c++ to uno mapping!" );
421*cdf0e10cSrcweir 			if (! _aCpp2Uno.is())
422*cdf0e10cSrcweir 			{
423*cdf0e10cSrcweir 				throw RuntimeException(
424*cdf0e10cSrcweir 					OUString( RTL_CONSTASCII_USTRINGPARAM("cannot get c++ to uno mapping!") ),
425*cdf0e10cSrcweir 					(XWeak *)(OWeakObject *)this );
426*cdf0e10cSrcweir 			}
427*cdf0e10cSrcweir 		}
428*cdf0e10cSrcweir 	}
429*cdf0e10cSrcweir 	return _aCpp2Uno;
430*cdf0e10cSrcweir }
431*cdf0e10cSrcweir //__________________________________________________________________________________________________
432*cdf0e10cSrcweir const Mapping & IdlReflectionServiceImpl::getUno2Cpp()
433*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
434*cdf0e10cSrcweir {
435*cdf0e10cSrcweir 	if (! _aUno2Cpp.is())
436*cdf0e10cSrcweir 	{
437*cdf0e10cSrcweir 		MutexGuard aGuard( getMutexAccess() );
438*cdf0e10cSrcweir 		if (! _aUno2Cpp.is())
439*cdf0e10cSrcweir 		{
440*cdf0e10cSrcweir 			_aUno2Cpp = Mapping(
441*cdf0e10cSrcweir                 OUString( RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO) ),
442*cdf0e10cSrcweir                 OUString( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ) );
443*cdf0e10cSrcweir 			OSL_ENSURE( _aUno2Cpp.is(), "### cannot get uno to c++ mapping!" );
444*cdf0e10cSrcweir 			if (! _aUno2Cpp.is())
445*cdf0e10cSrcweir 			{
446*cdf0e10cSrcweir 				throw RuntimeException(
447*cdf0e10cSrcweir 					OUString( RTL_CONSTASCII_USTRINGPARAM("cannot get uno to c++ mapping!") ),
448*cdf0e10cSrcweir 					(XWeak *)(OWeakObject *)this );
449*cdf0e10cSrcweir 			}
450*cdf0e10cSrcweir 		}
451*cdf0e10cSrcweir 	}
452*cdf0e10cSrcweir 	return _aUno2Cpp;
453*cdf0e10cSrcweir }
454*cdf0e10cSrcweir //__________________________________________________________________________________________________
455*cdf0e10cSrcweir uno_Interface * IdlReflectionServiceImpl::mapToUno(
456*cdf0e10cSrcweir     const Any & rObj, typelib_InterfaceTypeDescription * pTo )
457*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
458*cdf0e10cSrcweir {
459*cdf0e10cSrcweir 	Reference< XInterface > xObj;
460*cdf0e10cSrcweir 	if (extract( rObj, pTo, xObj, this ))
461*cdf0e10cSrcweir 		return (uno_Interface *)getCpp2Uno().mapInterface( xObj.get(), pTo );
462*cdf0e10cSrcweir 
463*cdf0e10cSrcweir 	throw RuntimeException(
464*cdf0e10cSrcweir 		OUString( RTL_CONSTASCII_USTRINGPARAM("illegal object given!") ),
465*cdf0e10cSrcweir 		(XWeak *)(OWeakObject *)this );
466*cdf0e10cSrcweir }
467*cdf0e10cSrcweir 
468*cdf0e10cSrcweir //==================================================================================================
469*cdf0e10cSrcweir Reference< XInterface > SAL_CALL IdlReflectionServiceImpl_create(
470*cdf0e10cSrcweir 	const Reference< XComponentContext > & xContext )
471*cdf0e10cSrcweir 	throw(::com::sun::star::uno::Exception)
472*cdf0e10cSrcweir {
473*cdf0e10cSrcweir 	return Reference< XInterface >( (XWeak *)(OWeakObject *)new IdlReflectionServiceImpl( xContext ) );
474*cdf0e10cSrcweir }
475*cdf0e10cSrcweir 
476*cdf0e10cSrcweir }
477*cdf0e10cSrcweir 
478*cdf0e10cSrcweir 
479*cdf0e10cSrcweir //##################################################################################################
480*cdf0e10cSrcweir //##################################################################################################
481*cdf0e10cSrcweir //##################################################################################################
482*cdf0e10cSrcweir 
483*cdf0e10cSrcweir using namespace stoc_corefl;
484*cdf0e10cSrcweir 
485*cdf0e10cSrcweir static struct ImplementationEntry g_entries[] =
486*cdf0e10cSrcweir {
487*cdf0e10cSrcweir 	{
488*cdf0e10cSrcweir 		IdlReflectionServiceImpl_create, core_getImplementationName,
489*cdf0e10cSrcweir 		core_getSupportedServiceNames, createSingleComponentFactory,
490*cdf0e10cSrcweir 		&g_moduleCount.modCnt , 0
491*cdf0e10cSrcweir 	},
492*cdf0e10cSrcweir 	{ 0, 0, 0, 0, 0, 0 }
493*cdf0e10cSrcweir };
494*cdf0e10cSrcweir 
495*cdf0e10cSrcweir extern "C"
496*cdf0e10cSrcweir {
497*cdf0e10cSrcweir sal_Bool SAL_CALL component_canUnload( TimeValue *pTime )
498*cdf0e10cSrcweir {
499*cdf0e10cSrcweir 	return g_moduleCount.canUnload( &g_moduleCount , pTime );
500*cdf0e10cSrcweir }
501*cdf0e10cSrcweir 
502*cdf0e10cSrcweir //==================================================================================================
503*cdf0e10cSrcweir void SAL_CALL component_getImplementationEnvironment(
504*cdf0e10cSrcweir 	const sal_Char ** ppEnvTypeName, uno_Environment ** )
505*cdf0e10cSrcweir {
506*cdf0e10cSrcweir 	*ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
507*cdf0e10cSrcweir }
508*cdf0e10cSrcweir //==================================================================================================
509*cdf0e10cSrcweir void * SAL_CALL component_getFactory(
510*cdf0e10cSrcweir 	const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey )
511*cdf0e10cSrcweir {
512*cdf0e10cSrcweir 	return component_getFactoryHelper( pImplName, pServiceManager, pRegistryKey , g_entries );
513*cdf0e10cSrcweir }
514*cdf0e10cSrcweir }
515