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