VirtualBox

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

Last change on this file since 56290 was 53939, checked in by vboxsync, 10 years ago

shared uppercase template.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 155.4 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-2014 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 IVirtualBox getVBox()
3173 {
3174 return this.vbox;
3175 }
3176
3177 public ISession getSessionObject()
3178 {
3179 return new ISession((org.mozilla.interfaces.ISession) componentManager
3180 .createInstanceByContractID("@virtualbox.org/Session;1", null,
3181 org.mozilla.interfaces.ISession.ISESSION_IID));
3182 }
3183
3184 public ISession openMachineSession(IMachine m) throws Exception
3185 {
3186 ISession s = getSessionObject();
3187 m.lockMachine(s, LockType.Shared);
3188 return s;
3189 }
3190
3191 public void closeMachineSession(ISession s)
3192 {
3193 if (s != null)
3194 s.unlockMachine();
3195 }
3196
3197 private static boolean hasInstance = false;
3198 private static boolean isMozillaInited = false;
3199
3200 public static synchronized VirtualBoxManager createInstance(String home)
3201 {
3202 if (hasInstance)
3203 throw new VBoxException("only one instance of VirtualBoxManager at a time allowed");
3204 if (home == null || home.equals(""))
3205 home = System.getProperty("vbox.home");
3206
3207 if (home == null)
3208 throw new VBoxException("vbox.home Java property must be defined to use XPCOM bridge");
3209
3210 File grePath = new File(home);
3211
3212 Mozilla mozilla = Mozilla.getInstance();
3213 if (!isMozillaInited)
3214 {
3215 mozilla.initialize(grePath);
3216 try
3217 {
3218 mozilla.initXPCOM(grePath, null);
3219 isMozillaInited = true;
3220 }
3221 catch (Exception e)
3222 {
3223 e.printStackTrace();
3224 return null;
3225 }
3226 }
3227
3228 hasInstance = true;
3229
3230 return new VirtualBoxManager(mozilla);
3231 }
3232
3233 public IEventListener createListener(Object sink)
3234 {
3235 return new IEventListener(new EventListenerImpl(sink));
3236 }
3237
3238 public void cleanup()
3239 {
3240 deinitPerThread();
3241 // cleanup, we don't do that, as XPCOM bridge doesn't cleanly
3242 // shuts down, so we prefer to avoid native shutdown
3243 // mozilla.shutdownXPCOM(null);
3244 mozilla = null;
3245 hasInstance = false;
3246 }
3247
3248 public void waitForEvents(long tmo)
3249 {
3250 mozilla.waitForEvents(tmo);
3251 }
3252}
3253]]></xsl:text>
3254 </xsl:if>
3255
3256 <xsl:call-template name="endFile">
3257 <xsl:with-param name="file" select="'VirtualBoxManager.java'" />
3258 </xsl:call-template>
3259
3260 <xsl:call-template name="startFile">
3261 <xsl:with-param name="file" select="'EventListenerImpl.java'" />
3262 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
3263 </xsl:call-template>
3264
3265 <xsl:if test="$filelistonly=''">
3266 <xsl:text><![CDATA[
3267import org.mozilla.interfaces.*;
3268
3269public class EventListenerImpl extends nsISupportsBase implements org.mozilla.interfaces.IEventListener
3270{
3271 private Object obj;
3272 private java.lang.reflect.Method handleEvent;
3273 EventListenerImpl(Object obj)
3274 {
3275 this.obj = obj;
3276 try
3277 {
3278 this.handleEvent = obj.getClass().getMethod("handleEvent", IEvent.class);
3279 }
3280 catch (Exception e)
3281 {
3282 e.printStackTrace();
3283 }
3284 }
3285 public void handleEvent(org.mozilla.interfaces.IEvent ev)
3286 {
3287 try
3288 {
3289 if (obj != null && handleEvent != null)
3290 handleEvent.invoke(obj, ev != null ? new IEvent(ev) : null);
3291 }
3292 catch (Exception e)
3293 {
3294 e.printStackTrace();
3295 }
3296 }
3297}]]></xsl:text>
3298 </xsl:if>
3299
3300 <xsl:call-template name="endFile">
3301 <xsl:with-param name="file" select="'EventListenerImpl.java'" />
3302 </xsl:call-template>
3303
3304 <xsl:call-template name="startFile">
3305 <xsl:with-param name="file" select="'VBoxObjectBase.java'" />
3306 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
3307 </xsl:call-template>
3308
3309 <xsl:if test="$filelistonly=''">
3310 <xsl:text><![CDATA[
3311abstract class nsISupportsBase implements org.mozilla.interfaces.nsISupports
3312{
3313 public org.mozilla.interfaces.nsISupports queryInterface(String iid)
3314 {
3315 return org.mozilla.xpcom.Mozilla.queryInterface(this, iid);
3316 }
3317}
3318
3319]]></xsl:text>
3320 </xsl:if>
3321
3322 <xsl:call-template name="endFile">
3323 <xsl:with-param name="file" select="'VBoxObjectBase.java'" />
3324 </xsl:call-template>
3325</xsl:template>
3326
3327
3328<xsl:template name="emitHandwrittenMscom">
3329
3330 <xsl:call-template name="startFile">
3331 <xsl:with-param name="file" select="'IUnknown.java'" />
3332 <xsl:with-param name="package" select="$G_virtualBoxPackageCom" />
3333 </xsl:call-template>
3334
3335 <xsl:if test="$filelistonly=''">
3336 <xsl:text><![CDATA[
3337public class IUnknown
3338{
3339 private Object obj;
3340 public IUnknown(Object obj)
3341 {
3342 this.obj = obj;
3343 }
3344
3345 public Object getWrapped()
3346 {
3347 return this.obj;
3348 }
3349
3350 public void setWrapped(Object obj)
3351 {
3352 this.obj = obj;
3353 }
3354}
3355]]></xsl:text>
3356 </xsl:if>
3357
3358 <xsl:call-template name="endFile">
3359 <xsl:with-param name="file" select="'IUnknown.java'" />
3360 </xsl:call-template>
3361
3362 <xsl:call-template name="startFile">
3363 <xsl:with-param name="file" select="'Helper.java'" />
3364 <xsl:with-param name="package" select="$G_virtualBoxPackageCom" />
3365 </xsl:call-template>
3366
3367 <xsl:if test="$filelistonly=''">
3368 <xsl:text><![CDATA[
3369
3370import java.util.List;
3371import java.util.ArrayList;
3372import java.util.Collections;
3373import java.lang.reflect.Array;
3374import java.lang.reflect.Constructor;
3375import java.lang.reflect.InvocationTargetException;
3376import com.jacob.com.*;
3377
3378public class Helper
3379{
3380 public static List<Short> wrap(short[] values)
3381 {
3382 if (values == null)
3383 return null;
3384
3385 List<Short> ret = new ArrayList<Short>(values.length);
3386 for (short v : values)
3387 {
3388 ret.add(v);
3389 }
3390 return ret;
3391 }
3392
3393 public static List<Integer> wrap(int[] values)
3394 {
3395 if (values == null)
3396 return null;
3397
3398 List<Integer> ret = new ArrayList<Integer>(values.length);
3399 for (int v : values)
3400 {
3401 ret.add(v);
3402 }
3403 return ret;
3404 }
3405
3406 public static List<Long> wrap(long[] values)
3407 {
3408 if (values == null)
3409 return null;
3410
3411 List<Long> ret = new ArrayList<Long>(values.length);
3412 for (long v : values)
3413 {
3414 ret.add(v);
3415 }
3416 return ret;
3417 }
3418
3419 public static List<String> wrap(String[] values)
3420 {
3421 if (values == null)
3422 return null;
3423
3424 List<String> ret = new ArrayList<String>(values.length);
3425 for (String v : values)
3426 {
3427 ret.add(v);
3428 }
3429 return ret;
3430 }
3431
3432 public static <T> T wrapDispatch(Class<T> wrapperClass, Dispatch d)
3433 {
3434 try
3435 {
3436 if (d == null || d.m_pDispatch == 0)
3437 return null;
3438 Constructor<T> c = wrapperClass.getConstructor(Dispatch.class);
3439 return (T)c.newInstance(d);
3440 }
3441 catch (NoSuchMethodException e)
3442 {
3443 throw new AssertionError(e);
3444 }
3445 catch (InstantiationException e)
3446 {
3447 throw new AssertionError(e);
3448 }
3449 catch (IllegalAccessException e)
3450 {
3451 throw new AssertionError(e);
3452 }
3453 catch (InvocationTargetException e)
3454 {
3455 throw new AssertionError(e);
3456 }
3457 }
3458
3459 @SuppressWarnings("unchecked")
3460 public static <T> Object wrapVariant(Class<T> wrapperClass, Variant v)
3461 {
3462 if (v == null)
3463 return null;
3464
3465 short vt = v.getvt();
3466 switch (vt)
3467 {
3468 case Variant.VariantNull:
3469 return null;
3470 case Variant.VariantBoolean:
3471 return v.getBoolean();
3472 case Variant.VariantByte:
3473 return v.getByte();
3474 case Variant.VariantShort:
3475 return v.getShort();
3476 case Variant.VariantInt:
3477 return v.getInt();
3478 case Variant.VariantLongInt:
3479 return v.getLong();
3480 case Variant.VariantString:
3481 return v.getString();
3482 case Variant.VariantDispatch:
3483 return wrapDispatch(wrapperClass, v.getDispatch());
3484 default:
3485 throw new IllegalArgumentException("unhandled variant type " + vt);
3486 }
3487 }
3488
3489 public static byte[] wrapBytes(SafeArray sa)
3490 {
3491 if (sa == null)
3492 return null;
3493
3494 int saLen = sa.getUBound() - sa.getLBound() + 1;
3495
3496 byte[] ret = new byte[saLen];
3497 int j = 0;
3498 for (int i = sa.getLBound(); i <= sa.getUBound(); i++)
3499 {
3500 Variant v = sa.getVariant(i);
3501 // come up with more effective approach!!!
3502 ret[j++] = v.getByte();
3503 }
3504 return ret;
3505 }
3506
3507 @SuppressWarnings("unchecked")
3508 public static <T> List<T> wrap(Class<T> wrapperClass, SafeArray sa)
3509 {
3510 if (sa == null)
3511 return null;
3512
3513 int saLen = sa.getUBound() - sa.getLBound() + 1;
3514 if (saLen == 0)
3515 return Collections.emptyList();
3516
3517 List<T> ret = new ArrayList<T>(saLen);
3518 for (int i = sa.getLBound(); i <= sa.getUBound(); i++)
3519 {
3520 Variant v = sa.getVariant(i);
3521 ret.add((T)wrapVariant(wrapperClass, v));
3522 }
3523 return ret;
3524 }
3525
3526 public static <T> List<T> wrapEnum(Class<T> wrapperClass, SafeArray sa)
3527 {
3528 try
3529 {
3530 if (sa == null)
3531 return null;
3532
3533 int saLen = sa.getUBound() - sa.getLBound() + 1;
3534 if (saLen == 0)
3535 return Collections.emptyList();
3536 List<T> ret = new ArrayList<T>(saLen);
3537 Constructor<T> c = wrapperClass.getConstructor(int.class);
3538 for (int i = sa.getLBound(); i <= sa.getUBound(); i++)
3539 {
3540 Variant v = sa.getVariant(i);
3541 ret.add(c.newInstance(v.getInt()));
3542 }
3543 return ret;
3544 }
3545 catch (NoSuchMethodException e)
3546 {
3547 throw new AssertionError(e);
3548 }
3549 catch (InstantiationException e)
3550 {
3551 throw new AssertionError(e);
3552 }
3553 catch (IllegalAccessException e)
3554 {
3555 throw new AssertionError(e);
3556 }
3557 catch (InvocationTargetException e)
3558 {
3559 throw new AssertionError(e);
3560 }
3561 }
3562
3563 public static SafeArray unwrapInt(List<Integer> values)
3564 {
3565 if (values == null)
3566 return null;
3567 SafeArray ret = new SafeArray(Variant.VariantInt, values.size());
3568 int i = 0;
3569 for (int l : values)
3570 {
3571 ret.setInt(i++, l);
3572 }
3573 return ret;
3574 }
3575
3576 public static SafeArray unwrapLong(List<Long> values)
3577 {
3578 if (values == null)
3579 return null;
3580 SafeArray ret = new SafeArray(Variant.VariantLongInt, values.size());
3581 int i = 0;
3582 for (long l : values)
3583 {
3584 ret.setLong(i++, l);
3585 }
3586 return ret;
3587 }
3588
3589 public static SafeArray unwrapBool(List<Boolean> values)
3590 {
3591 if (values == null)
3592 return null;
3593
3594 SafeArray result = new SafeArray(Variant.VariantBoolean, values.size());
3595 int i = 0;
3596 for (boolean l : values)
3597 {
3598 result.setBoolean(i++, l);
3599 }
3600 return result;
3601 }
3602
3603
3604 public static SafeArray unwrapBytes(byte[] values)
3605 {
3606 if (values == null)
3607 return null;
3608
3609 SafeArray result = new SafeArray(Variant.VariantByte, values.length);
3610 int i = 0;
3611 for (byte l : values)
3612 {
3613 result.setByte(i++, l);
3614 }
3615 return result;
3616 }
3617
3618
3619 public static <T extends Enum <T>> SafeArray unwrapEnum(Class<T> enumClass, List<T> values)
3620 {
3621 if (values == null)
3622 return null;
3623
3624 SafeArray result = new SafeArray(Variant.VariantInt, values.size());
3625 try
3626 {
3627 java.lang.reflect.Method valueM = enumClass.getMethod("value");
3628 int i = 0;
3629 for (T v : values)
3630 {
3631 result.setInt(i++, (Integer)valueM.invoke(v));
3632 }
3633 return result;
3634 }
3635 catch (NoSuchMethodException e)
3636 {
3637 throw new AssertionError(e);
3638 }
3639 catch(SecurityException e)
3640 {
3641 throw new AssertionError(e);
3642 }
3643 catch (IllegalAccessException e)
3644 {
3645 throw new AssertionError(e);
3646 }
3647 catch (IllegalArgumentException e)
3648 {
3649 throw new AssertionError(e);
3650 }
3651 catch (InvocationTargetException e)
3652 {
3653 throw new AssertionError(e);
3654 }
3655 }
3656 public static SafeArray unwrapString(List<String> values)
3657 {
3658 if (values == null)
3659 return null;
3660 SafeArray result = new SafeArray(Variant.VariantString, values.size());
3661 int i = 0;
3662 for (String l : values)
3663 {
3664 result.setString(i++, l);
3665 }
3666 return result;
3667 }
3668
3669 public static <T1, T2> List<T1> wrap2(Class<T1> wrapperClass1, Class<T2> wrapperClass2, T2[] values)
3670 {
3671 try
3672 {
3673 if (values == null)
3674 return null;
3675 if (values.length == 0)
3676 return Collections.emptyList();
3677
3678 Constructor<T1> c = wrapperClass1.getConstructor(wrapperClass2);
3679 List<T1> ret = new ArrayList<T1>(values.length);
3680 for (T2 v : values)
3681 {
3682 ret.add(c.newInstance(v));
3683 }
3684 return ret;
3685 }
3686 catch (NoSuchMethodException e)
3687 {
3688 throw new AssertionError(e);
3689 }
3690 catch (InstantiationException e)
3691 {
3692 throw new AssertionError(e);
3693 }
3694 catch (IllegalAccessException e)
3695 {
3696 throw new AssertionError(e);
3697 }
3698 catch (InvocationTargetException e)
3699 {
3700 throw new AssertionError(e);
3701 }
3702 }
3703
3704 @SuppressWarnings("unchecked")
3705 public static <T> T[] unwrap(Class<T> wrapperClass, List<T> values)
3706 {
3707 if (values == null)
3708 return null;
3709 return (T[])values.toArray((T[])Array.newInstance(wrapperClass, values.size()));
3710 }
3711
3712 @SuppressWarnings("unchecked")
3713 public static <T1 extends IUnknown, T2> T2[] unwrap2(Class<T1> wrapperClass1, Class<T2> wrapperClass2, List<T1> values)
3714 {
3715 if (values == null)
3716 return null;
3717
3718 T2 ret[] = (T2[])Array.newInstance(wrapperClass2, values.size());
3719 int i = 0;
3720 for (T1 obj : values)
3721 {
3722 ret[i++] = (T2)obj.getWrapped();
3723 }
3724 return ret;
3725 }
3726
3727 /* We have very long invoke lists sometimes */
3728 public static Variant invoke(Dispatch d, String method, Object ... args)
3729 {
3730 return Dispatch.callN(d, method, args);
3731 }
3732}
3733]]></xsl:text>
3734 </xsl:if>
3735
3736 <xsl:call-template name="endFile">
3737 <xsl:with-param name="file" select="'Helper.java'" />
3738 </xsl:call-template>
3739
3740 <xsl:call-template name="startFile">
3741 <xsl:with-param name="file" select="'VBoxException.java'" />
3742 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
3743 </xsl:call-template>
3744
3745 <xsl:if test="$filelistonly=''">
3746 <xsl:text>
3747
3748public class VBoxException extends RuntimeException
3749{
3750 private int resultCode;
3751 private IVirtualBoxErrorInfo errorInfo;
3752
3753 public VBoxException(String message)
3754 {
3755 super(message);
3756 resultCode = -1;
3757 errorInfo = null;
3758 }
3759
3760 public VBoxException(String message, Throwable cause)
3761 {
3762 super(message, cause);
3763 if (cause instanceof com.jacob.com.ComException)
3764 {
3765 resultCode = ((com.jacob.com.ComException)cause).getHResult();
3766 // JACOB doesn't support calling GetErrorInfo, which
3767 // means there is no way of getting an IErrorInfo reference,
3768 // and that means no way of getting to IVirtualBoxErrorInfo.
3769 errorInfo = null;
3770 }
3771 else
3772 resultCode = -1;
3773 }
3774
3775 public int getResultCode()
3776 {
3777 return resultCode;
3778 }
3779
3780 public IVirtualBoxErrorInfo getVirtualBoxErrorInfo()
3781 {
3782 return errorInfo;
3783 }
3784}
3785</xsl:text>
3786 </xsl:if>
3787
3788 <xsl:call-template name="endFile">
3789 <xsl:with-param name="file" select="'VBoxException.java'" />
3790 </xsl:call-template>
3791
3792
3793 <xsl:call-template name="startFile">
3794 <xsl:with-param name="file" select="'VirtualBoxManager.java'" />
3795 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
3796 </xsl:call-template>
3797
3798 <xsl:if test="$filelistonly=''">
3799 <xsl:text><![CDATA[
3800
3801import com.jacob.activeX.ActiveXComponent;
3802import com.jacob.com.ComThread;
3803import com.jacob.com.Dispatch;
3804import com.jacob.com.Variant;
3805import com.jacob.com.SafeArray;
3806import com.jacob.com.DispatchEvents;
3807
3808public class VirtualBoxManager
3809{
3810 private IVirtualBox vbox;
3811
3812 private VirtualBoxManager()
3813 {
3814 initPerThread();
3815 vbox = new IVirtualBox(new ActiveXComponent("VirtualBox.VirtualBox"));
3816 }
3817
3818 public static void initPerThread()
3819 {
3820 ComThread.InitMTA();
3821 }
3822
3823 public static void deinitPerThread()
3824 {
3825 ComThread.Release();
3826 }
3827
3828 public void connect(String url, String username, String passwd)
3829 {
3830 throw new VBoxException("Connect doesn't make sense for local bindings");
3831 }
3832
3833 public void disconnect()
3834 {
3835 throw new VBoxException("Disconnect doesn't make sense for local bindings");
3836 }
3837
3838 public IVirtualBox getVBox()
3839 {
3840 return this.vbox;
3841 }
3842
3843 public ISession getSessionObject()
3844 {
3845 return new ISession(new ActiveXComponent("VirtualBox.Session"));
3846 }
3847
3848 public ISession openMachineSession(IMachine m)
3849 {
3850 ISession s = getSessionObject();
3851 m.lockMachine(s, LockType.Shared);
3852 return s;
3853 }
3854
3855 public void closeMachineSession(ISession s)
3856 {
3857 if (s != null)
3858 s.unlockMachine();
3859 }
3860
3861 private static boolean hasInstance = false;
3862
3863 public static synchronized VirtualBoxManager createInstance(String home)
3864 {
3865 if (hasInstance)
3866 throw new VBoxException("only one instance of VirtualBoxManager at a time allowed");
3867
3868 hasInstance = true;
3869 return new VirtualBoxManager();
3870 }
3871
3872 public void cleanup()
3873 {
3874 deinitPerThread();
3875 hasInstance = false;
3876 }
3877
3878 public void waitForEvents(long tmo)
3879 {
3880 // what to do here?
3881 try
3882 {
3883 Thread.sleep(tmo);
3884 }
3885 catch (InterruptedException ie)
3886 {
3887 }
3888 }
3889}
3890]]></xsl:text>
3891 </xsl:if>
3892
3893 <xsl:call-template name="endFile">
3894 <xsl:with-param name="file" select="'VirtualBoxManager.java'" />
3895 </xsl:call-template>
3896</xsl:template>
3897
3898<xsl:template name="emitHandwrittenJaxws">
3899
3900 <xsl:call-template name="startFile">
3901 <xsl:with-param name="file" select="'IUnknown.java'" />
3902 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
3903 </xsl:call-template>
3904
3905 <xsl:if test="$filelistonly=''">
3906 <xsl:text><![CDATA[
3907public class IUnknown
3908{
3909 protected String obj;
3910 protected final VboxPortType port;
3911
3912 public IUnknown(String obj, VboxPortType port)
3913 {
3914 this.obj = obj;
3915 this.port = port;
3916 }
3917
3918 public final String getWrapped()
3919 {
3920 return this.obj;
3921 }
3922
3923 public final VboxPortType getRemoteWSPort()
3924 {
3925 return this.port;
3926 }
3927
3928 public synchronized void releaseRemote() throws WebServiceException
3929 {
3930 if (obj == null)
3931 return;
3932
3933 try
3934 {
3935 this.port.iManagedObjectRefRelease(obj);
3936 this.obj = null;
3937 }
3938 catch (InvalidObjectFaultMsg e)
3939 {
3940 throw new WebServiceException(e);
3941 }
3942 catch (RuntimeFaultMsg e)
3943 {
3944 throw new WebServiceException(e);
3945 }
3946 }
3947}
3948]]></xsl:text>
3949 </xsl:if>
3950
3951 <xsl:call-template name="endFile">
3952 <xsl:with-param name="file" select="'IUnknown.java'" />
3953 </xsl:call-template>
3954
3955 <xsl:call-template name="startFile">
3956 <xsl:with-param name="file" select="'Helper.java'" />
3957 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
3958 </xsl:call-template>
3959
3960 <xsl:if test="$filelistonly=''">
3961 <xsl:text><![CDATA[
3962
3963import java.util.List;
3964import java.util.ArrayList;
3965import java.util.Collections;
3966import java.lang.reflect.Array;
3967import java.lang.reflect.Constructor;
3968import java.lang.reflect.InvocationTargetException;
3969import java.math.BigInteger;
3970
3971public class Helper
3972{
3973 public static <T> List<T> wrap(Class<T> wrapperClass, VboxPortType pt, List<String> values)
3974 {
3975 try
3976 {
3977 if (values == null)
3978 return null;
3979
3980 Constructor<T> c = wrapperClass.getConstructor(String.class, VboxPortType.class);
3981 List<T> ret = new ArrayList<T>(values.size());
3982 for (String v : values)
3983 {
3984 ret.add(c.newInstance(v, pt));
3985 }
3986 return ret;
3987 }
3988 catch (NoSuchMethodException e)
3989 {
3990 throw new AssertionError(e);
3991 }
3992 catch (InstantiationException e)
3993 {
3994 throw new AssertionError(e);
3995 }
3996 catch (IllegalAccessException e)
3997 {
3998 throw new AssertionError(e);
3999 }
4000 catch (InvocationTargetException e)
4001 {
4002 throw new AssertionError(e);
4003 }
4004 }
4005
4006 public static <T1, T2> List<T1> wrap2(Class<T1> wrapperClass1, Class<T2> wrapperClass2, VboxPortType pt, List<T2> values)
4007 {
4008 try
4009 {
4010 if (values == null)
4011 return null;
4012
4013 Constructor<T1> c = wrapperClass1.getConstructor(wrapperClass2, VboxPortType.class);
4014 List<T1> ret = new ArrayList<T1>(values.size());
4015 for (T2 v : values)
4016 {
4017 ret.add(c.newInstance(v, pt));
4018 }
4019 return ret;
4020 }
4021 catch (NoSuchMethodException e)
4022 {
4023 throw new AssertionError(e);
4024 }
4025 catch (InstantiationException e)
4026 {
4027 throw new AssertionError(e);
4028 }
4029 catch (IllegalAccessException e)
4030 {
4031 throw new AssertionError(e);
4032 }
4033 catch (InvocationTargetException e)
4034 {
4035 throw new AssertionError(e);
4036 }
4037 }
4038
4039 public static <T extends IUnknown> List<String> unwrap(List<T> values)
4040 {
4041 if (values == null)
4042 return null;
4043
4044 List<String> ret = new ArrayList<String>(values.size());
4045 for (T obj : values)
4046 {
4047 ret.add(obj.getWrapped());
4048 }
4049 return ret;
4050 }
4051
4052 @SuppressWarnings("unchecked" )
4053 public static <T1 extends Enum <T1>, T2 extends Enum <T2>> List<T2> convertEnums(Class<T1> fromClass,
4054 Class<T2> toClass,
4055 List<T1> values)
4056 {
4057 try
4058 {
4059 if (values == null)
4060 return null;
4061 List<T2> ret = new ArrayList<T2>(values.size());
4062 for (T1 v : values)
4063 {
4064 // Ordinal based enum conversion, as JAX-WS "invents" its own
4065 // enum names and has string values with the expected content.
4066 int enumOrdinal = v.ordinal();
4067 T2 convEnum = toClass.getEnumConstants()[enumOrdinal];
4068 ret.add(convEnum);
4069 }
4070 return ret;
4071 }
4072 catch (ArrayIndexOutOfBoundsException e)
4073 {
4074 throw new AssertionError(e);
4075 }
4076 }
4077
4078 /* Pretty naive Base64 encoder/decoder. */
4079 private static final char[] valToChar = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray();
4080 private static final int[] charToVal = new int[256];
4081
4082 /* Initialize recoding alphabet. */
4083 static
4084 {
4085 for (int i = 0; i < charToVal.length; i++)
4086 charToVal[i] = -1;
4087
4088 for (int i = 0; i < valToChar.length; i++)
4089 charToVal[valToChar[i]] = i;
4090
4091 charToVal['='] = 0;
4092 }
4093
4094 public static String encodeBase64(byte[] data)
4095 {
4096 if (data == null)
4097 return null;
4098
4099 if (data.length == 0)
4100 return "";
4101
4102 int fullTriplets = data.length / 3;
4103 int resultLen = ((data.length - 1) / 3 + 1) * 4;
4104 char[] result = new char[resultLen];
4105 int dataIndex = 0, stringIndex = 0;
4106
4107 for (int i = 0; i < fullTriplets; i++)
4108 {
4109 int ch1 = data[dataIndex++] & 0xff;
4110 result[stringIndex++] = valToChar[ch1 >> 2];
4111 int ch2 = data[dataIndex++] & 0xff;
4112 result[stringIndex++] = valToChar[((ch1 << 4) & 0x3f) | (ch2 >> 4)];
4113 int ch3 = data[dataIndex++] & 0xff;
4114 result[stringIndex++] = valToChar[((ch2 << 2) & 0x3f) | (ch3 >> 6)];
4115 result[stringIndex++] = valToChar[ch3 & 0x3f];
4116 }
4117
4118 switch (data.length - dataIndex)
4119 {
4120 case 0:
4121 // do nothing
4122 break;
4123 case 1:
4124 {
4125 int ch1 = data[dataIndex++] & 0xff;
4126 result[stringIndex++] = valToChar[ch1 >> 2];
4127 result[stringIndex++] = valToChar[(ch1 << 4) & 0x3f];
4128 result[stringIndex++] = '=';
4129 result[stringIndex++] = '=';
4130 break;
4131 }
4132 case 2:
4133 {
4134 int ch1 = data[dataIndex++] & 0xff;
4135 result[stringIndex++] = valToChar[ch1 >> 2];
4136 int ch2 = data[dataIndex++] & 0xff;
4137 result[stringIndex++] = valToChar[((ch1 << 4) & 0x3f) | (ch2 >> 4)];
4138 result[stringIndex++] = valToChar[(ch2 << 2) & 0x3f];
4139 result[stringIndex++] = '=';
4140 break;
4141 }
4142 default:
4143 throw new VBoxException("bug!");
4144 }
4145
4146 return new String(result);
4147 }
4148
4149 private static int skipInvalid(String str, int stringIndex)
4150 {
4151 while (charToVal[str.charAt(stringIndex)] < 0)
4152 stringIndex++;
4153
4154 return stringIndex;
4155 }
4156
4157 public static byte[] decodeBase64(String str)
4158 {
4159 if (str == null)
4160 return null;
4161
4162 int stringLength = str.length();
4163 if (stringLength == 0)
4164 return new byte[0];
4165
4166 int validChars = 0, padChars = 0;
4167 for (int i = 0; i < str.length(); i++)
4168 {
4169 char ch = str.charAt(i);
4170
4171 if (charToVal[ch] >= 0)
4172 validChars++;
4173
4174 if (ch == '=')
4175 padChars++;
4176 }
4177
4178 if ((validChars * 3 % 4) != 0)
4179 throw new VBoxException("invalid base64 encoded string " + str);
4180
4181 int resultLength = validChars * 3 / 4 - padChars;
4182 byte[] result = new byte[resultLength];
4183
4184 int dataIndex = 0, stringIndex = 0;
4185 int quadraplets = validChars / 4;
4186
4187 for (int i = 0; i < quadraplets; i++)
4188 {
4189 stringIndex = skipInvalid(str, stringIndex);
4190 int ch1 = str.charAt(stringIndex++);
4191 stringIndex = skipInvalid(str, stringIndex);
4192 int ch2 = str.charAt(stringIndex++);
4193 stringIndex = skipInvalid(str, stringIndex);
4194 int ch3 = str.charAt(stringIndex++);
4195 stringIndex = skipInvalid(str, stringIndex);
4196 int ch4 = str.charAt(stringIndex++);
4197
4198 result[dataIndex++] = (byte)(((charToVal[ch1] << 2) | charToVal[ch2] >> 4) & 0xff);
4199 /* we check this to ensure that we don't override data with '=' padding. */
4200 if (dataIndex < result.length)
4201 result[dataIndex++] = (byte)(((charToVal[ch2] << 4) | charToVal[ch3] >> 2) & 0xff);
4202 if (dataIndex < result.length)
4203 result[dataIndex++] = (byte)(((charToVal[ch3] << 6) | charToVal[ch4]) & 0xff);
4204 }
4205
4206 return result;
4207 }
4208}
4209]]></xsl:text>
4210 </xsl:if>
4211
4212 <xsl:call-template name="endFile">
4213 <xsl:with-param name="file" select="'Helper.java'" />
4214 </xsl:call-template>
4215
4216 <xsl:call-template name="startFile">
4217 <xsl:with-param name="file" select="'VBoxException.java'" />
4218 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
4219 </xsl:call-template>
4220
4221 <xsl:if test="$filelistonly=''">
4222 <xsl:text>
4223public class VBoxException extends RuntimeException
4224{
4225 private int resultCode;
4226 private IVirtualBoxErrorInfo errorInfo;
4227
4228 public VBoxException(String message)
4229 {
4230 super(message);
4231 resultCode = -1;
4232 errorInfo = null;
4233 }
4234
4235 public VBoxException(String message, Throwable cause)
4236 {
4237 super(message, cause);
4238 resultCode = -1;
4239 errorInfo = null;
4240 }
4241
4242 public VBoxException(String message, Throwable cause, VboxPortType port)
4243 {
4244 super(message, cause);
4245 if (cause instanceof RuntimeFaultMsg)
4246 {
4247 RuntimeFaultMsg m = (RuntimeFaultMsg)cause;
4248 RuntimeFault f = m.getFaultInfo();
4249 resultCode = f.getResultCode();
4250 String retVal = f.getReturnval();
4251 errorInfo = (retVal.length() > 0) ? new IVirtualBoxErrorInfo(retVal, port) : null;
4252 }
4253 else
4254 resultCode = -1;
4255 }
4256
4257 public int getResultCode()
4258 {
4259 return resultCode;
4260 }
4261
4262 public IVirtualBoxErrorInfo getVirtualBoxErrorInfo()
4263 {
4264 return errorInfo;
4265 }
4266}
4267</xsl:text>
4268 </xsl:if>
4269
4270 <xsl:call-template name="endFile">
4271 <xsl:with-param name="file" select="'VBoxException.java'" />
4272 </xsl:call-template>
4273
4274 <xsl:call-template name="startFile">
4275 <xsl:with-param name="file" select="'VirtualBoxManager.java'" />
4276 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
4277 </xsl:call-template>
4278
4279 <xsl:if test="$filelistonly=''">
4280 <xsl:text>import java.net.URL;
4281import java.math.BigInteger;
4282import java.util.List;
4283import java.util.Map;
4284import java.util.HashMap;
4285import java.util.ArrayList;
4286import javax.xml.namespace.QName;
4287import javax.xml.ws.BindingProvider;
4288import javax.xml.ws.Holder;
4289import javax.xml.ws.WebServiceException;
4290import java.io.IOException;
4291import java.net.UnknownHostException;
4292import java.net.Socket;
4293import java.net.InetAddress;
4294import javax.net.SocketFactory;
4295import javax.net.ssl.SSLContext;
4296import javax.net.ssl.SSLSocketFactory;
4297import javax.net.ssl.SSLSocket;
4298
4299class PortPool
4300{
4301 private final static String wsdlFile = </xsl:text>
4302 <xsl:value-of select="$G_virtualBoxWsdl" />
4303 <xsl:text><![CDATA[;
4304 private Map<VboxPortType, Integer> known;
4305 private boolean initStarted;
4306 private VboxService svc;
4307
4308 PortPool(boolean usePreinit)
4309 {
4310 known = new HashMap<VboxPortType, Integer>();
4311
4312 if (usePreinit)
4313 {
4314 new Thread(new Runnable()
4315 {
4316 public void run()
4317 {
4318 // need to sync on something else but 'this'
4319 synchronized (known)
4320 {
4321 initStarted = true;
4322 known.notify();
4323 }
4324
4325 preinit();
4326 }
4327 }).start();
4328
4329 synchronized (known)
4330 {
4331 while (!initStarted)
4332 {
4333 try
4334 {
4335 known.wait();
4336 }
4337 catch (InterruptedException e)
4338 {
4339 break;
4340 }
4341 }
4342 }
4343 }
4344 }
4345
4346 private synchronized void preinit()
4347 {
4348 VboxPortType port = getPort();
4349 releasePort(port);
4350 }
4351
4352 synchronized VboxPortType getPort()
4353 {
4354 VboxPortType port = null;
4355 int ttl = 0;
4356
4357 for (VboxPortType cur: known.keySet())
4358 {
4359 int value = known.get(cur);
4360 if ((value & 0x10000) == 0)
4361 {
4362 port = cur;
4363 ttl = value & 0xffff;
4364 break;
4365 }
4366 }
4367
4368 if (port == null)
4369 {
4370 if (svc == null)
4371 {
4372 URL wsdl = PortPool.class.getClassLoader().getResource(wsdlFile);
4373 if (wsdl == null)
4374 throw new LinkageError(wsdlFile + " not found, but it should have been in the jar");
4375 svc = new VboxService(wsdl,
4376 new QName("http://www.virtualbox.org/Service",
4377 "vboxService"));
4378 }
4379 port = svc.getVboxServicePort();
4380 // reuse this object 0x10 times
4381 ttl = 0x10;
4382 }
4383 // mark as used
4384 known.put(port, new Integer(0x10000 | ttl));
4385 return port;
4386 }
4387
4388 synchronized void releasePort(VboxPortType port)
4389 {
4390 Integer val = known.get(port);
4391 if (val == null || val == 0)
4392 {
4393 // know you not
4394 return;
4395 }
4396
4397 int v = val;
4398 int ttl = v & 0xffff;
4399 // decrement TTL, and throw away port if used too much times
4400 if (--ttl <= 0)
4401 {
4402 known.remove(port);
4403 }
4404 else
4405 {
4406 v = ttl; // set new TTL and clear busy bit
4407 known.put(port, v);
4408 }
4409 }
4410}
4411
4412
4413class VBoxTLSSocketFactory extends SSLSocketFactory
4414{
4415 private final SSLSocketFactory sf;
4416
4417 private void setupSocket(SSLSocket s)
4418 {
4419 String[] oldproto = s.getEnabledProtocols();
4420 List<String> protolist = new ArrayList<String>();
4421 for (int i = 0; i < oldproto.length; i++)
4422 if (oldproto[i].toUpperCase().startsWith("TLS"))
4423 protolist.add(oldproto[i]);
4424 String[] newproto = protolist.toArray(new String[protolist.size()]);
4425 s.setEnabledProtocols(newproto);
4426 }
4427
4428 public VBoxTLSSocketFactory()
4429 {
4430 SSLSocketFactory tmp = null;
4431 try
4432 {
4433 SSLContext sc = SSLContext.getInstance("TLS");
4434 sc.init(null, null, null);
4435 tmp = sc.getSocketFactory();
4436 }
4437 catch (Exception e)
4438 {
4439 e.printStackTrace();
4440 }
4441 sf = tmp;
4442 }
4443
4444 public static SocketFactory getDefault()
4445 {
4446 return new VBoxTLSSocketFactory();
4447 }
4448
4449 public Socket createSocket(Socket socket, String host, int port,
4450 boolean autoClose) throws IOException, UnknownHostException
4451 {
4452 SSLSocket s = (SSLSocket)sf.createSocket(socket, host, port, autoClose);
4453 setupSocket(s);
4454 return s;
4455 }
4456
4457 public Socket createSocket() throws IOException
4458 {
4459 SSLSocket s = (SSLSocket)sf.createSocket();
4460 setupSocket(s);
4461 return s;
4462 }
4463
4464 public Socket createSocket(InetAddress host, int port) throws IOException
4465 {
4466 SSLSocket s = (SSLSocket)sf.createSocket(host, port);
4467 setupSocket(s);
4468 return s;
4469 }
4470
4471 public Socket createSocket(InetAddress address, int port,
4472 InetAddress localAddress, int localPort) throws IOException
4473 {
4474 SSLSocket s = (SSLSocket)sf.createSocket(address, port, localAddress, localPort);
4475 setupSocket(s);
4476 return s;
4477 }
4478
4479 public Socket createSocket(String host, int port) throws IOException, UnknownHostException
4480 {
4481 SSLSocket s = (SSLSocket)sf.createSocket(host, port);
4482 setupSocket(s);
4483 return s;
4484 }
4485
4486 public Socket createSocket(String host, int port,
4487 InetAddress localHost, int localPort) throws IOException, UnknownHostException
4488 {
4489 SSLSocket s = (SSLSocket)sf.createSocket(host, port, localHost, localPort);
4490 setupSocket(s);
4491 return s;
4492 }
4493
4494 public String[] getDefaultCipherSuites()
4495 {
4496 return sf.getSupportedCipherSuites();
4497 }
4498
4499 public String[] getSupportedCipherSuites()
4500 {
4501 return sf.getSupportedCipherSuites();
4502 }
4503}
4504
4505
4506public class VirtualBoxManager
4507{
4508 private static PortPool pool = new PortPool(true);
4509 protected VboxPortType port;
4510
4511 private IVirtualBox vbox;
4512
4513 private VirtualBoxManager()
4514 {
4515 }
4516
4517 public static void initPerThread()
4518 {
4519 }
4520
4521 public static void deinitPerThread()
4522 {
4523 }
4524
4525 public void connect(String url, String username, String passwd)
4526 {
4527 this.port = pool.getPort();
4528 try
4529 {
4530 ((BindingProvider)port).getRequestContext().
4531 put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
4532
4533 // Unfortunately there is no official way to make JAX-WS use
4534 // TLS only, which means that a rather tedious approach is
4535 // unavoidable (implementing a TLS only SSLSocketFactory,
4536 // because the default one associated with a TLS SSLContext
4537 // happily uses SSLv2/3 handshakes, which make TLS servers
4538 // drop the connection), and additionally a not standardized,
4539 // shotgun approach is needed to make the relevant JAX-WS
4540 // implementations use this factory.
4541 VBoxTLSSocketFactory sf = new VBoxTLSSocketFactory();
4542 ((BindingProvider)port).getRequestContext().
4543 put("com.sun.xml.internal.ws.transport.https.client.SSLSocketFactory", sf);
4544 ((BindingProvider)port).getRequestContext().
4545 put("com.sun.xml.ws.transport.https.client.SSLSocketFactory", sf);
4546
4547 String handle = port.iWebsessionManagerLogon(username, passwd);
4548 this.vbox = new IVirtualBox(handle, port);
4549 }
4550 catch (Throwable t)
4551 {
4552 if (this.port != null && pool != null)
4553 {
4554 pool.releasePort(this.port);
4555 this.port = null;
4556 }
4557 // we have to throw smth derived from RuntimeException
4558 throw new VBoxException(t.getMessage(), t, this.port);
4559 }
4560 }
4561
4562 public void connect(String url, String username, String passwd,
4563 Map<String, Object> requestContext, Map<String, Object> responseContext)
4564 {
4565 this.port = pool.getPort();
4566
4567 try
4568 {
4569 ((BindingProvider)port).getRequestContext();
4570 if (requestContext != null)
4571 ((BindingProvider)port).getRequestContext().putAll(requestContext);
4572
4573 if (responseContext != null)
4574 ((BindingProvider)port).getResponseContext().putAll(responseContext);
4575
4576 ((BindingProvider)port).getRequestContext().
4577 put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
4578 String handle = port.iWebsessionManagerLogon(username, passwd);
4579 this.vbox = new IVirtualBox(handle, port);
4580 }
4581 catch (Throwable t)
4582 {
4583 if (this.port != null && pool != null)
4584 {
4585 pool.releasePort(this.port);
4586 this.port = null;
4587 }
4588 // we have to throw smth derived from RuntimeException
4589 throw new VBoxException(t.getMessage(), t, this.port);
4590 }
4591 }
4592
4593 public void disconnect()
4594 {
4595 if (this.port == null)
4596 return;
4597
4598 try
4599 {
4600 if (this.vbox != null && port != null)
4601 port.iWebsessionManagerLogoff(this.vbox.getWrapped());
4602 }
4603 catch (InvalidObjectFaultMsg e)
4604 {
4605 throw new VBoxException(e.getMessage(), e, this.port);
4606 }
4607 catch (RuntimeFaultMsg e)
4608 {
4609 throw new VBoxException(e.getMessage(), e, this.port);
4610 }
4611 finally
4612 {
4613 if (this.port != null)
4614 {
4615 pool.releasePort(this.port);
4616 this.port = null;
4617 }
4618 }
4619 }
4620
4621 public IVirtualBox getVBox()
4622 {
4623 return this.vbox;
4624 }
4625
4626 public ISession getSessionObject()
4627 {
4628 if (this.vbox == null)
4629 throw new VBoxException("connect first");
4630 try
4631 {
4632 String handle = port.iWebsessionManagerGetSessionObject(this.vbox.getWrapped());
4633 return new ISession(handle, port);
4634 }
4635 catch (InvalidObjectFaultMsg e)
4636 {
4637 throw new VBoxException(e.getMessage(), e, this.port);
4638 }
4639 catch (RuntimeFaultMsg e)
4640 {
4641 throw new VBoxException(e.getMessage(), e, this.port);
4642 }
4643 }
4644
4645 public ISession openMachineSession(IMachine m) throws Exception
4646 {
4647 ISession s = getSessionObject();
4648 m.lockMachine(s, LockType.Shared);
4649 return s;
4650 }
4651
4652 public void closeMachineSession(ISession s)
4653 {
4654 if (s != null)
4655 s.unlockMachine();
4656 }
4657
4658 public static synchronized VirtualBoxManager createInstance(String home)
4659 {
4660 return new VirtualBoxManager();
4661 }
4662
4663 public IEventListener createListener(Object sink)
4664 {
4665 throw new VBoxException("no active listeners here");
4666 }
4667
4668 public void cleanup()
4669 {
4670 disconnect();
4671 deinitPerThread();
4672 }
4673
4674 public void waitForEvents(long tmo)
4675 {
4676 }
4677
4678 protected void finalize() throws Throwable
4679 {
4680 try
4681 {
4682 cleanup();
4683 }
4684 catch(Exception e)
4685 {
4686 }
4687 finally
4688 {
4689 super.finalize();
4690 }
4691 }
4692}
4693]]></xsl:text>
4694 </xsl:if>
4695
4696 <xsl:call-template name="endFile">
4697 <xsl:with-param name="file" select="'VirtualBoxManager.java'" />
4698 </xsl:call-template>
4699</xsl:template>
4700
4701
4702<xsl:template match="/">
4703
4704 <xsl:if test="not($G_vboxApiSuffix)">
4705 <xsl:call-template name="fatalError">
4706 <xsl:with-param name="msg" select="'G_vboxApiSuffix must be given'" />
4707 </xsl:call-template>
4708 </xsl:if>
4709
4710 <xsl:if test="not($filelistonly='')">
4711 <xsl:value-of select="concat($filelistonly, ' :=')"/>
4712 </xsl:if>
4713
4714 <!-- Handwritten files -->
4715 <xsl:call-template name="emitHandwritten"/>
4716
4717 <xsl:choose>
4718 <xsl:when test="$G_vboxGlueStyle='xpcom'">
4719 <xsl:call-template name="emitHandwrittenXpcom"/>
4720 </xsl:when>
4721
4722 <xsl:when test="$G_vboxGlueStyle='mscom'">
4723 <xsl:call-template name="emitHandwrittenMscom"/>
4724 </xsl:when>
4725
4726 <xsl:when test="$G_vboxGlueStyle='jaxws'">
4727 <xsl:call-template name="emitHandwrittenJaxws"/>
4728 </xsl:when>
4729
4730 <xsl:otherwise>
4731 <xsl:call-template name="fatalError">
4732 <xsl:with-param name="msg" select="'Style unknown (root)'" />
4733 </xsl:call-template>
4734 </xsl:otherwise>
4735 </xsl:choose>
4736
4737 <!-- Enums -->
4738 <xsl:for-each select="//enum">
4739 <xsl:call-template name="genEnum">
4740 <xsl:with-param name="enumname" select="@name" />
4741 <xsl:with-param name="filename" select="concat(@name, '.java')" />
4742 </xsl:call-template>
4743 </xsl:for-each>
4744
4745 <!-- Interfaces -->
4746 <xsl:for-each select="//interface">
4747 <xsl:variable name="self_target" select="current()/ancestor::if/@target"/>
4748 <xsl:variable name="module" select="current()/ancestor::module/@name"/>
4749
4750 <xsl:choose>
4751 <xsl:when test="$G_vboxGlueStyle='jaxws'">
4752 <xsl:if test="not($module) and not(@wsmap='suppress')">
4753 <xsl:call-template name="genIface">
4754 <xsl:with-param name="ifname" select="@name" />
4755 <xsl:with-param name="filename" select="concat(@name, '.java')" />
4756 </xsl:call-template>
4757 </xsl:if>
4758 </xsl:when>
4759
4760 <xsl:otherwise>
4761 <!-- We don't need WSDL-specific interfaces here -->
4762 <xsl:if test="not(@internal='yes') and not($self_target='wsdl') and not($module)">
4763 <xsl:call-template name="genIface">
4764 <xsl:with-param name="ifname" select="@name" />
4765 <xsl:with-param name="filename" select="concat(@name, '.java')" />
4766 </xsl:call-template>
4767 </xsl:if>
4768 </xsl:otherwise>
4769
4770 </xsl:choose>
4771 </xsl:for-each>
4772
4773 <xsl:if test="not($filelistonly='')">
4774 <xsl:value-of select="concat($G_sNewLine, $G_sNewLine)"/>
4775 </xsl:if>
4776
4777</xsl:template>
4778</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