VirtualBox

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

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

Java WS glue: better struct treatment, allow using struct fields in natural way

  • Property svn:eol-style set to native
File size: 53.4 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.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 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]/@wsmap='struct' or //interface[@name=$origname]/@wsmap='struct'">
115 <xsl:value-of select="concat($G_virtualBoxPackage2, concat('.', $name))" />
116 </xsl:when>
117 <xsl:when test="//interface[@name=$name]">
118 <xsl:value-of select="concat($G_virtualBoxPackage2, concat('.', $name))" />
119 </xsl:when>
120 <xsl:otherwise>
121 <xsl:call-template name="fatalError">
122 <xsl:with-param name="msg" select="concat('fullClassName: Type &quot;', $name, '&quot; is not supported.')" />
123 </xsl:call-template>
124 </xsl:otherwise>
125 </xsl:choose>
126</xsl:template>
127
128<!--
129 typeIdl2Glue: converts $type into a type as used by the java glue code.
130 For example, for an XIDL IMachineCollection, this will return
131 "List<com.sun.xml.ws.commons.virtualbox.IMachine>".
132 -->
133<xsl:template name="typeIdl2Glue">
134 <xsl:param name="ifname" />
135 <xsl:param name="method" />
136 <xsl:param name="name" />
137 <xsl:param name="type" />
138 <xsl:param name="safearray" />
139 <xsl:param name="forceelem" />
140
141 <xsl:variable name="needarray" select="($safearray='yes' or //collection[@name=$type]) and not($forceelem='yes')" />
142
143 <xsl:if test="$needarray">
144 <xsl:value-of select="'List&lt;'" />
145 </xsl:if>
146
147 <!-- look up Java type from IDL type from table array in websrv-shared.inc.xsl -->
148 <xsl:variable name="javatypefield" select="exsl:node-set($G_aSharedTypes)/type[@idlname=$type]/@javaname" />
149
150 <xsl:choose>
151 <xsl:when test="string-length($javatypefield)">
152 <xsl:value-of select="$javatypefield" />
153 </xsl:when>
154 <!-- not a standard type: then it better be one of the types defined in the XIDL -->
155 <xsl:when test="$type='$unknown'">IUnknown</xsl:when>
156 <xsl:otherwise>
157 <xsl:call-template name="fullClassName">
158 <xsl:with-param name="name" select="$type" />
159 <xsl:with-param name="collPrefix" select="''"/>
160 </xsl:call-template>
161 </xsl:otherwise>
162 </xsl:choose>
163
164 <xsl:if test="$needarray">
165 <xsl:value-of select="'&gt;'" />
166 </xsl:if>
167</xsl:template>
168
169<!--
170 typeIdl2Java: converts $type into a type as used by the JAX-WS backend.
171 For example, for an XIDL IMachineCollection, this will return
172 "ArrayOfIMachine".
173 -->
174<xsl:template name="typeIdl2Java">
175 <xsl:param name="ifname" />
176 <xsl:param name="method" />
177 <xsl:param name="name" />
178 <xsl:param name="type" />
179 <xsl:param name="safearray" />
180
181 <xsl:if test="$safearray">
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="$safearray">
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:value-of select="concat('Helper.wrap2(',$elemtype, '.class, port, ', $value,')')"/>
254 </xsl:when>
255 <xsl:otherwise>
256 <xsl:value-of select="concat('Helper.wrap(',$elemtype, '.class, port, ', $value,')')"/>
257 </xsl:otherwise>
258 </xsl:choose>
259 </xsl:when>
260 <xsl:otherwise>
261 <xsl:variable name="gluetype">
262 <xsl:call-template name="typeIdl2Glue">
263 <xsl:with-param name="ifname" select="$ifname" />
264 <xsl:with-param name="method" select="$methodname" />
265 <xsl:with-param name="name" select="$value" />
266 <xsl:with-param name="type" select="$idltype" />
267 <xsl:with-param name="safearray" select="$safearray" />
268 </xsl:call-template>
269 </xsl:variable>
270 <xsl:choose>
271 <xsl:when test="$isstruct">
272 <xsl:value-of select="concat('(', $value, ' != null) ? new ', $gluetype, '(', $value,', port) : null')" />
273 </xsl:when>
274 <xsl:otherwise>
275 <!-- if the MOR string is empty, that means NULL, so return NULL instead of an object then -->
276 <xsl:value-of select="concat('(', $value, '.length() > 0) ? new ', $gluetype, '(', $value,', port) : null')" />
277 </xsl:otherwise>
278 </xsl:choose>
279 </xsl:otherwise>
280 </xsl:choose>
281 </xsl:when>
282 <xsl:otherwise>
283 <xsl:value-of select="$value"/>
284 </xsl:otherwise>
285 </xsl:choose>
286</xsl:template>
287
288<xsl:template name="genStructWrapper">
289 <xsl:param name="ifname" select="@name" />
290
291 <xsl:value-of select="concat(' private ', $G_virtualBoxPackage,'.',$ifname, ' real;&#10;')"/>
292 <xsl:value-of select="' private VboxPortType port;&#10;&#10;'"/>
293
294 <xsl:value-of select="concat(' public ', $ifname, '(', $G_virtualBoxPackage,'.',$ifname,' real, VboxPortType port) {&#10; this.real = real; &#10; this.port = port; &#10; }&#10;')"/>
295 <xsl:for-each select="attribute">
296 <xsl:variable name="attrname"><xsl:value-of select="@name" /></xsl:variable>
297 <xsl:variable name="attrtype"><xsl:value-of select="@type" /></xsl:variable>
298 <xsl:variable name="attrreadonly"><xsl:value-of select="@readonly" /></xsl:variable>
299 <xsl:variable name="attrsafearray"><xsl:value-of select="@safearray" /></xsl:variable>
300 <xsl:choose>
301 <xsl:when test="$attrreadonly='yes'">
302 <xsl:value-of select="concat('&#10; // read-only attribute ', $ifname, '::', $attrname, ' of type ', $attrtype, '&#10;')" />
303
304 </xsl:when>
305 <xsl:otherwise>
306 <xsl:value-of select="concat('&#10; // read/write attribute ', $ifname, '::', $attrname, ' of type ', $attrtype, '&#10;')" />
307 </xsl:otherwise>
308 </xsl:choose>
309
310 <!-- emit getter method -->
311 <xsl:variable name="gettername">
312 <xsl:choose>
313 <!-- Stupid, but boolean getters called isFoo(), not getFoo() -->
314 <xsl:when test="$attrtype = 'boolean'">
315 <xsl:variable name="capsname">
316 <xsl:call-template name="capitalize">
317 <xsl:with-param name="str" select="$attrname" />
318 </xsl:call-template>
319 </xsl:variable>
320 <xsl:value-of select="concat('is', $capsname)" />
321 </xsl:when>
322 <xsl:otherwise>
323 <xsl:call-template name="makeGetterName">
324 <xsl:with-param name="attrname" select="$attrname" />
325 </xsl:call-template>
326 </xsl:otherwise>
327 </xsl:choose>
328 </xsl:variable>
329 <xsl:variable name="gluegettertype">
330 <xsl:call-template name="typeIdl2Glue">
331 <xsl:with-param name="ifname" select="$ifname" />
332 <xsl:with-param name="method" select="$gettername" />
333 <xsl:with-param name="name" select="$attrname" />
334 <xsl:with-param name="type" select="$attrtype" />
335 <xsl:with-param name="safearray" select="@safearray" />
336 </xsl:call-template>
337 </xsl:variable>
338 <xsl:variable name="javagettertype">
339 <xsl:call-template name="typeIdl2Java">
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:value-of select="concat(' public ', $gluegettertype, ' ', $gettername, '() {&#10;')" />
348 <xsl:value-of select="concat(' ', $javagettertype, ' retVal = real.', $gettername, '();&#10;')" />
349 <xsl:variable name="wrapped">
350 <xsl:call-template name="cookOutParam">
351 <xsl:with-param name="ifname" select="$ifname" />
352 <xsl:with-param name="method" select="$gettername" />
353 <xsl:with-param name="value" select="'retVal'" />
354 <xsl:with-param name="idltype" select="$attrtype" />
355 <xsl:with-param name="safearray" select="@safearray" />
356 </xsl:call-template>
357 </xsl:variable>
358 <xsl:value-of select="concat(' return ', $wrapped, ';&#10;')" />
359 <xsl:text> }&#10;</xsl:text>
360
361 </xsl:for-each>
362
363</xsl:template>
364
365
366<xsl:template name="emitArgInMethodImpl">
367 <xsl:param name="paramname" select="@name" />
368 <xsl:param name="paramtype" select="@type" />
369 <!-- per-argument special type handling -->
370 <xsl:choose>
371 <xsl:when test="//interface[@name=$paramtype] or $paramtype='$unknown'">
372 <xsl:choose>
373 <xsl:when test="@dir='out'">
374 <xsl:value-of select="concat('tmp', $paramname)" />
375 </xsl:when>
376 <xsl:otherwise>
377 <xsl:choose>
378 <xsl:when test="@safearray='yes'">
379 <xsl:value-of select="concat('Helper.unwrap(',$paramname,')')"/>
380 </xsl:when>
381 <xsl:otherwise>
382 <xsl:value-of select="concat('((', $paramname, ' == null)?null:', $paramname, '.getRef())')" />
383 </xsl:otherwise>
384 </xsl:choose>
385 </xsl:otherwise>
386 </xsl:choose>
387 </xsl:when>
388 <xsl:otherwise>
389 <xsl:value-of select="$paramname" />
390 </xsl:otherwise>
391 </xsl:choose>
392 <xsl:if test="not(position()=last())">
393 <xsl:text>, </xsl:text>
394 </xsl:if>
395</xsl:template>
396
397<xsl:template name="startFile">
398 <xsl:param name="file" />
399
400 <xsl:value-of select="concat('&#10;// ##### BEGINFILE &quot;', $file, '&quot;&#10;&#10;')" />
401 <xsl:call-template name="fileheader">
402 <xsl:with-param name="name" select="$file" />
403 </xsl:call-template>
404package <xsl:value-of select="$G_virtualBoxPackage2" />;
405
406import <xsl:value-of select="$G_virtualBoxPackage" />.VboxPortType;
407import <xsl:value-of select="$G_virtualBoxPackage" />.VboxService;
408import <xsl:value-of select="$G_virtualBoxPackage" />.InvalidObjectFaultMsg;
409import <xsl:value-of select="$G_virtualBoxPackage" />.RuntimeFaultMsg;
410import javax.xml.ws.WebServiceException;
411</xsl:template>
412
413<xsl:template name="endFile">
414 <xsl:param name="file" />
415 <xsl:value-of select="concat('&#10;// ##### ENDFILE &quot;', $file, '&quot;&#10;&#10;')" />
416</xsl:template>
417
418<!-- - - - - - - - - - - - - - - - - - - - - - -
419 root match
420 - - - - - - - - - - - - - - - - - - - - - - -->
421
422<xsl:template match="/idl">
423 <xsl:if test="not($G_vboxApiSuffix)">
424 <xsl:call-template name="fatalError">
425 <xsl:with-param name="msg" select="'G_vboxApiSuffix must be given'" />
426 </xsl:call-template>
427 </xsl:if>
428 <xsl:call-template name="startFile">
429 <xsl:with-param name="file" select="'IUnknown.java'" />
430 </xsl:call-template>
431
432 <xsl:text><![CDATA[
433public class IUnknown
434{
435 protected String _this; /* almost final, could only be set in finalizer */
436 protected final VboxPortType port;
437
438 public IUnknown(String _this, VboxPortType port)
439 {
440 this._this = _this;
441 this.port = port;
442 }
443
444 public final String getRef()
445 {
446 return _this;
447 }
448
449 public final VboxPortType getRemoteWSPort()
450 {
451 return port;
452 }
453
454 public synchronized void releaseRemote() throws WebServiceException
455 {
456 if (_this == null) {
457 return;
458 }
459 try {
460 port.iManagedObjectRefRelease(_this);
461 _this = null;
462 } catch (InvalidObjectFaultMsg e) {
463 throw new WebServiceException(e);
464 } catch (RuntimeFaultMsg e) {
465 throw new WebServiceException(e);
466 }
467 }
468
469 /*
470 protected void finalize()
471 {
472 try {
473 releaseRemote();
474 } catch (WebServiceException e) {
475 }
476 } */
477
478 // may need to support some sort of QueryInterface, to make this class useable
479 // not only as common baseclass
480}
481]]></xsl:text>
482
483 <xsl:call-template name="endFile">
484 <xsl:with-param name="file" select="'IUnknown.java'" />
485 </xsl:call-template>
486
487 <xsl:call-template name="startFile">
488 <xsl:with-param name="file" select="'Helper.java'" />
489 </xsl:call-template>
490
491<xsl:text><![CDATA[
492
493import java.util.List;
494import java.util.ArrayList;
495import java.util.Collections;
496import java.lang.reflect.Constructor;
497import java.lang.reflect.InvocationTargetException;
498
499class Helper {
500 public static <T> List<T> wrap(Class<T> wrapperClass, VboxPortType pt, List<String> thisPtrs) {
501 try {
502 if(thisPtrs==null) return Collections.emptyList();
503
504 Constructor<T> c = wrapperClass.getConstructor(String.class, VboxPortType.class);
505 List<T> ret = new ArrayList<T>(thisPtrs.size());
506 for (String thisPtr : thisPtrs) {
507 ret.add(c.newInstance(thisPtr,pt));
508 }
509 return ret;
510 } catch (NoSuchMethodException e) {
511 throw new AssertionError(e);
512 } catch (InstantiationException e) {
513 throw new AssertionError(e);
514 } catch (IllegalAccessException e) {
515 throw new AssertionError(e);
516 } catch (InvocationTargetException e) {
517 throw new AssertionError(e);
518 }
519 }
520
521
522 public static <T, T1> List<T> wrap2(Class<T> wrapperClass, VboxPortType pt, List<T1> thisPtrs) {
523 try {
524 if(thisPtrs==null) return Collections.emptyList();
525
526 Constructor<T> c = wrapperClass.getConstructor(String.class, VboxPortType.class);
527 List<T> ret = new ArrayList<T>(thisPtrs.size());
528 for (T1 thisPtr : thisPtrs) {
529 ret.add(c.newInstance(thisPtr,pt));
530 }
531 return ret;
532 } catch (NoSuchMethodException e) {
533 throw new AssertionError(e);
534 } catch (InstantiationException e) {
535 throw new AssertionError(e);
536 } catch (IllegalAccessException e) {
537 throw new AssertionError(e);
538 } catch (InvocationTargetException e) {
539 throw new AssertionError(e);
540 }
541 }
542
543 public static <T extends IUnknown> List<String> unwrap(List<T> thisPtrs) {
544 if (thisPtrs==null) return Collections.emptyList();
545
546 List<String> ret = new ArrayList<String>();
547 for (T obj : thisPtrs) {
548 ret.add(obj.getRef());
549 }
550 return ret;
551 }
552}
553]]></xsl:text>
554
555 <xsl:call-template name="endFile">
556 <xsl:with-param name="file" select="'Helper.java'" />
557 </xsl:call-template>
558
559 <xsl:call-template name="startFile">
560 <xsl:with-param name="file" select="'IWebsessionManager.java'" />
561 </xsl:call-template>
562
563
564import java.net.URL;
565import java.math.BigInteger;
566import java.util.List;
567import java.util.Map;
568import java.util.HashMap;
569import javax.xml.namespace.QName;
570import javax.xml.ws.BindingProvider;
571import javax.xml.ws.Holder;
572import javax.xml.ws.WebServiceException;
573
574class PortPool
575{
576 private final static String wsdlFile = <xsl:value-of select="$G_virtualBoxWsdl" />;
577
578 <xsl:text><![CDATA[
579 private Map<VboxPortType, Integer> known;
580 private boolean initStarted;
581 private VboxService svc;
582
583 PortPool(boolean usePreinit)
584 {
585 known = new HashMap<VboxPortType, Integer>();
586
587 if (usePreinit)
588 {
589 new Thread(new Runnable()
590 {
591 public void run()
592 {
593 // need to sync on something else but 'this'
594 synchronized (known)
595 {
596 initStarted = true;
597 known.notify();
598 }
599
600 preinit();
601 }
602 }).start();
603
604 synchronized (known)
605 {
606 while (!initStarted)
607 {
608 try {
609 known.wait();
610 } catch (InterruptedException e) {
611 break;
612 }
613 }
614 }
615 }
616 }
617
618 private synchronized void preinit()
619 {
620 VboxPortType port = getPort();
621 releasePort(port);
622 }
623
624 synchronized VboxPortType getPort()
625 {
626 VboxPortType port = null;
627 for (VboxPortType cur: known.keySet())
628 {
629 if (known.get(cur) == 0)
630 {
631 port = cur;
632 break;
633 }
634 }
635
636 if (port == null)
637 {
638 if (svc == null) {
639 URL wsdl = PortPool.class.getClassLoader().getResource(wsdlFile);
640 if (wsdl == null)
641 throw new LinkageError(wsdlFile+" not found, but it should have been in the jar");
642 svc = new VboxService(wsdl,
643 new QName("http://www.virtualbox.org/Service",
644 "vboxService"));
645 }
646 port = svc.getVboxServicePort();
647 }
648 known.put(port, new Integer(1));
649 return port;
650 }
651
652 synchronized void releasePort(VboxPortType port)
653 {
654 Integer val = known.get(port);
655 if (val == null || val == 0)
656 {
657 // know you not
658 return;
659 }
660 known.put(port, val - 1);
661 }
662}
663
664public class IWebsessionManager {
665
666 private static PortPool pool = new PortPool(true);
667 protected VboxPortType port;
668
669 public IWebsessionManager(URL url)
670 {
671 connect(url);
672 }
673
674 public IWebsessionManager(String url)
675 {
676 connect(url);
677 }
678
679 public IWebsessionManager(URL url, Map<String, Object> requestContext, Map<String, Object> responseContext)
680 {
681 connect(url.toExternalForm(), requestContext, responseContext);
682 }
683
684 public IWebsessionManager(String url, Map<String, Object> requestContext, Map<String, Object> responseContext)
685 {
686 connect(url, requestContext, responseContext);
687 }
688
689 public void connect(URL url)
690 {
691 connect(url.toExternalForm());
692 }
693
694 public void connect(String url)
695 {
696 this.port = pool.getPort();
697 ((BindingProvider)port).getRequestContext().
698 put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
699 }
700
701 public void connect(String url, Map<String, Object> requestContext, Map<String, Object> responseContext)
702 {
703 this.port = pool.getPort();
704
705 ((BindingProvider)port).getRequestContext();
706 if (requestContext != null)
707 ((BindingProvider)port).getRequestContext().putAll(requestContext);
708
709 if (responseContext != null)
710 ((BindingProvider)port).getResponseContext().putAll(responseContext);
711
712 ((BindingProvider)port).getRequestContext().
713 put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
714 }
715
716
717 public void disconnect(IVirtualBox refIVirtualBox)
718 {
719 logoff(refIVirtualBox);
720 pool.releasePort(port);
721 }
722
723 public void cleanupUnused()
724 {
725 System.gc();
726 Runtime.getRuntime().runFinalization();
727 }
728
729 /* method IWebsessionManager::logon(
730 [in] wstring username,
731 [in] wstring password,
732 [return] IVirtualBox return)
733 */
734 public IVirtualBox logon(String username, String password) {
735 try {
736 String retVal = port.iWebsessionManagerLogon(username, password);
737 return new IVirtualBox(retVal, port);
738 } catch (InvalidObjectFaultMsg e) {
739 throw new WebServiceException(e);
740 } catch (RuntimeFaultMsg e) {
741 throw new WebServiceException(e);
742 }
743 }
744
745 /* method IWebsessionManager::getSessionObject(
746 [in] IVirtualBox refIVirtualBox,
747 [return] ISession return)
748 */
749 public ISession getSessionObject(IVirtualBox refIVirtualBox) {
750 try {
751 String retVal = port.iWebsessionManagerGetSessionObject(((refIVirtualBox == null)?null:refIVirtualBox.getRef()));
752 return new ISession(retVal, port);
753 } catch (InvalidObjectFaultMsg e) {
754 throw new WebServiceException(e);
755 } catch (RuntimeFaultMsg e) {
756 throw new WebServiceException(e);
757 }
758 }
759
760 /* method IWebsessionManager::logoff(
761 [in] IVirtualBox refIVirtualBox)
762 */
763 public void logoff(IVirtualBox refIVirtualBox) {
764 try {
765 port.iWebsessionManagerLogoff(((refIVirtualBox == null)?null:refIVirtualBox.getRef()));
766 } catch (InvalidObjectFaultMsg e) {
767 throw new WebServiceException(e);
768 } catch (RuntimeFaultMsg e) {
769 throw new WebServiceException(e);
770 }
771 }
772}
773]]></xsl:text>
774 <xsl:call-template name="endFile">
775 <xsl:with-param name="file" select="'IWebsessionManager.java'" />
776 </xsl:call-template>
777
778 <xsl:text>// ######## COLLECTIONS&#10;&#10;</xsl:text>
779
780 <xsl:for-each select="//collection">
781 <xsl:variable name="type" select="@type" />
782 <xsl:variable name="arrayoftype" select="concat('ArrayOf', @type)" />
783 <xsl:variable name="filename" select="$arrayoftype" />
784
785 <xsl:value-of select="concat('&#10;// ##### BEGINFILE &quot;', $filename, '.java&quot;&#10;&#10;')" />
786
787 <xsl:call-template name="startFile">
788 <xsl:with-param name="file" select="concat($filename, '.java')" />
789 </xsl:call-template>
790
791 <xsl:text>import java.util.ArrayList;&#10;</xsl:text>
792 <xsl:text>import java.util.List;&#10;</xsl:text>
793 <xsl:text>import javax.xml.bind.annotation.XmlAccessType;&#10;</xsl:text>
794 <xsl:text>import javax.xml.bind.annotation.XmlAccessorType;&#10;</xsl:text>
795 <xsl:text>import javax.xml.bind.annotation.XmlType;&#10;&#10;</xsl:text>
796
797 <xsl:text>@XmlAccessorType(XmlAccessType.FIELD)&#10;</xsl:text>
798 <xsl:value-of select="concat('@XmlType(name = &quot;', $arrayoftype, '&quot;, propOrder = {&#10;')" />
799 <xsl:text> "array"&#10;</xsl:text>
800 <xsl:text>})&#10;&#10;</xsl:text>
801 <xsl:value-of select="concat('public class ', $arrayoftype, ' {&#10;&#10;')" />
802
803 <xsl:text> protected List&lt;String&gt; array;&#10;&#10;</xsl:text>
804
805 <xsl:text> public List&lt;String&gt; getArray() {&#10;</xsl:text>
806 <xsl:text> if (array == null) {&#10;</xsl:text>
807 <xsl:text> array = new ArrayList&lt;String&gt;();&#10;</xsl:text>
808 <xsl:text> }&#10;</xsl:text>
809 <xsl:text> return this.array;&#10;</xsl:text>
810 <xsl:text> }&#10;&#10;</xsl:text>
811 <xsl:text>}&#10;</xsl:text>
812 <xsl:call-template name="endFile">
813 <xsl:with-param name="file" select="concat($filename, '.java')" />
814 </xsl:call-template>
815
816 </xsl:for-each>
817
818 <xsl:text>// ######## ENUMS&#10;&#10;</xsl:text>
819
820 <xsl:for-each select="//enum">
821 <xsl:variable name="enumname" select="@name" />
822 <xsl:variable name="filename" select="$enumname" />
823
824 <xsl:call-template name="startFile">
825 <xsl:with-param name="file" select="concat($filename, '.java')" />
826 </xsl:call-template>
827
828 <xsl:text>import javax.xml.bind.annotation.XmlEnum;&#10;</xsl:text>
829 <xsl:text>import javax.xml.bind.annotation.XmlEnumValue;&#10;</xsl:text>
830 <xsl:text>import javax.xml.bind.annotation.XmlType;&#10;&#10;</xsl:text>
831
832 <xsl:value-of select="concat('@XmlType(name = &quot;', $enumname, '&quot;)&#10;')" />
833 <xsl:text>@XmlEnum&#10;</xsl:text>
834 <xsl:value-of select="concat('public enum ', $enumname, ' {&#10;&#10;')" />
835 <xsl:for-each select="const">
836 <xsl:variable name="enumconst" select="@name" />
837 <xsl:value-of select="concat(' @XmlEnumValue(&quot;', $enumconst, '&quot;)&#10;')" />
838 <xsl:value-of select="concat(' ', $enumconst, '(&quot;', $enumconst, '&quot;)')" />
839 <xsl:choose>
840 <xsl:when test="not(position()=last())">
841 <xsl:text>,&#10;</xsl:text>
842 </xsl:when>
843 <xsl:otherwise>
844 <xsl:text>;&#10;</xsl:text>
845 </xsl:otherwise>
846 </xsl:choose>
847 </xsl:for-each>
848
849 <xsl:text>&#10;</xsl:text>
850 <xsl:text> private final String value;&#10;&#10;</xsl:text>
851
852 <xsl:value-of select="concat(' ', $enumname, '(String v) {&#10;')" />
853 <xsl:text> value = v;&#10;</xsl:text>
854 <xsl:text> }&#10;&#10;</xsl:text>
855
856 <xsl:text> public String value() {&#10;</xsl:text>
857 <xsl:text> return value;&#10;</xsl:text>
858 <xsl:text> }&#10;&#10;</xsl:text>
859
860 <xsl:value-of select="concat(' public static ', $enumname, ' fromValue(String v) {&#10;')" />
861 <xsl:value-of select="concat(' for (', $enumname, ' c: ', $enumname, '. values()) {&#10;')" />
862 <xsl:text> if (c.value.equals(v)) {&#10;</xsl:text>
863 <xsl:text> return c;&#10;</xsl:text>
864 <xsl:text> }&#10;</xsl:text>
865 <xsl:text> }&#10;</xsl:text>
866 <xsl:text> throw new IllegalArgumentException(v);&#10;</xsl:text>
867 <xsl:text> }&#10;&#10;</xsl:text>
868
869 <xsl:text>}&#10;&#10;</xsl:text>
870
871 <xsl:call-template name="endFile">
872 <xsl:with-param name="file" select="concat($filename, '.java')" />
873 </xsl:call-template>
874
875 </xsl:for-each>
876
877 <xsl:text>// ######## INTERFACES &#10;&#10;</xsl:text>
878
879 <xsl:for-each select="//interface">
880 <xsl:variable name="ifname" select="@name" />
881 <xsl:variable name="filename" select="$ifname" />
882 <xsl:variable name="wsmap" select="@wsmap" />
883 <xsl:variable name="wscpp" select="@wscpp" />
884
885 <xsl:if test="not($wsmap='suppress') and not ($wsmap='global')">
886 <xsl:call-template name="startFile">
887 <xsl:with-param name="file" select="concat($filename, '.java')" />
888 </xsl:call-template>
889
890 <xsl:text>import java.math.BigInteger;&#10;</xsl:text>
891 <xsl:text>import java.util.List;&#10;</xsl:text>
892 <xsl:text>import javax.xml.ws.Holder;&#10;</xsl:text>
893 <xsl:text>import javax.xml.ws.WebServiceException;&#10;</xsl:text>
894
895 <xsl:choose>
896 <xsl:when test="$wsmap='struct'">
897 <xsl:value-of select="concat('public class ', $ifname, ' {&#10;&#10;')" />
898 <xsl:call-template name="genStructWrapper">
899 <xsl:with-param name="name" select="$ifname" />
900 </xsl:call-template>
901 </xsl:when>
902
903 <xsl:otherwise>
904 <xsl:variable name="extends" select="//interface[@name=$ifname]/@extends" />
905 <xsl:choose>
906 <xsl:when test="($extends = '$unknown') or ($extends = '$dispatched') or ($extends = '$errorinfo')">
907 <xsl:value-of select="concat('public class ', $ifname, ' extends IUnknown {&#10;&#10;')" />
908 </xsl:when>
909 <xsl:when test="//interface[@name=$extends]">
910 <xsl:value-of select="concat('public class ', $ifname, ' extends ', $extends, ' {&#10;&#10;')" />
911 </xsl:when>
912 <xsl:otherwise>
913 <xsl:call-template name="fatalError">
914 <xsl:with-param name="msg" select="concat('Interface generation: interface &quot;', $ifname, '&quot; has invalid &quot;extends&quot; value ', $extends, '.')" />
915 </xsl:call-template>
916 </xsl:otherwise>>
917 </xsl:choose>
918
919 <!-- interface (class) constructor -->
920 <xsl:value-of select="concat(' public static ', $ifname, ' cast(IUnknown other) {&#10;')" />
921 <xsl:value-of select="concat(' return new ', $ifname,
922 '(other.getRef(), other.getRemoteWSPort());&#10; }&#10;&#10;')"/>
923 <xsl:value-of select="concat(' public ', $ifname, '(String _this, VboxPortType port) {&#10;')" />
924 <xsl:text> super(_this,port);&#10;</xsl:text>
925 <xsl:text> }&#10;</xsl:text>
926
927 <!-- attributes -->
928 <xsl:for-each select="attribute">
929 <xsl:variable name="attrname"><xsl:value-of select="@name" /></xsl:variable>
930 <xsl:variable name="attrtype"><xsl:value-of select="@type" /></xsl:variable>
931 <xsl:variable name="attrreadonly"><xsl:value-of select="@readonly" /></xsl:variable>
932 <xsl:variable name="attrsafearray"><xsl:value-of select="@safearray" /></xsl:variable>
933
934 <xsl:choose>
935 <xsl:when test="( $attrtype=($G_setSuppressedInterfaces/@name) )">
936 <xsl:value-of select="concat('&#10; // Skipping attribute ', $attrtype, ' for it is of suppressed type ', $attrtype, '&#10;')" />
937 </xsl:when>
938 <xsl:otherwise>
939 <xsl:choose>
940 <xsl:when test="@readonly='yes'">
941 <xsl:value-of select="concat('&#10; // read-only attribute ', $ifname, '::', $attrname, ' of type ', $attrtype, '&#10;')" />
942 </xsl:when>
943 <xsl:otherwise>
944 <xsl:value-of select="concat('&#10; // read/write attribute ', $ifname, '::', $attrname, ' of type ', $attrtype, '&#10;')" />
945 </xsl:otherwise>
946 </xsl:choose>
947 <!-- emit getter method -->
948 <xsl:variable name="gettername"><xsl:call-template name="makeGetterName"><xsl:with-param name="attrname" select="$attrname" /></xsl:call-template></xsl:variable>
949 <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>
950 <xsl:variable name="gluegettertype">
951 <xsl:call-template name="typeIdl2Glue">
952 <xsl:with-param name="ifname" select="$ifname" />
953 <xsl:with-param name="method" select="$gettername" />
954 <xsl:with-param name="name" select="$attrname" />
955 <xsl:with-param name="type" select="$attrtype" />
956 <xsl:with-param name="safearray" select="@safearray" />
957 </xsl:call-template>
958 </xsl:variable>
959 <xsl:variable name="javagettertype">
960 <xsl:call-template name="typeIdl2Java">
961 <xsl:with-param name="ifname" select="$ifname" />
962 <xsl:with-param name="method" select="$gettername" />
963 <xsl:with-param name="name" select="$attrname" />
964 <xsl:with-param name="type" select="$attrtype" />
965 <xsl:with-param name="safearray" select="@safearray" />
966 </xsl:call-template>
967 </xsl:variable>
968 <xsl:value-of select="concat(' public ', $gluegettertype, ' ', $gettername, '() {&#10;')" />
969 <xsl:text> try {&#10;</xsl:text>
970 <xsl:value-of select="concat(' ', $javagettertype, ' retVal = port.', $jaxwsGetter, '(_this);&#10;')" />
971 <xsl:variable name="wrapped">
972 <xsl:call-template name="cookOutParam">
973 <xsl:with-param name="ifname" select="$ifname" />
974 <xsl:with-param name="method" select="$gettername" />
975 <xsl:with-param name="value" select="'retVal'" />
976 <xsl:with-param name="idltype" select="$attrtype" />
977 <xsl:with-param name="safearray" select="@safearray" />
978 </xsl:call-template>
979 </xsl:variable>
980 <xsl:value-of select="concat(' return ', $wrapped, ';&#10;')" />
981 <xsl:text> } catch (InvalidObjectFaultMsg e) {&#10;</xsl:text>
982 <xsl:text> throw new WebServiceException(e);&#10;</xsl:text>
983 <xsl:text> } catch (RuntimeFaultMsg e) {&#10;</xsl:text>
984 <xsl:text> throw new WebServiceException(e);&#10;</xsl:text>
985 <xsl:text> }&#10;</xsl:text>
986 <xsl:text> }&#10;</xsl:text>
987 <xsl:if test="not(@readonly='yes')">
988 <!-- emit setter -->
989 <xsl:variable name="settername"><xsl:call-template name="makeSetterName"><xsl:with-param name="attrname" select="$attrname" /></xsl:call-template></xsl:variable>
990 <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>
991 <xsl:variable name="javasettertype">
992 <xsl:call-template name="typeIdl2Java">
993 <xsl:with-param name="ifname" select="$ifname" />
994 <xsl:with-param name="method" select="$settername" />
995 <xsl:with-param name="name" select="$attrname" />
996 <xsl:with-param name="type" select="$attrtype" />
997 </xsl:call-template>
998 </xsl:variable>
999 <xsl:value-of select="concat(' public void ', $settername, '(', $javasettertype, ' value) {&#10;')" />
1000 <xsl:text> try {&#10;</xsl:text>
1001 <xsl:value-of select="concat(' port.', $jaxwsSetter, '(_this, value);&#10;')" />
1002 <xsl:text> } catch (InvalidObjectFaultMsg e) {&#10;</xsl:text>
1003 <xsl:text> throw new WebServiceException(e);&#10;</xsl:text>
1004 <xsl:text> } catch (RuntimeFaultMsg e) {&#10;</xsl:text>
1005 <xsl:text> throw new WebServiceException(e);&#10;</xsl:text>
1006 <xsl:text> }&#10;</xsl:text>
1007 <xsl:text> }&#10;</xsl:text>
1008 </xsl:if>
1009 </xsl:otherwise>
1010 </xsl:choose>
1011 </xsl:for-each> <!-- attribute -->
1012
1013 <!-- emit real methods -->
1014 <xsl:for-each select="method">
1015 <xsl:variable name="methodname"><xsl:value-of select="@name" /></xsl:variable>
1016 <xsl:variable name="portArg">
1017 <xsl:if test="not($wsmap='global')">
1018 <xsl:value-of select="'_this'"/>
1019 </xsl:if>
1020 </xsl:variable>
1021
1022 <!-- method header: return value "int", method name, soap arguments -->
1023 <!-- skip this method if it has parameters of a type that has wsmap="suppress" -->
1024 <xsl:choose>
1025 <xsl:when test=" (param[@type=($G_setSuppressedInterfaces/@name)])
1026 or (param[@mod='ptr'])" >
1027 <xsl:comment><xsl:value-of select="concat('Skipping method ', $methodname, ' for it has parameters with suppressed types')" /></xsl:comment>
1028 </xsl:when>
1029 <xsl:otherwise>
1030 <xsl:variable name="fHasReturnParms" select="param[@dir='return']" />
1031 <xsl:variable name="fHasOutParms" select="param[@dir='out']" />
1032
1033 <xsl:value-of select="concat('&#10; /* method ', $ifname, '::', $methodname, '(')" />
1034 <xsl:for-each select="param">
1035 <xsl:value-of select="concat('&#10; [', @dir, '] ', @type, ' ', @name)" />
1036 <xsl:if test="@safearray='yes'">
1037 <xsl:text>[]</xsl:text>
1038 </xsl:if>
1039 <xsl:if test="not(position()=last())">
1040 <xsl:text>,</xsl:text>
1041 </xsl:if>
1042 </xsl:for-each>
1043 <xsl:text>)&#10; */&#10;</xsl:text>
1044 <!-- method implementation -->
1045 <xsl:variable name="returnidltype" select="param[@dir='return']/@type" />
1046 <xsl:variable name="returnidlsafearray" select="param[@dir='return']/@safearray" />
1047 <xsl:variable name="returngluetype">
1048 <xsl:choose>
1049 <xsl:when test="$returnidltype">
1050 <xsl:call-template name="typeIdl2Glue">
1051 <xsl:with-param name="ifname" select="$ifname" />
1052 <xsl:with-param name="method" select="$methodname" />
1053 <xsl:with-param name="name" select="@name" />
1054 <xsl:with-param name="type" select="$returnidltype" />
1055 <xsl:with-param name="safearray" select="param[@dir='return']/@safearray" />
1056 </xsl:call-template>
1057 </xsl:when>
1058 <xsl:otherwise>
1059 <xsl:text>void</xsl:text>
1060 </xsl:otherwise>
1061 </xsl:choose>
1062 </xsl:variable>
1063 <xsl:value-of select="concat(' public ', $returngluetype, ' ', $methodname, '(')" />
1064 <!-- make a set of all parameters with in and out direction -->
1065 <xsl:variable name="paramsinout" select="param[@dir='in' or @dir='out']" />
1066 <xsl:for-each select="exsl:node-set($paramsinout)">
1067 <xsl:variable name="paramgluetype">
1068 <xsl:call-template name="typeIdl2Glue">
1069 <xsl:with-param name="ifname" select="$ifname" />
1070 <xsl:with-param name="method" select="$methodname" />
1071 <xsl:with-param name="name" select="@name" />
1072 <xsl:with-param name="type" select="@type" />
1073 <xsl:with-param name="safearray" select="@safearray" />
1074 </xsl:call-template>
1075 </xsl:variable>
1076 <xsl:choose>
1077 <xsl:when test="@dir='out'">
1078 <xsl:value-of select="concat('Holder&lt;', $paramgluetype, '&gt; ', @name)" />
1079 </xsl:when>
1080 <xsl:otherwise>
1081 <xsl:value-of select="concat($paramgluetype, ' ', @name)" />
1082 </xsl:otherwise>
1083 </xsl:choose>
1084 <xsl:if test="not(position()=last())">
1085 <xsl:text>, </xsl:text>
1086 </xsl:if>
1087 </xsl:for-each>
1088 <xsl:text>) {&#10;</xsl:text>
1089 <xsl:text> try {&#10;</xsl:text>
1090 <xsl:if test="param[@dir='out']">
1091 <xsl:for-each select="param[@dir='out']">
1092 <xsl:variable name="paramtype" select="@type" />
1093 <xsl:if test="//interface[@name=$paramtype] or $paramtype='$unknown'">
1094 <xsl:choose>
1095 <xsl:when test="@safearray='yes'">
1096 <xsl:value-of select="concat(' Holder&lt;List&lt;String&gt;&gt; tmp', @name, ' = new Holder&lt;List&lt;String&gt;&gt;(); &#10;')" />
1097 </xsl:when>
1098 <xsl:otherwise>
1099 <xsl:value-of select="concat(' Holder&lt;String&gt; tmp', @name, ' = new Holder&lt;String&gt;(); &#10;')" />
1100 </xsl:otherwise>
1101 </xsl:choose>
1102 </xsl:if>
1103 </xsl:for-each>
1104 </xsl:if>
1105
1106 <xsl:text> </xsl:text>
1107
1108 <!-- make the function call: first have a stack variable for the return value, if any -->
1109 <!-- XSLT doesn't allow variable override in inner blocks -->
1110 <xsl:variable name="retValValue">
1111 <xsl:choose>
1112 <xsl:when test="param[@dir='out']">
1113 <xsl:value-of select="'retVal.value'"/>
1114 </xsl:when>
1115 <xsl:otherwise>
1116 <xsl:value-of select="'retVal'"/>
1117 </xsl:otherwise>
1118 </xsl:choose>
1119 </xsl:variable>
1120
1121 <xsl:if test="$returnidltype">
1122 <xsl:variable name="javarettype">
1123 <xsl:call-template name="typeIdl2Java">
1124 <xsl:with-param name="ifname" select="$ifname" />
1125 <xsl:with-param name="method" select="$methodname" />
1126 <xsl:with-param name="name" select="@name" />
1127 <xsl:with-param name="type" select="$returnidltype" />
1128 <xsl:with-param name="safearray" select="$returnidlsafearray" />
1129 </xsl:call-template>
1130 </xsl:variable>
1131 <xsl:choose>
1132 <xsl:when test="param[@dir='out']">
1133 <!-- create a new object for return value -->
1134 <xsl:value-of select="
1135 concat('Holder&lt;', $javarettype, '&gt;',
1136 ' ', 'retVal = new Holder&lt;', $javarettype,
1137 '&gt;();&#xa; ')"/>
1138 </xsl:when>
1139 <xsl:otherwise>
1140 <xsl:value-of select="$javarettype"/>
1141 <xsl:text> retVal = </xsl:text>
1142 </xsl:otherwise>
1143 </xsl:choose>
1144 </xsl:if>
1145 <!-- function name and arguments -->
1146 <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>
1147 <xsl:value-of select="concat('port.', $jaxwsmethod, '(', $portArg)" />
1148 <xsl:if test="$paramsinout and not($portArg='')">
1149 <xsl:text>, </xsl:text>
1150 </xsl:if>
1151 <!-- 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... -->
1152 <xsl:choose>
1153 <xsl:when test="param[@dir='out'] and param[@dir='return']">
1154 <xsl:for-each select="param">
1155 <xsl:choose>
1156 <xsl:when test="@dir='return'">
1157 <xsl:text>retVal</xsl:text>
1158 </xsl:when>
1159 <xsl:otherwise>
1160 <xsl:call-template name="emitArgInMethodImpl">
1161 <xsl:with-param name="paramname" select="@name" />
1162 <xsl:with-param name="paramtype" select="@type" />
1163 </xsl:call-template>
1164 </xsl:otherwise>
1165 </xsl:choose>
1166 </xsl:for-each>
1167 </xsl:when>
1168 <xsl:otherwise>
1169 <xsl:for-each select="$paramsinout">
1170 <xsl:call-template name="emitArgInMethodImpl">
1171 <xsl:with-param name="paramname" select="@name" />
1172 <xsl:with-param name="paramtype" select="@type" />
1173 </xsl:call-template>
1174 </xsl:for-each>
1175 </xsl:otherwise>
1176 </xsl:choose>
1177 <xsl:text>);&#10;</xsl:text>
1178 <!-- now copy temp out parameters to their actual destination -->
1179 <xsl:for-each select="param[@dir='out']">
1180 <xsl:variable name="paramtype" select="@type" />
1181 <xsl:if test="//interface[@name=$paramtype] or $paramtype='$unknown'">
1182 <xsl:variable name="paramname" select="@name" />
1183 <xsl:variable name="wrapped">
1184 <xsl:call-template name="cookOutParam">
1185 <xsl:with-param name="ifname" select="$ifname" />
1186 <xsl:with-param name="method" select="$methodname" />
1187 <xsl:with-param name="value" select="concat('tmp',@name,'.value')" />
1188 <xsl:with-param name="idltype" select="@type" />
1189 <xsl:with-param name="safearray" select="@safearray" />
1190 </xsl:call-template>
1191 </xsl:variable>
1192 <xsl:value-of select="concat(' ',$paramname,'.value = ',
1193 $wrapped,';&#10;')"/>
1194 </xsl:if>
1195 </xsl:for-each>
1196 <!-- next line with return + glue type -->
1197 <xsl:if test="$returnidltype">
1198 <xsl:variable name="retval">
1199 <xsl:call-template name="cookOutParam">
1200 <xsl:with-param name="ifname" select="$ifname" />
1201 <xsl:with-param name="method" select="$methodname" />
1202 <xsl:with-param name="value" select="$retValValue" />
1203 <xsl:with-param name="idltype" select="$returnidltype" />
1204 <xsl:with-param name="safearray" select="$returnidlsafearray" />
1205 </xsl:call-template>
1206 </xsl:variable>
1207 <xsl:value-of select="concat(' return ', $retval, ';&#10;')"/>
1208 </xsl:if>
1209 <xsl:text> } catch (InvalidObjectFaultMsg e) {&#10;</xsl:text>
1210 <xsl:text> throw new WebServiceException(e);&#10;</xsl:text>
1211 <xsl:text> } catch (RuntimeFaultMsg e) {&#10;</xsl:text>
1212 <xsl:text> throw new WebServiceException(e);&#10;</xsl:text>
1213 <xsl:text> }&#10;</xsl:text>
1214 <xsl:text> }&#10;</xsl:text>
1215 </xsl:otherwise>
1216 </xsl:choose>
1217 </xsl:for-each>
1218
1219 </xsl:otherwise>
1220 </xsl:choose>
1221 <!-- end of class -->
1222 <xsl:text>}&#10;</xsl:text>
1223 <xsl:value-of select="concat('&#10;// ##### ENDFILE &quot;', $filename, '.java&quot;&#10;&#10;')" />
1224 <xsl:call-template name="endFile">
1225 <xsl:with-param name="file" select="concat($filename, '.java')" />
1226 </xsl:call-template>
1227 </xsl:if>
1228 </xsl:for-each>
1229
1230<!-- <xsl:apply-templates /> -->
1231</xsl:template>
1232
1233<!-- - - - - - - - - - - - - - - - - - - - - - -
1234 if
1235 - - - - - - - - - - - - - - - - - - - - - - -->
1236
1237<!--
1238 * ignore all |if|s except those for WSDL target
1239-->
1240<xsl:template match="if">
1241 <xsl:if test="@target='wsdl'">
1242 <xsl:apply-templates/>
1243 </xsl:if>
1244</xsl:template>
1245
1246<!-- - - - - - - - - - - - - - - - - - - - - - -
1247 cpp
1248 - - - - - - - - - - - - - - - - - - - - - - -->
1249
1250<xsl:template match="cpp">
1251<!-- ignore this -->
1252</xsl:template>
1253
1254<!-- - - - - - - - - - - - - - - - - - - - - - -
1255 library
1256 - - - - - - - - - - - - - - - - - - - - - - -->
1257
1258<xsl:template match="library">
1259 <xsl:apply-templates />
1260</xsl:template>
1261
1262<!-- - - - - - - - - - - - - - - - - - - - - - -
1263 class
1264 - - - - - - - - - - - - - - - - - - - - - - -->
1265
1266<xsl:template match="module/class">
1267<!-- TODO swallow for now -->
1268</xsl:template>
1269
1270<!-- - - - - - - - - - - - - - - - - - - - - - -
1271 enum
1272 - - - - - - - - - - - - - - - - - - - - - - -->
1273
1274<xsl:template match="enum">
1275</xsl:template>
1276
1277<!-- - - - - - - - - - - - - - - - - - - - - - -
1278 const
1279 - - - - - - - - - - - - - - - - - - - - - - -->
1280
1281<!--
1282<xsl:template match="const">
1283 <xsl:apply-templates />
1284</xsl:template>
1285-->
1286
1287<!-- - - - - - - - - - - - - - - - - - - - - - -
1288 desc
1289 - - - - - - - - - - - - - - - - - - - - - - -->
1290
1291<xsl:template match="desc">
1292<!-- TODO swallow for now -->
1293</xsl:template>
1294
1295<!-- - - - - - - - - - - - - - - - - - - - - - -
1296 note
1297 - - - - - - - - - - - - - - - - - - - - - - -->
1298
1299<xsl:template match="note">
1300<!-- TODO -->
1301 <xsl:apply-templates />
1302</xsl:template>
1303
1304<!-- - - - - - - - - - - - - - - - - - - - - - -
1305 interface
1306 - - - - - - - - - - - - - - - - - - - - - - -->
1307
1308<xsl:template match="interface">
1309
1310</xsl:template>
1311
1312
1313</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