VirtualBox

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

Last change on this file since 60682 was 56625, checked in by vboxsync, 9 years ago

doc/SDKRef: Document how to run the system event queue when using the Java binding, and make more use of it in the sample code (which already used it, and the method was already there since day 1), plus a fix in the webservice case.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 156.0 KB
Line 
1<xsl:stylesheet version = '1.0'
2 xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
3 xmlns:vbox="http://www.virtualbox.org/"
4 xmlns:exsl="http://exslt.org/common"
5 extension-element-prefixes="exsl">
6
7<!--
8
9 glue-java.xsl:
10 XSLT stylesheet that generates Java glue code for XPCOM, MSCOM and JAX-WS from
11 VirtualBox.xidl.
12
13 Copyright (C) 2010-2015 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('&quot;vboxwebService', $G_vboxApiSuffix, '.wsdl&quot;')" />
38<!-- collect all interfaces with "wsmap='suppress'" in a global variable for quick lookup -->
39<xsl:variable name="G_setSuppressedInterfaces"
40 select="//interface[@wsmap='suppress']" />
41
42<xsl:include href="../idl/typemap-shared.inc.xsl" />
43
44<xsl:strip-space elements="*"/>
45
46
47<!-- - - - - - - - - - - - - - - - - - - - - - -
48 Keys for more efficiently looking up of types.
49 - - - - - - - - - - - - - - - - - - - - - - -->
50
51<xsl:key name="G_keyEnumsByName" match="//enum[@name]" use="@name"/>
52<xsl:key name="G_keyInterfacesByName" match="//interface[@name]" use="@name"/>
53
54
55<!-- - - - - - - - - - - - - - - - - - - - - - -
56 - - - - - - - - - - - - - - - - - - - - - - -->
57
58<xsl:template name="fileheader">
59 <xsl:param name="name" />
60 <xsl:text>/*
61 * Copyright (C) 2010-2015 Oracle Corporation
62 *
63 * This file is part of the VirtualBox SDK, as available from
64 * http://www.virtualbox.org. This library is free software; you can
65 * redistribute it and/or modify it under the terms of the GNU Lesser General
66 * Public License as published by the Free Software Foundation, in version 2.1
67 * as it comes in the "COPYING.LIB" file of the VirtualBox SDK distribution.
68 * This library is distributed in the hope that it will be useful, but WITHOUT
69 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
70 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
71 * License for more details.
72 *
73</xsl:text>
74 <xsl:value-of select="concat(' * ', $name)"/>
75<xsl:text>
76 *
77 * DO NOT EDIT! This is a generated file.
78 * Generated from: src/VBox/Main/idl/VirtualBox.xidl (VirtualBox's interface definitions in XML)
79 * Generator: src/VBox/Main/glue/glue-java.xsl
80 */
81
82</xsl:text>
83</xsl:template>
84
85<xsl:template name="startFile">
86 <xsl:param name="file" />
87 <xsl:param name="package" />
88
89 <xsl:choose>
90 <xsl:when test="$filelistonly=''">
91 <xsl:value-of select="concat('&#10;// ##### BEGINFILE &quot;', $G_vboxDirPrefix, $file, '&quot;&#10;&#10;')" />
92 <xsl:call-template name="fileheader">
93 <xsl:with-param name="name" select="$file" />
94 </xsl:call-template>
95
96 <xsl:value-of select="concat('package ', $package, ';&#10;&#10;')" />
97 <xsl:value-of select="concat('import ', $G_virtualBoxPackageCom, '.*;&#10;')" />
98
99 <xsl:choose>
100 <xsl:when test="$G_vboxGlueStyle='xpcom'">
101 <xsl:text>import org.mozilla.interfaces.*;&#10;</xsl:text>
102 </xsl:when>
103
104 <xsl:when test="$G_vboxGlueStyle='mscom'">
105 <xsl:text>import com.jacob.com.*;&#10;</xsl:text>
106 <xsl:text>import com.jacob.activeX.ActiveXComponent;&#10;</xsl:text>
107 </xsl:when>
108
109 <xsl:when test="$G_vboxGlueStyle='jaxws'">
110 <xsl:text>import javax.xml.ws.*;&#10;</xsl:text>
111 </xsl:when>
112
113 <xsl:otherwise>
114 <xsl:call-template name="fatalError">
115 <xsl:with-param name="msg" select="'no header rule (startFile)'" />
116 </xsl:call-template>
117 </xsl:otherwise>
118 </xsl:choose>
119 </xsl:when>
120 <xsl:otherwise>
121 <xsl:value-of select="concat(' \', $G_sNewLine, '&#9;', $G_vboxDirPrefix, $file)"/>
122 </xsl:otherwise>
123 </xsl:choose>
124</xsl:template>
125
126<xsl:template name="endFile">
127 <xsl:param name="file" />
128 <xsl:if test="$filelistonly=''">
129 <xsl:value-of select="concat('&#10;// ##### ENDFILE &quot;', $file, '&quot;&#10;')" />
130 <xsl:call-template name="xsltprocNewlineOutputHack"/>
131 </xsl:if>
132</xsl:template>
133
134<!-- strip-and-normalize-desc
135 Removes leading and trailing white space on each line in the given text.
136 -->
137<xsl:template name="strip-and-normalize-desc">
138 <xsl:param name="text"/>
139
140 <!-- Strip the whole string first so we won't leave trailing new line chars behind. -->
141 <xsl:variable name="sStrippedText">
142 <xsl:call-template name="strip-string">
143 <xsl:with-param name="text" select="$text"/>
144 </xsl:call-template>
145 </xsl:variable>
146
147 <xsl:choose>
148 <!-- If there are multiple lines, strip them one by one on a recursive fasion. -->
149 <xsl:when test="contains($sStrippedText, '&#10;')">
150 <xsl:call-template name="strip-string-right">
151 <xsl:with-param name="text" select="substring-before($sStrippedText, '&#10;')"/>
152 </xsl:call-template>
153 <xsl:value-of select="'&#10;'"/>
154 <xsl:call-template name="strip-and-normalize-desc-recursive">
155 <xsl:with-param name="text" select="substring-after($sStrippedText, '&#10;')"/>
156 </xsl:call-template>
157 </xsl:when>
158
159 <!-- Single line, we're done. -->
160 <xsl:otherwise>
161 <xsl:value-of select="$sStrippedText"/>
162 </xsl:otherwise>
163 </xsl:choose>
164
165</xsl:template>
166
167<!-- Internal worker for strip-and-normalize-desc, don't use. -->
168<xsl:template name="strip-and-normalize-desc-recursive">
169 <xsl:param name="text"/>
170
171 <xsl:choose>
172 <!-- If there are multiple lines, strip them one by one on a recursive fasion. -->
173 <xsl:when test="contains($text, '&#10;')">
174 <xsl:call-template name="strip-string">
175 <xsl:with-param name="text" select="substring-before($text, '&#10;')"/>
176 </xsl:call-template>
177 <xsl:value-of select="'&#10;'"/>
178 <xsl:call-template name="strip-and-normalize-desc-recursive">
179 <xsl:with-param name="text" select="substring-after($text, '&#10;')"/>
180 </xsl:call-template>
181 </xsl:when>
182
183 <!-- Single line: Left strip it. -->
184 <xsl:otherwise>
185 <xsl:call-template name="strip-string-left">
186 <xsl:with-param name="text" select="$text"/>
187 </xsl:call-template>
188 </xsl:otherwise>
189 </xsl:choose>
190
191</xsl:template>
192
193<!-- descriptions -->
194
195<xsl:template match="*/text()">
196 <!-- TODO: strip out @c/@a for now. long term solution is changing that to a
197 tag in the xidl file, and translate it when generating doxygen etc. -->
198 <xsl:variable name="rep1">
199 <xsl:call-template name="string-replace">
200 <xsl:with-param name="haystack" select="."/>
201 <xsl:with-param name="needle" select="'@c'"/>
202 <xsl:with-param name="replacement" select="''"/>
203 </xsl:call-template>
204 </xsl:variable>
205
206 <xsl:variable name="rep2">
207 <xsl:call-template name="string-replace">
208 <xsl:with-param name="haystack" select="$rep1"/>
209 <xsl:with-param name="needle" select="'@a'"/>
210 <xsl:with-param name="replacement" select="''"/>
211 </xsl:call-template>
212 </xsl:variable>
213
214 <xsl:variable name="rep3">
215 <xsl:call-template name="string-replace">
216 <xsl:with-param name="haystack" select="$rep2"/>
217 <xsl:with-param name="needle" select="'@todo'"/>
218 <xsl:with-param name="replacement" select="'TODO'"/>
219 </xsl:call-template>
220 </xsl:variable>
221
222 <!-- &amp;, &lt; and &gt; must remain as they are or javadoc 8 throws a fit. -->
223 <xsl:variable name="rep4">
224 <xsl:call-template name="string-replace">
225 <xsl:with-param name="haystack" select="$rep3"/>
226 <xsl:with-param name="needle" select="'&amp;'"/>
227 <xsl:with-param name="replacement" select="'&amp;amp;'"/>
228 </xsl:call-template>
229 </xsl:variable>
230 <xsl:variable name="rep5">
231 <xsl:call-template name="string-replace">
232 <xsl:with-param name="haystack" select="$rep4"/>
233 <xsl:with-param name="needle" select="'&lt;'"/>
234 <xsl:with-param name="replacement" select="'&amp;lt;'"/>
235 </xsl:call-template>
236 </xsl:variable>
237 <xsl:variable name="rep6">
238 <xsl:call-template name="string-replace">
239 <xsl:with-param name="haystack" select="$rep5"/>
240 <xsl:with-param name="needle" select="'&gt;'"/>
241 <xsl:with-param name="replacement" select="'&amp;gt;'"/>
242 </xsl:call-template>
243 </xsl:variable>
244
245 <xsl:variable name="rep7">
246 <xsl:call-template name="strip-and-normalize-desc">
247 <xsl:with-param name="text" select="$rep6"/>
248 </xsl:call-template>
249 </xsl:variable>
250
251 <xsl:value-of select="$rep7"/>
252</xsl:template>
253
254<!--
255 * all sub-elements that are not explicitly matched are considered to be
256 * html tags and copied w/o modifications
257-->
258<xsl:template match="desc//*">
259 <xsl:variable name="tagname" select="local-name()"/>
260 <xsl:value-of select="concat('&lt;', $tagname)"/>
261 <xsl:if test="$tagname = 'table'"> <!-- javadoc 8 fudge -->
262 <xsl:text> summary=""</xsl:text>
263 </xsl:if>
264 <xsl:text>&gt;</xsl:text>
265 <xsl:apply-templates/>
266 <xsl:value-of select="concat('&lt;/', $tagname, '&gt;')"/>
267</xsl:template>
268
269<xsl:template name="emit_refsig">
270 <xsl:param name="context"/>
271 <xsl:param name="identifier"/>
272
273 <xsl:choose>
274 <xsl:when test="key('G_keyEnumsByName', $context)/const[@name=$identifier]">
275 <xsl:value-of select="$identifier"/>
276 </xsl:when>
277 <xsl:when test="key('G_keyInterfacesByName', $context)/method[@name=$identifier]">
278 <xsl:value-of select="$identifier"/>
279 <xsl:text>(</xsl:text>
280 <xsl:for-each select="key('G_keyInterfacesByName', $context)/method[@name=$identifier]/param">
281 <xsl:if test="@dir!='return'">
282 <xsl:if test="position() > 1">
283 <xsl:text>,</xsl:text>
284 </xsl:if>
285 <xsl:choose>
286 <xsl:when test="@dir='out'">
287 <xsl:text>Holder</xsl:text>
288 </xsl:when>
289 <xsl:otherwise>
290 <xsl:call-template name="typeIdl2Glue">
291 <xsl:with-param name="type" select="@type"/>
292 <xsl:with-param name="safearray" select="@safearray"/>
293 <xsl:with-param name="skiplisttype" select="'yes'"/>
294 </xsl:call-template>
295 </xsl:otherwise>
296 </xsl:choose>
297 </xsl:if>
298 </xsl:for-each>
299 <xsl:text>)</xsl:text>
300 </xsl:when>
301 <xsl:when test="key('G_keyInterfacesByName', $context)/attribute[@name=$identifier]">
302 <xsl:call-template name="makeGetterName">
303 <xsl:with-param name="attrname" select="$identifier" />
304 </xsl:call-template>
305 <xsl:text>()</xsl:text>
306 </xsl:when>
307 <xsl:otherwise>
308 <xsl:call-template name="fatalError">
309 <xsl:with-param name="msg" select="concat('unknown reference destination in @see/@link: context=', $context, ' identifier=', $identifier)" />
310 </xsl:call-template>
311 </xsl:otherwise>
312 </xsl:choose>
313</xsl:template>
314
315<!--
316 * link
317-->
318<xsl:template match="desc//link">
319 <xsl:text>{@link </xsl:text>
320 <xsl:apply-templates select="." mode="middle"/>
321 <xsl:text>}</xsl:text>
322</xsl:template>
323
324<xsl:template match="link" mode="middle">
325 <xsl:variable name="linktext">
326 <xsl:call-template name="string-replace-first">
327 <xsl:with-param name="haystack" select="@to"/>
328 <xsl:with-param name="needle" select="'_'"/>
329 <xsl:with-param name="replacement" select="'#'"/>
330 </xsl:call-template>
331 </xsl:variable>
332 <xsl:choose>
333 <xsl:when test="substring($linktext, 1, 1)='#'">
334 <xsl:variable name="context">
335 <xsl:choose>
336 <xsl:when test="local-name(../..)='interface' or local-name(../..)='enum'">
337 <xsl:value-of select="../../@name"/>
338 </xsl:when>
339 <xsl:when test="local-name(../../..)='interface' or local-name(../../..)='enum'">
340 <xsl:value-of select="../../../@name"/>
341 </xsl:when>
342 <xsl:when test="local-name(../../../..)='interface' or local-name(../../../..)='enum'">
343 <xsl:value-of select="../../../../@name"/>
344 </xsl:when>
345 <xsl:when test="local-name(../../../../..)='interface' or local-name(../../../../..)='enum'">
346 <xsl:value-of select="../../../../../@name"/>
347 </xsl:when>
348 <xsl:when test="local-name(../../../../../..)='interface' or local-name(../../../../../..)='enum'">
349 <xsl:value-of select="../../../../../../@name"/>
350 </xsl:when>
351 <xsl:otherwise>
352 <xsl:call-template name="fatalError">
353 <xsl:with-param name="msg" select="concat('cannot determine context for identifier ', $linktext)" />
354 </xsl:call-template>
355 </xsl:otherwise>
356 </xsl:choose>
357 </xsl:variable>
358 <xsl:variable name="linkname">
359 <xsl:value-of select="substring($linktext, 2)"/>
360 </xsl:variable>
361 <xsl:text>#</xsl:text>
362 <xsl:call-template name="emit_refsig">
363 <xsl:with-param name="context" select="$context"/>
364 <xsl:with-param name="identifier" select="$linkname"/>
365 </xsl:call-template>
366 </xsl:when>
367 <xsl:when test="contains($linktext, '::')">
368 <xsl:variable name="context">
369 <xsl:value-of select="substring-before($linktext, '::')"/>
370 </xsl:variable>
371 <xsl:variable name="linkname">
372 <xsl:value-of select="substring-after($linktext, '::')"/>
373 </xsl:variable>
374 <xsl:value-of select="concat($G_virtualBoxPackage, '.', $context, '#')"/>
375 <xsl:call-template name="emit_refsig">
376 <xsl:with-param name="context" select="$context"/>
377 <xsl:with-param name="identifier" select="$linkname"/>
378 </xsl:call-template>
379 </xsl:when>
380 <xsl:otherwise>
381 <xsl:value-of select="concat($G_virtualBoxPackage, '.', $linktext)"/>
382 </xsl:otherwise>
383 </xsl:choose>
384</xsl:template>
385<!--
386 * note
387-->
388<xsl:template match="desc/note">
389 <xsl:if test="not(@internal='yes')">
390 <xsl:text>&#10;NOTE: </xsl:text>
391 <xsl:apply-templates/>
392 <xsl:text>&#10;</xsl:text>
393 </xsl:if>
394</xsl:template>
395
396<!--
397 * see
398-->
399<xsl:template match="desc/see">
400 <!-- TODO: quirk in our xidl file: only one <see> tag with <link> nested
401 into it, translate this to multiple @see lines and strip the rest.
402 Should be replaced in the xidl by multiple <see> without nested tag -->
403 <xsl:text>&#10;</xsl:text>
404 <xsl:apply-templates match="link"/>
405</xsl:template>
406
407<xsl:template match="desc/see/text()"/>
408
409<xsl:template match="desc/see/link">
410 <xsl:text>@see </xsl:text>
411 <xsl:apply-templates select="." mode="middle"/>
412 <xsl:text>&#10;</xsl:text>
413</xsl:template>
414
415<!--
416 * common comment prologue (handles group IDs)
417-->
418<xsl:template match="desc" mode="begin">
419 <!-- TODO,XXX: This is a hot spot. The whole $id crap isn't working though,
420 so it's been disabled to save precious time. -->
421<!--
422 <xsl:param name="id" select="@group | preceding::descGroup[1]/@id"/>
423 <xsl:text>&#10;/**&#10;</xsl:text>
424 <xsl:if test="$id">
425 <xsl:value-of select="concat(' @ingroup ', $id, '&#10;')"/>
426 </xsl:if>
427-->
428 <xsl:value-of select="concat($G_sNewLine, '/**', $G_sNewLine)"/>
429</xsl:template>
430
431<!--
432 * common middle part of the comment block
433-->
434<xsl:template match="desc" mode="middle">
435 <xsl:apply-templates select="text() | *[not(self::note or self::see)]"/>
436 <xsl:apply-templates select="note"/>
437 <xsl:apply-templates select="see"/>
438</xsl:template>
439
440<!--
441 * result part of the comment block
442-->
443<xsl:template match="desc" mode="results">
444 <xsl:if test="result">
445 <xsl:text>&#10;Expected result codes:&#10;</xsl:text>
446 <xsl:text>&lt;table summary=""&gt;&#10;</xsl:text>
447 <xsl:for-each select="result">
448 <xsl:text>&lt;tr&gt;</xsl:text>
449 <xsl:choose>
450 <xsl:when test="ancestor::library/result[@name=current()/@name]">
451 <xsl:value-of select="concat('&lt;td&gt;@link ::', @name, ' ', @name, '&lt;/td&gt;')"/>
452 </xsl:when>
453 <xsl:otherwise>
454 <xsl:value-of select="concat('&lt;td&gt;', @name, '&lt;/td&gt;')"/>
455 </xsl:otherwise>
456 </xsl:choose>
457 <xsl:text>&lt;td&gt;</xsl:text>
458 <xsl:apply-templates select="text() | *[not(self::note or self::see or
459 self::result)]"/>
460 <xsl:text>&lt;/td&gt;&lt;/tr&gt;&#10;</xsl:text>
461 </xsl:for-each>
462 <xsl:text>&lt;/table&gt;&#10;</xsl:text>
463 </xsl:if>
464</xsl:template>
465
466<!--
467 * comment for interfaces
468-->
469<xsl:template match="desc" mode="interface">
470 <xsl:apply-templates select="." mode="begin"/>
471 <xsl:apply-templates select="." mode="middle"/>
472 <xsl:text>&#10;&#10;Interface ID: &lt;tt&gt;{</xsl:text>
473 <xsl:call-template name="string-to-upper">
474 <xsl:with-param name="str" select="../@uuid"/>
475 </xsl:call-template>
476 <xsl:text>}&lt;/tt&gt;&#10;*/&#10;</xsl:text>
477</xsl:template>
478
479<!--
480 * comment for attribute getters
481-->
482<xsl:template match="desc" mode="attribute_get">
483 <xsl:apply-templates select="." mode="begin"/>
484 <xsl:apply-templates select="text() | *[not(self::note or self::see or self::result)]"/>
485 <xsl:apply-templates select="." mode="results"/>
486 <xsl:apply-templates select="note"/>
487 <xsl:text>&#10;@return </xsl:text>
488 <xsl:call-template name="typeIdl2Glue">
489 <xsl:with-param name="type" select="../@type"/>
490 <xsl:with-param name="safearray" select="../@safearray"/>
491 <xsl:with-param name="doubleescape">yes</xsl:with-param>
492 </xsl:call-template>
493 <xsl:text>&#10;</xsl:text>
494 <xsl:apply-templates select="see"/>
495 <xsl:text>*/&#10;</xsl:text>
496</xsl:template>
497
498<!--
499 * comment for attribute setters
500-->
501<xsl:template match="desc" mode="attribute_set">
502 <xsl:apply-templates select="." mode="begin"/>
503 <xsl:apply-templates select="text() | *[not(self::note or self::see or self::result)]"/>
504 <xsl:apply-templates select="." mode="results"/>
505 <xsl:apply-templates select="note"/>
506 <xsl:text>&#10;@param value </xsl:text>
507 <xsl:call-template name="typeIdl2Glue">
508 <xsl:with-param name="type" select="../@type"/>
509 <xsl:with-param name="safearray" select="../@safearray"/>
510 <xsl:with-param name="doubleescape">yes</xsl:with-param>
511 </xsl:call-template>
512 <xsl:text>&#10;</xsl:text>
513 <xsl:apply-templates select="see"/>
514 <xsl:text>&#10;*/&#10;</xsl:text>
515</xsl:template>
516
517<!--
518 * comment for methods
519-->
520<xsl:template match="desc" mode="method">
521 <xsl:apply-templates select="." mode="begin"/>
522 <xsl:apply-templates select="text() | *[not(self::note or self::see or self::result)]"/>
523 <xsl:for-each select="../param">
524 <xsl:apply-templates select="desc"/>
525 </xsl:for-each>
526 <xsl:apply-templates select="." mode="results"/>
527 <xsl:apply-templates select="note"/>
528 <xsl:apply-templates select="../param/desc/note"/>
529 <xsl:apply-templates select="see"/>
530 <xsl:text>&#10;*/&#10;</xsl:text>
531</xsl:template>
532
533<!--
534 * comment for method parameters
535-->
536<xsl:template match="method/param/desc">
537 <xsl:if test="text() | *[not(self::note or self::see)]">
538 <xsl:choose>
539 <xsl:when test="../@dir='return'">
540 <xsl:text>&#10;@return </xsl:text>
541 </xsl:when>
542 <xsl:otherwise>
543 <xsl:text>&#10;@param </xsl:text>
544 <xsl:value-of select="../@name"/>
545 <xsl:text> </xsl:text>
546 </xsl:otherwise>
547 </xsl:choose>
548 <xsl:apply-templates select="text() | *[not(self::note or self::see)]"/>
549 <xsl:text>&#10;</xsl:text>
550 </xsl:if>
551</xsl:template>
552
553<!--
554 * comment for enums
555-->
556<xsl:template match="desc" mode="enum">
557 <xsl:apply-templates select="." mode="begin"/>
558 <xsl:apply-templates select="." mode="middle"/>
559 <xsl:text>&#10;Interface ID: &lt;tt&gt;{</xsl:text>
560 <xsl:call-template name="string-to-upper">
561 <xsl:with-param name="str" select="../@uuid"/>
562 </xsl:call-template>
563 <xsl:text>}&lt;/tt&gt;&#10;*/&#10;</xsl:text>
564</xsl:template>
565
566<!--
567 * comment for enum values
568-->
569<xsl:template match="desc" mode="enum_const">
570 <xsl:apply-templates select="." mode="begin"/>
571 <xsl:apply-templates select="." mode="middle"/>
572 <xsl:text>&#10;*/&#10;</xsl:text>
573</xsl:template>
574
575<!--
576 * ignore descGroups by default (processed in /idl)
577-->
578<xsl:template match="descGroup"/>
579
580
581
582<!-- actual code generation -->
583
584<xsl:template name="genEnum">
585 <xsl:param name="enumname" />
586 <xsl:param name="filename" />
587
588 <xsl:call-template name="startFile">
589 <xsl:with-param name="file" select="$filename" />
590 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
591 </xsl:call-template>
592
593 <xsl:if test="$filelistonly=''">
594 <xsl:apply-templates select="desc" mode="enum"/>
595 <xsl:value-of select="concat('public enum ', $enumname, '&#10;')" />
596 <xsl:text>{&#10;</xsl:text>
597 <xsl:for-each select="const">
598 <xsl:apply-templates select="desc" mode="enum_const"/>
599 <xsl:variable name="enumconst" select="@name" />
600 <xsl:value-of select="concat(' ', $enumconst, '(', @value, ')')" />
601 <xsl:choose>
602 <xsl:when test="not(position()=last())">
603 <xsl:text>,&#10;</xsl:text>
604 </xsl:when>
605 <xsl:otherwise>
606 <xsl:text>;&#10;</xsl:text>
607 </xsl:otherwise>
608 </xsl:choose>
609 </xsl:for-each>
610
611 <xsl:text>&#10;</xsl:text>
612 <xsl:text> private final int value;&#10;&#10;</xsl:text>
613
614 <xsl:value-of select="concat(' ', $enumname, '(int v)&#10;')" />
615 <xsl:text> {&#10;</xsl:text>
616 <xsl:text> value = v;&#10;</xsl:text>
617 <xsl:text> }&#10;&#10;</xsl:text>
618
619 <xsl:text> public int value()&#10;</xsl:text>
620 <xsl:text> {&#10;</xsl:text>
621 <xsl:text> return value;&#10;</xsl:text>
622 <xsl:text> }&#10;&#10;</xsl:text>
623
624 <xsl:value-of select="concat(' public static ', $enumname, ' fromValue(long v)&#10;')" />
625 <xsl:text> {&#10;</xsl:text>
626 <xsl:value-of select="concat(' for (', $enumname, ' c: ', $enumname, '.values())&#10;')" />
627 <xsl:text> {&#10;</xsl:text>
628 <xsl:text> if (c.value == (int)v)&#10;</xsl:text>
629 <xsl:text> {&#10;</xsl:text>
630 <xsl:text> return c;&#10;</xsl:text>
631 <xsl:text> }&#10;</xsl:text>
632 <xsl:text> }&#10;</xsl:text>
633 <xsl:text> throw new IllegalArgumentException(Long.toString(v));&#10;</xsl:text>
634 <xsl:text> }&#10;&#10;</xsl:text>
635
636 <xsl:value-of select="concat(' public static ', $enumname, ' fromValue(String v)&#10;')" />
637 <xsl:text> {&#10;</xsl:text>
638 <xsl:value-of select="concat(' return valueOf(', $enumname, '.class, v);&#10;')" />
639 <xsl:text> }&#10;</xsl:text>
640 <xsl:text>}&#10;&#10;</xsl:text>
641 </xsl:if>
642
643 <xsl:call-template name="endFile">
644 <xsl:with-param name="file" select="$filename" />
645 </xsl:call-template>
646
647</xsl:template>
648
649<xsl:template name="startExcWrapper">
650 <xsl:text> try&#10;</xsl:text>
651 <xsl:text> {&#10;</xsl:text>
652</xsl:template>
653
654<xsl:template name="endExcWrapper">
655
656 <xsl:choose>
657 <xsl:when test="$G_vboxGlueStyle='xpcom'">
658 <xsl:text> }&#10;</xsl:text>
659 <xsl:text> catch (org.mozilla.xpcom.XPCOMException e)&#10;</xsl:text>
660 <xsl:text> {&#10;</xsl:text>
661 <xsl:text> throw new VBoxException(e.getMessage(), e);&#10;</xsl:text>
662 <xsl:text> }&#10;</xsl:text>
663 </xsl:when>
664
665 <xsl:when test="$G_vboxGlueStyle='mscom'">
666 <xsl:text> }&#10;</xsl:text>
667 <xsl:text> catch (com.jacob.com.ComException e)&#10;</xsl:text>
668 <xsl:text> {&#10;</xsl:text>
669 <xsl:text> throw new VBoxException(e.getMessage(), e);&#10;</xsl:text>
670 <xsl:text> }&#10;</xsl:text>
671 </xsl:when>
672
673 <xsl:when test="$G_vboxGlueStyle='jaxws'">
674 <xsl:text> }&#10;</xsl:text>
675 <xsl:text> catch (InvalidObjectFaultMsg e)&#10;</xsl:text>
676 <xsl:text> {&#10;</xsl:text>
677 <xsl:text> throw new VBoxException(e.getMessage(), e, this.port);&#10;</xsl:text>
678 <xsl:text> }&#10;</xsl:text>
679 <xsl:text> catch (RuntimeFaultMsg e)&#10;</xsl:text>
680 <xsl:text> {&#10;</xsl:text>
681 <xsl:text> throw new VBoxException(e.getMessage(), e, this.port);&#10;</xsl:text>
682 <xsl:text> }&#10;</xsl:text>
683 </xsl:when>
684
685 <xsl:otherwise>
686 <xsl:call-template name="fatalError">
687 <xsl:with-param name="msg" select="'no header rule (startFile)'" />
688 </xsl:call-template>
689 </xsl:otherwise>
690 </xsl:choose>
691</xsl:template>
692
693<xsl:template name="wrappedName">
694 <xsl:param name="ifname" />
695
696 <xsl:choose>
697 <xsl:when test="$G_vboxGlueStyle='xpcom'">
698 <xsl:value-of select="concat('org.mozilla.interfaces.', $ifname)" />
699 </xsl:when>
700
701 <xsl:when test="$G_vboxGlueStyle='mscom'">
702 <xsl:text>com.jacob.com.Dispatch</xsl:text>
703 </xsl:when>
704
705 <xsl:when test="$G_vboxGlueStyle='jaxws'">
706 <xsl:text>String</xsl:text>
707 </xsl:when>
708
709 <xsl:otherwise>
710 <xsl:call-template name="fatalError">
711 <xsl:with-param name="msg" select="'no wrapper naming rule defined (wrappedName)'" />
712 </xsl:call-template>
713 </xsl:otherwise>
714
715 </xsl:choose>
716</xsl:template>
717
718<xsl:template name="fullClassName">
719 <xsl:param name="name" />
720 <xsl:param name="origname" />
721 <xsl:param name="collPrefix" />
722
723 <xsl:choose>
724 <xsl:when test="(count(key('G_keyEnumsByName', $name)) > 0) or (count(key('G_keyEnumsByName', $origname)) > 0)">
725 <xsl:value-of select="concat($G_virtualBoxPackage, concat('.', $name))" />
726 </xsl:when>
727 <xsl:when test="count(key('G_keyInterfacesByName', $name)) > 0">
728 <xsl:value-of select="concat($G_virtualBoxPackage, concat('.', $name))" />
729 </xsl:when>
730 <xsl:otherwise>
731 <xsl:call-template name="fatalError">
732 <xsl:with-param name="msg" select="concat('fullClassName: Type &quot;', $name, '&quot; is not supported.')" />
733 </xsl:call-template>
734 </xsl:otherwise>
735 </xsl:choose>
736</xsl:template>
737
738<xsl:template name="typeIdl2Glue">
739 <xsl:param name="type" />
740 <xsl:param name="safearray" />
741 <xsl:param name="forceelem" />
742 <xsl:param name="skiplisttype" />
743 <xsl:param name="doubleescape" />
744
745 <xsl:variable name="needarray" select="($safearray='yes') and not($forceelem='yes')" />
746 <xsl:variable name="needlist" select="($needarray) and not($type='octet')" />
747
748 <xsl:if test="($needlist)">
749 <xsl:text>List</xsl:text>
750 <xsl:if test="not($skiplisttype='yes')">
751 <xsl:choose>
752 <xsl:when test="$doubleescape='yes'">
753 <xsl:text>&amp;lt;</xsl:text>
754 </xsl:when>
755 <xsl:otherwise>
756 <xsl:text>&lt;</xsl:text>
757 </xsl:otherwise>
758 </xsl:choose>
759 </xsl:if>
760 </xsl:if>
761
762 <xsl:if test="not($needlist) or not($skiplisttype='yes')">
763 <!-- look up Java type from IDL type from table array in typemap-shared.inc.xsl -->
764 <xsl:variable name="javatypefield" select="exsl:node-set($G_aSharedTypes)/type[@idlname=$type]/@javaname" />
765
766 <xsl:choose>
767 <xsl:when test="string-length($javatypefield)">
768 <xsl:value-of select="$javatypefield" />
769 </xsl:when>
770 <!-- not a standard type: then it better be one of the types defined in the XIDL -->
771 <xsl:when test="$type='$unknown'">IUnknown</xsl:when>
772 <xsl:otherwise>
773 <xsl:call-template name="fullClassName">
774 <xsl:with-param name="name" select="$type" />
775 <xsl:with-param name="collPrefix" select="''"/>
776 </xsl:call-template>
777 </xsl:otherwise>
778 </xsl:choose>
779 </xsl:if>
780
781 <xsl:choose>
782 <xsl:when test="($needlist)">
783 <xsl:if test="not($skiplisttype='yes')">
784 <xsl:choose>
785 <xsl:when test="$doubleescape='yes'">
786 <xsl:text>&amp;gt;</xsl:text>
787 </xsl:when>
788 <xsl:otherwise>
789 <xsl:text>&gt;</xsl:text>
790 </xsl:otherwise>
791 </xsl:choose>
792 </xsl:if>
793 </xsl:when>
794 <xsl:when test="($needarray)">
795 <xsl:text>[]</xsl:text>
796 </xsl:when>
797 </xsl:choose>
798</xsl:template>
799
800<!--
801 typeIdl2Back: converts $type into a type as used by the backend.
802 -->
803<xsl:template name="typeIdl2Back">
804 <xsl:param name="type" />
805 <xsl:param name="safearray" />
806 <xsl:param name="forceelem" />
807
808 <xsl:choose>
809 <xsl:when test="($G_vboxGlueStyle='xpcom')">
810 <xsl:variable name="needarray" select="($safearray='yes') and not($forceelem='yes')" />
811
812 <xsl:choose>
813 <xsl:when test="$type='long long'">
814 <xsl:text>long</xsl:text>
815 </xsl:when>
816
817 <xsl:when test="$type='unsigned long'">
818 <xsl:text>long</xsl:text>
819 </xsl:when>
820
821 <xsl:when test="$type='long'">
822 <xsl:text>int</xsl:text>
823 </xsl:when>
824
825 <xsl:when test="$type='unsigned short'">
826 <xsl:text>int</xsl:text>
827 </xsl:when>
828
829 <xsl:when test="$type='short'">
830 <xsl:text>short</xsl:text>
831 </xsl:when>
832
833 <xsl:when test="$type='octet'">
834 <xsl:text>byte</xsl:text>
835 </xsl:when>
836
837 <xsl:when test="$type='boolean'">
838 <xsl:text>boolean</xsl:text>
839 </xsl:when>
840
841 <xsl:when test="$type='$unknown'">
842 <xsl:text>nsISupports</xsl:text>
843 </xsl:when>
844
845 <xsl:when test="$type='wstring'">
846 <xsl:text>String</xsl:text>
847 </xsl:when>
848
849 <xsl:when test="$type='uuid'">
850 <xsl:text>String</xsl:text>
851 </xsl:when>
852
853 <xsl:when test="key('G_keyInterfacesByName', $type)/@wsmap='struct'">
854 <xsl:call-template name="wrappedName">
855 <xsl:with-param name="ifname" select="$type" />
856 </xsl:call-template>
857 </xsl:when>
858
859 <xsl:when test="count(key('G_keyInterfacesByName', $type)) > 0">
860 <xsl:call-template name="wrappedName">
861 <xsl:with-param name="ifname" select="$type" />
862 </xsl:call-template>
863 </xsl:when>
864
865 <xsl:when test="count(key('G_keyEnumsByName', $type)) > 0">
866 <xsl:text>long</xsl:text>
867 </xsl:when>
868
869 <xsl:otherwise>
870 <xsl:call-template name="fullClassName">
871 <xsl:with-param name="name" select="$type" />
872 </xsl:call-template>
873 </xsl:otherwise>
874
875 </xsl:choose>
876 <xsl:if test="$needarray">
877 <xsl:text>[]</xsl:text>
878 </xsl:if>
879 </xsl:when>
880
881 <xsl:when test="($G_vboxGlueStyle='mscom')">
882 <xsl:text>Variant</xsl:text>
883 </xsl:when>
884
885 <xsl:when test="($G_vboxGlueStyle='jaxws')">
886 <xsl:variable name="needarray" select="($safearray='yes' and not($type='octet')) and not($forceelem='yes')" />
887
888 <xsl:if test="$needarray">
889 <xsl:text>List&lt;</xsl:text>
890 </xsl:if>
891 <xsl:choose>
892 <xsl:when test="$type='$unknown'">
893 <xsl:text>String</xsl:text>
894 </xsl:when>
895
896 <xsl:when test="key('G_keyInterfacesByName', $type)/@wsmap='managed'">
897 <xsl:text>String</xsl:text>
898 </xsl:when>
899
900 <xsl:when test="key('G_keyInterfacesByName', $type)/@wsmap='struct'">
901 <xsl:value-of select="concat($G_virtualBoxPackageCom, '.', $type)" />
902 </xsl:when>
903
904 <xsl:when test="count(key('G_keyEnumsByName', $type)) > 0">
905 <xsl:value-of select="concat($G_virtualBoxPackageCom, '.', $type)" />
906 </xsl:when>
907
908 <!-- we encode byte arrays as Base64 strings. -->
909 <xsl:when test="$type='octet'">
910 <xsl:text>/*base64*/String</xsl:text>
911 </xsl:when>
912
913 <xsl:when test="$type='long long'">
914 <xsl:text>Long</xsl:text>
915 </xsl:when>
916
917 <xsl:when test="$type='unsigned long'">
918 <xsl:text>Long</xsl:text>
919 </xsl:when>
920
921 <xsl:when test="$type='long'">
922 <xsl:text>Integer</xsl:text>
923 </xsl:when>
924
925 <xsl:when test="$type='unsigned short'">
926 <xsl:text>Integer</xsl:text>
927 </xsl:when>
928
929 <xsl:when test="$type='short'">
930 <xsl:text>Short</xsl:text>
931 </xsl:when>
932
933 <xsl:when test="$type='boolean'">
934 <xsl:text>Boolean</xsl:text>
935 </xsl:when>
936
937 <xsl:when test="$type='wstring'">
938 <xsl:text>String</xsl:text>
939 </xsl:when>
940
941 <xsl:when test="$type='uuid'">
942 <xsl:text>String</xsl:text>
943 </xsl:when>
944
945 <xsl:otherwise>
946 <xsl:call-template name="fatalError">
947 <xsl:with-param name="msg" select="concat('Unhandled type ', $type, ' (typeIdl2Back)')" />
948 </xsl:call-template>
949 </xsl:otherwise>
950
951 </xsl:choose>
952
953 <xsl:if test="$needarray">
954 <xsl:text>&gt;</xsl:text>
955 </xsl:if>
956 </xsl:when>
957
958 <xsl:otherwise>
959 <xsl:call-template name="fatalError">
960 <xsl:with-param name="msg" select="'Write typeIdl2Back for this style (typeIdl2Back)'" />
961 </xsl:call-template>
962 </xsl:otherwise>
963
964 </xsl:choose>
965</xsl:template>
966
967<xsl:template name="cookOutParamXpcom">
968 <xsl:param name="value"/>
969 <xsl:param name="idltype"/>
970 <xsl:param name="safearray"/>
971 <xsl:variable name="isstruct"
972 select="key('G_keyInterfacesByName', $idltype)/@wsmap='struct'" />
973
974 <xsl:variable name="gluetype">
975 <xsl:call-template name="typeIdl2Glue">
976 <xsl:with-param name="type" select="$idltype" />
977 <xsl:with-param name="safearray" select="$safearray" />
978 </xsl:call-template>
979 </xsl:variable>
980
981 <xsl:variable name="elemgluetype">
982 <xsl:if test="$safearray='yes'">
983 <xsl:call-template name="typeIdl2Glue">
984 <xsl:with-param name="type" select="$idltype" />
985 <xsl:with-param name="safearray" select="'no'" />
986 <xsl:with-param name="forceelem" select="'yes'" />
987 </xsl:call-template>
988 </xsl:if>
989 </xsl:variable>
990
991 <xsl:choose>
992 <xsl:when test="$idltype = '$unknown' or (count(key('G_keyInterfacesByName', $idltype)) > 0)">
993 <xsl:choose>
994 <xsl:when test="$safearray='yes'">
995 <xsl:variable name="elembacktype">
996 <xsl:call-template name="typeIdl2Back">
997 <xsl:with-param name="type" select="$idltype" />
998 <xsl:with-param name="safearray" select="$safearray" />
999 <xsl:with-param name="forceelem" select="'yes'" />
1000 </xsl:call-template>
1001 </xsl:variable>
1002 <xsl:value-of select="concat('Helper.wrap2(', $elemgluetype, '.class, ', $elembacktype, '.class, ', $value, ')')"/>
1003 </xsl:when>
1004 <xsl:otherwise>
1005 <xsl:value-of select="concat('(', $value, ' != null) ? new ', $gluetype, '(', $value, ') : null')" />
1006 </xsl:otherwise>
1007 </xsl:choose>
1008 </xsl:when>
1009
1010 <xsl:when test="count(key('G_keyEnumsByName', $idltype)) > 0">
1011 <xsl:choose>
1012 <xsl:when test="$safearray='yes'">
1013 <xsl:variable name="elembacktype">
1014 <xsl:call-template name="typeIdl2Back">
1015 <xsl:with-param name="type" select="$idltype" />
1016 <xsl:with-param name="safearray" select="$safearray" />
1017 <xsl:with-param name="forceelem" select="'yes'" />
1018 </xsl:call-template>
1019 </xsl:variable>
1020 <xsl:value-of select="concat('Helper.wrapEnum(', $elemgluetype, '.class, ', $value, ')')"/>
1021 </xsl:when>
1022 <xsl:otherwise>
1023 <xsl:value-of select="concat($gluetype, '.fromValue(', $value, ')')"/>
1024 </xsl:otherwise>
1025 </xsl:choose>
1026 </xsl:when>
1027
1028 <xsl:otherwise>
1029 <xsl:choose>
1030 <xsl:when test="($safearray='yes') and ($idltype='octet')">
1031 <xsl:value-of select="$value"/>
1032 </xsl:when>
1033 <xsl:when test="$safearray='yes'">
1034 <xsl:value-of select="concat('Helper.wrap(', $value, ')')"/>
1035 </xsl:when>
1036 <xsl:otherwise>
1037 <xsl:value-of select="$value"/>
1038 </xsl:otherwise>
1039 </xsl:choose>
1040 </xsl:otherwise>
1041 </xsl:choose>
1042</xsl:template>
1043
1044<xsl:template name="cookOutParamMscom">
1045 <xsl:param name="value"/>
1046 <xsl:param name="idltype"/>
1047 <xsl:param name="safearray"/>
1048
1049 <xsl:variable name="gluetype">
1050 <xsl:call-template name="typeIdl2Glue">
1051 <xsl:with-param name="type" select="$idltype" />
1052 <xsl:with-param name="safearray" select="$safearray" />
1053 </xsl:call-template>
1054 </xsl:variable>
1055
1056 <xsl:choose>
1057 <xsl:when test="$safearray='yes'">
1058 <xsl:variable name="elemgluetype">
1059 <xsl:call-template name="typeIdl2Glue">
1060 <xsl:with-param name="type" select="$idltype" />
1061 <xsl:with-param name="safearray" select="'no'" />
1062 <xsl:with-param name="forceelem" select="'yes'" />
1063 </xsl:call-template>
1064 </xsl:variable>
1065 <xsl:choose>
1066 <xsl:when test="($idltype='octet')">
1067 <xsl:value-of select="concat('Helper.wrapBytes(', $value, '.toSafeArray())')"/>
1068 </xsl:when>
1069 <xsl:otherwise>
1070 <xsl:value-of select="concat('Helper.wrap(', $elemgluetype, '.class, ', $value, '.toSafeArray())')"/>
1071 </xsl:otherwise>
1072 </xsl:choose>
1073 </xsl:when>
1074
1075 <xsl:when test="$idltype = '$unknown' or (count(key('G_keyInterfacesByName', $idltype)) > 0)">
1076 <xsl:value-of select="concat('Helper.wrapDispatch(', $gluetype, '.class, ', $value, '.getDispatch())')"/>
1077 </xsl:when>
1078
1079 <xsl:when test="count(key('G_keyEnumsByName', $idltype)) > 0">
1080 <xsl:value-of select="concat($gluetype, '.fromValue(', $value, '.getInt())')"/>
1081 </xsl:when>
1082
1083 <xsl:when test="$idltype='wstring'">
1084 <xsl:value-of select="concat($value, '.getString()')"/>
1085 </xsl:when>
1086
1087 <xsl:when test="$idltype='uuid'">
1088 <xsl:value-of select="concat($value, '.getString()')"/>
1089 </xsl:when>
1090
1091 <xsl:when test="$idltype='boolean'">
1092 <xsl:value-of select="concat($value, '.toBoolean()')"/>
1093 </xsl:when>
1094
1095 <xsl:when test="$idltype='unsigned short'">
1096 <xsl:value-of select="concat('(int)', $value, '.getShort()')"/>
1097 </xsl:when>
1098
1099 <xsl:when test="$idltype='short'">
1100 <xsl:value-of select="concat($value, '.getShort()')"/>
1101 </xsl:when>
1102
1103 <xsl:when test="$idltype='long'">
1104 <xsl:value-of select="concat($value, '.getInt()')"/>
1105 </xsl:when>
1106
1107
1108 <xsl:when test="$idltype='unsigned long'">
1109 <xsl:value-of select="concat('(long)', $value, '.getInt()')"/>
1110 </xsl:when>
1111
1112 <xsl:when test="$idltype='long'">
1113 <xsl:value-of select="concat($value, '.getInt()')"/>
1114 </xsl:when>
1115
1116 <xsl:when test="$idltype='long long'">
1117 <xsl:value-of select="concat($value, '.getLong()')"/>
1118 </xsl:when>
1119
1120 <xsl:otherwise>
1121 <xsl:call-template name="fatalError">
1122 <xsl:with-param name="msg" select="concat('Unhandled type' , $idltype, ' (cookOutParamMscom)')" />
1123 </xsl:call-template>
1124 </xsl:otherwise>
1125 </xsl:choose>
1126
1127</xsl:template>
1128
1129<xsl:template name="cookOutParamJaxws">
1130 <xsl:param name="value"/>
1131 <xsl:param name="idltype"/>
1132 <xsl:param name="safearray"/>
1133
1134 <xsl:variable name="isstruct"
1135 select="key('G_keyInterfacesByName', $idltype)/@wsmap='struct'" />
1136
1137 <xsl:variable name="gluetype">
1138 <xsl:call-template name="typeIdl2Glue">
1139 <xsl:with-param name="type" select="$idltype" />
1140 <xsl:with-param name="safearray" select="$safearray" />
1141 </xsl:call-template>
1142 </xsl:variable>
1143
1144 <xsl:choose>
1145 <xsl:when test="$safearray='yes'">
1146 <xsl:variable name="elemgluetype">
1147 <xsl:call-template name="typeIdl2Glue">
1148 <xsl:with-param name="type" select="$idltype" />
1149 <xsl:with-param name="safearray" select="''" />
1150 <xsl:with-param name="forceelem" select="'yes'" />
1151 </xsl:call-template>
1152 </xsl:variable>
1153 <xsl:variable name="elembacktype">
1154 <xsl:call-template name="typeIdl2Back">
1155 <xsl:with-param name="type" select="$idltype" />
1156 <xsl:with-param name="safearray" select="''" />
1157 <xsl:with-param name="forceelem" select="'yes'" />
1158 </xsl:call-template>
1159 </xsl:variable>
1160 <xsl:choose>
1161 <xsl:when test="$isstruct">
1162 <xsl:value-of select="concat('Helper.wrap2(', $elemgluetype, '.class, ', $elembacktype, '.class, port, ', $value, ')')"/>
1163 </xsl:when>
1164 <xsl:when test="count(key('G_keyEnumsByName', $idltype)) > 0">
1165 <xsl:value-of select="concat('Helper.convertEnums(', $elembacktype, '.class, ', $elemgluetype, '.class, ', $value, ')')"/>
1166 </xsl:when>
1167 <xsl:when test="$idltype = '$unknown' or (count(key('G_keyInterfacesByName', $idltype)) > 0)">
1168 <xsl:value-of select="concat('Helper.wrap(', $elemgluetype, '.class, port, ', $value, ')')"/>
1169 </xsl:when>
1170 <xsl:when test="$idltype='octet'">
1171 <xsl:value-of select="concat('Helper.decodeBase64(', $value, ')')"/>
1172 </xsl:when>
1173 <xsl:otherwise>
1174 <xsl:value-of select="$value" />
1175 </xsl:otherwise>
1176 </xsl:choose>
1177 </xsl:when>
1178
1179 <xsl:otherwise>
1180 <xsl:choose>
1181 <xsl:when test="count(key('G_keyEnumsByName', $idltype)) > 0">
1182 <xsl:value-of select="concat($gluetype, '.fromValue(', $value, '.value())')"/>
1183 </xsl:when>
1184 <xsl:when test="$idltype='boolean'">
1185 <xsl:value-of select="$value"/>
1186 </xsl:when>
1187 <xsl:when test="$idltype='long long'">
1188 <xsl:value-of select="$value"/>
1189 </xsl:when>
1190 <xsl:when test="$idltype='unsigned long long'">
1191 <xsl:value-of select="$value"/>
1192 </xsl:when>
1193 <xsl:when test="$idltype='long'">
1194 <xsl:value-of select="$value"/>
1195 </xsl:when>
1196 <xsl:when test="$idltype='unsigned long'">
1197 <xsl:value-of select="$value"/>
1198 </xsl:when>
1199 <xsl:when test="$idltype='short'">
1200 <xsl:value-of select="$value"/>
1201 </xsl:when>
1202 <xsl:when test="$idltype='unsigned short'">
1203 <xsl:value-of select="$value"/>
1204 </xsl:when>
1205 <xsl:when test="$idltype='wstring'">
1206 <xsl:value-of select="$value"/>
1207 </xsl:when>
1208 <xsl:when test="$idltype='uuid'">
1209 <xsl:value-of select="$value"/>
1210 </xsl:when>
1211 <xsl:when test="$isstruct">
1212 <xsl:value-of select="concat('(', $value, ' != null) ? new ', $gluetype, '(', $value, ', port) : null')" />
1213 </xsl:when>
1214 <xsl:when test="$idltype = '$unknown' or (count(key('G_keyInterfacesByName', $idltype)) > 0)">
1215 <!-- if the MOR string is empty, that means NULL, so return NULL instead of an object then -->
1216 <xsl:value-of select="concat('(', $value, '.length() > 0) ? new ', $gluetype, '(', $value, ', port) : null')" />
1217 </xsl:when>
1218 <xsl:otherwise>
1219 <xsl:call-template name="fatalError">
1220 <xsl:with-param name="msg" select="concat('Unhandled type ', $idltype, ' (cookOutParamJaxws)')" />
1221 </xsl:call-template>
1222 </xsl:otherwise>
1223 </xsl:choose>
1224 </xsl:otherwise>
1225 </xsl:choose>
1226
1227</xsl:template>
1228
1229<xsl:template name="cookOutParam">
1230 <xsl:param name="value"/>
1231 <xsl:param name="idltype"/>
1232 <xsl:param name="safearray"/>
1233 <xsl:choose>
1234 <xsl:when test="($G_vboxGlueStyle='xpcom')">
1235 <xsl:call-template name="cookOutParamXpcom">
1236 <xsl:with-param name="value" select="$value" />
1237 <xsl:with-param name="idltype" select="$idltype" />
1238 <xsl:with-param name="safearray" select="$safearray" />
1239 </xsl:call-template>
1240 </xsl:when>
1241 <xsl:when test="($G_vboxGlueStyle='mscom')">
1242 <xsl:call-template name="cookOutParamMscom">
1243 <xsl:with-param name="value" select="$value" />
1244 <xsl:with-param name="idltype" select="$idltype" />
1245 <xsl:with-param name="safearray" select="$safearray" />
1246 </xsl:call-template>
1247 </xsl:when>
1248 <xsl:when test="($G_vboxGlueStyle='jaxws')">
1249 <xsl:call-template name="cookOutParamJaxws">
1250 <xsl:with-param name="value" select="$value" />
1251 <xsl:with-param name="idltype" select="$idltype" />
1252 <xsl:with-param name="safearray" select="$safearray" />
1253 </xsl:call-template>
1254 </xsl:when>
1255 <xsl:otherwise>
1256 <xsl:call-template name="fatalError">
1257 <xsl:with-param name="msg" select="'Unhandled style(cookOutParam)'" />
1258 </xsl:call-template>
1259 </xsl:otherwise>
1260 </xsl:choose>
1261</xsl:template>
1262
1263<xsl:template name="cookInParamXpcom">
1264 <xsl:param name="value"/>
1265 <xsl:param name="idltype"/>
1266 <xsl:param name="safearray"/>
1267 <xsl:variable name="isstruct"
1268 select="key('G_keyInterfacesByName', $idltype)/@wsmap='struct'" />
1269 <xsl:variable name="gluetype">
1270 <xsl:call-template name="typeIdl2Glue">
1271 <xsl:with-param name="type" select="$idltype" />
1272 <xsl:with-param name="safearray" select="$safearray" />
1273 </xsl:call-template>
1274 </xsl:variable>
1275
1276 <xsl:variable name="backtype">
1277 <xsl:call-template name="typeIdl2Back">
1278 <xsl:with-param name="type" select="$idltype" />
1279 <xsl:with-param name="safearray" select="$safearray" />
1280 </xsl:call-template>
1281 </xsl:variable>
1282
1283 <xsl:variable name="elemgluetype">
1284 <xsl:if test="$safearray='yes'">
1285 <xsl:call-template name="typeIdl2Glue">
1286 <xsl:with-param name="type" select="$idltype" />
1287 <xsl:with-param name="safearray" select="'no'" />
1288 <xsl:with-param name="forceelem" select="'yes'" />
1289 </xsl:call-template>
1290 </xsl:if>
1291 </xsl:variable>
1292
1293 <xsl:choose>
1294 <xsl:when test="count(key('G_keyInterfacesByName', $idltype)) > 0">
1295 <xsl:choose>
1296 <xsl:when test="$safearray='yes'">
1297 <xsl:variable name="elembacktype">
1298 <xsl:call-template name="typeIdl2Back">
1299 <xsl:with-param name="type" select="$idltype" />
1300 <xsl:with-param name="safearray" select="$safearray" />
1301 <xsl:with-param name="forceelem" select="'yes'" />
1302 </xsl:call-template>
1303 </xsl:variable>
1304 <xsl:value-of select="concat('Helper.unwrap2(', $elemgluetype, '.class, ', $elembacktype, '.class, ', $value, ')')"/>
1305 </xsl:when>
1306 <xsl:otherwise>
1307 <xsl:value-of select="concat('(', $value, ' != null) ? ', $value, '.getTypedWrapped() : null')" />
1308 </xsl:otherwise>
1309 </xsl:choose>
1310 </xsl:when>
1311
1312 <xsl:when test="$idltype='$unknown'">
1313 <xsl:choose>
1314 <xsl:when test="$safearray='yes'">
1315 <xsl:value-of select="concat('Helper.unwrap2(', $elemgluetype, '.class, nsISupports.class, ', $value, ')')"/>
1316 </xsl:when>
1317 <xsl:otherwise>
1318 <xsl:value-of select="concat('(', $value, ' != null) ? (nsISupports)', $value, '.getWrapped() : null')" />
1319 </xsl:otherwise>
1320 </xsl:choose>
1321 </xsl:when>
1322
1323 <xsl:when test="count(key('G_keyEnumsByName', $idltype)) > 0">
1324 <xsl:choose>
1325 <xsl:when test="$safearray='yes'">
1326 <xsl:value-of select="concat('Helper.unwrapEnum(', $elemgluetype, '.class, ', $value, ')')"/>
1327 </xsl:when>
1328 <xsl:otherwise>
1329 <xsl:value-of select="concat($value, '.value()')"/>
1330 </xsl:otherwise>
1331 </xsl:choose>
1332 </xsl:when>
1333
1334 <xsl:when test="($idltype='octet') and ($safearray='yes')">
1335 <xsl:value-of select="$value"/>
1336 </xsl:when>
1337
1338 <xsl:otherwise>
1339 <xsl:choose>
1340 <xsl:when test="$safearray='yes'">
1341 <xsl:choose>
1342 <xsl:when test="$idltype='boolean'">
1343 <xsl:value-of select="concat('Helper.unwrapBoolean(', $value, ')')"/>
1344 </xsl:when>
1345 <xsl:when test="($idltype='long') or ($idltype='unsigned long') or ($idltype='integer')">
1346 <xsl:value-of select="concat('Helper.unwrapInteger(', $value, ')')"/>
1347 </xsl:when>
1348 <xsl:when test="($idltype='short') or ($idltype='unsigned short')">
1349 <xsl:value-of select="concat('Helper.unwrapUShort(', $value, ')')"/>
1350 </xsl:when>
1351 <xsl:when test="($idltype='unsigned long long') or ($idltype='long long')">
1352 <xsl:value-of select="concat('Helper.unwrapULong(', $value, ')')"/>
1353 </xsl:when>
1354 <xsl:when test="($idltype='wstring') or ($idltype='uuid')">
1355 <xsl:value-of select="concat('Helper.unwrapStr(', $value, ')')"/>
1356 </xsl:when>
1357 <xsl:otherwise>
1358 <xsl:value-of select="$value"/>
1359 </xsl:otherwise>
1360 </xsl:choose>
1361 </xsl:when>
1362 <xsl:otherwise>
1363 <xsl:value-of select="$value"/>
1364 </xsl:otherwise>
1365 </xsl:choose>
1366 </xsl:otherwise>
1367 </xsl:choose>
1368</xsl:template>
1369
1370<xsl:template name="cookInParamMscom">
1371 <xsl:param name="value"/>
1372 <xsl:param name="idltype"/>
1373 <xsl:param name="safearray"/>
1374
1375 <xsl:variable name="gluetype">
1376 <xsl:call-template name="typeIdl2Glue">
1377 <xsl:with-param name="type" select="$idltype" />
1378 <xsl:with-param name="safearray" select="$safearray" />
1379 </xsl:call-template>
1380 </xsl:variable>
1381
1382 <xsl:variable name="backtype">
1383 <xsl:call-template name="typeIdl2Back">
1384 <xsl:with-param name="type" select="$idltype" />
1385 <xsl:with-param name="safearray" select="$safearray" />
1386 </xsl:call-template>
1387 </xsl:variable>
1388
1389 <xsl:variable name="elemgluetype">
1390 <xsl:if test="$safearray='yes'">
1391 <xsl:call-template name="typeIdl2Glue">
1392 <xsl:with-param name="type" select="$idltype" />
1393 <xsl:with-param name="safearray" select="'no'" />
1394 <xsl:with-param name="forceelem" select="'yes'" />
1395 </xsl:call-template>
1396 </xsl:if>
1397 </xsl:variable>
1398
1399 <xsl:choose>
1400 <xsl:when test="count(key('G_keyInterfacesByName', $idltype)) > 0">
1401 <xsl:choose>
1402 <xsl:when test="$safearray='yes'">
1403 <xsl:variable name="elembacktype">
1404 <xsl:call-template name="typeIdl2Back">
1405 <xsl:with-param name="type" select="$idltype" />
1406 <xsl:with-param name="safearray" select="$safearray" />
1407 <xsl:with-param name="forceelem" select="'yes'" />
1408 </xsl:call-template>
1409 </xsl:variable>
1410 <!-- Sometimes javac needs a boost of self-confidence regarding
1411 varargs calls, and this (Object) cast makes sure that it calls
1412 the varargs method - as if there is any other. -->
1413 <xsl:value-of select="concat('(Object)Helper.unwrap2(', $elemgluetype, '.class, ', $elembacktype, '.class, ', $value, ')')"/>
1414 </xsl:when>
1415 <xsl:otherwise>
1416 <xsl:value-of select="concat('(', $value, ' != null) ? ', $value, '.getTypedWrapped() : null')" />
1417 </xsl:otherwise>
1418 </xsl:choose>
1419 </xsl:when>
1420
1421 <xsl:when test="$idltype='$unknown'">
1422 <xsl:choose>
1423 <xsl:when test="$safearray='yes'">
1424 <xsl:value-of select="concat('Helper.unwrap2(', $elemgluetype, '.class, Dispatch.class, ', $value, ')')"/>
1425 </xsl:when>
1426 <xsl:otherwise>
1427 <xsl:value-of select="concat('(', $value, ' != null) ? (Dispatch)', $value, '.getWrapped() : null')" />
1428 </xsl:otherwise>
1429 </xsl:choose>
1430 </xsl:when>
1431
1432 <xsl:when test="count(key('G_keyEnumsByName', $idltype)) > 0">
1433 <xsl:choose>
1434 <xsl:when test="$safearray='yes'">
1435 <xsl:value-of select="concat('Helper.unwrapEnum(', $elemgluetype, '.class, ', $value, ')')"/>
1436 </xsl:when>
1437 <xsl:otherwise>
1438 <xsl:value-of select="concat($value, '.value()')"/>
1439 </xsl:otherwise>
1440 </xsl:choose>
1441 </xsl:when>
1442
1443 <xsl:when test="$idltype='boolean'">
1444 <xsl:choose>
1445 <xsl:when test="$safearray='yes'">
1446 <xsl:value-of select="concat('Helper.unwrapBool(', $value, ')')"/>
1447 </xsl:when>
1448 <xsl:otherwise>
1449 <xsl:value-of select="concat('new Variant(', $value, ')')"/>
1450 </xsl:otherwise>
1451 </xsl:choose>
1452 </xsl:when>
1453
1454 <xsl:when test="($idltype='short') or ($idltype='unsigned short')">
1455 <xsl:choose>
1456 <xsl:when test="$safearray='yes'">
1457 <xsl:value-of select="concat('Helper.unwrapShort(', $value, ')')"/>
1458 </xsl:when>
1459 <xsl:otherwise>
1460 <xsl:value-of select="concat('new Variant(', $value, ')')"/>
1461 </xsl:otherwise>
1462 </xsl:choose>
1463 </xsl:when>
1464
1465
1466 <xsl:when test="($idltype='long') or ($idltype='unsigned long')">
1467 <xsl:choose>
1468 <xsl:when test="$safearray='yes'">
1469 <xsl:value-of select="concat('Helper.unwrapInt(', $value, ')')"/>
1470 </xsl:when>
1471 <xsl:otherwise>
1472 <xsl:value-of select="concat('new Variant(', $value, ')')"/>
1473 </xsl:otherwise>
1474 </xsl:choose>
1475 </xsl:when>
1476
1477 <xsl:when test="($idltype='wstring') or ($idltype='uuid')">
1478 <xsl:choose>
1479 <xsl:when test="$safearray='yes'">
1480 <xsl:value-of select="concat('Helper.unwrapString(', $value, ')')"/>
1481 </xsl:when>
1482 <xsl:otherwise>
1483 <xsl:value-of select="concat('new Variant(', $value, ')')"/>
1484 </xsl:otherwise>
1485 </xsl:choose>
1486 </xsl:when>
1487
1488 <xsl:when test="($idltype='unsigned long long') or ($idltype='long long')">
1489 <xsl:choose>
1490 <xsl:when test="$safearray='yes'">
1491 <xsl:value-of select="concat('Helper.unwrapLong(', $value, ')')"/>
1492 </xsl:when>
1493 <xsl:otherwise>
1494 <xsl:value-of select="concat('new Variant(', $value, '.longValue())')"/>
1495 </xsl:otherwise>
1496 </xsl:choose>
1497 </xsl:when>
1498
1499 <xsl:when test="($idltype='octet') and ($safearray='yes')">
1500 <xsl:value-of select="$value"/>
1501 </xsl:when>
1502
1503 <xsl:otherwise>
1504 <xsl:call-template name="fatalError">
1505 <xsl:with-param name="msg" select="concat('Unhandled type: ', $idltype)" />
1506 </xsl:call-template>
1507 </xsl:otherwise>
1508 </xsl:choose>
1509
1510</xsl:template>
1511
1512<xsl:template name="cookInParamJaxws">
1513 <xsl:param name="value"/>
1514 <xsl:param name="idltype"/>
1515 <xsl:param name="safearray"/>
1516 <xsl:variable name="isstruct"
1517 select="key('G_keyInterfacesByName', $idltype)/@wsmap='struct'" />
1518
1519 <xsl:variable name="gluetype">
1520 <xsl:call-template name="typeIdl2Glue">
1521 <xsl:with-param name="type" select="$idltype" />
1522 <xsl:with-param name="safearray" select="$safearray" />
1523 </xsl:call-template>
1524 </xsl:variable>
1525
1526 <xsl:variable name="elemgluetype">
1527 <xsl:if test="$safearray='yes'">
1528 <xsl:call-template name="typeIdl2Glue">
1529 <xsl:with-param name="type" select="$idltype" />
1530 <xsl:with-param name="safearray" select="'no'" />
1531 <xsl:with-param name="forceelem" select="'yes'" />
1532 </xsl:call-template>
1533 </xsl:if>
1534 </xsl:variable>
1535
1536 <xsl:choose>
1537 <xsl:when test="$idltype = '$unknown' or (count(key('G_keyInterfacesByName', $idltype)) > 0)">
1538 <xsl:choose>
1539 <xsl:when test="@safearray='yes'">
1540 <xsl:value-of select="concat('Helper.unwrap(', $value, ')')"/>
1541 </xsl:when>
1542 <xsl:otherwise>
1543 <xsl:value-of select="concat('((', $value, ' == null) ? null :', $value, '.getWrapped())')" />
1544 </xsl:otherwise>
1545 </xsl:choose>
1546 </xsl:when>
1547
1548 <xsl:when test="count(key('G_keyEnumsByName', $idltype)) > 0">
1549 <xsl:choose>
1550 <xsl:when test="$safearray='yes'">
1551 <xsl:variable name="elembacktype">
1552 <xsl:call-template name="typeIdl2Back">
1553 <xsl:with-param name="type" select="$idltype" />
1554 <xsl:with-param name="safearray" select="'no'" />
1555 <xsl:with-param name="forceelem" select="'yes'" />
1556 </xsl:call-template>
1557 </xsl:variable>
1558 <xsl:value-of select="concat('Helper.convertEnums(', $elemgluetype, '.class, ', $elembacktype, '.class, ', $value, ')')"/>
1559 </xsl:when>
1560 <xsl:otherwise>
1561 <xsl:variable name="backtype">
1562 <xsl:call-template name="typeIdl2Back">
1563 <xsl:with-param name="type" select="$idltype" />
1564 <xsl:with-param name="safearray" select="'no'" />
1565 <xsl:with-param name="forceelem" select="'yes'" />
1566 </xsl:call-template>
1567 </xsl:variable>
1568 <xsl:value-of select="concat($backtype, '.fromValue(', $value, '.name())')"/>
1569 </xsl:otherwise>
1570 </xsl:choose>
1571 </xsl:when>
1572
1573 <xsl:when test="($idltype='octet') and ($safearray='yes')">
1574 <xsl:value-of select="concat('Helper.encodeBase64(', $value, ')')"/>
1575 </xsl:when>
1576
1577 <xsl:otherwise>
1578 <xsl:value-of select="$value"/>
1579 </xsl:otherwise>
1580 </xsl:choose>
1581
1582</xsl:template>
1583
1584<xsl:template name="cookInParam">
1585 <xsl:param name="value"/>
1586 <xsl:param name="idltype"/>
1587 <xsl:param name="safearray"/>
1588 <xsl:choose>
1589 <xsl:when test="($G_vboxGlueStyle='xpcom')">
1590 <xsl:call-template name="cookInParamXpcom">
1591 <xsl:with-param name="value" select="$value" />
1592 <xsl:with-param name="idltype" select="$idltype" />
1593 <xsl:with-param name="safearray" select="$safearray" />
1594 </xsl:call-template>
1595 </xsl:when>
1596 <xsl:when test="($G_vboxGlueStyle='mscom')">
1597 <xsl:call-template name="cookInParamMscom">
1598 <xsl:with-param name="value" select="$value" />
1599 <xsl:with-param name="idltype" select="$idltype" />
1600 <xsl:with-param name="safearray" select="$safearray" />
1601 </xsl:call-template>
1602 </xsl:when>
1603 <xsl:when test="($G_vboxGlueStyle='jaxws')">
1604 <xsl:call-template name="cookInParamJaxws">
1605 <xsl:with-param name="value" select="$value" />
1606 <xsl:with-param name="idltype" select="$idltype" />
1607 <xsl:with-param name="safearray" select="$safearray" />
1608 </xsl:call-template>
1609 </xsl:when>
1610 <xsl:otherwise>
1611 <xsl:call-template name="fatalError">
1612 <xsl:with-param name="msg" select="'Unhandled style (cookInParam)'" />
1613 </xsl:call-template>
1614 </xsl:otherwise>
1615 </xsl:choose>
1616</xsl:template>
1617
1618<!-- Invoke backend method, including parameter conversion -->
1619<xsl:template name="genBackMethodCall">
1620 <xsl:param name="ifname"/>
1621 <xsl:param name="methodname"/>
1622 <xsl:param name="retval"/>
1623
1624 <xsl:choose>
1625 <xsl:when test="($G_vboxGlueStyle='xpcom')">
1626 <xsl:text> </xsl:text>
1627 <xsl:if test="param[@dir='return']">
1628 <xsl:value-of select="concat($retval, ' = ')" />
1629 </xsl:if>
1630 <xsl:value-of select="concat('getTypedWrapped().', $methodname, '(')"/>
1631 <xsl:for-each select="param">
1632 <xsl:choose>
1633 <xsl:when test="@dir='return'">
1634 <xsl:if test="@safearray='yes'">
1635 <xsl:text>null</xsl:text>
1636 </xsl:if>
1637 </xsl:when>
1638 <xsl:when test="@dir='out'">
1639 <xsl:if test="@safearray='yes'">
1640 <xsl:text>null, </xsl:text>
1641 </xsl:if>
1642 <xsl:value-of select="concat('tmp_', @name)" />
1643 </xsl:when>
1644 <xsl:when test="@dir='in'">
1645 <xsl:if test="(@safearray='yes') and not(@type = 'octet')">
1646 <xsl:value-of select="concat(@name, ' != null ? ', @name, '.size() : 0, ')" />
1647 </xsl:if>
1648 <xsl:variable name="unwrapped">
1649 <xsl:call-template name="cookInParam">
1650 <xsl:with-param name="value" select="@name" />
1651 <xsl:with-param name="idltype" select="@type" />
1652 <xsl:with-param name="safearray" select="@safearray" />
1653 </xsl:call-template>
1654 </xsl:variable>
1655 <xsl:value-of select="$unwrapped"/>
1656 </xsl:when>
1657 <xsl:otherwise>
1658 <xsl:call-template name="fatalError">
1659 <xsl:with-param name="msg" select="concat('Unsupported param dir: ', @dir, '&quot;.')" />
1660 </xsl:call-template>
1661 </xsl:otherwise>
1662 </xsl:choose>
1663 <xsl:if test="not(position()=last()) and not(following-sibling::param[1]/@dir='return' and not(following-sibling::param[1]/@safearray='yes'))">
1664 <xsl:text>, </xsl:text>
1665 </xsl:if>
1666 </xsl:for-each>
1667 <xsl:text>);&#10;</xsl:text>
1668 </xsl:when>
1669
1670 <xsl:when test="($G_vboxGlueStyle='mscom')">
1671 <xsl:text> </xsl:text>
1672 <xsl:if test="param[@dir='return']">
1673 <xsl:value-of select="concat($retval, ' = ')" />
1674 </xsl:if>
1675 <xsl:value-of select="concat('Helper.invoke(getTypedWrapped(), &quot;', $methodname, '&quot; ')"/>
1676 <xsl:for-each select="param[not(@dir='return')]">
1677 <xsl:text>, </xsl:text>
1678 <xsl:choose>
1679 <xsl:when test="@dir='out'">
1680 <xsl:value-of select="concat('tmp_', @name)" />
1681 </xsl:when>
1682 <xsl:when test="@dir='in'">
1683 <xsl:variable name="unwrapped">
1684 <xsl:call-template name="cookInParam">
1685 <xsl:with-param name="value" select="@name" />
1686 <xsl:with-param name="idltype" select="@type" />
1687 <xsl:with-param name="safearray" select="@safearray" />
1688 </xsl:call-template>
1689 </xsl:variable>
1690 <xsl:value-of select="$unwrapped"/>
1691 </xsl:when>
1692 </xsl:choose>
1693 </xsl:for-each>
1694 <xsl:text>);&#10;</xsl:text>
1695 </xsl:when>
1696
1697 <xsl:when test="($G_vboxGlueStyle='jaxws')">
1698 <xsl:variable name="jaxwsmethod">
1699 <xsl:call-template name="makeJaxwsMethod">
1700 <xsl:with-param name="ifname" select="$ifname" />
1701 <xsl:with-param name="methodname" select="$methodname" />
1702 </xsl:call-template>
1703 </xsl:variable>
1704 <xsl:variable name="portArg">
1705 <xsl:if test="not(key('G_keyInterfacesByName', $ifname)/@wsmap='global')">
1706 <xsl:text>obj</xsl:text>
1707 </xsl:if>
1708 </xsl:variable>
1709 <xsl:variable name="paramsinout" select="param[@dir='in' or @dir='out']" />
1710
1711 <xsl:text> </xsl:text>
1712 <xsl:if test="param[@dir='return'] and not(param[@dir='out'])">
1713 <xsl:value-of select="concat($retval, ' = ')" />
1714 </xsl:if>
1715 <xsl:value-of select="concat('port.', $jaxwsmethod, '(', $portArg)" />
1716 <xsl:if test="$paramsinout and not($portArg='')">
1717 <xsl:text>, </xsl:text>
1718 </xsl:if>
1719
1720 <!-- jax-ws has an oddity: if both out params and a return value exist,
1721 then the return value is moved to the function's argument list... -->
1722 <xsl:choose>
1723 <xsl:when test="param[@dir='out'] and param[@dir='return']">
1724 <xsl:for-each select="param">
1725 <xsl:choose>
1726 <xsl:when test="@dir='return'">
1727 <xsl:value-of select="$retval"/>
1728 </xsl:when>
1729 <xsl:when test="@dir='out'">
1730 <xsl:value-of select="concat('tmp_', @name)" />
1731 </xsl:when>
1732 <xsl:otherwise>
1733 <xsl:call-template name="cookInParam">
1734 <xsl:with-param name="value" select="@name" />
1735 <xsl:with-param name="idltype" select="@type" />
1736 <xsl:with-param name="safearray" select="@safearray" />
1737 </xsl:call-template>
1738 </xsl:otherwise>
1739 </xsl:choose>
1740 <xsl:if test="not(position()=last())">
1741 <xsl:text>, </xsl:text>
1742 </xsl:if>
1743 </xsl:for-each>
1744 </xsl:when>
1745 <xsl:otherwise>
1746 <xsl:for-each select="$paramsinout">
1747 <xsl:choose>
1748 <xsl:when test="@dir='return'">
1749 <xsl:value-of select="$retval"/>
1750 </xsl:when>
1751 <xsl:when test="@dir='out'">
1752 <xsl:value-of select="concat('tmp_', @name)" />
1753 </xsl:when>
1754 <xsl:otherwise>
1755 <xsl:call-template name="cookInParam">
1756 <xsl:with-param name="value" select="@name" />
1757 <xsl:with-param name="idltype" select="@type" />
1758 <xsl:with-param name="safearray" select="@safearray" />
1759 </xsl:call-template>
1760 </xsl:otherwise>
1761 </xsl:choose>
1762 <xsl:if test="not(position()=last())">
1763 <xsl:text>, </xsl:text>
1764 </xsl:if>
1765 </xsl:for-each>
1766 </xsl:otherwise>
1767 </xsl:choose>
1768 <xsl:text>);&#10;</xsl:text>
1769 </xsl:when>
1770
1771 <xsl:otherwise>
1772 <xsl:call-template name="fatalError">
1773 <xsl:with-param name="msg" select="'Style unknown (genBackMethodCall)'" />
1774 </xsl:call-template>
1775 </xsl:otherwise>
1776
1777 </xsl:choose>
1778</xsl:template>
1779
1780<xsl:template name="genGetterCall">
1781 <xsl:param name="ifname"/>
1782 <xsl:param name="gettername"/>
1783 <xsl:param name="backtype"/>
1784 <xsl:param name="retval"/>
1785
1786 <xsl:choose>
1787 <xsl:when test="$G_vboxGlueStyle='xpcom'">
1788 <xsl:value-of select="concat(' ', $backtype, ' ', $retval, ' = getTypedWrapped().', $gettername, '(')" />
1789 <xsl:if test="@safearray">
1790 <xsl:text>null</xsl:text>
1791 </xsl:if>
1792 <xsl:text>);&#10;</xsl:text>
1793 </xsl:when>
1794
1795 <xsl:when test="$G_vboxGlueStyle='mscom'">
1796 <xsl:value-of select="concat(' ', $backtype, ' ', $retval, ' = Dispatch.get(getTypedWrapped(), &quot;', @name, '&quot;);&#10;')" />
1797 </xsl:when>
1798
1799 <xsl:when test="$G_vboxGlueStyle='jaxws'">
1800 <xsl:variable name="jaxwsGetter">
1801 <xsl:call-template name="makeJaxwsMethod">
1802 <xsl:with-param name="ifname" select="$ifname" />
1803 <xsl:with-param name="methodname" select="$gettername" />
1804 </xsl:call-template>
1805 </xsl:variable>
1806 <xsl:value-of select="concat(' ', $backtype, ' ', $retval, ' = port.', $jaxwsGetter, '(obj);&#10;')" />
1807 </xsl:when>
1808
1809 <xsl:otherwise>
1810 <xsl:call-template name="fatalError">
1811 <xsl:with-param name="msg" select="'Style unknown (genGetterCall)'" />
1812 </xsl:call-template>
1813 </xsl:otherwise>
1814 </xsl:choose>
1815</xsl:template>
1816
1817<xsl:template name="genSetterCall">
1818 <xsl:param name="ifname"/>
1819 <xsl:param name="settername"/>
1820 <xsl:param name="value"/>
1821
1822 <xsl:choose>
1823 <xsl:when test="$G_vboxGlueStyle='xpcom'">
1824 <xsl:value-of select="concat(' getTypedWrapped().', $settername, '(', $value, ');&#10;')" />
1825 </xsl:when>
1826
1827 <xsl:when test="$G_vboxGlueStyle='mscom'">
1828 <xsl:value-of select="concat(' Dispatch.put(getTypedWrapped(), &quot;', @name, '&quot;, ', $value, ');&#10;')" />
1829 </xsl:when>
1830
1831 <xsl:when test="$G_vboxGlueStyle='jaxws'">
1832 <xsl:variable name="jaxwsSetter">
1833 <xsl:call-template name="makeJaxwsMethod">
1834 <xsl:with-param name="ifname" select="$ifname" />
1835 <xsl:with-param name="methodname" select="$settername" />
1836 </xsl:call-template>
1837 </xsl:variable>
1838 <xsl:value-of select="concat(' port.', $jaxwsSetter, '(obj, ', $value, ');&#10;')" />
1839 </xsl:when>
1840
1841 <xsl:otherwise>
1842 <xsl:call-template name="fatalError">
1843 <xsl:with-param name="msg" select="'Style unknown (genSetterCall)'" />
1844 </xsl:call-template>
1845 </xsl:otherwise>
1846 </xsl:choose>
1847</xsl:template>
1848
1849<xsl:template name="genStructWrapperJaxws">
1850 <xsl:param name="ifname"/>
1851
1852 <xsl:value-of select="concat(' private ', $G_virtualBoxPackageCom, '.', $ifname, ' real;&#10;')"/>
1853 <xsl:text> private VboxPortType port;&#10;&#10;</xsl:text>
1854
1855 <xsl:value-of select="concat(' public ', $ifname, '(', $G_virtualBoxPackageCom, '.', $ifname, ' real, VboxPortType port)&#10;')" />
1856 <xsl:text> {&#10;</xsl:text>
1857 <xsl:text> this.real = real;&#10;</xsl:text>
1858 <xsl:text> this.port = port;&#10;</xsl:text>
1859 <xsl:text> }&#10;&#10;</xsl:text>
1860
1861 <xsl:for-each select="attribute">
1862 <xsl:variable name="attrname"><xsl:value-of select="@name" /></xsl:variable>
1863 <xsl:variable name="attrtype"><xsl:value-of select="@type" /></xsl:variable>
1864 <xsl:variable name="attrsafearray"><xsl:value-of select="@safearray" /></xsl:variable>
1865
1866 <xsl:if test="not(@wsmap = 'suppress')">
1867
1868 <xsl:if test="not(@readonly = 'yes')">
1869 <xsl:call-template name="fatalError">
1870 <xsl:with-param name="msg" select="concat('Non read-only struct (genStructWrapperJaxws) in interface ', $ifname, ', attribute ', $attrname)" />
1871 </xsl:call-template>
1872 </xsl:if>
1873
1874 <!-- Emit getter -->
1875 <xsl:variable name="backgettername">
1876 <xsl:choose>
1877 <!-- Stupid, but backend boolean getters called isFoo(), not getFoo() -->
1878 <xsl:when test="$attrtype = 'boolean'">
1879 <xsl:variable name="capsname">
1880 <xsl:call-template name="capitalize">
1881 <xsl:with-param name="str" select="$attrname" />
1882 </xsl:call-template>
1883 </xsl:variable>
1884 <xsl:value-of select="concat('is', $capsname)" />
1885 </xsl:when>
1886 <xsl:otherwise>
1887 <xsl:call-template name="makeGetterName">
1888 <xsl:with-param name="attrname" select="$attrname" />
1889 </xsl:call-template>
1890 </xsl:otherwise>
1891 </xsl:choose>
1892 </xsl:variable>
1893
1894 <xsl:variable name="gluegettername">
1895 <xsl:call-template name="makeGetterName">
1896 <xsl:with-param name="attrname" select="$attrname" />
1897 </xsl:call-template>
1898 </xsl:variable>
1899
1900 <xsl:variable name="gluegettertype">
1901 <xsl:call-template name="typeIdl2Glue">
1902 <xsl:with-param name="type" select="$attrtype" />
1903 <xsl:with-param name="safearray" select="@safearray" />
1904 </xsl:call-template>
1905 </xsl:variable>
1906
1907 <xsl:variable name="backgettertype">
1908 <xsl:call-template name="typeIdl2Back">
1909 <xsl:with-param name="type" select="$attrtype" />
1910 <xsl:with-param name="safearray" select="@safearray" />
1911 </xsl:call-template>
1912 </xsl:variable>
1913
1914 <xsl:apply-templates select="desc" mode="attribute_get"/>
1915 <xsl:value-of select="concat(' public ', $gluegettertype, ' ', $gluegettername, '()&#10;')" />
1916 <xsl:text> {&#10;</xsl:text>
1917 <xsl:value-of select="concat(' ', $backgettertype, ' retVal = real.', $backgettername, '();&#10;')" />
1918 <xsl:variable name="wrapped">
1919 <xsl:call-template name="cookOutParam">
1920 <xsl:with-param name="value" select="'retVal'" />
1921 <xsl:with-param name="idltype" select="$attrtype" />
1922 <xsl:with-param name="safearray" select="@safearray" />
1923 </xsl:call-template>
1924 </xsl:variable>
1925 <xsl:value-of select="concat(' return ', $wrapped, ';&#10;')" />
1926 <xsl:text> }&#10;</xsl:text>
1927 </xsl:if>
1928
1929 </xsl:for-each>
1930
1931</xsl:template>
1932
1933<!-- Interface method wrapper -->
1934<xsl:template name="genMethod">
1935 <xsl:param name="ifname"/>
1936 <xsl:param name="methodname"/>
1937
1938 <xsl:choose>
1939 <xsl:when test="(param[@mod='ptr']) or (($G_vboxGlueStyle='jaxws') and (param[@type=($G_setSuppressedInterfaces/@name)]))" >
1940 <xsl:value-of select="concat(' // Skipping method ', $methodname, ' for it has parameters with suppressed types&#10;')" />
1941 </xsl:when>
1942 <xsl:when test="($G_vboxGlueStyle='jaxws') and (@wsmap = 'suppress')" >
1943 <xsl:value-of select="concat(' // Skipping method ', $methodname, ' for it is suppressed&#10;')" />
1944 </xsl:when>
1945 <xsl:otherwise>
1946 <xsl:variable name="hasReturnParms" select="param[@dir='return']" />
1947 <xsl:variable name="hasOutParms" select="count(param[@dir='out']) > 0" />
1948 <xsl:variable name="returnidltype" select="param[@dir='return']/@type" />
1949 <xsl:variable name="returnidlsafearray" select="param[@dir='return']/@safearray" />
1950 <xsl:if test="$hasOutParms and not($hasReturnParms) and (string-length(@wsmap) = 0) and (count(param[@dir='out']) = 1)">
1951 <xsl:call-template name="fatalError">
1952 <xsl:with-param name="msg" select="concat('genMethod: ', $ifname, $hasOutParms, not($hasReturnParms), 'a', string-length(@wsmap) = 0, 'b', @wsmap, (count(param[@dir='out']) = 1), '::', $methodname, ' has exactly one out parameter and no return parameter, this causes trouble with JAX-WS and the out parameter needs to be converted to return')" />
1953 </xsl:call-template>
1954 </xsl:if>
1955 <xsl:variable name="returngluetype">
1956 <xsl:choose>
1957 <xsl:when test="$returnidltype">
1958 <xsl:call-template name="typeIdl2Glue">
1959 <xsl:with-param name="type" select="$returnidltype" />
1960 <xsl:with-param name="safearray" select="$returnidlsafearray" />
1961 </xsl:call-template>
1962 </xsl:when>
1963 <xsl:otherwise>
1964 <xsl:text>void</xsl:text>
1965 </xsl:otherwise>
1966 </xsl:choose>
1967 </xsl:variable>
1968 <xsl:variable name="retValValue">
1969 <xsl:choose>
1970 <xsl:when test="(param[@dir='out']) and ($G_vboxGlueStyle='jaxws')">
1971 <xsl:text>retVal.value</xsl:text>
1972 </xsl:when>
1973 <xsl:otherwise>
1974 <xsl:text>retVal</xsl:text>
1975 </xsl:otherwise>
1976 </xsl:choose>
1977 </xsl:variable>
1978 <xsl:apply-templates select="desc" mode="method"/>
1979 <xsl:value-of select="concat(' public ', $returngluetype, ' ', $methodname, '(')" />
1980 <xsl:variable name="paramsinout" select="param[@dir='in' or @dir='out']" />
1981 <xsl:for-each select="exsl:node-set($paramsinout)">
1982 <xsl:variable name="paramgluetype">
1983 <xsl:call-template name="typeIdl2Glue">
1984 <xsl:with-param name="type" select="@type" />
1985 <xsl:with-param name="safearray" select="@safearray" />
1986 </xsl:call-template>
1987 </xsl:variable>
1988 <xsl:choose>
1989 <xsl:when test="@dir='out'">
1990 <xsl:value-of select="concat('Holder&lt;', $paramgluetype, '&gt; ', @name)" />
1991 </xsl:when>
1992 <xsl:otherwise>
1993 <xsl:value-of select="concat($paramgluetype, ' ', @name)" />
1994 </xsl:otherwise>
1995 </xsl:choose>
1996 <xsl:if test="not(position()=last())">
1997 <xsl:text>, </xsl:text>
1998 </xsl:if>
1999 </xsl:for-each>
2000 <xsl:text>)&#10;</xsl:text>
2001 <xsl:text> {&#10;</xsl:text>
2002
2003 <xsl:call-template name="startExcWrapper"/>
2004
2005 <!-- declare temp out params -->
2006 <xsl:for-each select="param[@dir='out']">
2007 <xsl:variable name="backouttype">
2008 <xsl:call-template name="typeIdl2Back">
2009 <xsl:with-param name="type" select="@type" />
2010 <xsl:with-param name="safearray" select="@safearray" />
2011 </xsl:call-template>
2012 </xsl:variable>
2013 <xsl:choose>
2014 <xsl:when test="$G_vboxGlueStyle='xpcom'">
2015 <xsl:value-of select="concat(' ', $backouttype, '[] tmp_', @name, ' = (', $backouttype, '[])java.lang.reflect.Array.newInstance(', $backouttype, '.class, 1);&#10;')"/>
2016 </xsl:when>
2017 <xsl:when test="$G_vboxGlueStyle='mscom'">
2018 <xsl:value-of select="concat(' Variant tmp_', @name, ' = new Variant();&#10;')"/>
2019 </xsl:when>
2020 <xsl:when test="$G_vboxGlueStyle='jaxws'">
2021 <xsl:value-of select="concat(' javax.xml.ws.Holder&lt;', $backouttype, '&gt; tmp_', @name, ' = new javax.xml.ws.Holder&lt;', $backouttype, '&gt;();&#10;')"/>
2022 </xsl:when>
2023 <xsl:otherwise>
2024 <xsl:call-template name="fatalError">
2025 <xsl:with-param name="msg" select="'Handle out param (genMethod)'" />
2026 </xsl:call-template>
2027 </xsl:otherwise>
2028 </xsl:choose>
2029 </xsl:for-each>
2030
2031 <!-- declare return param, if any -->
2032 <xsl:if test="$hasReturnParms">
2033 <xsl:variable name="backrettype">
2034 <xsl:call-template name="typeIdl2Back">
2035 <xsl:with-param name="type" select="$returnidltype" />
2036 <xsl:with-param name="safearray" select="$returnidlsafearray" />
2037 </xsl:call-template>
2038 </xsl:variable>
2039 <xsl:choose>
2040 <xsl:when test="(param[@dir='out']) and ($G_vboxGlueStyle='jaxws')">
2041 <xsl:value-of select="concat(' javax.xml.ws.Holder&lt;', $backrettype, '&gt;',
2042 ' retVal = new javax.xml.ws.Holder&lt;', $backrettype,
2043 '&gt;();&#10;')"/>
2044 </xsl:when>
2045 <xsl:otherwise>
2046 <xsl:value-of select="concat(' ', $backrettype, ' retVal;&#10;')"/>
2047 </xsl:otherwise>
2048 </xsl:choose>
2049 </xsl:if>
2050
2051 <!-- Method call -->
2052 <xsl:call-template name="genBackMethodCall">
2053 <xsl:with-param name="ifname" select="$ifname" />
2054 <xsl:with-param name="methodname" select="$methodname" />
2055 <xsl:with-param name="retval" select="'retVal'" />
2056 </xsl:call-template>
2057
2058 <!-- return out params -->
2059 <xsl:for-each select="param[@dir='out']">
2060 <xsl:variable name="varval">
2061 <xsl:choose>
2062 <xsl:when test="$G_vboxGlueStyle='xpcom'">
2063 <xsl:value-of select="concat('tmp_', @name, '[0]')" />
2064 </xsl:when>
2065 <xsl:when test="$G_vboxGlueStyle='mscom'">
2066 <xsl:value-of select="concat('tmp_', @name)" />
2067 </xsl:when>
2068 <xsl:when test="$G_vboxGlueStyle='jaxws'">
2069 <xsl:value-of select="concat('tmp_', @name, '.value')" />
2070 </xsl:when>
2071 <xsl:otherwise>
2072 <xsl:call-template name="fatalError">
2073 <xsl:with-param name="msg" select="'Style unknown (genMethod, outparam)'" />
2074 </xsl:call-template>
2075 </xsl:otherwise>
2076 </xsl:choose>
2077 </xsl:variable>
2078 <xsl:variable name="wrapped">
2079 <xsl:call-template name="cookOutParam">
2080 <xsl:with-param name="value" select="$varval" />
2081 <xsl:with-param name="idltype" select="@type" />
2082 <xsl:with-param name="safearray" select="@safearray" />
2083 </xsl:call-template>
2084 </xsl:variable>
2085 <xsl:value-of select="concat(' ', @name, '.value = ', $wrapped, ';&#10;')"/>
2086 </xsl:for-each>
2087
2088 <xsl:if test="$hasReturnParms">
2089 <!-- actual 'return' statement -->
2090 <xsl:variable name="wrapped">
2091 <xsl:call-template name="cookOutParam">
2092 <xsl:with-param name="value" select="$retValValue" />
2093 <xsl:with-param name="idltype" select="$returnidltype" />
2094 <xsl:with-param name="safearray" select="$returnidlsafearray" />
2095 </xsl:call-template>
2096 </xsl:variable>
2097 <xsl:value-of select="concat(' return ', $wrapped, ';&#10;')" />
2098 </xsl:if>
2099 <xsl:call-template name="endExcWrapper"/>
2100
2101 <xsl:text> }&#10;</xsl:text>
2102 </xsl:otherwise>
2103 </xsl:choose>
2104
2105</xsl:template>
2106
2107<!-- Callback interface method -->
2108<xsl:template name="genCbMethodDecl">
2109 <xsl:param name="ifname"/>
2110 <xsl:param name="methodname"/>
2111
2112 <xsl:choose>
2113 <xsl:when test="(param[@mod='ptr'])" >
2114 <xsl:value-of select="concat(' // Skipping method ', $methodname, ' for it has parameters with suppressed types&#10;')" />
2115 </xsl:when>
2116 <xsl:otherwise>
2117 <xsl:variable name="returnidltype" select="param[@dir='return']/@type" />
2118 <xsl:variable name="returnidlsafearray" select="param[@dir='return']/@safearray" />
2119 <xsl:variable name="returngluetype">
2120 <xsl:choose>
2121 <xsl:when test="$returnidltype">
2122 <xsl:call-template name="typeIdl2Glue">
2123 <xsl:with-param name="type" select="$returnidltype" />
2124 <xsl:with-param name="safearray" select="$returnidlsafearray" />
2125 </xsl:call-template>
2126 </xsl:when>
2127 <xsl:otherwise>
2128 <xsl:text>void</xsl:text>
2129 </xsl:otherwise>
2130 </xsl:choose>
2131 </xsl:variable>
2132 <xsl:value-of select="concat(' public ', $returngluetype, ' ', $methodname, '(')" />
2133 <xsl:variable name="paramsinout" select="param[@dir='in' or @dir='out']" />
2134 <xsl:for-each select="exsl:node-set($paramsinout)">
2135 <xsl:variable name="paramgluetype">
2136 <xsl:call-template name="typeIdl2Glue">
2137 <xsl:with-param name="type" select="@type" />
2138 <xsl:with-param name="safearray" select="@safearray" />
2139 </xsl:call-template>
2140 </xsl:variable>
2141 <xsl:choose>
2142 <xsl:when test="@dir='out'">
2143 <xsl:value-of select="concat('Holder&lt;', $paramgluetype, '&gt; ', @name)" />
2144 </xsl:when>
2145 <xsl:otherwise>
2146 <xsl:value-of select="concat($paramgluetype, ' ', @name)" />
2147 </xsl:otherwise>
2148 </xsl:choose>
2149 <xsl:if test="not(position()=last())">
2150 <xsl:text>, </xsl:text>
2151 </xsl:if>
2152 </xsl:for-each>
2153 <xsl:text>);&#10;</xsl:text>
2154 </xsl:otherwise>
2155 </xsl:choose>
2156</xsl:template>
2157
2158<!-- queryInterface wrapper -->
2159<xsl:template name="genQI">
2160 <xsl:param name="ifname"/>
2161 <xsl:param name="uuid" />
2162
2163 <xsl:value-of select="concat(' public static ', $ifname, ' queryInterface(IUnknown obj)&#10;')" />
2164 <xsl:text> {&#10;</xsl:text>
2165 <xsl:choose>
2166 <xsl:when test="$G_vboxGlueStyle='xpcom'">
2167 <xsl:variable name="backtype">
2168 <xsl:call-template name="typeIdl2Back">
2169 <xsl:with-param name="type" select="$ifname" />
2170 </xsl:call-template>
2171 </xsl:variable>
2172 <xsl:text> nsISupports nsobj = obj != null ? (nsISupports)obj.getWrapped() : null;&#10;</xsl:text>
2173 <xsl:text> if (nsobj == null) return null;&#10;</xsl:text>
2174 <xsl:value-of select="concat(' ', $backtype, ' qiobj = Helper.queryInterface(nsobj, &quot;{', $uuid, '}&quot;, ', $backtype, '.class);&#10;')" />
2175 <xsl:value-of select="concat(' return qiobj == null ? null : new ', $ifname, '(qiobj);&#10;')" />
2176 </xsl:when>
2177
2178 <xsl:when test="$G_vboxGlueStyle='mscom'">
2179 <xsl:value-of select="concat(' return', ' obj == null ? null : new ', $ifname, '((com.jacob.com.Dispatch)obj.getWrapped());&#10;')" />
2180 </xsl:when>
2181
2182 <xsl:when test="$G_vboxGlueStyle='jaxws'">
2183 <!-- bad, need to check that we really can be casted to this type -->
2184 <xsl:value-of select="concat(' return obj == null ? null : new ', $ifname, '(obj.getWrapped(), obj.getRemoteWSPort());&#10;')" />
2185 </xsl:when>
2186
2187 <xsl:otherwise>
2188 <xsl:call-template name="fatalError">
2189 <xsl:with-param name="msg" select="'Style unknown (genQI)'" />
2190 </xsl:call-template>
2191 </xsl:otherwise>
2192
2193 </xsl:choose>
2194 <xsl:text> }&#10;</xsl:text>
2195</xsl:template>
2196
2197
2198<xsl:template name="genCbMethodImpl">
2199 <xsl:param name="ifname"/>
2200 <xsl:param name="methodname"/>
2201
2202 <xsl:choose>
2203 <xsl:when test="(param[@mod='ptr'])" >
2204 <xsl:value-of select="concat(' // Skipping method ', $methodname, ' for it has parameters with suppressed types&#10;')" />
2205 </xsl:when>
2206 <xsl:otherwise>
2207 <xsl:variable name="hasReturnParms" select="param[@dir='return']" />
2208 <xsl:variable name="returnidltype" select="param[@dir='return']/@type" />
2209 <xsl:variable name="returnidlsafearray" select="param[@dir='return']/@safearray" />
2210 <xsl:variable name="returnbacktype">
2211 <xsl:choose>
2212 <xsl:when test="$returnidltype">
2213 <xsl:call-template name="typeIdl2Back">
2214 <xsl:with-param name="type" select="$returnidltype" />
2215 <xsl:with-param name="safearray" select="$returnidlsafearray" />
2216 </xsl:call-template>
2217 </xsl:when>
2218 <xsl:otherwise>
2219 <xsl:text>void</xsl:text>
2220 </xsl:otherwise>
2221 </xsl:choose>
2222 </xsl:variable>
2223 <xsl:variable name="paramsinout" select="param[@dir='in' or @dir='out']" />
2224 <xsl:choose>
2225 <xsl:when test="$G_vboxGlueStyle='xpcom'">
2226 <xsl:value-of select="concat(' public ', $returnbacktype, ' ', $methodname, '(')" />
2227 <xsl:for-each select="exsl:node-set($paramsinout)">
2228 <xsl:variable name="parambacktype">
2229 <xsl:call-template name="typeIdl2Back">
2230 <xsl:with-param name="type" select="@type" />
2231 <xsl:with-param name="safearray" select="@safearray" />
2232 </xsl:call-template>
2233 </xsl:variable>
2234 <xsl:choose>
2235 <xsl:when test="@dir='out'">
2236 <xsl:value-of select="concat($parambacktype, '[] ', @name)" />
2237 </xsl:when>
2238 <xsl:otherwise>
2239 <xsl:if test="@safearray">
2240 <xsl:value-of select="concat('long len_', @name, ', ')" />
2241 </xsl:if>
2242 <xsl:value-of select="concat($parambacktype, ' ', @name)" />
2243 </xsl:otherwise>
2244 </xsl:choose>
2245 <xsl:if test="not(position()=last())">
2246 <xsl:text>, </xsl:text>
2247 </xsl:if>
2248 </xsl:for-each>
2249 <xsl:text>)&#10;</xsl:text>
2250 <xsl:text> {&#10;</xsl:text>
2251 </xsl:when>
2252
2253 <xsl:when test="$G_vboxGlueStyle='mscom'">
2254 <xsl:variable name="capsname">
2255 <xsl:call-template name="capitalize">
2256 <xsl:with-param name="str" select="$methodname" />
2257 </xsl:call-template>
2258 </xsl:variable>
2259 <xsl:value-of select="concat(' public ', $returnbacktype, ' ', $capsname, '(')" />
2260 <xsl:text>Variant _args[])&#10;</xsl:text>
2261 <xsl:text> {&#10;</xsl:text>
2262 <xsl:for-each select="exsl:node-set($paramsinout)">
2263 <xsl:variable name="parambacktype">
2264 <xsl:call-template name="typeIdl2Back">
2265 <xsl:with-param name="type" select="@type" />
2266 <xsl:with-param name="safearray" select="@safearray" />
2267 </xsl:call-template>
2268 </xsl:variable>
2269 <xsl:value-of select="concat(' ', $parambacktype, ' ', @name, '=_args[', count(preceding-sibling::param), '];&#10;')" />
2270 </xsl:for-each>
2271 </xsl:when>
2272
2273 <xsl:otherwise>
2274 <xsl:call-template name="fatalError">
2275 <xsl:with-param name="msg" select="'Style unknown (genSetterCall)'" />
2276 </xsl:call-template>
2277 </xsl:otherwise>
2278 </xsl:choose>
2279
2280 <!-- declare temp out params -->
2281 <xsl:for-each select="param[@dir='out']">
2282 <xsl:variable name="glueouttype">
2283 <xsl:call-template name="typeIdl2Glue">
2284 <xsl:with-param name="type" select="@type" />
2285 <xsl:with-param name="safearray" select="@safearray" />
2286 </xsl:call-template>
2287 </xsl:variable>
2288 <xsl:value-of select="concat(' Holder&lt;', $glueouttype, '&gt; tmp_', @name, ' = new Holder&lt;', $glueouttype, '&gt;();&#10;')"/>
2289 </xsl:for-each>
2290
2291 <!-- declare return param, if any -->
2292 <xsl:if test="$hasReturnParms">
2293 <xsl:variable name="gluerettype">
2294 <xsl:call-template name="typeIdl2Glue">
2295 <xsl:with-param name="type" select="$returnidltype" />
2296 <xsl:with-param name="safearray" select="$returnidlsafearray" />
2297 </xsl:call-template>
2298 </xsl:variable>
2299 <xsl:value-of select="concat(' ', $gluerettype, ' retVal = &#10;')"/>
2300 </xsl:if>
2301
2302 <!-- Method call -->
2303 <xsl:value-of select="concat(' sink.', $methodname, '(')"/>
2304 <xsl:for-each select="param[not(@dir='return')]">
2305 <xsl:choose>
2306 <xsl:when test="@dir='out'">
2307 <xsl:value-of select="concat('tmp_', @name)" />
2308 </xsl:when>
2309 <xsl:when test="@dir='in'">
2310 <xsl:variable name="wrapped">
2311 <xsl:call-template name="cookOutParam">
2312 <xsl:with-param name="value" select="@name" />
2313 <xsl:with-param name="idltype" select="@type" />
2314 <xsl:with-param name="safearray" select="@safearray" />
2315 </xsl:call-template>
2316 </xsl:variable>
2317 <xsl:value-of select="$wrapped"/>
2318 </xsl:when>
2319 <xsl:otherwise>
2320 <xsl:call-template name="fatalError">
2321 <xsl:with-param name="msg" select="concat('Unsupported param dir: ', @dir, '&quot;.')" />
2322 </xsl:call-template>
2323 </xsl:otherwise>
2324 </xsl:choose>
2325 <xsl:if test="not(position()=last())">
2326 <xsl:text>, </xsl:text>
2327 </xsl:if>
2328 </xsl:for-each>
2329 <xsl:text>);&#10;</xsl:text>
2330
2331 <!-- return out params -->
2332 <xsl:for-each select="param[@dir='out']">
2333
2334 <xsl:variable name="unwrapped">
2335 <xsl:call-template name="cookInParam">
2336 <xsl:with-param name="value" select="concat('tmp_', @name, '.value')" />
2337 <xsl:with-param name="idltype" select="@type" />
2338 <xsl:with-param name="safearray" select="@safearray" />
2339 </xsl:call-template>
2340 </xsl:variable>
2341 <xsl:choose>
2342 <xsl:when test="$G_vboxGlueStyle='xpcom'">
2343 <xsl:value-of select="concat(' ', @name, '[0] = ', $unwrapped, ';&#10;')"/>
2344 </xsl:when>
2345 <xsl:when test="$G_vboxGlueStyle='mscom'">
2346 <xsl:value-of select="concat(' _args[', count(preceding-sibling::param), '] = ', $unwrapped, ';&#10;')"/>
2347 </xsl:when>
2348 </xsl:choose>
2349 </xsl:for-each>
2350
2351 <xsl:if test="$hasReturnParms">
2352 <!-- actual 'return' statement -->
2353 <xsl:variable name="unwrapped">
2354 <xsl:call-template name="cookInParam">
2355 <xsl:with-param name="value" select="'retVal'" />
2356 <xsl:with-param name="idltype" select="$returnidltype" />
2357 <xsl:with-param name="safearray" select="$returnidlsafearray" />
2358 </xsl:call-template>
2359 </xsl:variable>
2360 <xsl:value-of select="concat(' return ', $unwrapped, ';&#10;')" />
2361 </xsl:if>
2362 <xsl:text> }&#10;</xsl:text>
2363 </xsl:otherwise>
2364 </xsl:choose>
2365</xsl:template>
2366
2367<!-- Interface method -->
2368<xsl:template name="genIfaceWrapper">
2369 <xsl:param name="ifname"/>
2370
2371 <xsl:variable name="wrappedType">
2372 <xsl:call-template name="wrappedName">
2373 <xsl:with-param name="ifname" select="$ifname" />
2374 </xsl:call-template>
2375 </xsl:variable>
2376
2377 <!-- Constructor -->
2378 <xsl:choose>
2379 <xsl:when test="($G_vboxGlueStyle='jaxws')">
2380 <xsl:value-of select="concat(' public ', $ifname, '(String wrapped, VboxPortType port)&#10;')" />
2381 <xsl:text> {&#10;</xsl:text>
2382 <xsl:text> super(wrapped, port);&#10;</xsl:text>
2383 <xsl:text> }&#10;</xsl:text>
2384 </xsl:when>
2385
2386 <xsl:when test="($G_vboxGlueStyle='xpcom') or ($G_vboxGlueStyle='mscom')">
2387 <xsl:value-of select="concat(' public ', $ifname, '(', $wrappedType, ' wrapped)&#10;')" />
2388 <xsl:text> {&#10;</xsl:text>
2389 <xsl:text> super(wrapped);&#10;</xsl:text>
2390 <xsl:text> }&#10;</xsl:text>
2391
2392 <!-- Typed wrapped object accessor -->
2393 <xsl:value-of select="concat(' public ', $wrappedType, ' getTypedWrapped()&#10;')" />
2394 <xsl:text> {&#10;</xsl:text>
2395 <xsl:value-of select="concat(' return (', $wrappedType, ') getWrapped();&#10;')" />
2396 <xsl:text> }&#10;</xsl:text>
2397 </xsl:when>
2398
2399 <xsl:otherwise>
2400 <xsl:call-template name="fatalError">
2401 <xsl:with-param name="msg" select="'Style unknown (root, ctr)'" />
2402 </xsl:call-template>
2403 </xsl:otherwise>
2404 </xsl:choose>
2405 <!-- Attributes -->
2406 <xsl:for-each select="attribute[not(@mod='ptr')]">
2407 <xsl:variable name="attrname"><xsl:value-of select="@name" /></xsl:variable>
2408 <xsl:variable name="attrtype"><xsl:value-of select="@type" /></xsl:variable>
2409 <xsl:variable name="attrsafearray"><xsl:value-of select="@safearray" /></xsl:variable>
2410
2411 <xsl:choose>
2412 <xsl:when test="($G_vboxGlueStyle='jaxws') and ($attrtype=($G_setSuppressedInterfaces/@name))">
2413 <xsl:value-of select="concat(' // Skipping attribute ', $attrname, ' of suppressed type ', $attrtype, '&#10;&#10;')" />
2414 </xsl:when>
2415 <xsl:when test="($G_vboxGlueStyle='jaxws') and (@wsmap = 'suppress')" >
2416 <xsl:value-of select="concat(' // Skipping attribute ', $attrname, ' for it is suppressed&#10;')" />
2417 </xsl:when>
2418
2419 <xsl:otherwise>
2420 <!-- emit getter method -->
2421 <xsl:apply-templates select="desc" mode="attribute_get"/>
2422 <xsl:variable name="gettername">
2423 <xsl:call-template name="makeGetterName">
2424 <xsl:with-param name="attrname" select="$attrname" />
2425 </xsl:call-template>
2426 </xsl:variable>
2427 <xsl:variable name="gluetype">
2428 <xsl:call-template name="typeIdl2Glue">
2429 <xsl:with-param name="type" select="$attrtype" />
2430 <xsl:with-param name="safearray" select="@safearray" />
2431 </xsl:call-template>
2432 </xsl:variable>
2433 <xsl:variable name="backtype">
2434 <xsl:call-template name="typeIdl2Back">
2435 <xsl:with-param name="type" select="$attrtype" />
2436 <xsl:with-param name="safearray" select="@safearray" />
2437 </xsl:call-template>
2438 </xsl:variable>
2439 <xsl:variable name="wrapped">
2440 <xsl:call-template name="cookOutParam">
2441 <xsl:with-param name="value" select="'retVal'" />
2442 <xsl:with-param name="idltype" select="$attrtype" />
2443 <xsl:with-param name="safearray" select="@safearray" />
2444 </xsl:call-template>
2445 </xsl:variable>
2446 <xsl:value-of select="concat(' public ', $gluetype, ' ', $gettername, '()&#10;')" />
2447 <xsl:text> {&#10;</xsl:text>
2448
2449 <xsl:call-template name="startExcWrapper"/>
2450
2451 <!-- Actual getter implementation -->
2452 <xsl:call-template name="genGetterCall">
2453 <xsl:with-param name="ifname" select="$ifname" />
2454 <xsl:with-param name="gettername" select="$gettername" />
2455 <xsl:with-param name="backtype" select="$backtype" />
2456 <xsl:with-param name="retval" select="'retVal'" />
2457 </xsl:call-template>
2458
2459 <xsl:value-of select="concat(' return ', $wrapped, ';&#10;')" />
2460 <xsl:call-template name="endExcWrapper"/>
2461
2462 <xsl:text> }&#10;</xsl:text>
2463 <xsl:if test="not(@readonly = 'yes')">
2464 <!-- emit setter method -->
2465 <xsl:apply-templates select="desc" mode="attribute_set"/>
2466 <xsl:variable name="settername"><xsl:call-template name="makeSetterName"><xsl:with-param name="attrname" select="$attrname" /></xsl:call-template></xsl:variable>
2467 <xsl:variable name="unwrapped">
2468 <xsl:call-template name="cookInParam">
2469 <xsl:with-param name="ifname" select="$ifname" />
2470 <xsl:with-param name="value" select="'value'" />
2471 <xsl:with-param name="idltype" select="$attrtype" />
2472 <xsl:with-param name="safearray" select="@safearray" />
2473 </xsl:call-template>
2474 </xsl:variable>
2475 <xsl:value-of select="concat(' public void ', $settername, '(', $gluetype, ' value)&#10;')" />
2476 <xsl:text> {&#10;</xsl:text>
2477 <xsl:call-template name="startExcWrapper"/>
2478 <!-- Actual setter implementation -->
2479 <xsl:call-template name="genSetterCall">
2480 <xsl:with-param name="ifname" select="$ifname" />
2481 <xsl:with-param name="settername" select="$settername" />
2482 <xsl:with-param name="value" select="$unwrapped" />
2483 </xsl:call-template>
2484 <xsl:call-template name="endExcWrapper"/>
2485 <xsl:text> }&#10;</xsl:text>
2486 </xsl:if>
2487
2488 </xsl:otherwise>
2489 </xsl:choose>
2490
2491 </xsl:for-each>
2492
2493 <!-- emit queryInterface() *to* this class -->
2494 <xsl:call-template name="genQI">
2495 <xsl:with-param name="ifname" select="$ifname" />
2496 <xsl:with-param name="uuid" select="@uuid" />
2497 </xsl:call-template>
2498
2499 <!-- emit methods -->
2500 <xsl:for-each select="method">
2501 <xsl:call-template name="genMethod">
2502 <xsl:with-param name="ifname" select="$ifname" />
2503 <xsl:with-param name="methodname" select="@name" />
2504 </xsl:call-template>
2505 </xsl:for-each>
2506
2507</xsl:template>
2508
2509<xsl:template name="genIface">
2510 <xsl:param name="ifname" />
2511 <xsl:param name="filename" />
2512
2513 <xsl:variable name="wsmap" select="@wsmap" />
2514
2515 <xsl:call-template name="startFile">
2516 <xsl:with-param name="file" select="$filename" />
2517 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
2518 </xsl:call-template>
2519
2520 <xsl:if test="$filelistonly=''">
2521 <xsl:text>import java.util.List;&#10;&#10;</xsl:text>
2522
2523 <xsl:apply-templates select="desc" mode="interface"/>
2524
2525 <xsl:choose>
2526 <xsl:when test="($wsmap='struct') and ($G_vboxGlueStyle='jaxws')">
2527 <xsl:value-of select="concat('public class ', $ifname, '&#10;')" />
2528 <xsl:text>{&#10;&#10;</xsl:text>
2529 <xsl:call-template name="genStructWrapperJaxws">
2530 <xsl:with-param name="ifname" select="$ifname" />
2531 </xsl:call-template>
2532 </xsl:when>
2533
2534 <xsl:otherwise>
2535 <xsl:variable name="extends" select="key('G_keyInterfacesByName', $ifname)/@extends" />
2536 <xsl:choose>
2537 <xsl:when test="($extends = '$unknown') or ($extends = '$errorinfo')">
2538 <xsl:value-of select="concat('public class ', $ifname, ' extends IUnknown&#10;')" />
2539 <xsl:text>{&#10;&#10;</xsl:text>
2540 </xsl:when>
2541 <xsl:when test="count(key('G_keyInterfacesByName', $extends)) > 0">
2542 <xsl:value-of select="concat('public class ', $ifname, ' extends ', $extends, '&#10;')" />
2543 <xsl:text>{&#10;&#10;</xsl:text>
2544 </xsl:when>
2545 <xsl:otherwise>
2546 <xsl:call-template name="fatalError">
2547 <xsl:with-param name="msg" select="concat('Interface generation: interface &quot;', $ifname, '&quot; has invalid &quot;extends&quot; value ', $extends, '.')" />
2548 </xsl:call-template>
2549 </xsl:otherwise>
2550 </xsl:choose>
2551 <xsl:call-template name="genIfaceWrapper">
2552 <xsl:with-param name="ifname" select="$ifname" />
2553 </xsl:call-template>
2554 </xsl:otherwise>
2555 </xsl:choose>
2556
2557 <!-- end of class -->
2558 <xsl:text>}&#10;</xsl:text>
2559 </xsl:if>
2560
2561 <xsl:call-template name="endFile">
2562 <xsl:with-param name="file" select="$filename" />
2563 </xsl:call-template>
2564
2565</xsl:template>
2566
2567<xsl:template name="genCb">
2568 <xsl:param name="ifname" />
2569 <xsl:param name="filename" />
2570 <xsl:param name="filenameimpl" />
2571
2572 <xsl:call-template name="startFile">
2573 <xsl:with-param name="file" select="$filename" />
2574 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
2575 </xsl:call-template>
2576
2577 <xsl:text>import java.util.List;&#10;</xsl:text>
2578
2579 <xsl:value-of select="concat('public interface ', $ifname, '&#10;')" />
2580 <xsl:text>{&#10;</xsl:text>
2581
2582 <!-- emit methods declarations-->
2583 <xsl:for-each select="method">
2584 <xsl:call-template name="genCbMethodDecl">
2585 <xsl:with-param name="ifname" select="$ifname" />
2586 <xsl:with-param name="methodname" select="@name" />
2587 </xsl:call-template>
2588 </xsl:for-each>
2589
2590 <xsl:text>}&#10;&#10;</xsl:text>
2591
2592 <xsl:call-template name="endFile">
2593 <xsl:with-param name="file" select="$filename" />
2594 </xsl:call-template>
2595
2596 <xsl:call-template name="startFile">
2597 <xsl:with-param name="file" select="$filenameimpl" />
2598 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
2599 </xsl:call-template>
2600
2601 <xsl:text>import java.util.List;&#10;</xsl:text>
2602
2603 <xsl:variable name="backtype">
2604 <xsl:call-template name="typeIdl2Back">
2605 <xsl:with-param name="type" select="$ifname" />
2606 </xsl:call-template>
2607 </xsl:variable>
2608
2609 <!-- emit glue methods body -->
2610 <xsl:choose>
2611 <xsl:when test="$G_vboxGlueStyle='xpcom'">
2612 <xsl:value-of select="concat('class ', $ifname, 'Impl extends nsISupportsBase implements ', $backtype, '&#10;')" />
2613 <xsl:text>{&#10;</xsl:text>
2614 </xsl:when>
2615
2616 <xsl:when test="$G_vboxGlueStyle='mscom'">
2617 <xsl:value-of select="concat('public class ', $ifname, 'Impl&#10;')" />
2618 <xsl:text>{&#10;</xsl:text>
2619 </xsl:when>
2620 </xsl:choose>
2621
2622 <xsl:value-of select="concat(' ', $ifname, ' sink;&#10;')" />
2623
2624 <xsl:value-of select="concat(' ', $ifname, 'Impl(', $ifname, ' sink)&#10;')" />
2625 <xsl:text> {&#10;</xsl:text>
2626 <xsl:text> this.sink = sink;&#10;</xsl:text>
2627 <xsl:text> }&#10;</xsl:text>
2628
2629 <!-- emit methods implementations -->
2630 <xsl:for-each select="method">
2631 <xsl:call-template name="genCbMethodImpl">
2632 <xsl:with-param name="ifname" select="$ifname" />
2633 <xsl:with-param name="methodname" select="@name" />
2634 </xsl:call-template>
2635 </xsl:for-each>
2636
2637 <xsl:text>}&#10;&#10;</xsl:text>
2638
2639 <xsl:call-template name="endFile">
2640 <xsl:with-param name="file" select="$filenameimpl" />
2641 </xsl:call-template>
2642</xsl:template>
2643
2644<xsl:template name="emitHandwritten">
2645
2646 <xsl:call-template name="startFile">
2647 <xsl:with-param name="file" select="'Holder.java'" />
2648 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
2649 </xsl:call-template>
2650
2651 <xsl:if test="$filelistonly=''">
2652 <xsl:text><![CDATA[
2653public class Holder<T>
2654{
2655 public T value;
2656
2657 public Holder()
2658 {
2659 }
2660 public Holder(T value)
2661 {
2662 this.value = value;
2663 }
2664}
2665]]></xsl:text>
2666 </xsl:if>
2667
2668 <xsl:call-template name="endFile">
2669 <xsl:with-param name="file" select="'Holder.java'" />
2670 </xsl:call-template>
2671</xsl:template>
2672
2673<xsl:template name="emitHandwrittenXpcom">
2674
2675 <xsl:call-template name="startFile">
2676 <xsl:with-param name="file" select="'IUnknown.java'" />
2677 <xsl:with-param name="package" select="$G_virtualBoxPackageCom" />
2678 </xsl:call-template>
2679
2680 <xsl:if test="$filelistonly=''">
2681 <xsl:text><![CDATA[
2682public class IUnknown
2683{
2684 private Object obj;
2685 public IUnknown(Object obj)
2686 {
2687 this.obj = obj;
2688 }
2689
2690 public Object getWrapped()
2691 {
2692 return this.obj;
2693 }
2694
2695 public void setWrapped(Object obj)
2696 {
2697 this.obj = obj;
2698 }
2699}
2700]]></xsl:text>
2701 </xsl:if>
2702
2703 <xsl:call-template name="endFile">
2704 <xsl:with-param name="file" select="'IUnknown.java'" />
2705 </xsl:call-template>
2706
2707 <xsl:call-template name="startFile">
2708 <xsl:with-param name="file" select="'Helper.java'" />
2709 <xsl:with-param name="package" select="$G_virtualBoxPackageCom" />
2710 </xsl:call-template>
2711
2712 <xsl:if test="$filelistonly=''">
2713 <xsl:text><![CDATA[
2714
2715import java.util.List;
2716import java.util.ArrayList;
2717import java.util.Collections;
2718import java.lang.reflect.Array;
2719import java.lang.reflect.Constructor;
2720import java.lang.reflect.Method;
2721import java.lang.reflect.InvocationTargetException;
2722
2723public class Helper
2724{
2725 public static List<Short> wrap(byte[] values)
2726 {
2727 if (values == null)
2728 return null;
2729
2730 List<Short> ret = new ArrayList<Short>(values.length);
2731 for (short v : values)
2732 {
2733 ret.add(v);
2734 }
2735 return ret;
2736 }
2737
2738 public static List<Short> wrap(short[] values)
2739 {
2740 if (values == null)
2741 return null;
2742
2743 List<Short> ret = new ArrayList<Short>(values.length);
2744 for (short v : values)
2745 {
2746 ret.add(v);
2747 }
2748 return ret;
2749 }
2750
2751 public static List<Integer> wrap(int[] values)
2752 {
2753 if (values == null)
2754 return null;
2755
2756 List<Integer> ret = new ArrayList<Integer>(values.length);
2757 for (int v : values)
2758 {
2759 ret.add(v);
2760 }
2761 return ret;
2762 }
2763
2764 public static List<Long> wrap(long[] values)
2765 {
2766 if (values == null)
2767 return null;
2768
2769 List<Long> ret = new ArrayList<Long>(values.length);
2770 for (long v : values)
2771 {
2772 ret.add(v);
2773 }
2774 return ret;
2775 }
2776
2777 public static List<Boolean> wrap(boolean[] values)
2778 {
2779 if (values == null)
2780 return null;
2781
2782 List<Boolean> ret = new ArrayList<Boolean>(values.length);
2783 for (boolean v: values)
2784 {
2785 ret.add(v);
2786 }
2787 return ret;
2788 }
2789
2790 public static List<String> wrap(String[] values)
2791 {
2792 if (values == null)
2793 return null;
2794
2795 List<String> ret = new ArrayList<String>(values.length);
2796 for (String v : values)
2797 {
2798 ret.add(v);
2799 }
2800 return ret;
2801 }
2802
2803 public static <T> List<T> wrap(Class<T> wrapperClass, T[] values)
2804 {
2805 if (values == null)
2806 return null;
2807
2808 List<T> ret = new ArrayList<T>(values.length);
2809 for (T v : values)
2810 {
2811 ret.add(v);
2812 }
2813 return ret;
2814 }
2815
2816 @SuppressWarnings( "unchecked")
2817 public static <T> List<T> wrapEnum(Class<T> wrapperClass, long values[])
2818 {
2819 try
2820 {
2821 if (values == null)
2822 return null;
2823 //// This code is questionable, as it invokes a private constructor
2824 //// (all enums only have default constructors), and we don't really
2825 //// know what to pass as the name, and the ordinal may or may not
2826 //// be sensible, especially if the long was abused as a bitset.
2827 //Constructor<T> c = wrapperClass.getDeclaredConstructor(String.class, int.class, int.class);
2828 //c.setAccessible(true); // make it callable
2829 //List<T> ret = new ArrayList<T>(values.length);
2830 //for (long v : values)
2831 //{
2832 // T convEnum = c.newInstance("unknown", (int)v, (int)v);
2833 // ret.add(convEnum);
2834 //}
2835
2836 // Alternative implementation: use the fromValue method, which is
2837 // what the code handling single enums will do. I see no reason to
2838 // use the above very ugly hack if there are better alternatives,
2839 // which as a bonus complain about unknown values. This variant is
2840 // slower, but also orders of magnitude safer.
2841 java.lang.reflect.Method fromValue = wrapperClass.getMethod("fromValue", long.class);
2842 List<T> ret = new ArrayList<T>(values.length);
2843 for (long v : values)
2844 {
2845 T convEnum = (T)fromValue.invoke(null, v);
2846 ret.add(convEnum);
2847 }
2848 return ret;
2849 }
2850 catch (NoSuchMethodException e)
2851 {
2852 throw new AssertionError(e);
2853 }
2854 //catch (InstantiationException e)
2855 //{
2856 // throw new AssertionError(e);
2857 //}
2858 catch (IllegalAccessException e)
2859 {
2860 throw new AssertionError(e);
2861 }
2862 catch (InvocationTargetException e)
2863 {
2864 throw new AssertionError(e);
2865 }
2866 }
2867 public static short[] unwrapUShort(List<Short> values)
2868 {
2869 if (values == null)
2870 return null;
2871
2872 short[] ret = new short[values.size()];
2873 int i = 0;
2874 for (short l : values)
2875 {
2876 ret[i++] = l;
2877 }
2878 return ret;
2879 }
2880
2881 public static int[] unwrapInteger(List<Integer> values)
2882 {
2883 if (values == null)
2884 return null;
2885
2886 int[] ret = new int[values.size()];
2887 int i = 0;
2888 for (int l : values)
2889 {
2890 ret[i++] = l;
2891 }
2892 return ret;
2893 }
2894
2895 public static long[] unwrapULong(List<Long> values)
2896 {
2897 if (values == null)
2898 return null;
2899
2900 long[] ret = new long[values.size()];
2901 int i = 0;
2902 for (long l : values)
2903 {
2904 ret[i++] = l;
2905 }
2906 return ret;
2907 }
2908
2909 public static boolean[] unwrapBoolean(List<Boolean> values)
2910 {
2911 if (values == null)
2912 return null;
2913
2914 boolean[] ret = new boolean[values.size()];
2915 int i = 0;
2916 for (boolean l : values)
2917 {
2918 ret[i++] = l;
2919 }
2920 return ret;
2921 }
2922
2923 public static String[] unwrapStr(List<String> values)
2924 {
2925 if (values == null)
2926 return null;
2927
2928 String[] ret = new String[values.size()];
2929 int i = 0;
2930 for (String l : values)
2931 {
2932 ret[i++] = l;
2933 }
2934 return ret;
2935 }
2936
2937 public static <T extends Enum <T>> long[] unwrapEnum(Class<T> enumClass, List<T> values)
2938 {
2939 if (values == null)
2940 return null;
2941
2942 long result[] = new long[values.size()];
2943 try
2944 {
2945 java.lang.reflect.Method valueM = enumClass.getMethod("value");
2946 int i = 0;
2947 for (T v : values)
2948 {
2949 result[i++] = (Integer)valueM.invoke(v);
2950 }
2951 return result;
2952 }
2953 catch (NoSuchMethodException e)
2954 {
2955 throw new AssertionError(e);
2956 }
2957 catch(SecurityException e)
2958 {
2959 throw new AssertionError(e);
2960 }
2961 catch (IllegalAccessException e)
2962 {
2963 throw new AssertionError(e);
2964 }
2965 catch (IllegalArgumentException e)
2966 {
2967 throw new AssertionError(e);
2968 }
2969 catch (InvocationTargetException e)
2970 {
2971 throw new AssertionError(e);
2972 }
2973 }
2974
2975 public static <T1, T2> List<T1> wrap2(Class<T1> wrapperClass1, Class<T2> wrapperClass2, T2[] values)
2976 {
2977 try
2978 {
2979 if (values == null)
2980 return null;
2981
2982 Constructor<T1> c = wrapperClass1.getConstructor(wrapperClass2);
2983 List<T1> ret = new ArrayList<T1>(values.length);
2984 for (T2 v : values)
2985 {
2986 ret.add(c.newInstance(v));
2987 }
2988 return ret;
2989 }
2990 catch (NoSuchMethodException e)
2991 {
2992 throw new AssertionError(e);
2993 }
2994 catch (InstantiationException e)
2995 {
2996 throw new AssertionError(e);
2997 }
2998 catch (IllegalAccessException e)
2999 {
3000 throw new AssertionError(e);
3001 }
3002 catch (InvocationTargetException e)
3003 {
3004 throw new AssertionError(e);
3005 }
3006 }
3007
3008 @SuppressWarnings( "unchecked")
3009 public static <T> T[] unwrap(Class<T> wrapperClass, List<T> values)
3010 {
3011 if (values == null)
3012 return null;
3013 if (values.size() == 0)
3014 return null;
3015 return (T[])values.toArray((T[])Array.newInstance(wrapperClass, values.size()));
3016 }
3017
3018 @SuppressWarnings( "unchecked" )
3019 public static <T> T queryInterface(Object obj, String uuid, Class<T> iface)
3020 {
3021 return (T)queryInterface(obj, uuid);
3022 }
3023
3024 public static Object queryInterface(Object obj, String uuid)
3025 {
3026 try
3027 {
3028 /* Kind of ugly, but does the job of casting */
3029 org.mozilla.xpcom.Mozilla moz = org.mozilla.xpcom.Mozilla.getInstance();
3030 long xpobj = moz.wrapJavaObject(obj, uuid);
3031 return moz.wrapXPCOMObject(xpobj, uuid);
3032 }
3033 catch (Exception e)
3034 {
3035 return null;
3036 }
3037 }
3038
3039 @SuppressWarnings("unchecked")
3040 public static <T1 extends IUnknown, T2> T2[] unwrap2(Class<T1> wrapperClass1, Class<T2> wrapperClass2, List<T1> values)
3041 {
3042 if (values == null)
3043 return null;
3044
3045 T2 ret[] = (T2[])Array.newInstance(wrapperClass2, values.size());
3046 int i = 0;
3047 for (T1 obj : values)
3048 {
3049 ret[i++] = (T2)obj.getWrapped();
3050 }
3051 return ret;
3052 }
3053}
3054]]></xsl:text>
3055 </xsl:if>
3056
3057 <xsl:call-template name="endFile">
3058 <xsl:with-param name="file" select="'Helper.java'" />
3059 </xsl:call-template>
3060
3061 <xsl:call-template name="startFile">
3062 <xsl:with-param name="file" select="'VBoxException.java'" />
3063 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
3064 </xsl:call-template>
3065
3066 <xsl:if test="$filelistonly=''">
3067 <xsl:text>
3068import org.mozilla.xpcom.*;
3069
3070public class VBoxException extends RuntimeException
3071{
3072 private int resultCode;
3073 private IVirtualBoxErrorInfo errorInfo;
3074
3075 public VBoxException(String message)
3076 {
3077 super(message);
3078 resultCode = -1;
3079 errorInfo = null;
3080 }
3081
3082 public VBoxException(String message, Throwable cause)
3083 {
3084 super(message, cause);
3085 if (cause instanceof org.mozilla.xpcom.XPCOMException)
3086 {
3087 resultCode = (int)((org.mozilla.xpcom.XPCOMException)cause).errorcode;
3088 try
3089 {
3090 Mozilla mozilla = Mozilla.getInstance();
3091 nsIServiceManager sm = mozilla.getServiceManager();
3092 nsIExceptionService es = (nsIExceptionService)sm.getServiceByContractID("@mozilla.org/exceptionservice;1", nsIExceptionService.NS_IEXCEPTIONSERVICE_IID);
3093 nsIExceptionManager em = es.getCurrentExceptionManager();
3094 nsIException ex = em.getCurrentException();
3095 errorInfo = new IVirtualBoxErrorInfo((org.mozilla.interfaces.IVirtualBoxErrorInfo)ex.queryInterface(org.mozilla.interfaces.IVirtualBoxErrorInfo.IVIRTUALBOXERRORINFO_IID));
3096 }
3097 catch (NullPointerException e)
3098 {
3099 e.printStackTrace();
3100 // nothing we can do
3101 errorInfo = null;
3102 }
3103 }
3104 else
3105 resultCode = -1;
3106 }
3107
3108 public int getResultCode()
3109 {
3110 return resultCode;
3111 }
3112
3113 public IVirtualBoxErrorInfo getVirtualBoxErrorInfo()
3114 {
3115 return errorInfo;
3116 }
3117}
3118</xsl:text>
3119 </xsl:if>
3120
3121 <xsl:call-template name="endFile">
3122 <xsl:with-param name="file" select="'VBoxException.java'" />
3123 </xsl:call-template>
3124
3125 <xsl:call-template name="startFile">
3126 <xsl:with-param name="file" select="'VirtualBoxManager.java'" />
3127 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
3128 </xsl:call-template>
3129
3130 <xsl:if test="$filelistonly=''">
3131 <xsl:text><![CDATA[
3132
3133import java.io.File;
3134
3135import org.mozilla.xpcom.*;
3136import org.mozilla.interfaces.*;
3137
3138public class VirtualBoxManager
3139{
3140 private Mozilla mozilla;
3141 private IVirtualBox vbox;
3142 private nsIComponentManager componentManager;
3143
3144 private VirtualBoxManager(Mozilla mozilla)
3145 {
3146 this.mozilla = mozilla;
3147 this.componentManager = mozilla.getComponentManager();
3148 this.vbox = new IVirtualBox((org.mozilla.interfaces.IVirtualBox) this.componentManager
3149 .createInstanceByContractID("@virtualbox.org/VirtualBox;1",
3150 null,
3151 org.mozilla.interfaces.IVirtualBox.IVIRTUALBOX_IID));
3152 }
3153
3154 public void connect(String url, String username, String passwd)
3155 {
3156 throw new VBoxException("Connect doesn't make sense for local bindings");
3157 }
3158
3159 public void disconnect()
3160 {
3161 throw new VBoxException("Disconnect doesn't make sense for local bindings");
3162 }
3163
3164 public static void initPerThread()
3165 {
3166 }
3167
3168 public static void deinitPerThread()
3169 {
3170 }
3171
3172 public String getClientAPIVersion()
3173 {
3174 return "]]></xsl:text>
3175 <xsl:value-of select="substring($G_vboxApiSuffix, 2)" />
3176 <xsl:text><![CDATA[";
3177 }
3178
3179 public IVirtualBox getVBox()
3180 {
3181 return this.vbox;
3182 }
3183
3184 public ISession getSessionObject()
3185 {
3186 return new ISession((org.mozilla.interfaces.ISession) componentManager
3187 .createInstanceByContractID("@virtualbox.org/Session;1", null,
3188 org.mozilla.interfaces.ISession.ISESSION_IID));
3189 }
3190
3191 public ISession openMachineSession(IMachine m) throws Exception
3192 {
3193 ISession s = getSessionObject();
3194 m.lockMachine(s, LockType.Shared);
3195 return s;
3196 }
3197
3198 public void closeMachineSession(ISession s)
3199 {
3200 if (s != null)
3201 s.unlockMachine();
3202 }
3203
3204 private static boolean hasInstance = false;
3205 private static boolean isMozillaInited = false;
3206
3207 public static synchronized VirtualBoxManager createInstance(String home)
3208 {
3209 if (hasInstance)
3210 throw new VBoxException("only one instance of VirtualBoxManager at a time allowed");
3211 if (home == null || home.equals(""))
3212 home = System.getProperty("vbox.home");
3213
3214 if (home == null)
3215 throw new VBoxException("vbox.home Java property must be defined to use XPCOM bridge");
3216
3217 File grePath = new File(home);
3218
3219 Mozilla mozilla = Mozilla.getInstance();
3220 if (!isMozillaInited)
3221 {
3222 mozilla.initialize(grePath);
3223 try
3224 {
3225 mozilla.initXPCOM(grePath, null);
3226 isMozillaInited = true;
3227 }
3228 catch (Exception e)
3229 {
3230 e.printStackTrace();
3231 return null;
3232 }
3233 }
3234
3235 hasInstance = true;
3236
3237 return new VirtualBoxManager(mozilla);
3238 }
3239
3240 public IEventListener createListener(Object sink)
3241 {
3242 return new IEventListener(new EventListenerImpl(sink));
3243 }
3244
3245 public void cleanup()
3246 {
3247 deinitPerThread();
3248 // cleanup, we don't do that, as XPCOM bridge doesn't cleanly
3249 // shuts down, so we prefer to avoid native shutdown
3250 // mozilla.shutdownXPCOM(null);
3251 mozilla = null;
3252 hasInstance = false;
3253 }
3254
3255 public void waitForEvents(long tmo)
3256 {
3257 mozilla.waitForEvents(tmo);
3258 }
3259}
3260]]></xsl:text>
3261 </xsl:if>
3262
3263 <xsl:call-template name="endFile">
3264 <xsl:with-param name="file" select="'VirtualBoxManager.java'" />
3265 </xsl:call-template>
3266
3267 <xsl:call-template name="startFile">
3268 <xsl:with-param name="file" select="'EventListenerImpl.java'" />
3269 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
3270 </xsl:call-template>
3271
3272 <xsl:if test="$filelistonly=''">
3273 <xsl:text><![CDATA[
3274import org.mozilla.interfaces.*;
3275
3276public class EventListenerImpl extends nsISupportsBase implements org.mozilla.interfaces.IEventListener
3277{
3278 private Object obj;
3279 private java.lang.reflect.Method handleEvent;
3280 EventListenerImpl(Object obj)
3281 {
3282 this.obj = obj;
3283 try
3284 {
3285 this.handleEvent = obj.getClass().getMethod("handleEvent", IEvent.class);
3286 }
3287 catch (Exception e)
3288 {
3289 e.printStackTrace();
3290 }
3291 }
3292 public void handleEvent(org.mozilla.interfaces.IEvent ev)
3293 {
3294 try
3295 {
3296 if (obj != null && handleEvent != null)
3297 handleEvent.invoke(obj, ev != null ? new IEvent(ev) : null);
3298 }
3299 catch (Exception e)
3300 {
3301 e.printStackTrace();
3302 }
3303 }
3304}]]></xsl:text>
3305 </xsl:if>
3306
3307 <xsl:call-template name="endFile">
3308 <xsl:with-param name="file" select="'EventListenerImpl.java'" />
3309 </xsl:call-template>
3310
3311 <xsl:call-template name="startFile">
3312 <xsl:with-param name="file" select="'VBoxObjectBase.java'" />
3313 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
3314 </xsl:call-template>
3315
3316 <xsl:if test="$filelistonly=''">
3317 <xsl:text><![CDATA[
3318abstract class nsISupportsBase implements org.mozilla.interfaces.nsISupports
3319{
3320 public org.mozilla.interfaces.nsISupports queryInterface(String iid)
3321 {
3322 return org.mozilla.xpcom.Mozilla.queryInterface(this, iid);
3323 }
3324}
3325
3326]]></xsl:text>
3327 </xsl:if>
3328
3329 <xsl:call-template name="endFile">
3330 <xsl:with-param name="file" select="'VBoxObjectBase.java'" />
3331 </xsl:call-template>
3332</xsl:template>
3333
3334
3335<xsl:template name="emitHandwrittenMscom">
3336
3337 <xsl:call-template name="startFile">
3338 <xsl:with-param name="file" select="'IUnknown.java'" />
3339 <xsl:with-param name="package" select="$G_virtualBoxPackageCom" />
3340 </xsl:call-template>
3341
3342 <xsl:if test="$filelistonly=''">
3343 <xsl:text><![CDATA[
3344public class IUnknown
3345{
3346 private Object obj;
3347 public IUnknown(Object obj)
3348 {
3349 this.obj = obj;
3350 }
3351
3352 public Object getWrapped()
3353 {
3354 return this.obj;
3355 }
3356
3357 public void setWrapped(Object obj)
3358 {
3359 this.obj = obj;
3360 }
3361}
3362]]></xsl:text>
3363 </xsl:if>
3364
3365 <xsl:call-template name="endFile">
3366 <xsl:with-param name="file" select="'IUnknown.java'" />
3367 </xsl:call-template>
3368
3369 <xsl:call-template name="startFile">
3370 <xsl:with-param name="file" select="'Helper.java'" />
3371 <xsl:with-param name="package" select="$G_virtualBoxPackageCom" />
3372 </xsl:call-template>
3373
3374 <xsl:if test="$filelistonly=''">
3375 <xsl:text><![CDATA[
3376
3377import java.util.List;
3378import java.util.ArrayList;
3379import java.util.Collections;
3380import java.lang.reflect.Array;
3381import java.lang.reflect.Constructor;
3382import java.lang.reflect.InvocationTargetException;
3383import com.jacob.com.*;
3384
3385public class Helper
3386{
3387 public static List<Short> wrap(short[] values)
3388 {
3389 if (values == null)
3390 return null;
3391
3392 List<Short> ret = new ArrayList<Short>(values.length);
3393 for (short v : values)
3394 {
3395 ret.add(v);
3396 }
3397 return ret;
3398 }
3399
3400 public static List<Integer> wrap(int[] values)
3401 {
3402 if (values == null)
3403 return null;
3404
3405 List<Integer> ret = new ArrayList<Integer>(values.length);
3406 for (int v : values)
3407 {
3408 ret.add(v);
3409 }
3410 return ret;
3411 }
3412
3413 public static List<Long> wrap(long[] values)
3414 {
3415 if (values == null)
3416 return null;
3417
3418 List<Long> ret = new ArrayList<Long>(values.length);
3419 for (long v : values)
3420 {
3421 ret.add(v);
3422 }
3423 return ret;
3424 }
3425
3426 public static List<String> wrap(String[] values)
3427 {
3428 if (values == null)
3429 return null;
3430
3431 List<String> ret = new ArrayList<String>(values.length);
3432 for (String v : values)
3433 {
3434 ret.add(v);
3435 }
3436 return ret;
3437 }
3438
3439 public static <T> T wrapDispatch(Class<T> wrapperClass, Dispatch d)
3440 {
3441 try
3442 {
3443 if (d == null || d.m_pDispatch == 0)
3444 return null;
3445 Constructor<T> c = wrapperClass.getConstructor(Dispatch.class);
3446 return (T)c.newInstance(d);
3447 }
3448 catch (NoSuchMethodException e)
3449 {
3450 throw new AssertionError(e);
3451 }
3452 catch (InstantiationException e)
3453 {
3454 throw new AssertionError(e);
3455 }
3456 catch (IllegalAccessException e)
3457 {
3458 throw new AssertionError(e);
3459 }
3460 catch (InvocationTargetException e)
3461 {
3462 throw new AssertionError(e);
3463 }
3464 }
3465
3466 @SuppressWarnings("unchecked")
3467 public static <T> Object wrapVariant(Class<T> wrapperClass, Variant v)
3468 {
3469 if (v == null)
3470 return null;
3471
3472 short vt = v.getvt();
3473 switch (vt)
3474 {
3475 case Variant.VariantNull:
3476 return null;
3477 case Variant.VariantBoolean:
3478 return v.getBoolean();
3479 case Variant.VariantByte:
3480 return v.getByte();
3481 case Variant.VariantShort:
3482 return v.getShort();
3483 case Variant.VariantInt:
3484 return v.getInt();
3485 case Variant.VariantLongInt:
3486 return v.getLong();
3487 case Variant.VariantString:
3488 return v.getString();
3489 case Variant.VariantDispatch:
3490 return wrapDispatch(wrapperClass, v.getDispatch());
3491 default:
3492 throw new IllegalArgumentException("unhandled variant type " + vt);
3493 }
3494 }
3495
3496 public static byte[] wrapBytes(SafeArray sa)
3497 {
3498 if (sa == null)
3499 return null;
3500
3501 int saLen = sa.getUBound() - sa.getLBound() + 1;
3502
3503 byte[] ret = new byte[saLen];
3504 int j = 0;
3505 for (int i = sa.getLBound(); i <= sa.getUBound(); i++)
3506 {
3507 Variant v = sa.getVariant(i);
3508 // come up with more effective approach!!!
3509 ret[j++] = v.getByte();
3510 }
3511 return ret;
3512 }
3513
3514 @SuppressWarnings("unchecked")
3515 public static <T> List<T> wrap(Class<T> wrapperClass, SafeArray sa)
3516 {
3517 if (sa == null)
3518 return null;
3519
3520 int saLen = sa.getUBound() - sa.getLBound() + 1;
3521 if (saLen == 0)
3522 return Collections.emptyList();
3523
3524 List<T> ret = new ArrayList<T>(saLen);
3525 for (int i = sa.getLBound(); i <= sa.getUBound(); i++)
3526 {
3527 Variant v = sa.getVariant(i);
3528 ret.add((T)wrapVariant(wrapperClass, v));
3529 }
3530 return ret;
3531 }
3532
3533 public static <T> List<T> wrapEnum(Class<T> wrapperClass, SafeArray sa)
3534 {
3535 try
3536 {
3537 if (sa == null)
3538 return null;
3539
3540 int saLen = sa.getUBound() - sa.getLBound() + 1;
3541 if (saLen == 0)
3542 return Collections.emptyList();
3543 List<T> ret = new ArrayList<T>(saLen);
3544 Constructor<T> c = wrapperClass.getConstructor(int.class);
3545 for (int i = sa.getLBound(); i <= sa.getUBound(); i++)
3546 {
3547 Variant v = sa.getVariant(i);
3548 ret.add(c.newInstance(v.getInt()));
3549 }
3550 return ret;
3551 }
3552 catch (NoSuchMethodException e)
3553 {
3554 throw new AssertionError(e);
3555 }
3556 catch (InstantiationException e)
3557 {
3558 throw new AssertionError(e);
3559 }
3560 catch (IllegalAccessException e)
3561 {
3562 throw new AssertionError(e);
3563 }
3564 catch (InvocationTargetException e)
3565 {
3566 throw new AssertionError(e);
3567 }
3568 }
3569
3570 public static SafeArray unwrapInt(List<Integer> values)
3571 {
3572 if (values == null)
3573 return null;
3574 SafeArray ret = new SafeArray(Variant.VariantInt, values.size());
3575 int i = 0;
3576 for (int l : values)
3577 {
3578 ret.setInt(i++, l);
3579 }
3580 return ret;
3581 }
3582
3583 public static SafeArray unwrapLong(List<Long> values)
3584 {
3585 if (values == null)
3586 return null;
3587 SafeArray ret = new SafeArray(Variant.VariantLongInt, values.size());
3588 int i = 0;
3589 for (long l : values)
3590 {
3591 ret.setLong(i++, l);
3592 }
3593 return ret;
3594 }
3595
3596 public static SafeArray unwrapBool(List<Boolean> values)
3597 {
3598 if (values == null)
3599 return null;
3600
3601 SafeArray result = new SafeArray(Variant.VariantBoolean, values.size());
3602 int i = 0;
3603 for (boolean l : values)
3604 {
3605 result.setBoolean(i++, l);
3606 }
3607 return result;
3608 }
3609
3610
3611 public static SafeArray unwrapBytes(byte[] values)
3612 {
3613 if (values == null)
3614 return null;
3615
3616 SafeArray result = new SafeArray(Variant.VariantByte, values.length);
3617 int i = 0;
3618 for (byte l : values)
3619 {
3620 result.setByte(i++, l);
3621 }
3622 return result;
3623 }
3624
3625
3626 public static <T extends Enum <T>> SafeArray unwrapEnum(Class<T> enumClass, List<T> values)
3627 {
3628 if (values == null)
3629 return null;
3630
3631 SafeArray result = new SafeArray(Variant.VariantInt, values.size());
3632 try
3633 {
3634 java.lang.reflect.Method valueM = enumClass.getMethod("value");
3635 int i = 0;
3636 for (T v : values)
3637 {
3638 result.setInt(i++, (Integer)valueM.invoke(v));
3639 }
3640 return result;
3641 }
3642 catch (NoSuchMethodException e)
3643 {
3644 throw new AssertionError(e);
3645 }
3646 catch(SecurityException e)
3647 {
3648 throw new AssertionError(e);
3649 }
3650 catch (IllegalAccessException e)
3651 {
3652 throw new AssertionError(e);
3653 }
3654 catch (IllegalArgumentException e)
3655 {
3656 throw new AssertionError(e);
3657 }
3658 catch (InvocationTargetException e)
3659 {
3660 throw new AssertionError(e);
3661 }
3662 }
3663 public static SafeArray unwrapString(List<String> values)
3664 {
3665 if (values == null)
3666 return null;
3667 SafeArray result = new SafeArray(Variant.VariantString, values.size());
3668 int i = 0;
3669 for (String l : values)
3670 {
3671 result.setString(i++, l);
3672 }
3673 return result;
3674 }
3675
3676 public static <T1, T2> List<T1> wrap2(Class<T1> wrapperClass1, Class<T2> wrapperClass2, T2[] values)
3677 {
3678 try
3679 {
3680 if (values == null)
3681 return null;
3682 if (values.length == 0)
3683 return Collections.emptyList();
3684
3685 Constructor<T1> c = wrapperClass1.getConstructor(wrapperClass2);
3686 List<T1> ret = new ArrayList<T1>(values.length);
3687 for (T2 v : values)
3688 {
3689 ret.add(c.newInstance(v));
3690 }
3691 return ret;
3692 }
3693 catch (NoSuchMethodException e)
3694 {
3695 throw new AssertionError(e);
3696 }
3697 catch (InstantiationException e)
3698 {
3699 throw new AssertionError(e);
3700 }
3701 catch (IllegalAccessException e)
3702 {
3703 throw new AssertionError(e);
3704 }
3705 catch (InvocationTargetException e)
3706 {
3707 throw new AssertionError(e);
3708 }
3709 }
3710
3711 @SuppressWarnings("unchecked")
3712 public static <T> T[] unwrap(Class<T> wrapperClass, List<T> values)
3713 {
3714 if (values == null)
3715 return null;
3716 return (T[])values.toArray((T[])Array.newInstance(wrapperClass, values.size()));
3717 }
3718
3719 @SuppressWarnings("unchecked")
3720 public static <T1 extends IUnknown, T2> T2[] unwrap2(Class<T1> wrapperClass1, Class<T2> wrapperClass2, List<T1> values)
3721 {
3722 if (values == null)
3723 return null;
3724
3725 T2 ret[] = (T2[])Array.newInstance(wrapperClass2, values.size());
3726 int i = 0;
3727 for (T1 obj : values)
3728 {
3729 ret[i++] = (T2)obj.getWrapped();
3730 }
3731 return ret;
3732 }
3733
3734 /* We have very long invoke lists sometimes */
3735 public static Variant invoke(Dispatch d, String method, Object ... args)
3736 {
3737 return Dispatch.callN(d, method, args);
3738 }
3739}
3740]]></xsl:text>
3741 </xsl:if>
3742
3743 <xsl:call-template name="endFile">
3744 <xsl:with-param name="file" select="'Helper.java'" />
3745 </xsl:call-template>
3746
3747 <xsl:call-template name="startFile">
3748 <xsl:with-param name="file" select="'VBoxException.java'" />
3749 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
3750 </xsl:call-template>
3751
3752 <xsl:if test="$filelistonly=''">
3753 <xsl:text>
3754
3755public class VBoxException extends RuntimeException
3756{
3757 private int resultCode;
3758 private IVirtualBoxErrorInfo errorInfo;
3759
3760 public VBoxException(String message)
3761 {
3762 super(message);
3763 resultCode = -1;
3764 errorInfo = null;
3765 }
3766
3767 public VBoxException(String message, Throwable cause)
3768 {
3769 super(message, cause);
3770 if (cause instanceof com.jacob.com.ComException)
3771 {
3772 resultCode = ((com.jacob.com.ComException)cause).getHResult();
3773 // JACOB doesn't support calling GetErrorInfo, which
3774 // means there is no way of getting an IErrorInfo reference,
3775 // and that means no way of getting to IVirtualBoxErrorInfo.
3776 errorInfo = null;
3777 }
3778 else
3779 resultCode = -1;
3780 }
3781
3782 public int getResultCode()
3783 {
3784 return resultCode;
3785 }
3786
3787 public IVirtualBoxErrorInfo getVirtualBoxErrorInfo()
3788 {
3789 return errorInfo;
3790 }
3791}
3792</xsl:text>
3793 </xsl:if>
3794
3795 <xsl:call-template name="endFile">
3796 <xsl:with-param name="file" select="'VBoxException.java'" />
3797 </xsl:call-template>
3798
3799
3800 <xsl:call-template name="startFile">
3801 <xsl:with-param name="file" select="'VirtualBoxManager.java'" />
3802 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
3803 </xsl:call-template>
3804
3805 <xsl:if test="$filelistonly=''">
3806 <xsl:text><![CDATA[
3807
3808import com.jacob.activeX.ActiveXComponent;
3809import com.jacob.com.ComThread;
3810import com.jacob.com.Dispatch;
3811import com.jacob.com.Variant;
3812import com.jacob.com.SafeArray;
3813import com.jacob.com.DispatchEvents;
3814
3815public class VirtualBoxManager
3816{
3817 private IVirtualBox vbox;
3818
3819 private VirtualBoxManager()
3820 {
3821 initPerThread();
3822 vbox = new IVirtualBox(new ActiveXComponent("VirtualBox.VirtualBox"));
3823 }
3824
3825 public static void initPerThread()
3826 {
3827 ComThread.InitMTA();
3828 }
3829
3830 public static void deinitPerThread()
3831 {
3832 ComThread.Release();
3833 }
3834
3835 public void connect(String url, String username, String passwd)
3836 {
3837 throw new VBoxException("Connect doesn't make sense for local bindings");
3838 }
3839
3840 public void disconnect()
3841 {
3842 throw new VBoxException("Disconnect doesn't make sense for local bindings");
3843 }
3844
3845 public String getClientAPIVersion()
3846 {
3847 return "]]></xsl:text>
3848 <xsl:value-of select="substring($G_vboxApiSuffix, 2)" />
3849 <xsl:text><![CDATA[";
3850 }
3851
3852 public IVirtualBox getVBox()
3853 {
3854 return this.vbox;
3855 }
3856
3857 public ISession getSessionObject()
3858 {
3859 return new ISession(new ActiveXComponent("VirtualBox.Session"));
3860 }
3861
3862 public ISession openMachineSession(IMachine m)
3863 {
3864 ISession s = getSessionObject();
3865 m.lockMachine(s, LockType.Shared);
3866 return s;
3867 }
3868
3869 public void closeMachineSession(ISession s)
3870 {
3871 if (s != null)
3872 s.unlockMachine();
3873 }
3874
3875 private static boolean hasInstance = false;
3876
3877 public static synchronized VirtualBoxManager createInstance(String home)
3878 {
3879 if (hasInstance)
3880 throw new VBoxException("only one instance of VirtualBoxManager at a time allowed");
3881
3882 hasInstance = true;
3883 return new VirtualBoxManager();
3884 }
3885
3886 public void cleanup()
3887 {
3888 deinitPerThread();
3889 hasInstance = false;
3890 }
3891
3892 public void waitForEvents(long tmo)
3893 {
3894 try
3895 {
3896 Thread.sleep(tmo);
3897 }
3898 catch (InterruptedException ie)
3899 {
3900 }
3901 }
3902}
3903]]></xsl:text>
3904 </xsl:if>
3905
3906 <xsl:call-template name="endFile">
3907 <xsl:with-param name="file" select="'VirtualBoxManager.java'" />
3908 </xsl:call-template>
3909</xsl:template>
3910
3911<xsl:template name="emitHandwrittenJaxws">
3912
3913 <xsl:call-template name="startFile">
3914 <xsl:with-param name="file" select="'IUnknown.java'" />
3915 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
3916 </xsl:call-template>
3917
3918 <xsl:if test="$filelistonly=''">
3919 <xsl:text><![CDATA[
3920public class IUnknown
3921{
3922 protected String obj;
3923 protected final VboxPortType port;
3924
3925 public IUnknown(String obj, VboxPortType port)
3926 {
3927 this.obj = obj;
3928 this.port = port;
3929 }
3930
3931 public final String getWrapped()
3932 {
3933 return this.obj;
3934 }
3935
3936 public final VboxPortType getRemoteWSPort()
3937 {
3938 return this.port;
3939 }
3940
3941 public synchronized void releaseRemote() throws WebServiceException
3942 {
3943 if (obj == null)
3944 return;
3945
3946 try
3947 {
3948 this.port.iManagedObjectRefRelease(obj);
3949 this.obj = null;
3950 }
3951 catch (InvalidObjectFaultMsg e)
3952 {
3953 throw new WebServiceException(e);
3954 }
3955 catch (RuntimeFaultMsg e)
3956 {
3957 throw new WebServiceException(e);
3958 }
3959 }
3960}
3961]]></xsl:text>
3962 </xsl:if>
3963
3964 <xsl:call-template name="endFile">
3965 <xsl:with-param name="file" select="'IUnknown.java'" />
3966 </xsl:call-template>
3967
3968 <xsl:call-template name="startFile">
3969 <xsl:with-param name="file" select="'Helper.java'" />
3970 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
3971 </xsl:call-template>
3972
3973 <xsl:if test="$filelistonly=''">
3974 <xsl:text><![CDATA[
3975
3976import java.util.List;
3977import java.util.ArrayList;
3978import java.util.Collections;
3979import java.lang.reflect.Array;
3980import java.lang.reflect.Constructor;
3981import java.lang.reflect.InvocationTargetException;
3982import java.math.BigInteger;
3983
3984public class Helper
3985{
3986 public static <T> List<T> wrap(Class<T> wrapperClass, VboxPortType pt, List<String> values)
3987 {
3988 try
3989 {
3990 if (values == null)
3991 return null;
3992
3993 Constructor<T> c = wrapperClass.getConstructor(String.class, VboxPortType.class);
3994 List<T> ret = new ArrayList<T>(values.size());
3995 for (String v : values)
3996 {
3997 ret.add(c.newInstance(v, pt));
3998 }
3999 return ret;
4000 }
4001 catch (NoSuchMethodException e)
4002 {
4003 throw new AssertionError(e);
4004 }
4005 catch (InstantiationException e)
4006 {
4007 throw new AssertionError(e);
4008 }
4009 catch (IllegalAccessException e)
4010 {
4011 throw new AssertionError(e);
4012 }
4013 catch (InvocationTargetException e)
4014 {
4015 throw new AssertionError(e);
4016 }
4017 }
4018
4019 public static <T1, T2> List<T1> wrap2(Class<T1> wrapperClass1, Class<T2> wrapperClass2, VboxPortType pt, List<T2> values)
4020 {
4021 try
4022 {
4023 if (values == null)
4024 return null;
4025
4026 Constructor<T1> c = wrapperClass1.getConstructor(wrapperClass2, VboxPortType.class);
4027 List<T1> ret = new ArrayList<T1>(values.size());
4028 for (T2 v : values)
4029 {
4030 ret.add(c.newInstance(v, pt));
4031 }
4032 return ret;
4033 }
4034 catch (NoSuchMethodException e)
4035 {
4036 throw new AssertionError(e);
4037 }
4038 catch (InstantiationException e)
4039 {
4040 throw new AssertionError(e);
4041 }
4042 catch (IllegalAccessException e)
4043 {
4044 throw new AssertionError(e);
4045 }
4046 catch (InvocationTargetException e)
4047 {
4048 throw new AssertionError(e);
4049 }
4050 }
4051
4052 public static <T extends IUnknown> List<String> unwrap(List<T> values)
4053 {
4054 if (values == null)
4055 return null;
4056
4057 List<String> ret = new ArrayList<String>(values.size());
4058 for (T obj : values)
4059 {
4060 ret.add(obj.getWrapped());
4061 }
4062 return ret;
4063 }
4064
4065 @SuppressWarnings("unchecked" )
4066 public static <T1 extends Enum <T1>, T2 extends Enum <T2>> List<T2> convertEnums(Class<T1> fromClass,
4067 Class<T2> toClass,
4068 List<T1> values)
4069 {
4070 try
4071 {
4072 if (values == null)
4073 return null;
4074 List<T2> ret = new ArrayList<T2>(values.size());
4075 for (T1 v : values)
4076 {
4077 // Ordinal based enum conversion, as JAX-WS "invents" its own
4078 // enum names and has string values with the expected content.
4079 int enumOrdinal = v.ordinal();
4080 T2 convEnum = toClass.getEnumConstants()[enumOrdinal];
4081 ret.add(convEnum);
4082 }
4083 return ret;
4084 }
4085 catch (ArrayIndexOutOfBoundsException e)
4086 {
4087 throw new AssertionError(e);
4088 }
4089 }
4090
4091 /* Pretty naive Base64 encoder/decoder. */
4092 private static final char[] valToChar = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray();
4093 private static final int[] charToVal = new int[256];
4094
4095 /* Initialize recoding alphabet. */
4096 static
4097 {
4098 for (int i = 0; i < charToVal.length; i++)
4099 charToVal[i] = -1;
4100
4101 for (int i = 0; i < valToChar.length; i++)
4102 charToVal[valToChar[i]] = i;
4103
4104 charToVal['='] = 0;
4105 }
4106
4107 public static String encodeBase64(byte[] data)
4108 {
4109 if (data == null)
4110 return null;
4111
4112 if (data.length == 0)
4113 return "";
4114
4115 int fullTriplets = data.length / 3;
4116 int resultLen = ((data.length - 1) / 3 + 1) * 4;
4117 char[] result = new char[resultLen];
4118 int dataIndex = 0, stringIndex = 0;
4119
4120 for (int i = 0; i < fullTriplets; i++)
4121 {
4122 int ch1 = data[dataIndex++] & 0xff;
4123 result[stringIndex++] = valToChar[ch1 >> 2];
4124 int ch2 = data[dataIndex++] & 0xff;
4125 result[stringIndex++] = valToChar[((ch1 << 4) & 0x3f) | (ch2 >> 4)];
4126 int ch3 = data[dataIndex++] & 0xff;
4127 result[stringIndex++] = valToChar[((ch2 << 2) & 0x3f) | (ch3 >> 6)];
4128 result[stringIndex++] = valToChar[ch3 & 0x3f];
4129 }
4130
4131 switch (data.length - dataIndex)
4132 {
4133 case 0:
4134 // do nothing
4135 break;
4136 case 1:
4137 {
4138 int ch1 = data[dataIndex++] & 0xff;
4139 result[stringIndex++] = valToChar[ch1 >> 2];
4140 result[stringIndex++] = valToChar[(ch1 << 4) & 0x3f];
4141 result[stringIndex++] = '=';
4142 result[stringIndex++] = '=';
4143 break;
4144 }
4145 case 2:
4146 {
4147 int ch1 = data[dataIndex++] & 0xff;
4148 result[stringIndex++] = valToChar[ch1 >> 2];
4149 int ch2 = data[dataIndex++] & 0xff;
4150 result[stringIndex++] = valToChar[((ch1 << 4) & 0x3f) | (ch2 >> 4)];
4151 result[stringIndex++] = valToChar[(ch2 << 2) & 0x3f];
4152 result[stringIndex++] = '=';
4153 break;
4154 }
4155 default:
4156 throw new VBoxException("bug!");
4157 }
4158
4159 return new String(result);
4160 }
4161
4162 private static int skipInvalid(String str, int stringIndex)
4163 {
4164 while (charToVal[str.charAt(stringIndex)] < 0)
4165 stringIndex++;
4166
4167 return stringIndex;
4168 }
4169
4170 public static byte[] decodeBase64(String str)
4171 {
4172 if (str == null)
4173 return null;
4174
4175 int stringLength = str.length();
4176 if (stringLength == 0)
4177 return new byte[0];
4178
4179 int validChars = 0, padChars = 0;
4180 for (int i = 0; i < str.length(); i++)
4181 {
4182 char ch = str.charAt(i);
4183
4184 if (charToVal[ch] >= 0)
4185 validChars++;
4186
4187 if (ch == '=')
4188 padChars++;
4189 }
4190
4191 if ((validChars * 3 % 4) != 0)
4192 throw new VBoxException("invalid base64 encoded string " + str);
4193
4194 int resultLength = validChars * 3 / 4 - padChars;
4195 byte[] result = new byte[resultLength];
4196
4197 int dataIndex = 0, stringIndex = 0;
4198 int quadraplets = validChars / 4;
4199
4200 for (int i = 0; i < quadraplets; i++)
4201 {
4202 stringIndex = skipInvalid(str, stringIndex);
4203 int ch1 = str.charAt(stringIndex++);
4204 stringIndex = skipInvalid(str, stringIndex);
4205 int ch2 = str.charAt(stringIndex++);
4206 stringIndex = skipInvalid(str, stringIndex);
4207 int ch3 = str.charAt(stringIndex++);
4208 stringIndex = skipInvalid(str, stringIndex);
4209 int ch4 = str.charAt(stringIndex++);
4210
4211 result[dataIndex++] = (byte)(((charToVal[ch1] << 2) | charToVal[ch2] >> 4) & 0xff);
4212 /* we check this to ensure that we don't override data with '=' padding. */
4213 if (dataIndex < result.length)
4214 result[dataIndex++] = (byte)(((charToVal[ch2] << 4) | charToVal[ch3] >> 2) & 0xff);
4215 if (dataIndex < result.length)
4216 result[dataIndex++] = (byte)(((charToVal[ch3] << 6) | charToVal[ch4]) & 0xff);
4217 }
4218
4219 return result;
4220 }
4221}
4222]]></xsl:text>
4223 </xsl:if>
4224
4225 <xsl:call-template name="endFile">
4226 <xsl:with-param name="file" select="'Helper.java'" />
4227 </xsl:call-template>
4228
4229 <xsl:call-template name="startFile">
4230 <xsl:with-param name="file" select="'VBoxException.java'" />
4231 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
4232 </xsl:call-template>
4233
4234 <xsl:if test="$filelistonly=''">
4235 <xsl:text>
4236public class VBoxException extends RuntimeException
4237{
4238 private int resultCode;
4239 private IVirtualBoxErrorInfo errorInfo;
4240
4241 public VBoxException(String message)
4242 {
4243 super(message);
4244 resultCode = -1;
4245 errorInfo = null;
4246 }
4247
4248 public VBoxException(String message, Throwable cause)
4249 {
4250 super(message, cause);
4251 resultCode = -1;
4252 errorInfo = null;
4253 }
4254
4255 public VBoxException(String message, Throwable cause, VboxPortType port)
4256 {
4257 super(message, cause);
4258 if (cause instanceof RuntimeFaultMsg)
4259 {
4260 RuntimeFaultMsg m = (RuntimeFaultMsg)cause;
4261 RuntimeFault f = m.getFaultInfo();
4262 resultCode = f.getResultCode();
4263 String retVal = f.getReturnval();
4264 errorInfo = (retVal.length() > 0) ? new IVirtualBoxErrorInfo(retVal, port) : null;
4265 }
4266 else
4267 resultCode = -1;
4268 }
4269
4270 public int getResultCode()
4271 {
4272 return resultCode;
4273 }
4274
4275 public IVirtualBoxErrorInfo getVirtualBoxErrorInfo()
4276 {
4277 return errorInfo;
4278 }
4279}
4280</xsl:text>
4281 </xsl:if>
4282
4283 <xsl:call-template name="endFile">
4284 <xsl:with-param name="file" select="'VBoxException.java'" />
4285 </xsl:call-template>
4286
4287 <xsl:call-template name="startFile">
4288 <xsl:with-param name="file" select="'VirtualBoxManager.java'" />
4289 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
4290 </xsl:call-template>
4291
4292 <xsl:if test="$filelistonly=''">
4293 <xsl:text>import java.net.URL;
4294import java.math.BigInteger;
4295import java.util.List;
4296import java.util.Map;
4297import java.util.HashMap;
4298import java.util.ArrayList;
4299import javax.xml.namespace.QName;
4300import javax.xml.ws.BindingProvider;
4301import javax.xml.ws.Holder;
4302import javax.xml.ws.WebServiceException;
4303import java.io.IOException;
4304import java.net.UnknownHostException;
4305import java.net.Socket;
4306import java.net.InetAddress;
4307import javax.net.SocketFactory;
4308import javax.net.ssl.SSLContext;
4309import javax.net.ssl.SSLSocketFactory;
4310import javax.net.ssl.SSLSocket;
4311
4312class PortPool
4313{
4314 private final static String wsdlFile = </xsl:text>
4315 <xsl:value-of select="$G_virtualBoxWsdl" />
4316 <xsl:text><![CDATA[;
4317 private Map<VboxPortType, Integer> known;
4318 private boolean initStarted;
4319 private VboxService svc;
4320
4321 PortPool(boolean usePreinit)
4322 {
4323 known = new HashMap<VboxPortType, Integer>();
4324
4325 if (usePreinit)
4326 {
4327 new Thread(new Runnable()
4328 {
4329 public void run()
4330 {
4331 // need to sync on something else but 'this'
4332 synchronized (known)
4333 {
4334 initStarted = true;
4335 known.notify();
4336 }
4337
4338 preinit();
4339 }
4340 }).start();
4341
4342 synchronized (known)
4343 {
4344 while (!initStarted)
4345 {
4346 try
4347 {
4348 known.wait();
4349 }
4350 catch (InterruptedException e)
4351 {
4352 break;
4353 }
4354 }
4355 }
4356 }
4357 }
4358
4359 private synchronized void preinit()
4360 {
4361 VboxPortType port = getPort();
4362 releasePort(port);
4363 }
4364
4365 synchronized VboxPortType getPort()
4366 {
4367 VboxPortType port = null;
4368 int ttl = 0;
4369
4370 for (VboxPortType cur: known.keySet())
4371 {
4372 int value = known.get(cur);
4373 if ((value & 0x10000) == 0)
4374 {
4375 port = cur;
4376 ttl = value & 0xffff;
4377 break;
4378 }
4379 }
4380
4381 if (port == null)
4382 {
4383 if (svc == null)
4384 {
4385 URL wsdl = PortPool.class.getClassLoader().getResource(wsdlFile);
4386 if (wsdl == null)
4387 throw new LinkageError(wsdlFile + " not found, but it should have been in the jar");
4388 svc = new VboxService(wsdl,
4389 new QName("http://www.virtualbox.org/Service",
4390 "vboxService"));
4391 }
4392 port = svc.getVboxServicePort();
4393 // reuse this object 0x10 times
4394 ttl = 0x10;
4395 }
4396 // mark as used
4397 known.put(port, new Integer(0x10000 | ttl));
4398 return port;
4399 }
4400
4401 synchronized void releasePort(VboxPortType port)
4402 {
4403 Integer val = known.get(port);
4404 if (val == null || val == 0)
4405 {
4406 // know you not
4407 return;
4408 }
4409
4410 int v = val;
4411 int ttl = v & 0xffff;
4412 // decrement TTL, and throw away port if used too much times
4413 if (--ttl <= 0)
4414 {
4415 known.remove(port);
4416 }
4417 else
4418 {
4419 v = ttl; // set new TTL and clear busy bit
4420 known.put(port, v);
4421 }
4422 }
4423}
4424
4425
4426class VBoxTLSSocketFactory extends SSLSocketFactory
4427{
4428 private final SSLSocketFactory sf;
4429
4430 private void setupSocket(SSLSocket s)
4431 {
4432 String[] oldproto = s.getEnabledProtocols();
4433 List<String> protolist = new ArrayList<String>();
4434 for (int i = 0; i < oldproto.length; i++)
4435 if (oldproto[i].toUpperCase().startsWith("TLS"))
4436 protolist.add(oldproto[i]);
4437 String[] newproto = protolist.toArray(new String[protolist.size()]);
4438 s.setEnabledProtocols(newproto);
4439 }
4440
4441 public VBoxTLSSocketFactory()
4442 {
4443 SSLSocketFactory tmp = null;
4444 try
4445 {
4446 SSLContext sc = SSLContext.getInstance("TLS");
4447 sc.init(null, null, null);
4448 tmp = sc.getSocketFactory();
4449 }
4450 catch (Exception e)
4451 {
4452 e.printStackTrace();
4453 }
4454 sf = tmp;
4455 }
4456
4457 public static SocketFactory getDefault()
4458 {
4459 return new VBoxTLSSocketFactory();
4460 }
4461
4462 public Socket createSocket(Socket socket, String host, int port,
4463 boolean autoClose) throws IOException, UnknownHostException
4464 {
4465 SSLSocket s = (SSLSocket)sf.createSocket(socket, host, port, autoClose);
4466 setupSocket(s);
4467 return s;
4468 }
4469
4470 public Socket createSocket() throws IOException
4471 {
4472 SSLSocket s = (SSLSocket)sf.createSocket();
4473 setupSocket(s);
4474 return s;
4475 }
4476
4477 public Socket createSocket(InetAddress host, int port) throws IOException
4478 {
4479 SSLSocket s = (SSLSocket)sf.createSocket(host, port);
4480 setupSocket(s);
4481 return s;
4482 }
4483
4484 public Socket createSocket(InetAddress address, int port,
4485 InetAddress localAddress, int localPort) throws IOException
4486 {
4487 SSLSocket s = (SSLSocket)sf.createSocket(address, port, localAddress, localPort);
4488 setupSocket(s);
4489 return s;
4490 }
4491
4492 public Socket createSocket(String host, int port) throws IOException, UnknownHostException
4493 {
4494 SSLSocket s = (SSLSocket)sf.createSocket(host, port);
4495 setupSocket(s);
4496 return s;
4497 }
4498
4499 public Socket createSocket(String host, int port,
4500 InetAddress localHost, int localPort) throws IOException, UnknownHostException
4501 {
4502 SSLSocket s = (SSLSocket)sf.createSocket(host, port, localHost, localPort);
4503 setupSocket(s);
4504 return s;
4505 }
4506
4507 public String[] getDefaultCipherSuites()
4508 {
4509 return sf.getSupportedCipherSuites();
4510 }
4511
4512 public String[] getSupportedCipherSuites()
4513 {
4514 return sf.getSupportedCipherSuites();
4515 }
4516}
4517
4518
4519public class VirtualBoxManager
4520{
4521 private static PortPool pool = new PortPool(true);
4522 protected VboxPortType port;
4523
4524 private IVirtualBox vbox;
4525
4526 private VirtualBoxManager()
4527 {
4528 }
4529
4530 public static void initPerThread()
4531 {
4532 }
4533
4534 public static void deinitPerThread()
4535 {
4536 }
4537
4538 public void connect(String url, String username, String passwd)
4539 {
4540 this.port = pool.getPort();
4541 try
4542 {
4543 ((BindingProvider)port).getRequestContext().
4544 put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
4545
4546 // Unfortunately there is no official way to make JAX-WS use
4547 // TLS only, which means that a rather tedious approach is
4548 // unavoidable (implementing a TLS only SSLSocketFactory,
4549 // because the default one associated with a TLS SSLContext
4550 // happily uses SSLv2/3 handshakes, which make TLS servers
4551 // drop the connection), and additionally a not standardized,
4552 // shotgun approach is needed to make the relevant JAX-WS
4553 // implementations use this factory.
4554 VBoxTLSSocketFactory sf = new VBoxTLSSocketFactory();
4555 ((BindingProvider)port).getRequestContext().
4556 put("com.sun.xml.internal.ws.transport.https.client.SSLSocketFactory", sf);
4557 ((BindingProvider)port).getRequestContext().
4558 put("com.sun.xml.ws.transport.https.client.SSLSocketFactory", sf);
4559
4560 String handle = port.iWebsessionManagerLogon(username, passwd);
4561 this.vbox = new IVirtualBox(handle, port);
4562 }
4563 catch (Throwable t)
4564 {
4565 if (this.port != null && pool != null)
4566 {
4567 pool.releasePort(this.port);
4568 this.port = null;
4569 }
4570 // we have to throw smth derived from RuntimeException
4571 throw new VBoxException(t.getMessage(), t, this.port);
4572 }
4573 }
4574
4575 public void connect(String url, String username, String passwd,
4576 Map<String, Object> requestContext, Map<String, Object> responseContext)
4577 {
4578 this.port = pool.getPort();
4579
4580 try
4581 {
4582 ((BindingProvider)port).getRequestContext();
4583 if (requestContext != null)
4584 ((BindingProvider)port).getRequestContext().putAll(requestContext);
4585
4586 if (responseContext != null)
4587 ((BindingProvider)port).getResponseContext().putAll(responseContext);
4588
4589 ((BindingProvider)port).getRequestContext().
4590 put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
4591 String handle = port.iWebsessionManagerLogon(username, passwd);
4592 this.vbox = new IVirtualBox(handle, port);
4593 }
4594 catch (Throwable t)
4595 {
4596 if (this.port != null && pool != null)
4597 {
4598 pool.releasePort(this.port);
4599 this.port = null;
4600 }
4601 // we have to throw smth derived from RuntimeException
4602 throw new VBoxException(t.getMessage(), t, this.port);
4603 }
4604 }
4605
4606 public void disconnect()
4607 {
4608 if (this.port == null)
4609 return;
4610
4611 try
4612 {
4613 if (this.vbox != null && port != null)
4614 port.iWebsessionManagerLogoff(this.vbox.getWrapped());
4615 }
4616 catch (InvalidObjectFaultMsg e)
4617 {
4618 throw new VBoxException(e.getMessage(), e, this.port);
4619 }
4620 catch (RuntimeFaultMsg e)
4621 {
4622 throw new VBoxException(e.getMessage(), e, this.port);
4623 }
4624 finally
4625 {
4626 if (this.port != null)
4627 {
4628 pool.releasePort(this.port);
4629 this.port = null;
4630 }
4631 }
4632 }
4633
4634 public String getClientAPIVersion()
4635 {
4636 return "]]></xsl:text>
4637 <xsl:value-of select="substring($G_vboxApiSuffix, 2)" />
4638 <xsl:text><![CDATA[";
4639 }
4640
4641 public IVirtualBox getVBox()
4642 {
4643 return this.vbox;
4644 }
4645
4646 public ISession getSessionObject()
4647 {
4648 if (this.vbox == null)
4649 throw new VBoxException("connect first");
4650 try
4651 {
4652 String handle = port.iWebsessionManagerGetSessionObject(this.vbox.getWrapped());
4653 return new ISession(handle, port);
4654 }
4655 catch (InvalidObjectFaultMsg e)
4656 {
4657 throw new VBoxException(e.getMessage(), e, this.port);
4658 }
4659 catch (RuntimeFaultMsg e)
4660 {
4661 throw new VBoxException(e.getMessage(), e, this.port);
4662 }
4663 }
4664
4665 public ISession openMachineSession(IMachine m) throws Exception
4666 {
4667 ISession s = getSessionObject();
4668 m.lockMachine(s, LockType.Shared);
4669 return s;
4670 }
4671
4672 public void closeMachineSession(ISession s)
4673 {
4674 if (s != null)
4675 s.unlockMachine();
4676 }
4677
4678 public static synchronized VirtualBoxManager createInstance(String home)
4679 {
4680 return new VirtualBoxManager();
4681 }
4682
4683 public IEventListener createListener(Object sink)
4684 {
4685 throw new VBoxException("no active listeners here");
4686 }
4687
4688 public void cleanup()
4689 {
4690 disconnect();
4691 deinitPerThread();
4692 }
4693
4694 public void waitForEvents(long tmo)
4695 {
4696 try
4697 {
4698 Thread.sleep(tmo);
4699 }
4700 catch (InterruptedException ie)
4701 {
4702 }
4703 }
4704
4705 protected void finalize() throws Throwable
4706 {
4707 try
4708 {
4709 cleanup();
4710 }
4711 catch(Exception e)
4712 {
4713 }
4714 finally
4715 {
4716 super.finalize();
4717 }
4718 }
4719}
4720]]></xsl:text>
4721 </xsl:if>
4722
4723 <xsl:call-template name="endFile">
4724 <xsl:with-param name="file" select="'VirtualBoxManager.java'" />
4725 </xsl:call-template>
4726</xsl:template>
4727
4728
4729<xsl:template match="/">
4730
4731 <xsl:if test="not($G_vboxApiSuffix)">
4732 <xsl:call-template name="fatalError">
4733 <xsl:with-param name="msg" select="'G_vboxApiSuffix must be given'" />
4734 </xsl:call-template>
4735 </xsl:if>
4736
4737 <xsl:if test="not($filelistonly='')">
4738 <xsl:value-of select="concat($filelistonly, ' :=')"/>
4739 </xsl:if>
4740
4741 <!-- Handwritten files -->
4742 <xsl:call-template name="emitHandwritten"/>
4743
4744 <xsl:choose>
4745 <xsl:when test="$G_vboxGlueStyle='xpcom'">
4746 <xsl:call-template name="emitHandwrittenXpcom"/>
4747 </xsl:when>
4748
4749 <xsl:when test="$G_vboxGlueStyle='mscom'">
4750 <xsl:call-template name="emitHandwrittenMscom"/>
4751 </xsl:when>
4752
4753 <xsl:when test="$G_vboxGlueStyle='jaxws'">
4754 <xsl:call-template name="emitHandwrittenJaxws"/>
4755 </xsl:when>
4756
4757 <xsl:otherwise>
4758 <xsl:call-template name="fatalError">
4759 <xsl:with-param name="msg" select="'Style unknown (root)'" />
4760 </xsl:call-template>
4761 </xsl:otherwise>
4762 </xsl:choose>
4763
4764 <!-- Enums -->
4765 <xsl:for-each select="//enum">
4766 <xsl:call-template name="genEnum">
4767 <xsl:with-param name="enumname" select="@name" />
4768 <xsl:with-param name="filename" select="concat(@name, '.java')" />
4769 </xsl:call-template>
4770 </xsl:for-each>
4771
4772 <!-- Interfaces -->
4773 <xsl:for-each select="//interface">
4774 <xsl:variable name="self_target" select="current()/ancestor::if/@target"/>
4775 <xsl:variable name="module" select="current()/ancestor::module/@name"/>
4776
4777 <xsl:choose>
4778 <xsl:when test="$G_vboxGlueStyle='jaxws'">
4779 <xsl:if test="not($module) and not(@wsmap='suppress')">
4780 <xsl:call-template name="genIface">
4781 <xsl:with-param name="ifname" select="@name" />
4782 <xsl:with-param name="filename" select="concat(@name, '.java')" />
4783 </xsl:call-template>
4784 </xsl:if>
4785 </xsl:when>
4786
4787 <xsl:otherwise>
4788 <!-- We don't need WSDL-specific interfaces here -->
4789 <xsl:if test="not(@internal='yes') and not($self_target='wsdl') and not($module)">
4790 <xsl:call-template name="genIface">
4791 <xsl:with-param name="ifname" select="@name" />
4792 <xsl:with-param name="filename" select="concat(@name, '.java')" />
4793 </xsl:call-template>
4794 </xsl:if>
4795 </xsl:otherwise>
4796
4797 </xsl:choose>
4798 </xsl:for-each>
4799
4800 <xsl:if test="not($filelistonly='')">
4801 <xsl:value-of select="concat($G_sNewLine, $G_sNewLine)"/>
4802 </xsl:if>
4803
4804</xsl:template>
4805</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.

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