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