VirtualBox

source: vbox/trunk/src/VBox/Main/webservice/glue-jaxws.xsl@ 28851

Last change on this file since 28851 was 28800, checked in by vboxsync, 14 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
File size: 54.8 KB
Line 
1<?xml version="1.0"?>
2
3<!--
4 websrv-jax-ws.xsl:
5 XSLT stylesheet that generates virtualbox.java from
6 VirtualBox.xidl. This generated Java code contains
7 a Java wrapper that allows client code to use the
8 webservice in an object-oriented way.
9
10 Copyright (C) 2008-2009 Oracle Corporation
11
12 This file is part of VirtualBox Open Source Edition (OSE), as
13 available from http://www.virtualbox.org. This file is free software;
14 you can redistribute it and/or modify it under the terms of the GNU
15 General Public License (GPL) as published by the Free Software
16 Foundation, in version 2 as it comes in the "COPYING" file of the
17 VirtualBox OSE distribution. VirtualBox OSE is distributed in the
18 hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
19-->
20
21<xsl:stylesheet
22 version="1.0"
23 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
24 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
25 xmlns:exsl="http://exslt.org/common"
26 extension-element-prefixes="exsl">
27
28 <xsl:output method="text"/>
29
30 <xsl:strip-space elements="*"/>
31
32<!-- - - - - - - - - - - - - - - - - - - - - - -
33 global XSLT variables
34 - - - - - - - - - - - - - - - - - - - - - - -->
35
36<xsl:variable name="G_xsltFilename" select="'glue-jaxws.xsl'" />
37<!-- Keep in sync with VBOX_JAVA_PACKAGE in webservices/Makefile.kmk -->
38<xsl:variable name="G_virtualBoxPackage" select="concat('org.virtualbox',$G_vboxApiSuffix)" />
39<xsl:variable name="G_virtualBoxPackage2" select="concat('com.sun.xml.ws.commons.virtualbox',$G_vboxApiSuffix)" />
40<xsl:variable name="G_virtualBoxWsdl" select="concat(concat('&quot;vboxwebService',$G_vboxApiSuffix), '.wsdl&quot;')" />
41
42<xsl:include href="websrv-shared.inc.xsl" />
43
44<!-- collect all interfaces with "wsmap='suppress'" in a global variable for
45 quick lookup -->
46<xsl:variable name="G_setSuppressedInterfaces"
47 select="//interface[@wsmap='suppress']" />
48
49
50<xsl:template name="fileheader">
51 <xsl:param name="name" />
52 <xsl:text>/**
53 * Copyright (C) 2008-2009 Sun Microsystems, Inc.
54 *
55 * This file is part of a free software library; you can redistribute
56 * it and/or modify it under the terms of the GNU Lesser General
57 * Public License version 2.1 as published by the Free Software
58 * Foundation and shipped in the "COPYING.LIB" file with this library.
59 * The library is distributed in the hope that it will be useful,
60 * but WITHOUT ANY WARRANTY of any kind.
61 *
62 * Sun LGPL Disclaimer: For the avoidance of doubt, except that if
63 * any license choice other than GPL or LGPL is available it will
64 * apply instead, Sun elects to use only the Lesser General Public
65 * License version 2.1 (LGPLv2) at this time for any software where
66 * a choice of LGPL license versions is made available with the
67 * language indicating that LGPLv2 or any later version may be used,
68 * or where a choice of which version of the LGPL is applied is
69 * otherwise unspecified.
70 *
71 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
72 * Clara, CA 95054 USA or visit http://www.sun.com if you need
73 * additional information or have any questions.
74 *
75</xsl:text>
76 <xsl:value-of select="concat(' * ',$name)"/>
77<xsl:text>
78 *
79 * DO NOT EDIT! This is a generated file.
80 * Generated from: src/VBox/Main/idl/VirtualBox.xidl (VirtualBox's interface definitions in XML)
81 * Generator: src/VBox/Main/webservice/glue-jaxws.xsl
82 */
83
84</xsl:text>
85</xsl:template>
86
87<!-- Emits the fully prefixed class name, if necessary, of the given type. This dies
88 if $name is not defined in XIDL; in other words, do not call this for built-in types. -->
89<xsl:template name="fullClassName">
90 <xsl:param name="name" />
91 <xsl:param name="origname" />
92 <xsl:param name="collPrefix" />
93 <xsl:variable name="coll" select="//collection[@name=$name]" />
94 <xsl:choose>
95 <xsl:when test="//collection[@name=$name]">
96 <!-- for collections and safearrays we return element type -->
97 <xsl:call-template name="fullClassName">
98 <xsl:with-param name="name" select="concat($collPrefix,//collection[@name=$name]/@type)" />
99 <xsl:with-param name="origname" select="//collection[@name=$name]/@type" />
100 <xsl:with-param name="collPrefix" select="$collPrefix" />
101 </xsl:call-template>
102 <!-- <xsl:value-of select="concat('org.virtualbox.', concat($collPrefix,//collection[@name=$name]/@type))" /> -->
103 </xsl:when>
104 <xsl:when test="//enum[@name=$name] or //enum[@name=$origname]">
105 <xsl:value-of select="concat($G_virtualBoxPackage, concat('.', $name))" />
106 </xsl:when>
107 <xsl:when test="$collPrefix and //interface[@name=$origname]/@wsmap='managed'">
108 <xsl:value-of select="concat($G_virtualBoxPackage, concat('.', $name))" />
109 </xsl:when>
110 <xsl:when test="//interface[@name=$name]">
111 <xsl:value-of select="concat($G_virtualBoxPackage2, concat('.', $name))" />
112 </xsl:when>
113 <xsl:otherwise>
114 <xsl:call-template name="fatalError">
115 <xsl:with-param name="msg" select="concat('fullClassName: Type &quot;', $name, '&quot; is not supported.')" />
116 </xsl:call-template>
117 </xsl:otherwise>
118 </xsl:choose>
119</xsl:template>
120
121<!--
122 typeIdl2Glue: converts $type into a type as used by the java glue code.
123 For example, for an XIDL IMachineCollection, this will return
124 "List<com.sun.xml.ws.commons.virtualbox.IMachine>".
125 -->
126<xsl:template name="typeIdl2Glue">
127 <xsl:param name="ifname" />
128 <xsl:param name="method" />
129 <xsl:param name="name" />
130 <xsl:param name="type" />
131 <xsl:param name="safearray" />
132 <xsl:param name="forceelem" />
133
134 <xsl:variable name="needarray" select="($safearray='yes' or //collection[@name=$type]) and not($forceelem='yes')" />
135
136 <xsl:if test="$needarray">
137 <xsl:value-of select="'List&lt;'" />
138 </xsl:if>
139
140 <!-- look up Java type from IDL type from table array in websrv-shared.inc.xsl -->
141 <xsl:variable name="javatypefield" select="exsl:node-set($G_aSharedTypes)/type[@idlname=$type]/@javaname" />
142
143 <xsl:choose>
144 <xsl:when test="string-length($javatypefield)">
145 <xsl:value-of select="$javatypefield" />
146 </xsl:when>
147 <!-- not a standard type: then it better be one of the types defined in the XIDL -->
148 <xsl:when test="$type='$unknown'">IUnknown</xsl:when>
149 <xsl:otherwise>
150 <xsl:call-template name="fullClassName">
151 <xsl:with-param name="name" select="$type" />
152 <xsl:with-param name="collPrefix" select="''"/>
153 </xsl:call-template>
154 </xsl:otherwise>
155 </xsl:choose>
156
157 <xsl:if test="$needarray">
158 <xsl:value-of select="'&gt;'" />
159 </xsl:if>
160</xsl:template>
161
162<!--
163 typeIdl2Java: converts $type into a type as used by the JAX-WS backend.
164 For example, for an XIDL IMachineCollection, this will return
165 "ArrayOfIMachine".
166 -->
167<xsl:template name="typeIdl2Java">
168 <xsl:param name="ifname" />
169 <xsl:param name="method" />
170 <xsl:param name="name" />
171 <xsl:param name="type" />
172 <xsl:param name="safearray" />
173 <xsl:param name="forceelem" />
174
175 <xsl:variable name="needarray" select="($safearray='yes') and not($forceelem='yes')" />
176
177 <xsl:if test="$needarray">
178 <xsl:value-of select="'List&lt;'" />
179 </xsl:if>
180
181 <!-- look up Java type from IDL type from table array in websrv-shared.inc.xsl -->
182 <xsl:variable name="javatypefield" select="exsl:node-set($G_aSharedTypes)/type[@idlname=$type]/@javaname" />
183
184 <xsl:choose>
185 <xsl:when test="string-length($javatypefield)">
186 <xsl:value-of select="$javatypefield" />
187 </xsl:when>
188 <xsl:when test="$type='$unknown'">String</xsl:when>
189 <xsl:when test="//interface[@name=$type]/@wsmap='struct'">
190 <xsl:value-of select="concat($G_virtualBoxPackage, '.', $type)" />
191 </xsl:when>
192 <xsl:when test="//interface[@name=$type]/@wsmap='managed'">String</xsl:when>
193 <xsl:otherwise>
194 <xsl:call-template name="fullClassName">
195 <xsl:with-param name="name" select="$type" />
196 <xsl:with-param name="collPrefix" select="'ArrayOf'"/>
197 </xsl:call-template>
198 </xsl:otherwise>
199 </xsl:choose>
200 <xsl:if test="$needarray">
201 <xsl:value-of select="'&gt;'" />
202 </xsl:if>
203</xsl:template>
204
205<xsl:template name="cookOutParam">
206 <xsl:param name="ifname"/>
207 <xsl:param name="methodname"/>
208 <xsl:param name="value"/>
209 <xsl:param name="idltype"/>
210 <xsl:param name="safearray"/>
211 <xsl:variable name="isstruct"
212 select="//interface[@name=$idltype]/@wsmap='struct'" />
213 <xsl:choose>
214 <xsl:when test="//collection[@name=$idltype]">
215 <xsl:variable name="elemtype">
216 <xsl:call-template name="typeIdl2Glue">
217 <xsl:with-param name="ifname" select="$ifname" />
218 <xsl:with-param name="method" select="$methodname" />
219 <xsl:with-param name="name" select="$value" />
220 <xsl:with-param name="type" select="$idltype" />
221 <xsl:with-param name="forceelem" select="'yes'" />
222 </xsl:call-template>
223 </xsl:variable>
224 <xsl:choose>
225 <xsl:when test="contains($elemtype, $G_virtualBoxPackage)">
226 <xsl:value-of select="concat($value,'.getArray()')" />
227 </xsl:when>
228 <xsl:otherwise>
229 <xsl:value-of select="concat('Helper.wrap(', $elemtype, '.class, port, ((',
230 $value,' == null)? null : ',$value,'.getArray()))')" />
231 </xsl:otherwise>
232 </xsl:choose>
233 </xsl:when>
234 <xsl:when test="//interface[@name=$idltype] or $idltype='$unknown'">
235 <xsl:choose>
236 <xsl:when test="$safearray='yes'">
237 <xsl:variable name="elemtype">
238 <xsl:call-template name="typeIdl2Glue">
239 <xsl:with-param name="ifname" select="$ifname" />
240 <xsl:with-param name="method" select="$methodname" />
241 <xsl:with-param name="name" select="$value" />
242 <xsl:with-param name="type" select="$idltype" />
243 <xsl:with-param name="safearray" select="'no'" />
244 <xsl:with-param name="forceelem" select="'yes'" />
245 </xsl:call-template>
246 </xsl:variable>
247 <xsl:choose>
248 <xsl:when test="$isstruct">
249 <xsl:variable name="javagettertype">
250 <xsl:call-template name="typeIdl2Java">
251 <xsl:with-param name="method" select="$methodname" />
252 <xsl:with-param name="name" select="$value" />
253 <xsl:with-param name="type" select="$idltype" />
254 <xsl:with-param name="safearray" select="$safearray" />
255 <xsl:with-param name="forceelem" select="'yes'" />
256 </xsl:call-template>
257 </xsl:variable>
258 <xsl:value-of select="concat('Helper.wrap2(',$elemtype, '.class, ', $javagettertype, '.class, port, ', $value,')')"/>
259 </xsl:when>
260 <xsl:otherwise>
261 <xsl:value-of select="concat('Helper.wrap(',$elemtype, '.class, port, ', $value,')')"/>
262 </xsl:otherwise>
263 </xsl:choose>
264 </xsl:when>
265 <xsl:otherwise>
266 <xsl:variable name="gluetype">
267 <xsl:call-template name="typeIdl2Glue">
268 <xsl:with-param name="ifname" select="$ifname" />
269 <xsl:with-param name="method" select="$methodname" />
270 <xsl:with-param name="name" select="$value" />
271 <xsl:with-param name="type" select="$idltype" />
272 <xsl:with-param name="safearray" select="$safearray" />
273 </xsl:call-template>
274 </xsl:variable>
275 <xsl:choose>
276 <xsl:when test="$isstruct">
277 <xsl:value-of select="concat('(', $value, ' != null) ? new ', $gluetype, '(', $value,', port) : null')" />
278 </xsl:when>
279 <xsl:otherwise>
280 <!-- if the MOR string is empty, that means NULL, so return NULL instead of an object then -->
281 <xsl:value-of select="concat('(', $value, '.length() > 0) ? new ', $gluetype, '(', $value,', port) : null')" />
282 </xsl:otherwise>
283 </xsl:choose>
284 </xsl:otherwise>
285 </xsl:choose>
286 </xsl:when>
287 <xsl:otherwise>
288 <xsl:value-of select="$value"/>
289 </xsl:otherwise>
290 </xsl:choose>
291</xsl:template>
292
293<xsl:template name="genStructWrapper">
294 <xsl:param name="ifname" select="@name" />
295
296 <xsl:value-of select="concat(' private ', $G_virtualBoxPackage,'.',$ifname, ' real;&#10;')"/>
297 <xsl:value-of select="' private VboxPortType port;&#10;&#10;'"/>
298
299 <xsl:value-of select="concat(' public ', $ifname, '(', $G_virtualBoxPackage,'.',$ifname,' real, VboxPortType port) {&#10; this.real = real; &#10; this.port = port; &#10; }&#10;')"/>
300 <xsl:for-each select="attribute">
301 <xsl:variable name="attrname"><xsl:value-of select="@name" /></xsl:variable>
302 <xsl:variable name="attrtype"><xsl:value-of select="@type" /></xsl:variable>
303 <xsl:variable name="attrreadonly"><xsl:value-of select="@readonly" /></xsl:variable>
304 <xsl:variable name="attrsafearray"><xsl:value-of select="@safearray" /></xsl:variable>
305 <xsl:choose>
306 <xsl:when test="$attrreadonly='yes'">
307 <xsl:value-of select="concat('&#10; // read-only attribute ', $ifname, '::', $attrname, ' of type ', $attrtype, '&#10;')" />
308
309 </xsl:when>
310 <xsl:otherwise>
311 <xsl:value-of select="concat('&#10; // read/write attribute ', $ifname, '::', $attrname, ' of type ', $attrtype, '&#10;')" />
312 </xsl:otherwise>
313 </xsl:choose>
314
315 <!-- emit getter method -->
316 <xsl:variable name="gettername">
317 <xsl:choose>
318 <!-- Stupid, but boolean getters called isFoo(), not getFoo() -->
319 <xsl:when test="$attrtype = 'boolean'">
320 <xsl:variable name="capsname">
321 <xsl:call-template name="capitalize">
322 <xsl:with-param name="str" select="$attrname" />
323 </xsl:call-template>
324 </xsl:variable>
325 <xsl:value-of select="concat('is', $capsname)" />
326 </xsl:when>
327 <xsl:otherwise>
328 <xsl:call-template name="makeGetterName">
329 <xsl:with-param name="attrname" select="$attrname" />
330 </xsl:call-template>
331 </xsl:otherwise>
332 </xsl:choose>
333 </xsl:variable>
334 <xsl:variable name="gluegettertype">
335 <xsl:call-template name="typeIdl2Glue">
336 <xsl:with-param name="ifname" select="$ifname" />
337 <xsl:with-param name="method" select="$gettername" />
338 <xsl:with-param name="name" select="$attrname" />
339 <xsl:with-param name="type" select="$attrtype" />
340 <xsl:with-param name="safearray" select="@safearray" />
341 </xsl:call-template>
342 </xsl:variable>
343 <xsl:variable name="javagettertype">
344 <xsl:call-template name="typeIdl2Java">
345 <xsl:with-param name="ifname" select="$ifname" />
346 <xsl:with-param name="method" select="$gettername" />
347 <xsl:with-param name="name" select="$attrname" />
348 <xsl:with-param name="type" select="$attrtype" />
349 <xsl:with-param name="safearray" select="@safearray" />
350 </xsl:call-template>
351 </xsl:variable>
352 <xsl:value-of select="concat(' public ', $gluegettertype, ' ', $gettername, '() {&#10;')" />
353 <xsl:value-of select="concat(' ', $javagettertype, ' retVal = real.', $gettername, '();&#10;')" />
354 <xsl:variable name="wrapped">
355 <xsl:call-template name="cookOutParam">
356 <xsl:with-param name="ifname" select="$ifname" />
357 <xsl:with-param name="method" select="$gettername" />
358 <xsl:with-param name="value" select="'retVal'" />
359 <xsl:with-param name="idltype" select="$attrtype" />
360 <xsl:with-param name="safearray" select="@safearray" />
361 </xsl:call-template>
362 </xsl:variable>
363 <xsl:value-of select="concat(' return ', $wrapped, ';&#10;')" />
364 <xsl:text> }&#10;</xsl:text>
365
366 </xsl:for-each>
367
368</xsl:template>
369
370
371<xsl:template name="emitArgInMethodImpl">
372 <xsl:param name="paramname" select="@name" />
373 <xsl:param name="paramtype" select="@type" />
374 <!-- per-argument special type handling -->
375 <xsl:choose>
376 <xsl:when test="//interface[@name=$paramtype] or $paramtype='$unknown'">
377 <xsl:choose>
378 <xsl:when test="@dir='out'">
379 <xsl:value-of select="concat('tmp', $paramname)" />
380 </xsl:when>
381 <xsl:otherwise>
382 <xsl:choose>
383 <xsl:when test="@safearray='yes'">
384 <xsl:value-of select="concat('Helper.unwrap(',$paramname,')')"/>
385 </xsl:when>
386 <xsl:otherwise>
387 <xsl:value-of select="concat('((', $paramname, ' == null)?null:', $paramname, '.getRef())')" />
388 </xsl:otherwise>
389 </xsl:choose>
390 </xsl:otherwise>
391 </xsl:choose>
392 </xsl:when>
393 <xsl:otherwise>
394 <xsl:value-of select="$paramname" />
395 </xsl:otherwise>
396 </xsl:choose>
397 <xsl:if test="not(position()=last())">
398 <xsl:text>, </xsl:text>
399 </xsl:if>
400</xsl:template>
401
402<xsl:template name="startFile">
403 <xsl:param name="file" />
404
405 <xsl:value-of select="concat('&#10;// ##### BEGINFILE &quot;', $file, '&quot;&#10;&#10;')" />
406 <xsl:call-template name="fileheader">
407 <xsl:with-param name="name" select="$file" />
408 </xsl:call-template>
409package <xsl:value-of select="$G_virtualBoxPackage2" />;
410
411import <xsl:value-of select="$G_virtualBoxPackage" />.VboxPortType;
412import <xsl:value-of select="$G_virtualBoxPackage" />.VboxService;
413import <xsl:value-of select="$G_virtualBoxPackage" />.InvalidObjectFaultMsg;
414import <xsl:value-of select="$G_virtualBoxPackage" />.RuntimeFaultMsg;
415import javax.xml.ws.WebServiceException;
416</xsl:template>
417
418<xsl:template name="endFile">
419 <xsl:param name="file" />
420 <xsl:value-of select="concat('&#10;// ##### ENDFILE &quot;', $file, '&quot;&#10;&#10;')" />
421</xsl:template>
422
423<!-- - - - - - - - - - - - - - - - - - - - - - -
424 root match
425 - - - - - - - - - - - - - - - - - - - - - - -->
426
427<xsl:template match="/idl">
428 <xsl:if test="not($G_vboxApiSuffix)">
429 <xsl:call-template name="fatalError">
430 <xsl:with-param name="msg" select="'G_vboxApiSuffix must be given'" />
431 </xsl:call-template>
432 </xsl:if>
433 <xsl:call-template name="startFile">
434 <xsl:with-param name="file" select="'IUnknown.java'" />
435 </xsl:call-template>
436
437 <xsl:text><![CDATA[
438public class IUnknown
439{
440 protected String _this; /* almost final, could only be set in finalizer */
441 protected final VboxPortType port;
442
443 public IUnknown(String _this, VboxPortType port)
444 {
445 this._this = _this;
446 this.port = port;
447 }
448
449 public final String getRef()
450 {
451 return _this;
452 }
453
454 public final VboxPortType getRemoteWSPort()
455 {
456 return port;
457 }
458
459 public synchronized void releaseRemote() throws WebServiceException
460 {
461 if (_this == null) {
462 return;
463 }
464 try {
465 port.iManagedObjectRefRelease(_this);
466 _this = null;
467 } catch (InvalidObjectFaultMsg e) {
468 throw new WebServiceException(e);
469 } catch (RuntimeFaultMsg e) {
470 throw new WebServiceException(e);
471 }
472 }
473
474 /*
475 protected void finalize()
476 {
477 try {
478 releaseRemote();
479 } catch (WebServiceException e) {
480 }
481 } */
482
483 // may need to support some sort of QueryInterface, to make this class useable
484 // not only as common baseclass
485}
486]]></xsl:text>
487
488 <xsl:call-template name="endFile">
489 <xsl:with-param name="file" select="'IUnknown.java'" />
490 </xsl:call-template>
491
492 <xsl:call-template name="startFile">
493 <xsl:with-param name="file" select="'Helper.java'" />
494 </xsl:call-template>
495
496<xsl:text><![CDATA[
497
498import java.util.List;
499import java.util.ArrayList;
500import java.util.Collections;
501import java.lang.reflect.Constructor;
502import java.lang.reflect.InvocationTargetException;
503
504class Helper {
505 public static <T> List<T> wrap(Class<T> wrapperClass, VboxPortType pt, List<String> thisPtrs) {
506 try {
507 if(thisPtrs==null) return Collections.emptyList();
508
509 Constructor<T> c = wrapperClass.getConstructor(String.class, VboxPortType.class);
510 List<T> ret = new ArrayList<T>(thisPtrs.size());
511 for (String thisPtr : thisPtrs) {
512 ret.add(c.newInstance(thisPtr,pt));
513 }
514 return ret;
515 } catch (NoSuchMethodException e) {
516 throw new AssertionError(e);
517 } catch (InstantiationException e) {
518 throw new AssertionError(e);
519 } catch (IllegalAccessException e) {
520 throw new AssertionError(e);
521 } catch (InvocationTargetException e) {
522 throw new AssertionError(e);
523 }
524 }
525
526 public static <T1, T2> List<T1> wrap2(Class<T1> wrapperClass1, Class<T2> wrapperClass2, VboxPortType pt, List<T2> thisPtrs) {
527 try {
528 if(thisPtrs==null) return Collections.emptyList();
529
530 Constructor<T1> c = wrapperClass1.getConstructor(wrapperClass2, VboxPortType.class);
531 List<T1> ret = new ArrayList<T1>(thisPtrs.size());
532 for (T2 thisPtr : thisPtrs) {
533 ret.add(c.newInstance(thisPtr,pt));
534 }
535 return ret;
536 } catch (NoSuchMethodException e) {
537 throw new AssertionError(e);
538 } catch (InstantiationException e) {
539 throw new AssertionError(e);
540 } catch (IllegalAccessException e) {
541 throw new AssertionError(e);
542 } catch (InvocationTargetException e) {
543 throw new AssertionError(e);
544 }
545 }
546
547 public static <T extends IUnknown> List<String> unwrap(List<T> thisPtrs) {
548 if (thisPtrs==null) return Collections.emptyList();
549
550 List<String> ret = new ArrayList<String>();
551 for (T obj : thisPtrs) {
552 ret.add(obj.getRef());
553 }
554 return ret;
555 }
556}
557]]></xsl:text>
558
559 <xsl:call-template name="endFile">
560 <xsl:with-param name="file" select="'Helper.java'" />
561 </xsl:call-template>
562
563 <xsl:call-template name="startFile">
564 <xsl:with-param name="file" select="'IWebsessionManager.java'" />
565 </xsl:call-template>
566
567
568import java.net.URL;
569import java.math.BigInteger;
570import java.util.List;
571import java.util.Map;
572import java.util.HashMap;
573import javax.xml.namespace.QName;
574import javax.xml.ws.BindingProvider;
575import javax.xml.ws.Holder;
576import javax.xml.ws.WebServiceException;
577
578class PortPool
579{
580 private final static String wsdlFile = <xsl:value-of select="$G_virtualBoxWsdl" />;
581
582 <xsl:text><![CDATA[
583 private Map<VboxPortType, Integer> known;
584 private boolean initStarted;
585 private VboxService svc;
586
587 PortPool(boolean usePreinit)
588 {
589 known = new HashMap<VboxPortType, Integer>();
590
591 if (usePreinit)
592 {
593 new Thread(new Runnable()
594 {
595 public void run()
596 {
597 // need to sync on something else but 'this'
598 synchronized (known)
599 {
600 initStarted = true;
601 known.notify();
602 }
603
604 preinit();
605 }
606 }).start();
607
608 synchronized (known)
609 {
610 while (!initStarted)
611 {
612 try {
613 known.wait();
614 } catch (InterruptedException e) {
615 break;
616 }
617 }
618 }
619 }
620 }
621
622 private synchronized void preinit()
623 {
624 VboxPortType port = getPort();
625 releasePort(port);
626 }
627
628 synchronized VboxPortType getPort()
629 {
630 VboxPortType port = null;
631 int ttl = 0;
632
633 for (VboxPortType cur: known.keySet())
634 {
635 int value = known.get(cur);
636 if ((value & 0x10000) == 0)
637 {
638 port = cur;
639 ttl = value & 0xffff;
640 break;
641 }
642 }
643
644 if (port == null)
645 {
646 if (svc == null) {
647 URL wsdl = PortPool.class.getClassLoader().getResource(wsdlFile);
648 if (wsdl == null)
649 throw new LinkageError(wsdlFile+" not found, but it should have been in the jar");
650 svc = new VboxService(wsdl,
651 new QName("http://www.virtualbox.org/Service",
652 "vboxService"));
653 }
654 port = svc.getVboxServicePort();
655 // reuse this object 0x10 times
656 ttl = 0x10;
657 }
658 // mark as used
659 known.put(port, new Integer(0x10000 | ttl));
660 return port;
661 }
662
663 synchronized void releasePort(VboxPortType port)
664 {
665 Integer val = known.get(port);
666 if (val == null || val == 0)
667 {
668 // know you not
669 return;
670 }
671
672 int v = val;
673 int ttl = v & 0xffff;
674 // decrement TTL, and throw away port if used too much times
675 if (--ttl <= 0)
676 {
677 known.remove(port);
678 }
679 else
680 {
681 v = ttl; // set new TTL and clear busy bit
682 known.put(port, v);
683 }
684 }
685}
686
687public class IWebsessionManager {
688
689 private static PortPool pool = new PortPool(true);
690 protected VboxPortType port;
691
692 public IWebsessionManager(URL url)
693 {
694 connect(url);
695 }
696
697 public IWebsessionManager(String url)
698 {
699 connect(url);
700 }
701
702 public IWebsessionManager(URL url, Map<String, Object> requestContext, Map<String, Object> responseContext)
703 {
704 connect(url.toExternalForm(), requestContext, responseContext);
705 }
706
707 public IWebsessionManager(String url, Map<String, Object> requestContext, Map<String, Object> responseContext)
708 {
709 connect(url, requestContext, responseContext);
710 }
711
712 public void connect(URL url)
713 {
714 connect(url.toExternalForm());
715 }
716
717 public void connect(String url)
718 {
719 this.port = pool.getPort();
720
721 try {
722 ((BindingProvider)port).getRequestContext().
723 put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
724 } catch (Throwable t) {
725 if (this.port != null)
726 pool.releasePort(this.port);
727 // we have to throw smth derived from RuntimeException
728 throw new WebServiceException(t);
729 }
730 }
731
732 public void connect(String url, Map<String, Object> requestContext, Map<String, Object> responseContext)
733 {
734 this.port = pool.getPort();
735
736 try {
737 ((BindingProvider)port).getRequestContext();
738 if (requestContext != null)
739 ((BindingProvider)port).getRequestContext().putAll(requestContext);
740
741 if (responseContext != null)
742 ((BindingProvider)port).getResponseContext().putAll(responseContext);
743
744 ((BindingProvider)port).getRequestContext().
745 put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
746 } catch (Throwable t) {
747 if (this.port != null)
748 pool.releasePort(port);
749 // we have to throw smth derived from RuntimeException
750 throw new WebServiceException(t);
751 }
752 }
753
754
755 public void disconnect(IVirtualBox refIVirtualBox)
756 {
757 try {
758 logoff(refIVirtualBox);
759 } finally {
760 if (this.port != null) {
761 pool.releasePort(this.port);
762 this.port = null;
763 }
764 }
765 }
766
767 public void cleanupUnused()
768 {
769 System.gc();
770 Runtime.getRuntime().runFinalization();
771 }
772
773 /* method IWebsessionManager::logon(
774 [in] wstring username,
775 [in] wstring password,
776 [return] IVirtualBox return)
777 */
778 public IVirtualBox logon(String username, String password) {
779 try {
780 String retVal = port.iWebsessionManagerLogon(username, password);
781 return new IVirtualBox(retVal, port);
782 } catch (InvalidObjectFaultMsg e) {
783 throw new WebServiceException(e);
784 } catch (RuntimeFaultMsg e) {
785 throw new WebServiceException(e);
786 }
787 }
788
789 /* method IWebsessionManager::getSessionObject(
790 [in] IVirtualBox refIVirtualBox,
791 [return] ISession return)
792 */
793 public ISession getSessionObject(IVirtualBox refIVirtualBox) {
794 try {
795 String retVal = port.iWebsessionManagerGetSessionObject(((refIVirtualBox == null)?null:refIVirtualBox.getRef()));
796 return new ISession(retVal, port);
797 } catch (InvalidObjectFaultMsg e) {
798 throw new WebServiceException(e);
799 } catch (RuntimeFaultMsg e) {
800 throw new WebServiceException(e);
801 }
802 }
803
804 /* method IWebsessionManager::logoff(
805 [in] IVirtualBox refIVirtualBox)
806 */
807 public void logoff(IVirtualBox refIVirtualBox) {
808 try {
809 port.iWebsessionManagerLogoff(((refIVirtualBox == null)?null:refIVirtualBox.getRef()));
810 } catch (InvalidObjectFaultMsg e) {
811 throw new WebServiceException(e);
812 } catch (RuntimeFaultMsg e) {
813 throw new WebServiceException(e);
814 }
815 }
816}
817]]></xsl:text>
818 <xsl:call-template name="endFile">
819 <xsl:with-param name="file" select="'IWebsessionManager.java'" />
820 </xsl:call-template>
821
822 <xsl:text>// ######## COLLECTIONS&#10;&#10;</xsl:text>
823
824 <xsl:for-each select="//collection">
825 <xsl:variable name="type" select="@type" />
826 <xsl:variable name="arrayoftype" select="concat('ArrayOf', @type)" />
827 <xsl:variable name="filename" select="$arrayoftype" />
828
829 <xsl:value-of select="concat('&#10;// ##### BEGINFILE &quot;', $filename, '.java&quot;&#10;&#10;')" />
830
831 <xsl:call-template name="startFile">
832 <xsl:with-param name="file" select="concat($filename, '.java')" />
833 </xsl:call-template>
834
835 <xsl:text>import java.util.ArrayList;&#10;</xsl:text>
836 <xsl:text>import java.util.List;&#10;</xsl:text>
837 <xsl:text>import javax.xml.bind.annotation.XmlAccessType;&#10;</xsl:text>
838 <xsl:text>import javax.xml.bind.annotation.XmlAccessorType;&#10;</xsl:text>
839 <xsl:text>import javax.xml.bind.annotation.XmlType;&#10;&#10;</xsl:text>
840
841 <xsl:text>@XmlAccessorType(XmlAccessType.FIELD)&#10;</xsl:text>
842 <xsl:value-of select="concat('@XmlType(name = &quot;', $arrayoftype, '&quot;, propOrder = {&#10;')" />
843 <xsl:text> "array"&#10;</xsl:text>
844 <xsl:text>})&#10;&#10;</xsl:text>
845 <xsl:value-of select="concat('public class ', $arrayoftype, ' {&#10;&#10;')" />
846
847 <xsl:text> protected List&lt;String&gt; array;&#10;&#10;</xsl:text>
848
849 <xsl:text> public List&lt;String&gt; getArray() {&#10;</xsl:text>
850 <xsl:text> if (array == null) {&#10;</xsl:text>
851 <xsl:text> array = new ArrayList&lt;String&gt;();&#10;</xsl:text>
852 <xsl:text> }&#10;</xsl:text>
853 <xsl:text> return this.array;&#10;</xsl:text>
854 <xsl:text> }&#10;&#10;</xsl:text>
855 <xsl:text>}&#10;</xsl:text>
856 <xsl:call-template name="endFile">
857 <xsl:with-param name="file" select="concat($filename, '.java')" />
858 </xsl:call-template>
859
860 </xsl:for-each>
861
862 <xsl:text>// ######## ENUMS&#10;&#10;</xsl:text>
863
864 <xsl:for-each select="//enum">
865 <xsl:variable name="enumname" select="@name" />
866 <xsl:variable name="filename" select="$enumname" />
867
868 <xsl:call-template name="startFile">
869 <xsl:with-param name="file" select="concat($filename, '.java')" />
870 </xsl:call-template>
871
872 <xsl:text>import javax.xml.bind.annotation.XmlEnum;&#10;</xsl:text>
873 <xsl:text>import javax.xml.bind.annotation.XmlEnumValue;&#10;</xsl:text>
874 <xsl:text>import javax.xml.bind.annotation.XmlType;&#10;&#10;</xsl:text>
875
876 <xsl:value-of select="concat('@XmlType(name = &quot;', $enumname, '&quot;)&#10;')" />
877 <xsl:text>@XmlEnum&#10;</xsl:text>
878 <xsl:value-of select="concat('public enum ', $enumname, ' {&#10;&#10;')" />
879 <xsl:for-each select="const">
880 <xsl:variable name="enumconst" select="@name" />
881 <xsl:value-of select="concat(' @XmlEnumValue(&quot;', $enumconst, '&quot;)&#10;')" />
882 <xsl:value-of select="concat(' ', $enumconst, '(&quot;', $enumconst, '&quot;)')" />
883 <xsl:choose>
884 <xsl:when test="not(position()=last())">
885 <xsl:text>,&#10;</xsl:text>
886 </xsl:when>
887 <xsl:otherwise>
888 <xsl:text>;&#10;</xsl:text>
889 </xsl:otherwise>
890 </xsl:choose>
891 </xsl:for-each>
892
893 <xsl:text>&#10;</xsl:text>
894 <xsl:text> private final String value;&#10;&#10;</xsl:text>
895
896 <xsl:value-of select="concat(' ', $enumname, '(String v) {&#10;')" />
897 <xsl:text> value = v;&#10;</xsl:text>
898 <xsl:text> }&#10;&#10;</xsl:text>
899
900 <xsl:text> public String value() {&#10;</xsl:text>
901 <xsl:text> return value;&#10;</xsl:text>
902 <xsl:text> }&#10;&#10;</xsl:text>
903
904 <xsl:value-of select="concat(' public static ', $enumname, ' fromValue(String v) {&#10;')" />
905 <xsl:value-of select="concat(' for (', $enumname, ' c: ', $enumname, '. values()) {&#10;')" />
906 <xsl:text> if (c.value.equals(v)) {&#10;</xsl:text>
907 <xsl:text> return c;&#10;</xsl:text>
908 <xsl:text> }&#10;</xsl:text>
909 <xsl:text> }&#10;</xsl:text>
910 <xsl:text> throw new IllegalArgumentException(v);&#10;</xsl:text>
911 <xsl:text> }&#10;&#10;</xsl:text>
912
913 <xsl:text>}&#10;&#10;</xsl:text>
914
915 <xsl:call-template name="endFile">
916 <xsl:with-param name="file" select="concat($filename, '.java')" />
917 </xsl:call-template>
918
919 </xsl:for-each>
920
921 <xsl:text>// ######## INTERFACES &#10;&#10;</xsl:text>
922
923 <xsl:for-each select="//interface">
924 <xsl:variable name="ifname" select="@name" />
925 <xsl:variable name="filename" select="$ifname" />
926 <xsl:variable name="wsmap" select="@wsmap" />
927 <xsl:variable name="wscpp" select="@wscpp" />
928
929 <xsl:if test="not($wsmap='suppress') and not ($wsmap='global')">
930 <xsl:call-template name="startFile">
931 <xsl:with-param name="file" select="concat($filename, '.java')" />
932 </xsl:call-template>
933
934 <xsl:text>import java.math.BigInteger;&#10;</xsl:text>
935 <xsl:text>import java.util.List;&#10;</xsl:text>
936 <xsl:text>import javax.xml.ws.Holder;&#10;</xsl:text>
937 <xsl:text>import javax.xml.ws.WebServiceException;&#10;</xsl:text>
938
939 <xsl:choose>
940 <xsl:when test="$wsmap='struct'">
941 <xsl:value-of select="concat('public class ', $ifname, ' {&#10;&#10;')" />
942 <xsl:call-template name="genStructWrapper">
943 <xsl:with-param name="name" select="$ifname" />
944 </xsl:call-template>
945 </xsl:when>
946
947 <xsl:otherwise>
948 <xsl:variable name="extends" select="//interface[@name=$ifname]/@extends" />
949 <xsl:choose>
950 <xsl:when test="($extends = '$unknown') or ($extends = '$dispatched') or ($extends = '$errorinfo')">
951 <xsl:value-of select="concat('public class ', $ifname, ' extends IUnknown {&#10;&#10;')" />
952 </xsl:when>
953 <xsl:when test="//interface[@name=$extends]">
954 <xsl:value-of select="concat('public class ', $ifname, ' extends ', $extends, ' {&#10;&#10;')" />
955 </xsl:when>
956 <xsl:otherwise>
957 <xsl:call-template name="fatalError">
958 <xsl:with-param name="msg" select="concat('Interface generation: interface &quot;', $ifname, '&quot; has invalid &quot;extends&quot; value ', $extends, '.')" />
959 </xsl:call-template>
960 </xsl:otherwise>>
961 </xsl:choose>
962
963 <!-- interface (class) constructor -->
964 <xsl:value-of select="concat(' public static ', $ifname, ' cast(IUnknown other) {&#10;')" />
965 <xsl:value-of select="concat(' return new ', $ifname,
966 '(other.getRef(), other.getRemoteWSPort());&#10; }&#10;&#10;')"/>
967 <xsl:value-of select="concat(' public ', $ifname, '(String _this, VboxPortType port) {&#10;')" />
968 <xsl:text> super(_this,port);&#10;</xsl:text>
969 <xsl:text> }&#10;</xsl:text>
970
971 <!-- attributes -->
972 <xsl:for-each select="attribute">
973 <xsl:variable name="attrname"><xsl:value-of select="@name" /></xsl:variable>
974 <xsl:variable name="attrtype"><xsl:value-of select="@type" /></xsl:variable>
975 <xsl:variable name="attrreadonly"><xsl:value-of select="@readonly" /></xsl:variable>
976 <xsl:variable name="attrsafearray"><xsl:value-of select="@safearray" /></xsl:variable>
977
978 <xsl:choose>
979 <xsl:when test="( $attrtype=($G_setSuppressedInterfaces/@name) )">
980 <xsl:value-of select="concat('&#10; // Skipping attribute ', $attrtype, ' for it is of suppressed type ', $attrtype, '&#10;')" />
981 </xsl:when>
982 <xsl:otherwise>
983 <xsl:choose>
984 <xsl:when test="@readonly='yes'">
985 <xsl:value-of select="concat('&#10; // read-only attribute ', $ifname, '::', $attrname, ' of type ', $attrtype, '&#10;')" />
986 </xsl:when>
987 <xsl:otherwise>
988 <xsl:value-of select="concat('&#10; // read/write attribute ', $ifname, '::', $attrname, ' of type ', $attrtype, '&#10;')" />
989 </xsl:otherwise>
990 </xsl:choose>
991 <!-- emit getter method -->
992 <xsl:variable name="gettername"><xsl:call-template name="makeGetterName"><xsl:with-param name="attrname" select="$attrname" /></xsl:call-template></xsl:variable>
993 <xsl:variable name="jaxwsGetter"><xsl:call-template name="makeJaxwsMethod"><xsl:with-param name="ifname" select="$ifname" /><xsl:with-param name="methodname" select="$gettername" /></xsl:call-template></xsl:variable>
994 <xsl:variable name="gluegettertype">
995 <xsl:call-template name="typeIdl2Glue">
996 <xsl:with-param name="ifname" select="$ifname" />
997 <xsl:with-param name="method" select="$gettername" />
998 <xsl:with-param name="name" select="$attrname" />
999 <xsl:with-param name="type" select="$attrtype" />
1000 <xsl:with-param name="safearray" select="@safearray" />
1001 </xsl:call-template>
1002 </xsl:variable>
1003 <xsl:variable name="javagettertype">
1004 <xsl:call-template name="typeIdl2Java">
1005 <xsl:with-param name="ifname" select="$ifname" />
1006 <xsl:with-param name="method" select="$gettername" />
1007 <xsl:with-param name="name" select="$attrname" />
1008 <xsl:with-param name="type" select="$attrtype" />
1009 <xsl:with-param name="safearray" select="@safearray" />
1010 </xsl:call-template>
1011 </xsl:variable>
1012 <xsl:value-of select="concat(' public ', $gluegettertype, ' ', $gettername, '() {&#10;')" />
1013 <xsl:text> try {&#10;</xsl:text>
1014 <xsl:value-of select="concat(' ', $javagettertype, ' retVal = port.', $jaxwsGetter, '(_this);&#10;')" />
1015 <xsl:variable name="wrapped">
1016 <xsl:call-template name="cookOutParam">
1017 <xsl:with-param name="ifname" select="$ifname" />
1018 <xsl:with-param name="method" select="$gettername" />
1019 <xsl:with-param name="value" select="'retVal'" />
1020 <xsl:with-param name="idltype" select="$attrtype" />
1021 <xsl:with-param name="safearray" select="@safearray" />
1022 </xsl:call-template>
1023 </xsl:variable>
1024 <xsl:value-of select="concat(' return ', $wrapped, ';&#10;')" />
1025 <xsl:text> } catch (InvalidObjectFaultMsg e) {&#10;</xsl:text>
1026 <xsl:text> throw new WebServiceException(e);&#10;</xsl:text>
1027 <xsl:text> } catch (RuntimeFaultMsg e) {&#10;</xsl:text>
1028 <xsl:text> throw new WebServiceException(e);&#10;</xsl:text>
1029 <xsl:text> }&#10;</xsl:text>
1030 <xsl:text> }&#10;</xsl:text>
1031 <xsl:if test="not(@readonly='yes')">
1032 <!-- emit setter -->
1033 <xsl:variable name="settername"><xsl:call-template name="makeSetterName"><xsl:with-param name="attrname" select="$attrname" /></xsl:call-template></xsl:variable>
1034 <xsl:variable name="jaxwsSetter"><xsl:call-template name="makeJaxwsMethod"><xsl:with-param name="ifname" select="$ifname" /><xsl:with-param name="methodname" select="$settername" /></xsl:call-template></xsl:variable>
1035 <xsl:variable name="javasettertype">
1036 <xsl:call-template name="typeIdl2Java">
1037 <xsl:with-param name="ifname" select="$ifname" />
1038 <xsl:with-param name="method" select="$settername" />
1039 <xsl:with-param name="name" select="$attrname" />
1040 <xsl:with-param name="type" select="$attrtype" />
1041 </xsl:call-template>
1042 </xsl:variable>
1043 <xsl:value-of select="concat(' public void ', $settername, '(', $javasettertype, ' value) {&#10;')" />
1044 <xsl:text> try {&#10;</xsl:text>
1045 <xsl:value-of select="concat(' port.', $jaxwsSetter, '(_this, value);&#10;')" />
1046 <xsl:text> } catch (InvalidObjectFaultMsg e) {&#10;</xsl:text>
1047 <xsl:text> throw new WebServiceException(e);&#10;</xsl:text>
1048 <xsl:text> } catch (RuntimeFaultMsg e) {&#10;</xsl:text>
1049 <xsl:text> throw new WebServiceException(e);&#10;</xsl:text>
1050 <xsl:text> }&#10;</xsl:text>
1051 <xsl:text> }&#10;</xsl:text>
1052 </xsl:if>
1053 </xsl:otherwise>
1054 </xsl:choose>
1055 </xsl:for-each> <!-- attribute -->
1056
1057 <!-- emit real methods -->
1058 <xsl:for-each select="method">
1059 <xsl:variable name="methodname"><xsl:value-of select="@name" /></xsl:variable>
1060 <xsl:variable name="portArg">
1061 <xsl:if test="not($wsmap='global')">
1062 <xsl:value-of select="'_this'"/>
1063 </xsl:if>
1064 </xsl:variable>
1065
1066 <!-- method header: return value "int", method name, soap arguments -->
1067 <!-- skip this method if it has parameters of a type that has wsmap="suppress" -->
1068 <xsl:choose>
1069 <xsl:when test=" (param[@type=($G_setSuppressedInterfaces/@name)])
1070 or (param[@mod='ptr'])" >
1071 <xsl:comment><xsl:value-of select="concat('Skipping method ', $methodname, ' for it has parameters with suppressed types')" /></xsl:comment>
1072 </xsl:when>
1073 <xsl:otherwise>
1074 <xsl:variable name="fHasReturnParms" select="param[@dir='return']" />
1075 <xsl:variable name="fHasOutParms" select="param[@dir='out']" />
1076
1077 <xsl:value-of select="concat('&#10; /* method ', $ifname, '::', $methodname, '(')" />
1078 <xsl:for-each select="param">
1079 <xsl:value-of select="concat('&#10; [', @dir, '] ', @type, ' ', @name)" />
1080 <xsl:if test="@safearray='yes'">
1081 <xsl:text>[]</xsl:text>
1082 </xsl:if>
1083 <xsl:if test="not(position()=last())">
1084 <xsl:text>,</xsl:text>
1085 </xsl:if>
1086 </xsl:for-each>
1087 <xsl:text>)&#10; */&#10;</xsl:text>
1088 <!-- method implementation -->
1089 <xsl:variable name="returnidltype" select="param[@dir='return']/@type" />
1090 <xsl:variable name="returnidlsafearray" select="param[@dir='return']/@safearray" />
1091 <xsl:variable name="returngluetype">
1092 <xsl:choose>
1093 <xsl:when test="$returnidltype">
1094 <xsl:call-template name="typeIdl2Glue">
1095 <xsl:with-param name="ifname" select="$ifname" />
1096 <xsl:with-param name="method" select="$methodname" />
1097 <xsl:with-param name="name" select="@name" />
1098 <xsl:with-param name="type" select="$returnidltype" />
1099 <xsl:with-param name="safearray" select="param[@dir='return']/@safearray" />
1100 </xsl:call-template>
1101 </xsl:when>
1102 <xsl:otherwise>
1103 <xsl:text>void</xsl:text>
1104 </xsl:otherwise>
1105 </xsl:choose>
1106 </xsl:variable>
1107 <xsl:value-of select="concat(' public ', $returngluetype, ' ', $methodname, '(')" />
1108 <!-- make a set of all parameters with in and out direction -->
1109 <xsl:variable name="paramsinout" select="param[@dir='in' or @dir='out']" />
1110 <xsl:for-each select="exsl:node-set($paramsinout)">
1111 <xsl:variable name="paramgluetype">
1112 <xsl:call-template name="typeIdl2Glue">
1113 <xsl:with-param name="ifname" select="$ifname" />
1114 <xsl:with-param name="method" select="$methodname" />
1115 <xsl:with-param name="name" select="@name" />
1116 <xsl:with-param name="type" select="@type" />
1117 <xsl:with-param name="safearray" select="@safearray" />
1118 </xsl:call-template>
1119 </xsl:variable>
1120 <xsl:choose>
1121 <xsl:when test="@dir='out'">
1122 <xsl:value-of select="concat('Holder&lt;', $paramgluetype, '&gt; ', @name)" />
1123 </xsl:when>
1124 <xsl:otherwise>
1125 <xsl:value-of select="concat($paramgluetype, ' ', @name)" />
1126 </xsl:otherwise>
1127 </xsl:choose>
1128 <xsl:if test="not(position()=last())">
1129 <xsl:text>, </xsl:text>
1130 </xsl:if>
1131 </xsl:for-each>
1132 <xsl:text>) {&#10;</xsl:text>
1133 <xsl:text> try {&#10;</xsl:text>
1134 <xsl:if test="param[@dir='out']">
1135 <xsl:for-each select="param[@dir='out']">
1136 <xsl:variable name="paramtype" select="@type" />
1137 <xsl:if test="//interface[@name=$paramtype] or $paramtype='$unknown'">
1138 <xsl:choose>
1139 <xsl:when test="@safearray='yes'">
1140 <xsl:value-of select="concat(' Holder&lt;List&lt;String&gt;&gt; tmp', @name, ' = new Holder&lt;List&lt;String&gt;&gt;(); &#10;')" />
1141 </xsl:when>
1142 <xsl:otherwise>
1143 <xsl:value-of select="concat(' Holder&lt;String&gt; tmp', @name, ' = new Holder&lt;String&gt;(); &#10;')" />
1144 </xsl:otherwise>
1145 </xsl:choose>
1146 </xsl:if>
1147 </xsl:for-each>
1148 </xsl:if>
1149
1150 <xsl:text> </xsl:text>
1151
1152 <!-- make the function call: first have a stack variable for the return value, if any -->
1153 <!-- XSLT doesn't allow variable override in inner blocks -->
1154 <xsl:variable name="retValValue">
1155 <xsl:choose>
1156 <xsl:when test="param[@dir='out']">
1157 <xsl:value-of select="'retVal.value'"/>
1158 </xsl:when>
1159 <xsl:otherwise>
1160 <xsl:value-of select="'retVal'"/>
1161 </xsl:otherwise>
1162 </xsl:choose>
1163 </xsl:variable>
1164
1165 <xsl:if test="$returnidltype">
1166 <xsl:variable name="javarettype">
1167 <xsl:call-template name="typeIdl2Java">
1168 <xsl:with-param name="ifname" select="$ifname" />
1169 <xsl:with-param name="method" select="$methodname" />
1170 <xsl:with-param name="name" select="@name" />
1171 <xsl:with-param name="type" select="$returnidltype" />
1172 <xsl:with-param name="safearray" select="$returnidlsafearray" />
1173 </xsl:call-template>
1174 </xsl:variable>
1175 <xsl:choose>
1176 <xsl:when test="param[@dir='out']">
1177 <!-- create a new object for return value -->
1178 <xsl:value-of select="
1179 concat('Holder&lt;', $javarettype, '&gt;',
1180 ' ', 'retVal = new Holder&lt;', $javarettype,
1181 '&gt;();&#xa; ')"/>
1182 </xsl:when>
1183 <xsl:otherwise>
1184 <xsl:value-of select="$javarettype"/>
1185 <xsl:text> retVal = </xsl:text>
1186 </xsl:otherwise>
1187 </xsl:choose>
1188 </xsl:if>
1189 <!-- function name and arguments -->
1190 <xsl:variable name="jaxwsmethod"><xsl:call-template name="makeJaxwsMethod"><xsl:with-param name="ifname" select="$ifname" /><xsl:with-param name="methodname" select="$methodname" /></xsl:call-template></xsl:variable>
1191 <xsl:value-of select="concat('port.', $jaxwsmethod, '(', $portArg)" />
1192 <xsl:if test="$paramsinout and not($portArg='')">
1193 <xsl:text>, </xsl:text>
1194 </xsl:if>
1195 <!-- jax-ws has an oddity: if both out params and a return value exist, then the return value is moved to the function's argument list... -->
1196 <xsl:choose>
1197 <xsl:when test="param[@dir='out'] and param[@dir='return']">
1198 <xsl:for-each select="param">
1199 <xsl:choose>
1200 <xsl:when test="@dir='return'">
1201 <xsl:text>retVal</xsl:text>
1202 </xsl:when>
1203 <xsl:otherwise>
1204 <xsl:call-template name="emitArgInMethodImpl">
1205 <xsl:with-param name="paramname" select="@name" />
1206 <xsl:with-param name="paramtype" select="@type" />
1207 </xsl:call-template>
1208 </xsl:otherwise>
1209 </xsl:choose>
1210 </xsl:for-each>
1211 </xsl:when>
1212 <xsl:otherwise>
1213 <xsl:for-each select="$paramsinout">
1214 <xsl:call-template name="emitArgInMethodImpl">
1215 <xsl:with-param name="paramname" select="@name" />
1216 <xsl:with-param name="paramtype" select="@type" />
1217 </xsl:call-template>
1218 </xsl:for-each>
1219 </xsl:otherwise>
1220 </xsl:choose>
1221 <xsl:text>);&#10;</xsl:text>
1222 <!-- now copy temp out parameters to their actual destination -->
1223 <xsl:for-each select="param[@dir='out']">
1224 <xsl:variable name="paramtype" select="@type" />
1225 <xsl:if test="//interface[@name=$paramtype] or $paramtype='$unknown'">
1226 <xsl:variable name="paramname" select="@name" />
1227 <xsl:variable name="wrapped">
1228 <xsl:call-template name="cookOutParam">
1229 <xsl:with-param name="ifname" select="$ifname" />
1230 <xsl:with-param name="method" select="$methodname" />
1231 <xsl:with-param name="value" select="concat('tmp',@name,'.value')" />
1232 <xsl:with-param name="idltype" select="@type" />
1233 <xsl:with-param name="safearray" select="@safearray" />
1234 </xsl:call-template>
1235 </xsl:variable>
1236 <xsl:value-of select="concat(' ',$paramname,'.value = ',
1237 $wrapped,';&#10;')"/>
1238 </xsl:if>
1239 </xsl:for-each>
1240 <!-- next line with return + glue type -->
1241 <xsl:if test="$returnidltype">
1242 <xsl:variable name="retval">
1243 <xsl:call-template name="cookOutParam">
1244 <xsl:with-param name="ifname" select="$ifname" />
1245 <xsl:with-param name="method" select="$methodname" />
1246 <xsl:with-param name="value" select="$retValValue" />
1247 <xsl:with-param name="idltype" select="$returnidltype" />
1248 <xsl:with-param name="safearray" select="$returnidlsafearray" />
1249 </xsl:call-template>
1250 </xsl:variable>
1251 <xsl:value-of select="concat(' return ', $retval, ';&#10;')"/>
1252 </xsl:if>
1253 <xsl:text> } catch (InvalidObjectFaultMsg e) {&#10;</xsl:text>
1254 <xsl:text> throw new WebServiceException(e);&#10;</xsl:text>
1255 <xsl:text> } catch (RuntimeFaultMsg e) {&#10;</xsl:text>
1256 <xsl:text> throw new WebServiceException(e);&#10;</xsl:text>
1257 <xsl:text> }&#10;</xsl:text>
1258 <xsl:text> }&#10;</xsl:text>
1259 </xsl:otherwise>
1260 </xsl:choose>
1261 </xsl:for-each>
1262
1263 </xsl:otherwise>
1264 </xsl:choose>
1265 <!-- end of class -->
1266 <xsl:text>}&#10;</xsl:text>
1267 <xsl:value-of select="concat('&#10;// ##### ENDFILE &quot;', $filename, '.java&quot;&#10;&#10;')" />
1268 <xsl:call-template name="endFile">
1269 <xsl:with-param name="file" select="concat($filename, '.java')" />
1270 </xsl:call-template>
1271 </xsl:if>
1272 </xsl:for-each>
1273
1274<!-- <xsl:apply-templates /> -->
1275</xsl:template>
1276
1277<!-- - - - - - - - - - - - - - - - - - - - - - -
1278 if
1279 - - - - - - - - - - - - - - - - - - - - - - -->
1280
1281<!--
1282 * ignore all |if|s except those for WSDL target
1283-->
1284<xsl:template match="if">
1285 <xsl:if test="@target='wsdl'">
1286 <xsl:apply-templates/>
1287 </xsl:if>
1288</xsl:template>
1289
1290<!-- - - - - - - - - - - - - - - - - - - - - - -
1291 cpp
1292 - - - - - - - - - - - - - - - - - - - - - - -->
1293
1294<xsl:template match="cpp">
1295<!-- ignore this -->
1296</xsl:template>
1297
1298<!-- - - - - - - - - - - - - - - - - - - - - - -
1299 library
1300 - - - - - - - - - - - - - - - - - - - - - - -->
1301
1302<xsl:template match="library">
1303 <xsl:apply-templates />
1304</xsl:template>
1305
1306<!-- - - - - - - - - - - - - - - - - - - - - - -
1307 class
1308 - - - - - - - - - - - - - - - - - - - - - - -->
1309
1310<xsl:template match="module/class">
1311<!-- TODO swallow for now -->
1312</xsl:template>
1313
1314<!-- - - - - - - - - - - - - - - - - - - - - - -
1315 enum
1316 - - - - - - - - - - - - - - - - - - - - - - -->
1317
1318<xsl:template match="enum">
1319</xsl:template>
1320
1321<!-- - - - - - - - - - - - - - - - - - - - - - -
1322 const
1323 - - - - - - - - - - - - - - - - - - - - - - -->
1324
1325<!--
1326<xsl:template match="const">
1327 <xsl:apply-templates />
1328</xsl:template>
1329-->
1330
1331<!-- - - - - - - - - - - - - - - - - - - - - - -
1332 desc
1333 - - - - - - - - - - - - - - - - - - - - - - -->
1334
1335<xsl:template match="desc">
1336<!-- TODO swallow for now -->
1337</xsl:template>
1338
1339<!-- - - - - - - - - - - - - - - - - - - - - - -
1340 note
1341 - - - - - - - - - - - - - - - - - - - - - - -->
1342
1343<xsl:template match="note">
1344<!-- TODO -->
1345 <xsl:apply-templates />
1346</xsl:template>
1347
1348<!-- - - - - - - - - - - - - - - - - - - - - - -
1349 interface
1350 - - - - - - - - - - - - - - - - - - - - - - -->
1351
1352<xsl:template match="interface">
1353
1354</xsl:template>
1355
1356
1357</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