VirtualBox

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

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

glue-java.xsl: Don't end the file list with an escaped new line. (nit picking)

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