summaryrefslogtreecommitdiff
path: root/odk/examples/java/Inspector/Introspector.java
blob: db4c40b2fecb0bb5ab39cf381ea4a4f907e39df1 (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
/*************************************************************************
 *
 *  The Contents of this file are made available subject to the terms of
 *  the BSD license.
 *
 *  Copyright 2000, 2010 Oracle and/or its affiliates.
 *  All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *  1. Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *  2. Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 *  3. Neither the name of Sun Microsystems, Inc. nor the names of its
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 *  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
 *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
 *  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *************************************************************************/

import java.util.ArrayList;
import java.util.List;

import com.sun.star.beans.IllegalTypeException;
import com.sun.star.beans.MethodConcept;
import com.sun.star.beans.Property;
import com.sun.star.beans.XIntrospection;
import com.sun.star.beans.XIntrospectionAccess;
import com.sun.star.container.XEnumeration;
import com.sun.star.container.XEnumerationAccess;
import com.sun.star.container.XHierarchicalNameAccess;
import com.sun.star.container.XIndexAccess;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.lang.XServiceInfo;
import com.sun.star.lang.XTypeProvider;
import com.sun.star.lib.uno.helper.WeakBase;
import com.sun.star.reflection.TypeDescriptionSearchDepth;
import com.sun.star.reflection.XConstantTypeDescription;
import com.sun.star.reflection.XConstantsTypeDescription;
import com.sun.star.reflection.XIdlClass;
import com.sun.star.reflection.XIdlField;
import com.sun.star.reflection.XIdlMethod;
import com.sun.star.reflection.XIdlReflection;
import com.sun.star.reflection.XIndirectTypeDescription;
import com.sun.star.reflection.XInterfaceTypeDescription;
import com.sun.star.reflection.XPropertyTypeDescription;
import com.sun.star.reflection.XServiceTypeDescription;
import com.sun.star.reflection.XTypeDescription;
import com.sun.star.reflection.XTypeDescriptionEnumeration;
import com.sun.star.reflection.XTypeDescriptionEnumerationAccess;
import com.sun.star.ucb.XSimpleFileAccess;
import com.sun.star.uno.AnyConverter;
import com.sun.star.uno.Type;
import com.sun.star.uno.TypeClass;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;

public class Introspector extends WeakBase{

    private XIntrospection m_xIntrospection;
    private XMultiComponentFactory m_xMultiComponentFactory;
    private XComponentContext m_xComponentContext;
    private XTypeDescriptionEnumerationAccess m_xTDEnumerationAccess;
    private XIdlReflection mxIdlReflection;
    private static Introspector m_oIntrospector = null;
    private XSimpleFileAccess xSimpleFileAccess = null;



    public static Introspector getIntrospector(){
        if (m_oIntrospector == null){
            throw new NullPointerException();
        }
        else{
            return m_oIntrospector;
        }
    }

    public static Introspector getIntrospector(XComponentContext _xComponentContext){
        if (m_oIntrospector == null){
            m_oIntrospector =  new Introspector(_xComponentContext);
        }
        return m_oIntrospector;
    }


    /** Creates a new instance of Introspection */
    private Introspector(XComponentContext _xComponentContext) {
    try{
        m_xComponentContext = _xComponentContext;
        m_xMultiComponentFactory = m_xComponentContext.getServiceManager();
        Object o = m_xMultiComponentFactory.createInstanceWithContext("com.sun.star.beans.Introspection", m_xComponentContext);
        m_xIntrospection = UnoRuntime.queryInterface(XIntrospection.class, o );
        Object oCoreReflection = getXMultiComponentFactory().createInstanceWithContext("com.sun.star.reflection.CoreReflection", getXComponentContext());
        mxIdlReflection = UnoRuntime.queryInterface(XIdlReflection.class, oCoreReflection);
        initTypeDescriptionManager();
    }
    catch( Exception exception ) {
        System.err.println( exception );
    }}


    protected XComponentContext getXComponentContext(){
        return m_xComponentContext;
    }


    private XMultiComponentFactory getXMultiComponentFactory(){
        return m_xMultiComponentFactory;
    }


    protected XIntrospectionAccess getXIntrospectionAccess(Object _oUnoComponent){
        return m_xIntrospection.inspect(_oUnoComponent);
    }


    public boolean isContainer(Object _oUnoObject){
    boolean bIsContainer = false;
    try {
        XIntrospectionAccess xIntrospectionAccessObject = getXIntrospectionAccess(_oUnoObject);
        if (xIntrospectionAccessObject != null){
            XEnumerationAccess xEnumerationAccess = UnoRuntime.queryInterface(XEnumerationAccess.class, xIntrospectionAccessObject.queryAdapter( new Type( XEnumerationAccess.class ) ) );
            if (xEnumerationAccess != null){
                XEnumeration xEnumeration = xEnumerationAccess.createEnumeration();
                bIsContainer = xEnumeration.hasMoreElements();
            }
            if (!bIsContainer){
                XIndexAccess xIndexAccess = UnoRuntime.queryInterface( XIndexAccess.class, xIntrospectionAccessObject.queryAdapter(new Type( XIndexAccess.class )));
                if (xIndexAccess != null){
                    bIsContainer = (xIndexAccess.getCount() > 0);
                }
            }
        }
    } catch (IllegalTypeException ex) {
        ex.printStackTrace(System.err);
    }
        return bIsContainer;
    }


    //  add all containers for the given object to the tree under the node
    //  parent
    public Object[] getUnoObjectsOfContainer(Object _oUnoParentObject) {
    Object[] oRetComponents = null;
    try {
        ArrayList<Object> oRetComponentsVector = new ArrayList<Object>();
        XIntrospectionAccess xIntrospectionAccessObject = getXIntrospectionAccess(_oUnoParentObject);
        if ( xIntrospectionAccessObject != null ) {
            XEnumerationAccess xEnumerationAccess = UnoRuntime.queryInterface(XEnumerationAccess.class, xIntrospectionAccessObject.queryAdapter( new Type( XEnumerationAccess.class ) ) );
            if ( xEnumerationAccess != null ) {
                XEnumeration xEnumeration = xEnumerationAccess.createEnumeration();
                while ( xEnumeration.hasMoreElements() ) {
                    oRetComponentsVector.add(xEnumeration.nextElement());
                }
            }
            XIndexAccess xIndexAccess = UnoRuntime.queryInterface( XIndexAccess.class, xIntrospectionAccessObject.queryAdapter(new Type( XIndexAccess.class )));
            if ( xIndexAccess != null ) {
                XIdlMethod mMethod = xIntrospectionAccessObject.getMethod("getByIndex", com.sun.star.beans.MethodConcept.INDEXCONTAINER);
                for ( int i = 0; i < xIndexAccess.getCount(); i++ ) {
                    Object[][] aParamInfo = new Object[1][1];
                    aParamInfo[0] = new Integer[] { new Integer(i) };
                    oRetComponentsVector.add(mMethod.invoke(_oUnoParentObject, aParamInfo));
                }
            }
        }
        if (oRetComponentsVector != null){
            oRetComponents = new Object[oRetComponentsVector.size()];
            oRetComponentsVector.toArray(oRetComponents);
        }
    }
    catch( Exception exception ) {
        System.err.println( exception );
    }
    return oRetComponents;
    }


    protected XIdlMethod[] getMethodsOfInterface(Type _aType){
    try{
        XIdlClass xIdlClass = mxIdlReflection.forName(_aType.getTypeName());
        return xIdlClass.getMethods();
    }
    catch( Exception e ) {
        System.err.println( e );
        return null;
    }}





    public boolean hasMethods(Object _oUnoObject){
        boolean bHasMethods = (getMethods(_oUnoObject).length > 0);
        return bHasMethods;
    }


    //  add all methods for the given object to the tree under the node parent
    public XIdlMethod[] getMethods(Object _oUnoParentObject) {
    try {
        XIntrospectionAccess xIntrospectionAccess = getXIntrospectionAccess(_oUnoParentObject);
        if (xIntrospectionAccess != null){
            XIdlMethod[] xIdlMethods = xIntrospectionAccess.getMethods(MethodConcept.ALL - MethodConcept.DANGEROUS);
            return xIdlMethods;
        }
    }
    catch( Exception e ) {
        System.err.println( e );
    }
    return null;
    }


    public boolean hasProperties(Object _oUnoObject){
        boolean bHasProperties = (getProperties(_oUnoObject).length > 0);
        return bHasProperties;
    }


    protected Property[] getProperties( Object _oUnoParentObject){
    try {
        XIntrospectionAccess xIntrospectionAccess = getXIntrospectionAccess(_oUnoParentObject);
        if (xIntrospectionAccess != null){
            Property[] aProperties = xIntrospectionAccess.getProperties(com.sun.star.beans.PropertyConcept.ATTRIBUTES + com.sun.star.beans.PropertyConcept.PROPERTYSET);
            return aProperties;
        }
    }
    catch( Exception e ) {
        System.err.println( e );
    }
        return null;
    }


    protected Property[] getProperties(Object _oUnoObject, String _sServiceName){
        Property[] aProperties = getProperties(_oUnoObject);
        List<Property> aListOfProperties = java.util.Arrays.asList(aProperties);
        ArrayList<Property> aPropertiesVector = new ArrayList<Property>(aListOfProperties);
        if (aProperties != null){
            XPropertyTypeDescription[] xPropertyTypeDescriptions = getPropertyDescriptionsOfService(_sServiceName);
            for (int i = aProperties.length - 1; i >= 0; i--){
                if (!hasByName(xPropertyTypeDescriptions, _sServiceName + "." + aProperties[i].Name)){
                    aPropertiesVector.remove(i);
                }
            }
        }
        Property[] aRetProperties = new Property[aPropertiesVector.size()];
        aPropertiesVector.toArray(aRetProperties);
        return aRetProperties;
    }


    protected Type[] getInterfaces(Object _oUnoObject, String _sServiceName){
        Type[] aTypes = getInterfaces(_oUnoObject);
        List<Type> aListOfTypes = java.util.Arrays.asList(aTypes);
        ArrayList<Type> aTypesVector = new ArrayList<Type>(aListOfTypes);
        if (aTypes != null){
            XInterfaceTypeDescription[] xInterfaceTypeDescriptions = getInterfaceDescriptionsOfService(_sServiceName);
            for (int i = aTypes.length - 1; i >= 0; i--){
                if (!hasByName(xInterfaceTypeDescriptions, aTypes[i].getTypeName())){
                    aTypesVector.remove(i);
                }
            }
        }
        Type[] aRetTypes = new Type[aTypesVector.size()];
        aTypesVector.toArray(aRetTypes);
        return aRetTypes;
    }


    public boolean hasInterfaces(Object _oUnoObject){
        return (getInterfaces(_oUnoObject).length > 0);
    }


    protected Type[] getInterfaces(Object _oUnoParentObject){
        Type[] aTypes = new Type[]{};
        XTypeProvider xTypeProvider = UnoRuntime.queryInterface( XTypeProvider.class, _oUnoParentObject);
        if ( xTypeProvider != null ) {
            aTypes = xTypeProvider.getTypes();
        }
        return aTypes;
    }



    public static boolean isObjectSequence(Object _oUnoObject){
        Type aType = AnyConverter.getType(_oUnoObject);
        return aType.getTypeClass().getValue() == TypeClass.SEQUENCE_value;
    }


    public static boolean isObjectPrimitive(Object _oUnoObject){
        boolean breturn = false;
        if (_oUnoObject != null){
            Type aType = AnyConverter.getType(_oUnoObject);
            breturn = isObjectPrimitive(_oUnoObject.getClass(), aType.getTypeClass());
        }
        return breturn;
    }


    public static boolean isPrimitive(TypeClass _typeClass){
               return (( _typeClass == TypeClass.BOOLEAN )
                     || ( _typeClass == TypeClass.BYTE )
                     || ( _typeClass == TypeClass.CHAR )
                     || ( _typeClass == TypeClass.DOUBLE )
                     || ( _typeClass == TypeClass.ENUM )
                     || ( _typeClass == TypeClass.FLOAT )
                     || ( _typeClass == TypeClass.HYPER )
                     || ( _typeClass == TypeClass.LONG )
                     || ( _typeClass == TypeClass.SHORT )
                     || ( _typeClass == TypeClass.STRING )
                     || ( _typeClass == TypeClass.UNSIGNED_HYPER )
                     || ( _typeClass == TypeClass.UNSIGNED_LONG )
                     || ( _typeClass == TypeClass.UNSIGNED_SHORT ));
    }

    public static boolean isObjectPrimitive(Class<? extends Object> _oUnoClass, TypeClass _typeClass){
        return !( ( !_oUnoClass.isPrimitive() ) && ( _typeClass != TypeClass.ARRAY )
                                                         && ( _typeClass != TypeClass.BOOLEAN )
                                                         && ( _typeClass != TypeClass.BYTE )
                                                         && ( _typeClass != TypeClass.CHAR )
                                                         && ( _typeClass != TypeClass.DOUBLE )
                                                         && ( _typeClass != TypeClass.ENUM )
                                                         && ( _typeClass != TypeClass.FLOAT )
                                                         && ( _typeClass != TypeClass.HYPER )
                                                         && ( _typeClass != TypeClass.LONG )
                                                         && ( _typeClass != TypeClass.SHORT )
                                                         && ( _typeClass != TypeClass.STRING )
                                                         && ( _typeClass != TypeClass.UNSIGNED_HYPER )
                                                         && ( _typeClass != TypeClass.UNSIGNED_LONG )
                                                         && ( _typeClass != TypeClass.UNSIGNED_SHORT ));
    }


    private void initTypeDescriptionManager() {
    try {
        Object oTypeDescriptionManager = getXComponentContext().getValueByName("/singletons/com.sun.star.reflection.theTypeDescriptionManager");
        m_xTDEnumerationAccess = UnoRuntime.queryInterface(XTypeDescriptionEnumerationAccess.class, oTypeDescriptionManager);
    } catch ( java.lang.Exception e) {
        System.out.println(System.out);
    }}


    private XTypeDescriptionEnumerationAccess getXTypeDescriptionEnumerationAccess(){
        return m_xTDEnumerationAccess;
    }


    protected XConstantTypeDescription[] getFieldsOfConstantGroup(String _sTypeClass){
    XConstantTypeDescription[] xConstantTypeDescriptions = null;
    try {
        TypeClass[] eTypeClasses = new com.sun.star.uno.TypeClass[1];
        eTypeClasses[0] = com.sun.star.uno.TypeClass.CONSTANTS;
        XTypeDescriptionEnumeration xTDEnumeration = m_xTDEnumerationAccess.createTypeDescriptionEnumeration(getModuleName(_sTypeClass), eTypeClasses, TypeDescriptionSearchDepth.INFINITE);
        while (xTDEnumeration.hasMoreElements()) {
            XTypeDescription xTD = xTDEnumeration.nextTypeDescription();
            if (xTD.getName().equals(_sTypeClass)){
                XConstantsTypeDescription xConstantsTypeDescription = UnoRuntime.queryInterface(XConstantsTypeDescription.class, xTD);
                xConstantTypeDescriptions = xConstantsTypeDescription.getConstants();
            }
            String sName = xTD.getName();
        }
        return xConstantTypeDescriptions;
    } catch ( java.lang.Exception e) {
        System.out.println(System.out);
    }
        return null;
    }

    private XServiceTypeDescription getServiceTypeDescription(String _sServiceName, TypeClass _eTypeClass){
    try{
        if (_sServiceName.length() > 0){
            TypeClass[] eTypeClasses = new com.sun.star.uno.TypeClass[2];
            eTypeClasses[0] = com.sun.star.uno.TypeClass.SERVICE;
            eTypeClasses[1] = _eTypeClass;
            XTypeDescriptionEnumeration xTDEnumeration = getXTypeDescriptionEnumerationAccess().createTypeDescriptionEnumeration(Introspector.getModuleName(_sServiceName), eTypeClasses, TypeDescriptionSearchDepth.INFINITE);
            while (xTDEnumeration.hasMoreElements()) {
                XTypeDescription xTD = xTDEnumeration.nextTypeDescription();
                if (xTD.getName().equals(_sServiceName)){
                    XServiceTypeDescription xServiceTypeDescription = UnoRuntime.queryInterface(XServiceTypeDescription.class, xTD);
                    return xServiceTypeDescription;
                }
            }
        }
        return null;
    } catch (Exception ex) {
        ex.printStackTrace(System.err);
        return null;
    }}


    public XPropertyTypeDescription[] getPropertyDescriptionsOfService(String _sServiceName){
    try {
        XServiceTypeDescription xServiceTypeDescription = getServiceTypeDescription(_sServiceName, com.sun.star.uno.TypeClass.PROPERTY);
        if (xServiceTypeDescription != null){
            XPropertyTypeDescription[] xPropertyTypeDescriptions = xServiceTypeDescription.getProperties();
            return xPropertyTypeDescriptions;
        }
    } catch ( java.lang.Exception e) {
        System.out.println(System.out);
    }
    return new XPropertyTypeDescription[]{};
    }


    public XTypeDescription getReferencedType(String _sTypeName){
    XTypeDescription xTypeDescription = null;
    try{
        XHierarchicalNameAccess xHierarchicalNameAccess = UnoRuntime.queryInterface(XHierarchicalNameAccess.class, m_xTDEnumerationAccess);
        if (xHierarchicalNameAccess != null){
            if (xHierarchicalNameAccess.hasByHierarchicalName(_sTypeName)){
                XIndirectTypeDescription xIndirectTypeDescription = UnoRuntime.queryInterface(XIndirectTypeDescription.class, xHierarchicalNameAccess.getByHierarchicalName(_sTypeName));
                if (xIndirectTypeDescription != null){
                    xTypeDescription = xIndirectTypeDescription.getReferencedType();
                }
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace(System.err);
    }
        return xTypeDescription;
    }


    private XInterfaceTypeDescription[] getInterfaceDescriptionsOfService(String _sServiceName){
    try {
        XServiceTypeDescription xServiceTypeDescription = getServiceTypeDescription(_sServiceName, com.sun.star.uno.TypeClass.INTERFACE);
        if (xServiceTypeDescription != null){
            XInterfaceTypeDescription[] xInterfaceTypeDescriptions = xServiceTypeDescription.getMandatoryInterfaces();
            return xInterfaceTypeDescriptions;
        }
    } catch ( java.lang.Exception e) {
        System.out.println(System.out);
    }
        return new XInterfaceTypeDescription[]{};
    }


    private static boolean hasByName(XTypeDescription[] _xTypeDescriptions, String _sTypeName){
        for (int i = 0; i < _xTypeDescriptions.length; i++){
            if (_xTypeDescriptions[i].getName().equals(_sTypeName)){
                return true;
            }
        }
        return false;
    }


    public static String getModuleName(String _sTypeClass){
        int nlastindex = _sTypeClass.lastIndexOf(".");
        if (nlastindex > -1){
            return _sTypeClass.substring(0, nlastindex);
        }
        else{
            return "";
        }
    }


    public static String getShortClassName(String _sClassName){
        String sShortClassName = _sClassName;
        int nindex = _sClassName.lastIndexOf(".");
        if ((nindex < _sClassName.length()) && nindex > -1){
            sShortClassName = _sClassName.substring(nindex + 1);
        }
        return sShortClassName;
    }



    public static boolean isUnoTypeObject(Object _oUnoObject){
        return isOfUnoType(_oUnoObject, "com.sun.star.uno.Type");
    }


    public static boolean isUnoPropertyTypeObject(Object _oUnoObject){
        return isOfUnoType(_oUnoObject, "com.sun.star.beans.Property");
    }


    public static boolean isUnoPropertyValueTypeObject(Object _oUnoObject){
        return isOfUnoType(_oUnoObject, "com.sun.star.beans.PropertyValue");
    }


    private static boolean isOfUnoType(Object _oUnoObject, String _sTypeName){
        boolean bIsUnoObject = false;
        if (_oUnoObject != null){
            if (_oUnoObject.getClass().isArray()){
                if (!_oUnoObject.getClass().getComponentType().isPrimitive()){
                    Object[] oUnoArray = (Object[]) _oUnoObject;
                    if (oUnoArray.length > 0){
                        bIsUnoObject = ( oUnoArray[0].getClass().getName().equals(_sTypeName));
                    }
                }
            }
        }
        else{
            bIsUnoObject = (_oUnoObject.getClass().getName().equals(_sTypeName));
        }
        return bIsUnoObject;
    }


    public String getConstantDisplayString(int _nValue, XConstantTypeDescription[] _xConstantTypeDescription, String _sDisplayString){
        String sPrefix = "";
        int[] nbits = new int[_xConstantTypeDescription.length];
        for (int i = 0; i < _xConstantTypeDescription.length; i++){
            short nConstantValue = ((Short) _xConstantTypeDescription[i].getConstantValue()).shortValue();
            nbits[i] = _nValue & nConstantValue;
            if (nbits[i] > 0){
                _sDisplayString += sPrefix + _xConstantTypeDescription[i].getName();
                sPrefix = " + ";
            }
        }
        return _sDisplayString;
    }


    public static boolean isValid(Object[] _oObject){
        if (_oObject != null){
            if (_oObject.length > 0){
                return true;
            }
        }
        return false;
    }





    public static boolean isArray(Object _oObject){
        return _oObject.getClass().isArray();
    }


    public boolean hasSupportedServices(Object _oUnoObject){
        boolean bHasSupportedServices = false;
        XServiceInfo xServiceInfo = UnoRuntime.queryInterface( XServiceInfo.class, _oUnoObject);
        if ( xServiceInfo != null ){
            String[] sSupportedServiceNames = xServiceInfo.getSupportedServiceNames();
            bHasSupportedServices = sSupportedServiceNames.length > 0;
        }
        return bHasSupportedServices;
    }


    public Object getValueOfText(TypeClass aTypeClass, String sText){
        Object oReturn = null;
        switch (aTypeClass.getValue()){
            case TypeClass.CHAR_value:
                break;
            case TypeClass.DOUBLE_value:
                oReturn = Double.valueOf(sText);
                break;
            case TypeClass.ENUM_value:
                break;
            case TypeClass.FLOAT_value:
                oReturn = Float.valueOf(sText);
                break;
            case TypeClass.HYPER_value:
                oReturn = Long.valueOf(sText);
                break;
            case TypeClass.LONG_value:
                oReturn = Integer.valueOf(sText);
                break;
            case TypeClass.SHORT_value:
                oReturn = Byte.valueOf(sText);
                break;
            case TypeClass.STRING_value:
                oReturn = sText;
                break;
            case TypeClass.UNSIGNED_HYPER_value:
                oReturn = Long.valueOf(sText);
                break;
            case TypeClass.UNSIGNED_LONG_value:
                oReturn = Integer.valueOf(sText);
                break;
            case TypeClass.UNSIGNED_SHORT_value:
                oReturn = Byte.valueOf(sText);
                break;
            default:
        }
        return oReturn;
    }


    public XSimpleFileAccess getXSimpleFileAccess(){
    try {
        if (xSimpleFileAccess == null){
            Object oSimpleFileAccess = m_xComponentContext.getServiceManager().createInstanceWithContext("com.sun.star.ucb.SimpleFileAccess", m_xComponentContext);
            xSimpleFileAccess = com.sun.star.uno.UnoRuntime.queryInterface(XSimpleFileAccess.class, oSimpleFileAccess);
        }
        return xSimpleFileAccess;
    } catch (com.sun.star.uno.Exception ex) {
        ex.printStackTrace(System.err);
        return null;
    }}


    public boolean isValidSDKInstallationPath(String _sSDKInstallationPath){
    boolean bIsValid = false;
    try {
        String sIDLFolder = Introspector.addToPath(_sSDKInstallationPath, Inspector.sIDLDOCUMENTSUBFOLDER);
        String sIndexFile = Introspector.addToPath(_sSDKInstallationPath, "index.html");
        if (getXSimpleFileAccess() != null){
            bIsValid = (getXSimpleFileAccess().exists(sIDLFolder) && getXSimpleFileAccess().exists(sIndexFile));
        }
    } catch (com.sun.star.uno.Exception ex) {
        ex.printStackTrace(System.err);
    }
        return bIsValid;
    }


    public static String addToPath(String _sPath, String _sSubPath){
        if (!_sPath.endsWith("/")){
            _sPath += "/";
        }
        return _sPath + _sSubPath;
    }

}