1 /*************************************************************************
2  *
3  *  The Contents of this file are made available subject to the terms of
4  *  the BSD license.
5  *
6  *  Copyright 2000, 2010 Oracle and/or its affiliates.
7  *  All rights reserved.
8  *
9  *  Redistribution and use in source and binary forms, with or without
10  *  modification, are permitted provided that the following conditions
11  *  are met:
12  *  1. Redistributions of source code must retain the above copyright
13  *     notice, this list of conditions and the following disclaimer.
14  *  2. Redistributions in binary form must reproduce the above copyright
15  *     notice, this list of conditions and the following disclaimer in the
16  *     documentation and/or other materials provided with the distribution.
17  *  3. Neither the name of Sun Microsystems, Inc. nor the names of its
18  *     contributors may be used to endorse or promote products derived
19  *     from this software without specific prior written permission.
20  *
21  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28  *  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29  *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
30  *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
31  *  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  *************************************************************************/
34 
35 import com.sun.star.beans.IllegalTypeException;
36 import com.sun.star.beans.MethodConcept;
37 import com.sun.star.beans.NamedValue;
38 import com.sun.star.beans.Property;
39 import com.sun.star.beans.XIntrospection;
40 import com.sun.star.beans.XIntrospectionAccess;
41 import com.sun.star.beans.XPropertySet;
42 import com.sun.star.bridge.UnoUrlResolver;
43 import com.sun.star.bridge.XUnoUrlResolver;
44 import com.sun.star.comp.helper.Bootstrap;
45 import com.sun.star.container.XEnumeration;
46 import com.sun.star.container.XEnumerationAccess;
47 import com.sun.star.container.XHierarchicalNameAccess;
48 import com.sun.star.container.XIndexAccess;
49 import com.sun.star.container.XNameAccess;
50 import com.sun.star.lang.XMultiComponentFactory;
51 import com.sun.star.lang.XMultiServiceFactory;
52 import com.sun.star.lang.XServiceInfo;
53 import com.sun.star.lang.XTypeProvider;
54 import com.sun.star.lib.uno.helper.WeakBase;
55 import com.sun.star.reflection.ParamInfo;
56 import com.sun.star.reflection.TypeDescriptionSearchDepth;
57 import com.sun.star.reflection.XConstantTypeDescription;
58 import com.sun.star.reflection.XConstantsTypeDescription;
59 import com.sun.star.reflection.XIdlClass;
60 import com.sun.star.reflection.XIdlField;
61 import com.sun.star.reflection.XIdlMethod;
62 import com.sun.star.reflection.XIdlReflection;
63 import com.sun.star.reflection.XIndirectTypeDescription;
64 import com.sun.star.reflection.XInterfaceTypeDescription;
65 import com.sun.star.reflection.XInterfaceTypeDescription2;
66 import com.sun.star.reflection.XPropertyTypeDescription;
67 import com.sun.star.reflection.XServiceTypeDescription;
68 import com.sun.star.reflection.XTypeDescription;
69 import com.sun.star.reflection.XTypeDescriptionEnumeration;
70 import com.sun.star.reflection.XTypeDescriptionEnumerationAccess;
71 import com.sun.star.ucb.CommandAbortedException;
72 import com.sun.star.ucb.XSimpleFileAccess;
73 import com.sun.star.uno.AnyConverter;
74 import com.sun.star.uno.Type;
75 import com.sun.star.uno.TypeClass;
76 import com.sun.star.uno.UnoRuntime;
77 import com.sun.star.uno.XComponentContext;
78 import com.sun.star.util.URL;
79 import java.util.List;
80 import java.util.Vector;
81 import javax.swing.JOptionPane;
82 
83 public class Introspector extends WeakBase{
84 
85     private XIntrospection m_xIntrospection;
86     private XMultiComponentFactory m_xMultiComponentFactory;
87     private XComponentContext m_xComponentContext;
88     private XTypeDescriptionEnumerationAccess m_xTDEnumerationAccess;
89     private static XComponentContext xOfficeComponentContext;
90     private XIdlReflection mxIdlReflection;
91     private URL openHyperlink;
92     private static Introspector m_oIntrospector = null;
93     private XSimpleFileAccess xSimpleFileAccess = null;
94 
95 
96 
97     public static Introspector getIntrospector(){
98         if (m_oIntrospector == null){
99             throw new NullPointerException();
100         }
101         else{
102             return m_oIntrospector;
103         }
104     }
105 
106     public static Introspector getIntrospector(XComponentContext _xComponentContext){
107         if (m_oIntrospector == null){
108             m_oIntrospector =  new Introspector(_xComponentContext);
109         }
110         return m_oIntrospector;
111     }
112 
113 
114     /** Creates a new instance of Introspection */
115     private Introspector(XComponentContext _xComponentContext) {
116     try{
117         m_xComponentContext = _xComponentContext;
118         m_xMultiComponentFactory = m_xComponentContext.getServiceManager();
119         Object o = m_xMultiComponentFactory.createInstanceWithContext("com.sun.star.beans.Introspection", m_xComponentContext);
120         m_xIntrospection = ( XIntrospection ) UnoRuntime.queryInterface(XIntrospection.class, o );
121         Object oCoreReflection = getXMultiComponentFactory().createInstanceWithContext("com.sun.star.reflection.CoreReflection", getXComponentContext());
122         mxIdlReflection = (XIdlReflection) UnoRuntime.queryInterface(XIdlReflection.class, oCoreReflection);
123         initTypeDescriptionManager();
124     }
125     catch( Exception exception ) {
126         System.err.println( exception );
127     }}
128 
129 
130     protected XComponentContext getXComponentContext(){
131         return m_xComponentContext;
132     }
133 
134 
135     protected XMultiComponentFactory getXMultiComponentFactory(){
136         return m_xMultiComponentFactory;
137     }
138 
139 
140     protected XIntrospectionAccess getXIntrospectionAccess(Object _oUnoComponent){
141         return m_xIntrospection.inspect(_oUnoComponent);
142     }
143 
144 
145     public boolean isContainer(Object _oUnoObject){
146     boolean bIsContainer = false;
147     try {
148         XIntrospectionAccess xIntrospectionAccessObject = getXIntrospectionAccess(_oUnoObject);
149         if (xIntrospectionAccessObject != null){
150             XEnumerationAccess xEnumerationAccess = (XEnumerationAccess) UnoRuntime.queryInterface(XEnumerationAccess.class, xIntrospectionAccessObject.queryAdapter( new Type( XEnumerationAccess.class ) ) );
151             if (xEnumerationAccess != null){
152                 XEnumeration xEnumeration = xEnumerationAccess.createEnumeration();
153                 bIsContainer = xEnumeration.hasMoreElements();
154             }
155             if (!bIsContainer){
156                 XIndexAccess xIndexAccess = (XIndexAccess) UnoRuntime.queryInterface( XIndexAccess.class, xIntrospectionAccessObject.queryAdapter(new Type( XIndexAccess.class )));
157                 if (xIndexAccess != null){
158                     bIsContainer = (xIndexAccess.getCount() > 0);
159                 }
160             }
161         }
162     } catch (IllegalTypeException ex) {
163         ex.printStackTrace(System.out);
164     }
165         return bIsContainer;
166     }
167 
168 
169     //  add all containers for the given object to the tree under the node
170     //  parent
171     public Object[] getUnoObjectsOfContainer(Object _oUnoParentObject) {
172     Object[] oRetComponents = null;
173     try {
174         Vector oRetComponentsVector = new Vector();
175         XIntrospectionAccess xIntrospectionAccessObject = getXIntrospectionAccess(_oUnoParentObject);
176         if ( xIntrospectionAccessObject != null ) {
177             XEnumerationAccess xEnumerationAccess = (XEnumerationAccess) UnoRuntime.queryInterface(XEnumerationAccess.class, xIntrospectionAccessObject.queryAdapter( new Type( XEnumerationAccess.class ) ) );
178             if ( xEnumerationAccess != null ) {
179                 XEnumeration xEnumeration = xEnumerationAccess.createEnumeration();
180                 while ( xEnumeration.hasMoreElements() ) {
181                     oRetComponentsVector.add(xEnumeration.nextElement());
182                 }
183             }
184             XIndexAccess xIndexAccess = (XIndexAccess) UnoRuntime.queryInterface( XIndexAccess.class, xIntrospectionAccessObject.queryAdapter(new Type( XIndexAccess.class )));
185             if ( xIndexAccess != null ) {
186                 XIdlMethod mMethod = xIntrospectionAccessObject.getMethod("getByIndex", com.sun.star.beans.MethodConcept.INDEXCONTAINER);
187                 for ( int i = 0; i < xIndexAccess.getCount(); i++ ) {
188                     Object[][] aParamInfo = new Object[1][1];
189                     aParamInfo[0] = new Integer[] { new Integer(i) };
190                     oRetComponentsVector.add(mMethod.invoke(_oUnoParentObject, aParamInfo));
191                 }
192             }
193         }
194         if (oRetComponentsVector != null){
195             oRetComponents = new Object[oRetComponentsVector.size()];
196             oRetComponentsVector.toArray(oRetComponents);
197         }
198     }
199     catch( Exception exception ) {
200         System.err.println( exception );
201     }
202     return oRetComponents;
203     }
204 
205 
206     protected XIdlMethod[] getMethodsOfInterface(Type _aType){
207     try{
208         XIdlClass xIdlClass = mxIdlReflection.forName(_aType.getTypeName());
209         return xIdlClass.getMethods();
210     }
211     catch( Exception e ) {
212         System.err.println( e );
213         return null;
214     }}
215 
216 
217     protected XIdlField[] getFieldsOfType(Type _aType){
218     try{
219         XIdlClass xIdlClass = mxIdlReflection.forName(_aType.getTypeName());
220         return xIdlClass.getFields();
221     }
222     catch( Exception e ) {
223         System.err.println( e );
224         return null;
225     }}
226 
227 
228     public boolean hasMethods(Object _oUnoObject){
229         boolean bHasMethods = (getMethods(_oUnoObject).length > 0);
230         return bHasMethods;
231     }
232 
233 
234     //  add all methods for the given object to the tree under the node parent
235     public XIdlMethod[] getMethods(Object _oUnoParentObject) {
236     try {
237         XIntrospectionAccess xIntrospectionAccess = getXIntrospectionAccess(_oUnoParentObject);
238         if (xIntrospectionAccess != null){
239             XIdlMethod[] xIdlMethods = xIntrospectionAccess.getMethods(MethodConcept.ALL - MethodConcept.DANGEROUS);
240             return xIdlMethods;
241         }
242     }
243     catch( Exception e ) {
244         System.err.println( e );
245     }
246     return null;
247     }
248 
249 
250     public boolean hasProperties(Object _oUnoObject){
251         boolean bHasProperties = (getProperties(_oUnoObject).length > 0);
252         return bHasProperties;
253     }
254 
255 
256     protected Property[] getProperties( Object _oUnoParentObject){
257     try {
258         XIntrospectionAccess xIntrospectionAccess = getXIntrospectionAccess(_oUnoParentObject);
259         if (xIntrospectionAccess != null){
260             Property[] aProperties = xIntrospectionAccess.getProperties(com.sun.star.beans.PropertyConcept.ATTRIBUTES + com.sun.star.beans.PropertyConcept.PROPERTYSET);
261             return aProperties;
262         }
263     }
264     catch( Exception e ) {
265         System.err.println( e );
266     }
267         return null;
268     }
269 
270 
271     protected Property[] getProperties(Object _oUnoObject, String _sServiceName){
272         Property[] aProperties = getProperties(_oUnoObject);
273         List aListOfProperties = java.util.Arrays.asList(aProperties);
274         Vector aPropertiesVector = new Vector(aListOfProperties);
275         if (aProperties != null){
276             XPropertyTypeDescription[] xPropertyTypeDescriptions = getPropertyDescriptionsOfService(_sServiceName);
277             for (int i = aProperties.length - 1; i >= 0; i--){
278                 if (!hasByName(xPropertyTypeDescriptions, _sServiceName + "." + aProperties[i].Name)){
279                     aPropertiesVector.remove(i);
280                 }
281             }
282         }
283         Property[] aRetProperties = new Property[aPropertiesVector.size()];
284         aPropertiesVector.toArray(aRetProperties);
285         return aRetProperties;
286     }
287 
288 
289     protected Type[] getInterfaces(Object _oUnoObject, String _sServiceName){
290         Type[] aTypes = getInterfaces(_oUnoObject);
291         List aListOfTypes = java.util.Arrays.asList(aTypes);
292         Vector aTypesVector = new Vector(aListOfTypes);
293         if (aTypes != null){
294             XInterfaceTypeDescription[] xInterfaceTypeDescriptions = getInterfaceDescriptionsOfService(_sServiceName);
295             for (int i = aTypes.length - 1; i >= 0; i--){
296                 if (!hasByName(xInterfaceTypeDescriptions, aTypes[i].getTypeName())){
297                     aTypesVector.remove(i);
298                 }
299             }
300         }
301         Type[] aRetTypes = new Type[aTypesVector.size()];
302         aTypesVector.toArray(aRetTypes);
303         return aRetTypes;
304     }
305 
306 
307     public boolean hasInterfaces(Object _oUnoObject){
308         return (getInterfaces(_oUnoObject).length > 0);
309     }
310 
311 
312     protected Type[] getInterfaces(Object _oUnoParentObject){
313         Type[] aTypes = new Type[]{};
314         XTypeProvider xTypeProvider = ( XTypeProvider ) UnoRuntime.queryInterface( XTypeProvider.class, _oUnoParentObject);
315         if ( xTypeProvider != null ) {
316             aTypes = xTypeProvider.getTypes();
317         }
318         return aTypes;
319     }
320 
321 
322 
323     public static boolean isObjectSequence(Object _oUnoObject){
324         Type aType = AnyConverter.getType(_oUnoObject);
325         return aType.getTypeClass().getValue() == TypeClass.SEQUENCE_value;
326     }
327 
328 
329     public static boolean isObjectPrimitive(Object _oUnoObject){
330         boolean breturn = false;
331         if (_oUnoObject != null){
332             Type aType = AnyConverter.getType(_oUnoObject);
333             breturn = isObjectPrimitive(_oUnoObject.getClass(), aType.getTypeClass());
334         }
335         return breturn;
336     }
337 
338 
339     public static boolean isPrimitive(TypeClass _typeClass){
340                return (( _typeClass == TypeClass.BOOLEAN )
341                      || ( _typeClass == TypeClass.BYTE )
342                      || ( _typeClass == TypeClass.CHAR )
343                      || ( _typeClass == TypeClass.DOUBLE )
344                      || ( _typeClass == TypeClass.ENUM )
345                      || ( _typeClass == TypeClass.FLOAT )
346                      || ( _typeClass == TypeClass.HYPER )
347                      || ( _typeClass == TypeClass.LONG )
348                      || ( _typeClass == TypeClass.SHORT )
349                      || ( _typeClass == TypeClass.STRING )
350                      || ( _typeClass == TypeClass.UNSIGNED_HYPER )
351                      || ( _typeClass == TypeClass.UNSIGNED_LONG )
352                      || ( _typeClass == TypeClass.UNSIGNED_SHORT ));
353     }
354 
355     public static boolean isObjectPrimitive(Class _oUnoClass, TypeClass _typeClass){
356         return !( ( !_oUnoClass.isPrimitive() ) && ( _typeClass != TypeClass.ARRAY )
357                                                          && ( _typeClass != TypeClass.BOOLEAN )
358                                                          && ( _typeClass != TypeClass.BYTE )
359                                                          && ( _typeClass != TypeClass.CHAR )
360                                                          && ( _typeClass != TypeClass.DOUBLE )
361                                                          && ( _typeClass != TypeClass.ENUM )
362                                                          && ( _typeClass != TypeClass.FLOAT )
363                                                          && ( _typeClass != TypeClass.HYPER )
364                                                          && ( _typeClass != TypeClass.LONG )
365                                                          && ( _typeClass != TypeClass.SHORT )
366                                                          && ( _typeClass != TypeClass.STRING )
367                                                          && ( _typeClass != TypeClass.UNSIGNED_HYPER )
368                                                          && ( _typeClass != TypeClass.UNSIGNED_LONG )
369                                                          && ( _typeClass != TypeClass.UNSIGNED_SHORT ));
370     }
371 
372 
373     protected void initTypeDescriptionManager() {
374     try {
375         Object oTypeDescriptionManager = getXComponentContext().getValueByName("/singletons/com.sun.star.reflection.theTypeDescriptionManager");
376         m_xTDEnumerationAccess = (XTypeDescriptionEnumerationAccess) UnoRuntime.queryInterface(XTypeDescriptionEnumerationAccess.class, oTypeDescriptionManager);
377     } catch ( java.lang.Exception e) {
378         System.out.println(System.out);
379     }}
380 
381 
382     protected XTypeDescriptionEnumerationAccess getXTypeDescriptionEnumerationAccess(){
383         return m_xTDEnumerationAccess;
384     }
385 
386 
387     protected XConstantTypeDescription[] getFieldsOfConstantGroup(String _sTypeClass){
388     XConstantTypeDescription[] xConstantTypeDescriptions = null;
389     try {
390         TypeClass[] eTypeClasses = new com.sun.star.uno.TypeClass[1];
391         eTypeClasses[0] = com.sun.star.uno.TypeClass.CONSTANTS;
392         XTypeDescriptionEnumeration xTDEnumeration = m_xTDEnumerationAccess.createTypeDescriptionEnumeration(getModuleName(_sTypeClass), eTypeClasses, TypeDescriptionSearchDepth.INFINITE);
393         while (xTDEnumeration.hasMoreElements()) {
394             XTypeDescription xTD = xTDEnumeration.nextTypeDescription();
395             if (xTD.getName().equals(_sTypeClass)){
396                 XConstantsTypeDescription xConstantsTypeDescription = (XConstantsTypeDescription) UnoRuntime.queryInterface(XConstantsTypeDescription.class, xTD);
397                 xConstantTypeDescriptions = xConstantsTypeDescription.getConstants();
398             }
399             String sName = xTD.getName();
400         }
401         return xConstantTypeDescriptions;
402     } catch ( java.lang.Exception e) {
403         System.out.println(System.out);
404     }
405         return null;
406     }
407 
408     private XServiceTypeDescription getServiceTypeDescription(String _sServiceName, TypeClass _eTypeClass){
409     try{
410         if (_sServiceName.length() > 0){
411             TypeClass[] eTypeClasses = new com.sun.star.uno.TypeClass[2];
412             eTypeClasses[0] = com.sun.star.uno.TypeClass.SERVICE;
413             eTypeClasses[1] = _eTypeClass;
414             XTypeDescriptionEnumeration xTDEnumeration = getXTypeDescriptionEnumerationAccess().createTypeDescriptionEnumeration(Introspector.getModuleName(_sServiceName), eTypeClasses, TypeDescriptionSearchDepth.INFINITE);
415             while (xTDEnumeration.hasMoreElements()) {
416                 XTypeDescription xTD = xTDEnumeration.nextTypeDescription();
417                 if (xTD.getName().equals(_sServiceName)){
418                     XServiceTypeDescription xServiceTypeDescription = (XServiceTypeDescription) UnoRuntime.queryInterface(XServiceTypeDescription.class, xTD);
419                     return xServiceTypeDescription;
420                 }
421             }
422         }
423         return null;
424     } catch (Exception ex) {
425         ex.printStackTrace(System.out);
426         return null;
427     }}
428 
429 
430     public XPropertyTypeDescription[] getPropertyDescriptionsOfService(String _sServiceName){
431     try {
432         XServiceTypeDescription xServiceTypeDescription = getServiceTypeDescription(_sServiceName, com.sun.star.uno.TypeClass.PROPERTY);
433         if (xServiceTypeDescription != null){
434             XPropertyTypeDescription[] xPropertyTypeDescriptions = xServiceTypeDescription.getProperties();
435             return xPropertyTypeDescriptions;
436         }
437     } catch ( java.lang.Exception e) {
438         System.out.println(System.out);
439     }
440     return new XPropertyTypeDescription[]{};
441     }
442 
443 
444     public XTypeDescription getReferencedType(String _sTypeName){
445     XTypeDescription xTypeDescription = null;
446     try{
447         XHierarchicalNameAccess xHierarchicalNameAccess = (XHierarchicalNameAccess) UnoRuntime.queryInterface(XHierarchicalNameAccess.class, m_xTDEnumerationAccess);
448         if (xHierarchicalNameAccess != null){
449             if (xHierarchicalNameAccess.hasByHierarchicalName(_sTypeName)){
450                 XIndirectTypeDescription xIndirectTypeDescription = (XIndirectTypeDescription) UnoRuntime.queryInterface(XIndirectTypeDescription.class, xHierarchicalNameAccess.getByHierarchicalName(_sTypeName));
451                 if (xIndirectTypeDescription != null){
452                     xTypeDescription = xIndirectTypeDescription.getReferencedType();
453                 }
454             }
455         }
456     } catch (Exception ex) {
457         ex.printStackTrace(System.out);
458     }
459         return xTypeDescription;
460     }
461 
462 
463     public XInterfaceTypeDescription[] getInterfaceDescriptionsOfService(String _sServiceName){
464     try {
465         XServiceTypeDescription xServiceTypeDescription = getServiceTypeDescription(_sServiceName, com.sun.star.uno.TypeClass.INTERFACE);
466         if (xServiceTypeDescription != null){
467             XInterfaceTypeDescription[] xInterfaceTypeDescriptions = xServiceTypeDescription.getMandatoryInterfaces();
468             return xInterfaceTypeDescriptions;
469         }
470     } catch ( java.lang.Exception e) {
471         System.out.println(System.out);
472     }
473         return new XInterfaceTypeDescription[]{};
474     }
475 
476 
477     static boolean hasByName(XTypeDescription[] _xTypeDescriptions, String _sTypeName){
478         for (int i = 0; i < _xTypeDescriptions.length; i++){
479             if (_xTypeDescriptions[i].getName().equals(_sTypeName)){
480                 return true;
481             }
482         }
483         return false;
484     }
485 
486 
487     public static String getModuleName(String _sTypeClass){
488         int nlastindex = _sTypeClass.lastIndexOf(".");
489         if (nlastindex > -1){
490             return _sTypeClass.substring(0, nlastindex);
491         }
492         else{
493             return "";
494         }
495     }
496 
497 
498     public static String getShortClassName(String _sClassName){
499         String sShortClassName = _sClassName;
500         int nindex = _sClassName.lastIndexOf(".");
501         if ((nindex < _sClassName.length()) && nindex > -1){
502             sShortClassName = _sClassName.substring(nindex + 1);
503         }
504         return sShortClassName;
505     }
506 
507 
508 
509     public static boolean isUnoTypeObject(Object _oUnoObject){
510         return isOfUnoType(_oUnoObject, "com.sun.star.uno.Type");
511     }
512 
513 
514     public static boolean isUnoPropertyTypeObject(Object _oUnoObject){
515         return isOfUnoType(_oUnoObject, "com.sun.star.beans.Property");
516     }
517 
518 
519     public static boolean isUnoPropertyValueTypeObject(Object _oUnoObject){
520         return isOfUnoType(_oUnoObject, "com.sun.star.beans.PropertyValue");
521     }
522 
523 
524     public static boolean isOfUnoType(Object _oUnoObject, String _sTypeName){
525         boolean bIsUnoObject = false;
526         if (_oUnoObject != null){
527             if (_oUnoObject.getClass().isArray()){
528                 if (!_oUnoObject.getClass().getComponentType().isPrimitive()){
529                     Object[] oUnoArray = (Object[]) _oUnoObject;
530                     if (oUnoArray.length > 0){
531                         bIsUnoObject = ( oUnoArray[0].getClass().getName().equals(_sTypeName));
532                     }
533                 }
534             }
535         }
536         else{
537             bIsUnoObject = (_oUnoObject.getClass().getName().equals(_sTypeName));
538         }
539         return bIsUnoObject;
540     }
541 
542 
543     public String getConstantDisplayString(int _nValue, XConstantTypeDescription[] _xConstantTypeDescription, String _sDisplayString){
544         String sPrefix = "";
545         int[] nbits = new int[_xConstantTypeDescription.length];
546         for (int i = 0; i < _xConstantTypeDescription.length; i++){
547             short nConstantValue = ((Short) _xConstantTypeDescription[i].getConstantValue()).shortValue();
548             nbits[i] = _nValue & nConstantValue;
549             if (nbits[i] > 0){
550                 _sDisplayString += sPrefix + _xConstantTypeDescription[i].getName();
551                 sPrefix = " + ";
552             }
553         }
554         return _sDisplayString;
555     }
556 
557 
558     public static boolean isValid(Object[] _oObject){
559         if (_oObject != null){
560             if (_oObject.length > 0){
561                 return true;
562             }
563         }
564         return false;
565     }
566 
567 
568     public static boolean isValid(Object _oObject){
569         if (_oObject != null){
570             return (!AnyConverter.isVoid(_oObject));
571         }
572         return false;
573     }
574 
575 
576     public static boolean isArray(Object _oObject){
577         return _oObject.getClass().isArray();
578     }
579 
580 
581     public boolean hasSupportedServices(Object _oUnoObject){
582         boolean bHasSupportedServices = false;
583         XServiceInfo xServiceInfo = ( XServiceInfo ) UnoRuntime.queryInterface( XServiceInfo.class, _oUnoObject);
584         if ( xServiceInfo != null ){
585             String[] sSupportedServiceNames = xServiceInfo.getSupportedServiceNames();
586             bHasSupportedServices = sSupportedServiceNames.length > 0;
587         }
588         return bHasSupportedServices;
589     }
590 
591 
592     public Object getValueOfText(TypeClass aTypeClass, String sText){
593         Object oReturn = null;
594         switch (aTypeClass.getValue()){
595             case TypeClass.CHAR_value:
596                 break;
597             case TypeClass.DOUBLE_value:
598                 oReturn = Double.valueOf(sText);
599                 break;
600             case TypeClass.ENUM_value:
601                 break;
602             case TypeClass.FLOAT_value:
603                 oReturn = Float.valueOf(sText);
604                 break;
605             case TypeClass.HYPER_value:
606                 oReturn = Long.valueOf(sText);
607                 break;
608             case TypeClass.LONG_value:
609                 oReturn = Integer.valueOf(sText);
610                 break;
611             case TypeClass.SHORT_value:
612                 oReturn = Byte.valueOf(sText);
613                 break;
614             case TypeClass.STRING_value:
615                 oReturn = sText;
616                 break;
617             case TypeClass.UNSIGNED_HYPER_value:
618                 oReturn = Long.valueOf(sText);
619                 break;
620             case TypeClass.UNSIGNED_LONG_value:
621                 oReturn = Integer.valueOf(sText);
622                 break;
623             case TypeClass.UNSIGNED_SHORT_value:
624                 oReturn = Byte.valueOf(sText);
625                 break;
626             default:
627         }
628         return oReturn;
629     }
630 
631 
632     public XSimpleFileAccess getXSimpleFileAccess(){
633     try {
634         if (xSimpleFileAccess == null){
635             Object oSimpleFileAccess = m_xComponentContext.getServiceManager().createInstanceWithContext("com.sun.star.ucb.SimpleFileAccess", m_xComponentContext);
636             xSimpleFileAccess = (XSimpleFileAccess) com.sun.star.uno.UnoRuntime.queryInterface(XSimpleFileAccess.class, oSimpleFileAccess);
637         }
638         return xSimpleFileAccess;
639     } catch (com.sun.star.uno.Exception ex) {
640         ex.printStackTrace(System.out);
641         return null;
642     }}
643 
644 
645     public boolean isValidSDKInstallationPath(String _sSDKInstallationPath){
646     boolean bIsValid = false;
647     try {
648         String sIDLFolder = Introspector.addToPath(_sSDKInstallationPath, Inspector.sIDLDOCUMENTSUBFOLDER);
649         String sIndexFile = Introspector.addToPath(_sSDKInstallationPath, "index.html");
650         if (getXSimpleFileAccess() != null){
651             bIsValid = (getXSimpleFileAccess().exists(sIDLFolder) && getXSimpleFileAccess().exists(sIndexFile));
652         }
653     } catch (com.sun.star.uno.Exception ex) {
654         ex.printStackTrace(System.out);
655     }
656         return bIsValid;
657     }
658 
659 
660     public static String addToPath(String _sPath, String _sSubPath){
661         if (!_sPath.endsWith("/")){
662             _sPath += "/";
663         }
664         return _sPath + _sSubPath;
665     }
666 
667 }
668