VirtualBox

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

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

Java: use byte[] for glue layer (JWS converts from List<Short> atm)

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