VirtualBox

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

Last change on this file since 22142 was 22142, checked in by vboxsync, 16 years ago

Java glue: fixed memory leaks on error path for VDI, make port reusable only certain number of times

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

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