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.UnknownPropertyException; 25 import com.sun.star.beans.XPropertySet; 26 import com.sun.star.container.XNameAccess; 27 import com.sun.star.lang.Locale; 28 import com.sun.star.lang.WrappedTargetException; 29 import com.sun.star.lang.XServiceInfo; 30 import com.sun.star.reflection.ParamInfo; 31 import com.sun.star.reflection.XIdlClass; 32 import com.sun.star.reflection.XIdlMethod; 33 import com.sun.star.reflection.XTypeDescription; 34 import com.sun.star.text.XTextTablesSupplier; 35 import com.sun.star.uno.Any; 36 import com.sun.star.uno.AnyConverter; 37 import com.sun.star.uno.Type; 38 import com.sun.star.uno.TypeClass; 39 import com.sun.star.uno.UnoRuntime; 40 import java.util.Enumeration; 41 import java.util.Hashtable; 42 import java.util.Vector; 43 44 45 46 public class SourceCodeGenerator { 47 private Vector sExceptions = new Vector(); 48 Vector sHeaderStatements = new HeaderStatements(); 49 private XLanguageSourceCodeGenerator m_xLanguageSourceCodeGenerator; 50 private String sHeaderCode = ""; 51 private String sStatementCode = ""; 52 private String sMainMethodSignature = ""; 53 54 private Hashtable aVariables = new Hashtable(); 55 private final String SSUFFIXSEPARATOR = "_"; 56 private final String SVARIABLENAME = "VariableName"; 57 private final String SARRAYVARIABLENAME = "VariableNameList"; 58 private final String SUNOOBJECTNAME = "oUnobject"; 59 private final String SUNOSTRUCTNAME = "aUnoStruct"; 60 private Introspector m_oIntrospector; 61 private Vector aTreepathProviders = new Vector(); 62 private XTreePathProvider xTreepathProvider = null; 63 private boolean baddExceptionHandling = false; 64 private boolean bXPropertySetExceptionsAreAdded = false; 65 private XUnoNode oInitialUnoNode = null; 66 private final String sINITIALVARIABLENAME = "_oUnoEntryObject"; 67 68 69 /** Creates a new instance of SourceCodeGenerator */ SourceCodeGenerator(int _nLanguage)70 public SourceCodeGenerator(int _nLanguage) { 71 this.setLanguage(_nLanguage); 72 m_oIntrospector = Introspector.getIntrospector(); 73 } 74 75 addSourceCodeOfUnoObject(XTreePathProvider _xTreepathProvider, boolean _brememberPath, boolean _bAddMethodSignature, boolean _baddHeader)76 public String addSourceCodeOfUnoObject(XTreePathProvider _xTreepathProvider, boolean _brememberPath, boolean _bAddMethodSignature, boolean _baddHeader){ 77 String sSourceCode = ""; 78 String sVariableName = ""; 79 if (_xTreepathProvider != null) { 80 for (int i = 0; i < _xTreepathProvider.getPathCount(); i++){ 81 XUnoNode oUnoNode = _xTreepathProvider.getPathComponent(i); 82 if (i == 0){ 83 sVariableName = sINITIALVARIABLENAME; 84 oInitialUnoNode = oUnoNode; 85 } 86 else{ 87 if (oUnoNode instanceof XUnoMethodNode){ 88 XUnoMethodNode oUnoMethodNode = (XUnoMethodNode) oUnoNode; 89 if (oUnoMethodNode.isInvoked()){ 90 UnoObjectDefinition oUnoReturnObjectDefinition = getUnoObjectDefinition(_xTreepathProvider, oUnoMethodNode, i); 91 if (!isVariableDeclared(oUnoReturnObjectDefinition, this.generateVariableNameFromMethod(oUnoMethodNode.getXIdlMethod()))){ 92 // sStatementCode += "\n"; 93 sStatementCode += "\n" + getMethodStatementSourceCode(oUnoMethodNode, sVariableName, oUnoReturnObjectDefinition); 94 } 95 sVariableName = oUnoReturnObjectDefinition.getVariableName(); 96 } 97 } 98 else if (oUnoNode instanceof XUnoPropertyNode){ 99 XUnoPropertyNode oUnoPropertyNode = (XUnoPropertyNode) oUnoNode; 100 Any oReturnObject = com.sun.star.uno.Any.complete(oUnoPropertyNode.getUnoReturnObject()); 101 UnoObjectDefinition oUnoReturnObjectDefinition = new UnoObjectDefinition(oReturnObject); 102 if (!isVariableDeclared(oUnoReturnObjectDefinition, oUnoPropertyNode.getProperty().Name)){ 103 // sStatementCode += "\n"; 104 sStatementCode += "\n" + getPropertyStatementSourceCode(oUnoPropertyNode, sVariableName, oUnoReturnObjectDefinition); 105 } 106 sVariableName = oUnoReturnObjectDefinition.getVariableName(); 107 } 108 } 109 } 110 } 111 String sCompleteCode = combineCompleteSourceCode(sMainMethodSignature, _baddHeader); 112 xTreepathProvider = _xTreepathProvider; 113 if (_brememberPath){ 114 aTreepathProviders.add(_xTreepathProvider); 115 } 116 return sCompleteCode; 117 } 118 119 setLanguage(int _nLanguage)120 private void setLanguage(int _nLanguage){ 121 XLanguageSourceCodeGenerator xLanguageSourceCodeGenerator = null; 122 switch(_nLanguage){ 123 case XLanguageSourceCodeGenerator.nJAVA: 124 xLanguageSourceCodeGenerator = new JavaCodeGenerator(); 125 break; 126 case XLanguageSourceCodeGenerator.nCPLUSPLUS: 127 xLanguageSourceCodeGenerator = new CPlusPlusCodeGenerator(); 128 break; 129 case XLanguageSourceCodeGenerator.nBASIC: 130 xLanguageSourceCodeGenerator = new BasicCodeGenerator(); 131 break; 132 default: 133 System.out.println("Unknown Sourcecode Language. Check Menus!"); 134 } 135 if (xLanguageSourceCodeGenerator != null){ 136 m_xLanguageSourceCodeGenerator = xLanguageSourceCodeGenerator; 137 } 138 } 139 resetSourceCodeGeneration(int _nLanguage)140 private void resetSourceCodeGeneration(int _nLanguage){ 141 aVariables.clear(); 142 this.sHeaderStatements.clear(); 143 setLanguage(_nLanguage); 144 String sHeaderCode = ""; 145 sStatementCode = ""; 146 } 147 generateVariableNameFromMethod(String _sMethodName, String _sPrefix, boolean _bConsiderAll)148 private String generateVariableNameFromMethod(String _sMethodName, String _sPrefix, boolean _bConsiderAll){ 149 String sReturn = ""; 150 if (_sMethodName.startsWith(_sPrefix)){ 151 int nPrefixLength = _sPrefix.length(); 152 if (_sMethodName.length() > nPrefixLength){ 153 String sChar = _sMethodName.substring(nPrefixLength, nPrefixLength + 1); 154 String sUpperChar = sChar.toUpperCase(); 155 if (sUpperChar.equals(sChar)){ 156 if (_bConsiderAll){ 157 sReturn = _sMethodName; 158 } 159 else{ 160 sReturn = _sMethodName.substring(nPrefixLength, _sMethodName.length()); 161 } 162 } 163 } 164 } 165 return sReturn; 166 } 167 168 generateVariableNameFromMethod(XIdlMethod _xIdlMethod)169 private String generateVariableNameFromMethod(XIdlMethod _xIdlMethod){ 170 // todo: refactor this!!! 171 String sMethodName = _xIdlMethod.getName(); 172 String sReturn = ""; 173 sReturn = generateVariableNameFromMethod(sMethodName, "getBy", false); 174 if (sReturn.equals("")){ 175 sReturn = generateVariableNameFromMethod(sMethodName, "get", false); 176 } 177 if (sReturn.equals("")){ 178 sReturn = generateVariableNameFromMethod(sMethodName, "attach", false); 179 } 180 if (sReturn.equals("")){ 181 sReturn = generateVariableNameFromMethod(sMethodName, "assign", false); 182 } 183 if (sReturn.equals("")){ 184 sReturn = generateVariableNameFromMethod(sMethodName, "attach", false); 185 } 186 if (sReturn.equals("")){ 187 sReturn = generateVariableNameFromMethod(sMethodName, "create", false); 188 } 189 if (sReturn.equals("")){ 190 sReturn = generateVariableNameFromMethod(sMethodName, "is", true); 191 } 192 if (sReturn.equals("")){ 193 sReturn = generateVariableNameFromMethod(sMethodName, "has", true); 194 } 195 if (sReturn.equals("")){ 196 sReturn = sMethodName; 197 } 198 return sReturn; 199 } 200 201 convertAllUnoObjects(int _nLanguage)202 public String convertAllUnoObjects(int _nLanguage){ 203 String sSourceCode = ""; 204 resetSourceCodeGeneration(_nLanguage); 205 int ncount = aTreepathProviders.size(); 206 for (int i=0; i< ncount; i++){ 207 sSourceCode = addSourceCodeOfUnoObject((XTreePathProvider) aTreepathProviders.get(i), false, (i==0), (i == (ncount-1))); 208 } 209 return sSourceCode; 210 } 211 getUnoObjectDefinition(XTreePathProvider _xTreePathProvider, XUnoMethodNode _oUnoMethodNode, int _nindex)212 private UnoObjectDefinition getUnoObjectDefinition(XTreePathProvider _xTreePathProvider, XUnoMethodNode _oUnoMethodNode, int _nindex){ 213 XUnoNode oUnoNode = null; 214 Object oUnoReturnObject = null; 215 Object[] oParamObjects = null; 216 XIdlClass xIdlClass = _oUnoMethodNode.getXIdlMethod().getReturnType(); 217 String sTypeName = xIdlClass.getName(); 218 TypeClass aTypeClass = xIdlClass.getTypeClass(); 219 if (aTypeClass.getValue() != TypeClass.VOID_value){ 220 if (_xTreePathProvider.getPathCount() > _nindex + 1){ 221 oUnoNode = _xTreePathProvider.getPathComponent(_nindex + 1); 222 oUnoReturnObject = oUnoNode.getUnoObject(); 223 } 224 } 225 if (oUnoReturnObject == null){ 226 oUnoReturnObject = _oUnoMethodNode.getLastUnoReturnObject(); 227 } 228 UnoObjectDefinition oUnoObjectDefinition = new UnoObjectDefinition(oUnoReturnObject, sTypeName, aTypeClass); 229 if (_oUnoMethodNode.hasParameters()){ 230 if (oUnoNode != null){ 231 oParamObjects = oUnoNode.getParameterObjects(); 232 } 233 else{ 234 oParamObjects = _oUnoMethodNode.getLastParameterObjects(); 235 } 236 } 237 if (oParamObjects != null){ 238 oUnoObjectDefinition.addParameterObjects(oParamObjects); 239 } 240 return oUnoObjectDefinition; 241 } 242 243 combineCompleteSourceCode(String _sMethodSignature, boolean _bAddHeader)244 private String combineCompleteSourceCode(String _sMethodSignature, boolean _bAddHeader){ 245 String sCompleteCode = ""; 246 if (_bAddHeader){ 247 sMainMethodSignature = m_xLanguageSourceCodeGenerator.getMainMethodSignatureSourceCode(oInitialUnoNode, sINITIALVARIABLENAME); 248 m_xLanguageSourceCodeGenerator.assignqueryInterfaceHeaderSourceCode(); 249 sCompleteCode += getHeaderSourceCode(); 250 } 251 sCompleteCode += sMainMethodSignature; 252 sCompleteCode += sStatementCode; 253 if (_bAddHeader){ 254 sCompleteCode += m_xLanguageSourceCodeGenerator.getMethodTerminationSourceCode(); 255 sCompleteCode += "\n" + m_xLanguageSourceCodeGenerator.getCommentSign() + "..."; 256 } 257 return sCompleteCode; 258 } 259 260 getPropertyStatementSourceCode(XUnoPropertyNode _oUnoPropertyNode, String _sVariableName, UnoObjectDefinition _oUnoReturnObjectDefinition)261 public String getPropertyStatementSourceCode(XUnoPropertyNode _oUnoPropertyNode, String _sVariableName, UnoObjectDefinition _oUnoReturnObjectDefinition){ 262 String sReturnObjectVariableDefinition = ""; 263 String sStatement = ""; 264 String sPropertyName = _oUnoPropertyNode.getProperty().Name; 265 UnoObjectDefinition oUnoObjectDefinition = new UnoObjectDefinition(_oUnoPropertyNode.getUnoObject(), "com.sun.star.beans.XPropertySet"); 266 if (!m_xLanguageSourceCodeGenerator.needsqueryInterface() || (oUnoObjectDefinition.getTypeClass().getValue() == TypeClass.STRUCT_value)){ 267 oUnoObjectDefinition.setVariableName(_sVariableName); 268 if (oUnoObjectDefinition.getTypeClass().getValue() == TypeClass.STRUCT_value){ 269 sReturnObjectVariableDefinition = getVariableInitialization(_oUnoReturnObjectDefinition, false); 270 sStatement += m_xLanguageSourceCodeGenerator.getStructSourceCode(sReturnObjectVariableDefinition, oUnoObjectDefinition.getVariableName(), sPropertyName); 271 return sStatement; 272 } 273 } 274 sStatement += addQueryInterfaceSourceCode(oUnoObjectDefinition, _sVariableName, "com.sun.star.beans.XPropertySet"); 275 if (_oUnoReturnObjectDefinition.getTypeClass().getValue() != TypeClass.VOID_value){ 276 sReturnObjectVariableDefinition = getVariableInitialization(_oUnoReturnObjectDefinition, true); 277 } 278 sStatement += m_xLanguageSourceCodeGenerator.getPropertyValueGetterSourceCode(sPropertyName, sReturnObjectVariableDefinition, oUnoObjectDefinition.getVariableName(), _oUnoReturnObjectDefinition.getTypeClass(), _oUnoReturnObjectDefinition.getTypeName()); 279 addXPropertySetRelatedExceptions(); 280 return sStatement; 281 } 282 283 getMethodStatementSourceCode(XUnoMethodNode _oUnoMethodNode, String _sVariableName, UnoObjectDefinition _oUnoReturnObjectDefinition)284 public String getMethodStatementSourceCode(XUnoMethodNode _oUnoMethodNode, String _sVariableName, UnoObjectDefinition _oUnoReturnObjectDefinition){ 285 String sReturnObjectVariableDefinition = ""; 286 String sStatement = ""; 287 XIdlMethod xIdlMethod = _oUnoMethodNode.getXIdlMethod(); 288 TypeClass aReturnTypeClass = xIdlMethod.getReturnType().getTypeClass(); 289 UnoObjectDefinition oUnoObjectDefinition = new UnoObjectDefinition(_oUnoMethodNode.getUnoObject(), _oUnoMethodNode.getClassName()); 290 String sVariableStemName = this.generateVariableNameFromMethod(xIdlMethod); 291 sStatement += addQueryInterfaceSourceCode(oUnoObjectDefinition, _sVariableName, oUnoObjectDefinition.getTypeName()); 292 if (_oUnoReturnObjectDefinition.getTypeClass().getValue() != TypeClass.VOID_value){ 293 sReturnObjectVariableDefinition = getVariableInitialization(_oUnoReturnObjectDefinition, false) + " = "; 294 } 295 Object[] oParamObjects = _oUnoReturnObjectDefinition.getParameterObjects(); 296 String sParameterCode = getMethodParameterValueDescription(_oUnoMethodNode, oParamObjects, false); 297 String sSeparator = m_xLanguageSourceCodeGenerator.getMethodSeparator(); 298 sStatement += "\t" + sReturnObjectVariableDefinition + oUnoObjectDefinition.getVariableName() + sSeparator + xIdlMethod.getName() + "(" + sParameterCode + ")"; 299 sStatement += m_xLanguageSourceCodeGenerator.getStatementTerminationCharacter(); 300 addExceptions(xIdlMethod); 301 return sStatement; 302 } 303 304 addQueryInterfaceSourceCode(UnoObjectDefinition _oUnoObjectDefinition, String _sVariableName, String _sTypeName)305 private String addQueryInterfaceSourceCode(UnoObjectDefinition _oUnoObjectDefinition, String _sVariableName, String _sTypeName){ 306 String sLocStatement = ""; 307 if (m_xLanguageSourceCodeGenerator.needsqueryInterface()){ 308 if (!isVariableDeclared(_oUnoObjectDefinition, "")){ 309 String sObjectVariableDefinition = getVariableDeclaration(_oUnoObjectDefinition, false, ""); 310 sLocStatement += m_xLanguageSourceCodeGenerator.getqueryInterfaceSourceCode(_sTypeName, sObjectVariableDefinition, _sVariableName); 311 } 312 } 313 else{ 314 _oUnoObjectDefinition.setVariableName(_sVariableName); 315 } 316 return sLocStatement; 317 } 318 319 addXPropertySetRelatedExceptions()320 private void addXPropertySetRelatedExceptions(){ 321 if (!bXPropertySetExceptionsAreAdded){ 322 sExceptions.add("com.sun.star.beans.UnknownPropertyException"); 323 sExceptions.add("com.sun.star.lang.WrappedTargetException"); 324 sExceptions.add("com.sun.star.lang.IllegalArgumentException"); 325 bXPropertySetExceptionsAreAdded = true; 326 baddExceptionHandling = true; 327 } 328 } 329 330 addExceptions(XIdlMethod _xIdlMethod)331 private void addExceptions(XIdlMethod _xIdlMethod){ 332 XIdlClass[] xIdlClasses = _xIdlMethod.getExceptionTypes(); 333 for (int i = 0; i > xIdlClasses.length; i++){ 334 sExceptions.add(xIdlClasses[0].getName()); 335 baddExceptionHandling = true; 336 } 337 } 338 getRootDescription(XUnoNode _oUnoNode)339 private String getRootDescription(XUnoNode _oUnoNode){ 340 return "_o" + _oUnoNode.toString(); 341 } 342 343 getHeaderSourceCode()344 private String getHeaderSourceCode(){ 345 Enumeration aEnumeration = aVariables.elements(); 346 while(aEnumeration.hasMoreElements()){ 347 UnoObjectDefinition oUnoObjectDefinition = (UnoObjectDefinition) aEnumeration.nextElement(); 348 String sCurHeaderStatement = m_xLanguageSourceCodeGenerator.getHeaderSourceCode(oUnoObjectDefinition.getUnoObject(), oUnoObjectDefinition.getTypeName(), oUnoObjectDefinition.getTypeClass()); 349 sHeaderStatements.add(sCurHeaderStatement); 350 } 351 String sHeaderSourcecode = ""; 352 String[] sHeaderStatementArray = new String[sHeaderStatements.size()]; 353 sHeaderStatements.toArray(sHeaderStatementArray); 354 java.util.Arrays.sort(sHeaderStatementArray); 355 for (int i = 0; i < sHeaderStatementArray.length; i++){ 356 sHeaderSourcecode += sHeaderStatementArray[i]; 357 } 358 sHeaderSourcecode += m_xLanguageSourceCodeGenerator.getFinalHeaderStatements(); 359 return sHeaderSourcecode +"\n" + m_xLanguageSourceCodeGenerator.getCommentSign() + "...\n"; 360 } 361 362 363 private class HeaderStatements extends Vector{ 364 contains(Object _oElement)365 public boolean contains(Object _oElement){ 366 String sCompName = (String) _oElement; 367 for (int i = 0; i < this.size(); i++){ 368 String sElement = (String) this.get(i); 369 if (sElement.equals(sCompName)){ 370 return true; 371 } 372 } 373 return false; 374 } 375 376 add(Object _oElement)377 public boolean add(Object _oElement){ 378 if (_oElement instanceof String){ 379 if (!contains(_oElement)){ 380 super.add(_oElement); 381 return true; 382 } 383 } 384 return false; 385 } 386 } 387 388 isVariableDeclared(UnoObjectDefinition _oUnoObjectDefinition, String _sDefaultStemName)389 private boolean isVariableDeclared(UnoObjectDefinition _oUnoObjectDefinition, String _sDefaultStemName){ 390 boolean bisDeclared = false; 391 if (!_sDefaultStemName.equals("")){ 392 _oUnoObjectDefinition.setCentralVariableStemName(_sDefaultStemName); 393 } 394 String sVariableStemName = _oUnoObjectDefinition.getVariableStemName(); 395 bisDeclared = aVariables.containsKey(sVariableStemName); 396 if (bisDeclared){ 397 Object oUnoObject = _oUnoObjectDefinition.getUnoObject(); 398 if (m_oIntrospector.isObjectPrimitive(oUnoObject)){ 399 bisDeclared = false; 400 } 401 else if (m_oIntrospector.isObjectSequence(oUnoObject)){ 402 bisDeclared = false; 403 } 404 else{ 405 String sCompVariableName = sVariableStemName; 406 String sUnoObjectIdentity = oUnoObject.toString(); 407 boolean bleaveloop = false; 408 int a = 2; 409 while (!bleaveloop){ 410 if (aVariables.containsKey(sCompVariableName)){ 411 Object oUnoCompObject = ((UnoObjectDefinition) aVariables.get(sCompVariableName)).getUnoObject(); 412 String sUnoCompObjectIdentity = oUnoCompObject.toString(); 413 bleaveloop = sUnoCompObjectIdentity.equals(sUnoObjectIdentity); 414 bisDeclared = bleaveloop; 415 if (!bleaveloop){ 416 sCompVariableName = sVariableStemName + SSUFFIXSEPARATOR + a++; 417 } 418 } 419 else{ 420 bleaveloop = true; 421 bisDeclared = false; 422 } 423 } 424 } 425 } 426 return bisDeclared; 427 } 428 429 addUniqueVariableName(String _sStemVariableName, UnoObjectDefinition _oUnoObjectDefinition)430 private String addUniqueVariableName(String _sStemVariableName, UnoObjectDefinition _oUnoObjectDefinition){ 431 boolean bElementexists = true; 432 int a = 2; 433 String sCompName = _sStemVariableName; 434 while (bElementexists){ 435 if (! aVariables.containsKey(sCompName)){ 436 aVariables.put(sCompName, _oUnoObjectDefinition); 437 break; 438 } 439 sCompName = _sStemVariableName + SSUFFIXSEPARATOR + a++; 440 } 441 return sCompName; 442 } 443 444 445 getTypeString(String _sTypeName, TypeClass _aTypeClass, boolean _bAsHeaderSourceCode)446 private String getTypeString(String _sTypeName, TypeClass _aTypeClass, boolean _bAsHeaderSourceCode){ 447 String sTypeString = ""; 448 switch (_aTypeClass.getValue()){ 449 case TypeClass.BOOLEAN_value: 450 sTypeString = m_xLanguageSourceCodeGenerator.getbooleanTypeDescription(); 451 break; 452 case TypeClass.BYTE_value: 453 sTypeString = m_xLanguageSourceCodeGenerator.getbyteTypeDescription(); 454 break; 455 case TypeClass.CHAR_value: 456 sTypeString = m_xLanguageSourceCodeGenerator.getcharTypeDescription(); 457 break; 458 case TypeClass.DOUBLE_value: 459 sTypeString = m_xLanguageSourceCodeGenerator.getdoubleTypeDescription(); 460 break; 461 case TypeClass.FLOAT_value: 462 sTypeString = m_xLanguageSourceCodeGenerator.getfloatTypeDescription(); 463 break; 464 case TypeClass.HYPER_value: 465 sTypeString = m_xLanguageSourceCodeGenerator.gethyperTypeDescription(); 466 break; 467 case TypeClass.LONG_value: 468 sTypeString = m_xLanguageSourceCodeGenerator.getlongTypeDescription(); 469 break; 470 case TypeClass.SHORT_value: 471 sTypeString = m_xLanguageSourceCodeGenerator.getshortTypeDescription(); 472 break; 473 case TypeClass.STRING_value: 474 sTypeString = m_xLanguageSourceCodeGenerator.getstringTypeDescription(_bAsHeaderSourceCode); 475 break; 476 case TypeClass.UNSIGNED_HYPER_value: 477 sTypeString = m_xLanguageSourceCodeGenerator.getunsignedhyperTypeDescription(); 478 break; 479 case TypeClass.UNSIGNED_LONG_value: 480 sTypeString = m_xLanguageSourceCodeGenerator.getunsignedlongTypeDescription(); 481 break; 482 case TypeClass.UNSIGNED_SHORT_value: 483 sTypeString = m_xLanguageSourceCodeGenerator.getdoubleTypeDescription(); 484 break; 485 case TypeClass.SEQUENCE_value: 486 //TODO consider mulitdimensional Arrays 487 XTypeDescription xTypeDescription = Introspector.getIntrospector().getReferencedType(_sTypeName); 488 if (xTypeDescription != null){ 489 sTypeString = getTypeString(xTypeDescription.getName(), xTypeDescription.getTypeClass(), _bAsHeaderSourceCode); 490 } 491 break; 492 case TypeClass.ANY_value: 493 sTypeString = m_xLanguageSourceCodeGenerator.getanyTypeDescription(_bAsHeaderSourceCode); 494 break; 495 case TypeClass.TYPE_value: 496 sTypeString = m_xLanguageSourceCodeGenerator.getObjectTypeDescription("com.sun.star.uno.Type", _bAsHeaderSourceCode); 497 break; 498 case TypeClass.ENUM_value: 499 case TypeClass.STRUCT_value: 500 case TypeClass.INTERFACE_ATTRIBUTE_value: 501 case TypeClass.INTERFACE_METHOD_value: 502 case TypeClass.INTERFACE_value: 503 case TypeClass.PROPERTY_value: 504 sTypeString = m_xLanguageSourceCodeGenerator.getObjectTypeDescription(_sTypeName, _bAsHeaderSourceCode); 505 break; 506 default: 507 } 508 return sTypeString; 509 } 510 511 getVariableDeclaration(UnoObjectDefinition _oUnoObjectDefinition, boolean _bInitialize, String _sVariableDefaultName)512 private String getVariableDeclaration(UnoObjectDefinition _oUnoObjectDefinition, boolean _bInitialize, String _sVariableDefaultName){ 513 TypeClass aTypeClass = _oUnoObjectDefinition.getTypeClass(); 514 TypeClass aLocTypeClass = aTypeClass; 515 boolean bIsArray = false; 516 if (_oUnoObjectDefinition.getUnoObject() != null){ 517 bIsArray = m_oIntrospector.isObjectSequence(_oUnoObjectDefinition.getUnoObject()); 518 } 519 else{ 520 bIsArray = _oUnoObjectDefinition.getTypeClass().getValue() == TypeClass.SEQUENCE_value; 521 } 522 String sVariableName = _oUnoObjectDefinition.getVariableName(_sVariableDefaultName); 523 String sTypeName = _oUnoObjectDefinition.getTypeName(); 524 String sTypeString = getTypeString(sTypeName, aLocTypeClass, false); 525 if (bIsArray){ 526 XTypeDescription xTypeDescription = Introspector.getIntrospector().getReferencedType(sTypeName); 527 if (xTypeDescription != null){ 528 aLocTypeClass = xTypeDescription.getTypeClass(); 529 } 530 } 531 String sVariableDeclaration = m_xLanguageSourceCodeGenerator.getVariableDeclaration(sTypeString, sVariableName, bIsArray, aLocTypeClass, _bInitialize); 532 addUniqueVariableName(sVariableName, _oUnoObjectDefinition); 533 return sVariableDeclaration; 534 } 535 536 getVariableInitialization(UnoObjectDefinition _oUnoObjectDefinition, boolean _bInitialize)537 public String getVariableInitialization(UnoObjectDefinition _oUnoObjectDefinition, boolean _bInitialize){ 538 String sObjectVariableDeclaration = ""; 539 String sVariableName = _oUnoObjectDefinition.getVariableName(); 540 if (isVariableDeclared(_oUnoObjectDefinition, "")){ 541 sObjectVariableDeclaration = sVariableName; 542 } 543 else{ 544 sObjectVariableDeclaration = getVariableDeclaration(_oUnoObjectDefinition, _bInitialize, ""); 545 } 546 return sObjectVariableDeclaration; 547 } 548 549 550 getVariableNameforUnoObject(String _sShortClassName)551 public String getVariableNameforUnoObject(String _sShortClassName){ 552 if (_sShortClassName.startsWith("X")){ 553 return "x" + _sShortClassName.substring(1); 554 } 555 else{ 556 return _sShortClassName; 557 } 558 } 559 560 561 class UnoObjectDefinition{ 562 Object m_oUnoObject = null; 563 Type aType = null; 564 String sVariableStemName = ""; 565 String m_sCentralVariableStemName = ""; 566 String sVariableName = ""; 567 String m_sTypeName = ""; 568 TypeClass m_aTypeClass = null; 569 Object[] m_oParameterObjects = null; 570 571 UnoObjectDefinition(Any _oUnoObject)572 public UnoObjectDefinition(Any _oUnoObject){ 573 m_sTypeName = _oUnoObject.getType().getTypeName(); 574 m_aTypeClass = _oUnoObject.getType().getTypeClass(); 575 m_oUnoObject = _oUnoObject; 576 m_sCentralVariableStemName = getCentralVariableStemName(m_aTypeClass); 577 } 578 579 UnoObjectDefinition(Object _oUnoObject, String _sTypeName, TypeClass _aTypeClass)580 public UnoObjectDefinition(Object _oUnoObject, String _sTypeName, TypeClass _aTypeClass){ 581 m_oUnoObject = _oUnoObject; 582 m_sTypeName = _sTypeName; 583 m_aTypeClass = _aTypeClass; 584 m_sCentralVariableStemName = getCentralVariableStemName(m_aTypeClass); 585 } 586 587 UnoObjectDefinition(Object _oUnoObject, String _sTypeName)588 public UnoObjectDefinition(Object _oUnoObject, String _sTypeName){ 589 m_oUnoObject = _oUnoObject; 590 m_sTypeName = _sTypeName; 591 m_aTypeClass = AnyConverter.getType(_oUnoObject).getTypeClass(); 592 m_sCentralVariableStemName = getCentralVariableStemName(m_aTypeClass); 593 } 594 595 getCentralVariableStemName(TypeClass _aTypeClass)596 private String getCentralVariableStemName(TypeClass _aTypeClass){ 597 String sCentralVariableStemName = ""; 598 int nTypeClass = _aTypeClass.getValue(); 599 switch(nTypeClass){ 600 case TypeClass.SEQUENCE_value: 601 //TODO consider mulitdimensional Arrays 602 XTypeDescription xTypeDescription = Introspector.getIntrospector().getReferencedType(getTypeName()); 603 if (xTypeDescription != null){ 604 sCentralVariableStemName = getCentralVariableStemName(xTypeDescription.getTypeClass()); 605 } 606 break; 607 case TypeClass.TYPE_value: 608 sCentralVariableStemName = SVARIABLENAME; 609 break; 610 case TypeClass.STRUCT_value: 611 sCentralVariableStemName = Introspector.getShortClassName(getTypeName()); 612 break; 613 case TypeClass.INTERFACE_ATTRIBUTE_value: 614 case TypeClass.INTERFACE_METHOD_value: 615 case TypeClass.INTERFACE_value: 616 case TypeClass.PROPERTY_value: 617 String sShortClassName = m_oIntrospector.getShortClassName(getTypeName()); 618 sCentralVariableStemName = getVariableNameforUnoObject(sShortClassName); 619 default: 620 sCentralVariableStemName = SVARIABLENAME; 621 } 622 return sCentralVariableStemName; 623 } 624 625 /** may return null 626 */ getUnoObject()627 public Object getUnoObject(){ 628 return m_oUnoObject; 629 } 630 631 setTypeClass(TypeClass _aTypeClass)632 public void setTypeClass(TypeClass _aTypeClass){ 633 sVariableStemName = ""; 634 m_aTypeClass = _aTypeClass; 635 } 636 637 getTypeClass()638 public TypeClass getTypeClass(){ 639 return m_aTypeClass; 640 } 641 642 setTypeName(String _sTypeName)643 public void setTypeName(String _sTypeName){ 644 sVariableStemName = ""; 645 m_sTypeName = _sTypeName; 646 } 647 648 getTypeName()649 public String getTypeName(){ 650 return m_sTypeName; 651 } 652 653 setCentralVariableStemName(String _sCentralVariableStemName)654 public void setCentralVariableStemName(String _sCentralVariableStemName){ 655 m_sCentralVariableStemName = _sCentralVariableStemName; 656 } 657 658 getVariableStemName()659 public String getVariableStemName(){ 660 if (sVariableStemName.equals("")){ 661 sVariableStemName = getVariableStemName(m_aTypeClass); 662 } 663 return sVariableStemName; 664 } 665 666 addParameterObjects(Object[] _oParameterObjects)667 public void addParameterObjects(Object[] _oParameterObjects){ 668 m_oParameterObjects = _oParameterObjects; 669 } 670 671 getParameterObjects()672 public Object[] getParameterObjects(){ 673 return m_oParameterObjects; 674 } 675 676 hasParameterObjects()677 public boolean hasParameterObjects(){ 678 boolean breturn = false; 679 if (m_oParameterObjects != null){ 680 breturn = m_oParameterObjects.length > 0; 681 } 682 return breturn; 683 } 684 685 getVariableStemName(TypeClass _aTypeClass)686 public String getVariableStemName(TypeClass _aTypeClass){ 687 int nTypeClass = _aTypeClass.getValue(); 688 switch(nTypeClass){ 689 case TypeClass.BOOLEAN_value: 690 sVariableStemName = "b" + m_sCentralVariableStemName; 691 break; 692 case TypeClass.DOUBLE_value: 693 case TypeClass.FLOAT_value: 694 sVariableStemName = "f" + m_sCentralVariableStemName; 695 break; 696 case TypeClass.BYTE_value: 697 case TypeClass.HYPER_value: 698 case TypeClass.LONG_value: 699 case TypeClass.UNSIGNED_HYPER_value: 700 case TypeClass.UNSIGNED_LONG_value: 701 case TypeClass.UNSIGNED_SHORT_value: 702 case TypeClass.SHORT_value: 703 sVariableStemName = "n" + m_sCentralVariableStemName; 704 break; 705 case TypeClass.CHAR_value: 706 case TypeClass.STRING_value: 707 sVariableStemName = "s" + m_sCentralVariableStemName; 708 break; 709 case TypeClass.SEQUENCE_value: 710 //TODO consider mulitdimensional Arrays 711 XTypeDescription xTypeDescription = Introspector.getIntrospector().getReferencedType(getTypeName()); 712 if (xTypeDescription != null){ 713 sVariableStemName = getVariableStemName(xTypeDescription.getTypeClass()); 714 } 715 break; 716 case TypeClass.TYPE_value: 717 sVariableStemName = "a" + m_sCentralVariableStemName; 718 break; 719 case TypeClass.ANY_value: 720 sVariableStemName = "o" + m_sCentralVariableStemName; 721 break; 722 case TypeClass.STRUCT_value: 723 case TypeClass.ENUM_value: 724 sVariableStemName = "a" + m_sCentralVariableStemName; 725 break; 726 case TypeClass.INTERFACE_ATTRIBUTE_value: 727 case TypeClass.INTERFACE_METHOD_value: 728 case TypeClass.INTERFACE_value: 729 case TypeClass.PROPERTY_value: 730 String sShortClassName = m_oIntrospector.getShortClassName(getTypeName()); 731 sVariableStemName = getVariableNameforUnoObject(sShortClassName); 732 default: 733 } 734 return sVariableStemName; 735 } 736 737 setVariableName(String _sVariableName)738 private void setVariableName(String _sVariableName){ 739 sVariableName = _sVariableName; 740 } 741 742 getVariableName(String _sCentralVariableStemName)743 private String getVariableName(String _sCentralVariableStemName){ 744 if (!_sCentralVariableStemName.equals("")){ 745 this.m_sCentralVariableStemName = _sCentralVariableStemName; 746 } 747 return getVariableName(); 748 } 749 750 getVariableName()751 private String getVariableName() throws NullPointerException{ 752 if (sVariableName.equals("")){ 753 int a = 2; 754 sVariableName = getVariableStemName(); 755 boolean bleaveloop = false; 756 while (!bleaveloop){ 757 if (aVariables.containsKey(sVariableName)){ 758 String sUnoObjectIdentity = ((UnoObjectDefinition) aVariables.get(sVariableName)).getUnoObject().toString(); 759 if (m_oUnoObject != null){ 760 if ((sUnoObjectIdentity.equals(m_oUnoObject.toString()) && (!m_oIntrospector.isPrimitive(this.getTypeClass())) && 761 (! m_oIntrospector.isObjectSequence(m_oUnoObject)))){ 762 bleaveloop = true; 763 } 764 else{ 765 sVariableName = getVariableStemName() + SSUFFIXSEPARATOR + a++; 766 } 767 } 768 else{ 769 bleaveloop = true; 770 } 771 } 772 else{ 773 bleaveloop = true; 774 // throw new NullPointerException("SourceCode Variable " + _sStemVariableName + " not defined"); 775 } 776 } 777 } 778 return sVariableName; 779 } 780 } 781 782 getStringValueOfObject(Object _oUnoObject, TypeClass _aTypeClass)783 public String getStringValueOfObject(Object _oUnoObject, TypeClass _aTypeClass){ 784 String sReturn = ""; 785 switch (_aTypeClass.getValue()){ 786 case TypeClass.BOOLEAN_value: 787 boolean bbooleanValue = ((Boolean) _oUnoObject).booleanValue(); 788 sReturn += Boolean.toString(bbooleanValue); 789 case TypeClass.CHAR_value: 790 break; 791 case TypeClass.DOUBLE_value: 792 double fdoubleValue = ((Double) _oUnoObject).doubleValue(); 793 sReturn += Double.toString(fdoubleValue); 794 break; 795 case TypeClass.ENUM_value: 796 break; 797 case TypeClass.FLOAT_value: 798 float floatValue = ((Float) _oUnoObject).floatValue(); 799 sReturn += Float.toString(floatValue); 800 break; 801 case TypeClass.HYPER_value: 802 long nlongValue = ((Long) _oUnoObject).longValue(); 803 sReturn += Long.toString(nlongValue); 804 break; 805 case TypeClass.LONG_value: 806 int nintValue = ((Integer) _oUnoObject).intValue(); 807 sReturn += Integer.toString(nintValue); 808 break; 809 case TypeClass.SHORT_value: 810 short nshortValue = ((Short) _oUnoObject).shortValue(); 811 sReturn += Short.toString(nshortValue); 812 break; 813 case TypeClass.STRING_value: 814 sReturn += (String) _oUnoObject; 815 break; 816 case TypeClass.UNSIGNED_HYPER_value: 817 nlongValue = ((Long) _oUnoObject).longValue(); 818 sReturn += Long.toString(nlongValue); 819 break; 820 case TypeClass.UNSIGNED_LONG_value: 821 nintValue = ((Integer) _oUnoObject).intValue(); 822 sReturn += Integer.toString(nintValue); 823 break; 824 case TypeClass.UNSIGNED_SHORT_value: 825 nshortValue = ((Short) _oUnoObject).shortValue(); 826 sReturn += Short.toString(nshortValue); 827 break; 828 default: 829 System.out.println("Type " + _aTypeClass.getValue() + " not yet defined in 'getStringValueOfObject()'"); 830 } 831 return sReturn; 832 } 833 834 getMethodParameterValueDescription(XUnoMethodNode _oUnoMethodNode, Object[] _oParamObjects, boolean _bIncludeParameterNames)835 public String getMethodParameterValueDescription(XUnoMethodNode _oUnoMethodNode, Object[] _oParamObjects, boolean _bIncludeParameterNames){ 836 String sParamSourceCode = ""; 837 ParamInfo[] aParamInfos = _oUnoMethodNode.getXIdlMethod().getParameterInfos(); 838 if (_oParamObjects != null){ 839 for (int i = 0; i < _oParamObjects.length; i++){ 840 TypeClass aTypeClass = aParamInfos[i].aType.getTypeClass(); 841 if (_bIncludeParameterNames){ 842 sParamSourceCode += aParamInfos[i].aName + "="; 843 } 844 String sParamDescription = getStringValueOfObject(_oParamObjects[i], aTypeClass); 845 sParamDescription = this.m_xLanguageSourceCodeGenerator.castLiteral(sParamDescription, aTypeClass); 846 sParamSourceCode += sParamDescription; 847 848 if (i < _oParamObjects.length - 1){ 849 sParamSourceCode += ", "; 850 } 851 } 852 } 853 return sParamSourceCode; 854 } 855 856 857 public class JavaCodeGenerator implements XLanguageSourceCodeGenerator{ 858 String sStatementsCode = ""; 859 boolean bAddAnyConverter = false; 860 // boolean bAddTypeImport = false; 861 boolean bIsPropertyUnoObjectDefined = false; 862 JavaCodeGenerator()863 public JavaCodeGenerator(){ 864 } 865 866 getStatementTerminationCharacter()867 public String getStatementTerminationCharacter(){ 868 return ";"; 869 } 870 871 getHeaderSourceCode(Object _oUnoObject, String _sClassName, TypeClass _aTypeClass)872 public String getHeaderSourceCode(Object _oUnoObject, String _sClassName, TypeClass _aTypeClass){ 873 String sClassName = _sClassName; 874 String sHeaderStatement = ""; 875 if (_oUnoObject != null){ 876 if (!m_oIntrospector.isObjectPrimitive(_oUnoObject)){ 877 if (m_oIntrospector.isObjectSequence(_oUnoObject)){ 878 XTypeDescription xTypeDescription = m_oIntrospector.getReferencedType(sClassName); 879 if (xTypeDescription != null){ 880 if (!m_oIntrospector.isPrimitive(xTypeDescription.getTypeClass())){ 881 sClassName = getTypeString(xTypeDescription.getName(), xTypeDescription.getTypeClass(), true); 882 } 883 // primitive Types are not supposed to turn up in the import section... 884 else{ 885 sClassName = ""; 886 } 887 } 888 } 889 else{ 890 sClassName = getTypeString(_sClassName, _aTypeClass, true); 891 } 892 } 893 else if (_aTypeClass.getValue() == TypeClass.ENUM_value){ 894 sClassName = _sClassName; 895 } 896 else{ 897 sClassName = ""; 898 } 899 if (!sClassName.equals("")){ 900 sHeaderStatement = "import " + sClassName + ";\n"; 901 } 902 } 903 return sHeaderStatement; 904 } 905 906 getFinalHeaderStatements()907 public String getFinalHeaderStatements(){ 908 return ""; 909 } 910 911 assignqueryInterfaceHeaderSourceCode()912 public void assignqueryInterfaceHeaderSourceCode(){ 913 sHeaderStatements.add("import com.sun.star.uno.UnoRuntime;\n"); 914 sHeaderStatements.add("import com.sun.star.uno.XInterface;\n"); 915 if (bAddAnyConverter){ 916 sHeaderStatements.add("import com.sun.star.uno.AnyConverter;\n"); 917 } 918 } 919 920 921 getConvertedSourceCodeValueOfObject(String _sReturnVariableName, String _sObjectDescription, TypeClass _aTypeClass, String _sTypeName)922 public String getConvertedSourceCodeValueOfObject(String _sReturnVariableName, String _sObjectDescription, TypeClass _aTypeClass, String _sTypeName){ 923 boolean bLocAddAnyConverter = true; 924 String sReturn = ""; 925 switch (_aTypeClass.getValue()){ 926 case TypeClass.BOOLEAN_value: 927 sReturn = _sReturnVariableName + " = AnyConverter.toBoolean(" + _sObjectDescription + ")"; 928 break; 929 case TypeClass.CHAR_value: 930 sReturn = _sReturnVariableName + " = AnyConverter.toChar(" + _sObjectDescription + ")"; 931 break; 932 case TypeClass.BYTE_value: 933 sReturn = _sReturnVariableName + " = AnyConverter.toByte(" + _sObjectDescription + ")"; 934 break; 935 case TypeClass.DOUBLE_value: 936 sReturn = _sReturnVariableName + " = AnyConverter.toDouble(" + _sObjectDescription + ")"; 937 break; 938 case TypeClass.FLOAT_value: 939 sReturn = _sReturnVariableName + " = AnyConverter.toFloat(" + _sObjectDescription + ")"; 940 break; 941 case TypeClass.UNSIGNED_HYPER_value: 942 sReturn = _sReturnVariableName + " = AnyConverter.toUnsignedLong(" + _sObjectDescription + ")"; 943 break; 944 case TypeClass.HYPER_value: 945 sReturn = _sReturnVariableName + " = AnyConverter.toLong(" + _sObjectDescription + ")"; 946 break; 947 case TypeClass.UNSIGNED_LONG_value: 948 sReturn = _sReturnVariableName + " = AnyConverter.toUnsignedInt(" + _sObjectDescription + ")"; 949 break; 950 case TypeClass.LONG_value: 951 sReturn = _sReturnVariableName + " = AnyConverter.toInt(" + _sObjectDescription + ")"; 952 break; 953 case TypeClass.SHORT_value: 954 sReturn = _sReturnVariableName + " = AnyConverter.toShort(" + _sObjectDescription + ")"; 955 break; 956 case TypeClass.UNSIGNED_SHORT_value: 957 sReturn = _sReturnVariableName + " = AnyConverter.toUnsignedShort(" + _sObjectDescription + ")"; 958 break; 959 case TypeClass.STRING_value: 960 sReturn = _sReturnVariableName + " = AnyConverter.toString(" + _sObjectDescription + ")"; 961 break; 962 default: 963 String sShortTypeName = Introspector.getShortClassName(_sTypeName); 964 if (bIsPropertyUnoObjectDefined){ 965 sReturn = "oUnoObject = " + _sObjectDescription + ";\n\t"; 966 } 967 else{ 968 sReturn = "Object oUnoObject = " + _sObjectDescription + ";\n\t"; 969 bIsPropertyUnoObjectDefined = true; 970 } 971 sReturn += _sReturnVariableName + " = (" + sShortTypeName + ") AnyConverter.toObject(" + sShortTypeName + ".class, oUnoObject);"; 972 // this.bAddTypeImport = true; 973 break; 974 } 975 if (!bAddAnyConverter){ 976 bAddAnyConverter = bLocAddAnyConverter; 977 } 978 return sReturn; 979 } 980 981 getStructSourceCode(String _sReturnVariableDescription, String _sObjectDescription, String _sMember)982 public String getStructSourceCode(String _sReturnVariableDescription, String _sObjectDescription, String _sMember){ 983 return "\t" + _sReturnVariableDescription + " = " + _sObjectDescription + "." + _sMember + ";"; 984 } 985 getMainMethodSignatureSourceCode(XUnoNode _oUnoNode, String _soReturnObjectDescription)986 public String getMainMethodSignatureSourceCode(XUnoNode _oUnoNode, String _soReturnObjectDescription){ 987 //TODO try to use + _oUnoNode.getClassName() instead of the hack 988 String sReturn = "public void codesnippet(XInterface " + _soReturnObjectDescription + "){"; 989 if (baddExceptionHandling){ 990 sReturn += "\ntry{"; 991 } 992 return sReturn; 993 } 994 getMethodSeparator()995 public String getMethodSeparator(){ 996 return "."; 997 } 998 needsqueryInterface()999 public boolean needsqueryInterface(){ 1000 return true; 1001 } 1002 getqueryInterfaceSourceCode(String _sClassName, String _sReturnVariableName, String _sIncomingObjectName)1003 public String getqueryInterfaceSourceCode(String _sClassName, String _sReturnVariableName, String _sIncomingObjectName){ 1004 String sShortClassName = m_oIntrospector.getShortClassName(_sClassName); 1005 return "\t" + _sReturnVariableName + " = (" + sShortClassName + ") UnoRuntime.queryInterface(" + sShortClassName + ".class, " + _sIncomingObjectName + ");\n"; 1006 } 1007 1008 getPropertyValueGetterSourceCode(String _sPropertyName, String _sReturnVariableName, String _sIncomingObjectName, TypeClass _aTypeClass, String _sTypeName)1009 public String getPropertyValueGetterSourceCode(String _sPropertyName, String _sReturnVariableName, String _sIncomingObjectName, TypeClass _aTypeClass, String _sTypeName){ 1010 String sObjectDescription = _sIncomingObjectName + ".getPropertyValue(\"" + _sPropertyName + "\")"; 1011 String sReturn = getConvertedSourceCodeValueOfObject(_sReturnVariableName, sObjectDescription, _aTypeClass, _sTypeName); 1012 sReturn += ";"; 1013 sReturn = "\t" + sReturn; 1014 return sReturn; 1015 // return "\t" + _sReturnVariableName + " = " + _sIncomingObjectName + ".getPropertyValue(\"" + _sPropertyName + "\");"; 1016 } 1017 1018 getObjectTypeDescription(String _sClassName, boolean _bAsHeader)1019 public String getObjectTypeDescription(String _sClassName, boolean _bAsHeader){ 1020 String sReturn = ""; 1021 if (_bAsHeader){ 1022 sReturn = _sClassName; 1023 } 1024 else{ 1025 sReturn = m_oIntrospector.getShortClassName(_sClassName); 1026 } 1027 return sReturn; 1028 } 1029 1030 getMethodTerminationSourceCode()1031 public String getMethodTerminationSourceCode(){ 1032 String sReturn = ""; 1033 int nIndex = 1; 1034 String sExceptionName = "e"; 1035 if (baddExceptionHandling){ 1036 for (int i = 0; i < sExceptions.size(); i++){ 1037 String sCurException = (String) sExceptions.get(i); 1038 if (sReturn.indexOf(sCurException) == -1){ 1039 if (nIndex > 1){ 1040 sExceptionName = "e"+ nIndex; 1041 } 1042 else{ 1043 sReturn +="\n}"; 1044 } 1045 sReturn += "catch (" + sCurException + " " + sExceptionName + "){\n"; 1046 sReturn += "\t" + sExceptionName + ".printStackTrace(System.out);\n"; 1047 sReturn += "\t" + getCommentSign() + "Enter your Code here...\n}"; 1048 nIndex++; 1049 } 1050 } 1051 } 1052 sReturn += "\n}"; 1053 return sReturn; 1054 } 1055 castLiteral(String _sExpression, TypeClass _aTypeClass)1056 public String castLiteral(String _sExpression, TypeClass _aTypeClass){ 1057 String sReturn = ""; 1058 switch (_aTypeClass.getValue()){ 1059 case TypeClass.BOOLEAN_value: 1060 sReturn = _sExpression; 1061 break; 1062 case TypeClass.BYTE_value: 1063 sReturn = "(byte) " + _sExpression; 1064 break; 1065 case TypeClass.CHAR_value: 1066 sReturn = "'" + _sExpression + "'"; 1067 break; 1068 case TypeClass.DOUBLE_value: 1069 sReturn = "(double) " + _sExpression; 1070 break; 1071 case TypeClass.FLOAT_value: 1072 sReturn = "(float) " + _sExpression; 1073 break; 1074 case TypeClass.UNSIGNED_SHORT_value: 1075 case TypeClass.SHORT_value: 1076 sReturn = "(short) " + _sExpression; 1077 break; 1078 case TypeClass.STRING_value: 1079 sReturn = "\"" + _sExpression + "\""; 1080 break; 1081 case TypeClass.HYPER_value: 1082 case TypeClass.UNSIGNED_HYPER_value: 1083 sReturn = "(long) " + _sExpression; 1084 break; 1085 case TypeClass.LONG_value: 1086 sReturn = _sExpression; 1087 break; 1088 case TypeClass.ENUM_value: 1089 default: 1090 sReturn = _sExpression; 1091 System.out.println("Type " + _aTypeClass.getValue() + " not yet defined in 'castliteral()'"); 1092 } 1093 return sReturn; 1094 } 1095 1096 getbooleanTypeDescription()1097 public String getbooleanTypeDescription(){ 1098 return "boolean"; 1099 } 1100 getbyteTypeDescription()1101 public String getbyteTypeDescription(){ 1102 return "byte"; 1103 } 1104 getshortTypeDescription()1105 public String getshortTypeDescription(){ 1106 return "short"; 1107 } 1108 getunsignedshortTypeDescription()1109 public String getunsignedshortTypeDescription(){ 1110 return "short"; 1111 } 1112 getlongTypeDescription()1113 public String getlongTypeDescription(){ 1114 return "int"; 1115 } 1116 getunsignedlongTypeDescription()1117 public String getunsignedlongTypeDescription(){ 1118 return "int"; 1119 } 1120 gethyperTypeDescription()1121 public String gethyperTypeDescription(){ 1122 return "long"; 1123 } 1124 getunsignedhyperTypeDescription()1125 public String getunsignedhyperTypeDescription(){ 1126 return "long"; 1127 } 1128 getfloatTypeDescription()1129 public String getfloatTypeDescription(){ 1130 return "float"; 1131 } 1132 getdoubleTypeDescription()1133 public String getdoubleTypeDescription(){ 1134 return "double"; 1135 } 1136 getcharTypeDescription()1137 public String getcharTypeDescription(){ 1138 return "char"; 1139 } 1140 getstringTypeDescription(boolean _bAsHeaderSourceCode)1141 public String getstringTypeDescription(boolean _bAsHeaderSourceCode){ 1142 if (_bAsHeaderSourceCode){ 1143 return ""; 1144 } 1145 else{ 1146 return "String"; 1147 } 1148 } 1149 gettypeTypeDescription(boolean _bAsHeaderSourceCode)1150 public String gettypeTypeDescription(boolean _bAsHeaderSourceCode){ 1151 if (_bAsHeaderSourceCode){ 1152 return "com.sun.star.uno.Type"; 1153 } 1154 else{ 1155 return "Type"; 1156 } 1157 } 1158 getanyTypeDescription(boolean _bAsHeaderSourceCode)1159 public String getanyTypeDescription(boolean _bAsHeaderSourceCode){ 1160 if (_bAsHeaderSourceCode){ 1161 return ""; 1162 } 1163 else{ 1164 return "Object"; 1165 } 1166 } 1167 1168 getStringValue(String _sValue)1169 public String getStringValue(String _sValue){ 1170 return _sValue; 1171 } 1172 1173 getVariableDeclaration(String _sTypeString, String _sVariableName, boolean _bIsArray, TypeClass _aTypeClass, boolean _bInitialize)1174 public String getVariableDeclaration(String _sTypeString, String _sVariableName, boolean _bIsArray, TypeClass _aTypeClass, boolean _bInitialize){ 1175 String sReturn = ""; 1176 if (_bIsArray){ 1177 sReturn = _sTypeString + "[] " + _sVariableName; 1178 } 1179 else{ 1180 sReturn = _sTypeString + " " + _sVariableName; 1181 } 1182 return sReturn; 1183 } 1184 1185 getArrayDeclaration(String _sVariableDeclaration)1186 public String getArrayDeclaration(String _sVariableDeclaration){ 1187 String sReturn = ""; 1188 String[] sDeclarations = _sVariableDeclaration.split(" "); 1189 for (int i = 0; i< sDeclarations.length;i++){ 1190 sReturn += sDeclarations[i]; 1191 if (i == 0){ 1192 sReturn += "[]"; 1193 } 1194 if (i < (sDeclarations.length -1)){ 1195 sReturn += " "; 1196 } 1197 } 1198 return sReturn; 1199 } 1200 getCommentSign()1201 public String getCommentSign(){ 1202 return "//"; 1203 } 1204 } 1205 1206 1207 public class BasicCodeGenerator implements XLanguageSourceCodeGenerator{ 1208 String sStatementsCode = ""; 1209 BasicCodeGenerator()1210 public BasicCodeGenerator(){ 1211 } 1212 getHeaderSourceCode(Object _oUnoObject, String _sClassName, TypeClass _aTypeClass)1213 public String getHeaderSourceCode(Object _oUnoObject, String _sClassName, TypeClass _aTypeClass){ 1214 String sHeaderStatement = ""; 1215 return sHeaderStatement; 1216 } 1217 getFinalHeaderStatements()1218 public String getFinalHeaderStatements(){ 1219 return ""; 1220 } 1221 getMainMethodSignatureSourceCode(XUnoNode _oUnoNode, String _soReturnObjectDescription)1222 public String getMainMethodSignatureSourceCode(XUnoNode _oUnoNode, String _soReturnObjectDescription){ 1223 //TODO try to use + _oUnoNode.getClassName() instead of the hack 1224 return "Sub Main(" + _soReturnObjectDescription + " as " + getanyTypeDescription(false) + ")"; 1225 } 1226 needsqueryInterface()1227 public boolean needsqueryInterface(){ 1228 return false; 1229 } 1230 assignqueryInterfaceHeaderSourceCode()1231 public void assignqueryInterfaceHeaderSourceCode(){ 1232 } 1233 getMethodSeparator()1234 public String getMethodSeparator(){ 1235 return "."; 1236 } 1237 1238 getqueryInterfaceSourceCode(String _sClassName, String _sReturnVariableName, String _sIncomingObjectName)1239 public String getqueryInterfaceSourceCode(String _sClassName, String _sReturnVariableName, String _sIncomingObjectName){ 1240 return _sIncomingObjectName; 1241 } 1242 1243 getPropertyValueGetterSourceCode(String _sPropertyName, String _sReturnVariableName, String _sIncomingObjectName, TypeClass _aTypeClass, String _sTypeName)1244 public String getPropertyValueGetterSourceCode(String _sPropertyName, String _sReturnVariableName, String _sIncomingObjectName, TypeClass _aTypeClass, String _sTypeName){ 1245 return "\t" + _sReturnVariableName + " = " + _sIncomingObjectName + "." + _sPropertyName; 1246 } 1247 1248 getStructSourceCode(String _sReturnVariableDescription, String _sObjectDescription, String _sMember)1249 public String getStructSourceCode(String _sReturnVariableDescription, String _sObjectDescription, String _sMember){ 1250 return getPropertyValueGetterSourceCode(_sMember, _sReturnVariableDescription, _sObjectDescription, null, "" ); 1251 } 1252 getConvertedSourceCodeValueOfObject(String _sReturnVariableName, String _sObjectDescription, TypeClass _aTypeClass, String _sTypeName)1253 public String getConvertedSourceCodeValueOfObject(String _sReturnVariableName, String _sObjectDescription, TypeClass _aTypeClass, String _sTypeName){ 1254 return _sReturnVariableName + " = " + _sObjectDescription; 1255 } 1256 1257 getObjectTypeDescription(String _sClassName, boolean _bAsHeader)1258 public String getObjectTypeDescription(String _sClassName, boolean _bAsHeader){ 1259 return "Object"; 1260 } 1261 1262 getMethodTerminationSourceCode()1263 public String getMethodTerminationSourceCode(){ 1264 return "\nEnd Sub\n"; 1265 } 1266 1267 castLiteral(String _sExpression, TypeClass _aTypeClass)1268 public String castLiteral(String _sExpression, TypeClass _aTypeClass){ 1269 String sReturn = ""; 1270 switch (_aTypeClass.getValue()){ 1271 case TypeClass.BOOLEAN_value: 1272 case TypeClass.BYTE_value: 1273 case TypeClass.DOUBLE_value: 1274 case TypeClass.FLOAT_value: 1275 case TypeClass.UNSIGNED_SHORT_value: 1276 case TypeClass.SHORT_value: 1277 case TypeClass.LONG_value: 1278 case TypeClass.UNSIGNED_LONG_value: 1279 case TypeClass.HYPER_value: 1280 case TypeClass.UNSIGNED_HYPER_value: 1281 sReturn = _sExpression; 1282 break; 1283 case TypeClass.CHAR_value: 1284 case TypeClass.STRING_value: 1285 sReturn = "\"" +_sExpression + "\""; 1286 break; 1287 case TypeClass.ENUM_value: 1288 default: 1289 sReturn = _sExpression; 1290 System.out.println("Type " + _aTypeClass.getValue() + " not yet defined in 'castliteral()'"); 1291 } 1292 return sReturn; 1293 } 1294 1295 1296 getbooleanTypeDescription()1297 public String getbooleanTypeDescription(){ 1298 return "Boolean"; 1299 } 1300 getbyteTypeDescription()1301 public String getbyteTypeDescription(){ 1302 return "Integer"; 1303 } 1304 getshortTypeDescription()1305 public String getshortTypeDescription(){ 1306 return "Integer"; 1307 } 1308 getunsignedshortTypeDescription()1309 public String getunsignedshortTypeDescription(){ 1310 return "Integer"; 1311 } 1312 getlongTypeDescription()1313 public String getlongTypeDescription(){ 1314 return "Integer"; 1315 } 1316 getunsignedlongTypeDescription()1317 public String getunsignedlongTypeDescription(){ 1318 return "Long"; 1319 } 1320 gethyperTypeDescription()1321 public String gethyperTypeDescription(){ 1322 return "Long"; 1323 } 1324 getunsignedhyperTypeDescription()1325 public String getunsignedhyperTypeDescription(){ 1326 return "Long"; 1327 } 1328 getfloatTypeDescription()1329 public String getfloatTypeDescription(){ 1330 return "Double"; 1331 } 1332 getdoubleTypeDescription()1333 public String getdoubleTypeDescription(){ 1334 return "Double"; 1335 } 1336 getcharTypeDescription()1337 public String getcharTypeDescription(){ 1338 return "String"; 1339 } 1340 getstringTypeDescription(boolean _bAsHeaderSourceCode)1341 public String getstringTypeDescription(boolean _bAsHeaderSourceCode){ 1342 if (_bAsHeaderSourceCode){ 1343 return ""; 1344 } 1345 else{ 1346 return "String"; 1347 } 1348 } 1349 gettypeTypeDescription(boolean _bAsHeaderSourceCode)1350 public String gettypeTypeDescription(boolean _bAsHeaderSourceCode){ 1351 if (_bAsHeaderSourceCode){ 1352 return ""; 1353 } 1354 else{ 1355 return "Object"; 1356 } 1357 } 1358 getanyTypeDescription(boolean _bAsHeaderSourceCode)1359 public String getanyTypeDescription(boolean _bAsHeaderSourceCode){ 1360 if (_bAsHeaderSourceCode){ 1361 return ""; 1362 } 1363 else{ 1364 return "Object"; 1365 } 1366 } 1367 getStatementTerminationCharacter()1368 public String getStatementTerminationCharacter(){ 1369 return ""; 1370 } 1371 1372 getVariableDeclaration(String _sTypeString, String _sVariableName, boolean bIsArray, TypeClass _aTypeClass, boolean _bInitialize)1373 public String getVariableDeclaration(String _sTypeString, String _sVariableName, boolean bIsArray, TypeClass _aTypeClass, boolean _bInitialize){ 1374 String sReturn = ""; 1375 if (bIsArray){ 1376 sReturn = "Dim " + _sVariableName + "() as " + _sTypeString + "\n\t" + _sVariableName; 1377 } 1378 else{ 1379 sReturn = "Dim " + _sVariableName + " as " + _sTypeString + "\n\t" + _sVariableName; 1380 } 1381 return sReturn; 1382 } 1383 1384 getStringValue(String _sValue)1385 public String getStringValue(String _sValue){ 1386 return _sValue; 1387 } 1388 1389 getArrayDeclaration(String _sVariableDeclaration)1390 public String getArrayDeclaration(String _sVariableDeclaration){ 1391 String sReturn = ""; 1392 String[] sDeclarations = _sVariableDeclaration.split(" "); 1393 for (int i = 0; i< sDeclarations.length;i++){ 1394 sReturn += sDeclarations[i]; 1395 if (i == 0){ 1396 sReturn += "[]"; 1397 } 1398 if (i < (sDeclarations.length -1)){ 1399 sReturn += " "; 1400 } 1401 } 1402 return sReturn; 1403 } 1404 getCommentSign()1405 public String getCommentSign(){ 1406 return "'"; 1407 } 1408 1409 } 1410 1411 public class CPlusPlusCodeGenerator implements XLanguageSourceCodeGenerator{ 1412 String sStatementsCode = ""; 1413 boolean bIncludeStringHeader = false; 1414 boolean bIncludeAny = false; 1415 boolean bIncludeSequenceHeader = false; 1416 CPlusPlusCodeGenerator()1417 public CPlusPlusCodeGenerator(){ 1418 } 1419 getCSSNameSpaceString()1420 private String getCSSNameSpaceString(){ 1421 return "css"; 1422 } 1423 getStatementTerminationCharacter()1424 public String getStatementTerminationCharacter(){ 1425 return ";"; 1426 } 1427 1428 getHeaderSourceCode(Object _oUnoObject, String _sClassName, TypeClass _aTypeClass)1429 public String getHeaderSourceCode(Object _oUnoObject, String _sClassName, TypeClass _aTypeClass){ 1430 String sClassName = _sClassName; 1431 String sHeaderStatement = ""; 1432 if (_oUnoObject != null){ 1433 if (!m_oIntrospector.isObjectPrimitive(_oUnoObject)){ 1434 if (m_oIntrospector.isObjectSequence(_oUnoObject)){ 1435 XTypeDescription xTypeDescription = m_oIntrospector.getReferencedType(sClassName); 1436 if (xTypeDescription != null){ 1437 if (!m_oIntrospector.isPrimitive(xTypeDescription.getTypeClass())){ 1438 sClassName = getTypeString(xTypeDescription.getName(), xTypeDescription.getTypeClass(), true); 1439 } 1440 // primitive Types are not supposed to turn up in the import section... 1441 else{ 1442 sClassName = ""; 1443 } 1444 } 1445 } 1446 else{ 1447 sClassName = getTypeString(_sClassName, _aTypeClass, true); 1448 } 1449 if (!sClassName.equals("")){ 1450 sHeaderStatement = getHeaderOfClass(sClassName); 1451 } 1452 } 1453 } 1454 return sHeaderStatement; 1455 } 1456 1457 1458 getFinalHeaderStatements()1459 public String getFinalHeaderStatements(){ 1460 String sReturn = ""; 1461 sReturn += "\nnamespace " + getCSSNameSpaceString() + " = com::sun::star;\n"; 1462 sReturn += "using namespace rtl;\n"; 1463 return sReturn; 1464 } 1465 1466 getHeaderOfClass(String _sClassName)1467 private String getHeaderOfClass(String _sClassName){ 1468 return "#include \"" + _sClassName.replace('.', '/') + ".hpp\"\n"; // #include <com/sun/star/uno/XComponentContext.hpp> 1469 } 1470 1471 1472 assignqueryInterfaceHeaderSourceCode()1473 public void assignqueryInterfaceHeaderSourceCode(){ 1474 sHeaderStatements.add("#include \"sal/config.h\"\n"); 1475 sHeaderStatements.add("#include \"sal/types.h\"\n"); 1476 if (bIncludeStringHeader){ 1477 sHeaderStatements.add("#include \"rtl/ustring.hxx\"\n"); 1478 } 1479 sHeaderStatements.add("#include \"com/sun/star/uno/Reference.hxx\"\n"); 1480 if (bIncludeSequenceHeader){ 1481 sHeaderStatements.add("#include \"com/sun/star/uno/Sequence.hxx\"\n"); 1482 } 1483 sHeaderStatements.add(getHeaderOfClass("com.sun.star.uno.XInterface")); 1484 if (bIncludeAny){ 1485 sHeaderStatements.add(getHeaderOfClass("com.sun.star.uno.Any")); 1486 } 1487 } 1488 1489 getMainMethodSignatureSourceCode(XUnoNode _oUnoNode, String _soReturnObjectDescription)1490 public String getMainMethodSignatureSourceCode(XUnoNode _oUnoNode, String _soReturnObjectDescription){ 1491 String sReturn = ""; 1492 sReturn = "void codesnippet(const " + getCSSNameSpaceString() + "::uno::Reference<" + getCSSNameSpaceString() + "::uno::XInterface>& " + _soReturnObjectDescription + " ){"; 1493 int a = 0; 1494 if (!sExceptions.contains("com.sun.star.uno.RuntimeException")){ 1495 sExceptions.add("com.sun.star.uno.RuntimeException"); 1496 } 1497 if (baddExceptionHandling){ 1498 sReturn += "\n//throw "; 1499 for (int i = 0; i < sExceptions.size(); i++){ 1500 String sCurException = (String) sExceptions.get(i); 1501 if (sReturn.indexOf(sCurException) == -1){ 1502 if (a++ > 0){ 1503 sReturn += ", "; 1504 } 1505 sReturn += getObjectTypeDescription(sCurException, false); 1506 1507 } 1508 } 1509 1510 } 1511 sReturn += "{"; 1512 return sReturn; 1513 } 1514 1515 needsqueryInterface()1516 public boolean needsqueryInterface(){ 1517 return true; 1518 } 1519 1520 getqueryInterfaceSourceCode(String _sClassName, String _sReturnVariableName, String _sIncomingObjectName)1521 public String getqueryInterfaceSourceCode(String _sClassName, String _sReturnVariableName, String _sIncomingObjectName){ 1522 return "\t" + _sReturnVariableName + "( " + _sIncomingObjectName + ", " + getCSSNameSpaceString() + "::uno::UNO_QUERY_THROW);\n"; 1523 } 1524 1525 getPropertyValueGetterSourceCode(String _sPropertyName, String _sReturnVariableName, String _sIncomingObjectName, TypeClass _aTypeClass, String _sTypeName)1526 public String getPropertyValueGetterSourceCode(String _sPropertyName, String _sReturnVariableName, String _sIncomingObjectName, TypeClass _aTypeClass, String _sTypeName){ 1527 String sFirstLine = "\t"; 1528 String sReturnVariableName = _sReturnVariableName; 1529 // e.g. uno::Any a = xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" )) ); 1530 String[] sVarDefinition = _sReturnVariableName.split("="); 1531 if (sVarDefinition.length > 0){ 1532 String sVariable = sVarDefinition[0]; 1533 String[] sVarDeclaration = sVariable.split(" "); 1534 if (sVarDeclaration.length > 0){ 1535 sFirstLine += sReturnVariableName + ";\n"; 1536 sReturnVariableName = sVarDeclaration[sVarDeclaration.length-1]; 1537 } 1538 } 1539 String sObjectDescription = _sIncomingObjectName + "->getPropertyValue(" + getStringValue(_sPropertyName) + ")"; 1540 String sSecondLine = "\t" + getConvertedSourceCodeValueOfObject(sReturnVariableName, sObjectDescription, _aTypeClass, _sTypeName) + ";"; 1541 return sFirstLine + sSecondLine; 1542 } 1543 1544 getStructSourceCode(String _sReturnVariableDescription, String _sObjectDescription, String _sMember)1545 public String getStructSourceCode(String _sReturnVariableDescription, String _sObjectDescription, String _sMember){ 1546 return "\t" + _sReturnVariableDescription + " = " + _sObjectDescription + "->" + _sMember + ";"; 1547 } 1548 1549 getConvertedSourceCodeValueOfObject(String _sReturnVariableName, String _sObjectDescription, TypeClass _aTypeClass, String _sTypeName)1550 public String getConvertedSourceCodeValueOfObject(String _sReturnVariableName, String _sObjectDescription, TypeClass _aTypeClass, String _sTypeName){ 1551 // if (m_oIntrospector.isPrimitive(_aTypeClass)){ 1552 return _sObjectDescription + " >>= " + _sReturnVariableName; 1553 // } 1554 // else{ 1555 // return _sReturnVariableName + " = " + _sObjectDescription; 1556 // } 1557 } 1558 1559 getStringValue(String _sValue)1560 public String getStringValue(String _sValue){ 1561 bIncludeStringHeader = true; 1562 return "OUString(RTL_CONSTASCII_USTRINGPARAM(\"" + _sValue + "\"))"; 1563 } 1564 1565 getObjectTypeDescription(String _sClassName, boolean _bAsHeader)1566 public String getObjectTypeDescription(String _sClassName, boolean _bAsHeader){ 1567 String sReturn = ""; 1568 if (_bAsHeader){ 1569 sReturn = _sClassName.replace('.', '/'); 1570 } 1571 else{ 1572 String sModuleName = m_oIntrospector.getModuleName(_sClassName); 1573 sModuleName = m_oIntrospector.getShortClassName(sModuleName); 1574 sReturn = getCSSNameSpaceString() + "::" + sModuleName + "::" + m_oIntrospector.getShortClassName(_sClassName); 1575 } 1576 return sReturn; 1577 } 1578 1579 getMethodTerminationSourceCode()1580 public String getMethodTerminationSourceCode(){ 1581 return "\n}"; 1582 } 1583 getMethodSeparator()1584 public String getMethodSeparator(){ 1585 return "->"; 1586 } 1587 1588 castLiteral(String _sExpression, TypeClass _aTypeClass)1589 public String castLiteral(String _sExpression, TypeClass _aTypeClass){ 1590 String sReturn = ""; 1591 switch (_aTypeClass.getValue()){ 1592 case TypeClass.BOOLEAN_value: 1593 case TypeClass.BYTE_value: 1594 case TypeClass.DOUBLE_value: 1595 case TypeClass.FLOAT_value: 1596 case TypeClass.UNSIGNED_SHORT_value: 1597 case TypeClass.SHORT_value: 1598 case TypeClass.LONG_value: 1599 case TypeClass.UNSIGNED_LONG_value: 1600 case TypeClass.HYPER_value: 1601 case TypeClass.UNSIGNED_HYPER_value: 1602 sReturn = _sExpression; 1603 break; 1604 case TypeClass.CHAR_value: 1605 sReturn = "'" + _sExpression + "'"; 1606 break; 1607 case TypeClass.STRING_value: 1608 sReturn = getStringValue(_sExpression); 1609 break; 1610 case TypeClass.ENUM_value: 1611 default: 1612 sReturn = _sExpression; 1613 System.out.println("Type " + _aTypeClass.getValue() + " not yet defined in 'castliteral()'"); 1614 } 1615 return sReturn; 1616 } 1617 getbooleanTypeDescription()1618 public String getbooleanTypeDescription(){ 1619 return "sal_Bool"; 1620 } 1621 getbyteTypeDescription()1622 public String getbyteTypeDescription(){ 1623 return "sal_Int8"; 1624 } 1625 getshortTypeDescription()1626 public String getshortTypeDescription(){ 1627 return "sal_Int16"; 1628 } 1629 getunsignedshortTypeDescription()1630 public String getunsignedshortTypeDescription(){ 1631 return "sal_uInt16"; 1632 } 1633 getlongTypeDescription()1634 public String getlongTypeDescription(){ 1635 return "sal_Int32"; 1636 } 1637 getunsignedlongTypeDescription()1638 public String getunsignedlongTypeDescription(){ 1639 return "sal_uInt32"; 1640 } 1641 gethyperTypeDescription()1642 public String gethyperTypeDescription(){ 1643 return "sal_Int64"; 1644 } 1645 getunsignedhyperTypeDescription()1646 public String getunsignedhyperTypeDescription(){ 1647 return "sal_uInt64"; 1648 } 1649 getfloatTypeDescription()1650 public String getfloatTypeDescription(){ 1651 return "float"; 1652 } 1653 getdoubleTypeDescription()1654 public String getdoubleTypeDescription(){ 1655 return "double"; 1656 } 1657 getcharTypeDescription()1658 public String getcharTypeDescription(){ 1659 return "sal_Unicode"; 1660 } 1661 getstringTypeDescription(boolean _bAsHeaderSourceCode)1662 public String getstringTypeDescription(boolean _bAsHeaderSourceCode){ 1663 bIncludeStringHeader = true; 1664 if (_bAsHeaderSourceCode){ 1665 return ""; 1666 } 1667 else{ 1668 return "OUString"; 1669 } 1670 } 1671 gettypeTypeDescription(boolean _bAsHeaderSourceCode)1672 public String gettypeTypeDescription(boolean _bAsHeaderSourceCode){ 1673 if (_bAsHeaderSourceCode){ 1674 return "com/sun/star/uno/Type"; 1675 } 1676 else{ 1677 return "Type"; 1678 } 1679 } 1680 getanyTypeDescription(boolean _bAsHeaderSourceCode)1681 public String getanyTypeDescription(boolean _bAsHeaderSourceCode){ 1682 if (_bAsHeaderSourceCode){ 1683 return "com/sun/star/uno/XInterface"; 1684 } 1685 else{ 1686 return "XInterface"; 1687 } 1688 } 1689 1690 getVariableDeclaration(String _sTypeString, String _sVariableName, boolean bIsArray, TypeClass _aTypeClass, boolean _bInitialize)1691 public String getVariableDeclaration(String _sTypeString, String _sVariableName, boolean bIsArray, TypeClass _aTypeClass, boolean _bInitialize){ 1692 boolean bIsPrimitive = m_oIntrospector.isPrimitive(_aTypeClass); 1693 1694 // uno::Reference< frame::XDispatch > m_xDispatch 1695 String sReturn = ""; 1696 if (bIsArray){ 1697 bIncludeSequenceHeader = true; 1698 sReturn = getCSSNameSpaceString() + "::uno::Sequence<" + _sTypeString + "> " + _sVariableName; 1699 } 1700 else{ 1701 if (bIsPrimitive){ 1702 sReturn = _sTypeString + " " + _sVariableName; 1703 if (_bInitialize){ 1704 switch (_aTypeClass.getValue()){ 1705 case TypeClass.BOOLEAN_value: 1706 sReturn = sReturn + " = false"; 1707 break; 1708 case TypeClass.BYTE_value: 1709 case TypeClass.UNSIGNED_SHORT_value: 1710 case TypeClass.SHORT_value: 1711 case TypeClass.LONG_value: 1712 case TypeClass.UNSIGNED_LONG_value: 1713 case TypeClass.HYPER_value: 1714 case TypeClass.UNSIGNED_HYPER_value: 1715 sReturn = sReturn + " = 0"; 1716 break; 1717 case TypeClass.DOUBLE_value: 1718 case TypeClass.FLOAT_value: 1719 sReturn = sReturn + " = 0.0"; 1720 break; 1721 case TypeClass.CHAR_value: 1722 sReturn = sReturn + "'0'"; 1723 break; 1724 case TypeClass.STRING_value: 1725 sReturn = _sTypeString + " " + _sVariableName; 1726 break; 1727 default: 1728 sReturn = _sTypeString + " " + _sVariableName; 1729 System.out.println("Type " + _aTypeClass.getValue() + " not yet defined in 'getVariableDeclaration()'"); 1730 } 1731 } 1732 } 1733 else{ 1734 sReturn = getCSSNameSpaceString() + "::uno::Reference<" + _sTypeString + "> " +_sVariableName; 1735 } 1736 } 1737 return sReturn; 1738 } 1739 getArrayDeclaration(String _sVariableDeclaration)1740 public String getArrayDeclaration(String _sVariableDeclaration){ 1741 this.bIncludeSequenceHeader = true; 1742 String sReturn = ""; 1743 String[] sDeclarations = _sVariableDeclaration.split(" "); 1744 if (sDeclarations.length == 2){ 1745 sReturn = getCSSNameSpaceString() +"::uno::Sequence<" + sDeclarations[1] + ">"; 1746 } 1747 return sReturn; 1748 } 1749 getCommentSign()1750 public String getCommentSign(){ 1751 return "//"; 1752 } 1753 1754 } 1755 } 1756