VirtualBox

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

Last change on this file since 98188 was 98108, checked in by vboxsync, 2 years ago

Manual (C) year updates.

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