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