VirtualBox

source: vbox/trunk/src/VBox/Main/glue/glue-java.xsl@ 31751

Last change on this file since 31751 was 31711, checked in by vboxsync, 14 years ago

Java glue: update, MSCOM compiles again

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 119.3 KB
Line 
1<xsl:stylesheet version = '1.0'
2 xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
3 xmlns:vbox="http://www.virtualbox.org/"
4 xmlns:exsl="http://exslt.org/common"
5 extension-element-prefixes="exsl">
6
7<!--
8
9 glue-java.xsl:
10 XSLT stylesheet that generates Java glue code for XPCOM, MSCOM and JAX-WS from
11 VirtualBox.xidl.
12
13 Copyright (C) 2010 Oracle Corporation
14
15 This file is part of VirtualBox Open Source Edition (OSE), as
16 available from http://www.virtualbox.org. This file is free software;
17 you can redistribute it and/or modify it under the terms of the GNU
18 General Public License (GPL) as published by the Free Software
19 Foundation, in version 2 as it comes in the "COPYING" file of the
20 VirtualBox OSE distribution. VirtualBox OSE is distributed in the
21 hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
22-->
23
24<xsl:output
25 method="text"
26 version="1.0"
27 encoding="utf-8"
28 indent="no"/>
29
30<!-- - - - - - - - - - - - - - - - - - - - - - -
31 global XSLT variables
32 - - - - - - - - - - - - - - - - - - - - - - -->
33
34<xsl:variable name="G_xsltFilename" select="'glue-java.xsl'" />
35<xsl:variable name="G_virtualBoxPackage" select="concat('org.virtualbox',$G_vboxApiSuffix)" />
36<xsl:variable name="G_virtualBoxPackageCom" select="concat('org.virtualbox',$G_vboxApiSuffix,'.',$G_vboxGlueStyle)" />
37<xsl:variable name="G_virtualBoxWsdl" select="concat(concat('&quot;vboxwebService',$G_vboxApiSuffix), '.wsdl&quot;')" />
38<!-- collect all interfaces with "wsmap='suppress'" in a global variable for
39 quick lookup -->
40<xsl:variable name="G_setSuppressedInterfaces"
41 select="//interface[@wsmap='suppress']" />
42
43<xsl:include href="../webservice/websrv-shared.inc.xsl" />
44
45<xsl:template name="fileheader">
46 <xsl:param name="name" />
47 <xsl:text>/**
48 * Copyright (C) 2010 Oracle Corporation
49 *
50 * This file is part of VirtualBox Open Source Edition (OSE), as
51 * available from http://www.virtualbox.org. This file is free software;
52 * you can redistribute it and/or modify it under the terms of the GNU
53 * General Public License (GPL) as published by the Free Software
54 * Foundation, in version 2 as it comes in the "COPYING" file of the
55 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
56 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
57 *
58</xsl:text>
59 <xsl:value-of select="concat(' * ',$name)"/>
60<xsl:text>
61 *
62 * DO NOT EDIT! This is a generated file.
63 * Generated from: src/VBox/Main/idl/VirtualBox.xidl (VirtualBox's interface definitions in XML)
64 * Generator: src/VBox/Main/glue/glue-java.xsl
65 */
66
67</xsl:text>
68</xsl:template>
69
70<xsl:template name="startFile">
71 <xsl:param name="file" />
72 <xsl:param name="package" />
73
74 <xsl:value-of select="concat('&#10;// ##### BEGINFILE &quot;', $file, '&quot;&#10;&#10;')" />
75 <xsl:call-template name="fileheader">
76 <xsl:with-param name="name" select="$file" />
77 </xsl:call-template>
78
79 <xsl:value-of select="concat('package ',$package,';&#10;&#10;')" />
80 <xsl:value-of select="concat('import ',$G_virtualBoxPackageCom,'.*;&#10;')" />
81
82 <xsl:choose>
83 <xsl:when test="$G_vboxGlueStyle='xpcom'">
84 <xsl:value-of select="'import org.mozilla.interfaces.*;&#10;'" />
85 </xsl:when>
86
87 <xsl:when test="$G_vboxGlueStyle='mscom'">
88 <xsl:value-of select="'import com.jacob.com.*;&#10;'" />
89 <xsl:value-of select="'import com.jacob.activeX.ActiveXComponent;&#10;'" />
90 </xsl:when>
91
92 <xsl:when test="$G_vboxGlueStyle='jaxws'">
93 <xsl:value-of select=" 'import javax.xml.ws.*;&#10;'" />
94 </xsl:when>
95
96 <xsl:otherwise>
97 <xsl:call-template name="fatalError">
98 <xsl:with-param name="msg" select="'no header rule (startFile)'" />
99 </xsl:call-template>
100 </xsl:otherwise>
101 </xsl:choose>
102</xsl:template>
103
104<xsl:template name="endFile">
105 <xsl:param name="file" />
106 <xsl:value-of select="concat('&#10;// ##### ENDFILE &quot;', $file, '&quot;&#10;&#10;')" />
107</xsl:template>
108
109<xsl:template name="genEnum">
110 <xsl:param name="enumname" />
111 <xsl:param name="filename" />
112
113 <xsl:call-template name="startFile">
114 <xsl:with-param name="file" select="$filename" />
115 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
116 </xsl:call-template>
117
118 <xsl:value-of select="concat('public enum ', $enumname, ' {&#10;&#10;')" />
119 <xsl:for-each select="const">
120 <xsl:variable name="enumconst" select="@name" />
121 <xsl:value-of select="concat(' ', $enumconst, '(', @value, ')')" />
122 <xsl:choose>
123 <xsl:when test="not(position()=last())">
124 <xsl:text>,&#10;</xsl:text>
125 </xsl:when>
126 <xsl:otherwise>
127 <xsl:text>;&#10;</xsl:text>
128 </xsl:otherwise>
129 </xsl:choose>
130 </xsl:for-each>
131
132 <xsl:text>&#10;</xsl:text>
133 <xsl:text> private final int value;&#10;&#10;</xsl:text>
134
135 <xsl:value-of select="concat(' ', $enumname, '(int v) {&#10;')" />
136 <xsl:text> value = v;&#10;</xsl:text>
137 <xsl:text> }&#10;&#10;</xsl:text>
138
139 <xsl:text> public int value() {&#10;</xsl:text>
140 <xsl:text> return value;&#10;</xsl:text>
141 <xsl:text> }&#10;&#10;</xsl:text>
142
143 <xsl:value-of select="concat(' public static ', $enumname, ' fromValue(long v) {&#10;')" />
144 <xsl:value-of select="concat(' for (', $enumname, ' c: ', $enumname, '.values()) {&#10;')" />
145 <xsl:text> if (c.value == (int)v) {&#10;</xsl:text>
146 <xsl:text> return c;&#10;</xsl:text>
147 <xsl:text> }&#10;</xsl:text>
148 <xsl:text> }&#10;</xsl:text>
149 <xsl:text> throw new IllegalArgumentException(Long.toString(v));&#10;</xsl:text>
150 <xsl:text> }&#10;&#10;</xsl:text>
151
152 <xsl:value-of select="concat(' public static ', $enumname, ' fromValue(String v) {&#10;')" />
153 <xsl:value-of select="concat(' return valueOf(',$enumname, '.class, v);&#10;')" />
154 <xsl:value-of select=" ' }&#10;'" />
155
156 <xsl:text>}&#10;&#10;</xsl:text>
157
158 <xsl:call-template name="endFile">
159 <xsl:with-param name="file" select="$filename" />
160 </xsl:call-template>
161
162</xsl:template>
163
164<xsl:template name="startExcWrapper">
165
166 <xsl:value-of select=" ' try {&#10;'" />
167
168</xsl:template>
169
170<xsl:template name="endExcWrapper">
171
172 <xsl:choose>
173 <xsl:when test="$G_vboxGlueStyle='xpcom'">
174 <xsl:value-of select="' } catch (org.mozilla.xpcom.XPCOMException e) {&#10;'" />
175 <xsl:value-of select="' throw new VBoxException(e, e.getMessage());&#10;'" />
176 <xsl:value-of select="' }&#10;'" />
177 </xsl:when>
178
179 <xsl:when test="$G_vboxGlueStyle='mscom'">
180 <xsl:value-of select="' } catch (com.jacob.com.ComException e) {&#10;'" />
181 <xsl:value-of select="' throw new VBoxException(e, e.getMessage());&#10;'" />
182 <xsl:value-of select="' }&#10;'" />
183 </xsl:when>
184
185 <xsl:when test="$G_vboxGlueStyle='jaxws'">
186 <xsl:value-of select="' } catch (InvalidObjectFaultMsg e) {&#10;'" />
187 <xsl:value-of select="' throw new VBoxException(e, e.getMessage());&#10;'" />
188 <xsl:value-of select="' } catch (RuntimeFaultMsg e) {&#10;'" />
189 <xsl:value-of select="' throw new VBoxException(e, e.getMessage());&#10;'" />
190 <xsl:value-of select="' }&#10;'" />
191 </xsl:when>
192
193 <xsl:otherwise>
194 <xsl:call-template name="fatalError">
195 <xsl:with-param name="msg" select="'no header rule (startFile)'" />
196 </xsl:call-template>
197 </xsl:otherwise>
198 </xsl:choose>
199</xsl:template>
200
201<xsl:template name="wrappedName">
202 <xsl:param name="ifname" />
203
204 <xsl:choose>
205 <xsl:when test="$G_vboxGlueStyle='xpcom'">
206 <xsl:value-of select="concat('org.mozilla.interfaces.',$ifname)" />
207 </xsl:when>
208
209 <xsl:when test="$G_vboxGlueStyle='mscom'">
210 <xsl:value-of select="'com.jacob.com.Dispatch'" />
211 </xsl:when>
212
213 <xsl:when test="$G_vboxGlueStyle='jaxws'">
214 <xsl:value-of select="'String'" />
215 </xsl:when>
216
217 <xsl:otherwise>
218 <xsl:call-template name="fatalError">
219 <xsl:with-param name="msg" select="'no wrapper naming rule defined (wrappedName)'" />
220 </xsl:call-template>
221 </xsl:otherwise>
222
223 </xsl:choose>
224</xsl:template>
225
226<xsl:template name="fullClassName">
227 <xsl:param name="name" />
228 <xsl:param name="origname" />
229 <xsl:param name="collPrefix" />
230 <xsl:choose>
231 <xsl:when test="//enum[@name=$name] or //enum[@name=$origname]">
232 <xsl:value-of select="concat($G_virtualBoxPackage, concat('.', $name))" />
233 </xsl:when>
234 <xsl:when test="//interface[@name=$name]">
235 <xsl:value-of select="concat($G_virtualBoxPackage, concat('.', $name))" />
236 </xsl:when>
237 <xsl:otherwise>
238 <xsl:call-template name="fatalError">
239 <xsl:with-param name="msg" select="concat('fullClassName: Type &quot;', $name, '&quot; is not supported.')" />
240 </xsl:call-template>
241 </xsl:otherwise>
242 </xsl:choose>
243</xsl:template>
244
245<xsl:template name="typeIdl2Glue">
246 <xsl:param name="type" />
247 <xsl:param name="safearray" />
248 <xsl:param name="forceelem" />
249
250 <xsl:variable name="needarray" select="($safearray='yes') and not($forceelem='yes')" />
251 <xsl:variable name="needlist" select="($needarray) and not($type='octet')" />
252
253 <xsl:if test="($needlist)">
254 <xsl:value-of select="'List&lt;'" />
255 </xsl:if>
256
257 <!-- look up Java type from IDL type from table array in websrv-shared.inc.xsl -->
258 <xsl:variable name="javatypefield" select="exsl:node-set($G_aSharedTypes)/type[@idlname=$type]/@javaname" />
259
260 <xsl:choose>
261 <xsl:when test="string-length($javatypefield)">
262 <xsl:value-of select="$javatypefield" />
263 </xsl:when>
264 <!-- not a standard type: then it better be one of the types defined in the XIDL -->
265 <xsl:when test="$type='$unknown'">IUnknown</xsl:when>
266 <xsl:otherwise>
267 <xsl:call-template name="fullClassName">
268 <xsl:with-param name="name" select="$type" />
269 <xsl:with-param name="collPrefix" select="''"/>
270 </xsl:call-template>
271 </xsl:otherwise>
272 </xsl:choose>
273
274 <xsl:choose>
275 <xsl:when test="($needlist)">
276 <xsl:value-of select="'&gt;'" />
277 </xsl:when>
278 <xsl:when test="($needarray)">
279 <xsl:value-of select="'[]'" />
280 </xsl:when>
281 </xsl:choose>
282</xsl:template>
283
284<!--
285 typeIdl2Back: converts $type into a type as used by the backend.
286 -->
287<xsl:template name="typeIdl2Back">
288 <xsl:param name="type" />
289 <xsl:param name="safearray" />
290 <xsl:param name="forceelem" />
291
292 <xsl:variable name="needarray" select="($safearray='yes') and not($forceelem='yes')" />
293
294 <xsl:choose>
295 <xsl:when test="($G_vboxGlueStyle='xpcom')">
296 <xsl:choose>
297 <xsl:when test="$type='long long'">
298 <xsl:value-of select="'long'" />
299 </xsl:when>
300
301 <xsl:when test="$type='unsigned long'">
302 <xsl:value-of select="'long'" />
303 </xsl:when>
304
305 <xsl:when test="$type='long'">
306 <xsl:value-of select="'int'" />
307 </xsl:when>
308
309 <xsl:when test="$type='unsigned short'">
310 <xsl:value-of select="'int'" />
311 </xsl:when>
312
313 <xsl:when test="$type='short'">
314 <xsl:value-of select="'short'" />
315 </xsl:when>
316
317 <xsl:when test="$type='octet'">
318 <xsl:value-of select="'byte'" />
319 </xsl:when>
320
321 <xsl:when test="$type='boolean'">
322 <xsl:value-of select="'boolean'" />
323 </xsl:when>
324
325 <xsl:when test="$type='$unknown'">
326 <xsl:value-of select="'nsISupports'"/>
327 </xsl:when>
328
329 <xsl:when test="$type='wstring'">
330 <xsl:value-of select="'String'" />
331 </xsl:when>
332
333 <xsl:when test="$type='uuid'">
334 <xsl:value-of select="'String'" />
335 </xsl:when>
336
337 <xsl:when test="//interface[@name=$type]/@wsmap='struct'">
338 <xsl:call-template name="wrappedName">
339 <xsl:with-param name="ifname" select="$type" />
340 </xsl:call-template>
341 </xsl:when>
342
343 <xsl:when test="//interface[@name=$type]">
344 <xsl:call-template name="wrappedName">
345 <xsl:with-param name="ifname" select="$type" />
346 </xsl:call-template>
347 </xsl:when>
348
349 <xsl:when test="//enum[@name=$type]">
350 <xsl:value-of select="'long'" />
351 </xsl:when>
352
353 <xsl:otherwise>
354 <xsl:call-template name="fullClassName">
355 <xsl:with-param name="name" select="$type" />
356 </xsl:call-template>
357 </xsl:otherwise>
358
359 </xsl:choose>
360 <xsl:if test="$needarray">
361 <xsl:value-of select="'[]'" />
362 </xsl:if>
363 </xsl:when>
364
365 <xsl:when test="($G_vboxGlueStyle='mscom')">
366 <xsl:value-of select="'Variant'"/>
367 </xsl:when>
368
369 <xsl:when test="($G_vboxGlueStyle='jaxws')">
370 <xsl:if test="$needarray">
371 <xsl:value-of select="'List&lt;'" />
372 </xsl:if>
373 <xsl:choose>
374 <xsl:when test="$type='$unknown'">
375 <xsl:value-of select="'String'" />
376 </xsl:when>
377
378 <xsl:when test="//interface[@name=$type]/@wsmap='managed'">
379 <xsl:value-of select="'String'" />
380 </xsl:when>
381
382 <xsl:when test="//interface[@name=$type]/@wsmap='struct'">
383 <xsl:value-of select="concat($G_virtualBoxPackageCom, '.', $type)" />
384 </xsl:when>
385
386 <xsl:when test="//enum[@name=$type]">
387 <xsl:value-of select="concat($G_virtualBoxPackageCom, '.', $type)" />
388 </xsl:when>
389
390 <xsl:when test="$type='long long'">
391 <xsl:value-of select="'Long'" />
392 </xsl:when>
393
394 <xsl:when test="$type='unsigned long'">
395 <xsl:value-of select="'Long'" />
396 </xsl:when>
397
398 <xsl:when test="$type='long'">
399 <xsl:value-of select="'Integer'" />
400 </xsl:when>
401
402 <xsl:when test="$type='unsigned short'">
403 <xsl:value-of select="'Integer'" />
404 </xsl:when>
405
406 <xsl:when test="$type='short'">
407 <xsl:value-of select="'Short'" />
408 </xsl:when>
409
410 <xsl:when test="$type='octet'">
411 <xsl:value-of select="'Short'" />
412 </xsl:when>
413
414 <xsl:when test="$type='boolean'">
415 <xsl:value-of select="'Boolean'" />
416 </xsl:when>
417
418 <xsl:when test="$type='wstring'">
419 <xsl:value-of select="'String'" />
420 </xsl:when>
421
422 <xsl:when test="$type='uuid'">
423 <xsl:value-of select="'String'" />
424 </xsl:when>
425
426 <xsl:otherwise>
427 <xsl:call-template name="fatalError">
428 <xsl:with-param name="msg" select="concat('Unhandled type ', $type,' (typeIdl2Back)')" />
429 </xsl:call-template>
430 </xsl:otherwise>
431
432 </xsl:choose>
433
434 <xsl:if test="$needarray">
435 <xsl:value-of select="'&gt;'" />
436 </xsl:if>
437 </xsl:when>
438
439 <xsl:otherwise>
440 <xsl:call-template name="fatalError">
441 <xsl:with-param name="msg" select="'Write typeIdl2Back for this style (typeIdl2Back)'" />
442 </xsl:call-template>
443 </xsl:otherwise>
444
445 </xsl:choose>
446</xsl:template>
447
448<xsl:template name="cookOutParamXpcom">
449 <xsl:param name="value"/>
450 <xsl:param name="idltype"/>
451 <xsl:param name="safearray"/>
452 <xsl:variable name="isstruct"
453 select="//interface[@name=$idltype]/@wsmap='struct'" />
454
455 <xsl:variable name="gluetype">
456 <xsl:call-template name="typeIdl2Glue">
457 <xsl:with-param name="type" select="$idltype" />
458 <xsl:with-param name="safearray" select="$safearray" />
459 </xsl:call-template>
460 </xsl:variable>
461
462 <xsl:variable name="elemgluetype">
463 <xsl:if test="$safearray='yes'">
464 <xsl:call-template name="typeIdl2Glue">
465 <xsl:with-param name="type" select="$idltype" />
466 <xsl:with-param name="safearray" select="'no'" />
467 <xsl:with-param name="forceelem" select="'yes'" />
468 </xsl:call-template>
469 </xsl:if>
470 </xsl:variable>
471
472 <xsl:choose>
473 <xsl:when test="//interface[@name=$idltype] or $idltype='$unknown'">
474 <xsl:choose>
475 <xsl:when test="$safearray='yes'">
476 <xsl:variable name="elembacktype">
477 <xsl:call-template name="typeIdl2Back">
478 <xsl:with-param name="type" select="$idltype" />
479 <xsl:with-param name="safearray" select="$safearray" />
480 <xsl:with-param name="forceelem" select="'yes'" />
481 </xsl:call-template>
482 </xsl:variable>
483 <xsl:value-of select="concat('Helper.wrap2(',$elemgluetype, '.class, ', $elembacktype, '.class, ', $value,')')"/>
484 </xsl:when>
485 <xsl:otherwise>
486 <xsl:value-of select="concat('(', $value, ' != null) ? new ', $gluetype, '(', $value,') : null')" />
487 </xsl:otherwise>
488 </xsl:choose>
489 </xsl:when>
490
491 <xsl:when test="//enum[@name=$idltype]">
492 <xsl:choose>
493 <xsl:when test="$safearray='yes'">
494 <xsl:variable name="elembacktype">
495 <xsl:call-template name="typeIdl2Back">
496 <xsl:with-param name="type" select="$idltype" />
497 <xsl:with-param name="safearray" select="$safearray" />
498 <xsl:with-param name="forceelem" select="'yes'" />
499 </xsl:call-template>
500 </xsl:variable>
501 <xsl:value-of select="concat('Helper.wrapEnum(',$elemgluetype, '.class, ', $value,')')"/>
502 </xsl:when>
503 <xsl:otherwise>
504 <xsl:value-of select="concat($gluetype,'.fromValue(', $value,')')"/>
505 </xsl:otherwise>
506 </xsl:choose>
507 </xsl:when>
508
509 <xsl:otherwise>
510 <xsl:choose>
511 <xsl:when test="($safearray='yes') and ($idltype='octet')">
512 <xsl:value-of select="$value"/>
513 </xsl:when>
514 <xsl:when test="$safearray='yes'">
515 <xsl:value-of select="concat('Helper.wrap(', $value,')')"/>
516 </xsl:when>
517 <xsl:otherwise>
518 <xsl:value-of select="$value"/>
519 </xsl:otherwise>
520 </xsl:choose>
521 </xsl:otherwise>
522 </xsl:choose>
523</xsl:template>
524
525<xsl:template name="cookOutParamMscom">
526 <xsl:param name="value"/>
527 <xsl:param name="idltype"/>
528 <xsl:param name="safearray"/>
529
530 <xsl:variable name="gluetype">
531 <xsl:call-template name="typeIdl2Glue">
532 <xsl:with-param name="type" select="$idltype" />
533 <xsl:with-param name="safearray" select="$safearray" />
534 </xsl:call-template>
535 </xsl:variable>
536
537 <xsl:choose>
538 <xsl:when test="$safearray='yes'">
539 <xsl:variable name="elemgluetype">
540 <xsl:call-template name="typeIdl2Glue">
541 <xsl:with-param name="type" select="$idltype" />
542 <xsl:with-param name="safearray" select="'no'" />
543 <xsl:with-param name="forceelem" select="'yes'" />
544 </xsl:call-template>
545 </xsl:variable>
546 <xsl:choose>
547 <xsl:when test="($idltype='octet')">
548 <xsl:value-of select="concat('Helper.wrapBytes(', $value, '.toSafeArray())')"/>
549 </xsl:when>
550 <xsl:otherwise>
551 <xsl:value-of select="concat('Helper.wrap(', $elemgluetype, '.class, ', $value,'.toSafeArray())')"/>
552 </xsl:otherwise>
553 </xsl:choose>
554 </xsl:when>
555
556 <xsl:when test="//interface[@name=$idltype] or $idltype='$unknown'">
557 <xsl:value-of select="concat('Helper.wrapDispatch(',$gluetype, '.class, ', $value,'.getDispatch())')"/>
558 </xsl:when>
559
560 <xsl:when test="//enum[@name=$idltype]">
561 <xsl:value-of select="concat($gluetype,'.fromValue(', $value,'.getInt())')"/>
562 </xsl:when>
563
564 <xsl:when test="$idltype='wstring'">
565 <xsl:value-of select="concat($value,'.getString()')"/>
566 </xsl:when>
567
568 <xsl:when test="$idltype='uuid'">
569 <xsl:value-of select="concat($value,'.getString()')"/>
570 </xsl:when>
571
572 <xsl:when test="$idltype='boolean'">
573 <xsl:value-of select="concat($value,'.toBoolean()')"/>
574 </xsl:when>
575
576 <xsl:when test="$idltype='unsigned short'">
577 <xsl:value-of select="concat('(int)', $value,'.getShort()')"/>
578 </xsl:when>
579
580 <xsl:when test="$idltype='short'">
581 <xsl:value-of select="concat($value,'.getShort()')"/>
582 </xsl:when>
583
584 <xsl:when test="$idltype='long'">
585 <xsl:value-of select="concat($value,'.getInt()')"/>
586 </xsl:when>
587
588
589 <xsl:when test="$idltype='unsigned long'">
590 <xsl:value-of select="concat('(long)', $value,'.getInt()')"/>
591 </xsl:when>
592
593 <xsl:when test="$idltype='long'">
594 <xsl:value-of select="concat($value,'.getInt()')"/>
595 </xsl:when>
596
597 <xsl:when test="$idltype='long long'">
598 <xsl:value-of select="concat($value,'.getLong()')"/>
599 </xsl:when>
600
601 <xsl:otherwise>
602 <xsl:call-template name="fatalError">
603 <xsl:with-param name="msg" select="concat('Unhandled type' , $idltype, ' (cookOutParamMscom)')" />
604 </xsl:call-template>
605 </xsl:otherwise>
606 </xsl:choose>
607
608</xsl:template>
609
610<xsl:template name="cookOutParamJaxws">
611 <xsl:param name="value"/>
612 <xsl:param name="idltype"/>
613 <xsl:param name="safearray"/>
614
615 <xsl:variable name="isstruct"
616 select="//interface[@name=$idltype]/@wsmap='struct'" />
617
618 <xsl:variable name="gluetype">
619 <xsl:call-template name="typeIdl2Glue">
620 <xsl:with-param name="type" select="$idltype" />
621 <xsl:with-param name="safearray" select="$safearray" />
622 </xsl:call-template>
623 </xsl:variable>
624
625 <xsl:choose>
626 <xsl:when test="$safearray='yes'">
627 <xsl:variable name="elemgluetype">
628 <xsl:call-template name="typeIdl2Glue">
629 <xsl:with-param name="type" select="$idltype" />
630 <xsl:with-param name="safearray" select="''" />
631 <xsl:with-param name="forceelem" select="'yes'" />
632 </xsl:call-template>
633 </xsl:variable>
634 <xsl:variable name="elembacktype">
635 <xsl:call-template name="typeIdl2Back">
636 <xsl:with-param name="type" select="$idltype" />
637 <xsl:with-param name="safearray" select="''" />
638 <xsl:with-param name="forceelem" select="'yes'" />
639 </xsl:call-template>
640 </xsl:variable>
641 <xsl:choose>
642 <xsl:when test="$isstruct">
643 <xsl:value-of select="concat('Helper.wrap2(',$elemgluetype, '.class, ', $elembacktype, '.class, port, ', $value,')')"/>
644 </xsl:when>
645 <xsl:when test="//enum[@name=$idltype]">
646 <xsl:value-of select="concat('Helper.convertEnums(',$elembacktype, '.class, ', $elemgluetype, '.class, ', $value,')')"/>
647 </xsl:when>
648 <xsl:when test="//interface[@name=$idltype] or $idltype='$unknown'">
649 <xsl:value-of select="concat('Helper.wrap(',$elemgluetype,'.class, port, ', $value,')')"/>
650 </xsl:when>
651 <xsl:when test="$idltype='octet'">
652 <xsl:value-of select="concat('Helper.wrapBytes(',$value,')')"/>
653 </xsl:when>
654 <xsl:otherwise>
655 <xsl:value-of select="$value" />
656 </xsl:otherwise>
657 </xsl:choose>
658 </xsl:when>
659
660 <xsl:otherwise>
661 <xsl:choose>
662 <xsl:when test="//enum[@name=$idltype]">
663 <xsl:value-of select="concat($gluetype,'.fromValue(', $value,'.value())')"/>
664 </xsl:when>
665 <xsl:when test="$idltype='boolean'">
666 <xsl:value-of select="$value"/>
667 </xsl:when>
668 <xsl:when test="$idltype='long long'">
669 <xsl:value-of select="$value"/>
670 </xsl:when>
671 <xsl:when test="$idltype='unsigned long long'">
672 <xsl:value-of select="$value"/>
673 </xsl:when>
674 <xsl:when test="$idltype='long'">
675 <xsl:value-of select="$value"/>
676 </xsl:when>
677 <xsl:when test="$idltype='unsigned long'">
678 <xsl:value-of select="$value"/>
679 </xsl:when>
680 <xsl:when test="$idltype='short'">
681 <xsl:value-of select="$value"/>
682 </xsl:when>
683 <xsl:when test="$idltype='unsigned short'">
684 <xsl:value-of select="$value"/>
685 </xsl:when>
686 <xsl:when test="$idltype='wstring'">
687 <xsl:value-of select="$value"/>
688 </xsl:when>
689 <xsl:when test="$idltype='uuid'">
690 <xsl:value-of select="$value"/>
691 </xsl:when>
692 <xsl:when test="$isstruct">
693 <xsl:value-of select="concat('(', $value, ' != null) ? new ', $gluetype, '(', $value,', port) : null')" />
694 </xsl:when>
695 <xsl:when test="//interface[@name=$idltype] or $idltype='$unknown'">
696 <!-- if the MOR string is empty, that means NULL, so return NULL instead of an object then -->
697 <xsl:value-of select="concat('(', $value, '.length() > 0) ? new ', $gluetype, '(', $value,', port) : null')" />
698 </xsl:when>
699 <xsl:otherwise>
700 <xsl:call-template name="fatalError">
701 <xsl:with-param name="msg" select="concat('Unhandled type ', $idltype, ' (cookOutParamJaxws)')" />
702 </xsl:call-template>
703 </xsl:otherwise>
704 </xsl:choose>
705 </xsl:otherwise>
706 </xsl:choose>
707
708</xsl:template>
709
710<xsl:template name="cookOutParam">
711 <xsl:param name="value"/>
712 <xsl:param name="idltype"/>
713 <xsl:param name="safearray"/>
714 <xsl:choose>
715 <xsl:when test="($G_vboxGlueStyle='xpcom')">
716 <xsl:call-template name="cookOutParamXpcom">
717 <xsl:with-param name="value" select="$value" />
718 <xsl:with-param name="idltype" select="$idltype" />
719 <xsl:with-param name="safearray" select="$safearray" />
720 </xsl:call-template>
721 </xsl:when>
722 <xsl:when test="($G_vboxGlueStyle='mscom')">
723 <xsl:call-template name="cookOutParamMscom">
724 <xsl:with-param name="value" select="$value" />
725 <xsl:with-param name="idltype" select="$idltype" />
726 <xsl:with-param name="safearray" select="$safearray" />
727 </xsl:call-template>
728 </xsl:when>
729 <xsl:when test="($G_vboxGlueStyle='jaxws')">
730 <xsl:call-template name="cookOutParamJaxws">
731 <xsl:with-param name="value" select="$value" />
732 <xsl:with-param name="idltype" select="$idltype" />
733 <xsl:with-param name="safearray" select="$safearray" />
734 </xsl:call-template>
735 </xsl:when>
736 <xsl:otherwise>
737 <xsl:call-template name="fatalError">
738 <xsl:with-param name="msg" select="'Unhandled style(cookOutParam)'" />
739 </xsl:call-template>
740 </xsl:otherwise>
741 </xsl:choose>
742</xsl:template>
743
744<xsl:template name="cookInParamXpcom">
745 <xsl:param name="value"/>
746 <xsl:param name="idltype"/>
747 <xsl:param name="safearray"/>
748 <xsl:variable name="isstruct"
749 select="//interface[@name=$idltype]/@wsmap='struct'" />
750 <xsl:variable name="gluetype">
751 <xsl:call-template name="typeIdl2Glue">
752 <xsl:with-param name="type" select="$idltype" />
753 <xsl:with-param name="safearray" select="$safearray" />
754 </xsl:call-template>
755 </xsl:variable>
756
757 <xsl:variable name="backtype">
758 <xsl:call-template name="typeIdl2Back">
759 <xsl:with-param name="type" select="$idltype" />
760 <xsl:with-param name="safearray" select="$safearray" />
761 </xsl:call-template>
762 </xsl:variable>
763
764 <xsl:variable name="elemgluetype">
765 <xsl:if test="$safearray='yes'">
766 <xsl:call-template name="typeIdl2Glue">
767 <xsl:with-param name="type" select="$idltype" />
768 <xsl:with-param name="safearray" select="'no'" />
769 <xsl:with-param name="forceelem" select="'yes'" />
770 </xsl:call-template>
771 </xsl:if>
772 </xsl:variable>
773
774 <xsl:choose>
775 <xsl:when test="//interface[@name=$idltype]">
776 <xsl:choose>
777 <xsl:when test="$safearray='yes'">
778 <xsl:variable name="elembacktype">
779 <xsl:call-template name="typeIdl2Back">
780 <xsl:with-param name="type" select="$idltype" />
781 <xsl:with-param name="safearray" select="$safearray" />
782 <xsl:with-param name="forceelem" select="'yes'" />
783 </xsl:call-template>
784 </xsl:variable>
785 <xsl:value-of select="concat('Helper.unwrap2(',$elemgluetype, '.class, ', $elembacktype, '.class, ', $value,')')"/>
786 </xsl:when>
787 <xsl:otherwise>
788 <xsl:value-of select="concat('(', $value, ' != null) ? ', $value, '.getTypedWrapped() : null')" />
789 </xsl:otherwise>
790 </xsl:choose>
791 </xsl:when>
792
793 <xsl:when test="$idltype='$unknown'">
794 <xsl:choose>
795 <xsl:when test="$safearray='yes'">
796 <xsl:value-of select="concat('Helper.unwrap2(',$elemgluetype, '.class, nsISupports.class, ', $value,')')"/>
797 </xsl:when>
798 <xsl:otherwise>
799 <xsl:value-of select="concat('(', $value, ' != null) ? (nsISupports)', $value, '.getWrapped() : null')" />
800 </xsl:otherwise>
801 </xsl:choose>
802 </xsl:when>
803
804 <xsl:when test="//enum[@name=$idltype]">
805 <xsl:choose>
806 <xsl:when test="$safearray='yes'">
807 <xsl:value-of select="concat('Helper.unwrapEnum(', $elemgluetype, '.class,', $value,')')"/>
808 </xsl:when>
809 <xsl:otherwise>
810 <xsl:value-of select="concat($value,'.value()')"/>
811 </xsl:otherwise>
812 </xsl:choose>
813 </xsl:when>
814
815 <xsl:otherwise>
816 <xsl:choose>
817 <xsl:when test="$safearray='yes'">
818 <xsl:value-of select="concat('Helper.unwrap(',$value,')')"/>
819 </xsl:when>
820 <xsl:otherwise>
821 <xsl:value-of select="$value"/>
822 </xsl:otherwise>
823 </xsl:choose>
824 </xsl:otherwise>
825 </xsl:choose>
826</xsl:template>
827
828<xsl:template name="cookInParamMscom">
829 <xsl:param name="value"/>
830 <xsl:param name="idltype"/>
831 <xsl:param name="safearray"/>
832
833 <xsl:variable name="gluetype">
834 <xsl:call-template name="typeIdl2Glue">
835 <xsl:with-param name="type" select="$idltype" />
836 <xsl:with-param name="safearray" select="$safearray" />
837 </xsl:call-template>
838 </xsl:variable>
839
840 <xsl:variable name="backtype">
841 <xsl:call-template name="typeIdl2Back">
842 <xsl:with-param name="type" select="$idltype" />
843 <xsl:with-param name="safearray" select="$safearray" />
844 </xsl:call-template>
845 </xsl:variable>
846
847 <xsl:variable name="elemgluetype">
848 <xsl:if test="$safearray='yes'">
849 <xsl:call-template name="typeIdl2Glue">
850 <xsl:with-param name="type" select="$idltype" />
851 <xsl:with-param name="safearray" select="'no'" />
852 <xsl:with-param name="forceelem" select="'yes'" />
853 </xsl:call-template>
854 </xsl:if>
855 </xsl:variable>
856
857 <xsl:choose>
858 <xsl:when test="//interface[@name=$idltype]">
859 <xsl:choose>
860 <xsl:when test="$safearray='yes'">
861 <xsl:variable name="elembacktype">
862 <xsl:call-template name="typeIdl2Back">
863 <xsl:with-param name="type" select="$idltype" />
864 <xsl:with-param name="safearray" select="$safearray" />
865 <xsl:with-param name="forceelem" select="'yes'" />
866 </xsl:call-template>
867 </xsl:variable>
868 <xsl:value-of select="concat('Helper.unwrap2(',$elemgluetype, '.class, ', $elembacktype, '.class, ', $value,')')"/>
869 </xsl:when>
870 <xsl:otherwise>
871 <xsl:value-of select="concat('(', $value, ' != null) ? ', $value, '.getTypedWrapped() : null')" />
872 </xsl:otherwise>
873 </xsl:choose>
874 </xsl:when>
875
876 <xsl:when test="$idltype='$unknown'">
877 <xsl:choose>
878 <xsl:when test="$safearray='yes'">
879 <xsl:value-of select="concat('Helper.unwrap2(',$elemgluetype, '.class, Dispatch.class, ', $value,')')"/>
880 </xsl:when>
881 <xsl:otherwise>
882 <xsl:value-of select="concat('(', $value, ' != null) ? (Dispatch)', $value, '.getWrapped() : null')" />
883 </xsl:otherwise>
884 </xsl:choose>
885 </xsl:when>
886
887 <xsl:when test="//enum[@name=$idltype]">
888 <xsl:choose>
889 <xsl:when test="$safearray='yes'">
890 <xsl:value-of select="concat('Helper.unwrapEnum(', $elemgluetype, '.class,',$value,')')"/>
891 </xsl:when>
892 <xsl:otherwise>
893 <xsl:value-of select="concat($value,'.value()')"/>
894 </xsl:otherwise>
895 </xsl:choose>
896 </xsl:when>
897
898 <xsl:when test="$idltype='boolean'">
899 <xsl:choose>
900 <xsl:when test="$safearray='yes'">
901 <xsl:value-of select="concat('Helper.unwrapBool(', $value,')')"/>
902 </xsl:when>
903 <xsl:otherwise>
904 <xsl:value-of select="concat('new Variant(',$value,')')"/>
905 </xsl:otherwise>
906 </xsl:choose>
907 </xsl:when>
908
909 <xsl:when test="($idltype='short') or ($idltype='unsigned short')">
910 <xsl:choose>
911 <xsl:when test="$safearray='yes'">
912 <xsl:value-of select="concat('Helper.unwrapShort(', $value,')')"/>
913 </xsl:when>
914 <xsl:otherwise>
915 <xsl:value-of select="concat('new Variant(',$value,')')"/>
916 </xsl:otherwise>
917 </xsl:choose>
918 </xsl:when>
919
920
921 <xsl:when test="($idltype='long') or ($idltype='unsigned long')">
922 <xsl:choose>
923 <xsl:when test="$safearray='yes'">
924 <xsl:value-of select="concat('Helper.unwrapInt(', $value,')')"/>
925 </xsl:when>
926 <xsl:otherwise>
927 <xsl:value-of select="concat('new Variant(',$value,')')"/>
928 </xsl:otherwise>
929 </xsl:choose>
930 </xsl:when>
931
932 <xsl:when test="($idltype='wstring') or ($idltype='uuid')">
933 <xsl:choose>
934 <xsl:when test="$safearray='yes'">
935 <xsl:value-of select="concat('Helper.unwrapString(', $value,')')"/>
936 </xsl:when>
937 <xsl:otherwise>
938 <xsl:value-of select="concat('new Variant(',$value,')')"/>
939 </xsl:otherwise>
940 </xsl:choose>
941 </xsl:when>
942
943 <xsl:when test="($idltype='unsigned long long') or ($idltype='long long')">
944 <xsl:choose>
945 <xsl:when test="$safearray='yes'">
946 <xsl:value-of select="concat('Helper.unwrapLong(', $value,')')"/>
947 </xsl:when>
948 <xsl:otherwise>
949 <xsl:value-of select="concat('new Variant(',$value,'.longValue())')"/>
950 </xsl:otherwise>
951 </xsl:choose>
952 </xsl:when>
953
954 <xsl:otherwise>
955 <xsl:call-template name="fatalError">
956 <xsl:with-param name="msg" select="concat('Unhandled type: ', $idltype)" />
957 </xsl:call-template>
958 </xsl:otherwise>
959 </xsl:choose>
960
961</xsl:template>
962
963<xsl:template name="cookInParamJaxws">
964 <xsl:param name="value"/>
965 <xsl:param name="idltype"/>
966 <xsl:param name="safearray"/>
967 <xsl:variable name="isstruct"
968 select="//interface[@name=$idltype]/@wsmap='struct'" />
969
970 <xsl:variable name="gluetype">
971 <xsl:call-template name="typeIdl2Glue">
972 <xsl:with-param name="type" select="$idltype" />
973 <xsl:with-param name="safearray" select="$safearray" />
974 </xsl:call-template>
975 </xsl:variable>
976
977 <xsl:variable name="elemgluetype">
978 <xsl:if test="$safearray='yes'">
979 <xsl:call-template name="typeIdl2Glue">
980 <xsl:with-param name="type" select="$idltype" />
981 <xsl:with-param name="safearray" select="'no'" />
982 <xsl:with-param name="forceelem" select="'yes'" />
983 </xsl:call-template>
984 </xsl:if>
985 </xsl:variable>
986
987 <xsl:choose>
988 <xsl:when test="//interface[@name=$idltype] or $idltype='$unknown'">
989 <xsl:choose>
990 <xsl:when test="@safearray='yes'">
991 <xsl:value-of select="concat('Helper.unwrap(',$value,')')"/>
992 </xsl:when>
993 <xsl:otherwise>
994 <xsl:value-of select="concat('((', $value, ' == null) ? null :', $value, '.getWrapped())')" />
995 </xsl:otherwise>
996 </xsl:choose>
997 </xsl:when>
998
999 <xsl:when test="//enum[@name=$idltype]">
1000 <xsl:choose>
1001 <xsl:when test="$safearray='yes'">
1002 <xsl:variable name="elembacktype">
1003 <xsl:call-template name="typeIdl2Back">
1004 <xsl:with-param name="type" select="$idltype" />
1005 <xsl:with-param name="safearray" select="'no'" />
1006 <xsl:with-param name="forceelem" select="'yes'" />
1007 </xsl:call-template>
1008 </xsl:variable>
1009 <xsl:value-of select="concat('Helper.convertEnums(', $elemgluetype, '.class,', $elembacktype, '.class,', $value,')')"/>
1010 </xsl:when>
1011 <xsl:otherwise>
1012 <xsl:variable name="backtype">
1013 <xsl:call-template name="typeIdl2Back">
1014 <xsl:with-param name="type" select="$idltype" />
1015 <xsl:with-param name="safearray" select="'no'" />
1016 <xsl:with-param name="forceelem" select="'yes'" />
1017 </xsl:call-template>
1018 </xsl:variable>
1019 <xsl:value-of select="concat($backtype, '.fromValue(', $value, '.name())')"/>
1020 </xsl:otherwise>
1021 </xsl:choose>
1022 </xsl:when>
1023
1024 <xsl:otherwise>
1025 <xsl:value-of select="$value"/>
1026 </xsl:otherwise>
1027 </xsl:choose>
1028
1029</xsl:template>
1030
1031<xsl:template name="cookInParam">
1032 <xsl:param name="value"/>
1033 <xsl:param name="idltype"/>
1034 <xsl:param name="safearray"/>
1035 <xsl:choose>
1036 <xsl:when test="($G_vboxGlueStyle='xpcom')">
1037 <xsl:call-template name="cookInParamXpcom">
1038 <xsl:with-param name="value" select="$value" />
1039 <xsl:with-param name="idltype" select="$idltype" />
1040 <xsl:with-param name="safearray" select="$safearray" />
1041 </xsl:call-template>
1042 </xsl:when>
1043 <xsl:when test="($G_vboxGlueStyle='mscom')">
1044 <xsl:call-template name="cookInParamMscom">
1045 <xsl:with-param name="value" select="$value" />
1046 <xsl:with-param name="idltype" select="$idltype" />
1047 <xsl:with-param name="safearray" select="$safearray" />
1048 </xsl:call-template>
1049 </xsl:when>
1050 <xsl:when test="($G_vboxGlueStyle='jaxws')">
1051 <xsl:call-template name="cookInParamJaxws">
1052 <xsl:with-param name="value" select="$value" />
1053 <xsl:with-param name="idltype" select="$idltype" />
1054 <xsl:with-param name="safearray" select="$safearray" />
1055 </xsl:call-template>
1056 </xsl:when>
1057 <xsl:otherwise>
1058 <xsl:call-template name="fatalError">
1059 <xsl:with-param name="msg" select="'Unhandled style (cookInParam)'" />
1060 </xsl:call-template>
1061 </xsl:otherwise>
1062 </xsl:choose>
1063</xsl:template>
1064
1065<!-- Invoke backend method, including parameter conversion -->
1066<xsl:template name="genBackMethodCall">
1067 <xsl:param name="ifname"/>
1068 <xsl:param name="methodname"/>
1069 <xsl:param name="retval"/>
1070
1071 <xsl:choose>
1072 <xsl:when test="($G_vboxGlueStyle='xpcom')">
1073 <xsl:value-of select="' '" />
1074 <xsl:if test="param[@dir='return']">
1075 <xsl:value-of select="concat($retval, ' = ')" />
1076 </xsl:if>
1077 <xsl:value-of select="concat('getTypedWrapped().', $methodname,'(')"/>
1078 <xsl:for-each select="param">
1079 <xsl:choose>
1080 <xsl:when test="@dir='return'">
1081 <xsl:if test="@safearray='yes'">
1082 <xsl:value-of select="'null'" />
1083 </xsl:if>
1084 </xsl:when>
1085 <xsl:when test="@dir='out'">
1086 <xsl:if test="@safearray='yes'">
1087 <xsl:value-of select="'null, '" />
1088 </xsl:if>
1089 <xsl:value-of select="concat('tmp_', @name)" />
1090 </xsl:when>
1091 <xsl:when test="@dir='in'">
1092 <xsl:if test="@safearray='yes'">
1093 <xsl:value-of select="concat(@name,'.size(), ')" />
1094 </xsl:if>
1095 <xsl:variable name="unwrapped">
1096 <xsl:call-template name="cookInParam">
1097 <xsl:with-param name="value" select="@name" />
1098 <xsl:with-param name="idltype" select="@type" />
1099 <xsl:with-param name="safearray" select="@safearray" />
1100 </xsl:call-template>
1101 </xsl:variable>
1102 <xsl:value-of select="$unwrapped"/>
1103 </xsl:when>
1104 <xsl:otherwise>
1105 <xsl:call-template name="fatalError">
1106 <xsl:with-param name="msg" select="concat('Unsupported param dir: ', @dir, '&quot;.')" />
1107 </xsl:call-template>
1108 </xsl:otherwise>
1109 </xsl:choose>
1110 <xsl:if test="not(position()=last()) and not(following-sibling::param[1]/@dir='return' and not(following-sibling::param[1]/@safearray='yes'))">
1111 <xsl:value-of select="', '"/>
1112 </xsl:if>
1113 </xsl:for-each>
1114 <xsl:value-of select="');&#10;'"/>
1115 </xsl:when>
1116
1117 <xsl:when test="($G_vboxGlueStyle='mscom')">
1118 <xsl:value-of select="' '" />
1119 <xsl:if test="param[@dir='return']">
1120 <xsl:value-of select="concat($retval, ' = ')" />
1121 </xsl:if>
1122 <xsl:value-of select="concat('Helper.invoke(getTypedWrapped(), &quot;', $methodname, '&quot; ')"/>
1123 <xsl:for-each select="param[not(@dir='return')]">
1124 <xsl:value-of select="', '"/>
1125 <xsl:choose>
1126 <xsl:when test="@dir='out'">
1127 <xsl:value-of select="concat('tmp_', @name)" />
1128 </xsl:when>
1129 <xsl:when test="@dir='in'">
1130 <xsl:variable name="unwrapped">
1131 <xsl:call-template name="cookInParam">
1132 <xsl:with-param name="value" select="@name" />
1133 <xsl:with-param name="idltype" select="@type" />
1134 <xsl:with-param name="safearray" select="@safearray" />
1135 </xsl:call-template>
1136 </xsl:variable>
1137 <xsl:value-of select="$unwrapped"/>
1138 </xsl:when>
1139 </xsl:choose>
1140 </xsl:for-each>
1141 <xsl:value-of select="');&#10;'"/>
1142 </xsl:when>
1143
1144 <xsl:when test="($G_vboxGlueStyle='jaxws')">
1145 <xsl:variable name="jaxwsmethod">
1146 <xsl:call-template name="makeJaxwsMethod">
1147 <xsl:with-param name="ifname" select="$ifname" />
1148 <xsl:with-param name="methodname" select="$methodname" />
1149 </xsl:call-template>
1150 </xsl:variable>
1151 <xsl:variable name="portArg">
1152 <xsl:if test="not(//interface[@name=$ifname]/@wsmap='global')">
1153 <xsl:value-of select="'obj'"/>
1154 </xsl:if>
1155 </xsl:variable>
1156 <xsl:variable name="paramsinout" select="param[@dir='in' or @dir='out']" />
1157
1158 <xsl:value-of select="' '" />
1159 <xsl:if test="param[@dir='return'] and not(param[@dir='out'])">
1160 <xsl:value-of select="concat($retval, ' = ')" />
1161 </xsl:if>
1162 <xsl:value-of select="concat('port.', $jaxwsmethod, '(', $portArg)" />
1163 <xsl:if test="$paramsinout and not($portArg='')">
1164 <xsl:value-of select="', '"/>
1165 </xsl:if>
1166
1167 <!-- jax-ws has an oddity: if both out params and a return value exist,
1168 then the return value is moved to the function's argument list... -->
1169 <xsl:choose>
1170 <xsl:when test="param[@dir='out'] and param[@dir='return']">
1171 <xsl:for-each select="param">
1172 <xsl:choose>
1173 <xsl:when test="@dir='return'">
1174 <xsl:value-of select="$retval"/>
1175 </xsl:when>
1176 <xsl:when test="@dir='out'">
1177 <xsl:value-of select="concat('tmp_', @name)" />
1178 </xsl:when>
1179 <xsl:otherwise>
1180 <xsl:call-template name="cookInParam">
1181 <xsl:with-param name="value" select="@name" />
1182 <xsl:with-param name="idltype" select="@type" />
1183 <xsl:with-param name="safearray" select="@safearray" />
1184 </xsl:call-template>
1185 </xsl:otherwise>
1186 </xsl:choose>
1187 <xsl:if test="not(position()=last())">
1188 <xsl:value-of select="', '"/>
1189 </xsl:if>
1190 </xsl:for-each>
1191 </xsl:when>
1192 <xsl:otherwise>
1193 <xsl:for-each select="$paramsinout">
1194 <xsl:choose>
1195 <xsl:when test="@dir='return'">
1196 <xsl:value-of select="$retval"/>
1197 </xsl:when>
1198 <xsl:when test="@dir='out'">
1199 <xsl:value-of select="concat('tmp_', @name)" />
1200 </xsl:when>
1201 <xsl:otherwise>
1202 <xsl:call-template name="cookInParam">
1203 <xsl:with-param name="value" select="@name" />
1204 <xsl:with-param name="idltype" select="@type" />
1205 <xsl:with-param name="safearray" select="@safearray" />
1206 </xsl:call-template>
1207 </xsl:otherwise>
1208 </xsl:choose>
1209 <xsl:if test="not(position()=last())">
1210 <xsl:value-of select="', '"/>
1211 </xsl:if>
1212 </xsl:for-each>
1213 </xsl:otherwise>
1214 </xsl:choose>
1215 <xsl:value-of select="');&#10;'"/>
1216 </xsl:when>
1217
1218 <xsl:otherwise>
1219 <xsl:call-template name="fatalError">
1220 <xsl:with-param name="msg" select="'Style unknown (genBackMethodCall)'" />
1221 </xsl:call-template>
1222 </xsl:otherwise>
1223
1224 </xsl:choose>
1225</xsl:template>
1226
1227<xsl:template name="genGetterCall">
1228 <xsl:param name="ifname"/>
1229 <xsl:param name="gettername"/>
1230 <xsl:param name="backtype"/>
1231 <xsl:param name="retval"/>
1232
1233 <xsl:choose>
1234
1235 <xsl:when test="$G_vboxGlueStyle='xpcom'">
1236 <xsl:value-of select="concat(' ', $backtype, ' ', $retval,' = getTypedWrapped().', $gettername,'(')" />
1237 <xsl:if test="@safearray">
1238 <xsl:value-of select="'null'" />
1239 </xsl:if>
1240 <xsl:value-of select="');&#10;'" />
1241 </xsl:when>
1242
1243 <xsl:when test="$G_vboxGlueStyle='mscom'">
1244 <xsl:value-of select="concat(' ', $backtype, ' ', $retval,' = Dispatch.get(getTypedWrapped(), &quot;', @name,'&quot;);&#10;')" />
1245 </xsl:when>
1246
1247 <xsl:when test="$G_vboxGlueStyle='jaxws'">
1248 <xsl:variable name="jaxwsGetter">
1249 <xsl:call-template name="makeJaxwsMethod">
1250 <xsl:with-param name="ifname" select="$ifname" />
1251 <xsl:with-param name="methodname" select="$gettername" />
1252 </xsl:call-template>
1253 </xsl:variable>
1254 <xsl:value-of select="concat(' ', $backtype, ' ', $retval,' = port.', $jaxwsGetter, '(obj);&#10;')" />
1255 </xsl:when>
1256
1257 <xsl:otherwise>
1258 <xsl:call-template name="fatalError">
1259 <xsl:with-param name="msg" select="'Style unknown (genGetterCall)'" />
1260 </xsl:call-template>
1261 </xsl:otherwise>
1262
1263 </xsl:choose>
1264</xsl:template>
1265
1266<xsl:template name="genSetterCall">
1267 <xsl:param name="ifname"/>
1268 <xsl:param name="settername"/>
1269 <xsl:param name="value"/>
1270
1271 <xsl:choose>
1272 <xsl:when test="$G_vboxGlueStyle='xpcom'">
1273 <xsl:value-of select="concat(' getTypedWrapped().', $settername, '(', $value,');&#10;')" />
1274 </xsl:when>
1275
1276 <xsl:when test="$G_vboxGlueStyle='mscom'">
1277 <xsl:value-of select="concat(' Dispatch.put(getTypedWrapped(), &quot;', @name,'&quot;, ',$value, ');&#10;')" />
1278 </xsl:when>
1279
1280 <xsl:when test="$G_vboxGlueStyle='jaxws'">
1281 <xsl:variable name="jaxwsSetter">
1282 <xsl:call-template name="makeJaxwsMethod">
1283 <xsl:with-param name="ifname" select="$ifname" />
1284 <xsl:with-param name="methodname" select="$settername" />
1285 </xsl:call-template>
1286 </xsl:variable>
1287 <xsl:value-of select="concat(' port.', $jaxwsSetter, '(obj, ', $value,');&#10;')" />
1288 </xsl:when>
1289
1290 <xsl:otherwise>
1291 <xsl:call-template name="fatalError">
1292 <xsl:with-param name="msg" select="'Style unknown (genSetterCall)'" />
1293 </xsl:call-template>
1294 </xsl:otherwise>
1295
1296 </xsl:choose>
1297</xsl:template>
1298
1299<xsl:template name="genStructWrapperJaxws">
1300 <xsl:param name="ifname"/>
1301
1302 <xsl:value-of select="concat(' private ', $G_virtualBoxPackageCom,'.',$ifname, ' real;&#10;')"/>
1303 <xsl:value-of select="' private VboxPortType port;&#10;&#10;'"/>
1304
1305 <xsl:value-of select="concat(' public ', $ifname, '(', $G_virtualBoxPackageCom,'.',$ifname,' real, VboxPortType port) {&#10; this.real = real; &#10; this.port = port; &#10; }&#10;')"/>
1306
1307 <xsl:for-each select="attribute">
1308 <xsl:variable name="attrname"><xsl:value-of select="@name" /></xsl:variable>
1309 <xsl:variable name="attrtype"><xsl:value-of select="@type" /></xsl:variable>
1310 <xsl:variable name="attrreadonly"><xsl:value-of select="@readonly" /></xsl:variable>
1311 <xsl:variable name="attrsafearray"><xsl:value-of select="@safearray" /></xsl:variable>
1312
1313 <xsl:if test="not($attrreadonly)">
1314 <xsl:call-template name="fatalError">
1315 <xsl:with-param name="msg" select="'Non read-only struct (genStructWrapperJaxws)'" />
1316 </xsl:call-template>
1317 </xsl:if>
1318
1319 <!-- Emit getter -->
1320 <xsl:variable name="backgettername">
1321 <xsl:choose>
1322 <!-- Stupid, but backend boolean getters called isFoo(), not getFoo() -->
1323 <xsl:when test="$attrtype = 'boolean'">
1324 <xsl:variable name="capsname">
1325 <xsl:call-template name="capitalize">
1326 <xsl:with-param name="str" select="$attrname" />
1327 </xsl:call-template>
1328 </xsl:variable>
1329 <xsl:value-of select="concat('is', $capsname)" />
1330 </xsl:when>
1331 <xsl:otherwise>
1332 <xsl:call-template name="makeGetterName">
1333 <xsl:with-param name="attrname" select="$attrname" />
1334 </xsl:call-template>
1335 </xsl:otherwise>
1336 </xsl:choose>
1337 </xsl:variable>
1338
1339 <xsl:variable name="gluegettername">
1340 <xsl:call-template name="makeGetterName">
1341 <xsl:with-param name="attrname" select="$attrname" />
1342 </xsl:call-template>
1343 </xsl:variable>
1344
1345 <xsl:variable name="gluegettertype">
1346 <xsl:call-template name="typeIdl2Glue">
1347 <xsl:with-param name="type" select="$attrtype" />
1348 <xsl:with-param name="safearray" select="@safearray" />
1349 </xsl:call-template>
1350 </xsl:variable>
1351
1352 <xsl:variable name="backgettertype">
1353 <xsl:call-template name="typeIdl2Back">
1354 <xsl:with-param name="type" select="$attrtype" />
1355 <xsl:with-param name="safearray" select="@safearray" />
1356 </xsl:call-template>
1357 </xsl:variable>
1358
1359 <xsl:value-of select="concat(' public ', $gluegettertype, ' ', $gluegettername, '() {&#10;')" />
1360 <xsl:value-of select="concat(' ', $backgettertype, ' retVal = real.', $backgettername, '();&#10;')" />
1361 <xsl:variable name="wrapped">
1362 <xsl:call-template name="cookOutParam">
1363 <xsl:with-param name="value" select="'retVal'" />
1364 <xsl:with-param name="idltype" select="$attrtype" />
1365 <xsl:with-param name="safearray" select="@safearray" />
1366 </xsl:call-template>
1367 </xsl:variable>
1368 <xsl:value-of select="concat(' return ', $wrapped, ';&#10;')" />
1369 <xsl:value-of select=" ' }&#10;'" />
1370
1371 </xsl:for-each>
1372
1373</xsl:template>
1374
1375<!-- Interface method wrapper -->
1376<xsl:template name="genMethod">
1377 <xsl:param name="ifname"/>
1378 <xsl:param name="methodname"/>
1379
1380 <xsl:choose>
1381 <xsl:when test="(param[@mod='ptr']) or (($G_vboxGlueStyle='jaxws') and (param[@type=($G_setSuppressedInterfaces/@name)]))" >
1382 <xsl:comment>
1383 <xsl:value-of select="concat('Skipping method ', $methodname, ' for it has parameters with suppressed types')" />
1384 </xsl:comment>
1385 </xsl:when>
1386 <xsl:otherwise>
1387 <xsl:variable name="hasReturnParms" select="param[@dir='return']" />
1388 <xsl:variable name="hasOutParms" select="param[@dir='out']" />
1389 <xsl:variable name="returnidltype" select="param[@dir='return']/@type" />
1390 <xsl:variable name="returnidlsafearray" select="param[@dir='return']/@safearray" />
1391 <xsl:variable name="returngluetype">
1392 <xsl:choose>
1393 <xsl:when test="$returnidltype">
1394 <xsl:call-template name="typeIdl2Glue">
1395 <xsl:with-param name="type" select="$returnidltype" />
1396 <xsl:with-param name="safearray" select="$returnidlsafearray" />
1397 </xsl:call-template>
1398 </xsl:when>
1399 <xsl:otherwise>
1400 <xsl:text>void</xsl:text>
1401 </xsl:otherwise>
1402 </xsl:choose>
1403 </xsl:variable>
1404 <xsl:variable name="retValValue">
1405 <xsl:choose>
1406 <xsl:when test="(param[@dir='out']) and ($G_vboxGlueStyle='jaxws')">
1407 <xsl:value-of select="'retVal.value'"/>
1408 </xsl:when>
1409 <xsl:otherwise>
1410 <xsl:value-of select="'retVal'"/>
1411 </xsl:otherwise>
1412 </xsl:choose>
1413 </xsl:variable>
1414 <xsl:value-of select="concat(' public ', $returngluetype, ' ', $methodname, '(')" />
1415 <xsl:variable name="paramsinout" select="param[@dir='in' or @dir='out']" />
1416 <xsl:for-each select="exsl:node-set($paramsinout)">
1417 <xsl:variable name="paramgluetype">
1418 <xsl:call-template name="typeIdl2Glue">
1419 <xsl:with-param name="type" select="@type" />
1420 <xsl:with-param name="safearray" select="@safearray" />
1421 </xsl:call-template>
1422 </xsl:variable>
1423 <xsl:choose>
1424 <xsl:when test="@dir='out'">
1425 <xsl:value-of select="concat('Holder&lt;', $paramgluetype, '&gt; ', @name)" />
1426 </xsl:when>
1427 <xsl:otherwise>
1428 <xsl:value-of select="concat($paramgluetype, ' ', @name)" />
1429 </xsl:otherwise>
1430 </xsl:choose>
1431 <xsl:if test="not(position()=last())">
1432 <xsl:value-of select="', '" />
1433 </xsl:if>
1434 </xsl:for-each>
1435 <xsl:value-of select="') {&#10;'"/>
1436
1437 <xsl:call-template name="startExcWrapper"/>
1438
1439 <!-- declare temp out params -->
1440 <xsl:for-each select="param[@dir='out']">
1441 <xsl:variable name="backouttype">
1442 <xsl:call-template name="typeIdl2Back">
1443 <xsl:with-param name="type" select="@type" />
1444 <xsl:with-param name="safearray" select="@safearray" />
1445 </xsl:call-template>
1446 </xsl:variable>
1447 <xsl:choose>
1448 <xsl:when test="$G_vboxGlueStyle='xpcom'">
1449 <xsl:value-of select="concat(' ', $backouttype, '[] tmp_', @name, ' = (', $backouttype, '[])java.lang.reflect.Array.newInstance(',$backouttype,'.class, 1);&#10;')"/>
1450 </xsl:when>
1451 <xsl:when test="$G_vboxGlueStyle='mscom'">
1452 <xsl:value-of select="concat(' Variant tmp_', @name, ' = new Variant();&#10;')"/>
1453 </xsl:when>
1454 <xsl:when test="$G_vboxGlueStyle='jaxws'">
1455 <xsl:value-of select="concat(' javax.xml.ws.Holder&lt;', $backouttype,'&gt; tmp_', @name, ' = new javax.xml.ws.Holder&lt;', $backouttype,'&gt;();&#10;')"/>
1456 </xsl:when>
1457 <xsl:otherwise>
1458 <xsl:call-template name="fatalError">
1459 <xsl:with-param name="msg" select="'Handle out param (genMethod)'" />
1460 </xsl:call-template>
1461 </xsl:otherwise>
1462 </xsl:choose>
1463 </xsl:for-each>
1464
1465 <!-- declare return param, if any -->
1466 <xsl:if test="$hasReturnParms">
1467 <xsl:variable name="backrettype">
1468 <xsl:call-template name="typeIdl2Back">
1469 <xsl:with-param name="type" select="$returnidltype" />
1470 <xsl:with-param name="safearray" select="$returnidlsafearray" />
1471 </xsl:call-template>
1472 </xsl:variable>
1473 <xsl:choose>
1474 <xsl:when test="(param[@dir='out']) and ($G_vboxGlueStyle='jaxws')">
1475 <xsl:value-of select="concat(' javax.xml.ws.Holder&lt;', $backrettype, '&gt;',
1476 ' retVal = new javax.xml.ws.Holder&lt;', $backrettype,
1477 '&gt;();&#10;')"/>
1478 </xsl:when>
1479 <xsl:otherwise>
1480 <xsl:value-of select="concat(' ', $backrettype, ' retVal;&#10;')"/>
1481 </xsl:otherwise>
1482 </xsl:choose>
1483 </xsl:if>
1484
1485 <!-- Method call -->
1486 <xsl:call-template name="genBackMethodCall">
1487 <xsl:with-param name="ifname" select="$ifname" />
1488 <xsl:with-param name="methodname" select="$methodname" />
1489 <xsl:with-param name="retval" select="'retVal'" />
1490 </xsl:call-template>
1491
1492 <!-- return out params -->
1493 <xsl:for-each select="param[@dir='out']">
1494 <xsl:variable name="varval">
1495 <xsl:choose>
1496 <xsl:when test="$G_vboxGlueStyle='xpcom'">
1497 <xsl:value-of select="concat('tmp_',@name,'[0]')" />
1498 </xsl:when>
1499 <xsl:when test="$G_vboxGlueStyle='mscom'">
1500 <xsl:value-of select="concat('tmp_',@name)" />
1501 </xsl:when>
1502 <xsl:when test="$G_vboxGlueStyle='jaxws'">
1503 <xsl:value-of select="concat('tmp_',@name,'.value')" />
1504 </xsl:when>
1505 <xsl:otherwise>
1506 <xsl:call-template name="fatalError">
1507 <xsl:with-param name="msg" select="'Style unknown (genMethod, outparam)'" />
1508 </xsl:call-template>
1509 </xsl:otherwise>
1510 </xsl:choose>
1511 </xsl:variable>
1512 <xsl:variable name="wrapped">
1513 <xsl:call-template name="cookOutParam">
1514 <xsl:with-param name="value" select="$varval" />
1515 <xsl:with-param name="idltype" select="@type" />
1516 <xsl:with-param name="safearray" select="@safearray" />
1517 </xsl:call-template>
1518 </xsl:variable>
1519 <xsl:value-of select="concat(' ', @name, '.value = ',$wrapped,';&#10;')"/>
1520 </xsl:for-each>
1521
1522 <xsl:if test="$hasReturnParms">
1523 <!-- actual 'return' statement -->
1524 <xsl:variable name="wrapped">
1525 <xsl:call-template name="cookOutParam">
1526 <xsl:with-param name="value" select="$retValValue" />
1527 <xsl:with-param name="idltype" select="$returnidltype" />
1528 <xsl:with-param name="safearray" select="$returnidlsafearray" />
1529 </xsl:call-template>
1530 </xsl:variable>
1531 <xsl:value-of select="concat(' return ', $wrapped, ';&#10;')" />
1532 </xsl:if>
1533 <xsl:call-template name="endExcWrapper"/>
1534
1535 <xsl:value-of select="' }&#10;'"/>
1536 </xsl:otherwise>
1537 </xsl:choose>
1538
1539</xsl:template>
1540
1541<!-- Callback interface method -->
1542<xsl:template name="genCbMethodDecl">
1543 <xsl:param name="ifname"/>
1544 <xsl:param name="methodname"/>
1545
1546 <xsl:choose>
1547 <xsl:when test="(param[@mod='ptr'])" >
1548 <xsl:comment>
1549 <xsl:value-of select="concat('Skipping method ', $methodname, ' for it has parameters with suppressed types')" />
1550 </xsl:comment>
1551 </xsl:when>
1552 <xsl:otherwise>
1553 <xsl:variable name="returnidltype" select="param[@dir='return']/@type" />
1554 <xsl:variable name="returnidlsafearray" select="param[@dir='return']/@safearray" />
1555 <xsl:variable name="returngluetype">
1556 <xsl:choose>
1557 <xsl:when test="$returnidltype">
1558 <xsl:call-template name="typeIdl2Glue">
1559 <xsl:with-param name="type" select="$returnidltype" />
1560 <xsl:with-param name="safearray" select="$returnidlsafearray" />
1561 </xsl:call-template>
1562 </xsl:when>
1563 <xsl:otherwise>
1564 <xsl:text>void</xsl:text>
1565 </xsl:otherwise>
1566 </xsl:choose>
1567 </xsl:variable>
1568 <xsl:value-of select="concat(' public ', $returngluetype, ' ', $methodname, '(')" />
1569 <xsl:variable name="paramsinout" select="param[@dir='in' or @dir='out']" />
1570 <xsl:for-each select="exsl:node-set($paramsinout)">
1571 <xsl:variable name="paramgluetype">
1572 <xsl:call-template name="typeIdl2Glue">
1573 <xsl:with-param name="type" select="@type" />
1574 <xsl:with-param name="safearray" select="@safearray" />
1575 </xsl:call-template>
1576 </xsl:variable>
1577 <xsl:choose>
1578 <xsl:when test="@dir='out'">
1579 <xsl:value-of select="concat('Holder&lt;', $paramgluetype, '&gt; ', @name)" />
1580 </xsl:when>
1581 <xsl:otherwise>
1582 <xsl:value-of select="concat($paramgluetype, ' ', @name)" />
1583 </xsl:otherwise>
1584 </xsl:choose>
1585 <xsl:if test="not(position()=last())">
1586 <xsl:text>, </xsl:text>
1587 </xsl:if>
1588 </xsl:for-each>
1589 <xsl:value-of select="');&#10;'"/>
1590 </xsl:otherwise>
1591 </xsl:choose>
1592</xsl:template>
1593
1594<!-- queryInterface wrapper -->
1595<xsl:template name="genQI">
1596 <xsl:param name="ifname"/>
1597 <xsl:param name="uuid" />
1598
1599 <xsl:value-of select="concat(' public static ', $ifname, ' queryInterface(IUnknown obj) {&#10;')" />
1600 <xsl:choose>
1601 <xsl:when test="$G_vboxGlueStyle='xpcom'">
1602 <xsl:variable name="backtype">
1603 <xsl:call-template name="typeIdl2Back">
1604 <xsl:with-param name="type" select="$ifname" />
1605 </xsl:call-template>
1606 </xsl:variable>
1607 <xsl:value-of select=" ' nsISupports nsobj = obj != null ? (nsISupports)obj.getWrapped() : null;&#10;'"/>
1608 <xsl:value-of select=" ' if (nsobj == null) return null;&#10;'"/>
1609 <xsl:value-of select="concat(' ',$backtype, ' qiobj = Helper.queryInterface(nsobj, &quot;{',$uuid,'}&quot;, ',$backtype,'.class);&#10;')" />
1610 <xsl:value-of select="concat(' return qiobj == null ? null : new ', $ifname, '(qiobj);&#10;')" />
1611 </xsl:when>
1612
1613 <xsl:when test="$G_vboxGlueStyle='mscom'">
1614 <xsl:value-of select="concat(' return', ' obj == null ? null : new ', $ifname, '((com.jacob.com.Dispatch)obj.getWrapped());&#10;')" />
1615 </xsl:when>
1616
1617 <xsl:when test="$G_vboxGlueStyle='jaxws'">
1618 <!-- bad, need to check that we really can be casted to this type -->
1619 <xsl:value-of select="concat(' return obj == null ? null : new ', $ifname, '(obj.getWrapped(), obj.getRemoteWSPort());&#10;')" />
1620 </xsl:when>
1621
1622 <xsl:otherwise>
1623 <xsl:call-template name="fatalError">
1624 <xsl:with-param name="msg" select="'Style unknown (genQI)'" />
1625 </xsl:call-template>
1626 </xsl:otherwise>
1627
1628 </xsl:choose>
1629 <xsl:value-of select=" ' }&#10;'" />
1630</xsl:template>
1631
1632
1633<xsl:template name="genCbMethodImpl">
1634 <xsl:param name="ifname"/>
1635 <xsl:param name="methodname"/>
1636
1637 <xsl:choose>
1638 <xsl:when test="(param[@mod='ptr'])" >
1639 <xsl:comment>
1640 <xsl:value-of select="concat('Skipping method ', $methodname, ' for it has parameters with suppressed types')" />
1641 </xsl:comment>
1642 </xsl:when>
1643 <xsl:otherwise>
1644 <xsl:variable name="hasReturnParms" select="param[@dir='return']" />
1645 <xsl:variable name="hasOutParms" select="param[@dir='out']" />
1646 <xsl:variable name="returnidltype" select="param[@dir='return']/@type" />
1647 <xsl:variable name="returnidlsafearray" select="param[@dir='return']/@safearray" />
1648 <xsl:variable name="returnbacktype">
1649 <xsl:choose>
1650 <xsl:when test="$returnidltype">
1651 <xsl:call-template name="typeIdl2Back">
1652 <xsl:with-param name="type" select="$returnidltype" />
1653 <xsl:with-param name="safearray" select="$returnidlsafearray" />
1654 </xsl:call-template>
1655 </xsl:when>
1656 <xsl:otherwise>
1657 <xsl:text>void</xsl:text>
1658 </xsl:otherwise>
1659 </xsl:choose>
1660 </xsl:variable>
1661 <xsl:variable name="paramsinout" select="param[@dir='in' or @dir='out']" />
1662 <xsl:choose>
1663 <xsl:when test="$G_vboxGlueStyle='xpcom'">
1664 <xsl:value-of select="concat(' public ', $returnbacktype, ' ', $methodname, '(')" />
1665 <xsl:for-each select="exsl:node-set($paramsinout)">
1666 <xsl:variable name="parambacktype">
1667 <xsl:call-template name="typeIdl2Back">
1668 <xsl:with-param name="type" select="@type" />
1669 <xsl:with-param name="safearray" select="@safearray" />
1670 </xsl:call-template>
1671 </xsl:variable>
1672 <xsl:choose>
1673 <xsl:when test="@dir='out'">
1674 <xsl:value-of select="concat($parambacktype, '[] ', @name)" />
1675 </xsl:when>
1676 <xsl:otherwise>
1677 <xsl:if test="@safearray">
1678 <xsl:value-of select="concat('long len_',@name,', ')" />
1679 </xsl:if>
1680 <xsl:value-of select="concat($parambacktype, ' ', @name)" />
1681 </xsl:otherwise>
1682 </xsl:choose>
1683 <xsl:if test="not(position()=last())">
1684 <xsl:text>, </xsl:text>
1685 </xsl:if>
1686 </xsl:for-each>
1687 <xsl:value-of select="') {&#10;'"/>
1688 </xsl:when>
1689
1690 <xsl:when test="$G_vboxGlueStyle='mscom'">
1691 <xsl:variable name="capsname">
1692 <xsl:call-template name="capitalize">
1693 <xsl:with-param name="str" select="$methodname" />
1694 </xsl:call-template>
1695 </xsl:variable>
1696 <xsl:value-of select="concat(' public ', $returnbacktype, ' ', $capsname, '(')" />
1697 <xsl:value-of select="'Variant _args[]'"/>
1698 <xsl:value-of select="') {&#10;'"/>
1699 <xsl:for-each select="exsl:node-set($paramsinout)">
1700 <xsl:variable name="parambacktype">
1701 <xsl:call-template name="typeIdl2Back">
1702 <xsl:with-param name="type" select="@type" />
1703 <xsl:with-param name="safearray" select="@safearray" />
1704 </xsl:call-template>
1705 </xsl:variable>
1706 <xsl:value-of select="concat(' ', $parambacktype, ' ', @name, '=_args[', count(preceding-sibling::param),'];&#10;')" />
1707 </xsl:for-each>
1708 </xsl:when>
1709
1710 <xsl:otherwise>
1711 <xsl:call-template name="fatalError">
1712 <xsl:with-param name="msg" select="'Style unknown (genSetterCall)'" />
1713 </xsl:call-template>
1714 </xsl:otherwise>
1715
1716 </xsl:choose>
1717
1718 <!-- declare temp out params -->
1719 <xsl:for-each select="param[@dir='out']">
1720 <xsl:variable name="glueouttype">
1721 <xsl:call-template name="typeIdl2Glue">
1722 <xsl:with-param name="type" select="@type" />
1723 <xsl:with-param name="safearray" select="@safearray" />
1724 </xsl:call-template>
1725 </xsl:variable>
1726 <xsl:value-of select="concat(' Holder&lt;', $glueouttype, '&gt; tmp_', @name, ' = new Holder&lt;', $glueouttype, '&gt;();&#10;')"/>
1727 </xsl:for-each>
1728
1729 <!-- declare return param, if any -->
1730 <xsl:if test="$hasReturnParms">
1731 <xsl:variable name="gluerettype">
1732 <xsl:call-template name="typeIdl2Glue">
1733 <xsl:with-param name="type" select="$returnidltype" />
1734 <xsl:with-param name="safearray" select="$returnidlsafearray" />
1735 </xsl:call-template>
1736 </xsl:variable>
1737 <xsl:value-of select="concat(' ', $gluerettype, ' retVal = &#10;')"/>
1738 </xsl:if>
1739
1740 <!-- Method call -->
1741 <xsl:value-of select="concat(' sink.', $methodname,'(')"/>
1742 <xsl:for-each select="param[not(@dir='return')]">
1743 <xsl:choose>
1744 <xsl:when test="@dir='out'">
1745 <xsl:value-of select="concat('tmp_', @name)" />
1746 </xsl:when>
1747 <xsl:when test="@dir='in'">
1748 <xsl:variable name="wrapped">
1749 <xsl:call-template name="cookOutParam">
1750 <xsl:with-param name="value" select="@name" />
1751 <xsl:with-param name="idltype" select="@type" />
1752 <xsl:with-param name="safearray" select="@safearray" />
1753 </xsl:call-template>
1754 </xsl:variable>
1755 <xsl:value-of select="$wrapped"/>
1756 </xsl:when>
1757 <xsl:otherwise>
1758 <xsl:call-template name="fatalError">
1759 <xsl:with-param name="msg" select="concat('Unsupported param dir: ', @dir, '&quot;.')" />
1760 </xsl:call-template>
1761 </xsl:otherwise>
1762 </xsl:choose>
1763 <xsl:if test="not(position()=last())">
1764 <xsl:value-of select="', '"/>
1765 </xsl:if>
1766 </xsl:for-each>
1767 <xsl:value-of select="');&#10;'"/>
1768
1769 <!-- return out params -->
1770 <xsl:for-each select="param[@dir='out']">
1771
1772 <xsl:variable name="unwrapped">
1773 <xsl:call-template name="cookInParam">
1774 <xsl:with-param name="value" select="concat('tmp_',@name,'.value')" />
1775 <xsl:with-param name="idltype" select="@type" />
1776 <xsl:with-param name="safearray" select="@safearray" />
1777 </xsl:call-template>
1778 </xsl:variable>
1779 <xsl:choose>
1780 <xsl:when test="$G_vboxGlueStyle='xpcom'">
1781 <xsl:value-of select="concat(' ', @name, '[0] = ',$unwrapped,';&#10;')"/>
1782 </xsl:when>
1783 <xsl:when test="$G_vboxGlueStyle='mscom'">
1784 <xsl:value-of select="concat(' _args[',count(preceding-sibling::param),'] = ',$unwrapped,';&#10;')"/>
1785 </xsl:when>
1786 </xsl:choose>
1787 </xsl:for-each>
1788
1789 <xsl:if test="$hasReturnParms">
1790 <!-- actual 'return' statement -->
1791 <xsl:variable name="unwrapped">
1792 <xsl:call-template name="cookInParam">
1793 <xsl:with-param name="value" select="'retVal'" />
1794 <xsl:with-param name="idltype" select="$returnidltype" />
1795 <xsl:with-param name="safearray" select="$returnidlsafearray" />
1796 </xsl:call-template>
1797 </xsl:variable>
1798 <xsl:value-of select="concat(' return ', $unwrapped, ';&#10;')" />
1799 </xsl:if>
1800 <xsl:value-of select="' }&#10;'"/>
1801 </xsl:otherwise>
1802 </xsl:choose>
1803</xsl:template>
1804
1805<!-- Interface method -->
1806<xsl:template name="genIfaceWrapper">
1807 <xsl:param name="ifname"/>
1808
1809 <xsl:variable name="wrappedType">
1810 <xsl:call-template name="wrappedName">
1811 <xsl:with-param name="ifname" select="$ifname" />
1812 </xsl:call-template>
1813 </xsl:variable>
1814
1815 <!-- Constructor -->
1816 <xsl:choose>
1817 <xsl:when test="($G_vboxGlueStyle='jaxws')">
1818 <xsl:value-of select="concat(' public ', $ifname, '(String wrapped, VboxPortType port) {&#10;')" />
1819 <xsl:value-of select=" ' super(wrapped, port);&#10;'"/>
1820 <xsl:value-of select=" ' }&#10;'"/>
1821 </xsl:when>
1822
1823 <xsl:when test="($G_vboxGlueStyle='xpcom') or ($G_vboxGlueStyle='mscom')">
1824 <xsl:value-of select="concat(' public ', $ifname, '(', $wrappedType,' wrapped) {&#10;')" />
1825 <xsl:value-of select=" ' super(wrapped);&#10;'"/>
1826 <xsl:value-of select=" ' }&#10;'"/>
1827
1828 <!-- Typed wrapped object accessor -->
1829 <xsl:value-of select="concat(' public ', $wrappedType, ' getTypedWrapped() {&#10;')" />
1830 <xsl:value-of select="concat(' return (', $wrappedType, ') getWrapped();&#10;')" />
1831 <xsl:value-of select=" ' }&#10;'" />
1832 </xsl:when>
1833
1834 <xsl:otherwise>
1835 <xsl:call-template name="fatalError">
1836 <xsl:with-param name="msg" select="'Style unknown (root, ctr)'" />
1837 </xsl:call-template>
1838 </xsl:otherwise>
1839 </xsl:choose>
1840 <!-- Attributes -->
1841 <xsl:for-each select="attribute[not(@mod='ptr')]">
1842 <xsl:variable name="attrname"><xsl:value-of select="@name" /></xsl:variable>
1843 <xsl:variable name="attrtype"><xsl:value-of select="@type" /></xsl:variable>
1844 <xsl:variable name="attrreadonly"><xsl:value-of select="@readonly" /></xsl:variable>
1845 <xsl:variable name="attrsafearray"><xsl:value-of select="@safearray" /></xsl:variable>
1846
1847 <xsl:choose>
1848 <xsl:when test="($G_vboxGlueStyle='jaxws') and ($attrtype=($G_setSuppressedInterfaces/@name))">
1849 <xsl:value-of select="concat(' // skip attribute ',$attrname, ' of suppressed type ', $attrtype, '&#10;&#10;')" />
1850 </xsl:when>
1851
1852 <xsl:otherwise>
1853 <!-- emit getter method -->
1854 <xsl:variable name="gettername">
1855 <xsl:call-template name="makeGetterName">
1856 <xsl:with-param name="attrname" select="$attrname" />
1857 </xsl:call-template>
1858 </xsl:variable>
1859 <xsl:variable name="gluetype">
1860 <xsl:call-template name="typeIdl2Glue">
1861 <xsl:with-param name="type" select="$attrtype" />
1862 <xsl:with-param name="safearray" select="@safearray" />
1863 </xsl:call-template>
1864 </xsl:variable>
1865 <xsl:variable name="backtype">
1866 <xsl:call-template name="typeIdl2Back">
1867 <xsl:with-param name="type" select="$attrtype" />
1868 <xsl:with-param name="safearray" select="@safearray" />
1869 </xsl:call-template>
1870 </xsl:variable>
1871 <xsl:variable name="wrapped">
1872 <xsl:call-template name="cookOutParam">
1873 <xsl:with-param name="value" select="'retVal'" />
1874 <xsl:with-param name="idltype" select="$attrtype" />
1875 <xsl:with-param name="safearray" select="@safearray" />
1876 </xsl:call-template>
1877 </xsl:variable>
1878 <xsl:value-of select="concat(' public ', $gluetype, ' ', $gettername, '() {&#10;')" />
1879
1880 <xsl:call-template name="startExcWrapper"/>
1881
1882 <!-- Actual getter implementation -->
1883 <xsl:call-template name="genGetterCall">
1884 <xsl:with-param name="ifname" select="$ifname" />
1885 <xsl:with-param name="gettername" select="$gettername" />
1886 <xsl:with-param name="backtype" select="$backtype" />
1887 <xsl:with-param name="retval" select="'retVal'" />
1888 </xsl:call-template>
1889
1890 <xsl:value-of select="concat(' return ', $wrapped, ';&#10;')" />
1891 <xsl:call-template name="endExcWrapper"/>
1892
1893 <xsl:value-of select= "' }&#10;'" />
1894 <xsl:if test="not(@readonly='yes')">
1895 <!-- emit setter method -->
1896 <xsl:variable name="settername"><xsl:call-template name="makeSetterName"><xsl:with-param name="attrname" select="$attrname" /></xsl:call-template></xsl:variable>
1897 <xsl:variable name="unwrapped">
1898 <xsl:call-template name="cookInParam">
1899 <xsl:with-param name="ifname" select="$ifname" />
1900 <xsl:with-param name="value" select="'value'" />
1901 <xsl:with-param name="idltype" select="$attrtype" />
1902 <xsl:with-param name="safearray" select="@safearray" />
1903 </xsl:call-template>
1904 </xsl:variable>
1905 <xsl:value-of select="concat(' public void ', $settername, '(', $gluetype, ' value) {&#10;')" />
1906 <xsl:call-template name="startExcWrapper"/>
1907 <!-- Actual setter implementation -->
1908 <xsl:call-template name="genSetterCall">
1909 <xsl:with-param name="ifname" select="$ifname" />
1910 <xsl:with-param name="settername" select="$settername" />
1911 <xsl:with-param name="value" select="$unwrapped" />
1912 </xsl:call-template>
1913 <xsl:call-template name="endExcWrapper"/>
1914 <xsl:value-of select= "' }&#10;'" />
1915 </xsl:if>
1916
1917 </xsl:otherwise>
1918 </xsl:choose>
1919
1920 </xsl:for-each>
1921
1922 <!-- emit queryInterface() *to* this class -->
1923 <xsl:call-template name="genQI">
1924 <xsl:with-param name="ifname" select="$ifname" />
1925 <xsl:with-param name="uuid" select="@uuid" />
1926 </xsl:call-template>
1927
1928 <!-- emit methods -->
1929 <xsl:for-each select="method">
1930 <xsl:call-template name="genMethod">
1931 <xsl:with-param name="ifname" select="$ifname" />
1932 <xsl:with-param name="methodname" select="@name" />
1933 </xsl:call-template>
1934 </xsl:for-each>
1935
1936</xsl:template>
1937
1938<xsl:template name="genIface">
1939 <xsl:param name="ifname" />
1940 <xsl:param name="filename" />
1941
1942 <xsl:variable name="wsmap" select="@wsmap" />
1943
1944 <xsl:call-template name="startFile">
1945 <xsl:with-param name="file" select="$filename" />
1946 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
1947 </xsl:call-template>
1948
1949 <xsl:text>import java.util.List;&#10;</xsl:text>
1950
1951 <xsl:choose>
1952 <xsl:when test="($wsmap='struct') and ($G_vboxGlueStyle='jaxws')">
1953 <xsl:value-of select="concat('public class ', $ifname, ' {&#10;&#10;')" />
1954 <xsl:call-template name="genStructWrapperJaxws">
1955 <xsl:with-param name="ifname" select="$ifname" />
1956 </xsl:call-template>
1957 </xsl:when>
1958
1959 <xsl:otherwise>
1960 <xsl:variable name="extends" select="//interface[@name=$ifname]/@extends" />
1961 <xsl:choose>
1962 <xsl:when test="($extends = '$unknown') or ($extends = '$dispatched') or ($extends = '$errorinfo')">
1963 <xsl:value-of select="concat('public class ', $ifname, ' extends IUnknown {&#10;&#10;')" />
1964 </xsl:when>
1965 <xsl:when test="//interface[@name=$extends]">
1966 <xsl:value-of select="concat('public class ', $ifname, ' extends ', $extends, ' {&#10;&#10;')" />
1967 </xsl:when>
1968 <xsl:otherwise>
1969 <xsl:call-template name="fatalError">
1970 <xsl:with-param name="msg" select="concat('Interface generation: interface &quot;', $ifname, '&quot; has invalid &quot;extends&quot; value ', $extends, '.')" />
1971 </xsl:call-template>
1972 </xsl:otherwise>
1973 </xsl:choose>
1974 <xsl:call-template name="genIfaceWrapper">
1975 <xsl:with-param name="ifname" select="$ifname" />
1976 </xsl:call-template>
1977 </xsl:otherwise>
1978 </xsl:choose>
1979
1980 <!-- end of class -->
1981 <xsl:value-of select="'}&#10;'" />
1982
1983 <xsl:call-template name="endFile">
1984 <xsl:with-param name="file" select="$filename" />
1985 </xsl:call-template>
1986
1987</xsl:template>
1988
1989<xsl:template name="genCb">
1990 <xsl:param name="ifname" />
1991 <xsl:param name="filename" />
1992 <xsl:param name="filenameimpl" />
1993
1994 <xsl:call-template name="startFile">
1995 <xsl:with-param name="file" select="$filename" />
1996 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
1997 </xsl:call-template>
1998
1999 <xsl:text>import java.util.List;&#10;</xsl:text>
2000
2001 <xsl:value-of select="concat('public interface ', $ifname, ' {&#10;')" />
2002
2003 <!-- emit methods declarations-->
2004 <xsl:for-each select="method">
2005 <xsl:call-template name="genCbMethodDecl">
2006 <xsl:with-param name="ifname" select="$ifname" />
2007 <xsl:with-param name="methodname" select="@name" />
2008 </xsl:call-template>
2009 </xsl:for-each>
2010
2011 <xsl:value-of select="'}&#10;&#10;'" />
2012
2013 <xsl:call-template name="endFile">
2014 <xsl:with-param name="file" select="$filename" />
2015 </xsl:call-template>
2016
2017 <xsl:call-template name="startFile">
2018 <xsl:with-param name="file" select="$filenameimpl" />
2019 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
2020 </xsl:call-template>
2021
2022 <xsl:text>import java.util.List;&#10;</xsl:text>
2023
2024 <xsl:variable name="backtype">
2025 <xsl:call-template name="typeIdl2Back">
2026 <xsl:with-param name="type" select="$ifname" />
2027 </xsl:call-template>
2028 </xsl:variable>
2029
2030 <!-- emit glue methods body -->
2031 <xsl:choose>
2032 <xsl:when test="$G_vboxGlueStyle='xpcom'">
2033 <xsl:value-of select="concat('class ', $ifname, 'Impl extends nsISupportsBase implements ', $backtype, ' {&#10;')" />
2034 </xsl:when>
2035
2036 <xsl:when test="$G_vboxGlueStyle='mscom'">
2037 <xsl:value-of select="concat('public class ', $ifname, 'Impl {&#10;')" />
2038 </xsl:when>
2039 </xsl:choose>
2040
2041 <xsl:value-of select="concat(' ', $ifname, ' sink;&#10;')" />
2042
2043 <xsl:value-of select="concat(' ', $ifname, 'Impl(', $ifname,' sink) {&#10;')" />
2044 <xsl:value-of select="' this.sink = sink;&#10;'" />
2045 <xsl:value-of select="' }&#10;'" />
2046
2047 <!-- emit methods implementations -->
2048 <xsl:for-each select="method">
2049 <xsl:call-template name="genCbMethodImpl">
2050 <xsl:with-param name="ifname" select="$ifname" />
2051 <xsl:with-param name="methodname" select="@name" />
2052 </xsl:call-template>
2053 </xsl:for-each>
2054
2055 <xsl:value-of select="'}&#10;&#10;'" />
2056
2057 <xsl:call-template name="endFile">
2058 <xsl:with-param name="file" select="$filenameimpl" />
2059 </xsl:call-template>
2060</xsl:template>
2061
2062<xsl:template name="emitHandwritten">
2063
2064 <xsl:call-template name="startFile">
2065 <xsl:with-param name="file" select="'Holder.java'" />
2066 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
2067 </xsl:call-template>
2068
2069 <xsl:text><![CDATA[
2070public class Holder<T>
2071{
2072 public T value;
2073
2074 public Holder()
2075 {
2076 }
2077 public Holder(T value)
2078 {
2079 this.value = value;
2080 }
2081}
2082]]></xsl:text>
2083
2084 <xsl:call-template name="endFile">
2085 <xsl:with-param name="file" select="'Holder.java'" />
2086 </xsl:call-template>
2087
2088<xsl:call-template name="startFile">
2089 <xsl:with-param name="file" select="'Holder.java'" />
2090 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
2091 </xsl:call-template>
2092
2093 <xsl:text><![CDATA[
2094public class Holder<T>
2095{
2096 public T value;
2097
2098 public Holder()
2099 {
2100 }
2101 public Holder(T value)
2102 {
2103 this.value = value;
2104 }
2105}
2106]]></xsl:text>
2107
2108 <xsl:call-template name="endFile">
2109 <xsl:with-param name="file" select="'Holder.java'" />
2110 </xsl:call-template>
2111
2112<xsl:call-template name="startFile">
2113 <xsl:with-param name="file" select="'VBoxException.java'" />
2114 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
2115 </xsl:call-template>
2116
2117 <xsl:text><![CDATA[
2118public class VBoxException extends RuntimeException
2119{
2120 private Throwable wrapped;
2121 private String msg;
2122
2123 public VBoxException(Throwable wrapped, String msg)
2124 {
2125 this.wrapped = wrapped;
2126 this.msg = msg;
2127 }
2128 public Throwable getWrapped()
2129 {
2130 return wrapped;
2131 }
2132 public String getMessage()
2133 {
2134 return msg;
2135 }
2136}
2137]]></xsl:text>
2138
2139 <xsl:call-template name="endFile">
2140 <xsl:with-param name="file" select="'VBoxException.java'" />
2141 </xsl:call-template>
2142
2143
2144</xsl:template>
2145
2146<xsl:template name="emitHandwrittenXpcom">
2147
2148<xsl:call-template name="startFile">
2149 <xsl:with-param name="file" select="'IUnknown.java'" />
2150 <xsl:with-param name="package" select="$G_virtualBoxPackageCom" />
2151 </xsl:call-template>
2152
2153 <xsl:text><![CDATA[
2154public class IUnknown
2155{
2156 private Object obj;
2157 public IUnknown(Object obj)
2158 {
2159 this.obj = obj;
2160 }
2161
2162 public Object getWrapped()
2163 {
2164 return this.obj;
2165 }
2166
2167 public void setWrapped(Object obj)
2168 {
2169 this.obj = obj;
2170 }
2171}
2172]]></xsl:text>
2173
2174 <xsl:call-template name="endFile">
2175 <xsl:with-param name="file" select="'IUnknown.java'" />
2176 </xsl:call-template>
2177
2178 <xsl:call-template name="startFile">
2179 <xsl:with-param name="file" select="'Helper.java'" />
2180 <xsl:with-param name="package" select="$G_virtualBoxPackageCom" />
2181 </xsl:call-template>
2182
2183<xsl:text><![CDATA[
2184
2185import java.util.List;
2186import java.util.ArrayList;
2187import java.util.Collections;
2188import java.lang.reflect.Array;
2189import java.lang.reflect.Constructor;
2190import java.lang.reflect.InvocationTargetException;
2191
2192public class Helper {
2193 public static List<Short> wrap(byte[] vals) {
2194 if (vals==null)
2195 return null;
2196
2197 List<Short> ret = new ArrayList<Short>(vals.length);
2198 for (short v : vals) {
2199 ret.add(v);
2200 }
2201 return ret;
2202 }
2203
2204 public static List<Integer> wrap(int[] vals) {
2205 if (vals==null)
2206 return null;
2207
2208 List<Integer> ret = new ArrayList<Integer>(vals.length);
2209 for (int v : vals) {
2210 ret.add(v);
2211 }
2212 return ret;
2213 }
2214
2215 public static List<Long> wrap(long[] vals) {
2216 if (vals==null)
2217 return null;
2218
2219 List<Long> ret = new ArrayList<Long>(vals.length);
2220 for (long v : vals) {
2221 ret.add(v);
2222 }
2223 return ret;
2224 }
2225
2226 public static List<String> wrap(String[] vals) {
2227 if (vals==null)
2228 return null;
2229 List<String> ret = new ArrayList<String>(vals.length);
2230 for (String v : vals) {
2231 ret.add(v);
2232 }
2233 return ret;
2234 }
2235
2236 public static <T> List<T> wrap(Class<T> wrapperClass, T[] thisPtrs) {
2237 if (thisPtrs==null)
2238 return null;
2239
2240 List<T> ret = new ArrayList<T>(thisPtrs.length);
2241 for (T thisPtr : thisPtrs) {
2242 ret.add(thisPtr);
2243 }
2244 return ret;
2245 }
2246
2247 public static <T> List<T> wrapEnum(Class<T> wrapperClass, long values[]) {
2248 try {
2249 if (values==null)
2250 return null;
2251 Constructor<T> c = wrapperClass.getConstructor(int.class);
2252 List<T> ret = new ArrayList<T>(values.length);
2253 for (long v : values) {
2254 ret.add(c.newInstance(v));
2255 }
2256 return ret;
2257 } catch (NoSuchMethodException e) {
2258 throw new AssertionError(e);
2259 } catch (InstantiationException e) {
2260 throw new AssertionError(e);
2261 } catch (IllegalAccessException e) {
2262 throw new AssertionError(e);
2263 } catch (InvocationTargetException e) {
2264 throw new AssertionError(e);
2265 }
2266 }
2267
2268 public static short[] unwrap(List<Short> vals) {
2269 if (vals==null)
2270 return null;
2271
2272 short[] ret = new short[vals.size()];
2273 int i = 0;
2274 for (short l : vals) {
2275 ret[i++] = l;
2276 }
2277 return ret;
2278 }
2279
2280 public static int[] unwrap(List<Integer> vals) {
2281 if (vals == null)
2282 return null;
2283
2284 int[] ret = new int[vals.size()];
2285 int i = 0;
2286 for (int l : vals) {
2287 ret[i++] = l;
2288 }
2289 return ret;
2290 }
2291
2292 public static long[] unwrap(List<Long> vals) {
2293 if (vals == null)
2294 return null;
2295
2296 long[] ret = new long[vals.size()];
2297 int i = 0;
2298 for (long l : vals) {
2299 ret[i++] = l;
2300 }
2301 return ret;
2302 }
2303
2304 public static boolean[] unwrap(List<Boolean> vals) {
2305 if (vals==null)
2306 return null;
2307
2308 boolean[] ret = new boolean[vals.size()];
2309 int i = 0;
2310 for (boolean l : vals) {
2311 ret[i++] = l;
2312 }
2313 return ret;
2314 }
2315
2316 public static String[] unwrap(List<String> vals) {
2317 if (vals==null)
2318 return null;
2319
2320 String[] ret = new String[vals.size()];
2321 int i = 0;
2322 for (String l : vals) {
2323 ret[i++] = l;
2324 }
2325 return ret;
2326 }
2327
2328 public static <T extends Enum <T>> long[] unwrapEnum(Class<T> enumClass, List<T> values) {
2329 if (values == null) return null;
2330
2331 long result[] = new long[values.size()];
2332 try {
2333 java.lang.reflect.Method valueM = enumClass.getMethod("value");
2334 int i = 0;
2335 for (T v : values) {
2336 result[i++] = (Integer)valueM.invoke(v);
2337 }
2338 return result;
2339 } catch (NoSuchMethodException e) {
2340 throw new AssertionError(e);
2341 } catch(SecurityException e) {
2342 throw new AssertionError(e);
2343 } catch (IllegalAccessException e) {
2344 throw new AssertionError(e);
2345 } catch (IllegalArgumentException e) {
2346 throw new AssertionError(e);
2347 } catch (InvocationTargetException e) {
2348 throw new AssertionError(e);
2349 }
2350 }
2351
2352 public static <T1, T2> List<T1> wrap2(Class<T1> wrapperClass1, Class<T2> wrapperClass2, T2[] thisPtrs) {
2353 try {
2354 if (thisPtrs==null)
2355 return null;
2356
2357 Constructor<T1> c = wrapperClass1.getConstructor(wrapperClass2);
2358 List<T1> ret = new ArrayList<T1>(thisPtrs.length);
2359 for (T2 thisPtr : thisPtrs) {
2360 ret.add(c.newInstance(thisPtr));
2361 }
2362 return ret;
2363 } catch (NoSuchMethodException e) {
2364 throw new AssertionError(e);
2365 } catch (InstantiationException e) {
2366 throw new AssertionError(e);
2367 } catch (IllegalAccessException e) {
2368 throw new AssertionError(e);
2369 } catch (InvocationTargetException e) {
2370 throw new AssertionError(e);
2371 }
2372 }
2373
2374 @SuppressWarnings( "unchecked")
2375 public static <T> T[] unwrap(Class<T> wrapperClass, List<T> thisPtrs) {
2376 if (thisPtrs==null)
2377 return null;
2378 if (thisPtrs.size() == 0)
2379 return null;
2380 return (T[])thisPtrs.toArray((T[])Array.newInstance(wrapperClass, thisPtrs.size()));
2381 }
2382
2383 @SuppressWarnings( "unchecked" )
2384 public static <T> T queryInterface(Object obj, String uuid, Class<T> iface)
2385 {
2386 return (T)queryInterface(obj, uuid);
2387 }
2388
2389 public static Object queryInterface(Object obj, String uuid)
2390 {
2391 try {
2392 /* Kind of ugly, but does the job of casting */
2393 org.mozilla.xpcom.Mozilla moz = org.mozilla.xpcom.Mozilla.getInstance();
2394 long xpobj = moz.wrapJavaObject(obj, uuid);
2395 return moz.wrapXPCOMObject(xpobj, uuid);
2396 } catch (Exception e) {
2397 return null;
2398 }
2399 }
2400
2401 @SuppressWarnings("unchecked")
2402 public static <T1 extends IUnknown,T2> T2[] unwrap2(Class<T1> wrapperClass1, Class<T2> wrapperClass2, List<T1> thisPtrs) {
2403 if (thisPtrs==null) return null;
2404
2405 T2 ret[] = (T2[])Array.newInstance(wrapperClass2, thisPtrs.size());
2406 int i = 0;
2407 for (T1 obj : thisPtrs) {
2408 ret[i++] = (T2)obj.getWrapped();
2409 }
2410 return ret;
2411 }
2412}
2413]]></xsl:text>
2414
2415 <xsl:call-template name="endFile">
2416 <xsl:with-param name="file" select="'Helper.java'" />
2417 </xsl:call-template>
2418
2419 <xsl:call-template name="startFile">
2420 <xsl:with-param name="file" select="'VirtualBoxManager.java'" />
2421 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
2422 </xsl:call-template>
2423
2424 <xsl:text><![CDATA[
2425
2426import java.io.File;
2427
2428import org.mozilla.xpcom.*;
2429import org.mozilla.interfaces.*;
2430
2431public class VirtualBoxManager
2432{
2433 private Mozilla mozilla;
2434 private IVirtualBox vbox;
2435 private nsIComponentManager componentManager;
2436 private nsIServiceManager servMgr;
2437
2438 private VirtualBoxManager(Mozilla mozilla, nsIServiceManager servMgr)
2439 {
2440 this.mozilla = mozilla;
2441 this.servMgr = servMgr;
2442 this.componentManager = mozilla.getComponentManager();
2443 this.vbox = new IVirtualBox((org.mozilla.interfaces.IVirtualBox) this.componentManager
2444 .createInstanceByContractID("@virtualbox.org/VirtualBox;1",
2445 null,
2446 org.mozilla.interfaces.IVirtualBox.IVIRTUALBOX_IID));
2447 }
2448
2449 public void connect(String url, String username, String passwd)
2450 {
2451 throw new RuntimeException("Connect doesn't make sense for local bindings");
2452 }
2453
2454 public void disconnect()
2455 {
2456 throw new RuntimeException("Disconnect doesn't make sense for local bindings");
2457 }
2458
2459 public static void initPerThread()
2460 {
2461 }
2462
2463 public static void deinitPerThread()
2464 {
2465 }
2466
2467 public IVirtualBox getVBox()
2468 {
2469 return this.vbox;
2470 }
2471
2472 public ISession getSessionObject()
2473 {
2474 return new ISession((org.mozilla.interfaces.ISession) componentManager
2475 .createInstanceByContractID("@virtualbox.org/Session;1", null,
2476 org.mozilla.interfaces.ISession.ISESSION_IID));
2477 }
2478
2479 public ISession openMachineSession(IMachine m) throws Exception
2480 {
2481 ISession s = getSessionObject();
2482 m.lockMachine(s, LockType.Shared);
2483 return s;
2484 }
2485
2486 public void closeMachineSession(ISession s)
2487 {
2488 if (s != null)
2489 s.unlockMachine();
2490 }
2491
2492 private static boolean hasInstance = false;
2493
2494 public static synchronized VirtualBoxManager createInstance(String home)
2495 {
2496 if (hasInstance)
2497 throw new VBoxException(null, "only one instance at the time allowed");
2498
2499 if (home == null)
2500 home = System.getProperty("vbox.home");
2501
2502 File grePath = new File(home);
2503 Mozilla mozilla = Mozilla.getInstance();
2504 mozilla.initialize(grePath);
2505 nsIServiceManager servMgr = null;
2506 try {
2507 servMgr = mozilla.initXPCOM(grePath, null);
2508 } catch (Exception e) {
2509 e.printStackTrace();
2510 return null;
2511 }
2512
2513 hasInstance = true;
2514
2515 return new VirtualBoxManager(mozilla, servMgr);
2516 }
2517
2518 public IEventListener createListener(Object sink)
2519 {
2520 return new IEventListener(new EventListenerImpl(sink));
2521 }
2522 public void cleanup()
2523 {
2524 deinitPerThread();
2525 // cleanup
2526 mozilla.shutdownXPCOM(servMgr);
2527 mozilla = null;
2528 hasInstance = false;
2529 }
2530
2531 public boolean progressBar(IProgress p, int wait)
2532 {
2533 long end = System.currentTimeMillis() + wait;
2534 while (!p.getCompleted())
2535 {
2536 mozilla.waitForEvents(0);
2537 p.waitForCompletion(wait);
2538 if (System.currentTimeMillis() >= end)
2539 return false;
2540 }
2541
2542 return true;
2543 }
2544
2545 public boolean startVm(String name, String type, int timeout)
2546 {
2547 IMachine m = vbox.findMachine(name);
2548 if (m == null)
2549 return false;
2550 ISession session = getSessionObject();
2551
2552 if (type == null)
2553 type = "gui";
2554 IProgress p = m.launchVMProcess(session, type, "");
2555 progressBar(p, timeout);
2556 session.unlockMachine();
2557 return true;
2558 }
2559
2560 public void waitForEvents(long tmo)
2561 {
2562 mozilla.waitForEvents(tmo);
2563 }
2564}
2565]]></xsl:text>
2566
2567 <xsl:call-template name="endFile">
2568 <xsl:with-param name="file" select="'VirtualBoxManager.java'" />
2569 </xsl:call-template>
2570
2571 <xsl:call-template name="startFile">
2572 <xsl:with-param name="file" select="'EventListenerImpl.java'" />
2573 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
2574 </xsl:call-template>
2575
2576 <xsl:text><![CDATA[
2577 import org.mozilla.interfaces.*;
2578
2579 public class EventListenerImpl extends nsISupportsBase implements org.mozilla.interfaces.IEventListener
2580 {
2581 private Object obj;
2582 private java.lang.reflect.Method handleEvent;
2583 EventListenerImpl(Object obj)
2584 {
2585 this.obj = obj;
2586 try {
2587 this.handleEvent = obj.getClass().getMethod("handleEvent", IEvent.class);
2588 } catch (Exception e) {
2589 e.printStackTrace();
2590 }
2591 }
2592 public void handleEvent(org.mozilla.interfaces.IEvent ev)
2593 {
2594 try {
2595 if (obj != null && handleEvent != null)
2596 handleEvent.invoke(obj, ev != null ? new IEvent(ev) : null);
2597 } catch (Exception e) {
2598 e.printStackTrace();
2599 }
2600 }
2601 }]]></xsl:text>
2602
2603 <xsl:call-template name="endFile">
2604 <xsl:with-param name="file" select="'EventListenerImpl.java'" />
2605 </xsl:call-template>
2606
2607 <xsl:call-template name="startFile">
2608 <xsl:with-param name="file" select="'VBoxObjectBase.java'" />
2609 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
2610 </xsl:call-template>
2611
2612<xsl:text><![CDATA[
2613abstract class nsISupportsBase implements org.mozilla.interfaces.nsISupports
2614{
2615 public org.mozilla.interfaces.nsISupports queryInterface(String iid)
2616 {
2617 return org.mozilla.xpcom.Mozilla.queryInterface(this, iid);
2618 }
2619}
2620
2621]]></xsl:text><xsl:call-template name="endFile">
2622 <xsl:with-param name="file" select="'VBoxObjectBase.java'" />
2623 </xsl:call-template>
2624
2625</xsl:template>
2626
2627
2628<xsl:template name="emitHandwrittenMscom">
2629
2630<xsl:call-template name="startFile">
2631 <xsl:with-param name="file" select="'IUnknown.java'" />
2632 <xsl:with-param name="package" select="$G_virtualBoxPackageCom" />
2633 </xsl:call-template>
2634
2635 <xsl:text><![CDATA[
2636public class IUnknown
2637{
2638 private Object obj;
2639 public IUnknown(Object obj)
2640 {
2641 this.obj = obj;
2642 }
2643
2644 public Object getWrapped()
2645 {
2646 return this.obj;
2647 }
2648
2649 public void setWrapped(Object obj)
2650 {
2651 this.obj = obj;
2652 }
2653}
2654]]></xsl:text>
2655
2656 <xsl:call-template name="endFile">
2657 <xsl:with-param name="file" select="'IUnknown.java'" />
2658 </xsl:call-template>
2659
2660<xsl:call-template name="startFile">
2661 <xsl:with-param name="file" select="'Helper.java'" />
2662 <xsl:with-param name="package" select="$G_virtualBoxPackageCom" />
2663 </xsl:call-template>
2664
2665<xsl:text><![CDATA[
2666
2667import java.util.List;
2668import java.util.ArrayList;
2669import java.util.Collections;
2670import java.lang.reflect.Array;
2671import java.lang.reflect.Constructor;
2672import java.lang.reflect.InvocationTargetException;
2673import com.jacob.com.*;
2674
2675public class Helper {
2676 public static List<Short> wrap(short[] vals) {
2677 if (vals==null) return null;
2678 if (vals.length == 0) return Collections.emptyList();
2679
2680 List<Short> ret = new ArrayList<Short>(vals.length);
2681 for (short v : vals) {
2682 ret.add(v);
2683 }
2684 return ret;
2685 }
2686
2687 public static List<Integer> wrap(int[] vals) {
2688 if (vals == null) return null;
2689 if (vals.length == 0) return Collections.emptyList();
2690
2691 List<Integer> ret = new ArrayList<Integer>(vals.length);
2692 for (int v : vals) {
2693 ret.add(v);
2694 }
2695 return ret;
2696 }
2697
2698 public static List<Long> wrap(long[] vals) {
2699 if (vals==null) return null;
2700 if (vals.length == 0) return Collections.emptyList();
2701
2702 List<Long> ret = new ArrayList<Long>(vals.length);
2703 for (long v : vals) {
2704 ret.add(v);
2705 }
2706 return ret;
2707 }
2708
2709 public static List<String> wrap(String[] vals) {
2710 if (vals==null) return null;
2711 if (vals.length == 0) return Collections.emptyList();
2712
2713 List<String> ret = new ArrayList<String>(vals.length);
2714 for (String v : vals) {
2715 ret.add(v);
2716 }
2717 return ret;
2718 }
2719
2720 public static <T> T wrapDispatch(Class<T> wrapperClass, Dispatch d)
2721 {
2722 try {
2723 if (d == null || d.m_pDispatch == 0)
2724 return null;
2725 Constructor<T> c = wrapperClass.getConstructor(Dispatch.class);
2726 return (T)c.newInstance(d);
2727 } catch (NoSuchMethodException e) {
2728 throw new AssertionError(e);
2729 } catch (InstantiationException e) {
2730 throw new AssertionError(e);
2731 } catch (IllegalAccessException e) {
2732 throw new AssertionError(e);
2733 } catch (InvocationTargetException e) {
2734 throw new AssertionError(e);
2735 }
2736 }
2737
2738 @SuppressWarnings("unchecked")
2739 public static <T> Object wrapVariant(Class<T> wrapperClass, Variant v)
2740 {
2741 if (v == null)
2742 return null;
2743
2744 short vt = v.getvt();
2745 switch (vt)
2746 {
2747 case Variant.VariantNull:
2748 return null;
2749 case Variant.VariantBoolean:
2750 return v.getBoolean();
2751 case Variant.VariantByte:
2752 return v.getByte();
2753 case Variant.VariantShort:
2754 return v.getShort();
2755 case Variant.VariantInt:
2756 return v.getInt();
2757 case Variant.VariantLongInt:
2758 return v.getLong();
2759 case Variant.VariantString:
2760 return v.getString();
2761 case Variant.VariantDispatch:
2762 return wrapDispatch(wrapperClass, v.getDispatch());
2763 default:
2764 throw new RuntimeException("unhandled variant type "+vt);
2765 }
2766 }
2767
2768 public static byte[] wrapBytes(SafeArray sa) {
2769 if (sa==null) return null;
2770
2771 int saLen = sa.getUBound() - sa.getLBound() + 1;
2772
2773 byte[] ret = new byte[saLen];
2774 int j = 0;
2775 for (int i = sa.getLBound(); i <= sa.getUBound(); i++)
2776 {
2777 Variant v = sa.getVariant(i);
2778 // come upo with more effective approach!!!
2779 ret[j++] = v.getByte();
2780 }
2781 return ret;
2782 }
2783
2784 @SuppressWarnings("unchecked")
2785 public static <T> List<T> wrap(Class<T> wrapperClass, SafeArray sa) {
2786 if (sa==null) return null;
2787
2788 int saLen = sa.getUBound() - sa.getLBound() + 1;
2789 if (saLen == 0) return Collections.emptyList();
2790
2791 List<T> ret = new ArrayList<T>(saLen);
2792 for (int i = sa.getLBound(); i <= sa.getUBound(); i++)
2793 {
2794 Variant v = sa.getVariant(i);
2795 ret.add((T)wrapVariant(wrapperClass, v));
2796 }
2797 return ret;
2798 }
2799
2800 public static <T> List<T> wrapEnum(Class<T> wrapperClass, SafeArray sa) {
2801 try {
2802 if (sa==null) return null;
2803
2804 int saLen = sa.getUBound() - sa.getLBound() + 1;
2805 if (saLen == 0) return Collections.emptyList();
2806 List<T> ret = new ArrayList<T>(saLen);
2807 Constructor<T> c = wrapperClass.getConstructor(int.class);
2808 for (int i = sa.getLBound(); i <= sa.getUBound(); i++)
2809 {
2810 Variant v = sa.getVariant(i);
2811 ret.add(c.newInstance(v.getInt()));
2812 }
2813 return ret;
2814 } catch (NoSuchMethodException e) {
2815 throw new AssertionError(e);
2816 } catch (InstantiationException e) {
2817 throw new AssertionError(e);
2818 } catch (IllegalAccessException e) {
2819 throw new AssertionError(e);
2820 } catch (InvocationTargetException e) {
2821 throw new AssertionError(e);
2822 }
2823 }
2824
2825 public static SafeArray unwrapInt(List<Integer> vals) {
2826 if (vals==null) return null;
2827 SafeArray ret = new SafeArray(Variant.VariantInt, vals.size());
2828 int i = 0;
2829 for (int l : vals) {
2830 ret.setInt(i++, l);
2831 }
2832 return ret;
2833 }
2834
2835 public static SafeArray unwrapLong(List<Long> vals) {
2836 if (vals==null) return null;
2837 SafeArray ret = new SafeArray(Variant.VariantLongInt, vals.size());
2838 int i = 0;
2839 for (long l : vals) {
2840 ret.setLong(i++, l);
2841 }
2842 return ret;
2843 }
2844
2845 public static SafeArray unwrapBool(List<Boolean> vals) {
2846 if (vals==null) return null;
2847
2848 SafeArray result = new SafeArray(Variant.VariantBoolean, vals.size());
2849 int i = 0;
2850 for (boolean l : vals) {
2851 result.setBoolean(i, l);
2852 }
2853 return result;
2854 }
2855
2856 public static <T extends Enum <T>> SafeArray unwrapEnum(Class<T> enumClass, List<T> values) {
2857 if (values == null) return null;
2858
2859 SafeArray result = new SafeArray(Variant.VariantInt, values.size());
2860 try {
2861 java.lang.reflect.Method valueM = enumClass.getMethod("value");
2862 int i = 0;
2863 for (T v : values) {
2864 result.setInt(i, (Integer)valueM.invoke(v));
2865 }
2866 return result;
2867 } catch (NoSuchMethodException e) {
2868 throw new AssertionError(e);
2869 } catch(SecurityException e) {
2870 throw new AssertionError(e);
2871 } catch (IllegalAccessException e) {
2872 throw new AssertionError(e);
2873 } catch (IllegalArgumentException e) {
2874 throw new AssertionError(e);
2875 } catch (InvocationTargetException e) {
2876 throw new AssertionError(e);
2877 }
2878 }
2879 public static SafeArray unwrapString(List<String> vals) {
2880 if (vals==null)
2881 return null;
2882 SafeArray result = new SafeArray(Variant.VariantString, vals.size());
2883 int i = 0;
2884 for (String l : vals) {
2885 result.setString(i, l);
2886 }
2887 return result;
2888 }
2889
2890 public static <T1, T2> List<T1> wrap2(Class<T1> wrapperClass1, Class<T2> wrapperClass2, T2[] thisPtrs) {
2891 try {
2892 if (thisPtrs==null) return null;
2893 if (thisPtrs.length == 0) return Collections.emptyList();
2894
2895 Constructor<T1> c = wrapperClass1.getConstructor(wrapperClass2);
2896 List<T1> ret = new ArrayList<T1>(thisPtrs.length);
2897 for (T2 thisPtr : thisPtrs) {
2898 ret.add(c.newInstance(thisPtr));
2899 }
2900 return ret;
2901 } catch (NoSuchMethodException e) {
2902 throw new AssertionError(e);
2903 } catch (InstantiationException e) {
2904 throw new AssertionError(e);
2905 } catch (IllegalAccessException e) {
2906 throw new AssertionError(e);
2907 } catch (InvocationTargetException e) {
2908 throw new AssertionError(e);
2909 }
2910 }
2911
2912 @SuppressWarnings("unchecked")
2913 public static <T> T[] unwrap(Class<T> wrapperClass, List<T> thisPtrs) {
2914 if (thisPtrs==null) return null;
2915 return (T[])thisPtrs.toArray((T[])Array.newInstance(wrapperClass, thisPtrs.size()));
2916 }
2917
2918 @SuppressWarnings("unchecked")
2919 public static <T1 extends IUnknown,T2> T2[] unwrap2(Class<T1> wrapperClass1, Class<T2> wrapperClass2, List<T1> thisPtrs) {
2920 if (thisPtrs==null) return null;
2921
2922 T2 ret[] = (T2[])Array.newInstance(wrapperClass2, thisPtrs.size());
2923 int i = 0;
2924 for (T1 obj : thisPtrs) {
2925 ret[i++] = (T2)obj.getWrapped();
2926 }
2927 return ret;
2928 }
2929
2930 /* We have very long invoke lists sometimes */
2931 public static Variant invoke(Dispatch d, String method, Object ... args)
2932 {
2933 return Dispatch.callN(d, method, args);
2934 }
2935}
2936]]></xsl:text>
2937
2938 <xsl:call-template name="endFile">
2939 <xsl:with-param name="file" select="'Helper.java'" />
2940 </xsl:call-template>
2941
2942
2943 <xsl:call-template name="startFile">
2944 <xsl:with-param name="file" select="'VirtualBoxManager.java'" />
2945 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
2946 </xsl:call-template>
2947
2948 <xsl:text><![CDATA[
2949
2950import com.jacob.activeX.ActiveXComponent;
2951import com.jacob.com.ComThread;
2952import com.jacob.com.Dispatch;
2953import com.jacob.com.Variant;
2954import com.jacob.com.SafeArray;
2955import com.jacob.com.DispatchEvents;
2956
2957public class VirtualBoxManager
2958{
2959 private IVirtualBox vbox;
2960
2961 private VirtualBoxManager()
2962 {
2963 initPerThread();
2964 vbox = new IVirtualBox(new ActiveXComponent("VirtualBox.VirtualBox"));
2965 }
2966
2967 public static void initPerThread()
2968 {
2969 ComThread.InitMTA();
2970 }
2971
2972 public static void deinitPerThread()
2973 {
2974 ComThread.Release();
2975 }
2976
2977 public void connect(String url, String username, String passwd)
2978 {
2979 throw new RuntimeException("Connect doesn't make sense for local bindings");
2980 }
2981
2982 public void disconnect()
2983 {
2984 throw new RuntimeException("Disconnect doesn't make sense for local bindings");
2985 }
2986
2987 public IVirtualBox getVBox()
2988 {
2989 return this.vbox;
2990 }
2991
2992 public ISession getSessionObject()
2993 {
2994 return new ISession(new ActiveXComponent("VirtualBox.Session"));
2995 }
2996
2997 public ISession openMachineSession(IMachine m)
2998 {
2999 ISession s = getSessionObject();
3000 m.lockMachine(s, LockType.Shared);
3001 return s;
3002 }
3003
3004 public void closeMachineSession(ISession s)
3005 {
3006 if (s != null)
3007 s.unlockMachine();
3008 }
3009
3010 private static boolean hasInstance = false;
3011
3012 public static synchronized VirtualBoxManager createInstance(String home)
3013 {
3014 if (hasInstance)
3015 throw new VBoxException(null, "only one instance at the time allowed");
3016
3017 hasInstance = true;
3018 return new VirtualBoxManager();
3019 }
3020
3021 public void cleanup()
3022 {
3023 deinitPerThread();
3024 hasInstance = false;
3025 }
3026
3027 public boolean progressBar(IProgress p, int wait)
3028 {
3029 long end = System.currentTimeMillis() + wait;
3030 while (!p.getCompleted())
3031 {
3032 p.waitForCompletion(wait);
3033 if (System.currentTimeMillis() >= end)
3034 return false;
3035 }
3036
3037 return true;
3038 }
3039
3040 public boolean startVm(String name, String type, int timeout)
3041 {
3042 IMachine m = vbox.findMachine(name);
3043 if (m == null)
3044 return false;
3045 ISession session = getSessionObject();
3046 if (type == null)
3047 type = "gui";
3048 IProgress p = m.launchVMProcess(session, type, "");
3049 progressBar(p, timeout);
3050 session.unlockMachine();
3051 return true;
3052 }
3053
3054 public void waitForEvents(long tmo)
3055 {
3056 // what to do here?
3057 try {
3058 Thread.sleep(tmo);
3059 } catch (InterruptedException ie) {
3060 }
3061 }
3062}
3063]]></xsl:text>
3064
3065 <xsl:call-template name="endFile">
3066 <xsl:with-param name="file" select="'VirtualBoxManager.java'" />
3067 </xsl:call-template>
3068
3069</xsl:template>
3070
3071<xsl:template name="emitHandwrittenJaxws">
3072
3073 <xsl:call-template name="startFile">
3074 <xsl:with-param name="file" select="'IUnknown.java'" />
3075 <xsl:with-param name="package" select="$G_virtualBoxPackageCom" />
3076 </xsl:call-template>
3077
3078 <xsl:text><![CDATA[
3079public class IUnknown
3080{
3081 protected String obj;
3082 protected final VboxPortType port;
3083
3084 public IUnknown(String obj, VboxPortType port)
3085 {
3086 this.obj = obj;
3087 this.port = port;
3088 }
3089
3090 public final String getWrapped()
3091 {
3092 return this.obj;
3093 }
3094
3095 public final VboxPortType getRemoteWSPort()
3096 {
3097 return this.port;
3098 }
3099
3100 public synchronized void releaseRemote() throws WebServiceException
3101 {
3102 if (obj == null) {
3103 return;
3104 }
3105 try {
3106 this.port.iManagedObjectRefRelease(obj);
3107 this.obj = null;
3108 } catch (InvalidObjectFaultMsg e) {
3109 throw new WebServiceException(e);
3110 } catch (RuntimeFaultMsg e) {
3111 throw new WebServiceException(e);
3112 }
3113 }
3114}
3115]]></xsl:text>
3116
3117 <xsl:call-template name="endFile">
3118 <xsl:with-param name="file" select="'IUnknown.java'" />
3119 </xsl:call-template>
3120
3121 <xsl:call-template name="startFile">
3122 <xsl:with-param name="file" select="'Helper.java'" />
3123 <xsl:with-param name="package" select="$G_virtualBoxPackageCom" />
3124 </xsl:call-template>
3125
3126<xsl:text><![CDATA[
3127
3128import java.util.List;
3129import java.util.ArrayList;
3130import java.util.Collections;
3131import java.lang.reflect.Array;
3132import java.lang.reflect.Constructor;
3133import java.lang.reflect.InvocationTargetException;
3134import java.math.BigInteger;
3135
3136public class Helper {
3137 public static <T> List<T> wrap(Class<T> wrapperClass, VboxPortType pt, List<String> thisPtrs) {
3138 try {
3139 if(thisPtrs==null) return null;
3140
3141 Constructor<T> c = wrapperClass.getConstructor(String.class, VboxPortType.class);
3142 List<T> ret = new ArrayList<T>(thisPtrs.size());
3143 for (String thisPtr : thisPtrs) {
3144 ret.add(c.newInstance(thisPtr,pt));
3145 }
3146 return ret;
3147 } catch (NoSuchMethodException e) {
3148 throw new AssertionError(e);
3149 } catch (InstantiationException e) {
3150 throw new AssertionError(e);
3151 } catch (IllegalAccessException e) {
3152 throw new AssertionError(e);
3153 } catch (InvocationTargetException e) {
3154 throw new AssertionError(e);
3155 }
3156 }
3157
3158 public static <T1, T2> List<T1> wrap2(Class<T1> wrapperClass1, Class<T2> wrapperClass2, VboxPortType pt, List<T2> thisPtrs) {
3159 try {
3160 if(thisPtrs==null) return null;
3161
3162 Constructor<T1> c = wrapperClass1.getConstructor(wrapperClass2, VboxPortType.class);
3163 List<T1> ret = new ArrayList<T1>(thisPtrs.size());
3164 for (T2 thisPtr : thisPtrs) {
3165 ret.add(c.newInstance(thisPtr,pt));
3166 }
3167 return ret;
3168 } catch (NoSuchMethodException e) {
3169 throw new AssertionError(e);
3170 } catch (InstantiationException e) {
3171 throw new AssertionError(e);
3172 } catch (IllegalAccessException e) {
3173 throw new AssertionError(e);
3174 } catch (InvocationTargetException e) {
3175 throw new AssertionError(e);
3176 }
3177 }
3178
3179 public static <T extends IUnknown> List<String> unwrap(List<T> thisPtrs) {
3180 if (thisPtrs==null) return null;
3181
3182 List<String> ret = new ArrayList<String>(thisPtrs.size());
3183 for (T obj : thisPtrs) {
3184 ret.add(obj.getWrapped());
3185 }
3186 return ret;
3187 }
3188
3189 @SuppressWarnings("unchecked" )
3190 public static <T1 extends Enum <T1>, T2 extends Enum <T2>> List<T2> convertEnums(Class<T1> fromClass,
3191 Class<T2> toClass,
3192 List<T1> values) {
3193 try {
3194 if (values==null)
3195 return null;
3196 java.lang.reflect.Method fromValue = toClass.getMethod("fromValue", String.class);
3197 List<T2> ret = new ArrayList<T2>(values.size());
3198 for (T1 v : values) {
3199 // static method is called with null this
3200 ret.add((T2)fromValue.invoke(null, v.name()));
3201 }
3202 return ret;
3203 } catch (NoSuchMethodException e) {
3204 throw new AssertionError(e);
3205 } catch (IllegalAccessException e) {
3206 throw new AssertionError(e);
3207 } catch (InvocationTargetException e) {
3208 throw new AssertionError(e);
3209 }
3210 }
3211 // temporary method, will bo away soon
3212 public static byte[] wrapBytes(List<Short> arr)
3213 {
3214 if (arr == null)
3215 return null;
3216 int i = 0;
3217 byte[] rv = new byte[arr.size()];
3218 for (short s : arr)
3219 rv[i++] = (byte)(s & 0xff);
3220 return rv;
3221 }
3222}
3223]]></xsl:text>
3224
3225 <xsl:call-template name="endFile">
3226 <xsl:with-param name="file" select="'Helper.java'" />
3227 </xsl:call-template>
3228
3229 <xsl:call-template name="startFile">
3230 <xsl:with-param name="file" select="'VirtualBoxManager.java'" />
3231 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
3232 </xsl:call-template>
3233
3234import java.net.URL;
3235import java.math.BigInteger;
3236import java.util.List;
3237import java.util.Map;
3238import java.util.HashMap;
3239import javax.xml.namespace.QName;
3240import javax.xml.ws.BindingProvider;
3241import javax.xml.ws.Holder;
3242import javax.xml.ws.WebServiceException;
3243
3244class PortPool
3245{
3246 private final static String wsdlFile = <xsl:value-of select="$G_virtualBoxWsdl" />;
3247
3248 <xsl:text><![CDATA[
3249private Map<VboxPortType, Integer> known;
3250 private boolean initStarted;
3251 private VboxService svc;
3252
3253 PortPool(boolean usePreinit)
3254 {
3255 known = new HashMap<VboxPortType, Integer>();
3256
3257 if (usePreinit)
3258 {
3259 new Thread(new Runnable()
3260 {
3261 public void run()
3262 {
3263 // need to sync on something else but 'this'
3264 synchronized (known)
3265 {
3266 initStarted = true;
3267 known.notify();
3268 }
3269
3270 preinit();
3271 }
3272 }).start();
3273
3274 synchronized (known)
3275 {
3276 while (!initStarted)
3277 {
3278 try {
3279 known.wait();
3280 } catch (InterruptedException e) {
3281 break;
3282 }
3283 }
3284 }
3285 }
3286 }
3287
3288 private synchronized void preinit()
3289 {
3290 VboxPortType port = getPort();
3291 releasePort(port);
3292 }
3293
3294 synchronized VboxPortType getPort()
3295 {
3296 VboxPortType port = null;
3297 int ttl = 0;
3298
3299 for (VboxPortType cur: known.keySet())
3300 {
3301 int value = known.get(cur);
3302 if ((value & 0x10000) == 0)
3303 {
3304 port = cur;
3305 ttl = value & 0xffff;
3306 break;
3307 }
3308 }
3309
3310 if (port == null)
3311 {
3312 if (svc == null) {
3313 URL wsdl = PortPool.class.getClassLoader().getResource(wsdlFile);
3314 if (wsdl == null)
3315 throw new LinkageError(wsdlFile+" not found, but it should have been in the jar");
3316 svc = new VboxService(wsdl,
3317 new QName("http://www.virtualbox.org/Service",
3318 "vboxService"));
3319 }
3320 port = svc.getVboxServicePort();
3321 // reuse this object 0x10 times
3322 ttl = 0x10;
3323 }
3324 // mark as used
3325 known.put(port, new Integer(0x10000 | ttl));
3326 return port;
3327 }
3328
3329 synchronized void releasePort(VboxPortType port)
3330 {
3331 Integer val = known.get(port);
3332 if (val == null || val == 0)
3333 {
3334 // know you not
3335 return;
3336 }
3337
3338 int v = val;
3339 int ttl = v & 0xffff;
3340 // decrement TTL, and throw away port if used too much times
3341 if (--ttl <= 0)
3342 {
3343 known.remove(port);
3344 }
3345 else
3346 {
3347 v = ttl; // set new TTL and clear busy bit
3348 known.put(port, v);
3349 }
3350 }
3351}
3352
3353
3354public class VirtualBoxManager
3355{
3356 private static PortPool pool = new PortPool(true);
3357 protected VboxPortType port;
3358
3359 private IVirtualBox vbox;
3360
3361 private VirtualBoxManager()
3362 {
3363 }
3364
3365 public static void initPerThread()
3366 {
3367 }
3368
3369 public static void deinitPerThread()
3370 {
3371 }
3372
3373 public void connect(String url, String username, String passwd)
3374 {
3375 this.port = pool.getPort();
3376 try {
3377 ((BindingProvider)port).getRequestContext().
3378 put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
3379 String handle = port.iWebsessionManagerLogon(username, passwd);
3380 this.vbox = new IVirtualBox(handle, port);
3381 } catch (Throwable t) {
3382 if (this.port != null)
3383 pool.releasePort(this.port);
3384 // we have to throw smth derived from RuntimeException
3385 throw new VBoxException(t, t.getMessage());
3386 }
3387 }
3388
3389 public void connect(String url, String username, String passwd,
3390 Map<String, Object> requestContext, Map<String, Object> responseContext)
3391 {
3392 this.port = pool.getPort();
3393
3394 try {
3395 ((BindingProvider)port).getRequestContext();
3396 if (requestContext != null)
3397 ((BindingProvider)port).getRequestContext().putAll(requestContext);
3398
3399 if (responseContext != null)
3400 ((BindingProvider)port).getResponseContext().putAll(responseContext);
3401
3402 ((BindingProvider)port).getRequestContext().
3403 put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
3404 String handle = port.iWebsessionManagerLogon(username, passwd);
3405 this.vbox = new IVirtualBox(handle, port);
3406 } catch (Throwable t) {
3407 if (this.port != null)
3408 pool.releasePort(port);
3409 // we have to throw smth derived from RuntimeException
3410 throw new VBoxException(t, t.getMessage());
3411 }
3412 }
3413
3414 public void disconnect()
3415 {
3416 try {
3417 if (this.vbox != null)
3418 port.iWebsessionManagerLogoff(this.vbox.getWrapped());
3419 } catch (InvalidObjectFaultMsg e) {
3420 throw new VBoxException(e, e.getMessage());
3421 } catch (RuntimeFaultMsg e) {
3422 throw new VBoxException(e, e.getMessage());
3423 } finally {
3424 if (this.port != null) {
3425 pool.releasePort(this.port);
3426 this.port = null;
3427 }
3428 }
3429 }
3430
3431 public IVirtualBox getVBox()
3432 {
3433 return this.vbox;
3434 }
3435
3436 public ISession getSessionObject()
3437 {
3438 if (this.vbox == null)
3439 throw new RuntimeException("connect first");
3440 try {
3441 String handle = port.iWebsessionManagerGetSessionObject(this.vbox.getWrapped());
3442 return new ISession(handle, port);
3443 } catch (InvalidObjectFaultMsg e) {
3444 throw new VBoxException(e, e.getMessage());
3445 } catch (RuntimeFaultMsg e) {
3446 throw new VBoxException(e, e.getMessage());
3447 }
3448 }
3449
3450 public ISession openMachineSession(IMachine m) throws Exception
3451 {
3452 ISession s = getSessionObject();
3453 m.lockMachine(s, LockType.Shared);
3454 return s;
3455 }
3456
3457 public void closeMachineSession(ISession s)
3458 {
3459 if (s != null)
3460 s.unlockMachine();
3461 }
3462
3463 public static synchronized VirtualBoxManager createInstance(String home)
3464 {
3465 return new VirtualBoxManager();
3466 }
3467
3468 public IEventListener createListener(Object sink)
3469 {
3470 throw new RuntimeException("no active listeners here");
3471 }
3472 public void cleanup()
3473 {
3474 deinitPerThread();
3475 }
3476
3477 public boolean progressBar(IProgress p, int wait)
3478 {
3479 long end = System.currentTimeMillis() + wait;
3480 while (!p.getCompleted())
3481 {
3482 p.waitForCompletion(wait);
3483 if (System.currentTimeMillis() >= end)
3484 return false;
3485 }
3486
3487 return true;
3488 }
3489
3490 public boolean startVm(String name, String type, int timeout)
3491 {
3492 IMachine m = vbox.findMachine(name);
3493 if (m == null)
3494 return false;
3495 ISession session = getSessionObject();
3496
3497 if (type == null)
3498 type = "gui";
3499 IProgress p = m.launchVMProcess(session, type, "");
3500 progressBar(p, timeout);
3501 session.unlockMachine();
3502 return true;
3503 }
3504
3505 public void waitForEvents(long tmo)
3506 {
3507 }
3508}
3509]]></xsl:text>
3510
3511 <xsl:call-template name="endFile">
3512 <xsl:with-param name="file" select="'VirtualBoxManager.java'" />
3513 </xsl:call-template>
3514
3515</xsl:template>
3516
3517
3518<xsl:template match="/">
3519
3520 <xsl:if test="not($G_vboxApiSuffix)">
3521 <xsl:call-template name="fatalError">
3522 <xsl:with-param name="msg" select="'G_vboxApiSuffix must be given'" />
3523 </xsl:call-template>
3524 </xsl:if>
3525
3526 <!-- Handwritten files -->
3527 <xsl:call-template name="emitHandwritten"/>
3528
3529 <xsl:choose>
3530 <xsl:when test="$G_vboxGlueStyle='xpcom'">
3531 <xsl:call-template name="emitHandwrittenXpcom"/>
3532 </xsl:when>
3533
3534 <xsl:when test="$G_vboxGlueStyle='mscom'">
3535 <xsl:call-template name="emitHandwrittenMscom"/>
3536 </xsl:when>
3537
3538 <xsl:when test="$G_vboxGlueStyle='jaxws'">
3539 <xsl:call-template name="emitHandwrittenJaxws"/>
3540 </xsl:when>
3541
3542 <xsl:otherwise>
3543 <xsl:call-template name="fatalError">
3544 <xsl:with-param name="msg" select="'Style unknown (root)'" />
3545 </xsl:call-template>
3546 </xsl:otherwise>
3547 </xsl:choose>
3548
3549 <!-- Enums -->
3550 <xsl:for-each select="//enum">
3551 <xsl:call-template name="genEnum">
3552 <xsl:with-param name="enumname" select="@name" />
3553 <xsl:with-param name="filename" select="concat(@name, '.java')" />
3554 </xsl:call-template>
3555 </xsl:for-each>
3556
3557 <!-- Interfaces -->
3558 <xsl:for-each select="//interface">
3559 <xsl:variable name="self_target" select="current()/ancestor::if/@target"/>
3560 <xsl:variable name="module" select="current()/ancestor::module/@name"/>
3561
3562 <xsl:choose>
3563 <xsl:when test="$G_vboxGlueStyle='jaxws'">
3564 <xsl:if test="not($module) and not(@wsmap='suppress') and not(@wsmap='global')">
3565 <xsl:call-template name="genIface">
3566 <xsl:with-param name="ifname" select="@name" />
3567 <xsl:with-param name="filename" select="concat(@name, '.java')" />
3568 </xsl:call-template>
3569 </xsl:if>
3570 </xsl:when>
3571
3572 <xsl:otherwise>
3573 <!-- We don't need WSDL-specific interfaces here -->
3574 <xsl:if test="not($self_target='wsdl') and not($module)">
3575 <xsl:call-template name="genIface">
3576 <xsl:with-param name="ifname" select="@name" />
3577 <xsl:with-param name="filename" select="concat(@name, '.java')" />
3578 </xsl:call-template>
3579 </xsl:if>
3580 </xsl:otherwise>
3581
3582 </xsl:choose>
3583 </xsl:for-each>
3584</xsl:template>
3585</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette