summaryrefslogtreecommitdiff
path: root/stoc/source/invocation/invocation.cxx
blob: ca9731b75b0cb0532ba744e46f0a4aae22891e10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 * 
 * Copyright 2000, 2010 Oracle and/or its affiliates.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_stoc.hxx"
#include <osl/mutex.hxx>
#include <cppuhelper/queryinterface.hxx>
#include <cppuhelper/weak.hxx>
#include <cppuhelper/factory.hxx>
#include <cppuhelper/implementationentry.hxx>
#include <cppuhelper/typeprovider.hxx>
#include <cppuhelper/implbase2.hxx>

#include <com/sun/star/uno/DeploymentException.hpp>
#include <com/sun/star/script/FailReason.hpp>
#include <com/sun/star/script/XTypeConverter.hpp>
#include <com/sun/star/script/XInvocation.hpp>
#include <com/sun/star/script/XInvocation2.hpp>
#include <com/sun/star/reflection/XIdlReflection.hpp>
#include <com/sun/star/container/XNameContainer.hpp>
#include <com/sun/star/container/XIndexContainer.hpp>
#include <com/sun/star/container/XEnumerationAccess.hpp>
#include <com/sun/star/beans/XExactName.hpp>
#include <com/sun/star/beans/XMaterialHolder.hpp>
#include <com/sun/star/beans/XIntrospection.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/beans/PropertyAttribute.hpp>
#include <com/sun/star/beans/MethodConcept.hpp>
#include <com/sun/star/beans/PropertyConcept.hpp>
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/XTypeProvider.hpp>
#include <com/sun/star/registry/XRegistryKey.hpp>

#include <boost/scoped_array.hpp>
#include <rtl/ustrbuf.hxx>
#include <rtl/strbuf.hxx>

#define SERVICENAME "com.sun.star.script.Invocation"
#define IMPLNAME	 "com.sun.star.comp.stoc.Invocation"

using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
using namespace com::sun::star::script;
using namespace com::sun::star::reflection;
using namespace com::sun::star::beans;
using namespace com::sun::star::registry;
using namespace com::sun::star::container;
using namespace cppu;
using namespace osl;
using ::rtl::OUString;

namespace stoc_inv
{
static rtl_StandardModuleCount g_moduleCount = MODULE_COUNT_INIT;

static Sequence< OUString > inv_getSupportedServiceNames()
{
    Sequence< OUString > seqNames(1);
    seqNames.getArray()[0] = OUString(RTL_CONSTASCII_USTRINGPARAM(SERVICENAME));
    return seqNames;
}

static OUString inv_getImplementationName()
{
    return OUString(RTL_CONSTASCII_USTRINGPARAM(IMPLNAME));
}

// TODO: Zentral implementieren
inline Reference<XIdlClass> TypeToIdlClass( const Type& rType, const Reference< XIdlReflection > & xRefl )
{
    return xRefl->forName( rType.getTypeName() );
}


//==================================================================================================
class Invocation_Impl
    : public OWeakObject
    , public XInvocation2
    , public XNameContainer
    , public XIndexContainer
    , public XEnumerationAccess
    , public XExactName
    , public XMaterialHolder
    , public XTypeProvider
{
public:
    Invocation_Impl( const Any & rAdapted, const Reference<XTypeConverter> &, 
                                           const Reference<XIntrospection> &,
                                           const Reference<XIdlReflection> & );
    virtual ~Invocation_Impl();

    // XInterface
    virtual Any	        SAL_CALL queryInterface( const Type & aType) throw( RuntimeException );
    virtual void		SAL_CALL acquire() throw() { OWeakObject::acquire(); }
    virtual void		SAL_CALL release() throw() { OWeakObject::release(); }

    
    // XTypeProvider
    virtual Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes(  )
       throw(RuntimeException);
    virtual Sequence< sal_Int8 > SAL_CALL getImplementationId(  )
       throw( RuntimeException);

    // Methoden von XMaterialHolder
    virtual Any			SAL_CALL getMaterial(void) throw(RuntimeException);

    // ? XTool
    virtual void		SAL_CALL setMaterial( const Any& rMaterial );
    
    // XInvocation
    virtual Reference<XIntrospectionAccess> SAL_CALL getIntrospection(void) throw( RuntimeException );
    virtual Any SAL_CALL invoke(const OUString& FunctionName, const Sequence< Any >& Params, Sequence< sal_Int16 >& OutParamIndex, Sequence< Any >& OutParam) 
        throw( IllegalArgumentException, CannotConvertException, InvocationTargetException, RuntimeException );
    virtual void SAL_CALL setValue(const OUString& PropertyName, const Any& Value) 
        throw( UnknownPropertyException, CannotConvertException, InvocationTargetException, RuntimeException );
    virtual Any SAL_CALL getValue(const OUString& PropertyName) 
        throw( UnknownPropertyException, RuntimeException );
    virtual sal_Bool SAL_CALL hasMethod(const OUString& Name) throw( RuntimeException );
    virtual sal_Bool SAL_CALL hasProperty(const OUString& Name) throw( RuntimeException );

    // XInvocation2
    virtual Sequence< OUString > SAL_CALL getMemberNames(  ) 
        throw( RuntimeException );
    virtual Sequence< InvocationInfo > SAL_CALL getInfo(  ) 
        throw( RuntimeException );
    virtual InvocationInfo SAL_CALL getInfoForName( const OUString& aName, sal_Bool bExact ) 
        throw( IllegalArgumentException, RuntimeException );

    // All Access and Container methods are not thread save
    // XElementAccess
    virtual Type SAL_CALL getElementType(void) throw( RuntimeException )
        { return _xElementAccess->getElementType(); }
    
    virtual sal_Bool SAL_CALL hasElements(void) throw( RuntimeException )
        { return _xElementAccess->hasElements(); }
    
    // XNameContainer
    virtual void SAL_CALL insertByName( const OUString& Name, const Any& Element )
        throw( IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException )
        { _xNameContainer->insertByName( Name, Element ); }
    
    virtual void SAL_CALL replaceByName( const OUString& Name, const Any& Element )
        throw( IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException )
        { _xNameContainer->replaceByName( Name, Element ); }
    
    virtual void SAL_CALL removeByName( const OUString& Name )
        throw( NoSuchElementException, WrappedTargetException, RuntimeException )
        { _xNameContainer->removeByName( Name ); }
    
    // XNameAccess
    virtual Any SAL_CALL getByName( const OUString& Name )
        throw( NoSuchElementException, WrappedTargetException, RuntimeException )
        { return _xNameAccess->getByName( Name ); }
    
    virtual Sequence<OUString> SAL_CALL getElementNames(void) throw( RuntimeException )
        { return _xNameAccess->getElementNames(); }
    
    virtual sal_Bool SAL_CALL hasByName( const OUString& Name ) throw( RuntimeException )
        { return _xNameAccess->hasByName( Name ); }

    // XIndexContainer
    virtual void SAL_CALL insertByIndex( sal_Int32 Index, const Any& Element )
        throw( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
        { _xIndexContainer->insertByIndex( Index, Element ); }
    
    virtual void SAL_CALL replaceByIndex( sal_Int32 Index, const Any& Element )
        throw( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
        { _xIndexContainer->replaceByIndex( Index, Element ); }
    
    virtual void SAL_CALL removeByIndex( sal_Int32 Index )
        throw( IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
        { _xIndexContainer->removeByIndex( Index ); }
    
    // XIndexAccess
    virtual sal_Int32 SAL_CALL getCount(void) throw( RuntimeException )
        { return _xIndexAccess->getCount(); }
    
    virtual Any SAL_CALL getByIndex( sal_Int32 Index ) 
        throw( IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
        { return _xIndexAccess->getByIndex( Index ); }
    
    // XEnumerationAccess
    virtual Reference<XEnumeration> SAL_CALL createEnumeration(void) throw( RuntimeException )
        { return _xEnumerationAccess->createEnumeration(); }

    // XExactName
    virtual OUString SAL_CALL getExactName( const OUString& rApproximateName ) throw( RuntimeException );
        
    
    //=====================================================================================================
private:
    void getInfoSequenceImpl( Sequence< OUString >* pStringSeq, Sequence< InvocationInfo >* pInfoSeq );
    void fillInfoForNameAccess( InvocationInfo& rInfo, const OUString& aName );
    void fillInfoForProperty( InvocationInfo& rInfo, const Property& rProp );
    void fillInfoForMethod( InvocationInfo& rInfo, const Reference< XIdlMethod > xMethod );

    Reference<XTypeConverter>			xTypeConverter;
    Reference<XIntrospection>			xIntrospection;
    Reference<XIdlReflection>			xCoreReflection;
    
    Any								_aMaterial;
    // _xDirect and (_xIntrospectionAccess, xPropertySet) are exclusive
    Reference<XInvocation>				_xDirect;
    Reference<XInvocation2>				_xDirect2;
    Reference<XPropertySet>				_xPropertySet;
    Reference<XIntrospectionAccess>		_xIntrospectionAccess;

    // supplied Interfaces
    Reference<XNameContainer>			_xNameContainer;
    Reference<XNameAccess>				_xNameAccess;
    Reference<XIndexContainer>			_xIndexContainer;
    Reference<XIndexAccess>				_xIndexAccess;
    Reference<XEnumerationAccess>		_xEnumerationAccess;
    Reference<XElementAccess>			_xElementAccess;

    //
    Reference<XExactName>				_xENDirect, _xENIntrospection, _xENNameAccess;
};


//==================================================================================================
//==================================================================================================
//==================================================================================================

//--------------------------------------------------------------------------------------------------
Invocation_Impl::Invocation_Impl
(
    const Any & rAdapted, 
    const Reference<XTypeConverter> & rTC, 
    const Reference<XIntrospection>	& rI,
    const Reference<XIdlReflection> & rCR
)
    : xTypeConverter( rTC )
    , xIntrospection( rI )
    , xCoreReflection( rCR )
{
    g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
    setMaterial( rAdapted );
}

Invocation_Impl::~Invocation_Impl()
{
    g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
}

//##################################################################################################
//### INTERFACE IMPLEMENTATIONS ####################################################################
//##################################################################################################


Any SAL_CALL Invocation_Impl::queryInterface( const Type & aType ) 
    throw( RuntimeException )
{
    // PropertySet-Implementation
    Any a = ::cppu::queryInterface( aType, 
                                   SAL_STATIC_CAST(XInvocation*, this),
                                   SAL_STATIC_CAST(XMaterialHolder*, this),
                                   SAL_STATIC_CAST(XTypeProvider *,this)	);
    if( a.hasValue() )
    {
        return a;
    }

    if( aType  == getCppuType( (Reference<XExactName>*) NULL ) )
    {
        // Ivocation does not support XExactName, if direct object supports
        // XInvocation, but not XExactName.
        if ((_xDirect.is() && _xENDirect.is()) ||
            (!_xDirect.is() && (_xENIntrospection.is() || _xENNameAccess.is())))
        {
            return makeAny( Reference< XExactName >( SAL_STATIC_CAST(XExactName*, this) ) );
        }
    }
    else if ( aType == getCppuType( (Reference<XNameContainer>*) NULL ) )
    {
        if( _xNameContainer.is() )
            return makeAny( Reference< XNameContainer >( SAL_STATIC_CAST(XNameContainer*, this) ) );
    }
    else if ( aType == getCppuType( (Reference<XNameAccess>*) NULL ) ) 
    {
        if( _xNameAccess.is() )
            return makeAny( Reference< XNameAccess >( SAL_STATIC_CAST(XNameAccess*, this) ) );
    }
    else if ( aType == getCppuType( (Reference<XIndexContainer>*) NULL ) )
    {
        if (_xIndexContainer.is())
            return makeAny( Reference< XIndexContainer >( SAL_STATIC_CAST(XIndexContainer*, this) ) );
    }
    else if ( aType == getCppuType( (Reference<XIndexAccess>*) NULL ) )
    {
        if (_xIndexAccess.is())
            return makeAny( Reference< XIndexAccess >( SAL_STATIC_CAST(XIndexAccess*, this) ) );
    }
    else if ( aType == getCppuType( (Reference<XEnumerationAccess>*) NULL ) )
    {
        if (_xEnumerationAccess.is())
            return makeAny( Reference< XEnumerationAccess >( SAL_STATIC_CAST(XEnumerationAccess*, this) ) );
    }
    else if ( aType == getCppuType( (Reference<XElementAccess>*) NULL ) )
    {
        if (_xElementAccess.is())
        {
            return makeAny( Reference< XElementAccess >(
                SAL_STATIC_CAST(XElementAccess*, SAL_STATIC_CAST(XNameContainer*, this) ) ) );
        }
    }
    else if ( aType == getCppuType( (Reference<XInvocation2>*) NULL ) )
    {
        // Invocation does not support XInvocation2, if direct object supports
        // XInvocation, but not XInvocation2.
        if ( ( _xDirect.is() && _xDirect2.is()) ||
             (!_xDirect.is() && _xIntrospectionAccess.is() ) )
        {
            return makeAny( Reference< XInvocation2 >( SAL_STATIC_CAST(XInvocation2*, this) ) );
        }
    }

    return OWeakObject::queryInterface( aType );
}


//--------------------------------------------------------------------------------------------------
Any Invocation_Impl::getMaterial(void) throw(RuntimeException)
{
    // AB, 12.2.1999  Sicherstellen, dass das Material wenn moeglich
    // aus der direkten Invocation bzw. von der Introspection geholt
    // wird, da sonst Structs nicht korrekt behandelt werden
    Reference<XMaterialHolder> xMaterialHolder;
    if( _xDirect.is() )
    {
        xMaterialHolder = Reference<XMaterialHolder>::query( _xDirect );
        //_xDirect->queryInterface( XMaterialHolder::getSmartUik(), xMaterialHolder );
    }
    else if( _xIntrospectionAccess.is() )
    {
        xMaterialHolder = Reference<XMaterialHolder>::query( _xIntrospectionAccess );
        //_xIntrospectionAccess->queryInterface( XMaterialHolder::getSmartUik(), xMaterialHolder );
    }
    if( xMaterialHolder.is() )
    {
        return xMaterialHolder->getMaterial();
    }
    return _aMaterial;
}

//--------------------------------------------------------------------------------------------------
void Invocation_Impl::setMaterial( const Any& rMaterial )
{
    // set the material first and only once
    Reference<XInterface> xObj;

    if (rMaterial.getValueType().getTypeClass() == TypeClass_INTERFACE)
        xObj = *(Reference<XInterface>*)rMaterial.getValue();
    _aMaterial = rMaterial;

    // Ersteinmal alles ausserhalb des guards machen
    _xDirect = Reference<XInvocation>::query( xObj );

    if( _xDirect.is() )
    {
        // Objekt direkt befragen
        _xElementAccess		= Reference<XElementAccess>::query( _xDirect );
        _xEnumerationAccess = Reference<XEnumerationAccess>::query( _xDirect );
        _xIndexAccess		= Reference<XIndexAccess>::query( _xDirect );
        _xIndexContainer	= Reference<XIndexContainer>::query( _xDirect );
        _xNameAccess		= Reference<XNameAccess>::query( _xDirect );
        _xNameContainer		= Reference<XNameContainer>::query( _xDirect );
        _xENDirect			= Reference<XExactName>::query( _xDirect );
        _xDirect2			= Reference<XInvocation2>::query( _xDirect );
        
        // only once!!!
        //_xIntrospectionAccess = XIntrospectionAccessRef();
        //_xPropertySet			= XPropertySetRef();
    }
    else
    {
        // Invocation ueber die Introspection machen
        if (xIntrospection.is())
        {
            _xIntrospectionAccess = xIntrospection->inspect( _aMaterial );
            if( _xIntrospectionAccess.is() )
            {

                _xElementAccess = Reference<XElementAccess>::query(
                      _xIntrospectionAccess->queryAdapter(
                                 getCppuType( (Reference<XElementAccess>*) NULL ) ) );

                _xEnumerationAccess = Reference<XEnumerationAccess>::query(
                           _xIntrospectionAccess->queryAdapter(
                                getCppuType( (Reference<XEnumerationAccess>*) NULL )) );

                _xIndexAccess = Reference<XIndexAccess>::query(
                       _xIntrospectionAccess->queryAdapter(
                                getCppuType( (Reference<XIndexAccess>*) NULL ) ) );

                _xIndexContainer = Reference<XIndexContainer>::query(
                     _xIntrospectionAccess->queryAdapter(
                                getCppuType( (Reference<XIndexContainer>*) NULL ) ) );

                _xNameAccess = Reference<XNameAccess>::query(
                     _xIntrospectionAccess->queryAdapter(
                                getCppuType( (Reference<XNameAccess>*) NULL ) ) );

                _xNameContainer = Reference<XNameContainer>::query(
                           _xIntrospectionAccess->queryAdapter(
                               getCppuType( (Reference<XNameContainer>*) NULL ) ) );

                _xPropertySet = Reference<XPropertySet>::query(
                           _xIntrospectionAccess->queryAdapter(
                               getCppuType( (Reference<XPropertySet>*) NULL )) );

                _xENIntrospection = Reference<XExactName>::query( _xIntrospectionAccess );
                if (_xNameAccess.is())
                    _xENNameAccess = Reference<XExactName>::query( _xNameAccess );
            }
        }
        /* only once !!!
        _xDirect = XInvocationRef();
        if( !_xIntrospectionAccess.is() )
        {
            // reset
            _xElementAccess		= XElementAccessRef();
            _xEnumerationAccess = XEnumerationAccessRef();
            _xIndexAccess		= XIndexAccessRef();
            _xIndexContainer	= XIndexContainerRef();
            _xNameAccess		= XNameAccessRef();
            _xNameContainer		= XNameContainerRef();
            _xPropertySet		= XPropertySetRef();
        }
        */
    }
}

//--------------------------------------------------------------------------------------------------
OUString Invocation_Impl::getExactName( const OUString& rApproximateName )
    throw( RuntimeException )
{
    if (_xENDirect.is())
        return _xENDirect->getExactName( rApproximateName );

    OUString aRet;
    if (_xENIntrospection.is())
        aRet = _xENIntrospection->getExactName( rApproximateName );
    if (!aRet.getLength() && _xENNameAccess.is())
        aRet = _xENNameAccess->getExactName( rApproximateName );
    return aRet;
}

//--------------------------------------------------------------------------------------------------
Reference<XIntrospectionAccess>	Invocation_Impl::getIntrospection(void)
    throw( RuntimeException )
{
    if( _xDirect.is() )
        return _xDirect->getIntrospection();
    else
        return _xIntrospectionAccess;
}

//--------------------------------------------------------------------------------------------------
sal_Bool Invocation_Impl::hasMethod( const OUString& Name )
    throw( RuntimeException )
{
    if (_xDirect.is())
        return _xDirect->hasMethod( Name );
    if( _xIntrospectionAccess.is() )
        return _xIntrospectionAccess->hasMethod( Name, MethodConcept::ALL ^ MethodConcept::DANGEROUS );
    return sal_False;
}

//--------------------------------------------------------------------------------------------------
sal_Bool Invocation_Impl::hasProperty( const OUString& Name )
    throw( RuntimeException )
{
    if (_xDirect.is())
        return _xDirect->hasProperty( Name );
    // PropertySet
    if( _xIntrospectionAccess.is()
        && _xIntrospectionAccess->hasProperty( Name, PropertyConcept::ALL ^ PropertyConcept::DANGEROUS ) )
        return sal_True;
    // NameAccess
    if( _xNameAccess.is() )
        return _xNameAccess->hasByName( Name );
    return sal_False;
}

//--------------------------------------------------------------------------------------------------
Any Invocation_Impl::getValue( const OUString& PropertyName )
    throw( UnknownPropertyException, RuntimeException )
{
    if (_xDirect.is())
        return _xDirect->getValue( PropertyName );
    try
    {
        // PropertySet
        if( _xIntrospectionAccess.is() && _xPropertySet.is()
            && _xIntrospectionAccess->hasProperty
            ( PropertyName, PropertyConcept::ALL ^ PropertyConcept::DANGEROUS ) )
        {
            return _xPropertySet->getPropertyValue( PropertyName );
        }
        // NameAccess
        if( _xNameAccess.is() && _xNameAccess->hasByName( PropertyName ) )
            return _xNameAccess->getByName( PropertyName );
    }
    catch (UnknownPropertyException &)
    {
        throw;
    }
    catch (RuntimeException &)
    {
        throw;
    }
    catch (Exception &)
    {
    }
    
    throw UnknownPropertyException(
        OUString( RTL_CONSTASCII_USTRINGPARAM("cannot get value ") ) + PropertyName,
        Reference< XInterface >() );
}

//--------------------------------------------------------------------------------------------------
void Invocation_Impl::setValue( const OUString& PropertyName, const Any& Value )
    throw( UnknownPropertyException, CannotConvertException, InvocationTargetException, RuntimeException )
{
    if (_xDirect.is())
        _xDirect->setValue( PropertyName, Value );
    else
    {
        try
        {
            // Properties
            if( _xIntrospectionAccess.is() && _xPropertySet.is()
                && _xIntrospectionAccess->hasProperty(
                    PropertyName, PropertyConcept::ALL ^ PropertyConcept::DANGEROUS ) )
            {
                Property aProp = _xIntrospectionAccess->getProperty(
                    PropertyName, PropertyConcept::ALL ^ PropertyConcept::DANGEROUS );
                Reference < XIdlClass > r = TypeToIdlClass( aProp.Type, xCoreReflection );
                if( r->isAssignableFrom( TypeToIdlClass( Value.getValueType(), xCoreReflection ) ) )
                    _xPropertySet->setPropertyValue( PropertyName, Value );
                else if( xTypeConverter.is() )
                    _xPropertySet->setPropertyValue(
                        PropertyName, xTypeConverter->convertTo( Value, aProp.Type ) );
                else
                    throw RuntimeException(
                        OUString( RTL_CONSTASCII_USTRINGPARAM("no type converter service!") ),
                        Reference< XInterface >() );
            }
            // NameContainer
            else if( _xNameContainer.is() )
            {
                Any aConv;
                Reference < XIdlClass > r =
                    TypeToIdlClass( _xNameContainer->getElementType(), xCoreReflection );
                if( r->isAssignableFrom(TypeToIdlClass( Value.getValueType(), xCoreReflection ) ) )
                    aConv = Value;
                else if( xTypeConverter.is() )
                    aConv = xTypeConverter->convertTo( Value, _xNameContainer->getElementType() );
                else
                    throw RuntimeException(
                        OUString( RTL_CONSTASCII_USTRINGPARAM("no type converter service!") ),
                        Reference< XInterface >() );
            
                // bei Vorhandensein ersetzen, ansonsten einfuegen
                if (_xNameContainer->hasByName( PropertyName ))
                    _xNameContainer->replaceByName( PropertyName, aConv );
                else
                    _xNameContainer->insertByName( PropertyName, aConv );
            }
            else
                throw UnknownPropertyException(
                    OUString( RTL_CONSTASCII_USTRINGPARAM("no introspection nor name container!") ),
                    Reference< XInterface >() );
        }
        catch (UnknownPropertyException &)
        {
            throw;
        }
        catch (CannotConvertException &)
        {
            throw;
        }
        catch (InvocationTargetException &)
        {
            throw;
        }
        catch (RuntimeException &)
        {
            throw;
        }
        catch (Exception & exc)
        {
            throw InvocationTargetException(
                OUString( RTL_CONSTASCII_USTRINGPARAM("exception occurred in setValue(): ") ) +
                exc.Message, Reference< XInterface >(), makeAny( exc /* though sliced */ ) );
        }
    }
}

//--------------------------------------------------------------------------------------------------
Any Invocation_Impl::invoke( const OUString& FunctionName, const Sequence<Any>& InParams,
                                Sequence<sal_Int16>& OutIndizes, Sequence<Any>& OutParams )
    throw( IllegalArgumentException, CannotConvertException, InvocationTargetException, RuntimeException )
{
    if (_xDirect.is())
        return _xDirect->invoke( FunctionName, InParams, OutIndizes, OutParams );
    
    if (_xIntrospectionAccess.is())
    {
        // throw NoSuchMethodException if not exist
        Reference<XIdlMethod> xMethod = _xIntrospectionAccess->getMethod(
            FunctionName, MethodConcept::ALL ^ MethodConcept::DANGEROUS );
        
        // ParameterInfos
        Sequence<ParamInfo> aFParams		= xMethod->getParameterInfos();
        const ParamInfo* pFParams			= aFParams.getConstArray();
        sal_Int32 nFParamsLen				= aFParams.getLength();
        if (nFParamsLen != InParams.getLength())
        {
            throw IllegalArgumentException(
                OUString( RTL_CONSTASCII_USTRINGPARAM("incorrect number of parameters passed invoking function ") ) + FunctionName,
                (OWeakObject *) this, (sal_Int16) 1 );
        }
        
        // IN Parameter
        const Any* pInParams				= InParams.getConstArray();
        
        // Introspection Invoke Parameter
        Sequence<Any> aInvokeParams( nFParamsLen );
        Any* pInvokeParams					= aInvokeParams.getArray();
        
        // OUT Indizes
        OutIndizes.realloc( nFParamsLen );
        sal_Int16* pOutIndizes				= OutIndizes.getArray();
        sal_uInt32 nOutIndex				= 0;

        for ( sal_Int32 nPos = 0; nPos < nFParamsLen; ++nPos )
        {
            try
            {
                const ParamInfo& rFParam = pFParams[nPos];
                const Reference<XIdlClass>& rDestType = rFParam.aType;
                
                // is IN/INOUT parameter?
                if (rFParam.aMode != ParamMode_OUT)
                {
                    if (rDestType->isAssignableFrom( TypeToIdlClass( pInParams[nPos].getValueType(), xCoreReflection ) ))
                    {
                        pInvokeParams[nPos]	= pInParams[nPos];
                    }
                    else if (xTypeConverter.is())
                    {
                        Type aDestType( rDestType->getTypeClass(), rDestType->getName() );
                        pInvokeParams[nPos]	= xTypeConverter->convertTo( pInParams[nPos], aDestType );
                    }
                    else
                    {
                        CannotConvertException aExc;
                        aExc.Context = *this;
                        aExc.Message = OUString( RTL_CONSTASCII_USTRINGPARAM("invocation type mismatch!") );
                        throw aExc;
                    }
                }
                
                // is OUT/INOUT parameter?
                if (rFParam.aMode != ParamMode_IN)
                {
                    pOutIndizes[nOutIndex] = (sal_Int16)nPos;
                    if (rFParam.aMode == ParamMode_OUT)
                        rDestType->createObject( pInvokeParams[nPos] );		// default init
                    ++nOutIndex;
                }
            }
            catch( CannotConvertException& rExc )
            {
                rExc.ArgumentIndex = nPos;	// optionalen Parameter Index hinzufuegen
                throw rExc;
            }
        }

        // execute Method
        Any aRet = xMethod->invoke( _aMaterial, aInvokeParams );

        // OUT Params
        OutIndizes.realloc( nOutIndex );
        pOutIndizes		   = OutIndizes.getArray();
        OutParams.realloc( nOutIndex );
        Any* pOutParams = OutParams.getArray();
            
        while (nOutIndex--)
        {
            pOutParams[nOutIndex] = pInvokeParams[ pOutIndizes[nOutIndex] ];
        }
            
        return aRet;
    }
    
    RuntimeException aExc;
    aExc.Context = *this;
    aExc.Message = OUString( RTL_CONSTASCII_USTRINGPARAM("invocation lacking of introspection access!") );
    throw aExc;
}

//--------------------------------------------------------------------------------------------------

// Struct to optimize sorting
struct MemberItem
{
    OUString aName;

    // Defines where the member comes from
    enum Mode { NAMEACCESS, PROPERTYSET, METHOD } eMode;

    // Index to respective sequence 
    // (Index to NameAccess sequence for eMode==NAMEACCESS etc.)
    sal_Int32 nIndex;
};

// Implementation of getting name or info
// String sequence will be filled when pStringSeq != NULL
// Info sequence will be filled when pInfoSeq != NULL
void Invocation_Impl::getInfoSequenceImpl
(
    Sequence< OUString >* pStringSeq,
    Sequence< InvocationInfo >* pInfoSeq
)
{
    //Sequence< OUString > aStrSeq;
    //if( !pStringSeq )
        //pStringSeq = &aStrSeq;
    

    // Get all needed sequences
    Sequence<OUString> aNameAccessNames;
    Sequence<Property> aPropertySeq;
    Sequence< Reference< XIdlMethod > > aMethodSeq;

    if( _xNameAccess.is() )
    {
        aNameAccessNames = _xNameAccess->getElementNames();
    }

    if( _xIntrospectionAccess.is() )
    {
        aPropertySeq = _xIntrospectionAccess->getProperties
            ( PropertyConcept::ALL - PropertyConcept::DANGEROUS );
        
        aMethodSeq = _xIntrospectionAccess->getMethods
            ( MethodConcept::ALL - MethodConcept::DANGEROUS );
    }

    sal_Int32 nNameAccessCount = aNameAccessNames.getLength();
    sal_Int32 nPropertyCount = aPropertySeq.getLength();
    sal_Int32 nMethodCount = aMethodSeq.getLength();
    sal_Int32 nTotalCount = nNameAccessCount + nPropertyCount + nMethodCount;

    // Create and fill array of MemberItems
    boost::scoped_array< MemberItem > pItems( new MemberItem[ nTotalCount ] );
    const OUString* pStrings = aNameAccessNames.getConstArray();
    const Property* pProps = aPropertySeq.getConstArray();
    const Reference< XIdlMethod >* pMethods = aMethodSeq.getConstArray();

    // Fill array of MemberItems
    sal_Int32 i, iTotal = 0;

    // Name Access
    for( i = 0 ; i < nNameAccessCount ; i++, iTotal++ )
    {
        MemberItem& rItem = pItems[ iTotal ];
        rItem.aName = pStrings[ i ];
        rItem.eMode = MemberItem::NAMEACCESS;
        rItem.nIndex = i;
    }

    // Property set
    for( i = 0 ; i < nPropertyCount ; i++, iTotal++ )
    {
        MemberItem& rItem = pItems[ iTotal ];
        rItem.aName = pProps[ i ].Name;
        rItem.eMode = MemberItem::PROPERTYSET;
        rItem.nIndex = i;
    }

    // Methods
    for( i = 0 ; i < nMethodCount ; i++, iTotal++ )
    {
        MemberItem& rItem = pItems[ iTotal ];
        Reference< XIdlMethod > xMethod = pMethods[ i ];
        rItem.aName = xMethod->getName();
        rItem.eMode = MemberItem::METHOD;
        rItem.nIndex = i;
    }

    // Setting up result sequences 
    OUString* pRetStrings = NULL;
    if( pStringSeq )
    {
        pStringSeq->realloc( nTotalCount );
        pRetStrings = pStringSeq->getArray();
    }

    InvocationInfo* pRetInfos = NULL;
    if( pInfoSeq )
    {
        pInfoSeq->realloc( nTotalCount );
        pRetInfos = pInfoSeq->getArray();
    }

    // Fill result sequences in the correct order of members
    for( iTotal = 0 ; iTotal < nTotalCount ; iTotal++ )
    {
        MemberItem& rItem = pItems[ iTotal ];
        if( pRetStrings )
        {
            pRetStrings[ iTotal ] = rItem.aName;
        }

        if( pRetInfos )
        {
            if( rItem.eMode == MemberItem::NAMEACCESS )
            {
                fillInfoForNameAccess( pRetInfos[ iTotal ], rItem.aName );
            }
            else if( rItem.eMode == MemberItem::PROPERTYSET )
            {
                fillInfoForProperty( pRetInfos[ iTotal ], pProps[ rItem.nIndex ] );
            }
            else if( rItem.eMode == MemberItem::METHOD )
            {
                fillInfoForMethod( pRetInfos[ iTotal ], pMethods[ rItem.nIndex ] );
            }
        }
    }
}

// XInvocation2
Sequence< OUString > SAL_CALL Invocation_Impl::getMemberNames(  ) 
    throw( RuntimeException )
{
    if( _xDirect2.is() )
    {
        return _xDirect2->getMemberNames();
    }
    Sequence< OUString > aRetSeq;
    getInfoSequenceImpl( &aRetSeq, NULL );
    return aRetSeq;
}

Sequence< InvocationInfo > SAL_CALL Invocation_Impl::getInfo(  ) 
    throw( RuntimeException )
{
    if( _xDirect2.is() )
    {
        return _xDirect2->getInfo();
    }
    Sequence< InvocationInfo > aRetSeq;
    getInfoSequenceImpl( NULL, &aRetSeq );
    return aRetSeq;
}

InvocationInfo SAL_CALL Invocation_Impl::getInfoForName( const OUString& aName, sal_Bool bExact ) 
    throw( IllegalArgumentException, RuntimeException )
{
    if( _xDirect2.is() )
    {
        return _xDirect2->getInfoForName( aName, bExact );
    }

    sal_Bool bFound = sal_False;
    OUString aExactName = aName;
    InvocationInfo aRetInfo;

    if( bExact )
        aExactName = getExactName( aName );
    if( aExactName.getLength() > 0 )
    {
        if( _xIntrospectionAccess->hasMethod( aExactName, MethodConcept::ALL ^ MethodConcept::DANGEROUS ) )
        {
            Reference<XIdlMethod> xMethod = _xIntrospectionAccess->getMethod
                ( aExactName, MethodConcept::ALL ^ MethodConcept::DANGEROUS );
            fillInfoForMethod( aRetInfo, xMethod );
            bFound = sal_True;
        }
        else
        {
            if( _xIntrospectionAccess.is() && _xIntrospectionAccess->hasProperty
                 ( aExactName, PropertyConcept::ALL ^ PropertyConcept::DANGEROUS ) )
            {
                 Property aProp = _xIntrospectionAccess->getProperty
                    ( aExactName, PropertyConcept::ALL ^ PropertyConcept::DANGEROUS );
                fillInfoForProperty( aRetInfo, aProp );
                bFound = sal_True;
            }
            // NameAccess
            else if( _xNameAccess.is() && _xNameAccess->hasByName( aExactName ) )
            {
                fillInfoForNameAccess( aRetInfo, aExactName );
                bFound = sal_True;
            }
        }
    }
    if( !bFound )
    {
        throw IllegalArgumentException(
            OUString( RTL_CONSTASCII_USTRINGPARAM("Unknown name, getExactName() failed!") ),
            (XWeak *)(OWeakObject *)this, 0 );
    }
    return aRetInfo;
}

// Helper functions to fill InvocationInfo for XNameAccess
void Invocation_Impl::fillInfoForNameAccess
(
    InvocationInfo& rInfo, 
    const OUString& aName
)
{
    rInfo.aName = aName;
    rInfo.eMemberType = MemberType_PROPERTY;
    rInfo.PropertyAttribute = 0;
    if( !_xNameContainer.is() )
    {
        rInfo.PropertyAttribute = PropertyAttribute::READONLY;
    }
    rInfo.aType = _xNameAccess->getElementType();
}

void Invocation_Impl::fillInfoForProperty
( 
    InvocationInfo& rInfo, 
    const Property& rProp 
)
{
    rInfo.aName = rProp.Name;
    rInfo.eMemberType = MemberType_PROPERTY;
    rInfo.PropertyAttribute = rProp.Attributes;
    rInfo.aType = rProp.Type;
}

void Invocation_Impl::fillInfoForMethod
(
    InvocationInfo& rInfo, 
    const Reference< XIdlMethod > xMethod
)
{
    rInfo.aName = xMethod->getName();
    rInfo.eMemberType = MemberType_METHOD;
    Reference< XIdlClass > xReturnClass = xMethod->getReturnType();
    Type aReturnType( xReturnClass->getTypeClass(), xReturnClass->getName() );
    rInfo.aType = aReturnType;
    Sequence<ParamInfo> aParamInfos = xMethod->getParameterInfos();
    sal_Int32 nParamCount = aParamInfos.getLength();
    if( nParamCount > 0 )
    {
        const ParamInfo* pInfos = aParamInfos.getConstArray();

        rInfo.aParamTypes.realloc( nParamCount );
        Type* pParamTypes = rInfo.aParamTypes.getArray();
        rInfo.aParamModes.realloc( nParamCount );
        ParamMode* pParamModes = rInfo.aParamModes.getArray();

        for( sal_Int32 i = 0 ; i < nParamCount ; i++ )
        {
            Reference< XIdlClass > xParamClass = pInfos[i].aType;
            Type aParamType( xParamClass->getTypeClass(), xParamClass->getName() );
            pParamTypes[ i ] = aParamType;
            pParamModes[ i ] = pInfos[i].aMode;
        }
    }
}


// XTypeProvider
Sequence< Type > SAL_CALL Invocation_Impl::getTypes(void) throw( RuntimeException )
{
    static Sequence< Type > const * s_pTypes = 0;
    if (! s_pTypes)
    {
        Sequence< Type > types( 4 +8 );
        Type * pTypes = types.getArray();
        sal_Int32 n = 0;
        
        pTypes[ n++ ] = ::getCppuType( (Reference< XTypeProvider > const *)0 );
        pTypes[ n++ ] = ::getCppuType( (Reference< XWeak > const *)0 );
        pTypes[ n++ ] = ::getCppuType( (Reference< XInvocation > const *)0 );
        pTypes[ n++ ] = ::getCppuType( (Reference< XMaterialHolder > const *)0 );
        
        // Ivocation does not support XExactName, if direct object supports
        // XInvocation, but not XExactName.
        if ((_xDirect.is() && _xENDirect.is()) ||
            (!_xDirect.is() && (_xENIntrospection.is() || _xENNameAccess.is())))
        {
            pTypes[ n++ ] = ::getCppuType( (Reference< XExactName > const *)0 );
        }
        if( _xNameContainer.is() )
        {
            pTypes[ n++ ] = ::getCppuType( (Reference< XNameContainer > const *)0 );
        }
        if( _xNameAccess.is() )
        {
            pTypes[ n++ ] = ::getCppuType( (Reference< XNameAccess > const *)0 );
        }
        if (_xIndexContainer.is())
        {
            pTypes[ n++ ] = ::getCppuType( (Reference< XIndexContainer > const *)0 );
        }
        if (_xIndexAccess.is())
        {
            pTypes[ n++ ] = ::getCppuType( (Reference< XIndexAccess > const *)0 );
        }
        if (_xEnumerationAccess.is())
        {
            pTypes[ n++ ] = ::getCppuType( (Reference< XEnumerationAccess > const *)0 );
        }
        if (_xElementAccess.is())
        {
            pTypes[ n++ ] = ::getCppuType( (Reference< XElementAccess > const *)0 );
        }
        // Invocation does not support XInvocation2, if direct object supports
        // XInvocation, but not XInvocation2.
        if ( ( _xDirect.is() && _xDirect2.is()) ||
             (!_xDirect.is() && _xIntrospectionAccess.is() ) )
        {
            pTypes[ n++ ] = ::getCppuType( (Reference< XInvocation2 > const *)0 );
        }
        
        types.realloc( n );
        
        // store types
        MutexGuard guard( Mutex::getGlobalMutex() );
        if (! s_pTypes)
        {
            static Sequence< Type > s_types( types );
            s_pTypes = &s_types;
        }
    }
    return *s_pTypes;
}

Sequence< sal_Int8 > SAL_CALL Invocation_Impl::getImplementationId(  ) throw( RuntimeException)
{
    static OImplementationId *pId = 0;
    if( ! pId )
    {
        MutexGuard guard( Mutex::getGlobalMutex() );
        if( ! pId )
        {
            static OImplementationId id( sal_False );
            pId = &id;
        }
    }
    return pId->getImplementationId();
}

//==================================================================================================
//==================================================================================================
//==================================================================================================
class InvocationService
    : public WeakImplHelper2< XSingleServiceFactory, XServiceInfo >
{
public:
    InvocationService( const Reference<XComponentContext> & xCtx );
    virtual ~InvocationService();
    
    // XServiceInfo
    OUString 					SAL_CALL getImplementationName() throw( RuntimeException );
    sal_Bool 						SAL_CALL supportsService(const OUString& ServiceName) throw( RuntimeException );
    Sequence< OUString > 		SAL_CALL getSupportedServiceNames(void) throw( RuntimeException );

    // XSingleServiceFactory
    Reference<XInterface>		SAL_CALL createInstance(void) throw( Exception, RuntimeException );
    Reference<XInterface>		SAL_CALL createInstanceWithArguments(
        const Sequence<Any>& rArguments ) throw( Exception, RuntimeException );
private:
    Reference<XComponentContext> mxCtx;
    Reference<XMultiComponentFactory> mxSMgr;
    Reference<XTypeConverter> xTypeConverter;
    Reference<XIntrospection> xIntrospection;
    Reference<XIdlReflection> xCoreReflection;
};

InvocationService::InvocationService( const Reference<XComponentContext> & xCtx )
    : mxCtx( xCtx )
    , mxSMgr( xCtx->getServiceManager() )
{
    g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
    xTypeConverter = Reference<XTypeConverter>(
        mxSMgr->createInstanceWithContext(
            OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.script.Converter")),
            xCtx ),
        UNO_QUERY );
    xIntrospection = Reference<XIntrospection>(
        mxSMgr->createInstanceWithContext(
            OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.beans.Introspection")),
            xCtx),
        UNO_QUERY);
    mxCtx->getValueByName(
        OUString(
            RTL_CONSTASCII_USTRINGPARAM("/singletons/com.sun.star.reflection.theCoreReflection")) )
                >>= xCoreReflection;
    OSL_ENSURE( xCoreReflection.is(), "### CoreReflection singleton not accessable!?" );
    if (! xCoreReflection.is())
    {
        throw DeploymentException(
            OUString( RTL_CONSTASCII_USTRINGPARAM("/singletons/com.sun.star.reflection.theCoreReflection singleton not accessable") ),
            Reference< XInterface >() );
    }
//         xCoreReflection = Reference<XIdlReflection>(
// 		mxSMgr->createInstanceWithContext(
// 			OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.reflection.CoreReflection")),
// 			xCtx),
// 		UNO_QUERY);
}

InvocationService::~InvocationService()
{
    g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
}

// XServiceInfo
OUString InvocationService::getImplementationName() throw( RuntimeException )
{
    return inv_getImplementationName();
}

// XServiceInfo
sal_Bool InvocationService::supportsService(const OUString& ServiceName) throw( RuntimeException )
{
    Sequence< OUString > aSNL = getSupportedServiceNames();
    const OUString * pArray = aSNL.getConstArray();
    for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
        if( pArray[i] == ServiceName )
            return sal_True;
    return sal_False;
}

// XServiceInfo
Sequence< OUString > InvocationService::getSupportedServiceNames(void) throw( RuntimeException )
{
    return inv_getSupportedServiceNames();
}

//--------------------------------------------------------------------------------------------------
Reference<XInterface> InvocationService::createInstance(void) throw( Exception, RuntimeException )
{
    //TODO:throw( Exception(OUString( RTL_CONSTASCII_USTRINGPARAM("no default construction of invocation adapter possible!")), *this) );
    return Reference<XInterface>(); // dummy
}

//--------------------------------------------------------------------------------------------------
Reference<XInterface> InvocationService::createInstanceWithArguments(
    const Sequence<Any>& rArguments ) throw( Exception, RuntimeException )
{
    if (rArguments.getLength() == 1)
    {
        return Reference< XInterface > 
            ( *new Invocation_Impl( *rArguments.getConstArray(), 
              xTypeConverter, xIntrospection, xCoreReflection ) );
    }
    else
    {
        //TODO:throw( Exception(OUString( RTL_CONSTASCII_USTRINGPARAM("no default construction of invocation adapter possible!")), *this) );
        return Reference<XInterface>();
    }
}


//*************************************************************************
Reference<XInterface> SAL_CALL InvocationService_CreateInstance( const Reference<XComponentContext> & xCtx ) 
    throw( RuntimeException )
{
    Reference<XInterface> xService = Reference< XInterface > ( *new InvocationService( xCtx ) );
    return xService;
}

}

using namespace stoc_inv;
static struct ImplementationEntry g_entries[] =
{
    {
        InvocationService_CreateInstance, inv_getImplementationName,
        inv_getSupportedServiceNames, createSingleComponentFactory,
        &g_moduleCount.modCnt , 0
    },
    { 0, 0, 0, 0, 0, 0 }
};

extern "C"
{
sal_Bool SAL_CALL component_canUnload( TimeValue *pTime )
{
    return g_moduleCount.canUnload( &g_moduleCount , pTime );
}

//==================================================================================================
SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment(
    const sal_Char ** ppEnvTypeName, uno_Environment ** )
{
    *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
}
//==================================================================================================
SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(
    const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey )
{
    return component_getFactoryHelper( pImplName, pServiceManager, pRegistryKey , g_entries );
}
}



/* vim:set shiftwidth=4 softtabstop=4 expandtab: */