VirtualBox

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

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

export to OSE

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 120.8 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(String mid) throws Exception
2497 {
2498 ISession s = getSessionObject();
2499 try {
2500 this.vbox.openExistingSession(s, mid);
2501 return s;
2502 } catch (Exception e) {
2503 try {
2504 this.vbox.openSession(s, mid);
2505 return s;
2506 } catch (Exception e1) {
2507 closeMachineSession(s);
2508 throw e1;
2509 }
2510 }
2511 }
2512
2513 public ISession openMachineSession(IMachine m) throws Exception
2514 {
2515 return openMachineSession(m.getId());
2516 }
2517
2518 public void closeMachineSession(ISession s)
2519 {
2520 if (s != null)
2521 s.close();
2522 }
2523
2524 private static VirtualBoxManager mgr;
2525
2526 public static synchronized VirtualBoxManager getInstance(String home)
2527 {
2528 if (mgr != null)
2529 return mgr;
2530
2531 if (home == null)
2532 home = System.getProperty("vbox.home");
2533
2534 File grePath = new File(home);
2535 Mozilla mozilla = Mozilla.getInstance();
2536 mozilla.initialize(grePath);
2537 nsIServiceManager servMgr = null;
2538 try {
2539 servMgr = mozilla.initXPCOM(grePath, null);
2540 } catch (Exception e) {
2541 e.printStackTrace();
2542 return null;
2543 }
2544
2545 mgr = new VirtualBoxManager(mozilla, servMgr);
2546 return mgr;
2547 }
2548
2549 public IEventListener createListener(Object sink)
2550 {
2551 return new IEventListener(new EventListenerImpl(sink));
2552 }
2553 public void cleanup()
2554 {
2555 deinitPerThread();
2556 // cleanup
2557 mozilla.shutdownXPCOM(servMgr);
2558 mozilla = null;
2559 }
2560
2561 public boolean progressBar(IProgress p, int wait)
2562 {
2563 long end = System.currentTimeMillis() + wait;
2564 while (!p.getCompleted())
2565 {
2566 mozilla.waitForEvents(0);
2567 p.waitForCompletion(wait);
2568 if (System.currentTimeMillis() >= end)
2569 return false;
2570 }
2571
2572 return true;
2573 }
2574
2575 public boolean startVm(String name, String type, int timeout)
2576 {
2577 IMachine m = vbox.findMachine(name);
2578 if (m == null)
2579 return false;
2580 ISession session = getSessionObject();
2581
2582 String mid = m.getId();
2583 if (type == null)
2584 type = "gui";
2585 IProgress p = vbox.openRemoteSession(session, mid, type, "");
2586 progressBar(p, timeout);
2587 session.close();
2588 return true;
2589 }
2590
2591 public void waitForEvents(long tmo)
2592 {
2593 mozilla.waitForEvents(tmo);
2594 }
2595}
2596]]></xsl:text>
2597
2598 <xsl:call-template name="endFile">
2599 <xsl:with-param name="file" select="'VirtualBoxManager.java'" />
2600 </xsl:call-template>
2601
2602 <xsl:call-template name="startFile">
2603 <xsl:with-param name="file" select="'EventListenerImpl.java'" />
2604 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
2605 </xsl:call-template>
2606
2607 <xsl:text><![CDATA[
2608 import org.mozilla.interfaces.*;
2609
2610 public class EventListenerImpl extends nsISupportsBase implements org.mozilla.interfaces.IEventListener
2611 {
2612 private Object obj;
2613 private java.lang.reflect.Method handleEvent;
2614 EventListenerImpl(Object obj)
2615 {
2616 this.obj = obj;
2617 try {
2618 this.handleEvent = obj.getClass().getMethod("handleEvent", IEvent.class);
2619 } catch (Exception e) {
2620 e.printStackTrace();
2621 }
2622 }
2623 public void handleEvent(org.mozilla.interfaces.IEvent ev)
2624 {
2625 try {
2626 if (obj != null && handleEvent != null)
2627 handleEvent.invoke(obj, ev != null ? new IEvent(ev) : null);
2628 } catch (Exception e) {
2629 e.printStackTrace();
2630 }
2631 }
2632 }]]></xsl:text>
2633
2634 <xsl:call-template name="endFile">
2635 <xsl:with-param name="file" select="'EventListenerImpl.java'" />
2636 </xsl:call-template>
2637
2638 <xsl:call-template name="startFile">
2639 <xsl:with-param name="file" select="'VBoxObjectBase.java'" />
2640 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
2641 </xsl:call-template>
2642
2643<xsl:text><![CDATA[
2644abstract class nsISupportsBase implements org.mozilla.interfaces.nsISupports
2645{
2646 public org.mozilla.interfaces.nsISupports queryInterface(String iid)
2647 {
2648 return org.mozilla.xpcom.Mozilla.queryInterface(this, iid);
2649 }
2650}
2651
2652]]></xsl:text><xsl:call-template name="endFile">
2653 <xsl:with-param name="file" select="'VBoxObjectBase.java'" />
2654 </xsl:call-template>
2655
2656</xsl:template>
2657
2658
2659<xsl:template name="emitHandwrittenMscom">
2660
2661<xsl:call-template name="startFile">
2662 <xsl:with-param name="file" select="'IUnknown.java'" />
2663 <xsl:with-param name="package" select="$G_virtualBoxPackageCom" />
2664 </xsl:call-template>
2665
2666 <xsl:text><![CDATA[
2667public class IUnknown
2668{
2669 private Object obj;
2670 public IUnknown(Object obj)
2671 {
2672 this.obj = obj;
2673 }
2674
2675 public Object getWrapped()
2676 {
2677 return this.obj;
2678 }
2679
2680 public void setWrapped(Object obj)
2681 {
2682 this.obj = obj;
2683 }
2684}
2685]]></xsl:text>
2686
2687 <xsl:call-template name="endFile">
2688 <xsl:with-param name="file" select="'IUnknown.java'" />
2689 </xsl:call-template>
2690
2691<xsl:call-template name="startFile">
2692 <xsl:with-param name="file" select="'Helper.java'" />
2693 <xsl:with-param name="package" select="$G_virtualBoxPackageCom" />
2694 </xsl:call-template>
2695
2696<xsl:text><![CDATA[
2697
2698import java.util.List;
2699import java.util.ArrayList;
2700import java.util.Collections;
2701import java.lang.reflect.Array;
2702import java.lang.reflect.Constructor;
2703import java.lang.reflect.InvocationTargetException;
2704import java.math.BigInteger;
2705import com.jacob.com.*;
2706
2707public class Helper {
2708 public static List<Short> wrap(short[] vals) {
2709 if (vals==null) return null;
2710 if (vals.length == 0) return Collections.emptyList();
2711
2712 List<Short> ret = new ArrayList<Short>(vals.length);
2713 for (short v : vals) {
2714 ret.add(v);
2715 }
2716 return ret;
2717 }
2718
2719 public static List<Integer> wrap(int[] vals) {
2720 if (vals == null) return null;
2721 if (vals.length == 0) return Collections.emptyList();
2722
2723 List<Integer> ret = new ArrayList<Integer>(vals.length);
2724 for (int v : vals) {
2725 ret.add(v);
2726 }
2727 return ret;
2728 }
2729
2730 public static List<Long> wrap(long[] vals) {
2731 if (vals==null) return null;
2732 if (vals.length == 0) return Collections.emptyList();
2733
2734 List<Long> ret = new ArrayList<Long>(vals.length);
2735 for (long v : vals) {
2736 ret.add(v);
2737 }
2738 return ret;
2739 }
2740
2741 public static List<String> wrap(String[] vals) {
2742 if (vals==null) return null;
2743 if (vals.length == 0) return Collections.emptyList();
2744
2745 List<String> ret = new ArrayList<String>(vals.length);
2746 for (String v : vals) {
2747 ret.add(v);
2748 }
2749 return ret;
2750 }
2751
2752 public static <T> T wrapDispatch(Class<T> wrapperClass, Dispatch d)
2753 {
2754 try {
2755 if (d == null || d.m_pDispatch == 0)
2756 return null;
2757 Constructor<T> c = wrapperClass.getConstructor(Dispatch.class);
2758 return (T)c.newInstance(d);
2759 } catch (NoSuchMethodException e) {
2760 throw new AssertionError(e);
2761 } catch (InstantiationException e) {
2762 throw new AssertionError(e);
2763 } catch (IllegalAccessException e) {
2764 throw new AssertionError(e);
2765 } catch (InvocationTargetException e) {
2766 throw new AssertionError(e);
2767 }
2768 }
2769
2770 public static <T> Object wrapVariant(Class<T> wrapperClass, Variant v)
2771 {
2772 if (v == null)
2773 return null;
2774
2775 short vt = v.getvt();
2776 switch (vt)
2777 {
2778 case Variant.VariantNull:
2779 return null;
2780 case Variant.VariantBoolean:
2781 return v.getBoolean();
2782 case Variant.VariantByte:
2783 return v.getByte();
2784 case Variant.VariantShort:
2785 return v.getShort();
2786 case Variant.VariantInt:
2787 return v.getInt();
2788 case Variant.VariantLongInt:
2789 return v.getLong();
2790 case Variant.VariantString:
2791 return v.getString();
2792 case Variant.VariantDispatch:
2793 return wrapDispatch(wrapperClass, v.getDispatch());
2794 default:
2795 throw new RuntimeException("unhandled variant type "+vt);
2796 }
2797 }
2798
2799 public static <T> List<T> wrap(Class<T> wrapperClass, SafeArray sa) {
2800 if (sa==null) return null;
2801
2802 int saLen = sa.getUBound() - sa.getLBound() + 1;
2803 if (saLen == 0) return Collections.emptyList();
2804
2805 List<T> ret = new ArrayList<T>(saLen);
2806 for (int i = sa.getLBound(); i <= sa.getUBound(); i++)
2807 {
2808 Variant v = sa.getVariant(i);
2809 ret.add((T)wrapVariant(wrapperClass, v));
2810 }
2811 return ret;
2812 }
2813
2814 public static <T> List<T> wrapEnum(Class<T> wrapperClass, SafeArray sa) {
2815 try {
2816 if (sa==null) return null;
2817
2818 int saLen = sa.getUBound() - sa.getLBound() + 1;
2819 if (saLen == 0) return Collections.emptyList();
2820 List<T> ret = new ArrayList<T>(saLen);
2821 Constructor<T> c = wrapperClass.getConstructor(int.class);
2822 for (int i = sa.getLBound(); i <= sa.getUBound(); i++)
2823 {
2824 Variant v = sa.getVariant(i);
2825 ret.add(c.newInstance(v.getInt()));
2826 }
2827 return ret;
2828 } catch (NoSuchMethodException e) {
2829 throw new AssertionError(e);
2830 } catch (InstantiationException e) {
2831 throw new AssertionError(e);
2832 } catch (IllegalAccessException e) {
2833 throw new AssertionError(e);
2834 } catch (InvocationTargetException e) {
2835 throw new AssertionError(e);
2836 }
2837 }
2838
2839 public static SafeArray unwrapInt(List<Integer> vals) {
2840 if (vals==null) return null;
2841 SafeArray ret = new SafeArray(Variant.VariantInt, vals.size());
2842 int i = 0;
2843 for (int l : vals) {
2844 ret.setInt(i++, l);
2845 }
2846 return ret;
2847 }
2848
2849 public static SafeArray unwrapLong(List<Long> vals) {
2850 if (vals==null) return null;
2851 SafeArray ret = new SafeArray(Variant.VariantLongInt, vals.size());
2852 int i = 0;
2853 for (long l : vals) {
2854 ret.setLong(i++, l);
2855 }
2856 return ret;
2857 }
2858
2859 public static SafeArray unwrapBool(List<Boolean> vals) {
2860 if (vals==null) return null;
2861
2862 SafeArray result = new SafeArray(Variant.VariantBoolean, vals.size());
2863 int i = 0;
2864 for (boolean l : vals) {
2865 result.setBoolean(i, l);
2866 }
2867 return result;
2868 }
2869
2870 public static <T extends Enum <T>> SafeArray unwrapEnum(Class<T> enumClass, List<T> values) {
2871 if (values == null) return null;
2872
2873 SafeArray result = new SafeArray(Variant.VariantInt, values.size());
2874 try {
2875 java.lang.reflect.Method valueM = enumClass.getMethod("value");
2876 int i = 0;
2877 for (T v : values) {
2878 result.setInt(i, (Integer)valueM.invoke(v));
2879 }
2880 return result;
2881 } catch (NoSuchMethodException e) {
2882 throw new AssertionError(e);
2883 } catch(SecurityException e) {
2884 throw new AssertionError(e);
2885 } catch (IllegalAccessException e) {
2886 throw new AssertionError(e);
2887 } catch (IllegalArgumentException e) {
2888 throw new AssertionError(e);
2889 } catch (InvocationTargetException e) {
2890 throw new AssertionError(e);
2891 }
2892 }
2893 public static SafeArray unwrapString(List<String> vals) {
2894 if (vals==null)
2895 return null;
2896 SafeArray result = new SafeArray(Variant.VariantString, vals.size());
2897 int i = 0;
2898 for (String l : vals) {
2899 result.setString(i, l);
2900 }
2901 return result;
2902 }
2903
2904 public static <T1, T2> List<T1> wrap2(Class<T1> wrapperClass1, Class<T2> wrapperClass2, T2[] thisPtrs) {
2905 try {
2906 if (thisPtrs==null) return null;
2907 if (thisPtrs.length == 0) return Collections.emptyList();
2908
2909 Constructor<T1> c = wrapperClass1.getConstructor(wrapperClass2);
2910 List<T1> ret = new ArrayList<T1>(thisPtrs.length);
2911 for (T2 thisPtr : thisPtrs) {
2912 ret.add(c.newInstance(thisPtr));
2913 }
2914 return ret;
2915 } catch (NoSuchMethodException e) {
2916 throw new AssertionError(e);
2917 } catch (InstantiationException e) {
2918 throw new AssertionError(e);
2919 } catch (IllegalAccessException e) {
2920 throw new AssertionError(e);
2921 } catch (InvocationTargetException e) {
2922 throw new AssertionError(e);
2923 }
2924 }
2925
2926 public static <T> T[] unwrap(Class<T> wrapperClass, List<T> thisPtrs) {
2927 if (thisPtrs==null) return null;
2928 return (T[])thisPtrs.toArray((T[])Array.newInstance(wrapperClass, thisPtrs.size()));
2929 }
2930
2931 public static <T1 extends IUnknown,T2> T2[] unwrap2(Class<T1> wrapperClass1, Class<T2> wrapperClass2, List<T1> thisPtrs) {
2932 if (thisPtrs==null) return null;
2933
2934 T2 ret[] = (T2[])Array.newInstance(wrapperClass2, thisPtrs.size());
2935 int i = 0;
2936 for (T1 obj : thisPtrs) {
2937 ret[i++] = (T2)obj.getWrapped();
2938 }
2939 return ret;
2940 }
2941
2942 public static BigInteger longToBigInteger(long value) {
2943 return BigInteger.valueOf(value);
2944 }
2945
2946 /* We have very long invoke lists sometimes */
2947 public static Variant invoke(Dispatch d, String method, Object ... args)
2948 {
2949 return Dispatch.callN(d, method, args);
2950 }
2951}
2952]]></xsl:text>
2953
2954 <xsl:call-template name="endFile">
2955 <xsl:with-param name="file" select="'Helper.java'" />
2956 </xsl:call-template>
2957
2958
2959 <xsl:call-template name="startFile">
2960 <xsl:with-param name="file" select="'VirtualBoxManager.java'" />
2961 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
2962 </xsl:call-template>
2963
2964 <xsl:text><![CDATA[
2965
2966import com.jacob.activeX.ActiveXComponent;
2967import com.jacob.com.ComThread;
2968import com.jacob.com.Dispatch;
2969import com.jacob.com.Variant;
2970import com.jacob.com.SafeArray;
2971import com.jacob.com.DispatchEvents;
2972
2973public class VirtualBoxManager
2974{
2975 private IVirtualBox vbox;
2976
2977 private VirtualBoxManager()
2978 {
2979 initPerThread();
2980 vbox = new IVirtualBox(new ActiveXComponent("VirtualBox.VirtualBox"));
2981 }
2982
2983 public static void initPerThread()
2984 {
2985 ComThread.InitMTA();
2986 }
2987
2988 public static void deinitPerThread()
2989 {
2990 ComThread.Release();
2991 }
2992
2993 public void connect(String url, String username, String passwd)
2994 {
2995 throw new RuntimeException("Connect doesn't make sense for local bindings");
2996 }
2997
2998 public void disconnect()
2999 {
3000 throw new RuntimeException("Disconnect doesn't make sense for local bindings");
3001 }
3002
3003 public IVirtualBox getVBox()
3004 {
3005 return this.vbox;
3006 }
3007
3008 public ISession getSessionObject()
3009 {
3010 return new ISession(new ActiveXComponent("VirtualBox.Session"));
3011 }
3012
3013 public ISession openMachineSession(String mid) throws Exception
3014 {
3015 ISession s = getSessionObject();
3016 try {
3017 this.vbox.openExistingSession(s, mid);
3018 return s;
3019 } catch (Exception e) {
3020 try {
3021 this.vbox.openSession(s, mid);
3022 return s;
3023 } catch (Exception e1) {
3024 closeMachineSession(s);
3025 throw e1;
3026 }
3027 }
3028 }
3029
3030 public ISession openMachineSession(IMachine m) throws Exception
3031 {
3032 return openMachineSession(m.getId());
3033 }
3034
3035 public void closeMachineSession(ISession s)
3036 {
3037 if (s != null)
3038 s.close();
3039 }
3040
3041 private static VirtualBoxManager mgr;
3042
3043 public static synchronized VirtualBoxManager getInstance(String home)
3044 {
3045 if (mgr != null)
3046 return mgr;
3047
3048 if (home == null)
3049 home = System.getProperty("vbox.home");
3050
3051 mgr = new VirtualBoxManager();
3052 return mgr;
3053 }
3054
3055 public void cleanup()
3056 {
3057 deinitPerThread();
3058 mgr = null;
3059 }
3060
3061 public boolean progressBar(IProgress p, int wait)
3062 {
3063 long end = System.currentTimeMillis() + wait;
3064 while (!p.getCompleted())
3065 {
3066 p.waitForCompletion(wait);
3067 if (System.currentTimeMillis() >= end)
3068 return false;
3069 }
3070
3071 return true;
3072 }
3073
3074 public boolean startVm(String name, String type, int timeout)
3075 {
3076 IMachine m = vbox.findMachine(name);
3077 if (m == null)
3078 return false;
3079 ISession session = getSessionObject();
3080
3081 String mid = m.getId();
3082 if (type == null)
3083 type = "gui";
3084 IProgress p = vbox.openRemoteSession(session, mid, type, "");
3085 progressBar(p, timeout);
3086 session.close();
3087 return true;
3088 }
3089
3090 public void waitForEvents(long tmo)
3091 {
3092 // what to do here?
3093 try {
3094 Thread.sleep(tmo);
3095 } catch (InterruptedException ie) {
3096 }
3097 }
3098}
3099]]></xsl:text>
3100
3101 <xsl:call-template name="endFile">
3102 <xsl:with-param name="file" select="'VirtualBoxManager.java'" />
3103 </xsl:call-template>
3104
3105</xsl:template>
3106
3107<xsl:template name="emitHandwrittenJaxws">
3108
3109 <xsl:call-template name="startFile">
3110 <xsl:with-param name="file" select="'IUnknown.java'" />
3111 <xsl:with-param name="package" select="$G_virtualBoxPackageCom" />
3112 </xsl:call-template>
3113
3114 <xsl:text><![CDATA[
3115public class IUnknown
3116{
3117 protected String obj;
3118 protected final VboxPortType port;
3119
3120 public IUnknown(String obj, VboxPortType port)
3121 {
3122 this.obj = obj;
3123 this.port = port;
3124 }
3125
3126 public final String getWrapped()
3127 {
3128 return this.obj;
3129 }
3130
3131 public final VboxPortType getRemoteWSPort()
3132 {
3133 return this.port;
3134 }
3135
3136 public synchronized void releaseRemote() throws WebServiceException
3137 {
3138 if (obj == null) {
3139 return;
3140 }
3141 try {
3142 this.port.iManagedObjectRefRelease(obj);
3143 this.obj = null;
3144 } catch (InvalidObjectFaultMsg e) {
3145 throw new WebServiceException(e);
3146 } catch (RuntimeFaultMsg e) {
3147 throw new WebServiceException(e);
3148 }
3149 }
3150}
3151]]></xsl:text>
3152
3153 <xsl:call-template name="endFile">
3154 <xsl:with-param name="file" select="'IUnknown.java'" />
3155 </xsl:call-template>
3156
3157 <xsl:call-template name="startFile">
3158 <xsl:with-param name="file" select="'Helper.java'" />
3159 <xsl:with-param name="package" select="$G_virtualBoxPackageCom" />
3160 </xsl:call-template>
3161
3162<xsl:text><![CDATA[
3163
3164import java.util.List;
3165import java.util.ArrayList;
3166import java.util.Collections;
3167import java.lang.reflect.Array;
3168import java.lang.reflect.Constructor;
3169import java.lang.reflect.InvocationTargetException;
3170import java.math.BigInteger;
3171
3172public class Helper {
3173 public static <T> List<T> wrap(Class<T> wrapperClass, VboxPortType pt, List<String> thisPtrs) {
3174 try {
3175 if(thisPtrs==null) return null;
3176
3177 Constructor<T> c = wrapperClass.getConstructor(String.class, VboxPortType.class);
3178 List<T> ret = new ArrayList<T>(thisPtrs.size());
3179 for (String thisPtr : thisPtrs) {
3180 ret.add(c.newInstance(thisPtr,pt));
3181 }
3182 return ret;
3183 } catch (NoSuchMethodException e) {
3184 throw new AssertionError(e);
3185 } catch (InstantiationException e) {
3186 throw new AssertionError(e);
3187 } catch (IllegalAccessException e) {
3188 throw new AssertionError(e);
3189 } catch (InvocationTargetException e) {
3190 throw new AssertionError(e);
3191 }
3192 }
3193
3194 public static <T1, T2> List<T1> wrap2(Class<T1> wrapperClass1, Class<T2> wrapperClass2, VboxPortType pt, List<T2> thisPtrs) {
3195 try {
3196 if(thisPtrs==null) return null;
3197
3198 Constructor<T1> c = wrapperClass1.getConstructor(wrapperClass2, VboxPortType.class);
3199 List<T1> ret = new ArrayList<T1>(thisPtrs.size());
3200 for (T2 thisPtr : thisPtrs) {
3201 ret.add(c.newInstance(thisPtr,pt));
3202 }
3203 return ret;
3204 } catch (NoSuchMethodException e) {
3205 throw new AssertionError(e);
3206 } catch (InstantiationException e) {
3207 throw new AssertionError(e);
3208 } catch (IllegalAccessException e) {
3209 throw new AssertionError(e);
3210 } catch (InvocationTargetException e) {
3211 throw new AssertionError(e);
3212 }
3213 }
3214
3215 public static <T extends IUnknown> List<String> unwrap(List<T> thisPtrs) {
3216 if (thisPtrs==null) return null;
3217
3218 List<String> ret = new ArrayList<String>(thisPtrs.size());
3219 for (T obj : thisPtrs) {
3220 ret.add(obj.getWrapped());
3221 }
3222 return ret;
3223 }
3224
3225 public static <T1 extends Enum <T1>, T2 extends Enum <T2>> List<T2> convertEnums(Class<T1> fromClass,
3226 Class<T2> toClass,
3227 List<T1> values) {
3228 try {
3229 if (values==null)
3230 return null;
3231 java.lang.reflect.Method fromValue = toClass.getMethod("fromValue", String.class);
3232 List<T2> ret = new ArrayList<T2>(values.size());
3233 for (T1 v : values) {
3234 // static method is called with null this
3235 ret.add((T2)fromValue.invoke(null, v.name()));
3236 }
3237 return ret;
3238 } catch (NoSuchMethodException e) {
3239 throw new AssertionError(e);
3240 } catch (IllegalAccessException e) {
3241 throw new AssertionError(e);
3242 } catch (InvocationTargetException e) {
3243 throw new AssertionError(e);
3244 }
3245 }
3246}
3247]]></xsl:text>
3248
3249 <xsl:call-template name="endFile">
3250 <xsl:with-param name="file" select="'Helper.java'" />
3251 </xsl:call-template>
3252
3253 <xsl:call-template name="startFile">
3254 <xsl:with-param name="file" select="'VirtualBoxManager.java'" />
3255 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
3256 </xsl:call-template>
3257
3258import java.net.URL;
3259import java.math.BigInteger;
3260import java.util.List;
3261import java.util.Map;
3262import java.util.HashMap;
3263import javax.xml.namespace.QName;
3264import javax.xml.ws.BindingProvider;
3265import javax.xml.ws.Holder;
3266import javax.xml.ws.WebServiceException;
3267
3268class PortPool
3269{
3270 private final static String wsdlFile = <xsl:value-of select="$G_virtualBoxWsdl" />;
3271
3272 <xsl:text><![CDATA[
3273private Map<VboxPortType, Integer> known;
3274 private boolean initStarted;
3275 private VboxService svc;
3276
3277 PortPool(boolean usePreinit)
3278 {
3279 known = new HashMap<VboxPortType, Integer>();
3280
3281 if (usePreinit)
3282 {
3283 new Thread(new Runnable()
3284 {
3285 public void run()
3286 {
3287 // need to sync on something else but 'this'
3288 synchronized (known)
3289 {
3290 initStarted = true;
3291 known.notify();
3292 }
3293
3294 preinit();
3295 }
3296 }).start();
3297
3298 synchronized (known)
3299 {
3300 while (!initStarted)
3301 {
3302 try {
3303 known.wait();
3304 } catch (InterruptedException e) {
3305 break;
3306 }
3307 }
3308 }
3309 }
3310 }
3311
3312 private synchronized void preinit()
3313 {
3314 VboxPortType port = getPort();
3315 releasePort(port);
3316 }
3317
3318 synchronized VboxPortType getPort()
3319 {
3320 VboxPortType port = null;
3321 int ttl = 0;
3322
3323 for (VboxPortType cur: known.keySet())
3324 {
3325 int value = known.get(cur);
3326 if ((value & 0x10000) == 0)
3327 {
3328 port = cur;
3329 ttl = value & 0xffff;
3330 break;
3331 }
3332 }
3333
3334 if (port == null)
3335 {
3336 if (svc == null) {
3337 URL wsdl = PortPool.class.getClassLoader().getResource(wsdlFile);
3338 if (wsdl == null)
3339 throw new LinkageError(wsdlFile+" not found, but it should have been in the jar");
3340 svc = new VboxService(wsdl,
3341 new QName("http://www.virtualbox.org/Service",
3342 "vboxService"));
3343 }
3344 port = svc.getVboxServicePort();
3345 // reuse this object 0x10 times
3346 ttl = 0x10;
3347 }
3348 // mark as used
3349 known.put(port, new Integer(0x10000 | ttl));
3350 return port;
3351 }
3352
3353 synchronized void releasePort(VboxPortType port)
3354 {
3355 Integer val = known.get(port);
3356 if (val == null || val == 0)
3357 {
3358 // know you not
3359 return;
3360 }
3361
3362 int v = val;
3363 int ttl = v & 0xffff;
3364 // decrement TTL, and throw away port if used too much times
3365 if (--ttl <= 0)
3366 {
3367 known.remove(port);
3368 }
3369 else
3370 {
3371 v = ttl; // set new TTL and clear busy bit
3372 known.put(port, v);
3373 }
3374 }
3375}
3376
3377
3378public class VirtualBoxManager
3379{
3380 private static PortPool pool = new PortPool(true);
3381 protected VboxPortType port;
3382
3383 private IVirtualBox vbox;
3384
3385 private VirtualBoxManager()
3386 {
3387 }
3388
3389 public static void initPerThread()
3390 {
3391 }
3392
3393 public static void deinitPerThread()
3394 {
3395 }
3396
3397 public void connect(String url, String username, String passwd)
3398 {
3399 this.port = pool.getPort();
3400 try {
3401 ((BindingProvider)port).getRequestContext().
3402 put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
3403 String handle = port.iWebsessionManagerLogon(username, passwd);
3404 this.vbox = new IVirtualBox(handle, port);
3405 } catch (Throwable t) {
3406 if (this.port != null)
3407 pool.releasePort(this.port);
3408 // we have to throw smth derived from RuntimeException
3409 throw new VBoxException(t, t.getMessage());
3410 }
3411 }
3412
3413 public void connect(String url, String username, String passwd,
3414 Map<String, Object> requestContext, Map<String, Object> responseContext)
3415 {
3416 this.port = pool.getPort();
3417
3418 try {
3419 ((BindingProvider)port).getRequestContext();
3420 if (requestContext != null)
3421 ((BindingProvider)port).getRequestContext().putAll(requestContext);
3422
3423 if (responseContext != null)
3424 ((BindingProvider)port).getResponseContext().putAll(responseContext);
3425
3426 ((BindingProvider)port).getRequestContext().
3427 put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
3428 String handle = port.iWebsessionManagerLogon(username, passwd);
3429 this.vbox = new IVirtualBox(handle, port);
3430 } catch (Throwable t) {
3431 if (this.port != null)
3432 pool.releasePort(port);
3433 // we have to throw smth derived from RuntimeException
3434 throw new VBoxException(t, t.getMessage());
3435 }
3436 }
3437
3438 public void disconnect()
3439 {
3440 try {
3441 if (this.vbox != null)
3442 port.iWebsessionManagerLogoff(this.vbox.getWrapped());
3443 } catch (InvalidObjectFaultMsg e) {
3444 throw new VBoxException(e, e.getMessage());
3445 } catch (RuntimeFaultMsg e) {
3446 throw new VBoxException(e, e.getMessage());
3447 } finally {
3448 if (this.port != null) {
3449 pool.releasePort(this.port);
3450 this.port = null;
3451 }
3452 }
3453 }
3454
3455 public IVirtualBox getVBox()
3456 {
3457 return this.vbox;
3458 }
3459
3460 public ISession getSessionObject()
3461 {
3462 if (this.vbox == null)
3463 throw new RuntimeException("connect first");
3464 try {
3465 String handle = port.iWebsessionManagerGetSessionObject(this.vbox.getWrapped());
3466 return new ISession(handle, port);
3467 } catch (InvalidObjectFaultMsg e) {
3468 throw new VBoxException(e, e.getMessage());
3469 } catch (RuntimeFaultMsg e) {
3470 throw new VBoxException(e, e.getMessage());
3471 }
3472 }
3473
3474 public ISession openMachineSession(String mid) throws Exception
3475 {
3476 ISession s = getSessionObject();
3477 try {
3478 this.vbox.openExistingSession(s, mid);
3479 return s;
3480 } catch (Exception e) {
3481 try {
3482 this.vbox.openSession(s, mid);
3483 return s;
3484 } catch (Exception e1) {
3485 closeMachineSession(s);
3486 throw e1;
3487 }
3488 }
3489 }
3490
3491 public ISession openMachineSession(IMachine m) throws Exception
3492 {
3493 return openMachineSession(m.getId());
3494 }
3495
3496 public void closeMachineSession(ISession s)
3497 {
3498 if (s != null)
3499 s.close();
3500 }
3501
3502 private static VirtualBoxManager mgr;
3503
3504 public static synchronized VirtualBoxManager getInstance(String home)
3505 {
3506 if (mgr != null)
3507 return mgr;
3508
3509 mgr = new VirtualBoxManager();
3510 return mgr;
3511 }
3512
3513 public IEventListener createListener(Object sink)
3514 {
3515 throw new RuntimeException("no active listeners here");
3516 }
3517 public void cleanup()
3518 {
3519 deinitPerThread();
3520 }
3521
3522 public boolean progressBar(IProgress p, int wait)
3523 {
3524 long end = System.currentTimeMillis() + wait;
3525 while (!p.getCompleted())
3526 {
3527 p.waitForCompletion(wait);
3528 if (System.currentTimeMillis() >= end)
3529 return false;
3530 }
3531
3532 return true;
3533 }
3534
3535 public boolean startVm(String name, String type, int timeout)
3536 {
3537 IMachine m = vbox.findMachine(name);
3538 if (m == null)
3539 return false;
3540 ISession session = getSessionObject();
3541
3542 String mid = m.getId();
3543 if (type == null)
3544 type = "gui";
3545 IProgress p = vbox.openRemoteSession(session, mid, type, "");
3546 progressBar(p, timeout);
3547 session.close();
3548 return true;
3549 }
3550
3551 public void waitForEvents(long tmo)
3552 {
3553 }
3554}
3555]]></xsl:text>
3556
3557 <xsl:call-template name="endFile">
3558 <xsl:with-param name="file" select="'VirtualBoxManager.java'" />
3559 </xsl:call-template>
3560
3561</xsl:template>
3562
3563
3564<xsl:template match="/">
3565
3566 <xsl:if test="not($G_vboxApiSuffix)">
3567 <xsl:call-template name="fatalError">
3568 <xsl:with-param name="msg" select="'G_vboxApiSuffix must be given'" />
3569 </xsl:call-template>
3570 </xsl:if>
3571
3572 <!-- Handwritten files -->
3573 <xsl:call-template name="emitHandwritten"/>
3574
3575 <xsl:choose>
3576 <xsl:when test="$G_vboxGlueStyle='xpcom'">
3577 <xsl:call-template name="emitHandwrittenXpcom"/>
3578 </xsl:when>
3579
3580 <xsl:when test="$G_vboxGlueStyle='mscom'">
3581 <xsl:call-template name="emitHandwrittenMscom"/>
3582 </xsl:when>
3583
3584 <xsl:when test="$G_vboxGlueStyle='jaxws'">
3585 <xsl:call-template name="emitHandwrittenJaxws"/>
3586 </xsl:when>
3587
3588 <xsl:otherwise>
3589 <xsl:call-template name="fatalError">
3590 <xsl:with-param name="msg" select="'Style unknown (root)'" />
3591 </xsl:call-template>
3592 </xsl:otherwise>
3593 </xsl:choose>
3594
3595 <!-- Enums -->
3596 <xsl:for-each select="//enum">
3597 <xsl:call-template name="genEnum">
3598 <xsl:with-param name="enumname" select="@name" />
3599 <xsl:with-param name="filename" select="concat(@name, '.java')" />
3600 </xsl:call-template>
3601 </xsl:for-each>
3602
3603 <!-- Interfaces -->
3604 <xsl:for-each select="//interface">
3605 <xsl:variable name="self_target" select="current()/ancestor::if/@target"/>
3606 <xsl:variable name="module" select="current()/ancestor::module/@name"/>
3607
3608 <xsl:choose>
3609 <xsl:when test="$G_vboxGlueStyle='jaxws'">
3610 <xsl:if test="not($module) and not(@wsmap='suppress') and not(@wsmap='global')">
3611 <xsl:call-template name="genIface">
3612 <xsl:with-param name="ifname" select="@name" />
3613 <xsl:with-param name="filename" select="concat(@name, '.java')" />
3614 </xsl:call-template>
3615 </xsl:if>
3616 </xsl:when>
3617
3618 <xsl:otherwise>
3619 <!-- We don't need WSDL-specific interfaces here -->
3620 <xsl:if test="not($self_target='wsdl') and not($module)">
3621 <xsl:call-template name="genIface">
3622 <xsl:with-param name="ifname" select="@name" />
3623 <xsl:with-param name="filename" select="concat(@name, '.java')" />
3624 </xsl:call-template>
3625 </xsl:if>
3626 </xsl:otherwise>
3627
3628 </xsl:choose>
3629 </xsl:for-each>
3630</xsl:template>
3631</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.

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