VirtualBox

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

Last change on this file since 43446 was 43103, checked in by vboxsync, 12 years ago

whitespace/comment touchup

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