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