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/mutex.hxx>
31*cdf0e10cSrcweir #include <cppuhelper/queryinterface.hxx>
32*cdf0e10cSrcweir #ifndef _CPPUHELER_WEAK_HXX_
33*cdf0e10cSrcweir #include <cppuhelper/weak.hxx>
34*cdf0e10cSrcweir #endif
35*cdf0e10cSrcweir #include <cppuhelper/factory.hxx>
36*cdf0e10cSrcweir #ifndef _CPPUHELPER_IMPLEMENTATIONENTRY_HXX__
37*cdf0e10cSrcweir #include <cppuhelper/implementationentry.hxx>
38*cdf0e10cSrcweir #endif
39*cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
40*cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx>
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir #include <com/sun/star/uno/DeploymentException.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/script/FailReason.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/script/XTypeConverter.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/script/XInvocation.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/script/XInvocation2.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/reflection/XIdlReflection.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
49*cdf0e10cSrcweir #include <com/sun/star/container/XIndexContainer.hpp>
50*cdf0e10cSrcweir #include <com/sun/star/container/XEnumerationAccess.hpp>
51*cdf0e10cSrcweir #include <com/sun/star/beans/XExactName.hpp>
52*cdf0e10cSrcweir #include <com/sun/star/beans/XMaterialHolder.hpp>
53*cdf0e10cSrcweir #include <com/sun/star/beans/XIntrospection.hpp>
54*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
55*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
56*cdf0e10cSrcweir #include <com/sun/star/beans/MethodConcept.hpp>
57*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyConcept.hpp>
58*cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp>
59*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
60*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
61*cdf0e10cSrcweir #include <com/sun/star/lang/XTypeProvider.hpp>
62*cdf0e10cSrcweir #include <com/sun/star/registry/XRegistryKey.hpp>
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir #include <boost/scoped_array.hpp>
65*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
66*cdf0e10cSrcweir #include <rtl/strbuf.hxx>
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir #define SERVICENAME "com.sun.star.script.Invocation"
69*cdf0e10cSrcweir #define IMPLNAME	 "com.sun.star.comp.stoc.Invocation"
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir using namespace com::sun::star::uno;
72*cdf0e10cSrcweir using namespace com::sun::star::lang;
73*cdf0e10cSrcweir using namespace com::sun::star::script;
74*cdf0e10cSrcweir using namespace com::sun::star::reflection;
75*cdf0e10cSrcweir using namespace com::sun::star::beans;
76*cdf0e10cSrcweir using namespace com::sun::star::registry;
77*cdf0e10cSrcweir using namespace com::sun::star::container;
78*cdf0e10cSrcweir using namespace cppu;
79*cdf0e10cSrcweir using namespace rtl;
80*cdf0e10cSrcweir using namespace osl;
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir namespace stoc_inv
84*cdf0e10cSrcweir {
85*cdf0e10cSrcweir static rtl_StandardModuleCount g_moduleCount = MODULE_COUNT_INIT;
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir static Sequence< OUString > inv_getSupportedServiceNames()
88*cdf0e10cSrcweir {
89*cdf0e10cSrcweir 	static Sequence < OUString > *pNames = 0;
90*cdf0e10cSrcweir 	if( ! pNames )
91*cdf0e10cSrcweir 	{
92*cdf0e10cSrcweir 		MutexGuard guard( Mutex::getGlobalMutex() );
93*cdf0e10cSrcweir 		if( !pNames )
94*cdf0e10cSrcweir 		{
95*cdf0e10cSrcweir 			static Sequence< OUString > seqNames(1);
96*cdf0e10cSrcweir 			seqNames.getArray()[0] = OUString(RTL_CONSTASCII_USTRINGPARAM(SERVICENAME));
97*cdf0e10cSrcweir 			pNames = &seqNames;
98*cdf0e10cSrcweir 		}
99*cdf0e10cSrcweir 	}
100*cdf0e10cSrcweir 	return *pNames;
101*cdf0e10cSrcweir }
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir static OUString inv_getImplementationName()
104*cdf0e10cSrcweir {
105*cdf0e10cSrcweir 	static OUString *pImplName = 0;
106*cdf0e10cSrcweir 	if( ! pImplName )
107*cdf0e10cSrcweir 	{
108*cdf0e10cSrcweir 		MutexGuard guard( Mutex::getGlobalMutex() );
109*cdf0e10cSrcweir 		if( ! pImplName )
110*cdf0e10cSrcweir 		{
111*cdf0e10cSrcweir 			static OUString implName( RTL_CONSTASCII_USTRINGPARAM( IMPLNAME ) );
112*cdf0e10cSrcweir 			pImplName = &implName;
113*cdf0e10cSrcweir 		}
114*cdf0e10cSrcweir 	}
115*cdf0e10cSrcweir 	return *pImplName;
116*cdf0e10cSrcweir }
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir // TODO: Zentral implementieren
119*cdf0e10cSrcweir inline Reference<XIdlClass> TypeToIdlClass( const Type& rType, const Reference< XIdlReflection > & xRefl )
120*cdf0e10cSrcweir {
121*cdf0e10cSrcweir 	return xRefl->forName( rType.getTypeName() );
122*cdf0e10cSrcweir }
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir //==================================================================================================
126*cdf0e10cSrcweir class Invocation_Impl
127*cdf0e10cSrcweir 	: public OWeakObject
128*cdf0e10cSrcweir 	, public XInvocation2
129*cdf0e10cSrcweir 	, public XNameContainer
130*cdf0e10cSrcweir 	, public XIndexContainer
131*cdf0e10cSrcweir 	, public XEnumerationAccess
132*cdf0e10cSrcweir 	, public XExactName
133*cdf0e10cSrcweir 	, public XMaterialHolder
134*cdf0e10cSrcweir     , public XTypeProvider
135*cdf0e10cSrcweir {
136*cdf0e10cSrcweir public:
137*cdf0e10cSrcweir 	Invocation_Impl( const Any & rAdapted, const Reference<XTypeConverter> &,
138*cdf0e10cSrcweir 										   const Reference<XIntrospection> &,
139*cdf0e10cSrcweir 										   const Reference<XIdlReflection> & );
140*cdf0e10cSrcweir 	virtual ~Invocation_Impl();
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir 	// XInterface
143*cdf0e10cSrcweir     virtual Any	        SAL_CALL queryInterface( const Type & aType) throw( RuntimeException );
144*cdf0e10cSrcweir 	virtual void		SAL_CALL acquire() throw() { OWeakObject::acquire(); }
145*cdf0e10cSrcweir 	virtual void		SAL_CALL release() throw() { OWeakObject::release(); }
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir 	// XTypeProvider
149*cdf0e10cSrcweir     virtual Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes(  )
150*cdf0e10cSrcweir 	   throw(RuntimeException);
151*cdf0e10cSrcweir     virtual Sequence< sal_Int8 > SAL_CALL getImplementationId(  )
152*cdf0e10cSrcweir 	   throw( RuntimeException);
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir     // Methoden von XMaterialHolder
155*cdf0e10cSrcweir 	virtual Any			SAL_CALL getMaterial(void) throw(RuntimeException);
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir 	// ? XTool
158*cdf0e10cSrcweir 	virtual void		SAL_CALL setMaterial( const Any& rMaterial );
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir 	// XInvocation
161*cdf0e10cSrcweir     virtual Reference<XIntrospectionAccess> SAL_CALL getIntrospection(void) throw( RuntimeException );
162*cdf0e10cSrcweir     virtual Any SAL_CALL invoke(const OUString& FunctionName, const Sequence< Any >& Params, Sequence< sal_Int16 >& OutParamIndex, Sequence< Any >& OutParam)
163*cdf0e10cSrcweir 		throw( IllegalArgumentException, CannotConvertException, InvocationTargetException, RuntimeException );
164*cdf0e10cSrcweir     virtual void SAL_CALL setValue(const OUString& PropertyName, const Any& Value)
165*cdf0e10cSrcweir 		throw( UnknownPropertyException, CannotConvertException, InvocationTargetException, RuntimeException );
166*cdf0e10cSrcweir     virtual Any SAL_CALL getValue(const OUString& PropertyName)
167*cdf0e10cSrcweir 		throw( UnknownPropertyException, RuntimeException );
168*cdf0e10cSrcweir     virtual sal_Bool SAL_CALL hasMethod(const OUString& Name) throw( RuntimeException );
169*cdf0e10cSrcweir     virtual sal_Bool SAL_CALL hasProperty(const OUString& Name) throw( RuntimeException );
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir     // XInvocation2
172*cdf0e10cSrcweir     virtual Sequence< OUString > SAL_CALL getMemberNames(  )
173*cdf0e10cSrcweir 		throw( RuntimeException );
174*cdf0e10cSrcweir     virtual Sequence< InvocationInfo > SAL_CALL getInfo(  )
175*cdf0e10cSrcweir 		throw( RuntimeException );
176*cdf0e10cSrcweir     virtual InvocationInfo SAL_CALL getInfoForName( const OUString& aName, sal_Bool bExact )
177*cdf0e10cSrcweir 		throw( IllegalArgumentException, RuntimeException );
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir 	// All Access and Container methods are not thread save
180*cdf0e10cSrcweir 	// XElementAccess
181*cdf0e10cSrcweir 	virtual Type SAL_CALL getElementType(void) throw( RuntimeException )
182*cdf0e10cSrcweir 		{ return _xElementAccess->getElementType(); }
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir 	virtual sal_Bool SAL_CALL hasElements(void) throw( RuntimeException )
185*cdf0e10cSrcweir 		{ return _xElementAccess->hasElements(); }
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir 	// XNameContainer
188*cdf0e10cSrcweir     virtual void SAL_CALL insertByName( const OUString& Name, const Any& Element )
189*cdf0e10cSrcweir 		throw( IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException )
190*cdf0e10cSrcweir 		{ _xNameContainer->insertByName( Name, Element ); }
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir     virtual void SAL_CALL replaceByName( const OUString& Name, const Any& Element )
193*cdf0e10cSrcweir 		throw( IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException )
194*cdf0e10cSrcweir 		{ _xNameContainer->replaceByName( Name, Element ); }
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir     virtual void SAL_CALL removeByName( const OUString& Name )
197*cdf0e10cSrcweir 		throw( NoSuchElementException, WrappedTargetException, RuntimeException )
198*cdf0e10cSrcweir 		{ _xNameContainer->removeByName( Name ); }
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir 	// XNameAccess
201*cdf0e10cSrcweir     virtual Any SAL_CALL getByName( const OUString& Name )
202*cdf0e10cSrcweir 		throw( NoSuchElementException, WrappedTargetException, RuntimeException )
203*cdf0e10cSrcweir 		{ return _xNameAccess->getByName( Name ); }
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir     virtual Sequence<OUString> SAL_CALL getElementNames(void) throw( RuntimeException )
206*cdf0e10cSrcweir 		{ return _xNameAccess->getElementNames(); }
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir     virtual sal_Bool SAL_CALL hasByName( const OUString& Name ) throw( RuntimeException )
209*cdf0e10cSrcweir 		{ return _xNameAccess->hasByName( Name ); }
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir 	// XIndexContainer
212*cdf0e10cSrcweir     virtual void SAL_CALL insertByIndex( sal_Int32 Index, const Any& Element )
213*cdf0e10cSrcweir 		throw( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
214*cdf0e10cSrcweir 		{ _xIndexContainer->insertByIndex( Index, Element ); }
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir     virtual void SAL_CALL replaceByIndex( sal_Int32 Index, const Any& Element )
217*cdf0e10cSrcweir 		throw( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
218*cdf0e10cSrcweir 		{ _xIndexContainer->replaceByIndex( Index, Element ); }
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir     virtual void SAL_CALL removeByIndex( sal_Int32 Index )
221*cdf0e10cSrcweir 		throw( IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
222*cdf0e10cSrcweir 		{ _xIndexContainer->removeByIndex( Index ); }
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir 	// XIndexAccess
225*cdf0e10cSrcweir     virtual sal_Int32 SAL_CALL getCount(void) throw( RuntimeException )
226*cdf0e10cSrcweir 		{ return _xIndexAccess->getCount(); }
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir     virtual Any SAL_CALL getByIndex( sal_Int32 Index )
229*cdf0e10cSrcweir 		throw( IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
230*cdf0e10cSrcweir 		{ return _xIndexAccess->getByIndex( Index ); }
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir 	// XEnumerationAccess
233*cdf0e10cSrcweir     virtual Reference<XEnumeration> SAL_CALL createEnumeration(void) throw( RuntimeException )
234*cdf0e10cSrcweir 		{ return _xEnumerationAccess->createEnumeration(); }
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir 	// XExactName
237*cdf0e10cSrcweir     virtual OUString SAL_CALL getExactName( const OUString& rApproximateName ) throw( RuntimeException );
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir 	//=====================================================================================================
241*cdf0e10cSrcweir private:
242*cdf0e10cSrcweir 	void getInfoSequenceImpl( Sequence< OUString >* pStringSeq, Sequence< InvocationInfo >* pInfoSeq );
243*cdf0e10cSrcweir 	void fillInfoForNameAccess( InvocationInfo& rInfo, const OUString& aName );
244*cdf0e10cSrcweir 	void fillInfoForProperty( InvocationInfo& rInfo, const Property& rProp );
245*cdf0e10cSrcweir 	void fillInfoForMethod( InvocationInfo& rInfo, const Reference< XIdlMethod > xMethod );
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir 	Reference<XTypeConverter>			xTypeConverter;
248*cdf0e10cSrcweir 	Reference<XIntrospection>			xIntrospection;
249*cdf0e10cSrcweir 	Reference<XIdlReflection>			xCoreReflection;
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir 	Any								_aMaterial;
252*cdf0e10cSrcweir 	// _xDirect and (_xIntrospectionAccess, xPropertySet) are exclusive
253*cdf0e10cSrcweir 	Reference<XInvocation>				_xDirect;
254*cdf0e10cSrcweir 	Reference<XInvocation2>				_xDirect2;
255*cdf0e10cSrcweir 	Reference<XPropertySet>				_xPropertySet;
256*cdf0e10cSrcweir 	Reference<XIntrospectionAccess>		_xIntrospectionAccess;
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir 	// supplied Interfaces
259*cdf0e10cSrcweir 	Reference<XNameContainer>			_xNameContainer;
260*cdf0e10cSrcweir 	Reference<XNameAccess>				_xNameAccess;
261*cdf0e10cSrcweir 	Reference<XIndexContainer>			_xIndexContainer;
262*cdf0e10cSrcweir 	Reference<XIndexAccess>				_xIndexAccess;
263*cdf0e10cSrcweir 	Reference<XEnumerationAccess>		_xEnumerationAccess;
264*cdf0e10cSrcweir 	Reference<XElementAccess>			_xElementAccess;
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir 	//
267*cdf0e10cSrcweir 	Reference<XExactName>				_xENDirect, _xENIntrospection, _xENNameAccess;
268*cdf0e10cSrcweir };
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir //==================================================================================================
272*cdf0e10cSrcweir //==================================================================================================
273*cdf0e10cSrcweir //==================================================================================================
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
276*cdf0e10cSrcweir Invocation_Impl::Invocation_Impl
277*cdf0e10cSrcweir (
278*cdf0e10cSrcweir 	const Any & rAdapted,
279*cdf0e10cSrcweir 	const Reference<XTypeConverter> & rTC,
280*cdf0e10cSrcweir 	const Reference<XIntrospection>	& rI,
281*cdf0e10cSrcweir 	const Reference<XIdlReflection> & rCR
282*cdf0e10cSrcweir )
283*cdf0e10cSrcweir 	: xTypeConverter( rTC )
284*cdf0e10cSrcweir 	, xIntrospection( rI )
285*cdf0e10cSrcweir 	, xCoreReflection( rCR )
286*cdf0e10cSrcweir {
287*cdf0e10cSrcweir 	g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
288*cdf0e10cSrcweir 	setMaterial( rAdapted );
289*cdf0e10cSrcweir }
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir Invocation_Impl::~Invocation_Impl()
292*cdf0e10cSrcweir {
293*cdf0e10cSrcweir 	g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
294*cdf0e10cSrcweir }
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir //##################################################################################################
297*cdf0e10cSrcweir //### INTERFACE IMPLEMENTATIONS ####################################################################
298*cdf0e10cSrcweir //##################################################################################################
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir Any SAL_CALL Invocation_Impl::queryInterface( const Type & aType )
302*cdf0e10cSrcweir 	throw( RuntimeException )
303*cdf0e10cSrcweir {
304*cdf0e10cSrcweir 	// PropertySet-Implementation
305*cdf0e10cSrcweir 	Any a = ::cppu::queryInterface( aType,
306*cdf0e10cSrcweir 								   SAL_STATIC_CAST(XInvocation*, this),
307*cdf0e10cSrcweir 								   SAL_STATIC_CAST(XMaterialHolder*, this),
308*cdf0e10cSrcweir 								   SAL_STATIC_CAST(XTypeProvider *,this)	);
309*cdf0e10cSrcweir 	if( a.hasValue() )
310*cdf0e10cSrcweir 	{
311*cdf0e10cSrcweir 		return a;
312*cdf0e10cSrcweir 	}
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir 	if( aType  == getCppuType( (Reference<XExactName>*) NULL ) )
315*cdf0e10cSrcweir 	{
316*cdf0e10cSrcweir 		// Ivocation does not support XExactName, if direct object supports
317*cdf0e10cSrcweir 		// XInvocation, but not XExactName.
318*cdf0e10cSrcweir 		if ((_xDirect.is() && _xENDirect.is()) ||
319*cdf0e10cSrcweir 			(!_xDirect.is() && (_xENIntrospection.is() || _xENNameAccess.is())))
320*cdf0e10cSrcweir 		{
321*cdf0e10cSrcweir 			return makeAny( Reference< XExactName >( SAL_STATIC_CAST(XExactName*, this) ) );
322*cdf0e10cSrcweir 		}
323*cdf0e10cSrcweir 	}
324*cdf0e10cSrcweir 	else if ( aType == getCppuType( (Reference<XNameContainer>*) NULL ) )
325*cdf0e10cSrcweir 	{
326*cdf0e10cSrcweir 		if( _xNameContainer.is() )
327*cdf0e10cSrcweir 			return makeAny( Reference< XNameContainer >( SAL_STATIC_CAST(XNameContainer*, this) ) );
328*cdf0e10cSrcweir 	}
329*cdf0e10cSrcweir 	else if ( aType == getCppuType( (Reference<XNameAccess>*) NULL ) )
330*cdf0e10cSrcweir 	{
331*cdf0e10cSrcweir 		if( _xNameAccess.is() )
332*cdf0e10cSrcweir 			return makeAny( Reference< XNameAccess >( SAL_STATIC_CAST(XNameAccess*, this) ) );
333*cdf0e10cSrcweir 	}
334*cdf0e10cSrcweir 	else if ( aType == getCppuType( (Reference<XIndexContainer>*) NULL ) )
335*cdf0e10cSrcweir 	{
336*cdf0e10cSrcweir 		if (_xIndexContainer.is())
337*cdf0e10cSrcweir 			return makeAny( Reference< XIndexContainer >( SAL_STATIC_CAST(XIndexContainer*, this) ) );
338*cdf0e10cSrcweir 	}
339*cdf0e10cSrcweir 	else if ( aType == getCppuType( (Reference<XIndexAccess>*) NULL ) )
340*cdf0e10cSrcweir 	{
341*cdf0e10cSrcweir 		if (_xIndexAccess.is())
342*cdf0e10cSrcweir 			return makeAny( Reference< XIndexAccess >( SAL_STATIC_CAST(XIndexAccess*, this) ) );
343*cdf0e10cSrcweir 	}
344*cdf0e10cSrcweir 	else if ( aType == getCppuType( (Reference<XEnumerationAccess>*) NULL ) )
345*cdf0e10cSrcweir 	{
346*cdf0e10cSrcweir 		if (_xEnumerationAccess.is())
347*cdf0e10cSrcweir 			return makeAny( Reference< XEnumerationAccess >( SAL_STATIC_CAST(XEnumerationAccess*, this) ) );
348*cdf0e10cSrcweir 	}
349*cdf0e10cSrcweir 	else if ( aType == getCppuType( (Reference<XElementAccess>*) NULL ) )
350*cdf0e10cSrcweir 	{
351*cdf0e10cSrcweir 		if (_xElementAccess.is())
352*cdf0e10cSrcweir 		{
353*cdf0e10cSrcweir 			return makeAny( Reference< XElementAccess >(
354*cdf0e10cSrcweir 				SAL_STATIC_CAST(XElementAccess*, SAL_STATIC_CAST(XNameContainer*, this) ) ) );
355*cdf0e10cSrcweir 		}
356*cdf0e10cSrcweir 	}
357*cdf0e10cSrcweir 	else if ( aType == getCppuType( (Reference<XInvocation2>*) NULL ) )
358*cdf0e10cSrcweir 	{
359*cdf0e10cSrcweir 		// Invocation does not support XInvocation2, if direct object supports
360*cdf0e10cSrcweir 		// XInvocation, but not XInvocation2.
361*cdf0e10cSrcweir 		if ( ( _xDirect.is() && _xDirect2.is()) ||
362*cdf0e10cSrcweir 			 (!_xDirect.is() && _xIntrospectionAccess.is() ) )
363*cdf0e10cSrcweir 		{
364*cdf0e10cSrcweir 			return makeAny( Reference< XInvocation2 >( SAL_STATIC_CAST(XInvocation2*, this) ) );
365*cdf0e10cSrcweir 		}
366*cdf0e10cSrcweir 	}
367*cdf0e10cSrcweir 
368*cdf0e10cSrcweir 	return OWeakObject::queryInterface( aType );
369*cdf0e10cSrcweir }
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
373*cdf0e10cSrcweir Any Invocation_Impl::getMaterial(void) throw(RuntimeException)
374*cdf0e10cSrcweir {
375*cdf0e10cSrcweir 	// AB, 12.2.1999  Sicherstellen, dass das Material wenn moeglich
376*cdf0e10cSrcweir 	// aus der direkten Invocation bzw. von der Introspection geholt
377*cdf0e10cSrcweir 	// wird, da sonst Structs nicht korrekt behandelt werden
378*cdf0e10cSrcweir 	Reference<XMaterialHolder> xMaterialHolder;
379*cdf0e10cSrcweir 	if( _xDirect.is() )
380*cdf0e10cSrcweir 	{
381*cdf0e10cSrcweir 		xMaterialHolder = Reference<XMaterialHolder>::query( _xDirect );
382*cdf0e10cSrcweir 		//_xDirect->queryInterface( XMaterialHolder::getSmartUik(), xMaterialHolder );
383*cdf0e10cSrcweir 	}
384*cdf0e10cSrcweir 	else if( _xIntrospectionAccess.is() )
385*cdf0e10cSrcweir 	{
386*cdf0e10cSrcweir 		xMaterialHolder = Reference<XMaterialHolder>::query( _xIntrospectionAccess );
387*cdf0e10cSrcweir 		//_xIntrospectionAccess->queryInterface( XMaterialHolder::getSmartUik(), xMaterialHolder );
388*cdf0e10cSrcweir 	}
389*cdf0e10cSrcweir 	if( xMaterialHolder.is() )
390*cdf0e10cSrcweir 	{
391*cdf0e10cSrcweir 		return xMaterialHolder->getMaterial();
392*cdf0e10cSrcweir 	}
393*cdf0e10cSrcweir 	return _aMaterial;
394*cdf0e10cSrcweir }
395*cdf0e10cSrcweir 
396*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
397*cdf0e10cSrcweir void Invocation_Impl::setMaterial( const Any& rMaterial )
398*cdf0e10cSrcweir {
399*cdf0e10cSrcweir 	// set the material first and only once
400*cdf0e10cSrcweir 	Reference<XInterface> xObj;
401*cdf0e10cSrcweir 
402*cdf0e10cSrcweir 	if (rMaterial.getValueType().getTypeClass() == TypeClass_INTERFACE)
403*cdf0e10cSrcweir 		xObj = *(Reference<XInterface>*)rMaterial.getValue();
404*cdf0e10cSrcweir 	_aMaterial = rMaterial;
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir 	// Ersteinmal alles ausserhalb des guards machen
407*cdf0e10cSrcweir 	_xDirect = Reference<XInvocation>::query( xObj );
408*cdf0e10cSrcweir 
409*cdf0e10cSrcweir 	if( _xDirect.is() )
410*cdf0e10cSrcweir 	{
411*cdf0e10cSrcweir 		// Objekt direkt befragen
412*cdf0e10cSrcweir 		_xElementAccess		= Reference<XElementAccess>::query( _xDirect );
413*cdf0e10cSrcweir 		_xEnumerationAccess = Reference<XEnumerationAccess>::query( _xDirect );
414*cdf0e10cSrcweir 		_xIndexAccess		= Reference<XIndexAccess>::query( _xDirect );
415*cdf0e10cSrcweir 		_xIndexContainer	= Reference<XIndexContainer>::query( _xDirect );
416*cdf0e10cSrcweir 		_xNameAccess		= Reference<XNameAccess>::query( _xDirect );
417*cdf0e10cSrcweir 		_xNameContainer		= Reference<XNameContainer>::query( _xDirect );
418*cdf0e10cSrcweir 		_xENDirect			= Reference<XExactName>::query( _xDirect );
419*cdf0e10cSrcweir 		_xDirect2			= Reference<XInvocation2>::query( _xDirect );
420*cdf0e10cSrcweir 
421*cdf0e10cSrcweir 		// only once!!!
422*cdf0e10cSrcweir 		//_xIntrospectionAccess = XIntrospectionAccessRef();
423*cdf0e10cSrcweir 		//_xPropertySet			= XPropertySetRef();
424*cdf0e10cSrcweir 	}
425*cdf0e10cSrcweir 	else
426*cdf0e10cSrcweir 	{
427*cdf0e10cSrcweir 		// Invocation ueber die Introspection machen
428*cdf0e10cSrcweir 		if (xIntrospection.is())
429*cdf0e10cSrcweir 		{
430*cdf0e10cSrcweir 			_xIntrospectionAccess = xIntrospection->inspect( _aMaterial );
431*cdf0e10cSrcweir 			if( _xIntrospectionAccess.is() )
432*cdf0e10cSrcweir 			{
433*cdf0e10cSrcweir 
434*cdf0e10cSrcweir 				_xElementAccess = Reference<XElementAccess>::query(
435*cdf0e10cSrcweir 					  _xIntrospectionAccess->queryAdapter(
436*cdf0e10cSrcweir 						 	    getCppuType( (Reference<XElementAccess>*) NULL ) ) );
437*cdf0e10cSrcweir 
438*cdf0e10cSrcweir 				_xEnumerationAccess = Reference<XEnumerationAccess>::query(
439*cdf0e10cSrcweir 						   _xIntrospectionAccess->queryAdapter(
440*cdf0e10cSrcweir 								getCppuType( (Reference<XEnumerationAccess>*) NULL )) );
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir 				_xIndexAccess = Reference<XIndexAccess>::query(
443*cdf0e10cSrcweir 					   _xIntrospectionAccess->queryAdapter(
444*cdf0e10cSrcweir 							    getCppuType( (Reference<XIndexAccess>*) NULL ) ) );
445*cdf0e10cSrcweir 
446*cdf0e10cSrcweir 				_xIndexContainer = Reference<XIndexContainer>::query(
447*cdf0e10cSrcweir 					 _xIntrospectionAccess->queryAdapter(
448*cdf0e10cSrcweir 								getCppuType( (Reference<XIndexContainer>*) NULL ) ) );
449*cdf0e10cSrcweir 
450*cdf0e10cSrcweir 				_xNameAccess = Reference<XNameAccess>::query(
451*cdf0e10cSrcweir 					 _xIntrospectionAccess->queryAdapter(
452*cdf0e10cSrcweir 								getCppuType( (Reference<XNameAccess>*) NULL ) ) );
453*cdf0e10cSrcweir 
454*cdf0e10cSrcweir 				_xNameContainer = Reference<XNameContainer>::query(
455*cdf0e10cSrcweir 						   _xIntrospectionAccess->queryAdapter(
456*cdf0e10cSrcweir 							   getCppuType( (Reference<XNameContainer>*) NULL ) ) );
457*cdf0e10cSrcweir 
458*cdf0e10cSrcweir 				_xPropertySet = Reference<XPropertySet>::query(
459*cdf0e10cSrcweir 						   _xIntrospectionAccess->queryAdapter(
460*cdf0e10cSrcweir                                getCppuType( (Reference<XPropertySet>*) NULL )) );
461*cdf0e10cSrcweir 
462*cdf0e10cSrcweir 				_xENIntrospection = Reference<XExactName>::query( _xIntrospectionAccess );
463*cdf0e10cSrcweir 				if (_xNameAccess.is())
464*cdf0e10cSrcweir 					_xENNameAccess = Reference<XExactName>::query( _xNameAccess );
465*cdf0e10cSrcweir 			}
466*cdf0e10cSrcweir 		}
467*cdf0e10cSrcweir 		/* only once !!!
468*cdf0e10cSrcweir 		_xDirect = XInvocationRef();
469*cdf0e10cSrcweir 		if( !_xIntrospectionAccess.is() )
470*cdf0e10cSrcweir 		{
471*cdf0e10cSrcweir 			// reset
472*cdf0e10cSrcweir 			_xElementAccess		= XElementAccessRef();
473*cdf0e10cSrcweir 			_xEnumerationAccess = XEnumerationAccessRef();
474*cdf0e10cSrcweir 			_xIndexAccess		= XIndexAccessRef();
475*cdf0e10cSrcweir 			_xIndexContainer	= XIndexContainerRef();
476*cdf0e10cSrcweir 			_xNameAccess		= XNameAccessRef();
477*cdf0e10cSrcweir 			_xNameContainer		= XNameContainerRef();
478*cdf0e10cSrcweir 			_xPropertySet		= XPropertySetRef();
479*cdf0e10cSrcweir 		}
480*cdf0e10cSrcweir 		*/
481*cdf0e10cSrcweir 	}
482*cdf0e10cSrcweir }
483*cdf0e10cSrcweir 
484*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
485*cdf0e10cSrcweir OUString Invocation_Impl::getExactName( const OUString& rApproximateName )
486*cdf0e10cSrcweir 	throw( RuntimeException )
487*cdf0e10cSrcweir {
488*cdf0e10cSrcweir 	if (_xENDirect.is())
489*cdf0e10cSrcweir 		return _xENDirect->getExactName( rApproximateName );
490*cdf0e10cSrcweir 
491*cdf0e10cSrcweir 	OUString aRet;
492*cdf0e10cSrcweir 	if (_xENIntrospection.is())
493*cdf0e10cSrcweir 		aRet = _xENIntrospection->getExactName( rApproximateName );
494*cdf0e10cSrcweir 	if (!aRet.getLength() && _xENNameAccess.is())
495*cdf0e10cSrcweir 		aRet = _xENNameAccess->getExactName( rApproximateName );
496*cdf0e10cSrcweir 	return aRet;
497*cdf0e10cSrcweir }
498*cdf0e10cSrcweir 
499*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
500*cdf0e10cSrcweir Reference<XIntrospectionAccess>	Invocation_Impl::getIntrospection(void)
501*cdf0e10cSrcweir 	throw( RuntimeException )
502*cdf0e10cSrcweir {
503*cdf0e10cSrcweir 	if( _xDirect.is() )
504*cdf0e10cSrcweir 		return _xDirect->getIntrospection();
505*cdf0e10cSrcweir 	else
506*cdf0e10cSrcweir 		return _xIntrospectionAccess;
507*cdf0e10cSrcweir }
508*cdf0e10cSrcweir 
509*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
510*cdf0e10cSrcweir sal_Bool Invocation_Impl::hasMethod( const OUString& Name )
511*cdf0e10cSrcweir 	throw( RuntimeException )
512*cdf0e10cSrcweir {
513*cdf0e10cSrcweir 	if (_xDirect.is())
514*cdf0e10cSrcweir 		return _xDirect->hasMethod( Name );
515*cdf0e10cSrcweir 	if( _xIntrospectionAccess.is() )
516*cdf0e10cSrcweir 		return _xIntrospectionAccess->hasMethod( Name, MethodConcept::ALL ^ MethodConcept::DANGEROUS );
517*cdf0e10cSrcweir 	return sal_False;
518*cdf0e10cSrcweir }
519*cdf0e10cSrcweir 
520*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
521*cdf0e10cSrcweir sal_Bool Invocation_Impl::hasProperty( const OUString& Name )
522*cdf0e10cSrcweir 	throw( RuntimeException )
523*cdf0e10cSrcweir {
524*cdf0e10cSrcweir 	if (_xDirect.is())
525*cdf0e10cSrcweir 		return _xDirect->hasProperty( Name );
526*cdf0e10cSrcweir 	// PropertySet
527*cdf0e10cSrcweir 	if( _xIntrospectionAccess.is()
528*cdf0e10cSrcweir 		&& _xIntrospectionAccess->hasProperty( Name, PropertyConcept::ALL ^ PropertyConcept::DANGEROUS ) )
529*cdf0e10cSrcweir 		return sal_True;
530*cdf0e10cSrcweir 	// NameAccess
531*cdf0e10cSrcweir 	if( _xNameAccess.is() )
532*cdf0e10cSrcweir 		return _xNameAccess->hasByName( Name );
533*cdf0e10cSrcweir 	return sal_False;
534*cdf0e10cSrcweir }
535*cdf0e10cSrcweir 
536*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
537*cdf0e10cSrcweir Any Invocation_Impl::getValue( const OUString& PropertyName )
538*cdf0e10cSrcweir 	throw( UnknownPropertyException, RuntimeException )
539*cdf0e10cSrcweir {
540*cdf0e10cSrcweir     if (_xDirect.is())
541*cdf0e10cSrcweir         return _xDirect->getValue( PropertyName );
542*cdf0e10cSrcweir     try
543*cdf0e10cSrcweir     {
544*cdf0e10cSrcweir         // PropertySet
545*cdf0e10cSrcweir         if( _xIntrospectionAccess.is() && _xPropertySet.is()
546*cdf0e10cSrcweir             && _xIntrospectionAccess->hasProperty
547*cdf0e10cSrcweir             ( PropertyName, PropertyConcept::ALL ^ PropertyConcept::DANGEROUS ) )
548*cdf0e10cSrcweir         {
549*cdf0e10cSrcweir             return _xPropertySet->getPropertyValue( PropertyName );
550*cdf0e10cSrcweir         }
551*cdf0e10cSrcweir         // NameAccess
552*cdf0e10cSrcweir         if( _xNameAccess.is() && _xNameAccess->hasByName( PropertyName ) )
553*cdf0e10cSrcweir             return _xNameAccess->getByName( PropertyName );
554*cdf0e10cSrcweir     }
555*cdf0e10cSrcweir     catch (UnknownPropertyException &)
556*cdf0e10cSrcweir     {
557*cdf0e10cSrcweir         throw;
558*cdf0e10cSrcweir     }
559*cdf0e10cSrcweir     catch (RuntimeException &)
560*cdf0e10cSrcweir     {
561*cdf0e10cSrcweir         throw;
562*cdf0e10cSrcweir     }
563*cdf0e10cSrcweir     catch (Exception &)
564*cdf0e10cSrcweir     {
565*cdf0e10cSrcweir     }
566*cdf0e10cSrcweir 
567*cdf0e10cSrcweir 	throw UnknownPropertyException(
568*cdf0e10cSrcweir         OUString( RTL_CONSTASCII_USTRINGPARAM("cannot get value ") ) + PropertyName,
569*cdf0e10cSrcweir         Reference< XInterface >() );
570*cdf0e10cSrcweir }
571*cdf0e10cSrcweir 
572*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
573*cdf0e10cSrcweir void Invocation_Impl::setValue( const OUString& PropertyName, const Any& Value )
574*cdf0e10cSrcweir 	throw( UnknownPropertyException, CannotConvertException, InvocationTargetException, RuntimeException )
575*cdf0e10cSrcweir {
576*cdf0e10cSrcweir 	if (_xDirect.is())
577*cdf0e10cSrcweir 		_xDirect->setValue( PropertyName, Value );
578*cdf0e10cSrcweir 	else
579*cdf0e10cSrcweir 	{
580*cdf0e10cSrcweir         try
581*cdf0e10cSrcweir         {
582*cdf0e10cSrcweir             // Properties
583*cdf0e10cSrcweir             if( _xIntrospectionAccess.is() && _xPropertySet.is()
584*cdf0e10cSrcweir                 && _xIntrospectionAccess->hasProperty(
585*cdf0e10cSrcweir                     PropertyName, PropertyConcept::ALL ^ PropertyConcept::DANGEROUS ) )
586*cdf0e10cSrcweir             {
587*cdf0e10cSrcweir                 Property aProp = _xIntrospectionAccess->getProperty(
588*cdf0e10cSrcweir                     PropertyName, PropertyConcept::ALL ^ PropertyConcept::DANGEROUS );
589*cdf0e10cSrcweir                 Reference < XIdlClass > r = TypeToIdlClass( aProp.Type, xCoreReflection );
590*cdf0e10cSrcweir                 if( r->isAssignableFrom( TypeToIdlClass( Value.getValueType(), xCoreReflection ) ) )
591*cdf0e10cSrcweir                     _xPropertySet->setPropertyValue( PropertyName, Value );
592*cdf0e10cSrcweir                 else if( xTypeConverter.is() )
593*cdf0e10cSrcweir                     _xPropertySet->setPropertyValue(
594*cdf0e10cSrcweir                         PropertyName, xTypeConverter->convertTo( Value, aProp.Type ) );
595*cdf0e10cSrcweir                 else
596*cdf0e10cSrcweir                     throw RuntimeException(
597*cdf0e10cSrcweir                         OUString( RTL_CONSTASCII_USTRINGPARAM("no type converter service!") ),
598*cdf0e10cSrcweir                         Reference< XInterface >() );
599*cdf0e10cSrcweir             }
600*cdf0e10cSrcweir             // NameContainer
601*cdf0e10cSrcweir             else if( _xNameContainer.is() )
602*cdf0e10cSrcweir             {
603*cdf0e10cSrcweir                 Any aConv;
604*cdf0e10cSrcweir                 Reference < XIdlClass > r =
605*cdf0e10cSrcweir                     TypeToIdlClass( _xNameContainer->getElementType(), xCoreReflection );
606*cdf0e10cSrcweir                 if( r->isAssignableFrom(TypeToIdlClass( Value.getValueType(), xCoreReflection ) ) )
607*cdf0e10cSrcweir                     aConv = Value;
608*cdf0e10cSrcweir                 else if( xTypeConverter.is() )
609*cdf0e10cSrcweir                     aConv = xTypeConverter->convertTo( Value, _xNameContainer->getElementType() );
610*cdf0e10cSrcweir                 else
611*cdf0e10cSrcweir                     throw RuntimeException(
612*cdf0e10cSrcweir                         OUString( RTL_CONSTASCII_USTRINGPARAM("no type converter service!") ),
613*cdf0e10cSrcweir                         Reference< XInterface >() );
614*cdf0e10cSrcweir 
615*cdf0e10cSrcweir                 // bei Vorhandensein ersetzen, ansonsten einfuegen
616*cdf0e10cSrcweir                 if (_xNameContainer->hasByName( PropertyName ))
617*cdf0e10cSrcweir                     _xNameContainer->replaceByName( PropertyName, aConv );
618*cdf0e10cSrcweir                 else
619*cdf0e10cSrcweir                     _xNameContainer->insertByName( PropertyName, aConv );
620*cdf0e10cSrcweir             }
621*cdf0e10cSrcweir             else
622*cdf0e10cSrcweir                 throw UnknownPropertyException(
623*cdf0e10cSrcweir                     OUString( RTL_CONSTASCII_USTRINGPARAM("no introspection nor name container!") ),
624*cdf0e10cSrcweir                     Reference< XInterface >() );
625*cdf0e10cSrcweir         }
626*cdf0e10cSrcweir         catch (UnknownPropertyException &)
627*cdf0e10cSrcweir         {
628*cdf0e10cSrcweir             throw;
629*cdf0e10cSrcweir         }
630*cdf0e10cSrcweir         catch (CannotConvertException &)
631*cdf0e10cSrcweir         {
632*cdf0e10cSrcweir             throw;
633*cdf0e10cSrcweir         }
634*cdf0e10cSrcweir         catch (InvocationTargetException &)
635*cdf0e10cSrcweir         {
636*cdf0e10cSrcweir             throw;
637*cdf0e10cSrcweir         }
638*cdf0e10cSrcweir         catch (RuntimeException &)
639*cdf0e10cSrcweir         {
640*cdf0e10cSrcweir             throw;
641*cdf0e10cSrcweir         }
642*cdf0e10cSrcweir         catch (Exception & exc)
643*cdf0e10cSrcweir         {
644*cdf0e10cSrcweir             throw InvocationTargetException(
645*cdf0e10cSrcweir                 OUString( RTL_CONSTASCII_USTRINGPARAM("exception occured in setValue(): ") ) +
646*cdf0e10cSrcweir                 exc.Message, Reference< XInterface >(), makeAny( exc /* though sliced */ ) );
647*cdf0e10cSrcweir         }
648*cdf0e10cSrcweir 	}
649*cdf0e10cSrcweir }
650*cdf0e10cSrcweir 
651*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
652*cdf0e10cSrcweir Any Invocation_Impl::invoke( const OUString& FunctionName, const Sequence<Any>& InParams,
653*cdf0e10cSrcweir 								Sequence<sal_Int16>& OutIndizes, Sequence<Any>& OutParams )
654*cdf0e10cSrcweir 	throw( IllegalArgumentException, CannotConvertException, InvocationTargetException, RuntimeException )
655*cdf0e10cSrcweir {
656*cdf0e10cSrcweir 	if (_xDirect.is())
657*cdf0e10cSrcweir 		return _xDirect->invoke( FunctionName, InParams, OutIndizes, OutParams );
658*cdf0e10cSrcweir 
659*cdf0e10cSrcweir 	if (_xIntrospectionAccess.is())
660*cdf0e10cSrcweir 	{
661*cdf0e10cSrcweir 		// throw NoSuchMethodException if not exist
662*cdf0e10cSrcweir 		Reference<XIdlMethod> xMethod = _xIntrospectionAccess->getMethod(
663*cdf0e10cSrcweir 			FunctionName, MethodConcept::ALL ^ MethodConcept::DANGEROUS );
664*cdf0e10cSrcweir 
665*cdf0e10cSrcweir 		// ParameterInfos
666*cdf0e10cSrcweir 		Sequence<ParamInfo> aFParams		= xMethod->getParameterInfos();
667*cdf0e10cSrcweir 		const ParamInfo* pFParams			= aFParams.getConstArray();
668*cdf0e10cSrcweir 		sal_Int32 nFParamsLen				= aFParams.getLength();
669*cdf0e10cSrcweir 		if (nFParamsLen != InParams.getLength())
670*cdf0e10cSrcweir         {
671*cdf0e10cSrcweir             throw IllegalArgumentException(
672*cdf0e10cSrcweir                 OUString( RTL_CONSTASCII_USTRINGPARAM("incorrect number of parameters passed invoking function ") ) + FunctionName,
673*cdf0e10cSrcweir                 (OWeakObject *) this, (sal_Int16) 1 );
674*cdf0e10cSrcweir         }
675*cdf0e10cSrcweir 
676*cdf0e10cSrcweir 		// IN Parameter
677*cdf0e10cSrcweir 		const Any* pInParams				= InParams.getConstArray();
678*cdf0e10cSrcweir 
679*cdf0e10cSrcweir 		// Introspection Invoke Parameter
680*cdf0e10cSrcweir 		Sequence<Any> aInvokeParams( nFParamsLen );
681*cdf0e10cSrcweir 		Any* pInvokeParams					= aInvokeParams.getArray();
682*cdf0e10cSrcweir 
683*cdf0e10cSrcweir 		// OUT Indizes
684*cdf0e10cSrcweir 		OutIndizes.realloc( nFParamsLen );
685*cdf0e10cSrcweir 		sal_Int16* pOutIndizes				= OutIndizes.getArray();
686*cdf0e10cSrcweir 		sal_uInt32 nOutIndex				= 0;
687*cdf0e10cSrcweir 
688*cdf0e10cSrcweir         for ( sal_Int32 nPos = 0; nPos < nFParamsLen; ++nPos )
689*cdf0e10cSrcweir 		{
690*cdf0e10cSrcweir             try
691*cdf0e10cSrcweir 			{
692*cdf0e10cSrcweir 				const ParamInfo& rFParam = pFParams[nPos];
693*cdf0e10cSrcweir 				const Reference<XIdlClass>& rDestType = rFParam.aType;
694*cdf0e10cSrcweir 
695*cdf0e10cSrcweir 				// is IN/INOUT parameter?
696*cdf0e10cSrcweir 				if (rFParam.aMode != ParamMode_OUT)
697*cdf0e10cSrcweir 				{
698*cdf0e10cSrcweir 					if (rDestType->isAssignableFrom( TypeToIdlClass( pInParams[nPos].getValueType(), xCoreReflection ) ))
699*cdf0e10cSrcweir 					{
700*cdf0e10cSrcweir 						pInvokeParams[nPos]	= pInParams[nPos];
701*cdf0e10cSrcweir 					}
702*cdf0e10cSrcweir 					else if (xTypeConverter.is())
703*cdf0e10cSrcweir 					{
704*cdf0e10cSrcweir 						Type aDestType( rDestType->getTypeClass(), rDestType->getName() );
705*cdf0e10cSrcweir 						pInvokeParams[nPos]	= xTypeConverter->convertTo( pInParams[nPos], aDestType );
706*cdf0e10cSrcweir 					}
707*cdf0e10cSrcweir 					else
708*cdf0e10cSrcweir 					{
709*cdf0e10cSrcweir 						CannotConvertException aExc;
710*cdf0e10cSrcweir 						aExc.Context = *this;
711*cdf0e10cSrcweir 						aExc.Message = OUString( RTL_CONSTASCII_USTRINGPARAM("invocation type mismatch!") );
712*cdf0e10cSrcweir 						throw aExc;
713*cdf0e10cSrcweir 					}
714*cdf0e10cSrcweir 				}
715*cdf0e10cSrcweir 
716*cdf0e10cSrcweir 				// is OUT/INOUT parameter?
717*cdf0e10cSrcweir 				if (rFParam.aMode != ParamMode_IN)
718*cdf0e10cSrcweir 				{
719*cdf0e10cSrcweir 					pOutIndizes[nOutIndex] = (sal_Int16)nPos;
720*cdf0e10cSrcweir 					if (rFParam.aMode == ParamMode_OUT)
721*cdf0e10cSrcweir 						rDestType->createObject( pInvokeParams[nPos] );		// default init
722*cdf0e10cSrcweir 					++nOutIndex;
723*cdf0e10cSrcweir 				}
724*cdf0e10cSrcweir 			}
725*cdf0e10cSrcweir             catch( CannotConvertException& rExc )
726*cdf0e10cSrcweir             {
727*cdf0e10cSrcweir                 rExc.ArgumentIndex = nPos;	// optionalen Parameter Index hinzufuegen
728*cdf0e10cSrcweir                 throw rExc;
729*cdf0e10cSrcweir             }
730*cdf0e10cSrcweir 		}
731*cdf0e10cSrcweir 
732*cdf0e10cSrcweir         // execute Method
733*cdf0e10cSrcweir         Any aRet = xMethod->invoke( _aMaterial, aInvokeParams );
734*cdf0e10cSrcweir 
735*cdf0e10cSrcweir         // OUT Params
736*cdf0e10cSrcweir         OutIndizes.realloc( nOutIndex );
737*cdf0e10cSrcweir         pOutIndizes		   = OutIndizes.getArray();
738*cdf0e10cSrcweir         OutParams.realloc( nOutIndex );
739*cdf0e10cSrcweir         Any* pOutParams = OutParams.getArray();
740*cdf0e10cSrcweir 
741*cdf0e10cSrcweir         while (nOutIndex--)
742*cdf0e10cSrcweir         {
743*cdf0e10cSrcweir             pOutParams[nOutIndex] = pInvokeParams[ pOutIndizes[nOutIndex] ];
744*cdf0e10cSrcweir         }
745*cdf0e10cSrcweir 
746*cdf0e10cSrcweir         return aRet;
747*cdf0e10cSrcweir 	}
748*cdf0e10cSrcweir 
749*cdf0e10cSrcweir 	RuntimeException aExc;
750*cdf0e10cSrcweir 	aExc.Context = *this;
751*cdf0e10cSrcweir 	aExc.Message = OUString( RTL_CONSTASCII_USTRINGPARAM("invocation lacking of introspection access!") );
752*cdf0e10cSrcweir 	throw aExc;
753*cdf0e10cSrcweir }
754*cdf0e10cSrcweir 
755*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
756*cdf0e10cSrcweir 
757*cdf0e10cSrcweir // Struct to optimize sorting
758*cdf0e10cSrcweir struct MemberItem
759*cdf0e10cSrcweir {
760*cdf0e10cSrcweir 	OUString aName;
761*cdf0e10cSrcweir 
762*cdf0e10cSrcweir 	// Defines where the member comes from
763*cdf0e10cSrcweir 	enum Mode { NAMEACCESS, PROPERTYSET, METHOD } eMode;
764*cdf0e10cSrcweir 
765*cdf0e10cSrcweir 	// Index to respective sequence
766*cdf0e10cSrcweir 	// (Index to NameAccess sequence for eMode==NAMEACCESS etc.)
767*cdf0e10cSrcweir 	sal_Int32 nIndex;
768*cdf0e10cSrcweir };
769*cdf0e10cSrcweir 
770*cdf0e10cSrcweir // Implementation of getting name or info
771*cdf0e10cSrcweir // String sequence will be filled when pStringSeq != NULL
772*cdf0e10cSrcweir // Info sequence will be filled when pInfoSeq != NULL
773*cdf0e10cSrcweir void Invocation_Impl::getInfoSequenceImpl
774*cdf0e10cSrcweir (
775*cdf0e10cSrcweir 	Sequence< OUString >* pStringSeq,
776*cdf0e10cSrcweir 	Sequence< InvocationInfo >* pInfoSeq
777*cdf0e10cSrcweir )
778*cdf0e10cSrcweir {
779*cdf0e10cSrcweir 	//Sequence< OUString > aStrSeq;
780*cdf0e10cSrcweir 	//if( !pStringSeq )
781*cdf0e10cSrcweir 		//pStringSeq = &aStrSeq;
782*cdf0e10cSrcweir 
783*cdf0e10cSrcweir 
784*cdf0e10cSrcweir 	// Get all needed sequences
785*cdf0e10cSrcweir 	Sequence<OUString> aNameAccessNames;
786*cdf0e10cSrcweir 	Sequence<Property> aPropertySeq;
787*cdf0e10cSrcweir 	Sequence< Reference< XIdlMethod > > aMethodSeq;
788*cdf0e10cSrcweir 
789*cdf0e10cSrcweir 	if( _xNameAccess.is() )
790*cdf0e10cSrcweir 	{
791*cdf0e10cSrcweir 		aNameAccessNames = _xNameAccess->getElementNames();
792*cdf0e10cSrcweir 	}
793*cdf0e10cSrcweir 
794*cdf0e10cSrcweir 	if( _xIntrospectionAccess.is() )
795*cdf0e10cSrcweir 	{
796*cdf0e10cSrcweir 		aPropertySeq = _xIntrospectionAccess->getProperties
797*cdf0e10cSrcweir 			( PropertyConcept::ALL - PropertyConcept::DANGEROUS );
798*cdf0e10cSrcweir 
799*cdf0e10cSrcweir 		aMethodSeq = _xIntrospectionAccess->getMethods
800*cdf0e10cSrcweir 			( MethodConcept::ALL - MethodConcept::DANGEROUS );
801*cdf0e10cSrcweir 	}
802*cdf0e10cSrcweir 
803*cdf0e10cSrcweir 	sal_Int32 nNameAccessCount = aNameAccessNames.getLength();
804*cdf0e10cSrcweir 	sal_Int32 nPropertyCount = aPropertySeq.getLength();
805*cdf0e10cSrcweir 	sal_Int32 nMethodCount = aMethodSeq.getLength();
806*cdf0e10cSrcweir 	sal_Int32 nTotalCount = nNameAccessCount + nPropertyCount + nMethodCount;
807*cdf0e10cSrcweir 
808*cdf0e10cSrcweir 	// Create and fill array of MemberItems
809*cdf0e10cSrcweir     boost::scoped_array< MemberItem > pItems( new MemberItem[ nTotalCount ] );
810*cdf0e10cSrcweir 	const OUString* pStrings = aNameAccessNames.getConstArray();
811*cdf0e10cSrcweir 	const Property* pProps = aPropertySeq.getConstArray();
812*cdf0e10cSrcweir 	const Reference< XIdlMethod >* pMethods = aMethodSeq.getConstArray();
813*cdf0e10cSrcweir 
814*cdf0e10cSrcweir 	// Fill array of MemberItems
815*cdf0e10cSrcweir 	sal_Int32 i, iTotal = 0;
816*cdf0e10cSrcweir 
817*cdf0e10cSrcweir 	// Name Access
818*cdf0e10cSrcweir 	for( i = 0 ; i < nNameAccessCount ; i++, iTotal++ )
819*cdf0e10cSrcweir 	{
820*cdf0e10cSrcweir 		MemberItem& rItem = pItems[ iTotal ];
821*cdf0e10cSrcweir 		rItem.aName = pStrings[ i ];
822*cdf0e10cSrcweir 		rItem.eMode = MemberItem::NAMEACCESS;
823*cdf0e10cSrcweir 		rItem.nIndex = i;
824*cdf0e10cSrcweir 	}
825*cdf0e10cSrcweir 
826*cdf0e10cSrcweir 	// Property set
827*cdf0e10cSrcweir 	for( i = 0 ; i < nPropertyCount ; i++, iTotal++ )
828*cdf0e10cSrcweir 	{
829*cdf0e10cSrcweir 		MemberItem& rItem = pItems[ iTotal ];
830*cdf0e10cSrcweir 		rItem.aName = pProps[ i ].Name;
831*cdf0e10cSrcweir 		rItem.eMode = MemberItem::PROPERTYSET;
832*cdf0e10cSrcweir 		rItem.nIndex = i;
833*cdf0e10cSrcweir 	}
834*cdf0e10cSrcweir 
835*cdf0e10cSrcweir 	// Methods
836*cdf0e10cSrcweir 	for( i = 0 ; i < nMethodCount ; i++, iTotal++ )
837*cdf0e10cSrcweir 	{
838*cdf0e10cSrcweir 		MemberItem& rItem = pItems[ iTotal ];
839*cdf0e10cSrcweir 		Reference< XIdlMethod > xMethod = pMethods[ i ];
840*cdf0e10cSrcweir 		rItem.aName = xMethod->getName();
841*cdf0e10cSrcweir 		rItem.eMode = MemberItem::METHOD;
842*cdf0e10cSrcweir 		rItem.nIndex = i;
843*cdf0e10cSrcweir 	}
844*cdf0e10cSrcweir 
845*cdf0e10cSrcweir 	// Setting up result sequences
846*cdf0e10cSrcweir 	OUString* pRetStrings = NULL;
847*cdf0e10cSrcweir 	if( pStringSeq )
848*cdf0e10cSrcweir 	{
849*cdf0e10cSrcweir 		pStringSeq->realloc( nTotalCount );
850*cdf0e10cSrcweir 		pRetStrings = pStringSeq->getArray();
851*cdf0e10cSrcweir 	}
852*cdf0e10cSrcweir 
853*cdf0e10cSrcweir 	InvocationInfo* pRetInfos = NULL;
854*cdf0e10cSrcweir 	if( pInfoSeq )
855*cdf0e10cSrcweir 	{
856*cdf0e10cSrcweir 		pInfoSeq->realloc( nTotalCount );
857*cdf0e10cSrcweir 		pRetInfos = pInfoSeq->getArray();
858*cdf0e10cSrcweir 	}
859*cdf0e10cSrcweir 
860*cdf0e10cSrcweir 	// Fill result sequences in the correct order of members
861*cdf0e10cSrcweir 	for( iTotal = 0 ; iTotal < nTotalCount ; iTotal++ )
862*cdf0e10cSrcweir 	{
863*cdf0e10cSrcweir 		MemberItem& rItem = pItems[ iTotal ];
864*cdf0e10cSrcweir 		if( pRetStrings )
865*cdf0e10cSrcweir 		{
866*cdf0e10cSrcweir 			pRetStrings[ iTotal ] = rItem.aName;
867*cdf0e10cSrcweir 		}
868*cdf0e10cSrcweir 
869*cdf0e10cSrcweir 		if( pRetInfos )
870*cdf0e10cSrcweir 		{
871*cdf0e10cSrcweir 			if( rItem.eMode == MemberItem::NAMEACCESS )
872*cdf0e10cSrcweir 			{
873*cdf0e10cSrcweir 				fillInfoForNameAccess( pRetInfos[ iTotal ], rItem.aName );
874*cdf0e10cSrcweir 			}
875*cdf0e10cSrcweir 			else if( rItem.eMode == MemberItem::PROPERTYSET )
876*cdf0e10cSrcweir 			{
877*cdf0e10cSrcweir 				fillInfoForProperty( pRetInfos[ iTotal ], pProps[ rItem.nIndex ] );
878*cdf0e10cSrcweir 			}
879*cdf0e10cSrcweir 			else if( rItem.eMode == MemberItem::METHOD )
880*cdf0e10cSrcweir 			{
881*cdf0e10cSrcweir 				fillInfoForMethod( pRetInfos[ iTotal ], pMethods[ rItem.nIndex ] );
882*cdf0e10cSrcweir 			}
883*cdf0e10cSrcweir 		}
884*cdf0e10cSrcweir 	}
885*cdf0e10cSrcweir }
886*cdf0e10cSrcweir 
887*cdf0e10cSrcweir // XInvocation2
888*cdf0e10cSrcweir Sequence< OUString > SAL_CALL Invocation_Impl::getMemberNames(  )
889*cdf0e10cSrcweir 	throw( RuntimeException )
890*cdf0e10cSrcweir {
891*cdf0e10cSrcweir 	if( _xDirect2.is() )
892*cdf0e10cSrcweir 	{
893*cdf0e10cSrcweir 		return _xDirect2->getMemberNames();
894*cdf0e10cSrcweir 	}
895*cdf0e10cSrcweir 	Sequence< OUString > aRetSeq;
896*cdf0e10cSrcweir 	getInfoSequenceImpl( &aRetSeq, NULL );
897*cdf0e10cSrcweir 	return aRetSeq;
898*cdf0e10cSrcweir }
899*cdf0e10cSrcweir 
900*cdf0e10cSrcweir Sequence< InvocationInfo > SAL_CALL Invocation_Impl::getInfo(  )
901*cdf0e10cSrcweir 	throw( RuntimeException )
902*cdf0e10cSrcweir {
903*cdf0e10cSrcweir 	if( _xDirect2.is() )
904*cdf0e10cSrcweir 	{
905*cdf0e10cSrcweir 		return _xDirect2->getInfo();
906*cdf0e10cSrcweir 	}
907*cdf0e10cSrcweir 	Sequence< InvocationInfo > aRetSeq;
908*cdf0e10cSrcweir 	getInfoSequenceImpl( NULL, &aRetSeq );
909*cdf0e10cSrcweir 	return aRetSeq;
910*cdf0e10cSrcweir }
911*cdf0e10cSrcweir 
912*cdf0e10cSrcweir InvocationInfo SAL_CALL Invocation_Impl::getInfoForName( const OUString& aName, sal_Bool bExact )
913*cdf0e10cSrcweir 	throw( IllegalArgumentException, RuntimeException )
914*cdf0e10cSrcweir {
915*cdf0e10cSrcweir 	if( _xDirect2.is() )
916*cdf0e10cSrcweir 	{
917*cdf0e10cSrcweir 		return _xDirect2->getInfoForName( aName, bExact );
918*cdf0e10cSrcweir 	}
919*cdf0e10cSrcweir 
920*cdf0e10cSrcweir 	sal_Bool bFound = sal_False;
921*cdf0e10cSrcweir 	OUString aExactName = aName;
922*cdf0e10cSrcweir 	InvocationInfo aRetInfo;
923*cdf0e10cSrcweir 
924*cdf0e10cSrcweir 	if( bExact )
925*cdf0e10cSrcweir 		aExactName = getExactName( aName );
926*cdf0e10cSrcweir 	if( aExactName.getLength() > 0 )
927*cdf0e10cSrcweir 	{
928*cdf0e10cSrcweir 		if( _xIntrospectionAccess->hasMethod( aExactName, MethodConcept::ALL ^ MethodConcept::DANGEROUS ) )
929*cdf0e10cSrcweir 		{
930*cdf0e10cSrcweir 			Reference<XIdlMethod> xMethod = _xIntrospectionAccess->getMethod
931*cdf0e10cSrcweir 				( aExactName, MethodConcept::ALL ^ MethodConcept::DANGEROUS );
932*cdf0e10cSrcweir 			fillInfoForMethod( aRetInfo, xMethod );
933*cdf0e10cSrcweir 			bFound = sal_True;
934*cdf0e10cSrcweir 		}
935*cdf0e10cSrcweir 		else
936*cdf0e10cSrcweir 		{
937*cdf0e10cSrcweir 			if( _xIntrospectionAccess.is() && _xIntrospectionAccess->hasProperty
938*cdf0e10cSrcweir 				 ( aExactName, PropertyConcept::ALL ^ PropertyConcept::DANGEROUS ) )
939*cdf0e10cSrcweir 			{
940*cdf0e10cSrcweir  				Property aProp = _xIntrospectionAccess->getProperty
941*cdf0e10cSrcweir 					( aExactName, PropertyConcept::ALL ^ PropertyConcept::DANGEROUS );
942*cdf0e10cSrcweir 				fillInfoForProperty( aRetInfo, aProp );
943*cdf0e10cSrcweir 				bFound = sal_True;
944*cdf0e10cSrcweir 			}
945*cdf0e10cSrcweir 			// NameAccess
946*cdf0e10cSrcweir 			else if( _xNameAccess.is() && _xNameAccess->hasByName( aExactName ) )
947*cdf0e10cSrcweir 			{
948*cdf0e10cSrcweir 				fillInfoForNameAccess( aRetInfo, aExactName );
949*cdf0e10cSrcweir 				bFound = sal_True;
950*cdf0e10cSrcweir 			}
951*cdf0e10cSrcweir 		}
952*cdf0e10cSrcweir 	}
953*cdf0e10cSrcweir 	if( !bFound )
954*cdf0e10cSrcweir 	{
955*cdf0e10cSrcweir 		throw IllegalArgumentException(
956*cdf0e10cSrcweir 			OUString( RTL_CONSTASCII_USTRINGPARAM("Unknown name, getExactName() failed!") ),
957*cdf0e10cSrcweir 			(XWeak *)(OWeakObject *)this, 0 );
958*cdf0e10cSrcweir 	}
959*cdf0e10cSrcweir 	return aRetInfo;
960*cdf0e10cSrcweir }
961*cdf0e10cSrcweir 
962*cdf0e10cSrcweir // Helper functions to fill InvocationInfo for XNameAccess
963*cdf0e10cSrcweir void Invocation_Impl::fillInfoForNameAccess
964*cdf0e10cSrcweir (
965*cdf0e10cSrcweir 	InvocationInfo& rInfo,
966*cdf0e10cSrcweir 	const OUString& aName
967*cdf0e10cSrcweir )
968*cdf0e10cSrcweir {
969*cdf0e10cSrcweir 	rInfo.aName = aName;
970*cdf0e10cSrcweir     rInfo.eMemberType = MemberType_PROPERTY;
971*cdf0e10cSrcweir     rInfo.PropertyAttribute = 0;
972*cdf0e10cSrcweir 	if( !_xNameContainer.is() )
973*cdf0e10cSrcweir 	{
974*cdf0e10cSrcweir 		rInfo.PropertyAttribute = PropertyAttribute::READONLY;
975*cdf0e10cSrcweir 	}
976*cdf0e10cSrcweir     rInfo.aType = _xNameAccess->getElementType();
977*cdf0e10cSrcweir }
978*cdf0e10cSrcweir 
979*cdf0e10cSrcweir void Invocation_Impl::fillInfoForProperty
980*cdf0e10cSrcweir (
981*cdf0e10cSrcweir 	InvocationInfo& rInfo,
982*cdf0e10cSrcweir 	const Property& rProp
983*cdf0e10cSrcweir )
984*cdf0e10cSrcweir {
985*cdf0e10cSrcweir 	rInfo.aName = rProp.Name;
986*cdf0e10cSrcweir     rInfo.eMemberType = MemberType_PROPERTY;
987*cdf0e10cSrcweir     rInfo.PropertyAttribute = rProp.Attributes;
988*cdf0e10cSrcweir     rInfo.aType = rProp.Type;
989*cdf0e10cSrcweir }
990*cdf0e10cSrcweir 
991*cdf0e10cSrcweir void Invocation_Impl::fillInfoForMethod
992*cdf0e10cSrcweir (
993*cdf0e10cSrcweir 	InvocationInfo& rInfo,
994*cdf0e10cSrcweir 	const Reference< XIdlMethod > xMethod
995*cdf0e10cSrcweir )
996*cdf0e10cSrcweir {
997*cdf0e10cSrcweir 	rInfo.aName = xMethod->getName();
998*cdf0e10cSrcweir     rInfo.eMemberType = MemberType_METHOD;
999*cdf0e10cSrcweir 	Reference< XIdlClass > xReturnClass = xMethod->getReturnType();
1000*cdf0e10cSrcweir 	Type aReturnType( xReturnClass->getTypeClass(), xReturnClass->getName() );
1001*cdf0e10cSrcweir     rInfo.aType = aReturnType;
1002*cdf0e10cSrcweir 	Sequence<ParamInfo> aParamInfos = xMethod->getParameterInfos();
1003*cdf0e10cSrcweir 	sal_Int32 nParamCount = aParamInfos.getLength();
1004*cdf0e10cSrcweir 	if( nParamCount > 0 )
1005*cdf0e10cSrcweir 	{
1006*cdf0e10cSrcweir 		const ParamInfo* pInfos = aParamInfos.getConstArray();
1007*cdf0e10cSrcweir 
1008*cdf0e10cSrcweir 		rInfo.aParamTypes.realloc( nParamCount );
1009*cdf0e10cSrcweir 		Type* pParamTypes = rInfo.aParamTypes.getArray();
1010*cdf0e10cSrcweir 		rInfo.aParamModes.realloc( nParamCount );
1011*cdf0e10cSrcweir 		ParamMode* pParamModes = rInfo.aParamModes.getArray();
1012*cdf0e10cSrcweir 
1013*cdf0e10cSrcweir 		for( sal_Int32 i = 0 ; i < nParamCount ; i++ )
1014*cdf0e10cSrcweir 		{
1015*cdf0e10cSrcweir 			Reference< XIdlClass > xParamClass = pInfos[i].aType;
1016*cdf0e10cSrcweir 			Type aParamType( xParamClass->getTypeClass(), xParamClass->getName() );
1017*cdf0e10cSrcweir 			pParamTypes[ i ] = aParamType;
1018*cdf0e10cSrcweir 			pParamModes[ i ] = pInfos[i].aMode;
1019*cdf0e10cSrcweir 		}
1020*cdf0e10cSrcweir 	}
1021*cdf0e10cSrcweir }
1022*cdf0e10cSrcweir 
1023*cdf0e10cSrcweir 
1024*cdf0e10cSrcweir // XTypeProvider
1025*cdf0e10cSrcweir Sequence< Type > SAL_CALL Invocation_Impl::getTypes(void) throw( RuntimeException )
1026*cdf0e10cSrcweir {
1027*cdf0e10cSrcweir     static Sequence< Type > const * s_pTypes = 0;
1028*cdf0e10cSrcweir     if (! s_pTypes)
1029*cdf0e10cSrcweir     {
1030*cdf0e10cSrcweir         Sequence< Type > types( 4 +8 );
1031*cdf0e10cSrcweir         Type * pTypes = types.getArray();
1032*cdf0e10cSrcweir         sal_Int32 n = 0;
1033*cdf0e10cSrcweir 
1034*cdf0e10cSrcweir         pTypes[ n++ ] = ::getCppuType( (Reference< XTypeProvider > const *)0 );
1035*cdf0e10cSrcweir         pTypes[ n++ ] = ::getCppuType( (Reference< XWeak > const *)0 );
1036*cdf0e10cSrcweir         pTypes[ n++ ] = ::getCppuType( (Reference< XInvocation > const *)0 );
1037*cdf0e10cSrcweir         pTypes[ n++ ] = ::getCppuType( (Reference< XMaterialHolder > const *)0 );
1038*cdf0e10cSrcweir 
1039*cdf0e10cSrcweir 		// Ivocation does not support XExactName, if direct object supports
1040*cdf0e10cSrcweir 		// XInvocation, but not XExactName.
1041*cdf0e10cSrcweir 		if ((_xDirect.is() && _xENDirect.is()) ||
1042*cdf0e10cSrcweir 			(!_xDirect.is() && (_xENIntrospection.is() || _xENNameAccess.is())))
1043*cdf0e10cSrcweir 		{
1044*cdf0e10cSrcweir             pTypes[ n++ ] = ::getCppuType( (Reference< XExactName > const *)0 );
1045*cdf0e10cSrcweir 		}
1046*cdf0e10cSrcweir 		if( _xNameContainer.is() )
1047*cdf0e10cSrcweir 		{
1048*cdf0e10cSrcweir             pTypes[ n++ ] = ::getCppuType( (Reference< XNameContainer > const *)0 );
1049*cdf0e10cSrcweir 		}
1050*cdf0e10cSrcweir 		if( _xNameAccess.is() )
1051*cdf0e10cSrcweir 		{
1052*cdf0e10cSrcweir             pTypes[ n++ ] = ::getCppuType( (Reference< XNameAccess > const *)0 );
1053*cdf0e10cSrcweir 		}
1054*cdf0e10cSrcweir 		if (_xIndexContainer.is())
1055*cdf0e10cSrcweir 		{
1056*cdf0e10cSrcweir             pTypes[ n++ ] = ::getCppuType( (Reference< XIndexContainer > const *)0 );
1057*cdf0e10cSrcweir 		}
1058*cdf0e10cSrcweir 		if (_xIndexAccess.is())
1059*cdf0e10cSrcweir 		{
1060*cdf0e10cSrcweir             pTypes[ n++ ] = ::getCppuType( (Reference< XIndexAccess > const *)0 );
1061*cdf0e10cSrcweir 		}
1062*cdf0e10cSrcweir 		if (_xEnumerationAccess.is())
1063*cdf0e10cSrcweir 		{
1064*cdf0e10cSrcweir             pTypes[ n++ ] = ::getCppuType( (Reference< XEnumerationAccess > const *)0 );
1065*cdf0e10cSrcweir 		}
1066*cdf0e10cSrcweir 		if (_xElementAccess.is())
1067*cdf0e10cSrcweir 		{
1068*cdf0e10cSrcweir             pTypes[ n++ ] = ::getCppuType( (Reference< XElementAccess > const *)0 );
1069*cdf0e10cSrcweir 		}
1070*cdf0e10cSrcweir 		// Invocation does not support XInvocation2, if direct object supports
1071*cdf0e10cSrcweir 		// XInvocation, but not XInvocation2.
1072*cdf0e10cSrcweir 		if ( ( _xDirect.is() && _xDirect2.is()) ||
1073*cdf0e10cSrcweir 			 (!_xDirect.is() && _xIntrospectionAccess.is() ) )
1074*cdf0e10cSrcweir 		{
1075*cdf0e10cSrcweir             pTypes[ n++ ] = ::getCppuType( (Reference< XInvocation2 > const *)0 );
1076*cdf0e10cSrcweir 		}
1077*cdf0e10cSrcweir 
1078*cdf0e10cSrcweir         types.realloc( n );
1079*cdf0e10cSrcweir 
1080*cdf0e10cSrcweir         // store types
1081*cdf0e10cSrcweir         MutexGuard guard( Mutex::getGlobalMutex() );
1082*cdf0e10cSrcweir         if (! s_pTypes)
1083*cdf0e10cSrcweir         {
1084*cdf0e10cSrcweir             static Sequence< Type > s_types( types );
1085*cdf0e10cSrcweir             s_pTypes = &s_types;
1086*cdf0e10cSrcweir         }
1087*cdf0e10cSrcweir     }
1088*cdf0e10cSrcweir     return *s_pTypes;
1089*cdf0e10cSrcweir }
1090*cdf0e10cSrcweir 
1091*cdf0e10cSrcweir Sequence< sal_Int8 > SAL_CALL Invocation_Impl::getImplementationId(  ) throw( RuntimeException)
1092*cdf0e10cSrcweir {
1093*cdf0e10cSrcweir     static OImplementationId *pId = 0;
1094*cdf0e10cSrcweir     if( ! pId )
1095*cdf0e10cSrcweir     {
1096*cdf0e10cSrcweir         MutexGuard guard( Mutex::getGlobalMutex() );
1097*cdf0e10cSrcweir         if( ! pId )
1098*cdf0e10cSrcweir         {
1099*cdf0e10cSrcweir             static OImplementationId id( sal_False );
1100*cdf0e10cSrcweir             pId = &id;
1101*cdf0e10cSrcweir         }
1102*cdf0e10cSrcweir     }
1103*cdf0e10cSrcweir     return pId->getImplementationId();
1104*cdf0e10cSrcweir }
1105*cdf0e10cSrcweir 
1106*cdf0e10cSrcweir //==================================================================================================
1107*cdf0e10cSrcweir //==================================================================================================
1108*cdf0e10cSrcweir //==================================================================================================
1109*cdf0e10cSrcweir class InvocationService
1110*cdf0e10cSrcweir 	: public WeakImplHelper2< XSingleServiceFactory, XServiceInfo >
1111*cdf0e10cSrcweir {
1112*cdf0e10cSrcweir public:
1113*cdf0e10cSrcweir 	InvocationService( const Reference<XComponentContext> & xCtx );
1114*cdf0e10cSrcweir 	virtual ~InvocationService();
1115*cdf0e10cSrcweir 
1116*cdf0e10cSrcweir 	// XServiceInfo
1117*cdf0e10cSrcweir 	OUString 					SAL_CALL getImplementationName() throw( RuntimeException );
1118*cdf0e10cSrcweir     sal_Bool 						SAL_CALL supportsService(const OUString& ServiceName) throw( RuntimeException );
1119*cdf0e10cSrcweir     Sequence< OUString > 		SAL_CALL getSupportedServiceNames(void) throw( RuntimeException );
1120*cdf0e10cSrcweir 
1121*cdf0e10cSrcweir 	// XSingleServiceFactory
1122*cdf0e10cSrcweir     Reference<XInterface>		SAL_CALL createInstance(void) throw( Exception, RuntimeException );
1123*cdf0e10cSrcweir     Reference<XInterface>		SAL_CALL createInstanceWithArguments(
1124*cdf0e10cSrcweir 		const Sequence<Any>& rArguments ) throw( Exception, RuntimeException );
1125*cdf0e10cSrcweir private:
1126*cdf0e10cSrcweir 	Reference<XComponentContext> mxCtx;
1127*cdf0e10cSrcweir 	Reference<XMultiComponentFactory> mxSMgr;
1128*cdf0e10cSrcweir 	Reference<XTypeConverter> xTypeConverter;
1129*cdf0e10cSrcweir 	Reference<XIntrospection> xIntrospection;
1130*cdf0e10cSrcweir 	Reference<XIdlReflection> xCoreReflection;
1131*cdf0e10cSrcweir };
1132*cdf0e10cSrcweir 
1133*cdf0e10cSrcweir InvocationService::InvocationService( const Reference<XComponentContext> & xCtx )
1134*cdf0e10cSrcweir 	: mxCtx( xCtx )
1135*cdf0e10cSrcweir 	, mxSMgr( xCtx->getServiceManager() )
1136*cdf0e10cSrcweir {
1137*cdf0e10cSrcweir 	g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
1138*cdf0e10cSrcweir 	xTypeConverter = Reference<XTypeConverter>(
1139*cdf0e10cSrcweir 		mxSMgr->createInstanceWithContext(
1140*cdf0e10cSrcweir 			OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.script.Converter")),
1141*cdf0e10cSrcweir 			xCtx ),
1142*cdf0e10cSrcweir 		UNO_QUERY );
1143*cdf0e10cSrcweir 	xIntrospection = Reference<XIntrospection>(
1144*cdf0e10cSrcweir 		mxSMgr->createInstanceWithContext(
1145*cdf0e10cSrcweir 			OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.beans.Introspection")),
1146*cdf0e10cSrcweir 			xCtx),
1147*cdf0e10cSrcweir 		UNO_QUERY);
1148*cdf0e10cSrcweir     mxCtx->getValueByName(
1149*cdf0e10cSrcweir         OUString(
1150*cdf0e10cSrcweir             RTL_CONSTASCII_USTRINGPARAM("/singletons/com.sun.star.reflection.theCoreReflection")) )
1151*cdf0e10cSrcweir                 >>= xCoreReflection;
1152*cdf0e10cSrcweir     OSL_ENSURE( xCoreReflection.is(), "### CoreReflection singleton not accessable!?" );
1153*cdf0e10cSrcweir     if (! xCoreReflection.is())
1154*cdf0e10cSrcweir     {
1155*cdf0e10cSrcweir         throw DeploymentException(
1156*cdf0e10cSrcweir             OUString( RTL_CONSTASCII_USTRINGPARAM("/singletons/com.sun.star.reflection.theCoreReflection singleton not accessable") ),
1157*cdf0e10cSrcweir             Reference< XInterface >() );
1158*cdf0e10cSrcweir     }
1159*cdf0e10cSrcweir //         xCoreReflection = Reference<XIdlReflection>(
1160*cdf0e10cSrcweir // 		mxSMgr->createInstanceWithContext(
1161*cdf0e10cSrcweir // 			OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.reflection.CoreReflection")),
1162*cdf0e10cSrcweir // 			xCtx),
1163*cdf0e10cSrcweir // 		UNO_QUERY);
1164*cdf0e10cSrcweir }
1165*cdf0e10cSrcweir 
1166*cdf0e10cSrcweir InvocationService::~InvocationService()
1167*cdf0e10cSrcweir {
1168*cdf0e10cSrcweir 	g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
1169*cdf0e10cSrcweir }
1170*cdf0e10cSrcweir 
1171*cdf0e10cSrcweir // XServiceInfo
1172*cdf0e10cSrcweir OUString InvocationService::getImplementationName() throw( RuntimeException )
1173*cdf0e10cSrcweir {
1174*cdf0e10cSrcweir 	return inv_getImplementationName();
1175*cdf0e10cSrcweir }
1176*cdf0e10cSrcweir 
1177*cdf0e10cSrcweir // XServiceInfo
1178*cdf0e10cSrcweir sal_Bool InvocationService::supportsService(const OUString& ServiceName) throw( RuntimeException )
1179*cdf0e10cSrcweir {
1180*cdf0e10cSrcweir 	Sequence< OUString > aSNL = getSupportedServiceNames();
1181*cdf0e10cSrcweir 	const OUString * pArray = aSNL.getConstArray();
1182*cdf0e10cSrcweir 	for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
1183*cdf0e10cSrcweir 		if( pArray[i] == ServiceName )
1184*cdf0e10cSrcweir 			return sal_True;
1185*cdf0e10cSrcweir 	return sal_False;
1186*cdf0e10cSrcweir }
1187*cdf0e10cSrcweir 
1188*cdf0e10cSrcweir // XServiceInfo
1189*cdf0e10cSrcweir Sequence< OUString > InvocationService::getSupportedServiceNames(void) throw( RuntimeException )
1190*cdf0e10cSrcweir {
1191*cdf0e10cSrcweir 	return inv_getSupportedServiceNames();
1192*cdf0e10cSrcweir }
1193*cdf0e10cSrcweir 
1194*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
1195*cdf0e10cSrcweir Reference<XInterface> InvocationService::createInstance(void) throw( Exception, RuntimeException )
1196*cdf0e10cSrcweir {
1197*cdf0e10cSrcweir 	//TODO:throw( Exception(OUString( RTL_CONSTASCII_USTRINGPARAM("no default construction of invocation adapter possible!")), *this) );
1198*cdf0e10cSrcweir 	return Reference<XInterface>(); // dummy
1199*cdf0e10cSrcweir }
1200*cdf0e10cSrcweir 
1201*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
1202*cdf0e10cSrcweir Reference<XInterface> InvocationService::createInstanceWithArguments(
1203*cdf0e10cSrcweir 	const Sequence<Any>& rArguments ) throw( Exception, RuntimeException )
1204*cdf0e10cSrcweir {
1205*cdf0e10cSrcweir 	if (rArguments.getLength() == 1)
1206*cdf0e10cSrcweir 	{
1207*cdf0e10cSrcweir 		return Reference< XInterface >
1208*cdf0e10cSrcweir 			( *new Invocation_Impl( *rArguments.getConstArray(),
1209*cdf0e10cSrcweir 			  xTypeConverter, xIntrospection, xCoreReflection ) );
1210*cdf0e10cSrcweir 	}
1211*cdf0e10cSrcweir 	else
1212*cdf0e10cSrcweir 	{
1213*cdf0e10cSrcweir 		//TODO:throw( Exception(OUString( RTL_CONSTASCII_USTRINGPARAM("no default construction of invocation adapter possible!")), *this) );
1214*cdf0e10cSrcweir 		return Reference<XInterface>();
1215*cdf0e10cSrcweir 	}
1216*cdf0e10cSrcweir }
1217*cdf0e10cSrcweir 
1218*cdf0e10cSrcweir 
1219*cdf0e10cSrcweir //*************************************************************************
1220*cdf0e10cSrcweir Reference<XInterface> SAL_CALL InvocationService_CreateInstance( const Reference<XComponentContext> & xCtx )
1221*cdf0e10cSrcweir 	throw( RuntimeException )
1222*cdf0e10cSrcweir {
1223*cdf0e10cSrcweir 	Reference<XInterface> xService = Reference< XInterface > ( *new InvocationService( xCtx ) );
1224*cdf0e10cSrcweir 	return xService;
1225*cdf0e10cSrcweir }
1226*cdf0e10cSrcweir 
1227*cdf0e10cSrcweir }
1228*cdf0e10cSrcweir 
1229*cdf0e10cSrcweir using namespace stoc_inv;
1230*cdf0e10cSrcweir static struct ImplementationEntry g_entries[] =
1231*cdf0e10cSrcweir {
1232*cdf0e10cSrcweir 	{
1233*cdf0e10cSrcweir 		InvocationService_CreateInstance, inv_getImplementationName,
1234*cdf0e10cSrcweir 		inv_getSupportedServiceNames, createSingleComponentFactory,
1235*cdf0e10cSrcweir 		&g_moduleCount.modCnt , 0
1236*cdf0e10cSrcweir 	},
1237*cdf0e10cSrcweir 	{ 0, 0, 0, 0, 0, 0 }
1238*cdf0e10cSrcweir };
1239*cdf0e10cSrcweir 
1240*cdf0e10cSrcweir extern "C"
1241*cdf0e10cSrcweir {
1242*cdf0e10cSrcweir sal_Bool SAL_CALL component_canUnload( TimeValue *pTime )
1243*cdf0e10cSrcweir {
1244*cdf0e10cSrcweir 	return g_moduleCount.canUnload( &g_moduleCount , pTime );
1245*cdf0e10cSrcweir }
1246*cdf0e10cSrcweir 
1247*cdf0e10cSrcweir //==================================================================================================
1248*cdf0e10cSrcweir void SAL_CALL component_getImplementationEnvironment(
1249*cdf0e10cSrcweir 	const sal_Char ** ppEnvTypeName, uno_Environment ** )
1250*cdf0e10cSrcweir {
1251*cdf0e10cSrcweir 	*ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
1252*cdf0e10cSrcweir }
1253*cdf0e10cSrcweir //==================================================================================================
1254*cdf0e10cSrcweir void * SAL_CALL component_getFactory(
1255*cdf0e10cSrcweir 	const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey )
1256*cdf0e10cSrcweir {
1257*cdf0e10cSrcweir 	return component_getFactoryHelper( pImplName, pServiceManager, pRegistryKey , g_entries );
1258*cdf0e10cSrcweir }
1259*cdf0e10cSrcweir }
1260*cdf0e10cSrcweir 
1261*cdf0e10cSrcweir 
1262*cdf0e10cSrcweir 
1263