VirtualBox

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

Last change on this file since 97024 was 96417, checked in by vboxsync, 2 years ago

more manual copyright and license notice fixing

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