VirtualBox

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

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

Java XPCOM bridge: cleanup, survive multiple inits

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