VirtualBox

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

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

Java bridge: allow multiple concurrent SOAP connections

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

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