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