VirtualBox

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

Last change on this file since 31694 was 31694, checked in by vboxsync, 15 years ago

Java XPCOM bridge: octet arrays are byte[] in XPCOM backend, proper null treatment

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

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