VirtualBox

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

最後變更 在這個檔案從46123是 46123,由 vboxsync 提交於 12 年 前

Main/VPX, VBoxManage: added IMachine::VideoCaptureScreens and IDisplay::{enableVideoCapture,disableVideoCapture}

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 139.3 KB
 
1<xsl:stylesheet version = '1.0'
2 xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
3 xmlns:vbox="http://www.alldomusa.eu.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-2013 Oracle Corporation
14
15 This file is part of VirtualBox Open Source Edition (OSE), as
16 available from http://www.alldomusa.eu.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="../idl/typemap-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-2013 Oracle Corporation
51 *
52 * This file is part of the VirtualBox SDK, as available from
53 * http://www.alldomusa.eu.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 typemap-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 <xsl:if test="($G_vboxGlueStyle != 'jaxws') or (@wsmap != 'suppress')">
1746 <!-- Emit getter -->
1747 <xsl:variable name="backgettername">
1748 <xsl:choose>
1749 <!-- Stupid, but backend boolean getters called isFoo(), not getFoo() -->
1750 <xsl:when test="$attrtype = 'boolean'">
1751 <xsl:variable name="capsname">
1752 <xsl:call-template name="capitalize">
1753 <xsl:with-param name="str" select="$attrname" />
1754 </xsl:call-template>
1755 </xsl:variable>
1756 <xsl:value-of select="concat('is', $capsname)" />
1757 </xsl:when>
1758 <xsl:otherwise>
1759 <xsl:call-template name="makeGetterName">
1760 <xsl:with-param name="attrname" select="$attrname" />
1761 </xsl:call-template>
1762 </xsl:otherwise>
1763 </xsl:choose>
1764 </xsl:variable>
1765
1766 <xsl:variable name="gluegettername">
1767 <xsl:call-template name="makeGetterName">
1768 <xsl:with-param name="attrname" select="$attrname" />
1769 </xsl:call-template>
1770 </xsl:variable>
1771
1772 <xsl:variable name="gluegettertype">
1773 <xsl:call-template name="typeIdl2Glue">
1774 <xsl:with-param name="type" select="$attrtype" />
1775 <xsl:with-param name="safearray" select="@safearray" />
1776 </xsl:call-template>
1777 </xsl:variable>
1778
1779 <xsl:variable name="backgettertype">
1780 <xsl:call-template name="typeIdl2Back">
1781 <xsl:with-param name="type" select="$attrtype" />
1782 <xsl:with-param name="safearray" select="@safearray" />
1783 </xsl:call-template>
1784 </xsl:variable>
1785
1786 <xsl:value-of select="concat(' public ', $gluegettertype, ' ', $gluegettername, '() {&#10;')" />
1787 <xsl:value-of select="concat(' ', $backgettertype, ' retVal = real.', $backgettername, '();&#10;')" />
1788 <xsl:variable name="wrapped">
1789 <xsl:call-template name="cookOutParam">
1790 <xsl:with-param name="value" select="'retVal'" />
1791 <xsl:with-param name="idltype" select="$attrtype" />
1792 <xsl:with-param name="safearray" select="@safearray" />
1793 </xsl:call-template>
1794 </xsl:variable>
1795 <xsl:value-of select="concat(' return ', $wrapped, ';&#10;')" />
1796 <xsl:value-of select=" ' }&#10;'" />
1797 </xsl:if>
1798
1799 </xsl:for-each>
1800
1801</xsl:template>
1802
1803<!-- Interface method wrapper -->
1804<xsl:template name="genMethod">
1805 <xsl:param name="ifname"/>
1806 <xsl:param name="methodname"/>
1807
1808 <xsl:choose>
1809 <xsl:when test="(param[@mod='ptr']) or (($G_vboxGlueStyle='jaxws') and (param[@type=($G_setSuppressedInterfaces/@name)]))" >
1810 <xsl:value-of select="concat(' // Skipping method ', $methodname, ' for it has parameters with suppressed types&#10;')" />
1811 </xsl:when>
1812 <xsl:when test="($G_vboxGlueStyle='jaxws') and (@wsmap = 'suppress')" >
1813 <xsl:value-of select="concat(' // Skipping method ', $methodname, ' for it is suppressed&#10;')" />
1814 </xsl:when>
1815 <xsl:otherwise>
1816 <xsl:variable name="hasReturnParms" select="param[@dir='return']" />
1817 <xsl:variable name="hasOutParms" select="param[@dir='out']" />
1818 <xsl:variable name="returnidltype" select="param[@dir='return']/@type" />
1819 <xsl:variable name="returnidlsafearray" select="param[@dir='return']/@safearray" />
1820 <xsl:variable name="returngluetype">
1821 <xsl:choose>
1822 <xsl:when test="$returnidltype">
1823 <xsl:call-template name="typeIdl2Glue">
1824 <xsl:with-param name="type" select="$returnidltype" />
1825 <xsl:with-param name="safearray" select="$returnidlsafearray" />
1826 </xsl:call-template>
1827 </xsl:when>
1828 <xsl:otherwise>
1829 <xsl:text>void</xsl:text>
1830 </xsl:otherwise>
1831 </xsl:choose>
1832 </xsl:variable>
1833 <xsl:variable name="retValValue">
1834 <xsl:choose>
1835 <xsl:when test="(param[@dir='out']) and ($G_vboxGlueStyle='jaxws')">
1836 <xsl:value-of select="'retVal.value'"/>
1837 </xsl:when>
1838 <xsl:otherwise>
1839 <xsl:value-of select="'retVal'"/>
1840 </xsl:otherwise>
1841 </xsl:choose>
1842 </xsl:variable>
1843 <xsl:apply-templates select="desc" mode="method"/>
1844 <xsl:value-of select="concat(' public ', $returngluetype, ' ', $methodname, '(')" />
1845 <xsl:variable name="paramsinout" select="param[@dir='in' or @dir='out']" />
1846 <xsl:for-each select="exsl:node-set($paramsinout)">
1847 <xsl:variable name="paramgluetype">
1848 <xsl:call-template name="typeIdl2Glue">
1849 <xsl:with-param name="type" select="@type" />
1850 <xsl:with-param name="safearray" select="@safearray" />
1851 </xsl:call-template>
1852 </xsl:variable>
1853 <xsl:choose>
1854 <xsl:when test="@dir='out'">
1855 <xsl:value-of select="concat('Holder&lt;', $paramgluetype, '&gt; ', @name)" />
1856 </xsl:when>
1857 <xsl:otherwise>
1858 <xsl:value-of select="concat($paramgluetype, ' ', @name)" />
1859 </xsl:otherwise>
1860 </xsl:choose>
1861 <xsl:if test="not(position()=last())">
1862 <xsl:value-of select="', '" />
1863 </xsl:if>
1864 </xsl:for-each>
1865 <xsl:value-of select="') {&#10;'"/>
1866
1867 <xsl:call-template name="startExcWrapper"/>
1868
1869 <!-- declare temp out params -->
1870 <xsl:for-each select="param[@dir='out']">
1871 <xsl:variable name="backouttype">
1872 <xsl:call-template name="typeIdl2Back">
1873 <xsl:with-param name="type" select="@type" />
1874 <xsl:with-param name="safearray" select="@safearray" />
1875 </xsl:call-template>
1876 </xsl:variable>
1877 <xsl:choose>
1878 <xsl:when test="$G_vboxGlueStyle='xpcom'">
1879 <xsl:value-of select="concat(' ', $backouttype, '[] tmp_', @name, ' = (', $backouttype, '[])java.lang.reflect.Array.newInstance(',$backouttype,'.class, 1);&#10;')"/>
1880 </xsl:when>
1881 <xsl:when test="$G_vboxGlueStyle='mscom'">
1882 <xsl:value-of select="concat(' Variant tmp_', @name, ' = new Variant();&#10;')"/>
1883 </xsl:when>
1884 <xsl:when test="$G_vboxGlueStyle='jaxws'">
1885 <xsl:value-of select="concat(' javax.xml.ws.Holder&lt;', $backouttype,'&gt; tmp_', @name, ' = new javax.xml.ws.Holder&lt;', $backouttype,'&gt;();&#10;')"/>
1886 </xsl:when>
1887 <xsl:otherwise>
1888 <xsl:call-template name="fatalError">
1889 <xsl:with-param name="msg" select="'Handle out param (genMethod)'" />
1890 </xsl:call-template>
1891 </xsl:otherwise>
1892 </xsl:choose>
1893 </xsl:for-each>
1894
1895 <!-- declare return param, if any -->
1896 <xsl:if test="$hasReturnParms">
1897 <xsl:variable name="backrettype">
1898 <xsl:call-template name="typeIdl2Back">
1899 <xsl:with-param name="type" select="$returnidltype" />
1900 <xsl:with-param name="safearray" select="$returnidlsafearray" />
1901 </xsl:call-template>
1902 </xsl:variable>
1903 <xsl:choose>
1904 <xsl:when test="(param[@dir='out']) and ($G_vboxGlueStyle='jaxws')">
1905 <xsl:value-of select="concat(' javax.xml.ws.Holder&lt;', $backrettype, '&gt;',
1906 ' retVal = new javax.xml.ws.Holder&lt;', $backrettype,
1907 '&gt;();&#10;')"/>
1908 </xsl:when>
1909 <xsl:otherwise>
1910 <xsl:value-of select="concat(' ', $backrettype, ' retVal;&#10;')"/>
1911 </xsl:otherwise>
1912 </xsl:choose>
1913 </xsl:if>
1914
1915 <!-- Method call -->
1916 <xsl:call-template name="genBackMethodCall">
1917 <xsl:with-param name="ifname" select="$ifname" />
1918 <xsl:with-param name="methodname" select="$methodname" />
1919 <xsl:with-param name="retval" select="'retVal'" />
1920 </xsl:call-template>
1921
1922 <!-- return out params -->
1923 <xsl:for-each select="param[@dir='out']">
1924 <xsl:variable name="varval">
1925 <xsl:choose>
1926 <xsl:when test="$G_vboxGlueStyle='xpcom'">
1927 <xsl:value-of select="concat('tmp_',@name,'[0]')" />
1928 </xsl:when>
1929 <xsl:when test="$G_vboxGlueStyle='mscom'">
1930 <xsl:value-of select="concat('tmp_',@name)" />
1931 </xsl:when>
1932 <xsl:when test="$G_vboxGlueStyle='jaxws'">
1933 <xsl:value-of select="concat('tmp_',@name,'.value')" />
1934 </xsl:when>
1935 <xsl:otherwise>
1936 <xsl:call-template name="fatalError">
1937 <xsl:with-param name="msg" select="'Style unknown (genMethod, outparam)'" />
1938 </xsl:call-template>
1939 </xsl:otherwise>
1940 </xsl:choose>
1941 </xsl:variable>
1942 <xsl:variable name="wrapped">
1943 <xsl:call-template name="cookOutParam">
1944 <xsl:with-param name="value" select="$varval" />
1945 <xsl:with-param name="idltype" select="@type" />
1946 <xsl:with-param name="safearray" select="@safearray" />
1947 </xsl:call-template>
1948 </xsl:variable>
1949 <xsl:value-of select="concat(' ', @name, '.value = ',$wrapped,';&#10;')"/>
1950 </xsl:for-each>
1951
1952 <xsl:if test="$hasReturnParms">
1953 <!-- actual 'return' statement -->
1954 <xsl:variable name="wrapped">
1955 <xsl:call-template name="cookOutParam">
1956 <xsl:with-param name="value" select="$retValValue" />
1957 <xsl:with-param name="idltype" select="$returnidltype" />
1958 <xsl:with-param name="safearray" select="$returnidlsafearray" />
1959 </xsl:call-template>
1960 </xsl:variable>
1961 <xsl:value-of select="concat(' return ', $wrapped, ';&#10;')" />
1962 </xsl:if>
1963 <xsl:call-template name="endExcWrapper"/>
1964
1965 <xsl:value-of select="' }&#10;'"/>
1966 </xsl:otherwise>
1967 </xsl:choose>
1968
1969</xsl:template>
1970
1971<!-- Callback interface method -->
1972<xsl:template name="genCbMethodDecl">
1973 <xsl:param name="ifname"/>
1974 <xsl:param name="methodname"/>
1975
1976 <xsl:choose>
1977 <xsl:when test="(param[@mod='ptr'])" >
1978 <xsl:value-of select="concat(' // Skipping method ', $methodname, ' for it has parameters with suppressed types&#10;')" />
1979 </xsl:when>
1980 <xsl:otherwise>
1981 <xsl:variable name="returnidltype" select="param[@dir='return']/@type" />
1982 <xsl:variable name="returnidlsafearray" select="param[@dir='return']/@safearray" />
1983 <xsl:variable name="returngluetype">
1984 <xsl:choose>
1985 <xsl:when test="$returnidltype">
1986 <xsl:call-template name="typeIdl2Glue">
1987 <xsl:with-param name="type" select="$returnidltype" />
1988 <xsl:with-param name="safearray" select="$returnidlsafearray" />
1989 </xsl:call-template>
1990 </xsl:when>
1991 <xsl:otherwise>
1992 <xsl:text>void</xsl:text>
1993 </xsl:otherwise>
1994 </xsl:choose>
1995 </xsl:variable>
1996 <xsl:value-of select="concat(' public ', $returngluetype, ' ', $methodname, '(')" />
1997 <xsl:variable name="paramsinout" select="param[@dir='in' or @dir='out']" />
1998 <xsl:for-each select="exsl:node-set($paramsinout)">
1999 <xsl:variable name="paramgluetype">
2000 <xsl:call-template name="typeIdl2Glue">
2001 <xsl:with-param name="type" select="@type" />
2002 <xsl:with-param name="safearray" select="@safearray" />
2003 </xsl:call-template>
2004 </xsl:variable>
2005 <xsl:choose>
2006 <xsl:when test="@dir='out'">
2007 <xsl:value-of select="concat('Holder&lt;', $paramgluetype, '&gt; ', @name)" />
2008 </xsl:when>
2009 <xsl:otherwise>
2010 <xsl:value-of select="concat($paramgluetype, ' ', @name)" />
2011 </xsl:otherwise>
2012 </xsl:choose>
2013 <xsl:if test="not(position()=last())">
2014 <xsl:text>, </xsl:text>
2015 </xsl:if>
2016 </xsl:for-each>
2017 <xsl:value-of select="');&#10;'"/>
2018 </xsl:otherwise>
2019 </xsl:choose>
2020</xsl:template>
2021
2022<!-- queryInterface wrapper -->
2023<xsl:template name="genQI">
2024 <xsl:param name="ifname"/>
2025 <xsl:param name="uuid" />
2026
2027 <xsl:value-of select="concat(' public static ', $ifname, ' queryInterface(IUnknown obj) {&#10;')" />
2028 <xsl:choose>
2029 <xsl:when test="$G_vboxGlueStyle='xpcom'">
2030 <xsl:variable name="backtype">
2031 <xsl:call-template name="typeIdl2Back">
2032 <xsl:with-param name="type" select="$ifname" />
2033 </xsl:call-template>
2034 </xsl:variable>
2035 <xsl:value-of select=" ' nsISupports nsobj = obj != null ? (nsISupports)obj.getWrapped() : null;&#10;'"/>
2036 <xsl:value-of select=" ' if (nsobj == null) return null;&#10;'"/>
2037 <xsl:value-of select="concat(' ',$backtype, ' qiobj = Helper.queryInterface(nsobj, &quot;{',$uuid,'}&quot;, ',$backtype,'.class);&#10;')" />
2038 <xsl:value-of select="concat(' return qiobj == null ? null : new ', $ifname, '(qiobj);&#10;')" />
2039 </xsl:when>
2040
2041 <xsl:when test="$G_vboxGlueStyle='mscom'">
2042 <xsl:value-of select="concat(' return', ' obj == null ? null : new ', $ifname, '((com.jacob.com.Dispatch)obj.getWrapped());&#10;')" />
2043 </xsl:when>
2044
2045 <xsl:when test="$G_vboxGlueStyle='jaxws'">
2046 <!-- bad, need to check that we really can be casted to this type -->
2047 <xsl:value-of select="concat(' return obj == null ? null : new ', $ifname, '(obj.getWrapped(), obj.getRemoteWSPort());&#10;')" />
2048 </xsl:when>
2049
2050 <xsl:otherwise>
2051 <xsl:call-template name="fatalError">
2052 <xsl:with-param name="msg" select="'Style unknown (genQI)'" />
2053 </xsl:call-template>
2054 </xsl:otherwise>
2055
2056 </xsl:choose>
2057 <xsl:value-of select=" ' }&#10;'" />
2058</xsl:template>
2059
2060
2061<xsl:template name="genCbMethodImpl">
2062 <xsl:param name="ifname"/>
2063 <xsl:param name="methodname"/>
2064
2065 <xsl:choose>
2066 <xsl:when test="(param[@mod='ptr'])" >
2067 <xsl:value-of select="concat(' // Skipping method ', $methodname, ' for it has parameters with suppressed types&#10;')" />
2068 </xsl:when>
2069 <xsl:otherwise>
2070 <xsl:variable name="hasReturnParms" select="param[@dir='return']" />
2071 <xsl:variable name="hasOutParms" select="param[@dir='out']" />
2072 <xsl:variable name="returnidltype" select="param[@dir='return']/@type" />
2073 <xsl:variable name="returnidlsafearray" select="param[@dir='return']/@safearray" />
2074 <xsl:variable name="returnbacktype">
2075 <xsl:choose>
2076 <xsl:when test="$returnidltype">
2077 <xsl:call-template name="typeIdl2Back">
2078 <xsl:with-param name="type" select="$returnidltype" />
2079 <xsl:with-param name="safearray" select="$returnidlsafearray" />
2080 </xsl:call-template>
2081 </xsl:when>
2082 <xsl:otherwise>
2083 <xsl:text>void</xsl:text>
2084 </xsl:otherwise>
2085 </xsl:choose>
2086 </xsl:variable>
2087 <xsl:variable name="paramsinout" select="param[@dir='in' or @dir='out']" />
2088 <xsl:choose>
2089 <xsl:when test="$G_vboxGlueStyle='xpcom'">
2090 <xsl:value-of select="concat(' public ', $returnbacktype, ' ', $methodname, '(')" />
2091 <xsl:for-each select="exsl:node-set($paramsinout)">
2092 <xsl:variable name="parambacktype">
2093 <xsl:call-template name="typeIdl2Back">
2094 <xsl:with-param name="type" select="@type" />
2095 <xsl:with-param name="safearray" select="@safearray" />
2096 </xsl:call-template>
2097 </xsl:variable>
2098 <xsl:choose>
2099 <xsl:when test="@dir='out'">
2100 <xsl:value-of select="concat($parambacktype, '[] ', @name)" />
2101 </xsl:when>
2102 <xsl:otherwise>
2103 <xsl:if test="@safearray">
2104 <xsl:value-of select="concat('long len_',@name,', ')" />
2105 </xsl:if>
2106 <xsl:value-of select="concat($parambacktype, ' ', @name)" />
2107 </xsl:otherwise>
2108 </xsl:choose>
2109 <xsl:if test="not(position()=last())">
2110 <xsl:text>, </xsl:text>
2111 </xsl:if>
2112 </xsl:for-each>
2113 <xsl:value-of select="') {&#10;'"/>
2114 </xsl:when>
2115
2116 <xsl:when test="$G_vboxGlueStyle='mscom'">
2117 <xsl:variable name="capsname">
2118 <xsl:call-template name="capitalize">
2119 <xsl:with-param name="str" select="$methodname" />
2120 </xsl:call-template>
2121 </xsl:variable>
2122 <xsl:value-of select="concat(' public ', $returnbacktype, ' ', $capsname, '(')" />
2123 <xsl:value-of select="'Variant _args[]'"/>
2124 <xsl:value-of select="') {&#10;'"/>
2125 <xsl:for-each select="exsl:node-set($paramsinout)">
2126 <xsl:variable name="parambacktype">
2127 <xsl:call-template name="typeIdl2Back">
2128 <xsl:with-param name="type" select="@type" />
2129 <xsl:with-param name="safearray" select="@safearray" />
2130 </xsl:call-template>
2131 </xsl:variable>
2132 <xsl:value-of select="concat(' ', $parambacktype, ' ', @name, '=_args[', count(preceding-sibling::param),'];&#10;')" />
2133 </xsl:for-each>
2134 </xsl:when>
2135
2136 <xsl:otherwise>
2137 <xsl:call-template name="fatalError">
2138 <xsl:with-param name="msg" select="'Style unknown (genSetterCall)'" />
2139 </xsl:call-template>
2140 </xsl:otherwise>
2141
2142 </xsl:choose>
2143
2144 <!-- declare temp out params -->
2145 <xsl:for-each select="param[@dir='out']">
2146 <xsl:variable name="glueouttype">
2147 <xsl:call-template name="typeIdl2Glue">
2148 <xsl:with-param name="type" select="@type" />
2149 <xsl:with-param name="safearray" select="@safearray" />
2150 </xsl:call-template>
2151 </xsl:variable>
2152 <xsl:value-of select="concat(' Holder&lt;', $glueouttype, '&gt; tmp_', @name, ' = new Holder&lt;', $glueouttype, '&gt;();&#10;')"/>
2153 </xsl:for-each>
2154
2155 <!-- declare return param, if any -->
2156 <xsl:if test="$hasReturnParms">
2157 <xsl:variable name="gluerettype">
2158 <xsl:call-template name="typeIdl2Glue">
2159 <xsl:with-param name="type" select="$returnidltype" />
2160 <xsl:with-param name="safearray" select="$returnidlsafearray" />
2161 </xsl:call-template>
2162 </xsl:variable>
2163 <xsl:value-of select="concat(' ', $gluerettype, ' retVal = &#10;')"/>
2164 </xsl:if>
2165
2166 <!-- Method call -->
2167 <xsl:value-of select="concat(' sink.', $methodname,'(')"/>
2168 <xsl:for-each select="param[not(@dir='return')]">
2169 <xsl:choose>
2170 <xsl:when test="@dir='out'">
2171 <xsl:value-of select="concat('tmp_', @name)" />
2172 </xsl:when>
2173 <xsl:when test="@dir='in'">
2174 <xsl:variable name="wrapped">
2175 <xsl:call-template name="cookOutParam">
2176 <xsl:with-param name="value" select="@name" />
2177 <xsl:with-param name="idltype" select="@type" />
2178 <xsl:with-param name="safearray" select="@safearray" />
2179 </xsl:call-template>
2180 </xsl:variable>
2181 <xsl:value-of select="$wrapped"/>
2182 </xsl:when>
2183 <xsl:otherwise>
2184 <xsl:call-template name="fatalError">
2185 <xsl:with-param name="msg" select="concat('Unsupported param dir: ', @dir, '&quot;.')" />
2186 </xsl:call-template>
2187 </xsl:otherwise>
2188 </xsl:choose>
2189 <xsl:if test="not(position()=last())">
2190 <xsl:value-of select="', '"/>
2191 </xsl:if>
2192 </xsl:for-each>
2193 <xsl:value-of select="');&#10;'"/>
2194
2195 <!-- return out params -->
2196 <xsl:for-each select="param[@dir='out']">
2197
2198 <xsl:variable name="unwrapped">
2199 <xsl:call-template name="cookInParam">
2200 <xsl:with-param name="value" select="concat('tmp_',@name,'.value')" />
2201 <xsl:with-param name="idltype" select="@type" />
2202 <xsl:with-param name="safearray" select="@safearray" />
2203 </xsl:call-template>
2204 </xsl:variable>
2205 <xsl:choose>
2206 <xsl:when test="$G_vboxGlueStyle='xpcom'">
2207 <xsl:value-of select="concat(' ', @name, '[0] = ',$unwrapped,';&#10;')"/>
2208 </xsl:when>
2209 <xsl:when test="$G_vboxGlueStyle='mscom'">
2210 <xsl:value-of select="concat(' _args[',count(preceding-sibling::param),'] = ',$unwrapped,';&#10;')"/>
2211 </xsl:when>
2212 </xsl:choose>
2213 </xsl:for-each>
2214
2215 <xsl:if test="$hasReturnParms">
2216 <!-- actual 'return' statement -->
2217 <xsl:variable name="unwrapped">
2218 <xsl:call-template name="cookInParam">
2219 <xsl:with-param name="value" select="'retVal'" />
2220 <xsl:with-param name="idltype" select="$returnidltype" />
2221 <xsl:with-param name="safearray" select="$returnidlsafearray" />
2222 </xsl:call-template>
2223 </xsl:variable>
2224 <xsl:value-of select="concat(' return ', $unwrapped, ';&#10;')" />
2225 </xsl:if>
2226 <xsl:value-of select="' }&#10;'"/>
2227 </xsl:otherwise>
2228 </xsl:choose>
2229</xsl:template>
2230
2231<!-- Interface method -->
2232<xsl:template name="genIfaceWrapper">
2233 <xsl:param name="ifname"/>
2234
2235 <xsl:variable name="wrappedType">
2236 <xsl:call-template name="wrappedName">
2237 <xsl:with-param name="ifname" select="$ifname" />
2238 </xsl:call-template>
2239 </xsl:variable>
2240
2241 <!-- Constructor -->
2242 <xsl:choose>
2243 <xsl:when test="($G_vboxGlueStyle='jaxws')">
2244 <xsl:value-of select="concat(' public ', $ifname, '(String wrapped, VboxPortType port) {&#10;')" />
2245 <xsl:value-of select=" ' super(wrapped, port);&#10;'"/>
2246 <xsl:value-of select=" ' }&#10;'"/>
2247 </xsl:when>
2248
2249 <xsl:when test="($G_vboxGlueStyle='xpcom') or ($G_vboxGlueStyle='mscom')">
2250 <xsl:value-of select="concat(' public ', $ifname, '(', $wrappedType,' wrapped) {&#10;')" />
2251 <xsl:value-of select=" ' super(wrapped);&#10;'"/>
2252 <xsl:value-of select=" ' }&#10;'"/>
2253
2254 <!-- Typed wrapped object accessor -->
2255 <xsl:value-of select="concat(' public ', $wrappedType, ' getTypedWrapped() {&#10;')" />
2256 <xsl:value-of select="concat(' return (', $wrappedType, ') getWrapped();&#10;')" />
2257 <xsl:value-of select=" ' }&#10;'" />
2258 </xsl:when>
2259
2260 <xsl:otherwise>
2261 <xsl:call-template name="fatalError">
2262 <xsl:with-param name="msg" select="'Style unknown (root, ctr)'" />
2263 </xsl:call-template>
2264 </xsl:otherwise>
2265 </xsl:choose>
2266 <!-- Attributes -->
2267 <xsl:for-each select="attribute[not(@mod='ptr')]">
2268 <xsl:variable name="attrname"><xsl:value-of select="@name" /></xsl:variable>
2269 <xsl:variable name="attrtype"><xsl:value-of select="@type" /></xsl:variable>
2270 <xsl:variable name="attrreadonly"><xsl:value-of select="@readonly" /></xsl:variable>
2271 <xsl:variable name="attrsafearray"><xsl:value-of select="@safearray" /></xsl:variable>
2272
2273 <xsl:choose>
2274 <xsl:when test="($G_vboxGlueStyle='jaxws') and ($attrtype=($G_setSuppressedInterfaces/@name))">
2275 <xsl:value-of select="concat(' // Skipping attribute ',$attrname, ' of suppressed type ', $attrtype, '&#10;&#10;')" />
2276 </xsl:when>
2277 <xsl:when test="($G_vboxGlueStyle='jaxws') and (@wsmap = 'suppress')" >
2278 <xsl:value-of select="concat(' // Skipping attribute ', $attrname, ' for it is suppressed&#10;')" />
2279 </xsl:when>
2280
2281 <xsl:otherwise>
2282 <!-- emit getter method -->
2283 <xsl:apply-templates select="desc" mode="attribute_get"/>
2284 <xsl:variable name="gettername">
2285 <xsl:call-template name="makeGetterName">
2286 <xsl:with-param name="attrname" select="$attrname" />
2287 </xsl:call-template>
2288 </xsl:variable>
2289 <xsl:variable name="gluetype">
2290 <xsl:call-template name="typeIdl2Glue">
2291 <xsl:with-param name="type" select="$attrtype" />
2292 <xsl:with-param name="safearray" select="@safearray" />
2293 </xsl:call-template>
2294 </xsl:variable>
2295 <xsl:variable name="backtype">
2296 <xsl:call-template name="typeIdl2Back">
2297 <xsl:with-param name="type" select="$attrtype" />
2298 <xsl:with-param name="safearray" select="@safearray" />
2299 </xsl:call-template>
2300 </xsl:variable>
2301 <xsl:variable name="wrapped">
2302 <xsl:call-template name="cookOutParam">
2303 <xsl:with-param name="value" select="'retVal'" />
2304 <xsl:with-param name="idltype" select="$attrtype" />
2305 <xsl:with-param name="safearray" select="@safearray" />
2306 </xsl:call-template>
2307 </xsl:variable>
2308 <xsl:value-of select="concat(' public ', $gluetype, ' ', $gettername, '() {&#10;')" />
2309
2310 <xsl:call-template name="startExcWrapper"/>
2311
2312 <!-- Actual getter implementation -->
2313 <xsl:call-template name="genGetterCall">
2314 <xsl:with-param name="ifname" select="$ifname" />
2315 <xsl:with-param name="gettername" select="$gettername" />
2316 <xsl:with-param name="backtype" select="$backtype" />
2317 <xsl:with-param name="retval" select="'retVal'" />
2318 </xsl:call-template>
2319
2320 <xsl:value-of select="concat(' return ', $wrapped, ';&#10;')" />
2321 <xsl:call-template name="endExcWrapper"/>
2322
2323 <xsl:value-of select= "' }&#10;'" />
2324 <xsl:if test="not(@readonly='yes')">
2325 <!-- emit setter method -->
2326 <xsl:apply-templates select="desc" mode="attribute_set"/>
2327 <xsl:variable name="settername"><xsl:call-template name="makeSetterName"><xsl:with-param name="attrname" select="$attrname" /></xsl:call-template></xsl:variable>
2328 <xsl:variable name="unwrapped">
2329 <xsl:call-template name="cookInParam">
2330 <xsl:with-param name="ifname" select="$ifname" />
2331 <xsl:with-param name="value" select="'value'" />
2332 <xsl:with-param name="idltype" select="$attrtype" />
2333 <xsl:with-param name="safearray" select="@safearray" />
2334 </xsl:call-template>
2335 </xsl:variable>
2336 <xsl:value-of select="concat(' public void ', $settername, '(', $gluetype, ' value) {&#10;')" />
2337 <xsl:call-template name="startExcWrapper"/>
2338 <!-- Actual setter implementation -->
2339 <xsl:call-template name="genSetterCall">
2340 <xsl:with-param name="ifname" select="$ifname" />
2341 <xsl:with-param name="settername" select="$settername" />
2342 <xsl:with-param name="value" select="$unwrapped" />
2343 </xsl:call-template>
2344 <xsl:call-template name="endExcWrapper"/>
2345 <xsl:value-of select= "' }&#10;'" />
2346 </xsl:if>
2347
2348 </xsl:otherwise>
2349 </xsl:choose>
2350
2351 </xsl:for-each>
2352
2353 <!-- emit queryInterface() *to* this class -->
2354 <xsl:call-template name="genQI">
2355 <xsl:with-param name="ifname" select="$ifname" />
2356 <xsl:with-param name="uuid" select="@uuid" />
2357 </xsl:call-template>
2358
2359 <!-- emit methods -->
2360 <xsl:for-each select="method">
2361 <xsl:call-template name="genMethod">
2362 <xsl:with-param name="ifname" select="$ifname" />
2363 <xsl:with-param name="methodname" select="@name" />
2364 </xsl:call-template>
2365 </xsl:for-each>
2366
2367</xsl:template>
2368
2369<xsl:template name="genIface">
2370 <xsl:param name="ifname" />
2371 <xsl:param name="filename" />
2372
2373 <xsl:variable name="wsmap" select="@wsmap" />
2374
2375 <xsl:call-template name="startFile">
2376 <xsl:with-param name="file" select="$filename" />
2377 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
2378 </xsl:call-template>
2379
2380 <xsl:text>import java.util.List;&#10;&#10;</xsl:text>
2381
2382 <xsl:apply-templates select="desc" mode="interface"/>
2383
2384 <xsl:choose>
2385 <xsl:when test="($wsmap='struct') and ($G_vboxGlueStyle='jaxws')">
2386 <xsl:value-of select="concat('public class ', $ifname, ' {&#10;&#10;')" />
2387 <xsl:call-template name="genStructWrapperJaxws">
2388 <xsl:with-param name="ifname" select="$ifname" />
2389 </xsl:call-template>
2390 </xsl:when>
2391
2392 <xsl:otherwise>
2393 <xsl:variable name="extends" select="//interface[@name=$ifname]/@extends" />
2394 <xsl:choose>
2395 <xsl:when test="($extends = '$unknown') or ($extends = '$dispatched') or ($extends = '$errorinfo')">
2396 <xsl:value-of select="concat('public class ', $ifname, ' extends IUnknown {&#10;&#10;')" />
2397 </xsl:when>
2398 <xsl:when test="//interface[@name=$extends]">
2399 <xsl:value-of select="concat('public class ', $ifname, ' extends ', $extends, ' {&#10;&#10;')" />
2400 </xsl:when>
2401 <xsl:otherwise>
2402 <xsl:call-template name="fatalError">
2403 <xsl:with-param name="msg" select="concat('Interface generation: interface &quot;', $ifname, '&quot; has invalid &quot;extends&quot; value ', $extends, '.')" />
2404 </xsl:call-template>
2405 </xsl:otherwise>
2406 </xsl:choose>
2407 <xsl:call-template name="genIfaceWrapper">
2408 <xsl:with-param name="ifname" select="$ifname" />
2409 </xsl:call-template>
2410 </xsl:otherwise>
2411 </xsl:choose>
2412
2413 <!-- end of class -->
2414 <xsl:value-of select="'}&#10;'" />
2415
2416 <xsl:call-template name="endFile">
2417 <xsl:with-param name="file" select="$filename" />
2418 </xsl:call-template>
2419
2420</xsl:template>
2421
2422<xsl:template name="genCb">
2423 <xsl:param name="ifname" />
2424 <xsl:param name="filename" />
2425 <xsl:param name="filenameimpl" />
2426
2427 <xsl:call-template name="startFile">
2428 <xsl:with-param name="file" select="$filename" />
2429 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
2430 </xsl:call-template>
2431
2432 <xsl:text>import java.util.List;&#10;</xsl:text>
2433
2434 <xsl:value-of select="concat('public interface ', $ifname, ' {&#10;')" />
2435
2436 <!-- emit methods declarations-->
2437 <xsl:for-each select="method">
2438 <xsl:call-template name="genCbMethodDecl">
2439 <xsl:with-param name="ifname" select="$ifname" />
2440 <xsl:with-param name="methodname" select="@name" />
2441 </xsl:call-template>
2442 </xsl:for-each>
2443
2444 <xsl:value-of select="'}&#10;&#10;'" />
2445
2446 <xsl:call-template name="endFile">
2447 <xsl:with-param name="file" select="$filename" />
2448 </xsl:call-template>
2449
2450 <xsl:call-template name="startFile">
2451 <xsl:with-param name="file" select="$filenameimpl" />
2452 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
2453 </xsl:call-template>
2454
2455 <xsl:text>import java.util.List;&#10;</xsl:text>
2456
2457 <xsl:variable name="backtype">
2458 <xsl:call-template name="typeIdl2Back">
2459 <xsl:with-param name="type" select="$ifname" />
2460 </xsl:call-template>
2461 </xsl:variable>
2462
2463 <!-- emit glue methods body -->
2464 <xsl:choose>
2465 <xsl:when test="$G_vboxGlueStyle='xpcom'">
2466 <xsl:value-of select="concat('class ', $ifname, 'Impl extends nsISupportsBase implements ', $backtype, ' {&#10;')" />
2467 </xsl:when>
2468
2469 <xsl:when test="$G_vboxGlueStyle='mscom'">
2470 <xsl:value-of select="concat('public class ', $ifname, 'Impl {&#10;')" />
2471 </xsl:when>
2472 </xsl:choose>
2473
2474 <xsl:value-of select="concat(' ', $ifname, ' sink;&#10;')" />
2475
2476 <xsl:value-of select="concat(' ', $ifname, 'Impl(', $ifname,' sink) {&#10;')" />
2477 <xsl:value-of select="' this.sink = sink;&#10;'" />
2478 <xsl:value-of select="' }&#10;'" />
2479
2480 <!-- emit methods implementations -->
2481 <xsl:for-each select="method">
2482 <xsl:call-template name="genCbMethodImpl">
2483 <xsl:with-param name="ifname" select="$ifname" />
2484 <xsl:with-param name="methodname" select="@name" />
2485 </xsl:call-template>
2486 </xsl:for-each>
2487
2488 <xsl:value-of select="'}&#10;&#10;'" />
2489
2490 <xsl:call-template name="endFile">
2491 <xsl:with-param name="file" select="$filenameimpl" />
2492 </xsl:call-template>
2493</xsl:template>
2494
2495<xsl:template name="emitHandwritten">
2496
2497<xsl:call-template name="startFile">
2498 <xsl:with-param name="file" select="'Holder.java'" />
2499 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
2500 </xsl:call-template>
2501
2502 <xsl:text><![CDATA[
2503public class Holder<T>
2504{
2505 public T value;
2506
2507 public Holder()
2508 {
2509 }
2510 public Holder(T value)
2511 {
2512 this.value = value;
2513 }
2514}
2515]]></xsl:text>
2516
2517 <xsl:call-template name="endFile">
2518 <xsl:with-param name="file" select="'Holder.java'" />
2519 </xsl:call-template>
2520
2521<xsl:call-template name="startFile">
2522 <xsl:with-param name="file" select="'VBoxException.java'" />
2523 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
2524 </xsl:call-template>
2525
2526 <xsl:text><![CDATA[
2527public class VBoxException extends RuntimeException
2528{
2529 private Throwable wrapped;
2530 private String msg;
2531
2532 public VBoxException(Throwable wrapped, String msg)
2533 {
2534 this.wrapped = wrapped;
2535 this.msg = msg;
2536 }
2537 public Throwable getWrapped()
2538 {
2539 return wrapped;
2540 }
2541 public String getMessage()
2542 {
2543 return msg;
2544 }
2545}
2546]]></xsl:text>
2547
2548 <xsl:call-template name="endFile">
2549 <xsl:with-param name="file" select="'VBoxException.java'" />
2550 </xsl:call-template>
2551
2552
2553</xsl:template>
2554
2555<xsl:template name="emitHandwrittenXpcom">
2556
2557<xsl:call-template name="startFile">
2558 <xsl:with-param name="file" select="'IUnknown.java'" />
2559 <xsl:with-param name="package" select="$G_virtualBoxPackageCom" />
2560 </xsl:call-template>
2561
2562 <xsl:text><![CDATA[
2563public class IUnknown
2564{
2565 private Object obj;
2566 public IUnknown(Object obj)
2567 {
2568 this.obj = obj;
2569 }
2570
2571 public Object getWrapped()
2572 {
2573 return this.obj;
2574 }
2575
2576 public void setWrapped(Object obj)
2577 {
2578 this.obj = obj;
2579 }
2580}
2581]]></xsl:text>
2582
2583 <xsl:call-template name="endFile">
2584 <xsl:with-param name="file" select="'IUnknown.java'" />
2585 </xsl:call-template>
2586
2587 <xsl:call-template name="startFile">
2588 <xsl:with-param name="file" select="'Helper.java'" />
2589 <xsl:with-param name="package" select="$G_virtualBoxPackageCom" />
2590 </xsl:call-template>
2591
2592<xsl:text><![CDATA[
2593
2594import java.util.List;
2595import java.util.ArrayList;
2596import java.util.Collections;
2597import java.lang.reflect.Array;
2598import java.lang.reflect.Constructor;
2599import java.lang.reflect.InvocationTargetException;
2600
2601public class Helper {
2602 public static List<Short> wrap(byte[] vals) {
2603 if (vals==null)
2604 return null;
2605
2606 List<Short> ret = new ArrayList<Short>(vals.length);
2607 for (short v : vals) {
2608 ret.add(v);
2609 }
2610 return ret;
2611 }
2612
2613 public static List<Integer> wrap(int[] vals) {
2614 if (vals==null)
2615 return null;
2616
2617 List<Integer> ret = new ArrayList<Integer>(vals.length);
2618 for (int v : vals) {
2619 ret.add(v);
2620 }
2621 return ret;
2622 }
2623
2624 public static List<Long> wrap(long[] vals) {
2625 if (vals==null)
2626 return null;
2627
2628 List<Long> ret = new ArrayList<Long>(vals.length);
2629 for (long v : vals) {
2630 ret.add(v);
2631 }
2632 return ret;
2633 }
2634
2635 public static List<Boolean> wrap(boolean[] vals) {
2636 if (vals==null)
2637 return null;
2638
2639 List<Boolean> ret = new ArrayList<Boolean>(vals.length);
2640 for (boolean v: vals) {
2641 ret.add(v);
2642 }
2643 return ret;
2644 }
2645
2646 public static List<String> wrap(String[] vals) {
2647 if (vals==null)
2648 return null;
2649 List<String> ret = new ArrayList<String>(vals.length);
2650 for (String v : vals) {
2651 ret.add(v);
2652 }
2653 return ret;
2654 }
2655
2656 public static <T> List<T> wrap(Class<T> wrapperClass, T[] thisPtrs) {
2657 if (thisPtrs==null)
2658 return null;
2659
2660 List<T> ret = new ArrayList<T>(thisPtrs.length);
2661 for (T thisPtr : thisPtrs) {
2662 ret.add(thisPtr);
2663 }
2664 return ret;
2665 }
2666
2667 public static <T> List<T> wrapEnum(Class<T> wrapperClass, long values[]) {
2668 try {
2669 if (values==null)
2670 return null;
2671 Constructor<T> c = wrapperClass.getConstructor(int.class);
2672 List<T> ret = new ArrayList<T>(values.length);
2673 for (long v : values) {
2674 ret.add(c.newInstance(v));
2675 }
2676 return ret;
2677 } catch (NoSuchMethodException e) {
2678 throw new AssertionError(e);
2679 } catch (InstantiationException e) {
2680 throw new AssertionError(e);
2681 } catch (IllegalAccessException e) {
2682 throw new AssertionError(e);
2683 } catch (InvocationTargetException e) {
2684 throw new AssertionError(e);
2685 }
2686 }
2687 public static short[] unwrapUShort(List<Short> vals) {
2688 if (vals==null)
2689 return null;
2690
2691 short[] ret = new short[vals.size()];
2692 int i = 0;
2693 for (short l : vals) {
2694 ret[i++] = l;
2695 }
2696 return ret;
2697 }
2698
2699 public static int[] unwrapInteger(List<Integer> vals) {
2700 if (vals == null)
2701 return null;
2702
2703 int[] ret = new int[vals.size()];
2704 int i = 0;
2705 for (int l : vals) {
2706 ret[i++] = l;
2707 }
2708 return ret;
2709 }
2710
2711 public static long[] unwrapULong(List<Long> vals) {
2712 if (vals == null)
2713 return null;
2714
2715 long[] ret = new long[vals.size()];
2716 int i = 0;
2717 for (long l : vals) {
2718 ret[i++] = l;
2719 }
2720 return ret;
2721 }
2722
2723 public static boolean[] unwrapBoolean(List<Boolean> vals) {
2724 if (vals==null)
2725 return null;
2726
2727 boolean[] ret = new boolean[vals.size()];
2728 int i = 0;
2729 for (boolean l : vals) {
2730 ret[i++] = l;
2731 }
2732 return ret;
2733 }
2734
2735 public static String[] unwrapStr(List<String> vals) {
2736 if (vals==null)
2737 return null;
2738
2739 String[] ret = new String[vals.size()];
2740 int i = 0;
2741 for (String l : vals) {
2742 ret[i++] = l;
2743 }
2744 return ret;
2745 }
2746
2747 public static <T extends Enum <T>> long[] unwrapEnum(Class<T> enumClass, List<T> values) {
2748 if (values == null) return null;
2749
2750 long result[] = new long[values.size()];
2751 try {
2752 java.lang.reflect.Method valueM = enumClass.getMethod("value");
2753 int i = 0;
2754 for (T v : values) {
2755 result[i++] = (Integer)valueM.invoke(v);
2756 }
2757 return result;
2758 } catch (NoSuchMethodException e) {
2759 throw new AssertionError(e);
2760 } catch(SecurityException e) {
2761 throw new AssertionError(e);
2762 } catch (IllegalAccessException e) {
2763 throw new AssertionError(e);
2764 } catch (IllegalArgumentException e) {
2765 throw new AssertionError(e);
2766 } catch (InvocationTargetException e) {
2767 throw new AssertionError(e);
2768 }
2769 }
2770
2771 public static <T1, T2> List<T1> wrap2(Class<T1> wrapperClass1, Class<T2> wrapperClass2, T2[] thisPtrs) {
2772 try {
2773 if (thisPtrs==null)
2774 return null;
2775
2776 Constructor<T1> c = wrapperClass1.getConstructor(wrapperClass2);
2777 List<T1> ret = new ArrayList<T1>(thisPtrs.length);
2778 for (T2 thisPtr : thisPtrs) {
2779 ret.add(c.newInstance(thisPtr));
2780 }
2781 return ret;
2782 } catch (NoSuchMethodException e) {
2783 throw new AssertionError(e);
2784 } catch (InstantiationException e) {
2785 throw new AssertionError(e);
2786 } catch (IllegalAccessException e) {
2787 throw new AssertionError(e);
2788 } catch (InvocationTargetException e) {
2789 throw new AssertionError(e);
2790 }
2791 }
2792
2793 @SuppressWarnings( "unchecked")
2794 public static <T> T[] unwrap(Class<T> wrapperClass, List<T> thisPtrs)
2795 {
2796 if (thisPtrs==null)
2797 return null;
2798 if (thisPtrs.size() == 0)
2799 return null;
2800 return (T[])thisPtrs.toArray((T[])Array.newInstance(wrapperClass, thisPtrs.size()));
2801 }
2802
2803 @SuppressWarnings( "unchecked" )
2804 public static <T> T queryInterface(Object obj, String uuid, Class<T> iface)
2805 {
2806 return (T)queryInterface(obj, uuid);
2807 }
2808
2809 public static Object queryInterface(Object obj, String uuid)
2810 {
2811 try {
2812 /* Kind of ugly, but does the job of casting */
2813 org.mozilla.xpcom.Mozilla moz = org.mozilla.xpcom.Mozilla.getInstance();
2814 long xpobj = moz.wrapJavaObject(obj, uuid);
2815 return moz.wrapXPCOMObject(xpobj, uuid);
2816 } catch (Exception e) {
2817 return null;
2818 }
2819 }
2820
2821 @SuppressWarnings("unchecked")
2822 public static <T1 extends IUnknown,T2> T2[] unwrap2(Class<T1> wrapperClass1, Class<T2> wrapperClass2, List<T1> thisPtrs)
2823 {
2824 if (thisPtrs==null) return null;
2825
2826 T2 ret[] = (T2[])Array.newInstance(wrapperClass2, thisPtrs.size());
2827 int i = 0;
2828 for (T1 obj : thisPtrs) {
2829 ret[i++] = (T2)obj.getWrapped();
2830 }
2831 return ret;
2832 }
2833}
2834]]></xsl:text>
2835
2836 <xsl:call-template name="endFile">
2837 <xsl:with-param name="file" select="'Helper.java'" />
2838 </xsl:call-template>
2839
2840 <xsl:call-template name="startFile">
2841 <xsl:with-param name="file" select="'VirtualBoxManager.java'" />
2842 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
2843 </xsl:call-template>
2844
2845 <xsl:text><![CDATA[
2846
2847import java.io.File;
2848
2849import org.mozilla.xpcom.*;
2850import org.mozilla.interfaces.*;
2851
2852public class VirtualBoxManager
2853{
2854 private Mozilla mozilla;
2855 private IVirtualBox vbox;
2856 private nsIComponentManager componentManager;
2857
2858 private VirtualBoxManager(Mozilla mozilla)
2859 {
2860 this.mozilla = mozilla;
2861 this.componentManager = mozilla.getComponentManager();
2862 this.vbox = new IVirtualBox((org.mozilla.interfaces.IVirtualBox) this.componentManager
2863 .createInstanceByContractID("@virtualbox.org/VirtualBox;1",
2864 null,
2865 org.mozilla.interfaces.IVirtualBox.IVIRTUALBOX_IID));
2866 }
2867
2868 public void connect(String url, String username, String passwd)
2869 {
2870 throw new RuntimeException("Connect doesn't make sense for local bindings");
2871 }
2872
2873 public void disconnect()
2874 {
2875 throw new RuntimeException("Disconnect doesn't make sense for local bindings");
2876 }
2877
2878 public static void initPerThread()
2879 {
2880 }
2881
2882 public static void deinitPerThread()
2883 {
2884 }
2885
2886 public IVirtualBox getVBox()
2887 {
2888 return this.vbox;
2889 }
2890
2891 public ISession getSessionObject()
2892 {
2893 return new ISession((org.mozilla.interfaces.ISession) componentManager
2894 .createInstanceByContractID("@virtualbox.org/Session;1", null,
2895 org.mozilla.interfaces.ISession.ISESSION_IID));
2896 }
2897
2898 public ISession openMachineSession(IMachine m) throws Exception
2899 {
2900 ISession s = getSessionObject();
2901 m.lockMachine(s, LockType.Shared);
2902 return s;
2903 }
2904
2905 public void closeMachineSession(ISession s)
2906 {
2907 if (s != null)
2908 s.unlockMachine();
2909 }
2910
2911 private static boolean hasInstance = false;
2912 private static boolean isMozillaInited = false;
2913
2914 public static synchronized VirtualBoxManager createInstance(String home)
2915 {
2916 if (hasInstance)
2917 throw new VBoxException(null, "only one instance at the time allowed");
2918 if (home == null || "".equals(home))
2919 home = System.getProperty("vbox.home");
2920
2921 if (home == null)
2922 throw new RuntimeException("vbox.home Java property must be defined to use XPCOM bridge");
2923
2924 File grePath = new File(home);
2925
2926 Mozilla mozilla = Mozilla.getInstance();
2927 if (!isMozillaInited)
2928 {
2929 mozilla.initialize(grePath);
2930 try {
2931 mozilla.initXPCOM(grePath, null);
2932 isMozillaInited = true;
2933 } catch (Exception e) {
2934 e.printStackTrace();
2935 return null;
2936 }
2937 }
2938
2939 hasInstance = true;
2940
2941 return new VirtualBoxManager(mozilla);
2942 }
2943
2944 public IEventListener createListener(Object sink)
2945 {
2946 return new IEventListener(new EventListenerImpl(sink));
2947 }
2948 public void cleanup()
2949 {
2950 deinitPerThread();
2951 // cleanup, we don't do that, as XPCOM bridge doesn't cleanly
2952 // shuts down, so we prefer to avoid native shutdown
2953 // mozilla.shutdownXPCOM(null);
2954 mozilla = null;
2955 hasInstance = false;
2956 }
2957
2958 public boolean progressBar(IProgress p, int wait)
2959 {
2960 long end = System.currentTimeMillis() + wait;
2961 while (!p.getCompleted())
2962 {
2963 mozilla.waitForEvents(0);
2964 p.waitForCompletion(wait);
2965 if (System.currentTimeMillis() >= end)
2966 return false;
2967 }
2968
2969 return true;
2970 }
2971
2972 public boolean startVm(String name, String type, int timeout)
2973 {
2974 IMachine m = vbox.findMachine(name);
2975 if (m == null)
2976 return false;
2977 ISession session = getSessionObject();
2978
2979 if (type == null)
2980 type = "gui";
2981 IProgress p = m.launchVMProcess(session, type, "");
2982 progressBar(p, timeout);
2983 session.unlockMachine();
2984 return true;
2985 }
2986
2987 public void waitForEvents(long tmo)
2988 {
2989 mozilla.waitForEvents(tmo);
2990 }
2991}
2992]]></xsl:text>
2993
2994 <xsl:call-template name="endFile">
2995 <xsl:with-param name="file" select="'VirtualBoxManager.java'" />
2996 </xsl:call-template>
2997
2998 <xsl:call-template name="startFile">
2999 <xsl:with-param name="file" select="'EventListenerImpl.java'" />
3000 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
3001 </xsl:call-template>
3002
3003 <xsl:text><![CDATA[
3004 import org.mozilla.interfaces.*;
3005
3006 public class EventListenerImpl extends nsISupportsBase implements org.mozilla.interfaces.IEventListener
3007 {
3008 private Object obj;
3009 private java.lang.reflect.Method handleEvent;
3010 EventListenerImpl(Object obj)
3011 {
3012 this.obj = obj;
3013 try {
3014 this.handleEvent = obj.getClass().getMethod("handleEvent", IEvent.class);
3015 } catch (Exception e) {
3016 e.printStackTrace();
3017 }
3018 }
3019 public void handleEvent(org.mozilla.interfaces.IEvent ev)
3020 {
3021 try {
3022 if (obj != null && handleEvent != null)
3023 handleEvent.invoke(obj, ev != null ? new IEvent(ev) : null);
3024 } catch (Exception e) {
3025 e.printStackTrace();
3026 }
3027 }
3028 }]]></xsl:text>
3029
3030 <xsl:call-template name="endFile">
3031 <xsl:with-param name="file" select="'EventListenerImpl.java'" />
3032 </xsl:call-template>
3033
3034 <xsl:call-template name="startFile">
3035 <xsl:with-param name="file" select="'VBoxObjectBase.java'" />
3036 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
3037 </xsl:call-template>
3038
3039<xsl:text><![CDATA[
3040abstract class nsISupportsBase implements org.mozilla.interfaces.nsISupports
3041{
3042 public org.mozilla.interfaces.nsISupports queryInterface(String iid)
3043 {
3044 return org.mozilla.xpcom.Mozilla.queryInterface(this, iid);
3045 }
3046}
3047
3048]]></xsl:text><xsl:call-template name="endFile">
3049 <xsl:with-param name="file" select="'VBoxObjectBase.java'" />
3050 </xsl:call-template>
3051
3052</xsl:template>
3053
3054
3055<xsl:template name="emitHandwrittenMscom">
3056
3057<xsl:call-template name="startFile">
3058 <xsl:with-param name="file" select="'IUnknown.java'" />
3059 <xsl:with-param name="package" select="$G_virtualBoxPackageCom" />
3060 </xsl:call-template>
3061
3062 <xsl:text><![CDATA[
3063public class IUnknown
3064{
3065 private Object obj;
3066 public IUnknown(Object obj)
3067 {
3068 this.obj = obj;
3069 }
3070
3071 public Object getWrapped()
3072 {
3073 return this.obj;
3074 }
3075
3076 public void setWrapped(Object obj)
3077 {
3078 this.obj = obj;
3079 }
3080}
3081]]></xsl:text>
3082
3083 <xsl:call-template name="endFile">
3084 <xsl:with-param name="file" select="'IUnknown.java'" />
3085 </xsl:call-template>
3086
3087<xsl:call-template name="startFile">
3088 <xsl:with-param name="file" select="'Helper.java'" />
3089 <xsl:with-param name="package" select="$G_virtualBoxPackageCom" />
3090 </xsl:call-template>
3091
3092<xsl:text><![CDATA[
3093
3094import java.util.List;
3095import java.util.ArrayList;
3096import java.util.Collections;
3097import java.lang.reflect.Array;
3098import java.lang.reflect.Constructor;
3099import java.lang.reflect.InvocationTargetException;
3100import com.jacob.com.*;
3101
3102public class Helper {
3103 public static List<Short> wrap(short[] vals) {
3104 if (vals==null) return null;
3105 if (vals.length == 0) return Collections.emptyList();
3106
3107 List<Short> ret = new ArrayList<Short>(vals.length);
3108 for (short v : vals) {
3109 ret.add(v);
3110 }
3111 return ret;
3112 }
3113
3114 public static List<Integer> wrap(int[] vals) {
3115 if (vals == null) return null;
3116 if (vals.length == 0) return Collections.emptyList();
3117
3118 List<Integer> ret = new ArrayList<Integer>(vals.length);
3119 for (int v : vals) {
3120 ret.add(v);
3121 }
3122 return ret;
3123 }
3124
3125 public static List<Long> wrap(long[] vals) {
3126 if (vals==null) return null;
3127 if (vals.length == 0) return Collections.emptyList();
3128
3129 List<Long> ret = new ArrayList<Long>(vals.length);
3130 for (long v : vals) {
3131 ret.add(v);
3132 }
3133 return ret;
3134 }
3135
3136 public static List<String> wrap(String[] vals) {
3137 if (vals==null) return null;
3138 if (vals.length == 0) return Collections.emptyList();
3139
3140 List<String> ret = new ArrayList<String>(vals.length);
3141 for (String v : vals) {
3142 ret.add(v);
3143 }
3144 return ret;
3145 }
3146
3147 public static <T> T wrapDispatch(Class<T> wrapperClass, Dispatch d)
3148 {
3149 try {
3150 if (d == null || d.m_pDispatch == 0)
3151 return null;
3152 Constructor<T> c = wrapperClass.getConstructor(Dispatch.class);
3153 return (T)c.newInstance(d);
3154 } catch (NoSuchMethodException e) {
3155 throw new AssertionError(e);
3156 } catch (InstantiationException e) {
3157 throw new AssertionError(e);
3158 } catch (IllegalAccessException e) {
3159 throw new AssertionError(e);
3160 } catch (InvocationTargetException e) {
3161 throw new AssertionError(e);
3162 }
3163 }
3164
3165 @SuppressWarnings("unchecked")
3166 public static <T> Object wrapVariant(Class<T> wrapperClass, Variant v)
3167 {
3168 if (v == null)
3169 return null;
3170
3171 short vt = v.getvt();
3172 switch (vt)
3173 {
3174 case Variant.VariantNull:
3175 return null;
3176 case Variant.VariantBoolean:
3177 return v.getBoolean();
3178 case Variant.VariantByte:
3179 return v.getByte();
3180 case Variant.VariantShort:
3181 return v.getShort();
3182 case Variant.VariantInt:
3183 return v.getInt();
3184 case Variant.VariantLongInt:
3185 return v.getLong();
3186 case Variant.VariantString:
3187 return v.getString();
3188 case Variant.VariantDispatch:
3189 return wrapDispatch(wrapperClass, v.getDispatch());
3190 default:
3191 throw new RuntimeException("unhandled variant type "+vt);
3192 }
3193 }
3194
3195 public static byte[] wrapBytes(SafeArray sa) {
3196 if (sa==null) return null;
3197
3198 int saLen = sa.getUBound() - sa.getLBound() + 1;
3199
3200 byte[] ret = new byte[saLen];
3201 int j = 0;
3202 for (int i = sa.getLBound(); i <= sa.getUBound(); i++)
3203 {
3204 Variant v = sa.getVariant(i);
3205 // come upo with more effective approach!!!
3206 ret[j++] = v.getByte();
3207 }
3208 return ret;
3209 }
3210
3211 @SuppressWarnings("unchecked")
3212 public static <T> List<T> wrap(Class<T> wrapperClass, SafeArray sa) {
3213 if (sa==null) return null;
3214
3215 int saLen = sa.getUBound() - sa.getLBound() + 1;
3216 if (saLen == 0) return Collections.emptyList();
3217
3218 List<T> ret = new ArrayList<T>(saLen);
3219 for (int i = sa.getLBound(); i <= sa.getUBound(); i++)
3220 {
3221 Variant v = sa.getVariant(i);
3222 ret.add((T)wrapVariant(wrapperClass, v));
3223 }
3224 return ret;
3225 }
3226
3227 public static <T> List<T> wrapEnum(Class<T> wrapperClass, SafeArray sa) {
3228 try {
3229 if (sa==null) return null;
3230
3231 int saLen = sa.getUBound() - sa.getLBound() + 1;
3232 if (saLen == 0) return Collections.emptyList();
3233 List<T> ret = new ArrayList<T>(saLen);
3234 Constructor<T> c = wrapperClass.getConstructor(int.class);
3235 for (int i = sa.getLBound(); i <= sa.getUBound(); i++)
3236 {
3237 Variant v = sa.getVariant(i);
3238 ret.add(c.newInstance(v.getInt()));
3239 }
3240 return ret;
3241 } catch (NoSuchMethodException e) {
3242 throw new AssertionError(e);
3243 } catch (InstantiationException e) {
3244 throw new AssertionError(e);
3245 } catch (IllegalAccessException e) {
3246 throw new AssertionError(e);
3247 } catch (InvocationTargetException e) {
3248 throw new AssertionError(e);
3249 }
3250 }
3251
3252 public static SafeArray unwrapInt(List<Integer> vals) {
3253 if (vals==null) return null;
3254 SafeArray ret = new SafeArray(Variant.VariantInt, vals.size());
3255 int i = 0;
3256 for (int l : vals) {
3257 ret.setInt(i++, l);
3258 }
3259 return ret;
3260 }
3261
3262 public static SafeArray unwrapLong(List<Long> vals) {
3263 if (vals==null) return null;
3264 SafeArray ret = new SafeArray(Variant.VariantLongInt, vals.size());
3265 int i = 0;
3266 for (long l : vals) {
3267 ret.setLong(i++, l);
3268 }
3269 return ret;
3270 }
3271
3272 public static SafeArray unwrapBool(List<Boolean> vals) {
3273 if (vals==null) return null;
3274
3275 SafeArray result = new SafeArray(Variant.VariantBoolean, vals.size());
3276 int i = 0;
3277 for (boolean l : vals) {
3278 result.setBoolean(i++, l);
3279 }
3280 return result;
3281 }
3282
3283
3284 public static SafeArray unwrapBytes(byte[] vals) {
3285 if (vals==null) return null;
3286
3287 SafeArray result = new SafeArray(Variant.VariantByte, vals.length);
3288 int i = 0;
3289 for (byte l : vals) {
3290 result.setByte(i++, l);
3291 }
3292 return result;
3293 }
3294
3295
3296 public static <T extends Enum <T>> SafeArray unwrapEnum(Class<T> enumClass, List<T> values) {
3297 if (values == null) return null;
3298
3299 SafeArray result = new SafeArray(Variant.VariantInt, values.size());
3300 try {
3301 java.lang.reflect.Method valueM = enumClass.getMethod("value");
3302 int i = 0;
3303 for (T v : values) {
3304 result.setInt(i++, (Integer)valueM.invoke(v));
3305 }
3306 return result;
3307 } catch (NoSuchMethodException e) {
3308 throw new AssertionError(e);
3309 } catch(SecurityException e) {
3310 throw new AssertionError(e);
3311 } catch (IllegalAccessException e) {
3312 throw new AssertionError(e);
3313 } catch (IllegalArgumentException e) {
3314 throw new AssertionError(e);
3315 } catch (InvocationTargetException e) {
3316 throw new AssertionError(e);
3317 }
3318 }
3319 public static SafeArray unwrapString(List<String> vals) {
3320 if (vals==null)
3321 return null;
3322 SafeArray result = new SafeArray(Variant.VariantString, vals.size());
3323 int i = 0;
3324 for (String l : vals) {
3325 result.setString(i++, l);
3326 }
3327 return result;
3328 }
3329
3330 public static <T1, T2> List<T1> wrap2(Class<T1> wrapperClass1, Class<T2> wrapperClass2, T2[] thisPtrs) {
3331 try {
3332 if (thisPtrs==null) return null;
3333 if (thisPtrs.length == 0) return Collections.emptyList();
3334
3335 Constructor<T1> c = wrapperClass1.getConstructor(wrapperClass2);
3336 List<T1> ret = new ArrayList<T1>(thisPtrs.length);
3337 for (T2 thisPtr : thisPtrs) {
3338 ret.add(c.newInstance(thisPtr));
3339 }
3340 return ret;
3341 } catch (NoSuchMethodException e) {
3342 throw new AssertionError(e);
3343 } catch (InstantiationException e) {
3344 throw new AssertionError(e);
3345 } catch (IllegalAccessException e) {
3346 throw new AssertionError(e);
3347 } catch (InvocationTargetException e) {
3348 throw new AssertionError(e);
3349 }
3350 }
3351
3352 @SuppressWarnings("unchecked")
3353 public static <T> T[] unwrap(Class<T> wrapperClass, List<T> thisPtrs) {
3354 if (thisPtrs==null) return null;
3355 return (T[])thisPtrs.toArray((T[])Array.newInstance(wrapperClass, thisPtrs.size()));
3356 }
3357
3358 @SuppressWarnings("unchecked")
3359 public static <T1 extends IUnknown,T2> T2[] unwrap2(Class<T1> wrapperClass1, Class<T2> wrapperClass2, List<T1> thisPtrs) {
3360 if (thisPtrs==null) return null;
3361
3362 T2 ret[] = (T2[])Array.newInstance(wrapperClass2, thisPtrs.size());
3363 int i = 0;
3364 for (T1 obj : thisPtrs) {
3365 ret[i++] = (T2)obj.getWrapped();
3366 }
3367 return ret;
3368 }
3369
3370 /* We have very long invoke lists sometimes */
3371 public static Variant invoke(Dispatch d, String method, Object ... args)
3372 {
3373 return Dispatch.callN(d, method, args);
3374 }
3375}
3376]]></xsl:text>
3377
3378 <xsl:call-template name="endFile">
3379 <xsl:with-param name="file" select="'Helper.java'" />
3380 </xsl:call-template>
3381
3382
3383 <xsl:call-template name="startFile">
3384 <xsl:with-param name="file" select="'VirtualBoxManager.java'" />
3385 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
3386 </xsl:call-template>
3387
3388 <xsl:text><![CDATA[
3389
3390import com.jacob.activeX.ActiveXComponent;
3391import com.jacob.com.ComThread;
3392import com.jacob.com.Dispatch;
3393import com.jacob.com.Variant;
3394import com.jacob.com.SafeArray;
3395import com.jacob.com.DispatchEvents;
3396
3397public class VirtualBoxManager
3398{
3399 private IVirtualBox vbox;
3400
3401 private VirtualBoxManager()
3402 {
3403 initPerThread();
3404 vbox = new IVirtualBox(new ActiveXComponent("VirtualBox.VirtualBox"));
3405 }
3406
3407 public static void initPerThread()
3408 {
3409 ComThread.InitMTA();
3410 }
3411
3412 public static void deinitPerThread()
3413 {
3414 ComThread.Release();
3415 }
3416
3417 public void connect(String url, String username, String passwd)
3418 {
3419 throw new RuntimeException("Connect doesn't make sense for local bindings");
3420 }
3421
3422 public void disconnect()
3423 {
3424 throw new RuntimeException("Disconnect doesn't make sense for local bindings");
3425 }
3426
3427 public IVirtualBox getVBox()
3428 {
3429 return this.vbox;
3430 }
3431
3432 public ISession getSessionObject()
3433 {
3434 return new ISession(new ActiveXComponent("VirtualBox.Session"));
3435 }
3436
3437 public ISession openMachineSession(IMachine m)
3438 {
3439 ISession s = getSessionObject();
3440 m.lockMachine(s, LockType.Shared);
3441 return s;
3442 }
3443
3444 public void closeMachineSession(ISession s)
3445 {
3446 if (s != null)
3447 s.unlockMachine();
3448 }
3449
3450 private static boolean hasInstance = false;
3451
3452 public static synchronized VirtualBoxManager createInstance(String home)
3453 {
3454 if (hasInstance)
3455 throw new VBoxException(null, "only one instance at the time allowed");
3456
3457 hasInstance = true;
3458 return new VirtualBoxManager();
3459 }
3460
3461 public void cleanup()
3462 {
3463 deinitPerThread();
3464 hasInstance = false;
3465 }
3466
3467 public boolean progressBar(IProgress p, int wait)
3468 {
3469 long end = System.currentTimeMillis() + wait;
3470 while (!p.getCompleted())
3471 {
3472 p.waitForCompletion(wait);
3473 if (System.currentTimeMillis() >= end)
3474 return false;
3475 }
3476
3477 return true;
3478 }
3479
3480 public boolean startVm(String name, String type, int timeout)
3481 {
3482 IMachine m = vbox.findMachine(name);
3483 if (m == null)
3484 return false;
3485 ISession session = getSessionObject();
3486 if (type == null)
3487 type = "gui";
3488 IProgress p = m.launchVMProcess(session, type, "");
3489 progressBar(p, timeout);
3490 session.unlockMachine();
3491 return true;
3492 }
3493
3494 public void waitForEvents(long tmo)
3495 {
3496 // what to do here?
3497 try {
3498 Thread.sleep(tmo);
3499 } catch (InterruptedException ie) {
3500 }
3501 }
3502}
3503]]></xsl:text>
3504
3505 <xsl:call-template name="endFile">
3506 <xsl:with-param name="file" select="'VirtualBoxManager.java'" />
3507 </xsl:call-template>
3508
3509</xsl:template>
3510
3511<xsl:template name="emitHandwrittenJaxws">
3512
3513 <xsl:call-template name="startFile">
3514 <xsl:with-param name="file" select="'IUnknown.java'" />
3515 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
3516 </xsl:call-template>
3517
3518 <xsl:text><![CDATA[
3519public class IUnknown
3520{
3521 protected String obj;
3522 protected final VboxPortType port;
3523
3524 public IUnknown(String obj, VboxPortType port)
3525 {
3526 this.obj = obj;
3527 this.port = port;
3528 }
3529
3530 public final String getWrapped()
3531 {
3532 return this.obj;
3533 }
3534
3535 public final VboxPortType getRemoteWSPort()
3536 {
3537 return this.port;
3538 }
3539
3540 public synchronized void releaseRemote() throws WebServiceException
3541 {
3542 if (obj == null) {
3543 return;
3544 }
3545 try {
3546 this.port.iManagedObjectRefRelease(obj);
3547 this.obj = null;
3548 } catch (InvalidObjectFaultMsg e) {
3549 throw new WebServiceException(e);
3550 } catch (RuntimeFaultMsg e) {
3551 throw new WebServiceException(e);
3552 }
3553 }
3554}
3555]]></xsl:text>
3556
3557 <xsl:call-template name="endFile">
3558 <xsl:with-param name="file" select="'IUnknown.java'" />
3559 </xsl:call-template>
3560
3561 <xsl:call-template name="startFile">
3562 <xsl:with-param name="file" select="'Helper.java'" />
3563 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
3564 </xsl:call-template>
3565
3566<xsl:text><![CDATA[
3567
3568import java.util.List;
3569import java.util.ArrayList;
3570import java.util.Collections;
3571import java.lang.reflect.Array;
3572import java.lang.reflect.Constructor;
3573import java.lang.reflect.InvocationTargetException;
3574import java.math.BigInteger;
3575
3576public class Helper {
3577 public static <T> List<T> wrap(Class<T> wrapperClass, VboxPortType pt, List<String> thisPtrs) {
3578 try {
3579 if(thisPtrs==null) return null;
3580
3581 Constructor<T> c = wrapperClass.getConstructor(String.class, VboxPortType.class);
3582 List<T> ret = new ArrayList<T>(thisPtrs.size());
3583 for (String thisPtr : thisPtrs) {
3584 ret.add(c.newInstance(thisPtr,pt));
3585 }
3586 return ret;
3587 } catch (NoSuchMethodException e) {
3588 throw new AssertionError(e);
3589 } catch (InstantiationException e) {
3590 throw new AssertionError(e);
3591 } catch (IllegalAccessException e) {
3592 throw new AssertionError(e);
3593 } catch (InvocationTargetException e) {
3594 throw new AssertionError(e);
3595 }
3596 }
3597
3598 public static <T1, T2> List<T1> wrap2(Class<T1> wrapperClass1, Class<T2> wrapperClass2, VboxPortType pt, List<T2> thisPtrs) {
3599 try {
3600 if(thisPtrs==null) return null;
3601
3602 Constructor<T1> c = wrapperClass1.getConstructor(wrapperClass2, VboxPortType.class);
3603 List<T1> ret = new ArrayList<T1>(thisPtrs.size());
3604 for (T2 thisPtr : thisPtrs) {
3605 ret.add(c.newInstance(thisPtr,pt));
3606 }
3607 return ret;
3608 } catch (NoSuchMethodException e) {
3609 throw new AssertionError(e);
3610 } catch (InstantiationException e) {
3611 throw new AssertionError(e);
3612 } catch (IllegalAccessException e) {
3613 throw new AssertionError(e);
3614 } catch (InvocationTargetException e) {
3615 throw new AssertionError(e);
3616 }
3617 }
3618
3619 public static <T extends IUnknown> List<String> unwrap(List<T> thisPtrs) {
3620 if (thisPtrs==null) return null;
3621
3622 List<String> ret = new ArrayList<String>(thisPtrs.size());
3623 for (T obj : thisPtrs) {
3624 ret.add(obj.getWrapped());
3625 }
3626 return ret;
3627 }
3628
3629 @SuppressWarnings("unchecked" )
3630 public static <T1 extends Enum <T1>, T2 extends Enum <T2>> List<T2> convertEnums(Class<T1> fromClass,
3631 Class<T2> toClass,
3632 List<T1> values) {
3633 try {
3634 if (values==null)
3635 return null;
3636 java.lang.reflect.Method fromValue = toClass.getMethod("fromValue", String.class);
3637 List<T2> ret = new ArrayList<T2>(values.size());
3638 for (T1 v : values) {
3639 // static method is called with null this
3640 ret.add((T2)fromValue.invoke(null, v.name()));
3641 }
3642 return ret;
3643 } catch (NoSuchMethodException e) {
3644 throw new AssertionError(e);
3645 } catch (IllegalAccessException e) {
3646 throw new AssertionError(e);
3647 } catch (InvocationTargetException e) {
3648 throw new AssertionError(e);
3649 }
3650 }
3651
3652 /* Pretty naive Base64 encoder/decoder. */
3653 private static final char[] valToChar = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray();
3654 private static final int[] charToVal = new int[256];
3655
3656 /* Initialize recoding alphabet. */
3657 static
3658 {
3659 for (int i = 0; i < charToVal.length; i++)
3660 charToVal[i] = -1;
3661
3662 for (int i = 0; i < valToChar.length; i++)
3663 charToVal[valToChar[i]] = i;
3664
3665 charToVal['='] = 0;
3666 }
3667
3668 public static String encodeBase64(byte[] data)
3669 {
3670 if (data == null)
3671 return null;
3672
3673 if (data.length == 0)
3674 return "";
3675
3676 int fullTriplets = data.length / 3;
3677 int resultLen = ((data.length - 1) / 3 + 1) * 4;
3678 char[] result = new char[resultLen];
3679 int dataIndex = 0, stringIndex = 0;
3680
3681 for (int i = 0; i < fullTriplets; i++)
3682 {
3683 int ch1 = data[dataIndex++] & 0xff;
3684 result[stringIndex++] = valToChar[ch1 >> 2];
3685 int ch2 = data[dataIndex++] & 0xff;
3686 result[stringIndex++] = valToChar[((ch1 << 4) & 0x3f) | (ch2 >> 4)];
3687 int ch3 = data[dataIndex++] & 0xff;
3688 result[stringIndex++] = valToChar[((ch2 << 2) & 0x3f) | (ch3 >> 6)];
3689 result[stringIndex++] = valToChar[ch3 & 0x3f];
3690 }
3691
3692 switch (data.length - dataIndex)
3693 {
3694 case 0:
3695 // do nothing
3696 break;
3697 case 1:
3698 {
3699 int ch1 = data[dataIndex++] & 0xff;
3700 result[stringIndex++] = valToChar[ch1 >> 2];
3701 result[stringIndex++] = valToChar[(ch1 << 4) & 0x3f];
3702 result[stringIndex++] = '=';
3703 result[stringIndex++] = '=';
3704 break;
3705 }
3706 case 2:
3707 {
3708 int ch1 = data[dataIndex++] & 0xff;
3709 result[stringIndex++] = valToChar[ch1 >> 2];
3710 int ch2 = data[dataIndex++] & 0xff;
3711 result[stringIndex++] = valToChar[((ch1 << 4) & 0x3f) | (ch2 >> 4)];
3712 result[stringIndex++] = valToChar[(ch2 << 2) & 0x3f];
3713 result[stringIndex++] = '=';
3714 break;
3715 }
3716 default:
3717 throw new RuntimeException("bug!");
3718 }
3719
3720 return new String(result);
3721 }
3722
3723 private static int skipInvalid(String str, int stringIndex)
3724 {
3725 while (charToVal[str.charAt(stringIndex)] < 0)
3726 stringIndex++;
3727
3728 return stringIndex;
3729 }
3730
3731 public static byte[] decodeBase64(String str)
3732 {
3733 if (str == null)
3734 return null;
3735
3736 int stringLength = str.length();
3737 if (stringLength == 0)
3738 return new byte[0];
3739
3740 int validChars = 0, padChars = 0;
3741 for (int i = 0; i < str.length(); i++)
3742 {
3743 char ch = str.charAt(i);
3744
3745 if (charToVal[ch] >= 0)
3746 validChars++;
3747
3748 if (ch == '=')
3749 padChars++;
3750 }
3751
3752 if ((validChars * 3 % 4) != 0)
3753 throw new RuntimeException("invalid encoded string "+str);
3754
3755 int resultLength = validChars * 3 / 4 - padChars;
3756 byte[] result = new byte[resultLength];
3757
3758 int dataIndex = 0, stringIndex = 0;
3759 int quadraplets = validChars / 4;
3760
3761 for (int i=0; i<quadraplets; i++)
3762 {
3763 stringIndex = skipInvalid(str, stringIndex);
3764 int ch1 = str.charAt(stringIndex++);
3765 stringIndex = skipInvalid(str, stringIndex);
3766 int ch2 = str.charAt(stringIndex++);
3767 stringIndex = skipInvalid(str, stringIndex);
3768 int ch3 = str.charAt(stringIndex++);
3769 stringIndex = skipInvalid(str, stringIndex);
3770 int ch4 = str.charAt(stringIndex++);
3771
3772 result[dataIndex++] = (byte)(((charToVal[ch1] << 2) | charToVal[ch2] >> 4) & 0xff);
3773 /* we check this to ensure that we don't override data with '=' padding. */
3774 if (dataIndex < result.length)
3775 result[dataIndex++] = (byte)(((charToVal[ch2] << 4) | charToVal[ch3] >> 2) & 0xff);
3776 if (dataIndex < result.length)
3777 result[dataIndex++] = (byte)(((charToVal[ch3] << 6) | charToVal[ch4]) & 0xff);
3778 }
3779
3780 return result;
3781 }
3782}
3783]]></xsl:text>
3784
3785 <xsl:call-template name="endFile">
3786 <xsl:with-param name="file" select="'Helper.java'" />
3787 </xsl:call-template>
3788
3789 <xsl:call-template name="startFile">
3790 <xsl:with-param name="file" select="'VirtualBoxManager.java'" />
3791 <xsl:with-param name="package" select="$G_virtualBoxPackage" />
3792 </xsl:call-template>
3793
3794import java.net.URL;
3795import java.math.BigInteger;
3796import java.util.List;
3797import java.util.Map;
3798import java.util.HashMap;
3799import javax.xml.namespace.QName;
3800import javax.xml.ws.BindingProvider;
3801import javax.xml.ws.Holder;
3802import javax.xml.ws.WebServiceException;
3803
3804class PortPool
3805{
3806 private final static String wsdlFile = <xsl:value-of select="$G_virtualBoxWsdl" />;
3807
3808 <xsl:text><![CDATA[
3809private Map<VboxPortType, Integer> known;
3810 private boolean initStarted;
3811 private VboxService svc;
3812
3813 PortPool(boolean usePreinit)
3814 {
3815 known = new HashMap<VboxPortType, Integer>();
3816
3817 if (usePreinit)
3818 {
3819 new Thread(new Runnable()
3820 {
3821 public void run()
3822 {
3823 // need to sync on something else but 'this'
3824 synchronized (known)
3825 {
3826 initStarted = true;
3827 known.notify();
3828 }
3829
3830 preinit();
3831 }
3832 }).start();
3833
3834 synchronized (known)
3835 {
3836 while (!initStarted)
3837 {
3838 try {
3839 known.wait();
3840 } catch (InterruptedException e) {
3841 break;
3842 }
3843 }
3844 }
3845 }
3846 }
3847
3848 private synchronized void preinit()
3849 {
3850 VboxPortType port = getPort();
3851 releasePort(port);
3852 }
3853
3854 synchronized VboxPortType getPort()
3855 {
3856 VboxPortType port = null;
3857 int ttl = 0;
3858
3859 for (VboxPortType cur: known.keySet())
3860 {
3861 int value = known.get(cur);
3862 if ((value & 0x10000) == 0)
3863 {
3864 port = cur;
3865 ttl = value & 0xffff;
3866 break;
3867 }
3868 }
3869
3870 if (port == null)
3871 {
3872 if (svc == null) {
3873 URL wsdl = PortPool.class.getClassLoader().getResource(wsdlFile);
3874 if (wsdl == null)
3875 throw new LinkageError(wsdlFile+" not found, but it should have been in the jar");
3876 svc = new VboxService(wsdl,
3877 new QName("http://www.alldomusa.eu.org/Service",
3878 "vboxService"));
3879 }
3880 port = svc.getVboxServicePort();
3881 // reuse this object 0x10 times
3882 ttl = 0x10;
3883 }
3884 // mark as used
3885 known.put(port, new Integer(0x10000 | ttl));
3886 return port;
3887 }
3888
3889 synchronized void releasePort(VboxPortType port)
3890 {
3891 Integer val = known.get(port);
3892 if (val == null || val == 0)
3893 {
3894 // know you not
3895 return;
3896 }
3897
3898 int v = val;
3899 int ttl = v & 0xffff;
3900 // decrement TTL, and throw away port if used too much times
3901 if (--ttl <= 0)
3902 {
3903 known.remove(port);
3904 }
3905 else
3906 {
3907 v = ttl; // set new TTL and clear busy bit
3908 known.put(port, v);
3909 }
3910 }
3911}
3912
3913
3914public class VirtualBoxManager
3915{
3916 private static PortPool pool = new PortPool(true);
3917 protected VboxPortType port;
3918
3919 private IVirtualBox vbox;
3920
3921 private VirtualBoxManager()
3922 {
3923 }
3924
3925 public static void initPerThread()
3926 {
3927 }
3928
3929 public static void deinitPerThread()
3930 {
3931 }
3932
3933 public void connect(String url, String username, String passwd)
3934 {
3935 this.port = pool.getPort();
3936 try {
3937 ((BindingProvider)port).getRequestContext().
3938 put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
3939 String handle = port.iWebsessionManagerLogon(username, passwd);
3940 this.vbox = new IVirtualBox(handle, port);
3941 } catch (Throwable t) {
3942 if (this.port != null && pool != null) {
3943 pool.releasePort(this.port);
3944 this.port = null;
3945 }
3946 // we have to throw smth derived from RuntimeException
3947 throw new VBoxException(t, t.getMessage());
3948 }
3949 }
3950
3951 public void connect(String url, String username, String passwd,
3952 Map<String, Object> requestContext, Map<String, Object> responseContext)
3953 {
3954 this.port = pool.getPort();
3955
3956 try {
3957 ((BindingProvider)port).getRequestContext();
3958 if (requestContext != null)
3959 ((BindingProvider)port).getRequestContext().putAll(requestContext);
3960
3961 if (responseContext != null)
3962 ((BindingProvider)port).getResponseContext().putAll(responseContext);
3963
3964 ((BindingProvider)port).getRequestContext().
3965 put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
3966 String handle = port.iWebsessionManagerLogon(username, passwd);
3967 this.vbox = new IVirtualBox(handle, port);
3968 } catch (Throwable t) {
3969 if (this.port != null && pool != null) {
3970 pool.releasePort(this.port);
3971 this.port = null;
3972 }
3973 // we have to throw smth derived from RuntimeException
3974 throw new VBoxException(t, t.getMessage());
3975 }
3976 }
3977
3978 public void disconnect()
3979 {
3980 try {
3981 if ( this.vbox != null
3982 && port != null)
3983 port.iWebsessionManagerLogoff(this.vbox.getWrapped());
3984 } catch (InvalidObjectFaultMsg e) {
3985 throw new VBoxException(e, e.getMessage());
3986 } catch (RuntimeFaultMsg e) {
3987 throw new VBoxException(e, e.getMessage());
3988 } finally {
3989 if (this.port != null) {
3990 pool.releasePort(this.port);
3991 this.port = null;
3992 }
3993 }
3994 }
3995
3996 public IVirtualBox getVBox()
3997 {
3998 return this.vbox;
3999 }
4000
4001 public ISession getSessionObject()
4002 {
4003 if (this.vbox == null)
4004 throw new RuntimeException("connect first");
4005 try {
4006 String handle = port.iWebsessionManagerGetSessionObject(this.vbox.getWrapped());
4007 return new ISession(handle, port);
4008 } catch (InvalidObjectFaultMsg e) {
4009 throw new VBoxException(e, e.getMessage());
4010 } catch (RuntimeFaultMsg e) {
4011 throw new VBoxException(e, e.getMessage());
4012 }
4013 }
4014
4015 public ISession openMachineSession(IMachine m) throws Exception
4016 {
4017 ISession s = getSessionObject();
4018 m.lockMachine(s, LockType.Shared);
4019 return s;
4020 }
4021
4022 public void closeMachineSession(ISession s)
4023 {
4024 if (s != null)
4025 s.unlockMachine();
4026 }
4027
4028 public static synchronized VirtualBoxManager createInstance(String home)
4029 {
4030 return new VirtualBoxManager();
4031 }
4032
4033 public IEventListener createListener(Object sink)
4034 {
4035 throw new RuntimeException("no active listeners here");
4036 }
4037 public void cleanup()
4038 {
4039 disconnect();
4040 deinitPerThread();
4041 }
4042
4043 public boolean progressBar(IProgress p, int wait)
4044 {
4045 long end = System.currentTimeMillis() + wait;
4046 while (!p.getCompleted())
4047 {
4048 p.waitForCompletion(wait);
4049 if (System.currentTimeMillis() >= end)
4050 return false;
4051 }
4052
4053 return true;
4054 }
4055
4056 public boolean startVm(String name, String type, int timeout)
4057 {
4058 IMachine m = vbox.findMachine(name);
4059 if (m == null)
4060 return false;
4061 ISession session = getSessionObject();
4062
4063 if (type == null)
4064 type = "gui";
4065 IProgress p = m.launchVMProcess(session, type, "");
4066 progressBar(p, timeout);
4067 session.unlockMachine();
4068 return true;
4069 }
4070
4071 public void waitForEvents(long tmo)
4072 {
4073 }
4074
4075 protected void finalize() throws Throwable
4076 {
4077 try {
4078 cleanup();
4079 } catch(Exception e) {
4080 }
4081 finally {
4082 super.finalize();
4083 }
4084 }
4085}
4086]]></xsl:text>
4087
4088 <xsl:call-template name="endFile">
4089 <xsl:with-param name="file" select="'VirtualBoxManager.java'" />
4090 </xsl:call-template>
4091
4092</xsl:template>
4093
4094
4095<xsl:template match="/">
4096
4097 <xsl:if test="not($G_vboxApiSuffix)">
4098 <xsl:call-template name="fatalError">
4099 <xsl:with-param name="msg" select="'G_vboxApiSuffix must be given'" />
4100 </xsl:call-template>
4101 </xsl:if>
4102
4103 <!-- Handwritten files -->
4104 <xsl:call-template name="emitHandwritten"/>
4105
4106 <xsl:choose>
4107 <xsl:when test="$G_vboxGlueStyle='xpcom'">
4108 <xsl:call-template name="emitHandwrittenXpcom"/>
4109 </xsl:when>
4110
4111 <xsl:when test="$G_vboxGlueStyle='mscom'">
4112 <xsl:call-template name="emitHandwrittenMscom"/>
4113 </xsl:when>
4114
4115 <xsl:when test="$G_vboxGlueStyle='jaxws'">
4116 <xsl:call-template name="emitHandwrittenJaxws"/>
4117 </xsl:when>
4118
4119 <xsl:otherwise>
4120 <xsl:call-template name="fatalError">
4121 <xsl:with-param name="msg" select="'Style unknown (root)'" />
4122 </xsl:call-template>
4123 </xsl:otherwise>
4124 </xsl:choose>
4125
4126 <!-- Enums -->
4127 <xsl:for-each select="//enum">
4128 <xsl:call-template name="genEnum">
4129 <xsl:with-param name="enumname" select="@name" />
4130 <xsl:with-param name="filename" select="concat(@name, '.java')" />
4131 </xsl:call-template>
4132 </xsl:for-each>
4133
4134 <!-- Interfaces -->
4135 <xsl:for-each select="//interface">
4136 <xsl:variable name="self_target" select="current()/ancestor::if/@target"/>
4137 <xsl:variable name="module" select="current()/ancestor::module/@name"/>
4138
4139 <xsl:choose>
4140 <xsl:when test="$G_vboxGlueStyle='jaxws'">
4141 <xsl:if test="not($module) and not(@wsmap='suppress') and not(@wsmap='global')">
4142 <xsl:call-template name="genIface">
4143 <xsl:with-param name="ifname" select="@name" />
4144 <xsl:with-param name="filename" select="concat(@name, '.java')" />
4145 </xsl:call-template>
4146 </xsl:if>
4147 </xsl:when>
4148
4149 <xsl:otherwise>
4150 <!-- We don't need WSDL-specific interfaces here -->
4151 <xsl:if test="not($self_target='wsdl') and not($module)">
4152 <xsl:call-template name="genIface">
4153 <xsl:with-param name="ifname" select="@name" />
4154 <xsl:with-param name="filename" select="concat(@name, '.java')" />
4155 </xsl:call-template>
4156 </xsl:if>
4157 </xsl:otherwise>
4158
4159 </xsl:choose>
4160 </xsl:for-each>
4161</xsl:template>
4162</xsl:stylesheet>
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette