Branch data 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/XIntrospection.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 : 112 : static Sequence< OUString > inv_getSupportedServiceNames()
73 : : {
74 : 112 : Sequence< OUString > seqNames(1);
75 [ + - ][ + - ]: 112 : seqNames.getArray()[0] = OUString(RTL_CONSTASCII_USTRINGPARAM(SERVICENAME));
76 : 112 : return seqNames;
77 : : }
78 : :
79 : 112 : static OUString inv_getImplementationName()
80 : : {
81 : 112 : return OUString(RTL_CONSTASCII_USTRINGPARAM(IMPLNAME));
82 : : }
83 : :
84 : : // TODO: Zentral implementieren
85 : 114072 : inline Reference<XIdlClass> TypeToIdlClass( const Type& rType, const Reference< XIdlReflection > & xRefl )
86 : : {
87 [ + - ]: 114072 : 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 : 115834 : virtual void SAL_CALL acquire() throw() { OWeakObject::acquire(); }
111 : 115622 : 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 : 17344 : 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 : 17344 : , xCoreReflection( rCR )
252 : : {
253 [ + - ]: 17344 : g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
254 [ + - ]: 17344 : setMaterial( rAdapted );
255 : 17344 : }
256 : :
257 : 17132 : Invocation_Impl::~Invocation_Impl()
258 : : {
259 [ + - ]: 17132 : g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
260 [ - + ]: 34264 : }
261 : :
262 : : //##################################################################################################
263 : : //### INTERFACE IMPLEMENTATIONS ####################################################################
264 : : //##################################################################################################
265 : :
266 : :
267 : 30164 : 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 [ + - ]: 30164 : (static_cast< XTypeProvider * >(this)) );
275 [ + + ]: 30164 : if( a.hasValue() )
276 : : {
277 : 12820 : return a;
278 : : }
279 : :
280 [ + - ][ - + ]: 17344 : 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 [ + - ][ - + ]: 17344 : 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 [ + - ][ - + ]: 17344 : 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 [ + - ][ - + ]: 17344 : 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 [ + - ][ - + ]: 17344 : 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 [ + - ][ - + ]: 17344 : 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 [ + - ][ - + ]: 17344 : 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 [ + - ][ + - ]: 17344 : else if ( aType == getCppuType( (Reference<XInvocation2>*) NULL ) )
324 : : {
325 : : // Invocation does not support XInvocation2, if direct object supports
326 : : // XInvocation, but not XInvocation2.
327 [ - + ][ # # : 52032 : if ( ( _xDirect.is() && _xDirect2.is()) ||
+ - + - ]
[ + - ]
328 : 34688 : (!_xDirect.is() && _xIntrospectionAccess.is() ) )
329 : : {
330 [ + - ][ + - ]: 17344 : return makeAny( Reference< XInvocation2 >( (static_cast< XInvocation2* >(this)) ) );
331 : : }
332 : : }
333 : :
334 [ # # ]: 30164 : return OWeakObject::queryInterface( aType );
335 : : }
336 : :
337 : :
338 : : //--------------------------------------------------------------------------------------------------
339 : 12820 : 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 : 12820 : Reference<XMaterialHolder> xMaterialHolder;
345 [ - + ]: 12820 : if( _xDirect.is() )
346 : : {
347 [ # # ][ # # ]: 0 : xMaterialHolder = Reference<XMaterialHolder>::query( _xDirect );
348 : : //_xDirect->queryInterface( XMaterialHolder::getSmartUik(), xMaterialHolder );
349 : : }
350 [ + - ]: 12820 : else if( _xIntrospectionAccess.is() )
351 : : {
352 [ + - ][ + - ]: 12820 : xMaterialHolder = Reference<XMaterialHolder>::query( _xIntrospectionAccess );
353 : : //_xIntrospectionAccess->queryInterface( XMaterialHolder::getSmartUik(), xMaterialHolder );
354 : : }
355 [ + - ]: 12820 : if( xMaterialHolder.is() )
356 : : {
357 [ + - ][ + - ]: 12820 : return xMaterialHolder->getMaterial();
358 : : }
359 : 12820 : return _aMaterial;
360 : : }
361 : :
362 : : //--------------------------------------------------------------------------------------------------
363 : 17344 : void Invocation_Impl::setMaterial( const Any& rMaterial )
364 : : {
365 : : // set the material first and only once
366 : 17344 : Reference<XInterface> xObj;
367 : :
368 [ + + ]: 17344 : if (rMaterial.getValueType().getTypeClass() == TypeClass_INTERFACE)
369 [ + - ]: 2164 : xObj = *(Reference<XInterface>*)rMaterial.getValue();
370 : 17344 : _aMaterial = rMaterial;
371 : :
372 : : // Ersteinmal alles ausserhalb des guards machen
373 [ + - ][ + - ]: 17344 : _xDirect = Reference<XInvocation>::query( xObj );
374 : :
375 [ - + ]: 17344 : 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 [ + - ]: 17344 : if (xIntrospection.is())
395 : : {
396 [ + - ][ + - ]: 17344 : _xIntrospectionAccess = xIntrospection->inspect( _aMaterial );
[ + - ]
397 [ + - ]: 17344 : if( _xIntrospectionAccess.is() )
398 : : {
399 : :
400 : : _xElementAccess = Reference<XElementAccess>::query(
401 [ + - ]: 17344 : _xIntrospectionAccess->queryAdapter(
402 [ + - ][ + - ]: 17344 : getCppuType( (Reference<XElementAccess>*) NULL ) ) );
[ + - ][ + - ]
403 : :
404 : : _xEnumerationAccess = Reference<XEnumerationAccess>::query(
405 [ + - ]: 17344 : _xIntrospectionAccess->queryAdapter(
406 [ + - ][ + - ]: 17344 : getCppuType( (Reference<XEnumerationAccess>*) NULL )) );
[ + - ][ + - ]
407 : :
408 : : _xIndexAccess = Reference<XIndexAccess>::query(
409 [ + - ]: 17344 : _xIntrospectionAccess->queryAdapter(
410 [ + - ][ + - ]: 17344 : getCppuType( (Reference<XIndexAccess>*) NULL ) ) );
[ + - ][ + - ]
411 : :
412 : : _xIndexContainer = Reference<XIndexContainer>::query(
413 [ + - ]: 17344 : _xIntrospectionAccess->queryAdapter(
414 [ + - ][ + - ]: 17344 : getCppuType( (Reference<XIndexContainer>*) NULL ) ) );
[ + - ][ + - ]
415 : :
416 : : _xNameAccess = Reference<XNameAccess>::query(
417 [ + - ]: 17344 : _xIntrospectionAccess->queryAdapter(
418 [ + - ][ + - ]: 17344 : getCppuType( (Reference<XNameAccess>*) NULL ) ) );
[ + - ][ + - ]
419 : :
420 : : _xNameContainer = Reference<XNameContainer>::query(
421 [ + - ]: 17344 : _xIntrospectionAccess->queryAdapter(
422 [ + - ][ + - ]: 17344 : getCppuType( (Reference<XNameContainer>*) NULL ) ) );
[ + - ][ + - ]
423 : :
424 : : _xPropertySet = Reference<XPropertySet>::query(
425 [ + - ]: 17344 : _xIntrospectionAccess->queryAdapter(
426 [ + - ][ + - ]: 17344 : getCppuType( (Reference<XPropertySet>*) NULL )) );
[ + - ][ + - ]
427 : :
428 [ + - ][ + - ]: 17344 : _xENIntrospection = Reference<XExactName>::query( _xIntrospectionAccess );
429 [ + + ]: 17344 : if (_xNameAccess.is())
430 [ + - ][ + - ]: 677 : _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 : 17344 : }
448 : 17344 : }
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 : 50832 : sal_Bool Invocation_Impl::hasMethod( const OUString& Name )
477 : : throw( RuntimeException )
478 : : {
479 [ - + ]: 50832 : if (_xDirect.is())
480 : 0 : return _xDirect->hasMethod( Name );
481 [ + - ]: 50832 : if( _xIntrospectionAccess.is() )
482 : 50832 : return _xIntrospectionAccess->hasMethod( Name, MethodConcept::ALL ^ MethodConcept::DANGEROUS );
483 : 50832 : return sal_False;
484 : : }
485 : :
486 : : //--------------------------------------------------------------------------------------------------
487 : 99089 : sal_Bool Invocation_Impl::hasProperty( const OUString& Name )
488 : : throw( RuntimeException )
489 : : {
490 [ - + ]: 99089 : if (_xDirect.is())
491 : 0 : return _xDirect->hasProperty( Name );
492 : : // PropertySet
493 [ + - + + ]: 198178 : if( _xIntrospectionAccess.is()
[ + + ]
494 : 99089 : && _xIntrospectionAccess->hasProperty( Name, PropertyConcept::ALL ^ PropertyConcept::DANGEROUS ) )
495 : 96287 : return sal_True;
496 : : // NameAccess
497 [ - + ]: 2802 : if( _xNameAccess.is() )
498 : 0 : return _xNameAccess->hasByName( Name );
499 : 99089 : return sal_False;
500 : : }
501 : :
502 : : //--------------------------------------------------------------------------------------------------
503 : 47358 : Any Invocation_Impl::getValue( const OUString& PropertyName )
504 : : throw( UnknownPropertyException, RuntimeException )
505 : : {
506 [ - + ]: 47358 : if (_xDirect.is())
507 : 0 : return _xDirect->getValue( PropertyName );
508 : : try
509 : : {
510 : : // PropertySet
511 [ + - ][ + - ]: 94716 : if( _xIntrospectionAccess.is() && _xPropertySet.is()
[ + - ][ + - ]
512 [ + - ]: 47358 : && _xIntrospectionAccess->hasProperty
513 [ + - ]: 47358 : ( PropertyName, PropertyConcept::ALL ^ PropertyConcept::DANGEROUS ) )
514 : : {
515 [ + - ][ + - ]: 47358 : 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 : : OUString( RTL_CONSTASCII_USTRINGPARAM("cannot get value ") ) + PropertyName,
535 [ # # ][ # # ]: 47358 : Reference< XInterface >() );
536 : : }
537 : :
538 : : //--------------------------------------------------------------------------------------------------
539 : 55169 : void Invocation_Impl::setValue( const OUString& PropertyName, const Any& Value )
540 : : throw( UnknownPropertyException, CannotConvertException, InvocationTargetException, RuntimeException )
541 : : {
542 [ - + ]: 55169 : if (_xDirect.is())
543 : 0 : _xDirect->setValue( PropertyName, Value );
544 : : else
545 : : {
546 : : try
547 : : {
548 : : // Properties
549 [ + - ][ + - ]: 110338 : if( _xIntrospectionAccess.is() && _xPropertySet.is()
[ + - ][ + - ]
550 [ + - ]: 55169 : && _xIntrospectionAccess->hasProperty(
551 [ + - ]: 55169 : PropertyName, PropertyConcept::ALL ^ PropertyConcept::DANGEROUS ) )
552 : : {
553 [ + - ]: 55169 : Property aProp = _xIntrospectionAccess->getProperty(
554 [ + - ]: 55169 : PropertyName, PropertyConcept::ALL ^ PropertyConcept::DANGEROUS );
555 [ + - ]: 55169 : Reference < XIdlClass > r = TypeToIdlClass( aProp.Type, xCoreReflection );
556 [ + - ][ + - ]: 55169 : if( r->isAssignableFrom( TypeToIdlClass( Value.getValueType(), xCoreReflection ) ) )
[ + - ][ + + ]
557 [ + - ][ + - ]: 39530 : _xPropertySet->setPropertyValue( PropertyName, Value );
558 [ + - ]: 15639 : else if( xTypeConverter.is() )
559 [ + - ]: 15639 : _xPropertySet->setPropertyValue(
560 [ + - ][ + - ]: 15639 : PropertyName, xTypeConverter->convertTo( Value, aProp.Type ) );
[ + - ]
561 : : else
562 : : throw RuntimeException(
563 : : OUString( RTL_CONSTASCII_USTRINGPARAM("no type converter service!") ),
564 [ # # ][ # # ]: 55169 : 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 : 55169 : }
616 : :
617 : : //--------------------------------------------------------------------------------------------------
618 : 3474 : 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 [ - + ]: 3474 : if (_xDirect.is())
623 [ # # ][ # # ]: 0 : return _xDirect->invoke( FunctionName, InParams, OutIndizes, OutParams );
624 : :
625 [ + - ]: 3474 : if (_xIntrospectionAccess.is())
626 : : {
627 : : // throw NoSuchMethodException if not exist
628 [ + - ]: 3474 : Reference<XIdlMethod> xMethod = _xIntrospectionAccess->getMethod(
629 [ + - ]: 3474 : FunctionName, MethodConcept::ALL ^ MethodConcept::DANGEROUS );
630 : :
631 : : // ParameterInfos
632 [ + - ][ + - ]: 3474 : Sequence<ParamInfo> aFParams = xMethod->getParameterInfos();
633 : 3474 : const ParamInfo* pFParams = aFParams.getConstArray();
634 : 3474 : sal_Int32 nFParamsLen = aFParams.getLength();
635 [ - + ]: 3474 : if (nFParamsLen != InParams.getLength())
636 : : {
637 : : throw IllegalArgumentException(
638 : : 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 : 3474 : const Any* pInParams = InParams.getConstArray();
644 : :
645 : : // Introspection Invoke Parameter
646 [ + - ]: 3474 : Sequence<Any> aInvokeParams( nFParamsLen );
647 [ + - ]: 3474 : Any* pInvokeParams = aInvokeParams.getArray();
648 : :
649 : : // OUT Indizes
650 [ + - ]: 3474 : OutIndizes.realloc( nFParamsLen );
651 [ + - ]: 3474 : sal_Int16* pOutIndizes = OutIndizes.getArray();
652 : 3474 : sal_uInt32 nOutIndex = 0;
653 : :
654 [ + + ]: 7208 : for ( sal_Int32 nPos = 0; nPos < nFParamsLen; ++nPos )
655 : : {
656 : : try
657 : : {
658 : 3734 : const ParamInfo& rFParam = pFParams[nPos];
659 : 3734 : const Reference<XIdlClass>& rDestType = rFParam.aType;
660 : :
661 : : // is IN/INOUT parameter?
662 [ + - ]: 3734 : if (rFParam.aMode != ParamMode_OUT)
663 : : {
664 [ + - ][ + - ]: 3734 : if (rDestType->isAssignableFrom( TypeToIdlClass( pInParams[nPos].getValueType(), xCoreReflection ) ))
[ + - ][ + - ]
665 : : {
666 : 3734 : 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 [ - + ]: 3734 : 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 [ + - ][ + - ]: 3474 : Any aRet = xMethod->invoke( _aMaterial, aInvokeParams );
700 : :
701 : : // OUT Params
702 [ + - ]: 3474 : OutIndizes.realloc( nOutIndex );
703 [ + - ]: 3474 : pOutIndizes = OutIndizes.getArray();
704 [ + - ]: 3474 : OutParams.realloc( nOutIndex );
705 [ + - ]: 3474 : Any* pOutParams = OutParams.getArray();
706 : :
707 [ - + ]: 3474 : while (nOutIndex--)
708 : : {
709 : 0 : pOutParams[nOutIndex] = pInvokeParams[ pOutIndizes[nOutIndex] ];
710 : : }
711 : :
712 [ + - ][ + - ]: 3474 : 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 [ # # ]: 3474 : 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 : 112 : InvocationService::InvocationService( const Reference<XComponentContext> & xCtx )
1100 : : : mxCtx( xCtx )
1101 [ + - ][ + - ]: 112 : , mxSMgr( xCtx->getServiceManager() )
1102 : : {
1103 [ + - ]: 112 : g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
1104 : : xTypeConverter = Reference<XTypeConverter>(
1105 [ + - ]: 112 : mxSMgr->createInstanceWithContext(
1106 : : OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.script.Converter")),
1107 : 112 : xCtx ),
1108 [ + - ][ + - ]: 112 : UNO_QUERY );
[ + - ][ + - ]
1109 : : xIntrospection = Reference<XIntrospection>(
1110 [ + - ]: 112 : mxSMgr->createInstanceWithContext(
1111 : : OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.beans.Introspection")),
1112 : 112 : xCtx),
1113 [ + - ][ + - ]: 112 : UNO_QUERY);
[ + - ][ + - ]
1114 [ + - ]: 112 : mxCtx->getValueByName(
1115 : : OUString(
1116 : 112 : RTL_CONSTASCII_USTRINGPARAM("/singletons/com.sun.star.reflection.theCoreReflection")) )
1117 [ + - ][ + - ]: 112 : >>= xCoreReflection;
[ + - ]
1118 : : OSL_ENSURE( xCoreReflection.is(), "### CoreReflection singleton not accessable!?" );
1119 [ - + ]: 112 : if (! xCoreReflection.is())
1120 : : {
1121 : : throw DeploymentException(
1122 : : OUString( RTL_CONSTASCII_USTRINGPARAM("/singletons/com.sun.star.reflection.theCoreReflection singleton not accessable") ),
1123 [ # # ][ # # ]: 0 : Reference< XInterface >() );
1124 : : }
1125 : : // xCoreReflection = Reference<XIdlReflection>(
1126 : : // mxSMgr->createInstanceWithContext(
1127 : : // OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.reflection.CoreReflection")),
1128 : : // xCtx),
1129 : : // UNO_QUERY);
1130 : 112 : }
1131 : :
1132 : 0 : InvocationService::~InvocationService()
1133 : : {
1134 [ # # ]: 0 : g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
1135 [ # # ]: 0 : }
1136 : :
1137 : : // XServiceInfo
1138 : 0 : OUString InvocationService::getImplementationName() throw( RuntimeException )
1139 : : {
1140 : 0 : return inv_getImplementationName();
1141 : : }
1142 : :
1143 : : // XServiceInfo
1144 : 0 : sal_Bool InvocationService::supportsService(const OUString& ServiceName) throw( RuntimeException )
1145 : : {
1146 [ # # ]: 0 : Sequence< OUString > aSNL = getSupportedServiceNames();
1147 : 0 : const OUString * pArray = aSNL.getConstArray();
1148 [ # # ]: 0 : for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
1149 [ # # ]: 0 : if( pArray[i] == ServiceName )
1150 : 0 : return sal_True;
1151 [ # # ]: 0 : return sal_False;
1152 : : }
1153 : :
1154 : : // XServiceInfo
1155 : 0 : Sequence< OUString > InvocationService::getSupportedServiceNames(void) throw( RuntimeException )
1156 : : {
1157 : 0 : return inv_getSupportedServiceNames();
1158 : : }
1159 : :
1160 : : //--------------------------------------------------------------------------------------------------
1161 : 0 : Reference<XInterface> InvocationService::createInstance(void) throw( Exception, RuntimeException )
1162 : : {
1163 : : //TODO:throw( Exception(OUString( RTL_CONSTASCII_USTRINGPARAM("no default construction of invocation adapter possible!")), *this) );
1164 : 0 : return Reference<XInterface>(); // dummy
1165 : : }
1166 : :
1167 : : //--------------------------------------------------------------------------------------------------
1168 : 17344 : Reference<XInterface> InvocationService::createInstanceWithArguments(
1169 : : const Sequence<Any>& rArguments ) throw( Exception, RuntimeException )
1170 : : {
1171 [ + - ]: 17344 : if (rArguments.getLength() == 1)
1172 : : {
1173 : : return Reference< XInterface >
1174 : : ( *new Invocation_Impl( *rArguments.getConstArray(),
1175 [ + - ]: 17344 : xTypeConverter, xIntrospection, xCoreReflection ) );
1176 : : }
1177 : : else
1178 : : {
1179 : : //TODO:throw( Exception(OUString( RTL_CONSTASCII_USTRINGPARAM("no default construction of invocation adapter possible!")), *this) );
1180 : 17344 : return Reference<XInterface>();
1181 : : }
1182 : : }
1183 : :
1184 : :
1185 : : //*************************************************************************
1186 : 112 : Reference<XInterface> SAL_CALL InvocationService_CreateInstance( const Reference<XComponentContext> & xCtx )
1187 : : throw( RuntimeException )
1188 : : {
1189 [ + - ][ + - ]: 112 : Reference<XInterface> xService = Reference< XInterface > ( *new InvocationService( xCtx ) );
1190 : 112 : return xService;
1191 : : }
1192 : :
1193 : : }
1194 : :
1195 : : using namespace stoc_inv;
1196 : : static struct ImplementationEntry g_entries[] =
1197 : : {
1198 : : {
1199 : : InvocationService_CreateInstance, inv_getImplementationName,
1200 : : inv_getSupportedServiceNames, createSingleComponentFactory,
1201 : : &g_moduleCount.modCnt , 0
1202 : : },
1203 : : { 0, 0, 0, 0, 0, 0 }
1204 : : };
1205 : :
1206 : : extern "C"
1207 : : {
1208 : 0 : SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL component_canUnload( TimeValue *pTime )
1209 : : {
1210 : 0 : return g_moduleCount.canUnload( &g_moduleCount , pTime );
1211 : : }
1212 : :
1213 : : //==================================================================================================
1214 : 112 : SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(
1215 : : const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey )
1216 : : {
1217 : 112 : return component_getFactoryHelper( pImplName, pServiceManager, pRegistryKey , g_entries );
1218 : : }
1219 : : }
1220 : :
1221 : :
1222 : :
1223 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|