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