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