VirtualBox

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

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

Main: reorganize session APIs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 120.1 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="'short'" />
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(short[] vals) {
2207 if (vals==null || vals.length == 0) return Collections.emptyList();
2208
2209 List<Short> ret = new ArrayList<Short>(vals.length);
2210 for (short v : vals) {
2211 ret.add(v);
2212 }
2213 return ret;
2214 }
2215
2216 public static List<Integer> wrap(int[] vals) {
2217 if (vals==null || vals.length == 0) return Collections.emptyList();
2218
2219 List<Integer> ret = new ArrayList<Integer>(vals.length);
2220 for (int v : vals) {
2221 ret.add(v);
2222 }
2223 return ret;
2224 }
2225
2226 public static List<Long> wrap(long[] vals) {
2227 if (vals==null || vals.length == 0) return Collections.emptyList();
2228
2229 List<Long> ret = new ArrayList<Long>(vals.length);
2230 for (long v : vals) {
2231 ret.add(v);
2232 }
2233 return ret;
2234 }
2235
2236 public static List<String> wrap(String[] vals) {
2237 if (vals==null || vals.length == 0) return Collections.emptyList();
2238
2239 List<String> ret = new ArrayList<String>(vals.length);
2240 for (String v : vals) {
2241 ret.add(v);
2242 }
2243 return ret;
2244 }
2245
2246 public static <T> List<T> wrap(Class<T> wrapperClass, T[] thisPtrs) {
2247 if (thisPtrs==null || thisPtrs.length == 0) return Collections.emptyList();
2248
2249 List<T> ret = new ArrayList<T>(thisPtrs.length);
2250 for (T thisPtr : thisPtrs) {
2251 ret.add(thisPtr);
2252 }
2253 return ret;
2254 }
2255
2256 public static <T> List<T> wrapEnum(Class<T> wrapperClass, long values[]) {
2257 try {
2258 if (values==null)
2259 return null;
2260 Constructor<T> c = wrapperClass.getConstructor(int.class);
2261 List<T> ret = new ArrayList<T>(values.length);
2262 for (long v : values) {
2263 ret.add(c.newInstance(v));
2264 }
2265 return ret;
2266 } catch (NoSuchMethodException e) {
2267 throw new AssertionError(e);
2268 } catch (InstantiationException e) {
2269 throw new AssertionError(e);
2270 } catch (IllegalAccessException e) {
2271 throw new AssertionError(e);
2272 } catch (InvocationTargetException e) {
2273 throw new AssertionError(e);
2274 }
2275 }
2276
2277 public static List<BigInteger> wrapUnsignedLongLong(double vals[]) {
2278 List<BigInteger> ret = new ArrayList<BigInteger>(vals.length);
2279 for (double v : vals) {
2280 ret.add(doubleToBigInteger(v));
2281 }
2282 return ret;
2283 }
2284
2285
2286 public static short[] unwrap(List<Short> vals) {
2287 if (vals==null || vals.size() == 0) return new short[0];
2288
2289 short[] ret = new short[vals.size()];
2290 int i = 0;
2291 for (short l : vals) {
2292 ret[i++] = l;
2293 }
2294 return ret;
2295 }
2296
2297 public static int[] unwrap(List<Integer> vals) {
2298 if (vals==null || vals.size() == 0) return new int[0];
2299
2300 int[] ret = new int[vals.size()];
2301 int i = 0;
2302 for (int l : vals) {
2303 ret[i++] = l;
2304 }
2305 return ret;
2306 }
2307
2308 public static long[] unwrap(List<Long> vals) {
2309 if (vals==null || vals.size() == 0) return new long[0];
2310
2311 long[] ret = new long[vals.size()];
2312 int i = 0;
2313 for (long l : vals) {
2314 ret[i++] = l;
2315 }
2316 return ret;
2317 }
2318
2319 public static boolean[] unwrap(List<Boolean> vals) {
2320 if (vals==null || vals.size() == 0) return new boolean[0];
2321
2322 boolean[] ret = new boolean[vals.size()];
2323 int i = 0;
2324 for (boolean l : vals) {
2325 ret[i++] = l;
2326 }
2327 return ret;
2328 }
2329
2330 public static String[] unwrap(List<String> vals) {
2331 if (vals==null || vals.size() == 0) return new String[0];
2332
2333 String[] ret = new String[vals.size()];
2334 int i = 0;
2335 for (String l : vals) {
2336 ret[i++] = l;
2337 }
2338 return ret;
2339 }
2340
2341 public static <T extends Enum <T>> long[] unwrapEnum(Class<T> enumClass, List<T> values) {
2342 if (values == null) return null;
2343
2344 long result[] = new long[values.size()];
2345 try {
2346 java.lang.reflect.Method valueM = enumClass.getMethod("value");
2347 int i = 0;
2348 for (T v : values) {
2349 result[i++] = (Integer)valueM.invoke(v);
2350 }
2351 return result;
2352 } catch (NoSuchMethodException e) {
2353 throw new AssertionError(e);
2354 } catch(SecurityException e) {
2355 throw new AssertionError(e);
2356 } catch (IllegalAccessException e) {
2357 throw new AssertionError(e);
2358 } catch (IllegalArgumentException e) {
2359 throw new AssertionError(e);
2360 } catch (InvocationTargetException e) {
2361 throw new AssertionError(e);
2362 }
2363 }
2364
2365 public static <T1, T2> List<T1> wrap2(Class<T1> wrapperClass1, Class<T2> wrapperClass2, T2[] thisPtrs) {
2366 try {
2367 if (thisPtrs==null || thisPtrs.length == 0) return Collections.emptyList();
2368
2369 Constructor<T1> c = wrapperClass1.getConstructor(wrapperClass2);
2370 List<T1> ret = new ArrayList<T1>(thisPtrs.length);
2371 for (T2 thisPtr : thisPtrs) {
2372 ret.add(c.newInstance(thisPtr));
2373 }
2374 return ret;
2375 } catch (NoSuchMethodException e) {
2376 throw new AssertionError(e);
2377 } catch (InstantiationException e) {
2378 throw new AssertionError(e);
2379 } catch (IllegalAccessException e) {
2380 throw new AssertionError(e);
2381 } catch (InvocationTargetException e) {
2382 throw new AssertionError(e);
2383 }
2384 }
2385
2386 public static <T> T[] unwrap(Class<T> wrapperClass, List<T> thisPtrs) {
2387 if (thisPtrs==null)
2388 return null;
2389 if (thisPtrs.size() == 0)
2390 return null;
2391 return (T[])thisPtrs.toArray((T[])Array.newInstance(wrapperClass, thisPtrs.size()));
2392 }
2393
2394 public static <T> T queryInterface(Object obj, String uuid, Class<T> iface)
2395 {
2396 return (T)queryInterface(obj, uuid);
2397 }
2398
2399 public static Object queryInterface(Object obj, String uuid)
2400 {
2401 try {
2402 /* Kind of ugly, but does the job of casting */
2403 org.mozilla.xpcom.Mozilla moz = org.mozilla.xpcom.Mozilla.getInstance();
2404 long xpobj = moz.wrapJavaObject(obj, uuid);
2405 return moz.wrapXPCOMObject(xpobj, uuid);
2406 } catch (Exception e) {
2407 return null;
2408 }
2409 }
2410
2411 public static <T1 extends IUnknown,T2> T2[] unwrap2(Class<T1> wrapperClass1, Class<T2> wrapperClass2, List<T1> thisPtrs) {
2412 if (thisPtrs==null || thisPtrs.size() == 0) return null;
2413
2414 T2 ret[] = (T2[])Array.newInstance(wrapperClass2, thisPtrs.size());
2415 int i = 0;
2416 for (T1 obj : thisPtrs) {
2417 ret[i++] = (T2)obj.getWrapped();
2418 }
2419 return ret;
2420 }
2421
2422 /* We do loose precision here */
2423 public static BigInteger doubleToBigInteger(double val) {
2424 return new BigInteger(Long.toString((long)val));
2425 }
2426 public static double bigIntegerToDouble(BigInteger val) {
2427 return val.doubleValue();
2428 }
2429}
2430]]></xsl:text>
2431
2432 <xsl:call-template name="endFile">
2433 <xsl:with-param name="file" select="'Helper.java'" />
2434 </xsl:call-template>
2435
2436 <xsl:call-template name="startFile">
2437 <xsl:with-param name="file" select="'VirtualBoxManager.java'" />
2438 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
2439 </xsl:call-template>
2440
2441 <xsl:text><![CDATA[
2442
2443import java.io.File;
2444
2445import org.mozilla.xpcom.*;
2446import org.mozilla.interfaces.*;
2447
2448public class VirtualBoxManager
2449{
2450 private Mozilla mozilla;
2451 private IVirtualBox vbox;
2452 private nsIComponentManager componentManager;
2453 private nsIServiceManager servMgr;
2454
2455 private VirtualBoxManager(Mozilla mozilla, nsIServiceManager servMgr)
2456 {
2457 this.mozilla = mozilla;
2458 this.servMgr = servMgr;
2459 this.componentManager = mozilla.getComponentManager();
2460 this.vbox = new IVirtualBox((org.mozilla.interfaces.IVirtualBox) this.componentManager
2461 .createInstanceByContractID("@virtualbox.org/VirtualBox;1",
2462 null,
2463 org.mozilla.interfaces.IVirtualBox.IVIRTUALBOX_IID));
2464 }
2465
2466 public void connect(String url, String username, String passwd)
2467 {
2468 throw new RuntimeException("Connect doesn't make sense for local bindings");
2469 }
2470
2471 public void disconnect()
2472 {
2473 throw new RuntimeException("Disconnect doesn't make sense for local bindings");
2474 }
2475
2476 public static void initPerThread()
2477 {
2478 }
2479
2480 public static void deinitPerThread()
2481 {
2482 }
2483
2484 public IVirtualBox getVBox()
2485 {
2486 return this.vbox;
2487 }
2488
2489 public ISession getSessionObject()
2490 {
2491 return new ISession((org.mozilla.interfaces.ISession) componentManager
2492 .createInstanceByContractID("@virtualbox.org/Session;1", null,
2493 org.mozilla.interfaces.ISession.ISESSION_IID));
2494 }
2495
2496 public ISession openMachineSession(IMachine m) throws Exception
2497 {
2498 ISession s = getSessionObject();
2499 m.lockForSession(s, true /* fPermitShared */);
2500 return s;
2501 }
2502
2503 public void closeMachineSession(ISession s)
2504 {
2505 if (s != null)
2506 s.close();
2507 }
2508
2509 private static VirtualBoxManager mgr;
2510
2511 public static synchronized VirtualBoxManager getInstance(String home)
2512 {
2513 if (mgr != null)
2514 return mgr;
2515
2516 if (home == null)
2517 home = System.getProperty("vbox.home");
2518
2519 File grePath = new File(home);
2520 Mozilla mozilla = Mozilla.getInstance();
2521 mozilla.initialize(grePath);
2522 nsIServiceManager servMgr = null;
2523 try {
2524 servMgr = mozilla.initXPCOM(grePath, null);
2525 } catch (Exception e) {
2526 e.printStackTrace();
2527 return null;
2528 }
2529
2530 mgr = new VirtualBoxManager(mozilla, servMgr);
2531 return mgr;
2532 }
2533
2534 public IEventListener createListener(Object sink)
2535 {
2536 return new IEventListener(new EventListenerImpl(sink));
2537 }
2538 public void cleanup()
2539 {
2540 deinitPerThread();
2541 // cleanup
2542 mozilla.shutdownXPCOM(servMgr);
2543 mozilla = null;
2544 }
2545
2546 public boolean progressBar(IProgress p, int wait)
2547 {
2548 long end = System.currentTimeMillis() + wait;
2549 while (!p.getCompleted())
2550 {
2551 mozilla.waitForEvents(0);
2552 p.waitForCompletion(wait);
2553 if (System.currentTimeMillis() >= end)
2554 return false;
2555 }
2556
2557 return true;
2558 }
2559
2560 public boolean startVm(String name, String type, int timeout)
2561 {
2562 IMachine m = vbox.findMachine(name);
2563 if (m == null)
2564 return false;
2565 ISession session = getSessionObject();
2566
2567 if (type == null)
2568 type = "gui";
2569 IProgress p = m.launchVMProcess(session, type, "");
2570 progressBar(p, timeout);
2571 session.close();
2572 return true;
2573 }
2574
2575 public void waitForEvents(long tmo)
2576 {
2577 mozilla.waitForEvents(tmo);
2578 }
2579}
2580]]></xsl:text>
2581
2582 <xsl:call-template name="endFile">
2583 <xsl:with-param name="file" select="'VirtualBoxManager.java'" />
2584 </xsl:call-template>
2585
2586 <xsl:call-template name="startFile">
2587 <xsl:with-param name="file" select="'EventListenerImpl.java'" />
2588 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
2589 </xsl:call-template>
2590
2591 <xsl:text><![CDATA[
2592 import org.mozilla.interfaces.*;
2593
2594 public class EventListenerImpl extends nsISupportsBase implements org.mozilla.interfaces.IEventListener
2595 {
2596 private Object obj;
2597 private java.lang.reflect.Method handleEvent;
2598 EventListenerImpl(Object obj)
2599 {
2600 this.obj = obj;
2601 try {
2602 this.handleEvent = obj.getClass().getMethod("handleEvent", IEvent.class);
2603 } catch (Exception e) {
2604 e.printStackTrace();
2605 }
2606 }
2607 public void handleEvent(org.mozilla.interfaces.IEvent ev)
2608 {
2609 try {
2610 if (obj != null && handleEvent != null)
2611 handleEvent.invoke(obj, ev != null ? new IEvent(ev) : null);
2612 } catch (Exception e) {
2613 e.printStackTrace();
2614 }
2615 }
2616 }]]></xsl:text>
2617
2618 <xsl:call-template name="endFile">
2619 <xsl:with-param name="file" select="'EventListenerImpl.java'" />
2620 </xsl:call-template>
2621
2622 <xsl:call-template name="startFile">
2623 <xsl:with-param name="file" select="'VBoxObjectBase.java'" />
2624 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
2625 </xsl:call-template>
2626
2627<xsl:text><![CDATA[
2628abstract class nsISupportsBase implements org.mozilla.interfaces.nsISupports
2629{
2630 public org.mozilla.interfaces.nsISupports queryInterface(String iid)
2631 {
2632 return org.mozilla.xpcom.Mozilla.queryInterface(this, iid);
2633 }
2634}
2635
2636]]></xsl:text><xsl:call-template name="endFile">
2637 <xsl:with-param name="file" select="'VBoxObjectBase.java'" />
2638 </xsl:call-template>
2639
2640</xsl:template>
2641
2642
2643<xsl:template name="emitHandwrittenMscom">
2644
2645<xsl:call-template name="startFile">
2646 <xsl:with-param name="file" select="'IUnknown.java'" />
2647 <xsl:with-param name="package" select="$G_virtualBoxPackageCom" />
2648 </xsl:call-template>
2649
2650 <xsl:text><![CDATA[
2651public class IUnknown
2652{
2653 private Object obj;
2654 public IUnknown(Object obj)
2655 {
2656 this.obj = obj;
2657 }
2658
2659 public Object getWrapped()
2660 {
2661 return this.obj;
2662 }
2663
2664 public void setWrapped(Object obj)
2665 {
2666 this.obj = obj;
2667 }
2668}
2669]]></xsl:text>
2670
2671 <xsl:call-template name="endFile">
2672 <xsl:with-param name="file" select="'IUnknown.java'" />
2673 </xsl:call-template>
2674
2675<xsl:call-template name="startFile">
2676 <xsl:with-param name="file" select="'Helper.java'" />
2677 <xsl:with-param name="package" select="$G_virtualBoxPackageCom" />
2678 </xsl:call-template>
2679
2680<xsl:text><![CDATA[
2681
2682import java.util.List;
2683import java.util.ArrayList;
2684import java.util.Collections;
2685import java.lang.reflect.Array;
2686import java.lang.reflect.Constructor;
2687import java.lang.reflect.InvocationTargetException;
2688import java.math.BigInteger;
2689import com.jacob.com.*;
2690
2691public class Helper {
2692 public static List<Short> wrap(short[] vals) {
2693 if (vals==null) return null;
2694 if (vals.length == 0) return Collections.emptyList();
2695
2696 List<Short> ret = new ArrayList<Short>(vals.length);
2697 for (short v : vals) {
2698 ret.add(v);
2699 }
2700 return ret;
2701 }
2702
2703 public static List<Integer> wrap(int[] vals) {
2704 if (vals == null) return null;
2705 if (vals.length == 0) return Collections.emptyList();
2706
2707 List<Integer> ret = new ArrayList<Integer>(vals.length);
2708 for (int v : vals) {
2709 ret.add(v);
2710 }
2711 return ret;
2712 }
2713
2714 public static List<Long> wrap(long[] vals) {
2715 if (vals==null) return null;
2716 if (vals.length == 0) return Collections.emptyList();
2717
2718 List<Long> ret = new ArrayList<Long>(vals.length);
2719 for (long v : vals) {
2720 ret.add(v);
2721 }
2722 return ret;
2723 }
2724
2725 public static List<String> wrap(String[] vals) {
2726 if (vals==null) return null;
2727 if (vals.length == 0) return Collections.emptyList();
2728
2729 List<String> ret = new ArrayList<String>(vals.length);
2730 for (String v : vals) {
2731 ret.add(v);
2732 }
2733 return ret;
2734 }
2735
2736 public static <T> T wrapDispatch(Class<T> wrapperClass, Dispatch d)
2737 {
2738 try {
2739 if (d == null || d.m_pDispatch == 0)
2740 return null;
2741 Constructor<T> c = wrapperClass.getConstructor(Dispatch.class);
2742 return (T)c.newInstance(d);
2743 } catch (NoSuchMethodException e) {
2744 throw new AssertionError(e);
2745 } catch (InstantiationException e) {
2746 throw new AssertionError(e);
2747 } catch (IllegalAccessException e) {
2748 throw new AssertionError(e);
2749 } catch (InvocationTargetException e) {
2750 throw new AssertionError(e);
2751 }
2752 }
2753
2754 public static <T> Object wrapVariant(Class<T> wrapperClass, Variant v)
2755 {
2756 if (v == null)
2757 return null;
2758
2759 short vt = v.getvt();
2760 switch (vt)
2761 {
2762 case Variant.VariantNull:
2763 return null;
2764 case Variant.VariantBoolean:
2765 return v.getBoolean();
2766 case Variant.VariantByte:
2767 return v.getByte();
2768 case Variant.VariantShort:
2769 return v.getShort();
2770 case Variant.VariantInt:
2771 return v.getInt();
2772 case Variant.VariantLongInt:
2773 return v.getLong();
2774 case Variant.VariantString:
2775 return v.getString();
2776 case Variant.VariantDispatch:
2777 return wrapDispatch(wrapperClass, v.getDispatch());
2778 default:
2779 throw new RuntimeException("unhandled variant type "+vt);
2780 }
2781 }
2782
2783 public static <T> List<T> wrap(Class<T> wrapperClass, SafeArray sa) {
2784 if (sa==null) return null;
2785
2786 int saLen = sa.getUBound() - sa.getLBound() + 1;
2787 if (saLen == 0) return Collections.emptyList();
2788
2789 List<T> ret = new ArrayList<T>(saLen);
2790 for (int i = sa.getLBound(); i <= sa.getUBound(); i++)
2791 {
2792 Variant v = sa.getVariant(i);
2793 ret.add((T)wrapVariant(wrapperClass, v));
2794 }
2795 return ret;
2796 }
2797
2798 public static <T> List<T> wrapEnum(Class<T> wrapperClass, SafeArray sa) {
2799 try {
2800 if (sa==null) return null;
2801
2802 int saLen = sa.getUBound() - sa.getLBound() + 1;
2803 if (saLen == 0) return Collections.emptyList();
2804 List<T> ret = new ArrayList<T>(saLen);
2805 Constructor<T> c = wrapperClass.getConstructor(int.class);
2806 for (int i = sa.getLBound(); i <= sa.getUBound(); i++)
2807 {
2808 Variant v = sa.getVariant(i);
2809 ret.add(c.newInstance(v.getInt()));
2810 }
2811 return ret;
2812 } catch (NoSuchMethodException e) {
2813 throw new AssertionError(e);
2814 } catch (InstantiationException e) {
2815 throw new AssertionError(e);
2816 } catch (IllegalAccessException e) {
2817 throw new AssertionError(e);
2818 } catch (InvocationTargetException e) {
2819 throw new AssertionError(e);
2820 }
2821 }
2822
2823 public static SafeArray unwrapInt(List<Integer> vals) {
2824 if (vals==null) return null;
2825 SafeArray ret = new SafeArray(Variant.VariantInt, vals.size());
2826 int i = 0;
2827 for (int l : vals) {
2828 ret.setInt(i++, l);
2829 }
2830 return ret;
2831 }
2832
2833 public static SafeArray unwrapLong(List<Long> vals) {
2834 if (vals==null) return null;
2835 SafeArray ret = new SafeArray(Variant.VariantLongInt, vals.size());
2836 int i = 0;
2837 for (long l : vals) {
2838 ret.setLong(i++, l);
2839 }
2840 return ret;
2841 }
2842
2843 public static SafeArray unwrapBool(List<Boolean> vals) {
2844 if (vals==null) return null;
2845
2846 SafeArray result = new SafeArray(Variant.VariantBoolean, vals.size());
2847 int i = 0;
2848 for (boolean l : vals) {
2849 result.setBoolean(i, l);
2850 }
2851 return result;
2852 }
2853
2854 public static <T extends Enum <T>> SafeArray unwrapEnum(Class<T> enumClass, List<T> values) {
2855 if (values == null) return null;
2856
2857 SafeArray result = new SafeArray(Variant.VariantInt, values.size());
2858 try {
2859 java.lang.reflect.Method valueM = enumClass.getMethod("value");
2860 int i = 0;
2861 for (T v : values) {
2862 result.setInt(i, (Integer)valueM.invoke(v));
2863 }
2864 return result;
2865 } catch (NoSuchMethodException e) {
2866 throw new AssertionError(e);
2867 } catch(SecurityException e) {
2868 throw new AssertionError(e);
2869 } catch (IllegalAccessException e) {
2870 throw new AssertionError(e);
2871 } catch (IllegalArgumentException e) {
2872 throw new AssertionError(e);
2873 } catch (InvocationTargetException e) {
2874 throw new AssertionError(e);
2875 }
2876 }
2877 public static SafeArray unwrapString(List<String> vals) {
2878 if (vals==null)
2879 return null;
2880 SafeArray result = new SafeArray(Variant.VariantString, vals.size());
2881 int i = 0;
2882 for (String l : vals) {
2883 result.setString(i, l);
2884 }
2885 return result;
2886 }
2887
2888 public static <T1, T2> List<T1> wrap2(Class<T1> wrapperClass1, Class<T2> wrapperClass2, T2[] thisPtrs) {
2889 try {
2890 if (thisPtrs==null) return null;
2891 if (thisPtrs.length == 0) return Collections.emptyList();
2892
2893 Constructor<T1> c = wrapperClass1.getConstructor(wrapperClass2);
2894 List<T1> ret = new ArrayList<T1>(thisPtrs.length);
2895 for (T2 thisPtr : thisPtrs) {
2896 ret.add(c.newInstance(thisPtr));
2897 }
2898 return ret;
2899 } catch (NoSuchMethodException e) {
2900 throw new AssertionError(e);
2901 } catch (InstantiationException e) {
2902 throw new AssertionError(e);
2903 } catch (IllegalAccessException e) {
2904 throw new AssertionError(e);
2905 } catch (InvocationTargetException e) {
2906 throw new AssertionError(e);
2907 }
2908 }
2909
2910 public static <T> T[] unwrap(Class<T> wrapperClass, List<T> thisPtrs) {
2911 if (thisPtrs==null) return null;
2912 return (T[])thisPtrs.toArray((T[])Array.newInstance(wrapperClass, thisPtrs.size()));
2913 }
2914
2915 public static <T1 extends IUnknown,T2> T2[] unwrap2(Class<T1> wrapperClass1, Class<T2> wrapperClass2, List<T1> thisPtrs) {
2916 if (thisPtrs==null) return null;
2917
2918 T2 ret[] = (T2[])Array.newInstance(wrapperClass2, thisPtrs.size());
2919 int i = 0;
2920 for (T1 obj : thisPtrs) {
2921 ret[i++] = (T2)obj.getWrapped();
2922 }
2923 return ret;
2924 }
2925
2926 public static BigInteger longToBigInteger(long value) {
2927 return BigInteger.valueOf(value);
2928 }
2929
2930 /* We have very long invoke lists sometimes */
2931 public static Variant invoke(Dispatch d, String method, Object ... args)
2932 {
2933 return Dispatch.callN(d, method, args);
2934 }
2935}
2936]]></xsl:text>
2937
2938 <xsl:call-template name="endFile">
2939 <xsl:with-param name="file" select="'Helper.java'" />
2940 </xsl:call-template>
2941
2942
2943 <xsl:call-template name="startFile">
2944 <xsl:with-param name="file" select="'VirtualBoxManager.java'" />
2945 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
2946 </xsl:call-template>
2947
2948 <xsl:text><![CDATA[
2949
2950import com.jacob.activeX.ActiveXComponent;
2951import com.jacob.com.ComThread;
2952import com.jacob.com.Dispatch;
2953import com.jacob.com.Variant;
2954import com.jacob.com.SafeArray;
2955import com.jacob.com.DispatchEvents;
2956
2957public class VirtualBoxManager
2958{
2959 private IVirtualBox vbox;
2960
2961 private VirtualBoxManager()
2962 {
2963 initPerThread();
2964 vbox = new IVirtualBox(new ActiveXComponent("VirtualBox.VirtualBox"));
2965 }
2966
2967 public static void initPerThread()
2968 {
2969 ComThread.InitMTA();
2970 }
2971
2972 public static void deinitPerThread()
2973 {
2974 ComThread.Release();
2975 }
2976
2977 public void connect(String url, String username, String passwd)
2978 {
2979 throw new RuntimeException("Connect doesn't make sense for local bindings");
2980 }
2981
2982 public void disconnect()
2983 {
2984 throw new RuntimeException("Disconnect doesn't make sense for local bindings");
2985 }
2986
2987 public IVirtualBox getVBox()
2988 {
2989 return this.vbox;
2990 }
2991
2992 public ISession getSessionObject()
2993 {
2994 return new ISession(new ActiveXComponent("VirtualBox.Session"));
2995 }
2996
2997 public ISession openMachineSession(String mid) throws Exception
2998 {
2999 ISession s = getSessionObject();
3000 try {
3001 this.vbox.openExistingSession(s, mid);
3002 return s;
3003 } catch (Exception e) {
3004 try {
3005 this.vbox.openSession(s, mid);
3006 return s;
3007 } catch (Exception e1) {
3008 closeMachineSession(s);
3009 throw e1;
3010 }
3011 }
3012 }
3013
3014 public ISession openMachineSession(IMachine m) throws Exception
3015 {
3016 return openMachineSession(m.getId());
3017 }
3018
3019 public void closeMachineSession(ISession s)
3020 {
3021 if (s != null)
3022 s.close();
3023 }
3024
3025 private static VirtualBoxManager mgr;
3026
3027 public static synchronized VirtualBoxManager getInstance(String home)
3028 {
3029 if (mgr != null)
3030 return mgr;
3031
3032 if (home == null)
3033 home = System.getProperty("vbox.home");
3034
3035 mgr = new VirtualBoxManager();
3036 return mgr;
3037 }
3038
3039 public void cleanup()
3040 {
3041 deinitPerThread();
3042 mgr = null;
3043 }
3044
3045 public boolean progressBar(IProgress p, int wait)
3046 {
3047 long end = System.currentTimeMillis() + wait;
3048 while (!p.getCompleted())
3049 {
3050 p.waitForCompletion(wait);
3051 if (System.currentTimeMillis() >= end)
3052 return false;
3053 }
3054
3055 return true;
3056 }
3057
3058 public boolean startVm(String name, String type, int timeout)
3059 {
3060 IMachine m = vbox.findMachine(name);
3061 if (m == null)
3062 return false;
3063 ISession session = getSessionObject();
3064
3065 String mid = m.getId();
3066 if (type == null)
3067 type = "gui";
3068 IProgress p = vbox.openRemoteSession(session, mid, type, "");
3069 progressBar(p, timeout);
3070 session.close();
3071 return true;
3072 }
3073
3074 public void waitForEvents(long tmo)
3075 {
3076 // what to do here?
3077 try {
3078 Thread.sleep(tmo);
3079 } catch (InterruptedException ie) {
3080 }
3081 }
3082}
3083]]></xsl:text>
3084
3085 <xsl:call-template name="endFile">
3086 <xsl:with-param name="file" select="'VirtualBoxManager.java'" />
3087 </xsl:call-template>
3088
3089</xsl:template>
3090
3091<xsl:template name="emitHandwrittenJaxws">
3092
3093 <xsl:call-template name="startFile">
3094 <xsl:with-param name="file" select="'IUnknown.java'" />
3095 <xsl:with-param name="package" select="$G_virtualBoxPackageCom" />
3096 </xsl:call-template>
3097
3098 <xsl:text><![CDATA[
3099public class IUnknown
3100{
3101 protected String obj;
3102 protected final VboxPortType port;
3103
3104 public IUnknown(String obj, VboxPortType port)
3105 {
3106 this.obj = obj;
3107 this.port = port;
3108 }
3109
3110 public final String getWrapped()
3111 {
3112 return this.obj;
3113 }
3114
3115 public final VboxPortType getRemoteWSPort()
3116 {
3117 return this.port;
3118 }
3119
3120 public synchronized void releaseRemote() throws WebServiceException
3121 {
3122 if (obj == null) {
3123 return;
3124 }
3125 try {
3126 this.port.iManagedObjectRefRelease(obj);
3127 this.obj = null;
3128 } catch (InvalidObjectFaultMsg e) {
3129 throw new WebServiceException(e);
3130 } catch (RuntimeFaultMsg e) {
3131 throw new WebServiceException(e);
3132 }
3133 }
3134}
3135]]></xsl:text>
3136
3137 <xsl:call-template name="endFile">
3138 <xsl:with-param name="file" select="'IUnknown.java'" />
3139 </xsl:call-template>
3140
3141 <xsl:call-template name="startFile">
3142 <xsl:with-param name="file" select="'Helper.java'" />
3143 <xsl:with-param name="package" select="$G_virtualBoxPackageCom" />
3144 </xsl:call-template>
3145
3146<xsl:text><![CDATA[
3147
3148import java.util.List;
3149import java.util.ArrayList;
3150import java.util.Collections;
3151import java.lang.reflect.Array;
3152import java.lang.reflect.Constructor;
3153import java.lang.reflect.InvocationTargetException;
3154import java.math.BigInteger;
3155
3156public class Helper {
3157 public static <T> List<T> wrap(Class<T> wrapperClass, VboxPortType pt, List<String> thisPtrs) {
3158 try {
3159 if(thisPtrs==null) return null;
3160
3161 Constructor<T> c = wrapperClass.getConstructor(String.class, VboxPortType.class);
3162 List<T> ret = new ArrayList<T>(thisPtrs.size());
3163 for (String thisPtr : thisPtrs) {
3164 ret.add(c.newInstance(thisPtr,pt));
3165 }
3166 return ret;
3167 } catch (NoSuchMethodException e) {
3168 throw new AssertionError(e);
3169 } catch (InstantiationException e) {
3170 throw new AssertionError(e);
3171 } catch (IllegalAccessException e) {
3172 throw new AssertionError(e);
3173 } catch (InvocationTargetException e) {
3174 throw new AssertionError(e);
3175 }
3176 }
3177
3178 public static <T1, T2> List<T1> wrap2(Class<T1> wrapperClass1, Class<T2> wrapperClass2, VboxPortType pt, List<T2> thisPtrs) {
3179 try {
3180 if(thisPtrs==null) return null;
3181
3182 Constructor<T1> c = wrapperClass1.getConstructor(wrapperClass2, VboxPortType.class);
3183 List<T1> ret = new ArrayList<T1>(thisPtrs.size());
3184 for (T2 thisPtr : thisPtrs) {
3185 ret.add(c.newInstance(thisPtr,pt));
3186 }
3187 return ret;
3188 } catch (NoSuchMethodException e) {
3189 throw new AssertionError(e);
3190 } catch (InstantiationException e) {
3191 throw new AssertionError(e);
3192 } catch (IllegalAccessException e) {
3193 throw new AssertionError(e);
3194 } catch (InvocationTargetException e) {
3195 throw new AssertionError(e);
3196 }
3197 }
3198
3199 public static <T extends IUnknown> List<String> unwrap(List<T> thisPtrs) {
3200 if (thisPtrs==null) return null;
3201
3202 List<String> ret = new ArrayList<String>(thisPtrs.size());
3203 for (T obj : thisPtrs) {
3204 ret.add(obj.getWrapped());
3205 }
3206 return ret;
3207 }
3208
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.lockForSession(s, true /* fPermitShared */ );
3462 return s;
3463 }
3464
3465 public void closeMachineSession(ISession s)
3466 {
3467 if (s != null)
3468 s.close();
3469 }
3470
3471 private static VirtualBoxManager mgr;
3472
3473 public static synchronized VirtualBoxManager getInstance(String home)
3474 {
3475 if (mgr != null)
3476 return mgr;
3477
3478 mgr = new VirtualBoxManager();
3479 return mgr;
3480 }
3481
3482 public IEventListener createListener(Object sink)
3483 {
3484 throw new RuntimeException("no active listeners here");
3485 }
3486 public void cleanup()
3487 {
3488 deinitPerThread();
3489 }
3490
3491 public boolean progressBar(IProgress p, int wait)
3492 {
3493 long end = System.currentTimeMillis() + wait;
3494 while (!p.getCompleted())
3495 {
3496 p.waitForCompletion(wait);
3497 if (System.currentTimeMillis() >= end)
3498 return false;
3499 }
3500
3501 return true;
3502 }
3503
3504 public boolean startVm(String name, String type, int timeout)
3505 {
3506 IMachine m = vbox.findMachine(name);
3507 if (m == null)
3508 return false;
3509 ISession session = getSessionObject();
3510
3511 if (type == null)
3512 type = "gui";
3513 IProgress p = m.launchVMProcess(session, type, "");
3514 progressBar(p, timeout);
3515 session.close();
3516 return true;
3517 }
3518
3519 public void waitForEvents(long tmo)
3520 {
3521 }
3522}
3523]]></xsl:text>
3524
3525 <xsl:call-template name="endFile">
3526 <xsl:with-param name="file" select="'VirtualBoxManager.java'" />
3527 </xsl:call-template>
3528
3529</xsl:template>
3530
3531
3532<xsl:template match="/">
3533
3534 <xsl:if test="not($G_vboxApiSuffix)">
3535 <xsl:call-template name="fatalError">
3536 <xsl:with-param name="msg" select="'G_vboxApiSuffix must be given'" />
3537 </xsl:call-template>
3538 </xsl:if>
3539
3540 <!-- Handwritten files -->
3541 <xsl:call-template name="emitHandwritten"/>
3542
3543 <xsl:choose>
3544 <xsl:when test="$G_vboxGlueStyle='xpcom'">
3545 <xsl:call-template name="emitHandwrittenXpcom"/>
3546 </xsl:when>
3547
3548 <xsl:when test="$G_vboxGlueStyle='mscom'">
3549 <xsl:call-template name="emitHandwrittenMscom"/>
3550 </xsl:when>
3551
3552 <xsl:when test="$G_vboxGlueStyle='jaxws'">
3553 <xsl:call-template name="emitHandwrittenJaxws"/>
3554 </xsl:when>
3555
3556 <xsl:otherwise>
3557 <xsl:call-template name="fatalError">
3558 <xsl:with-param name="msg" select="'Style unknown (root)'" />
3559 </xsl:call-template>
3560 </xsl:otherwise>
3561 </xsl:choose>
3562
3563 <!-- Enums -->
3564 <xsl:for-each select="//enum">
3565 <xsl:call-template name="genEnum">
3566 <xsl:with-param name="enumname" select="@name" />
3567 <xsl:with-param name="filename" select="concat(@name, '.java')" />
3568 </xsl:call-template>
3569 </xsl:for-each>
3570
3571 <!-- Interfaces -->
3572 <xsl:for-each select="//interface">
3573 <xsl:variable name="self_target" select="current()/ancestor::if/@target"/>
3574 <xsl:variable name="module" select="current()/ancestor::module/@name"/>
3575
3576 <xsl:choose>
3577 <xsl:when test="$G_vboxGlueStyle='jaxws'">
3578 <xsl:if test="not($module) and not(@wsmap='suppress') and not(@wsmap='global')">
3579 <xsl:call-template name="genIface">
3580 <xsl:with-param name="ifname" select="@name" />
3581 <xsl:with-param name="filename" select="concat(@name, '.java')" />
3582 </xsl:call-template>
3583 </xsl:if>
3584 </xsl:when>
3585
3586 <xsl:otherwise>
3587 <!-- We don't need WSDL-specific interfaces here -->
3588 <xsl:if test="not($self_target='wsdl') and not($module)">
3589 <xsl:call-template name="genIface">
3590 <xsl:with-param name="ifname" select="@name" />
3591 <xsl:with-param name="filename" select="concat(@name, '.java')" />
3592 </xsl:call-template>
3593 </xsl:if>
3594 </xsl:otherwise>
3595
3596 </xsl:choose>
3597 </xsl:for-each>
3598</xsl:template>
3599</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.

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