VirtualBox

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

Last change on this file since 39252 was 38912, checked in by vboxsync, 13 years ago

Main/glue-java: fix copyright in the generated code

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

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