1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
7 * Copyright 2000, 2010 Oracle and/or its affiliates.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
29 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
31 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
32 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *************************************************************************/
36 import java
.util
.ArrayList
;
37 import java
.util
.HashMap
;
39 import com
.sun
.star
.reflection
.ParamInfo
;
40 import com
.sun
.star
.reflection
.XIdlClass
;
41 import com
.sun
.star
.reflection
.XIdlMethod
;
42 import com
.sun
.star
.reflection
.XTypeDescription
;
43 import com
.sun
.star
.uno
.Any
;
44 import com
.sun
.star
.uno
.AnyConverter
;
45 import com
.sun
.star
.uno
.TypeClass
;
49 public class SourceCodeGenerator
{
50 private ArrayList
<String
> sExceptions
= new ArrayList
<String
>();
51 private ArrayList
<String
> sHeaderStatements
= new HeaderStatements();
52 private XLanguageSourceCodeGenerator m_xLanguageSourceCodeGenerator
;
53 private String sStatementCode
= "";
54 private String sMainMethodSignature
= "";
56 private HashMap
<String
, UnoObjectDefinition
> aVariables
= new HashMap
<String
, UnoObjectDefinition
>();
57 private final String SSUFFIXSEPARATOR
= "_";
58 private final String SVARIABLENAME
= "VariableName";
59 private Introspector m_oIntrospector
;
60 private ArrayList
<XTreePathProvider
> aTreepathProviders
= new ArrayList
<XTreePathProvider
>();
61 private boolean baddExceptionHandling
= false;
62 private boolean bXPropertySetExceptionsAreAdded
= false;
63 private XUnoNode oInitialUnoNode
= null;
64 private final String sINITIALVARIABLENAME
= "_oUnoEntryObject";
67 /** Creates a new instance of SourceCodeGenerator */
68 public SourceCodeGenerator(int _nLanguage
) {
69 this.setLanguage(_nLanguage
);
70 m_oIntrospector
= Introspector
.getIntrospector();
74 public String
addSourceCodeOfUnoObject(XTreePathProvider _xTreepathProvider
, boolean _brememberPath
, boolean _baddHeader
){
75 String sVariableName
= "";
76 if (_xTreepathProvider
!= null) {
77 for (int i
= 0; i
< _xTreepathProvider
.getPathCount(); i
++){
78 XUnoNode oUnoNode
= _xTreepathProvider
.getPathComponent(i
);
80 sVariableName
= sINITIALVARIABLENAME
;
81 oInitialUnoNode
= oUnoNode
;
84 if (oUnoNode
instanceof XUnoMethodNode
){
85 XUnoMethodNode oUnoMethodNode
= (XUnoMethodNode
) oUnoNode
;
86 if (oUnoMethodNode
.isInvoked()){
87 UnoObjectDefinition oUnoReturnObjectDefinition
= getUnoObjectDefinition(_xTreepathProvider
, oUnoMethodNode
, i
);
88 if (!isVariableDeclared(oUnoReturnObjectDefinition
, this.generateVariableNameFromMethod(oUnoMethodNode
.getXIdlMethod()))){
89 sStatementCode
+= "\n" + getMethodStatementSourceCode(oUnoMethodNode
, sVariableName
, oUnoReturnObjectDefinition
);
91 sVariableName
= oUnoReturnObjectDefinition
.getVariableName();
94 else if (oUnoNode
instanceof XUnoPropertyNode
){
95 XUnoPropertyNode oUnoPropertyNode
= (XUnoPropertyNode
) oUnoNode
;
96 Any oReturnObject
= com
.sun
.star
.uno
.Any
.complete(oUnoPropertyNode
.getUnoReturnObject());
97 UnoObjectDefinition oUnoReturnObjectDefinition
= new UnoObjectDefinition(oReturnObject
);
98 if (!isVariableDeclared(oUnoReturnObjectDefinition
, oUnoPropertyNode
.getProperty().Name
)){
99 sStatementCode
+= "\n" + getPropertyStatementSourceCode(oUnoPropertyNode
, sVariableName
, oUnoReturnObjectDefinition
);
101 sVariableName
= oUnoReturnObjectDefinition
.getVariableName();
106 String sCompleteCode
= combineCompleteSourceCode(_baddHeader
);
108 aTreepathProviders
.add(_xTreepathProvider
);
110 return sCompleteCode
;
114 private void setLanguage(int _nLanguage
){
115 XLanguageSourceCodeGenerator xLanguageSourceCodeGenerator
= null;
117 case XLanguageSourceCodeGenerator
.nJAVA
:
118 xLanguageSourceCodeGenerator
= new JavaCodeGenerator();
120 case XLanguageSourceCodeGenerator
.nCPLUSPLUS
:
121 xLanguageSourceCodeGenerator
= new CPlusPlusCodeGenerator();
123 case XLanguageSourceCodeGenerator
.nBASIC
:
124 xLanguageSourceCodeGenerator
= new BasicCodeGenerator();
127 System
.out
.println("Unknown Sourcecode Language. Check Menus!");
129 if (xLanguageSourceCodeGenerator
!= null){
130 m_xLanguageSourceCodeGenerator
= xLanguageSourceCodeGenerator
;
134 private void resetSourceCodeGeneration(int _nLanguage
){
136 this.sHeaderStatements
.clear();
137 setLanguage(_nLanguage
);
141 private String
generateVariableNameFromMethod(String _sMethodName
, String _sPrefix
, boolean _bConsiderAll
){
143 if (_sMethodName
.startsWith(_sPrefix
)){
144 int nPrefixLength
= _sPrefix
.length();
145 if (_sMethodName
.length() > nPrefixLength
){
146 String sChar
= _sMethodName
.substring(nPrefixLength
, nPrefixLength
+ 1);
147 String sUpperChar
= sChar
.toUpperCase();
148 if (sUpperChar
.equals(sChar
)){
150 sReturn
= _sMethodName
;
153 sReturn
= _sMethodName
.substring(nPrefixLength
, _sMethodName
.length());
162 private String
generateVariableNameFromMethod(XIdlMethod _xIdlMethod
){
163 // todo: refactor this!!!
164 String sMethodName
= _xIdlMethod
.getName();
166 sReturn
= generateVariableNameFromMethod(sMethodName
, "getBy", false);
167 if (sReturn
.equals("")){
168 sReturn
= generateVariableNameFromMethod(sMethodName
, "get", false);
170 if (sReturn
.equals("")){
171 sReturn
= generateVariableNameFromMethod(sMethodName
, "attach", false);
173 if (sReturn
.equals("")){
174 sReturn
= generateVariableNameFromMethod(sMethodName
, "assign", false);
176 if (sReturn
.equals("")){
177 sReturn
= generateVariableNameFromMethod(sMethodName
, "attach", false);
179 if (sReturn
.equals("")){
180 sReturn
= generateVariableNameFromMethod(sMethodName
, "create", false);
182 if (sReturn
.equals("")){
183 sReturn
= generateVariableNameFromMethod(sMethodName
, "is", true);
185 if (sReturn
.equals("")){
186 sReturn
= generateVariableNameFromMethod(sMethodName
, "has", true);
188 if (sReturn
.equals("")){
189 sReturn
= sMethodName
;
195 public String
convertAllUnoObjects(int _nLanguage
){
196 String sSourceCode
= "";
197 resetSourceCodeGeneration(_nLanguage
);
198 int ncount
= aTreepathProviders
.size();
199 for (int i
=0; i
< ncount
; i
++){
200 sSourceCode
= addSourceCodeOfUnoObject(aTreepathProviders
.get(i
), false, (i
== (ncount
-1)));
205 private UnoObjectDefinition
getUnoObjectDefinition(XTreePathProvider _xTreePathProvider
, XUnoMethodNode _oUnoMethodNode
, int _nindex
){
206 XUnoNode oUnoNode
= null;
207 Object oUnoReturnObject
= null;
208 Object
[] oParamObjects
= null;
209 XIdlClass xIdlClass
= _oUnoMethodNode
.getXIdlMethod().getReturnType();
210 String sTypeName
= xIdlClass
.getName();
211 TypeClass aTypeClass
= xIdlClass
.getTypeClass();
212 if (aTypeClass
.getValue() != TypeClass
.VOID_value
){
213 if (_xTreePathProvider
.getPathCount() > _nindex
+ 1){
214 oUnoNode
= _xTreePathProvider
.getPathComponent(_nindex
+ 1);
215 oUnoReturnObject
= oUnoNode
.getUnoObject();
218 if (oUnoReturnObject
== null){
219 oUnoReturnObject
= _oUnoMethodNode
.getLastUnoReturnObject();
221 UnoObjectDefinition oUnoObjectDefinition
= new UnoObjectDefinition(oUnoReturnObject
, sTypeName
, aTypeClass
);
222 if (_oUnoMethodNode
.hasParameters()){
223 if (oUnoNode
!= null){
224 oParamObjects
= oUnoNode
.getParameterObjects();
227 oParamObjects
= _oUnoMethodNode
.getLastParameterObjects();
230 if (oParamObjects
!= null){
231 oUnoObjectDefinition
.addParameterObjects(oParamObjects
);
233 return oUnoObjectDefinition
;
237 private String
combineCompleteSourceCode(boolean _bAddHeader
){
238 String sCompleteCode
= "";
240 sMainMethodSignature
= m_xLanguageSourceCodeGenerator
.getMainMethodSignatureSourceCode(oInitialUnoNode
, sINITIALVARIABLENAME
);
241 m_xLanguageSourceCodeGenerator
.assignqueryInterfaceHeaderSourceCode();
242 sCompleteCode
+= getHeaderSourceCode();
244 sCompleteCode
+= sMainMethodSignature
;
245 sCompleteCode
+= sStatementCode
;
247 sCompleteCode
+= m_xLanguageSourceCodeGenerator
.getMethodTerminationSourceCode();
248 sCompleteCode
+= "\n" + m_xLanguageSourceCodeGenerator
.getCommentSign() + "...";
250 return sCompleteCode
;
254 private String
getPropertyStatementSourceCode(XUnoPropertyNode _oUnoPropertyNode
, String _sVariableName
, UnoObjectDefinition _oUnoReturnObjectDefinition
){
255 String sReturnObjectVariableDefinition
= "";
256 String sStatement
= "";
257 String sPropertyName
= _oUnoPropertyNode
.getProperty().Name
;
258 UnoObjectDefinition oUnoObjectDefinition
= new UnoObjectDefinition(_oUnoPropertyNode
.getUnoObject(), "com.sun.star.beans.XPropertySet");
259 if (!m_xLanguageSourceCodeGenerator
.needsqueryInterface() || (oUnoObjectDefinition
.getTypeClass().getValue() == TypeClass
.STRUCT_value
)){
260 oUnoObjectDefinition
.setVariableName(_sVariableName
);
261 if (oUnoObjectDefinition
.getTypeClass().getValue() == TypeClass
.STRUCT_value
){
262 sReturnObjectVariableDefinition
= getVariableInitialization(_oUnoReturnObjectDefinition
, false);
263 sStatement
+= m_xLanguageSourceCodeGenerator
.getStructSourceCode(sReturnObjectVariableDefinition
, oUnoObjectDefinition
.getVariableName(), sPropertyName
);
267 sStatement
+= addQueryInterfaceSourceCode(oUnoObjectDefinition
, _sVariableName
, "com.sun.star.beans.XPropertySet");
268 if (_oUnoReturnObjectDefinition
.getTypeClass().getValue() != TypeClass
.VOID_value
){
269 sReturnObjectVariableDefinition
= getVariableInitialization(_oUnoReturnObjectDefinition
, true);
271 sStatement
+= m_xLanguageSourceCodeGenerator
.getPropertyValueGetterSourceCode(sPropertyName
, sReturnObjectVariableDefinition
, oUnoObjectDefinition
.getVariableName(), _oUnoReturnObjectDefinition
.getTypeClass(), _oUnoReturnObjectDefinition
.getTypeName());
272 addXPropertySetRelatedExceptions();
277 private String
getMethodStatementSourceCode(XUnoMethodNode _oUnoMethodNode
, String _sVariableName
, UnoObjectDefinition _oUnoReturnObjectDefinition
){
278 String sReturnObjectVariableDefinition
= "";
279 String sStatement
= "";
280 XIdlMethod xIdlMethod
= _oUnoMethodNode
.getXIdlMethod();
281 TypeClass aReturnTypeClass
= xIdlMethod
.getReturnType().getTypeClass();
282 UnoObjectDefinition oUnoObjectDefinition
= new UnoObjectDefinition(_oUnoMethodNode
.getUnoObject(), _oUnoMethodNode
.getClassName());
283 String sVariableStemName
= this.generateVariableNameFromMethod(xIdlMethod
);
284 sStatement
+= addQueryInterfaceSourceCode(oUnoObjectDefinition
, _sVariableName
, oUnoObjectDefinition
.getTypeName());
285 if (_oUnoReturnObjectDefinition
.getTypeClass().getValue() != TypeClass
.VOID_value
){
286 sReturnObjectVariableDefinition
= getVariableInitialization(_oUnoReturnObjectDefinition
, false) + " = ";
288 Object
[] oParamObjects
= _oUnoReturnObjectDefinition
.getParameterObjects();
289 String sParameterCode
= getMethodParameterValueDescription(_oUnoMethodNode
, oParamObjects
, false);
290 String sSeparator
= m_xLanguageSourceCodeGenerator
.getMethodSeparator();
291 sStatement
+= "\t" + sReturnObjectVariableDefinition
+ oUnoObjectDefinition
.getVariableName() + sSeparator
+ xIdlMethod
.getName() + "(" + sParameterCode
+ ")";
292 sStatement
+= m_xLanguageSourceCodeGenerator
.getStatementTerminationCharacter();
293 addExceptions(xIdlMethod
);
298 private String
addQueryInterfaceSourceCode(UnoObjectDefinition _oUnoObjectDefinition
, String _sVariableName
, String _sTypeName
){
299 String sLocStatement
= "";
300 if (m_xLanguageSourceCodeGenerator
.needsqueryInterface()){
301 if (!isVariableDeclared(_oUnoObjectDefinition
, "")){
302 String sObjectVariableDefinition
= getVariableDeclaration(_oUnoObjectDefinition
, false, "");
303 sLocStatement
+= m_xLanguageSourceCodeGenerator
.getqueryInterfaceSourceCode(_sTypeName
, sObjectVariableDefinition
, _sVariableName
);
307 _oUnoObjectDefinition
.setVariableName(_sVariableName
);
309 return sLocStatement
;
313 private void addXPropertySetRelatedExceptions(){
314 if (!bXPropertySetExceptionsAreAdded
){
315 sExceptions
.add("com.sun.star.beans.UnknownPropertyException");
316 sExceptions
.add("com.sun.star.lang.WrappedTargetException");
317 sExceptions
.add("com.sun.star.lang.IllegalArgumentException");
318 bXPropertySetExceptionsAreAdded
= true;
319 baddExceptionHandling
= true;
324 private void addExceptions(XIdlMethod _xIdlMethod
){
325 XIdlClass
[] xIdlClasses
= _xIdlMethod
.getExceptionTypes();
326 for (int i
= 0; i
> xIdlClasses
.length
; i
++){
327 sExceptions
.add(xIdlClasses
[0].getName());
328 baddExceptionHandling
= true;
332 private String
getHeaderSourceCode(){
333 for(UnoObjectDefinition oUnoObjectDefinition
: aVariables
.values()){
334 String sCurHeaderStatement
= m_xLanguageSourceCodeGenerator
.getHeaderSourceCode(oUnoObjectDefinition
.getUnoObject(), oUnoObjectDefinition
.getTypeName(), oUnoObjectDefinition
.getTypeClass());
335 sHeaderStatements
.add(sCurHeaderStatement
);
337 String sHeaderSourcecode
= "";
338 String
[] sHeaderStatementArray
= new String
[sHeaderStatements
.size()];
339 sHeaderStatements
.toArray(sHeaderStatementArray
);
340 java
.util
.Arrays
.sort(sHeaderStatementArray
);
341 for (int i
= 0; i
< sHeaderStatementArray
.length
; i
++){
342 sHeaderSourcecode
+= sHeaderStatementArray
[i
];
344 sHeaderSourcecode
+= m_xLanguageSourceCodeGenerator
.getFinalHeaderStatements();
345 return sHeaderSourcecode
+"\n" + m_xLanguageSourceCodeGenerator
.getCommentSign() + "...\n";
349 private class HeaderStatements
extends ArrayList
<String
> {
351 public boolean contains(String _oElement
){
352 String sCompName
= _oElement
;
353 for (int i
= 0; i
< this.size(); i
++){
354 String sElement
= this.get(i
);
355 if (sElement
.equals(sCompName
)){
364 public boolean add(String _oElement
){
365 if (!contains(_oElement
)){
366 super.add(_oElement
);
374 private boolean isVariableDeclared(UnoObjectDefinition _oUnoObjectDefinition
, String _sDefaultStemName
){
375 boolean bisDeclared
= false;
376 if (!_sDefaultStemName
.equals("")){
377 _oUnoObjectDefinition
.setCentralVariableStemName(_sDefaultStemName
);
379 String sVariableStemName
= _oUnoObjectDefinition
.getVariableStemName();
380 bisDeclared
= aVariables
.containsKey(sVariableStemName
);
382 Object oUnoObject
= _oUnoObjectDefinition
.getUnoObject();
383 if (Introspector
.isObjectPrimitive(oUnoObject
)){
386 else if (Introspector
.isObjectSequence(oUnoObject
)){
390 String sCompVariableName
= sVariableStemName
;
391 String sUnoObjectIdentity
= oUnoObject
.toString();
392 boolean bleaveloop
= false;
395 if (aVariables
.containsKey(sCompVariableName
)){
396 Object oUnoCompObject
= aVariables
.get(sCompVariableName
).getUnoObject();
397 String sUnoCompObjectIdentity
= oUnoCompObject
.toString();
398 bleaveloop
= sUnoCompObjectIdentity
.equals(sUnoObjectIdentity
);
399 bisDeclared
= bleaveloop
;
401 sCompVariableName
= sVariableStemName
+ SSUFFIXSEPARATOR
+ a
++;
415 private String
addUniqueVariableName(String _sStemVariableName
, UnoObjectDefinition _oUnoObjectDefinition
){
416 boolean bElementexists
= true;
418 String sCompName
= _sStemVariableName
;
419 while (bElementexists
){
420 if (! aVariables
.containsKey(sCompName
)){
421 aVariables
.put(sCompName
, _oUnoObjectDefinition
);
424 sCompName
= _sStemVariableName
+ SSUFFIXSEPARATOR
+ a
++;
431 private String
getTypeString(String _sTypeName
, TypeClass _aTypeClass
, boolean _bAsHeaderSourceCode
){
432 String sTypeString
= "";
433 switch (_aTypeClass
.getValue()){
434 case TypeClass
.BOOLEAN_value
:
435 sTypeString
= m_xLanguageSourceCodeGenerator
.getbooleanTypeDescription();
437 case TypeClass
.BYTE_value
:
438 sTypeString
= m_xLanguageSourceCodeGenerator
.getbyteTypeDescription();
440 case TypeClass
.CHAR_value
:
441 sTypeString
= m_xLanguageSourceCodeGenerator
.getcharTypeDescription();
443 case TypeClass
.DOUBLE_value
:
444 sTypeString
= m_xLanguageSourceCodeGenerator
.getdoubleTypeDescription();
446 case TypeClass
.FLOAT_value
:
447 sTypeString
= m_xLanguageSourceCodeGenerator
.getfloatTypeDescription();
449 case TypeClass
.HYPER_value
:
450 sTypeString
= m_xLanguageSourceCodeGenerator
.gethyperTypeDescription();
452 case TypeClass
.LONG_value
:
453 sTypeString
= m_xLanguageSourceCodeGenerator
.getlongTypeDescription();
455 case TypeClass
.SHORT_value
:
456 sTypeString
= m_xLanguageSourceCodeGenerator
.getshortTypeDescription();
458 case TypeClass
.STRING_value
:
459 sTypeString
= m_xLanguageSourceCodeGenerator
.getstringTypeDescription(_bAsHeaderSourceCode
);
461 case TypeClass
.UNSIGNED_HYPER_value
:
462 sTypeString
= m_xLanguageSourceCodeGenerator
.getunsignedhyperTypeDescription();
464 case TypeClass
.UNSIGNED_LONG_value
:
465 sTypeString
= m_xLanguageSourceCodeGenerator
.getunsignedlongTypeDescription();
467 case TypeClass
.UNSIGNED_SHORT_value
:
468 sTypeString
= m_xLanguageSourceCodeGenerator
.getdoubleTypeDescription();
470 case TypeClass
.SEQUENCE_value
:
471 //TODO consider mulitdimensional Arrays
472 XTypeDescription xTypeDescription
= Introspector
.getIntrospector().getReferencedType(_sTypeName
);
473 if (xTypeDescription
!= null){
474 sTypeString
= getTypeString(xTypeDescription
.getName(), xTypeDescription
.getTypeClass(), _bAsHeaderSourceCode
);
477 case TypeClass
.ANY_value
:
478 sTypeString
= m_xLanguageSourceCodeGenerator
.getanyTypeDescription(_bAsHeaderSourceCode
);
480 case TypeClass
.TYPE_value
:
481 sTypeString
= m_xLanguageSourceCodeGenerator
.getObjectTypeDescription("com.sun.star.uno.Type", _bAsHeaderSourceCode
);
483 case TypeClass
.ENUM_value
:
484 case TypeClass
.STRUCT_value
:
485 case TypeClass
.INTERFACE_ATTRIBUTE_value
:
486 case TypeClass
.INTERFACE_METHOD_value
:
487 case TypeClass
.INTERFACE_value
:
488 case TypeClass
.PROPERTY_value
:
489 sTypeString
= m_xLanguageSourceCodeGenerator
.getObjectTypeDescription(_sTypeName
, _bAsHeaderSourceCode
);
497 private String
getVariableDeclaration(UnoObjectDefinition _oUnoObjectDefinition
, boolean _bInitialize
, String _sVariableDefaultName
){
498 TypeClass aTypeClass
= _oUnoObjectDefinition
.getTypeClass();
499 TypeClass aLocTypeClass
= aTypeClass
;
500 boolean bIsArray
= false;
501 if (_oUnoObjectDefinition
.getUnoObject() != null){
502 bIsArray
= Introspector
.isObjectSequence(_oUnoObjectDefinition
.getUnoObject());
505 bIsArray
= _oUnoObjectDefinition
.getTypeClass().getValue() == TypeClass
.SEQUENCE_value
;
507 String sVariableName
= _oUnoObjectDefinition
.getVariableName(_sVariableDefaultName
);
508 String sTypeName
= _oUnoObjectDefinition
.getTypeName();
509 String sTypeString
= getTypeString(sTypeName
, aLocTypeClass
, false);
511 XTypeDescription xTypeDescription
= Introspector
.getIntrospector().getReferencedType(sTypeName
);
512 if (xTypeDescription
!= null){
513 aLocTypeClass
= xTypeDescription
.getTypeClass();
516 String sVariableDeclaration
= m_xLanguageSourceCodeGenerator
.getVariableDeclaration(sTypeString
, sVariableName
, bIsArray
, aLocTypeClass
, _bInitialize
);
517 addUniqueVariableName(sVariableName
, _oUnoObjectDefinition
);
518 return sVariableDeclaration
;
522 private String
getVariableInitialization(UnoObjectDefinition _oUnoObjectDefinition
, boolean _bInitialize
){
523 String sObjectVariableDeclaration
= "";
524 String sVariableName
= _oUnoObjectDefinition
.getVariableName();
525 if (isVariableDeclared(_oUnoObjectDefinition
, "")){
526 sObjectVariableDeclaration
= sVariableName
;
529 sObjectVariableDeclaration
= getVariableDeclaration(_oUnoObjectDefinition
, _bInitialize
, "");
531 return sObjectVariableDeclaration
;
536 public String
getVariableNameforUnoObject(String _sShortClassName
){
537 if (_sShortClassName
.startsWith("X")){
538 return "x" + _sShortClassName
.substring(1);
541 return _sShortClassName
;
546 private class UnoObjectDefinition
{
547 private Object m_oUnoObject
= null;
549 private String sVariableStemName
= "";
550 private String m_sCentralVariableStemName
= "";
551 private String sVariableName
= "";
552 private String m_sTypeName
= "";
553 private TypeClass m_aTypeClass
= null;
554 private Object
[] m_oParameterObjects
= null;
557 private UnoObjectDefinition(Any _oUnoObject
){
558 m_sTypeName
= _oUnoObject
.getType().getTypeName();
559 m_aTypeClass
= _oUnoObject
.getType().getTypeClass();
560 m_oUnoObject
= _oUnoObject
;
561 m_sCentralVariableStemName
= getCentralVariableStemName(m_aTypeClass
);
565 private UnoObjectDefinition(Object _oUnoObject
, String _sTypeName
, TypeClass _aTypeClass
){
566 m_oUnoObject
= _oUnoObject
;
567 m_sTypeName
= _sTypeName
;
568 m_aTypeClass
= _aTypeClass
;
569 m_sCentralVariableStemName
= getCentralVariableStemName(m_aTypeClass
);
573 private UnoObjectDefinition(Object _oUnoObject
, String _sTypeName
){
574 m_oUnoObject
= _oUnoObject
;
575 m_sTypeName
= _sTypeName
;
576 m_aTypeClass
= AnyConverter
.getType(_oUnoObject
).getTypeClass();
577 m_sCentralVariableStemName
= getCentralVariableStemName(m_aTypeClass
);
581 private String
getCentralVariableStemName(TypeClass _aTypeClass
){
582 String sCentralVariableStemName
= "";
583 int nTypeClass
= _aTypeClass
.getValue();
585 case TypeClass
.SEQUENCE_value
:
586 //TODO consider mulitdimensional Arrays
587 XTypeDescription xTypeDescription
= Introspector
.getIntrospector().getReferencedType(getTypeName());
588 if (xTypeDescription
!= null){
589 sCentralVariableStemName
= getCentralVariableStemName(xTypeDescription
.getTypeClass());
592 case TypeClass
.TYPE_value
:
593 sCentralVariableStemName
= SVARIABLENAME
;
595 case TypeClass
.STRUCT_value
:
596 sCentralVariableStemName
= Introspector
.getShortClassName(getTypeName());
598 case TypeClass
.INTERFACE_ATTRIBUTE_value
:
599 case TypeClass
.INTERFACE_METHOD_value
:
600 case TypeClass
.INTERFACE_value
:
601 case TypeClass
.PROPERTY_value
:
602 String sShortClassName
= Introspector
.getShortClassName(getTypeName());
603 sCentralVariableStemName
= getVariableNameforUnoObject(sShortClassName
);
605 sCentralVariableStemName
= SVARIABLENAME
;
607 return sCentralVariableStemName
;
612 public Object
getUnoObject(){
617 public TypeClass
getTypeClass(){
622 public String
getTypeName(){
627 public void setCentralVariableStemName(String _sCentralVariableStemName
){
628 m_sCentralVariableStemName
= _sCentralVariableStemName
;
632 public String
getVariableStemName(){
633 if (sVariableStemName
.equals("")){
634 sVariableStemName
= getVariableStemName(m_aTypeClass
);
636 return sVariableStemName
;
640 private void addParameterObjects(Object
[] _oParameterObjects
){
641 m_oParameterObjects
= _oParameterObjects
;
645 public Object
[] getParameterObjects(){
646 return m_oParameterObjects
;
653 private String
getVariableStemName(TypeClass _aTypeClass
){
654 int nTypeClass
= _aTypeClass
.getValue();
656 case TypeClass
.BOOLEAN_value
:
657 sVariableStemName
= "b" + m_sCentralVariableStemName
;
659 case TypeClass
.DOUBLE_value
:
660 case TypeClass
.FLOAT_value
:
661 sVariableStemName
= "f" + m_sCentralVariableStemName
;
663 case TypeClass
.BYTE_value
:
664 case TypeClass
.HYPER_value
:
665 case TypeClass
.LONG_value
:
666 case TypeClass
.UNSIGNED_HYPER_value
:
667 case TypeClass
.UNSIGNED_LONG_value
:
668 case TypeClass
.UNSIGNED_SHORT_value
:
669 case TypeClass
.SHORT_value
:
670 sVariableStemName
= "n" + m_sCentralVariableStemName
;
672 case TypeClass
.CHAR_value
:
673 case TypeClass
.STRING_value
:
674 sVariableStemName
= "s" + m_sCentralVariableStemName
;
676 case TypeClass
.SEQUENCE_value
:
677 //TODO consider mulitdimensional Arrays
678 XTypeDescription xTypeDescription
= Introspector
.getIntrospector().getReferencedType(getTypeName());
679 if (xTypeDescription
!= null){
680 sVariableStemName
= getVariableStemName(xTypeDescription
.getTypeClass());
683 case TypeClass
.TYPE_value
:
684 sVariableStemName
= "a" + m_sCentralVariableStemName
;
686 case TypeClass
.ANY_value
:
687 sVariableStemName
= "o" + m_sCentralVariableStemName
;
689 case TypeClass
.STRUCT_value
:
690 case TypeClass
.ENUM_value
:
691 sVariableStemName
= "a" + m_sCentralVariableStemName
;
693 case TypeClass
.INTERFACE_ATTRIBUTE_value
:
694 case TypeClass
.INTERFACE_METHOD_value
:
695 case TypeClass
.INTERFACE_value
:
696 case TypeClass
.PROPERTY_value
:
697 String sShortClassName
= Introspector
.getShortClassName(getTypeName());
698 sVariableStemName
= getVariableNameforUnoObject(sShortClassName
);
701 return sVariableStemName
;
705 private void setVariableName(String _sVariableName
){
706 sVariableName
= _sVariableName
;
710 private String
getVariableName(String _sCentralVariableStemName
){
711 if (!_sCentralVariableStemName
.equals("")){
712 this.m_sCentralVariableStemName
= _sCentralVariableStemName
;
714 return getVariableName();
718 private String
getVariableName() throws NullPointerException
{
719 if (sVariableName
.equals("")){
721 sVariableName
= getVariableStemName();
722 boolean bleaveloop
= false;
724 if (aVariables
.containsKey(sVariableName
)){
725 String sUnoObjectIdentity
= aVariables
.get(sVariableName
).getUnoObject().toString();
726 if (m_oUnoObject
!= null){
727 if ((sUnoObjectIdentity
.equals(m_oUnoObject
.toString()) && (!Introspector
.isPrimitive(this.getTypeClass())) &&
728 (! Introspector
.isObjectSequence(m_oUnoObject
)))){
732 sVariableName
= getVariableStemName() + SSUFFIXSEPARATOR
+ a
++;
744 return sVariableName
;
749 public String
getStringValueOfObject(Object _oUnoObject
, TypeClass _aTypeClass
){
751 switch (_aTypeClass
.getValue()){
752 case TypeClass
.BOOLEAN_value
:
753 boolean bbooleanValue
= ((Boolean
) _oUnoObject
).booleanValue();
754 sReturn
+= Boolean
.toString(bbooleanValue
);
755 case TypeClass
.CHAR_value
:
757 case TypeClass
.DOUBLE_value
:
758 double fdoubleValue
= ((Double
) _oUnoObject
).doubleValue();
759 sReturn
+= Double
.toString(fdoubleValue
);
761 case TypeClass
.ENUM_value
:
763 case TypeClass
.FLOAT_value
:
764 float floatValue
= ((Float
) _oUnoObject
).floatValue();
765 sReturn
+= Float
.toString(floatValue
);
767 case TypeClass
.HYPER_value
:
768 long nlongValue
= ((Long
) _oUnoObject
).longValue();
769 sReturn
+= Long
.toString(nlongValue
);
771 case TypeClass
.LONG_value
:
772 int nintValue
= ((Integer
) _oUnoObject
).intValue();
773 sReturn
+= Integer
.toString(nintValue
);
775 case TypeClass
.SHORT_value
:
776 short nshortValue
= ((Short
) _oUnoObject
).shortValue();
777 sReturn
+= Short
.toString(nshortValue
);
779 case TypeClass
.STRING_value
:
780 sReturn
+= (String
) _oUnoObject
;
782 case TypeClass
.UNSIGNED_HYPER_value
:
783 nlongValue
= ((Long
) _oUnoObject
).longValue();
784 sReturn
+= Long
.toString(nlongValue
);
786 case TypeClass
.UNSIGNED_LONG_value
:
787 nintValue
= ((Integer
) _oUnoObject
).intValue();
788 sReturn
+= Integer
.toString(nintValue
);
790 case TypeClass
.UNSIGNED_SHORT_value
:
791 nshortValue
= ((Short
) _oUnoObject
).shortValue();
792 sReturn
+= Short
.toString(nshortValue
);
795 System
.out
.println("Type " + _aTypeClass
.getValue() + " not yet defined in 'getStringValueOfObject()'");
801 public String
getMethodParameterValueDescription(XUnoMethodNode _oUnoMethodNode
, Object
[] _oParamObjects
, boolean _bIncludeParameterNames
){
802 String sParamSourceCode
= "";
803 ParamInfo
[] aParamInfos
= _oUnoMethodNode
.getXIdlMethod().getParameterInfos();
804 if (_oParamObjects
!= null){
805 for (int i
= 0; i
< _oParamObjects
.length
; i
++){
806 TypeClass aTypeClass
= aParamInfos
[i
].aType
.getTypeClass();
807 if (_bIncludeParameterNames
){
808 sParamSourceCode
+= aParamInfos
[i
].aName
+ "=";
810 String sParamDescription
= getStringValueOfObject(_oParamObjects
[i
], aTypeClass
);
811 sParamDescription
= this.m_xLanguageSourceCodeGenerator
.castLiteral(sParamDescription
, aTypeClass
);
812 sParamSourceCode
+= sParamDescription
;
814 if (i
< _oParamObjects
.length
- 1){
815 sParamSourceCode
+= ", ";
819 return sParamSourceCode
;
823 private class JavaCodeGenerator
implements XLanguageSourceCodeGenerator
{
825 private boolean bAddAnyConverter
= false;
826 private boolean bIsPropertyUnoObjectDefined
= false;
828 public JavaCodeGenerator(){
832 public String
getStatementTerminationCharacter(){
837 public String
getHeaderSourceCode(Object _oUnoObject
, String _sClassName
, TypeClass _aTypeClass
){
838 String sClassName
= _sClassName
;
839 String sHeaderStatement
= "";
840 if (_oUnoObject
!= null){
841 if (!Introspector
.isObjectPrimitive(_oUnoObject
)){
842 if (Introspector
.isObjectSequence(_oUnoObject
)){
843 XTypeDescription xTypeDescription
= m_oIntrospector
.getReferencedType(sClassName
);
844 if (xTypeDescription
!= null){
845 if (!Introspector
.isPrimitive(xTypeDescription
.getTypeClass())){
846 sClassName
= getTypeString(xTypeDescription
.getName(), xTypeDescription
.getTypeClass(), true);
848 // primitive Types are not supposed to turn up in the import section...
855 sClassName
= getTypeString(_sClassName
, _aTypeClass
, true);
858 else if (_aTypeClass
.getValue() == TypeClass
.ENUM_value
){
859 sClassName
= _sClassName
;
864 if (!sClassName
.equals("")){
865 sHeaderStatement
= "import " + sClassName
+ ";\n";
868 return sHeaderStatement
;
872 public String
getFinalHeaderStatements(){
877 public void assignqueryInterfaceHeaderSourceCode(){
878 sHeaderStatements
.add("import com.sun.star.uno.UnoRuntime;\n");
879 sHeaderStatements
.add("import com.sun.star.uno.XInterface;\n");
880 if (bAddAnyConverter
){
881 sHeaderStatements
.add("import com.sun.star.uno.AnyConverter;\n");
887 public String
getConvertedSourceCodeValueOfObject(String _sReturnVariableName
, String _sObjectDescription
, TypeClass _aTypeClass
, String _sTypeName
){
888 boolean bLocAddAnyConverter
= true;
890 switch (_aTypeClass
.getValue()){
891 case TypeClass
.BOOLEAN_value
:
892 sReturn
= _sReturnVariableName
+ " = AnyConverter.toBoolean(" + _sObjectDescription
+ ")";
894 case TypeClass
.CHAR_value
:
895 sReturn
= _sReturnVariableName
+ " = AnyConverter.toChar(" + _sObjectDescription
+ ")";
897 case TypeClass
.BYTE_value
:
898 sReturn
= _sReturnVariableName
+ " = AnyConverter.toByte(" + _sObjectDescription
+ ")";
900 case TypeClass
.DOUBLE_value
:
901 sReturn
= _sReturnVariableName
+ " = AnyConverter.toDouble(" + _sObjectDescription
+ ")";
903 case TypeClass
.FLOAT_value
:
904 sReturn
= _sReturnVariableName
+ " = AnyConverter.toFloat(" + _sObjectDescription
+ ")";
906 case TypeClass
.UNSIGNED_HYPER_value
:
907 sReturn
= _sReturnVariableName
+ " = AnyConverter.toUnsignedLong(" + _sObjectDescription
+ ")";
909 case TypeClass
.HYPER_value
:
910 sReturn
= _sReturnVariableName
+ " = AnyConverter.toLong(" + _sObjectDescription
+ ")";
912 case TypeClass
.UNSIGNED_LONG_value
:
913 sReturn
= _sReturnVariableName
+ " = AnyConverter.toUnsignedInt(" + _sObjectDescription
+ ")";
915 case TypeClass
.LONG_value
:
916 sReturn
= _sReturnVariableName
+ " = AnyConverter.toInt(" + _sObjectDescription
+ ")";
918 case TypeClass
.SHORT_value
:
919 sReturn
= _sReturnVariableName
+ " = AnyConverter.toShort(" + _sObjectDescription
+ ")";
921 case TypeClass
.UNSIGNED_SHORT_value
:
922 sReturn
= _sReturnVariableName
+ " = AnyConverter.toUnsignedShort(" + _sObjectDescription
+ ")";
924 case TypeClass
.STRING_value
:
925 sReturn
= _sReturnVariableName
+ " = AnyConverter.toString(" + _sObjectDescription
+ ")";
928 String sShortTypeName
= Introspector
.getShortClassName(_sTypeName
);
929 if (bIsPropertyUnoObjectDefined
){
930 sReturn
= "oUnoObject = " + _sObjectDescription
+ ";\n\t";
933 sReturn
= "Object oUnoObject = " + _sObjectDescription
+ ";\n\t";
934 bIsPropertyUnoObjectDefined
= true;
936 sReturn
+= _sReturnVariableName
+ " = (" + sShortTypeName
+ ") AnyConverter.toObject(" + sShortTypeName
+ ".class, oUnoObject);";
939 if (!bAddAnyConverter
){
940 bAddAnyConverter
= bLocAddAnyConverter
;
946 public String
getStructSourceCode(String _sReturnVariableDescription
, String _sObjectDescription
, String _sMember
){
947 return "\t" + _sReturnVariableDescription
+ " = " + _sObjectDescription
+ "." + _sMember
+ ";";
950 public String
getMainMethodSignatureSourceCode(XUnoNode _oUnoNode
, String _soReturnObjectDescription
){
951 //TODO try to use + _oUnoNode.getClassName() instead of the hack
952 String sReturn
= "public void codesnippet(XInterface " + _soReturnObjectDescription
+ "){";
953 if (baddExceptionHandling
){
959 public String
getMethodSeparator(){
963 public boolean needsqueryInterface(){
967 public String
getqueryInterfaceSourceCode(String _sClassName
, String _sReturnVariableName
, String _sIncomingObjectName
){
968 String sShortClassName
= Introspector
.getShortClassName(_sClassName
);
969 return "\t" + _sReturnVariableName
+ " = (" + sShortClassName
+ ") UnoRuntime.queryInterface(" + sShortClassName
+ ".class, " + _sIncomingObjectName
+ ");\n";
973 public String
getPropertyValueGetterSourceCode(String _sPropertyName
, String _sReturnVariableName
, String _sIncomingObjectName
, TypeClass _aTypeClass
, String _sTypeName
){
974 String sObjectDescription
= _sIncomingObjectName
+ ".getPropertyValue(\"" + _sPropertyName
+ "\")";
975 String sReturn
= getConvertedSourceCodeValueOfObject(_sReturnVariableName
, sObjectDescription
, _aTypeClass
, _sTypeName
);
977 sReturn
= "\t" + sReturn
;
982 public String
getObjectTypeDescription(String _sClassName
, boolean _bAsHeader
){
985 sReturn
= _sClassName
;
988 sReturn
= Introspector
.getShortClassName(_sClassName
);
994 public String
getMethodTerminationSourceCode(){
997 String sExceptionName
= "e";
998 if (baddExceptionHandling
){
999 for (int i
= 0; i
< sExceptions
.size(); i
++){
1000 String sCurException
= sExceptions
.get(i
);
1001 if (sReturn
.indexOf(sCurException
) == -1){
1003 sExceptionName
= "e"+ nIndex
;
1008 sReturn
+= "catch (" + sCurException
+ " " + sExceptionName
+ "){\n";
1009 sReturn
+= "\t" + sExceptionName
+ ".printStackTrace(System.err);\n";
1010 sReturn
+= "\t" + getCommentSign() + "Enter your Code here...\n}";
1019 public String
castLiteral(String _sExpression
, TypeClass _aTypeClass
){
1020 String sReturn
= "";
1021 switch (_aTypeClass
.getValue()){
1022 case TypeClass
.BOOLEAN_value
:
1023 sReturn
= _sExpression
;
1025 case TypeClass
.BYTE_value
:
1026 sReturn
= "(byte) " + _sExpression
;
1028 case TypeClass
.CHAR_value
:
1029 sReturn
= "'" + _sExpression
+ "'";
1031 case TypeClass
.DOUBLE_value
:
1032 sReturn
= "(double) " + _sExpression
;
1034 case TypeClass
.FLOAT_value
:
1035 sReturn
= "(float) " + _sExpression
;
1037 case TypeClass
.UNSIGNED_SHORT_value
:
1038 case TypeClass
.SHORT_value
:
1039 sReturn
= "(short) " + _sExpression
;
1041 case TypeClass
.STRING_value
:
1042 sReturn
= "\"" + _sExpression
+ "\"";
1044 case TypeClass
.HYPER_value
:
1045 case TypeClass
.UNSIGNED_HYPER_value
:
1046 sReturn
= "(long) " + _sExpression
;
1048 case TypeClass
.LONG_value
:
1049 sReturn
= _sExpression
;
1051 case TypeClass
.ENUM_value
:
1053 sReturn
= _sExpression
;
1054 System
.out
.println("Type " + _aTypeClass
.getValue() + " not yet defined in 'castliteral()'");
1060 public String
getbooleanTypeDescription(){
1064 public String
getbyteTypeDescription(){
1068 public String
getshortTypeDescription(){
1072 public String
getlongTypeDescription(){
1076 public String
getunsignedlongTypeDescription(){
1080 public String
gethyperTypeDescription(){
1084 public String
getunsignedhyperTypeDescription(){
1088 public String
getfloatTypeDescription(){
1092 public String
getdoubleTypeDescription(){
1096 public String
getcharTypeDescription(){
1100 public String
getstringTypeDescription(boolean _bAsHeaderSourceCode
){
1101 if (_bAsHeaderSourceCode
){
1109 public String
getanyTypeDescription(boolean _bAsHeaderSourceCode
){
1110 if (_bAsHeaderSourceCode
){
1119 public String
getStringValue(String _sValue
){
1124 public String
getVariableDeclaration(String _sTypeString
, String _sVariableName
, boolean _bIsArray
, TypeClass _aTypeClass
, boolean _bInitialize
){
1125 String sReturn
= "";
1127 sReturn
= _sTypeString
+ "[] " + _sVariableName
;
1130 sReturn
= _sTypeString
+ " " + _sVariableName
;
1136 public String
getCommentSign(){
1142 private class BasicCodeGenerator
implements XLanguageSourceCodeGenerator
{
1145 public BasicCodeGenerator(){
1148 public String
getHeaderSourceCode(Object _oUnoObject
, String _sClassName
, TypeClass _aTypeClass
){
1149 String sHeaderStatement
= "";
1150 return sHeaderStatement
;
1153 public String
getFinalHeaderStatements(){
1157 public String
getMainMethodSignatureSourceCode(XUnoNode _oUnoNode
, String _soReturnObjectDescription
){
1158 //TODO try to use + _oUnoNode.getClassName() instead of the hack
1159 return "Sub Main(" + _soReturnObjectDescription
+ " as " + getanyTypeDescription(false) + ")";
1162 public boolean needsqueryInterface(){
1166 public void assignqueryInterfaceHeaderSourceCode(){
1169 public String
getMethodSeparator(){
1174 public String
getqueryInterfaceSourceCode(String _sClassName
, String _sReturnVariableName
, String _sIncomingObjectName
){
1175 return _sIncomingObjectName
;
1179 public String
getPropertyValueGetterSourceCode(String _sPropertyName
, String _sReturnVariableName
, String _sIncomingObjectName
, TypeClass _aTypeClass
, String _sTypeName
){
1180 return "\t" + _sReturnVariableName
+ " = " + _sIncomingObjectName
+ "." + _sPropertyName
;
1184 public String
getStructSourceCode(String _sReturnVariableDescription
, String _sObjectDescription
, String _sMember
){
1185 return getPropertyValueGetterSourceCode(_sMember
, _sReturnVariableDescription
, _sObjectDescription
, null, "" );
1188 public String
getConvertedSourceCodeValueOfObject(String _sReturnVariableName
, String _sObjectDescription
, TypeClass _aTypeClass
, String _sTypeName
){
1189 return _sReturnVariableName
+ " = " + _sObjectDescription
;
1193 public String
getObjectTypeDescription(String _sClassName
, boolean _bAsHeader
){
1198 public String
getMethodTerminationSourceCode(){
1199 return "\nEnd Sub\n";
1203 public String
castLiteral(String _sExpression
, TypeClass _aTypeClass
){
1204 String sReturn
= "";
1205 switch (_aTypeClass
.getValue()){
1206 case TypeClass
.BOOLEAN_value
:
1207 case TypeClass
.BYTE_value
:
1208 case TypeClass
.DOUBLE_value
:
1209 case TypeClass
.FLOAT_value
:
1210 case TypeClass
.UNSIGNED_SHORT_value
:
1211 case TypeClass
.SHORT_value
:
1212 case TypeClass
.LONG_value
:
1213 case TypeClass
.UNSIGNED_LONG_value
:
1214 case TypeClass
.HYPER_value
:
1215 case TypeClass
.UNSIGNED_HYPER_value
:
1216 sReturn
= _sExpression
;
1218 case TypeClass
.CHAR_value
:
1219 case TypeClass
.STRING_value
:
1220 sReturn
= "\"" +_sExpression
+ "\"";
1222 case TypeClass
.ENUM_value
:
1224 sReturn
= _sExpression
;
1225 System
.out
.println("Type " + _aTypeClass
.getValue() + " not yet defined in 'castliteral()'");
1232 public String
getbooleanTypeDescription(){
1236 public String
getbyteTypeDescription(){
1240 public String
getshortTypeDescription(){
1244 public String
getlongTypeDescription(){
1248 public String
getunsignedlongTypeDescription(){
1252 public String
gethyperTypeDescription(){
1256 public String
getunsignedhyperTypeDescription(){
1260 public String
getfloatTypeDescription(){
1264 public String
getdoubleTypeDescription(){
1268 public String
getcharTypeDescription(){
1272 public String
getstringTypeDescription(boolean _bAsHeaderSourceCode
){
1273 if (_bAsHeaderSourceCode
){
1281 public String
getanyTypeDescription(boolean _bAsHeaderSourceCode
){
1282 if (_bAsHeaderSourceCode
){
1290 public String
getStatementTerminationCharacter(){
1295 public String
getVariableDeclaration(String _sTypeString
, String _sVariableName
, boolean bIsArray
, TypeClass _aTypeClass
, boolean _bInitialize
){
1296 String sReturn
= "";
1298 sReturn
= "Dim " + _sVariableName
+ "() as " + _sTypeString
+ "\n\t" + _sVariableName
;
1301 sReturn
= "Dim " + _sVariableName
+ " as " + _sTypeString
+ "\n\t" + _sVariableName
;
1307 public String
getStringValue(String _sValue
){
1312 public String
getCommentSign(){
1318 private class CPlusPlusCodeGenerator
implements XLanguageSourceCodeGenerator
{
1320 private boolean bIncludeStringHeader
= false;
1321 private boolean bIncludeAny
= false;
1322 private boolean bIncludeSequenceHeader
= false;
1324 public CPlusPlusCodeGenerator(){
1327 private String
getCSSNameSpaceString(){
1331 public String
getStatementTerminationCharacter(){
1336 public String
getHeaderSourceCode(Object _oUnoObject
, String _sClassName
, TypeClass _aTypeClass
){
1337 String sClassName
= _sClassName
;
1338 String sHeaderStatement
= "";
1339 if (_oUnoObject
!= null){
1340 if (!Introspector
.isObjectPrimitive(_oUnoObject
)){
1341 if (Introspector
.isObjectSequence(_oUnoObject
)){
1342 XTypeDescription xTypeDescription
= m_oIntrospector
.getReferencedType(sClassName
);
1343 if (xTypeDescription
!= null){
1344 if (!Introspector
.isPrimitive(xTypeDescription
.getTypeClass())){
1345 sClassName
= getTypeString(xTypeDescription
.getName(), xTypeDescription
.getTypeClass(), true);
1347 // primitive Types are not supposed to turn up in the import section...
1354 sClassName
= getTypeString(_sClassName
, _aTypeClass
, true);
1356 if (!sClassName
.equals("")){
1357 sHeaderStatement
= getHeaderOfClass(sClassName
);
1361 return sHeaderStatement
;
1366 public String
getFinalHeaderStatements(){
1367 String sReturn
= "";
1368 sReturn
+= "\nnamespace " + getCSSNameSpaceString() + " = com::sun::star;\n";
1369 sReturn
+= "using ::rtl::OUString;\n";
1374 private String
getHeaderOfClass(String _sClassName
){
1375 return "#include \"" + _sClassName
.replace('.', '/') + ".hpp\"\n";
1380 public void assignqueryInterfaceHeaderSourceCode(){
1381 sHeaderStatements
.add("#include \"sal/config.h\"\n");
1382 sHeaderStatements
.add("#include \"sal/types.h\"\n");
1383 if (bIncludeStringHeader
){
1384 sHeaderStatements
.add("#include \"rtl/ustring.hxx\"\n");
1386 sHeaderStatements
.add("#include \"com/sun/star/uno/Reference.hxx\"\n");
1387 if (bIncludeSequenceHeader
){
1388 sHeaderStatements
.add("#include \"com/sun/star/uno/Sequence.hxx\"\n");
1390 sHeaderStatements
.add(getHeaderOfClass("com.sun.star.uno.XInterface"));
1392 sHeaderStatements
.add(getHeaderOfClass("com.sun.star.uno.Any"));
1397 public String
getMainMethodSignatureSourceCode(XUnoNode _oUnoNode
, String _soReturnObjectDescription
){
1398 String sReturn
= "";
1399 sReturn
= "void codesnippet(const " + getCSSNameSpaceString() + "::uno::Reference<" + getCSSNameSpaceString() + "::uno::XInterface>& " + _soReturnObjectDescription
+ " ){";
1401 if (!sExceptions
.contains("com.sun.star.uno.RuntimeException")){
1402 sExceptions
.add("com.sun.star.uno.RuntimeException");
1404 if (baddExceptionHandling
){
1405 sReturn
+= "\n//throw ";
1406 for (int i
= 0; i
< sExceptions
.size(); i
++){
1407 String sCurException
= sExceptions
.get(i
);
1408 if (sReturn
.indexOf(sCurException
) == -1){
1412 sReturn
+= getObjectTypeDescription(sCurException
, false);
1423 public boolean needsqueryInterface(){
1428 public String
getqueryInterfaceSourceCode(String _sClassName
, String _sReturnVariableName
, String _sIncomingObjectName
){
1429 return "\t" + _sReturnVariableName
+ "( " + _sIncomingObjectName
+ ", " + getCSSNameSpaceString() + "::uno::UNO_QUERY_THROW);\n";
1433 public String
getPropertyValueGetterSourceCode(String _sPropertyName
, String _sReturnVariableName
, String _sIncomingObjectName
, TypeClass _aTypeClass
, String _sTypeName
){
1434 String sFirstLine
= "\t";
1435 String sReturnVariableName
= _sReturnVariableName
;
1436 // e.g. uno::Any a = xPropSet->getPropertyValue( rtl::OUString( "DefaultContext" ) );
1437 String
[] sVarDefinition
= _sReturnVariableName
.split("=");
1438 if (sVarDefinition
.length
> 0){
1439 String sVariable
= sVarDefinition
[0];
1440 String
[] sVarDeclaration
= sVariable
.split(" ");
1441 if (sVarDeclaration
.length
> 0){
1442 sFirstLine
+= sReturnVariableName
+ ";\n";
1443 sReturnVariableName
= sVarDeclaration
[sVarDeclaration
.length
-1];
1446 String sObjectDescription
= _sIncomingObjectName
+ "->getPropertyValue(" + getStringValue(_sPropertyName
) + ")";
1447 String sSecondLine
= "\t" + getConvertedSourceCodeValueOfObject(sReturnVariableName
, sObjectDescription
, _aTypeClass
, _sTypeName
) + ";";
1448 return sFirstLine
+ sSecondLine
;
1452 public String
getStructSourceCode(String _sReturnVariableDescription
, String _sObjectDescription
, String _sMember
){
1453 return "\t" + _sReturnVariableDescription
+ " = " + _sObjectDescription
+ "->" + _sMember
+ ";";
1457 public String
getConvertedSourceCodeValueOfObject(String _sReturnVariableName
, String _sObjectDescription
, TypeClass _aTypeClass
, String _sTypeName
){
1458 return _sObjectDescription
+ " >>= " + _sReturnVariableName
;
1462 public String
getStringValue(String _sValue
){
1463 bIncludeStringHeader
= true;
1464 return "OUString(\"" + _sValue
+ "\")";
1468 public String
getObjectTypeDescription(String _sClassName
, boolean _bAsHeader
){
1469 String sReturn
= "";
1471 sReturn
= _sClassName
.replace('.', '/');
1474 String sModuleName
= Introspector
.getModuleName(_sClassName
);
1475 sModuleName
= Introspector
.getShortClassName(sModuleName
);
1476 sReturn
= getCSSNameSpaceString() + "::" + sModuleName
+ "::" + Introspector
.getShortClassName(_sClassName
);
1482 public String
getMethodTerminationSourceCode(){
1486 public String
getMethodSeparator(){
1491 public String
castLiteral(String _sExpression
, TypeClass _aTypeClass
){
1492 String sReturn
= "";
1493 switch (_aTypeClass
.getValue()){
1494 case TypeClass
.BOOLEAN_value
:
1495 case TypeClass
.BYTE_value
:
1496 case TypeClass
.DOUBLE_value
:
1497 case TypeClass
.FLOAT_value
:
1498 case TypeClass
.UNSIGNED_SHORT_value
:
1499 case TypeClass
.SHORT_value
:
1500 case TypeClass
.LONG_value
:
1501 case TypeClass
.UNSIGNED_LONG_value
:
1502 case TypeClass
.HYPER_value
:
1503 case TypeClass
.UNSIGNED_HYPER_value
:
1504 sReturn
= _sExpression
;
1506 case TypeClass
.CHAR_value
:
1507 sReturn
= "'" + _sExpression
+ "'";
1509 case TypeClass
.STRING_value
:
1510 sReturn
= getStringValue(_sExpression
);
1512 case TypeClass
.ENUM_value
:
1514 sReturn
= _sExpression
;
1515 System
.out
.println("Type " + _aTypeClass
.getValue() + " not yet defined in 'castliteral()'");
1520 public String
getbooleanTypeDescription(){
1524 public String
getbyteTypeDescription(){
1528 public String
getshortTypeDescription(){
1532 public String
getlongTypeDescription(){
1536 public String
getunsignedlongTypeDescription(){
1537 return "sal_uInt32";
1540 public String
gethyperTypeDescription(){
1544 public String
getunsignedhyperTypeDescription(){
1545 return "sal_uInt64";
1548 public String
getfloatTypeDescription(){
1552 public String
getdoubleTypeDescription(){
1556 public String
getcharTypeDescription(){
1557 return "sal_Unicode";
1560 public String
getstringTypeDescription(boolean _bAsHeaderSourceCode
){
1561 bIncludeStringHeader
= true;
1562 if (_bAsHeaderSourceCode
){
1570 public String
getanyTypeDescription(boolean _bAsHeaderSourceCode
){
1571 if (_bAsHeaderSourceCode
){
1572 return "com/sun/star/uno/XInterface";
1575 return "XInterface";
1580 public String
getVariableDeclaration(String _sTypeString
, String _sVariableName
, boolean bIsArray
, TypeClass _aTypeClass
, boolean _bInitialize
){
1581 boolean bIsPrimitive
= Introspector
.isPrimitive(_aTypeClass
);
1583 String sReturn
= "";
1585 bIncludeSequenceHeader
= true;
1586 sReturn
= getCSSNameSpaceString() + "::uno::Sequence<" + _sTypeString
+ "> " + _sVariableName
;
1590 sReturn
= _sTypeString
+ " " + _sVariableName
;
1592 switch (_aTypeClass
.getValue()){
1593 case TypeClass
.BOOLEAN_value
:
1594 sReturn
= sReturn
+ " = false";
1596 case TypeClass
.BYTE_value
:
1597 case TypeClass
.UNSIGNED_SHORT_value
:
1598 case TypeClass
.SHORT_value
:
1599 case TypeClass
.LONG_value
:
1600 case TypeClass
.UNSIGNED_LONG_value
:
1601 case TypeClass
.HYPER_value
:
1602 case TypeClass
.UNSIGNED_HYPER_value
:
1603 sReturn
= sReturn
+ " = 0";
1605 case TypeClass
.DOUBLE_value
:
1606 case TypeClass
.FLOAT_value
:
1607 sReturn
= sReturn
+ " = 0.0";
1609 case TypeClass
.CHAR_value
:
1610 sReturn
= sReturn
+ "'0'";
1612 case TypeClass
.STRING_value
:
1613 sReturn
= _sTypeString
+ " " + _sVariableName
;
1616 sReturn
= _sTypeString
+ " " + _sVariableName
;
1617 System
.out
.println("Type " + _aTypeClass
.getValue() + " not yet defined in 'getVariableDeclaration()'");
1622 sReturn
= getCSSNameSpaceString() + "::uno::Reference<" + _sTypeString
+ "> " +_sVariableName
;
1628 public String
getCommentSign(){
1635 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */