VirtualBox

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

Last change on this file since 33557 was 33069, checked in by vboxsync, 14 years ago

WS, Java: handle input safearrays

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