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