VirtualBox

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

Last change on this file since 53390 was 53386, checked in by vboxsync, 10 years ago

glue-java.xsl: Fixed bug in string-trim where it was looking at the penultimate character instead of the last one.

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