VirtualBox

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

Last change on this file since 107044 was 106065, checked in by vboxsync, 2 months ago

Manual copyright year updates.

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