VirtualBox

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

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

Java: MSCOM update

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

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