VirtualBox

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

Last change on this file since 38869 was 38799, checked in by vboxsync, 13 years ago

Main/webservice: only document the official API package, not the internal jaxws classes

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