VirtualBox

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

Last change on this file since 25881 was 22653, checked in by vboxsync, 15 years ago

OSE headers fixes

  • Property svn:eol-style set to native
File size: 55.0 KB
Line 
1<?xml version="1.0"?>
2
3<!--
4 websrv-jax-ws.xsl:
5 XSLT stylesheet that generates virtualbox.java from
6 VirtualBox.xidl. This generated Java code contains
7 a Java wrapper that allows client code to use the
8 webservice in an object-oriented way.
9
10 Copyright (C) 2008-2009 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]">
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.virtualbox.org/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 try {
762 logoff(refIVirtualBox);
763 } finally {
764 if (this.port != null) {
765 pool.releasePort(this.port);
766 this.port = null;
767 }
768 }
769 }
770
771 public void cleanupUnused()
772 {
773 System.gc();
774 Runtime.getRuntime().runFinalization();
775 }
776
777 /* method IWebsessionManager::logon(
778 [in] wstring username,
779 [in] wstring password,
780 [return] IVirtualBox return)
781 */
782 public IVirtualBox logon(String username, String password) {
783 try {
784 String retVal = port.iWebsessionManagerLogon(username, password);
785 return new IVirtualBox(retVal, port);
786 } catch (InvalidObjectFaultMsg e) {
787 throw new WebServiceException(e);
788 } catch (RuntimeFaultMsg e) {
789 throw new WebServiceException(e);
790 }
791 }
792
793 /* method IWebsessionManager::getSessionObject(
794 [in] IVirtualBox refIVirtualBox,
795 [return] ISession return)
796 */
797 public ISession getSessionObject(IVirtualBox refIVirtualBox) {
798 try {
799 String retVal = port.iWebsessionManagerGetSessionObject(((refIVirtualBox == null)?null:refIVirtualBox.getRef()));
800 return new ISession(retVal, port);
801 } catch (InvalidObjectFaultMsg e) {
802 throw new WebServiceException(e);
803 } catch (RuntimeFaultMsg e) {
804 throw new WebServiceException(e);
805 }
806 }
807
808 /* method IWebsessionManager::logoff(
809 [in] IVirtualBox refIVirtualBox)
810 */
811 public void logoff(IVirtualBox refIVirtualBox) {
812 try {
813 port.iWebsessionManagerLogoff(((refIVirtualBox == null)?null:refIVirtualBox.getRef()));
814 } catch (InvalidObjectFaultMsg e) {
815 throw new WebServiceException(e);
816 } catch (RuntimeFaultMsg e) {
817 throw new WebServiceException(e);
818 }
819 }
820}
821]]></xsl:text>
822 <xsl:call-template name="endFile">
823 <xsl:with-param name="file" select="'IWebsessionManager.java'" />
824 </xsl:call-template>
825
826 <xsl:text>// ######## COLLECTIONS&#10;&#10;</xsl:text>
827
828 <xsl:for-each select="//collection">
829 <xsl:variable name="type" select="@type" />
830 <xsl:variable name="arrayoftype" select="concat('ArrayOf', @type)" />
831 <xsl:variable name="filename" select="$arrayoftype" />
832
833 <xsl:value-of select="concat('&#10;// ##### BEGINFILE &quot;', $filename, '.java&quot;&#10;&#10;')" />
834
835 <xsl:call-template name="startFile">
836 <xsl:with-param name="file" select="concat($filename, '.java')" />
837 </xsl:call-template>
838
839 <xsl:text>import java.util.ArrayList;&#10;</xsl:text>
840 <xsl:text>import java.util.List;&#10;</xsl:text>
841 <xsl:text>import javax.xml.bind.annotation.XmlAccessType;&#10;</xsl:text>
842 <xsl:text>import javax.xml.bind.annotation.XmlAccessorType;&#10;</xsl:text>
843 <xsl:text>import javax.xml.bind.annotation.XmlType;&#10;&#10;</xsl:text>
844
845 <xsl:text>@XmlAccessorType(XmlAccessType.FIELD)&#10;</xsl:text>
846 <xsl:value-of select="concat('@XmlType(name = &quot;', $arrayoftype, '&quot;, propOrder = {&#10;')" />
847 <xsl:text> "array"&#10;</xsl:text>
848 <xsl:text>})&#10;&#10;</xsl:text>
849 <xsl:value-of select="concat('public class ', $arrayoftype, ' {&#10;&#10;')" />
850
851 <xsl:text> protected List&lt;String&gt; array;&#10;&#10;</xsl:text>
852
853 <xsl:text> public List&lt;String&gt; getArray() {&#10;</xsl:text>
854 <xsl:text> if (array == null) {&#10;</xsl:text>
855 <xsl:text> array = new ArrayList&lt;String&gt;();&#10;</xsl:text>
856 <xsl:text> }&#10;</xsl:text>
857 <xsl:text> return this.array;&#10;</xsl:text>
858 <xsl:text> }&#10;&#10;</xsl:text>
859 <xsl:text>}&#10;</xsl:text>
860 <xsl:call-template name="endFile">
861 <xsl:with-param name="file" select="concat($filename, '.java')" />
862 </xsl:call-template>
863
864 </xsl:for-each>
865
866 <xsl:text>// ######## ENUMS&#10;&#10;</xsl:text>
867
868 <xsl:for-each select="//enum">
869 <xsl:variable name="enumname" select="@name" />
870 <xsl:variable name="filename" select="$enumname" />
871
872 <xsl:call-template name="startFile">
873 <xsl:with-param name="file" select="concat($filename, '.java')" />
874 </xsl:call-template>
875
876 <xsl:text>import javax.xml.bind.annotation.XmlEnum;&#10;</xsl:text>
877 <xsl:text>import javax.xml.bind.annotation.XmlEnumValue;&#10;</xsl:text>
878 <xsl:text>import javax.xml.bind.annotation.XmlType;&#10;&#10;</xsl:text>
879
880 <xsl:value-of select="concat('@XmlType(name = &quot;', $enumname, '&quot;)&#10;')" />
881 <xsl:text>@XmlEnum&#10;</xsl:text>
882 <xsl:value-of select="concat('public enum ', $enumname, ' {&#10;&#10;')" />
883 <xsl:for-each select="const">
884 <xsl:variable name="enumconst" select="@name" />
885 <xsl:value-of select="concat(' @XmlEnumValue(&quot;', $enumconst, '&quot;)&#10;')" />
886 <xsl:value-of select="concat(' ', $enumconst, '(&quot;', $enumconst, '&quot;)')" />
887 <xsl:choose>
888 <xsl:when test="not(position()=last())">
889 <xsl:text>,&#10;</xsl:text>
890 </xsl:when>
891 <xsl:otherwise>
892 <xsl:text>;&#10;</xsl:text>
893 </xsl:otherwise>
894 </xsl:choose>
895 </xsl:for-each>
896
897 <xsl:text>&#10;</xsl:text>
898 <xsl:text> private final String value;&#10;&#10;</xsl:text>
899
900 <xsl:value-of select="concat(' ', $enumname, '(String v) {&#10;')" />
901 <xsl:text> value = v;&#10;</xsl:text>
902 <xsl:text> }&#10;&#10;</xsl:text>
903
904 <xsl:text> public String value() {&#10;</xsl:text>
905 <xsl:text> return value;&#10;</xsl:text>
906 <xsl:text> }&#10;&#10;</xsl:text>
907
908 <xsl:value-of select="concat(' public static ', $enumname, ' fromValue(String v) {&#10;')" />
909 <xsl:value-of select="concat(' for (', $enumname, ' c: ', $enumname, '. values()) {&#10;')" />
910 <xsl:text> if (c.value.equals(v)) {&#10;</xsl:text>
911 <xsl:text> return c;&#10;</xsl:text>
912 <xsl:text> }&#10;</xsl:text>
913 <xsl:text> }&#10;</xsl:text>
914 <xsl:text> throw new IllegalArgumentException(v);&#10;</xsl:text>
915 <xsl:text> }&#10;&#10;</xsl:text>
916
917 <xsl:text>}&#10;&#10;</xsl:text>
918
919 <xsl:call-template name="endFile">
920 <xsl:with-param name="file" select="concat($filename, '.java')" />
921 </xsl:call-template>
922
923 </xsl:for-each>
924
925 <xsl:text>// ######## INTERFACES &#10;&#10;</xsl:text>
926
927 <xsl:for-each select="//interface">
928 <xsl:variable name="ifname" select="@name" />
929 <xsl:variable name="filename" select="$ifname" />
930 <xsl:variable name="wsmap" select="@wsmap" />
931 <xsl:variable name="wscpp" select="@wscpp" />
932
933 <xsl:if test="not($wsmap='suppress') and not ($wsmap='global')">
934 <xsl:call-template name="startFile">
935 <xsl:with-param name="file" select="concat($filename, '.java')" />
936 </xsl:call-template>
937
938 <xsl:text>import java.math.BigInteger;&#10;</xsl:text>
939 <xsl:text>import java.util.List;&#10;</xsl:text>
940 <xsl:text>import javax.xml.ws.Holder;&#10;</xsl:text>
941 <xsl:text>import javax.xml.ws.WebServiceException;&#10;</xsl:text>
942
943 <xsl:choose>
944 <xsl:when test="$wsmap='struct'">
945 <xsl:value-of select="concat('public class ', $ifname, ' {&#10;&#10;')" />
946 <xsl:call-template name="genStructWrapper">
947 <xsl:with-param name="name" select="$ifname" />
948 </xsl:call-template>
949 </xsl:when>
950
951 <xsl:otherwise>
952 <xsl:variable name="extends" select="//interface[@name=$ifname]/@extends" />
953 <xsl:choose>
954 <xsl:when test="($extends = '$unknown') or ($extends = '$dispatched') or ($extends = '$errorinfo')">
955 <xsl:value-of select="concat('public class ', $ifname, ' extends IUnknown {&#10;&#10;')" />
956 </xsl:when>
957 <xsl:when test="//interface[@name=$extends]">
958 <xsl:value-of select="concat('public class ', $ifname, ' extends ', $extends, ' {&#10;&#10;')" />
959 </xsl:when>
960 <xsl:otherwise>
961 <xsl:call-template name="fatalError">
962 <xsl:with-param name="msg" select="concat('Interface generation: interface &quot;', $ifname, '&quot; has invalid &quot;extends&quot; value ', $extends, '.')" />
963 </xsl:call-template>
964 </xsl:otherwise>>
965 </xsl:choose>
966
967 <!-- interface (class) constructor -->
968 <xsl:value-of select="concat(' public static ', $ifname, ' cast(IUnknown other) {&#10;')" />
969 <xsl:value-of select="concat(' return new ', $ifname,
970 '(other.getRef(), other.getRemoteWSPort());&#10; }&#10;&#10;')"/>
971 <xsl:value-of select="concat(' public ', $ifname, '(String _this, VboxPortType port) {&#10;')" />
972 <xsl:text> super(_this,port);&#10;</xsl:text>
973 <xsl:text> }&#10;</xsl:text>
974
975 <!-- attributes -->
976 <xsl:for-each select="attribute">
977 <xsl:variable name="attrname"><xsl:value-of select="@name" /></xsl:variable>
978 <xsl:variable name="attrtype"><xsl:value-of select="@type" /></xsl:variable>
979 <xsl:variable name="attrreadonly"><xsl:value-of select="@readonly" /></xsl:variable>
980 <xsl:variable name="attrsafearray"><xsl:value-of select="@safearray" /></xsl:variable>
981
982 <xsl:choose>
983 <xsl:when test="( $attrtype=($G_setSuppressedInterfaces/@name) )">
984 <xsl:value-of select="concat('&#10; // Skipping attribute ', $attrtype, ' for it is of suppressed type ', $attrtype, '&#10;')" />
985 </xsl:when>
986 <xsl:otherwise>
987 <xsl:choose>
988 <xsl:when test="@readonly='yes'">
989 <xsl:value-of select="concat('&#10; // read-only attribute ', $ifname, '::', $attrname, ' of type ', $attrtype, '&#10;')" />
990 </xsl:when>
991 <xsl:otherwise>
992 <xsl:value-of select="concat('&#10; // read/write attribute ', $ifname, '::', $attrname, ' of type ', $attrtype, '&#10;')" />
993 </xsl:otherwise>
994 </xsl:choose>
995 <!-- emit getter method -->
996 <xsl:variable name="gettername"><xsl:call-template name="makeGetterName"><xsl:with-param name="attrname" select="$attrname" /></xsl:call-template></xsl:variable>
997 <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>
998 <xsl:variable name="gluegettertype">
999 <xsl:call-template name="typeIdl2Glue">
1000 <xsl:with-param name="ifname" select="$ifname" />
1001 <xsl:with-param name="method" select="$gettername" />
1002 <xsl:with-param name="name" select="$attrname" />
1003 <xsl:with-param name="type" select="$attrtype" />
1004 <xsl:with-param name="safearray" select="@safearray" />
1005 </xsl:call-template>
1006 </xsl:variable>
1007 <xsl:variable name="javagettertype">
1008 <xsl:call-template name="typeIdl2Java">
1009 <xsl:with-param name="ifname" select="$ifname" />
1010 <xsl:with-param name="method" select="$gettername" />
1011 <xsl:with-param name="name" select="$attrname" />
1012 <xsl:with-param name="type" select="$attrtype" />
1013 <xsl:with-param name="safearray" select="@safearray" />
1014 </xsl:call-template>
1015 </xsl:variable>
1016 <xsl:value-of select="concat(' public ', $gluegettertype, ' ', $gettername, '() {&#10;')" />
1017 <xsl:text> try {&#10;</xsl:text>
1018 <xsl:value-of select="concat(' ', $javagettertype, ' retVal = port.', $jaxwsGetter, '(_this);&#10;')" />
1019 <xsl:variable name="wrapped">
1020 <xsl:call-template name="cookOutParam">
1021 <xsl:with-param name="ifname" select="$ifname" />
1022 <xsl:with-param name="method" select="$gettername" />
1023 <xsl:with-param name="value" select="'retVal'" />
1024 <xsl:with-param name="idltype" select="$attrtype" />
1025 <xsl:with-param name="safearray" select="@safearray" />
1026 </xsl:call-template>
1027 </xsl:variable>
1028 <xsl:value-of select="concat(' return ', $wrapped, ';&#10;')" />
1029 <xsl:text> } catch (InvalidObjectFaultMsg e) {&#10;</xsl:text>
1030 <xsl:text> throw new WebServiceException(e);&#10;</xsl:text>
1031 <xsl:text> } catch (RuntimeFaultMsg e) {&#10;</xsl:text>
1032 <xsl:text> throw new WebServiceException(e);&#10;</xsl:text>
1033 <xsl:text> }&#10;</xsl:text>
1034 <xsl:text> }&#10;</xsl:text>
1035 <xsl:if test="not(@readonly='yes')">
1036 <!-- emit setter -->
1037 <xsl:variable name="settername"><xsl:call-template name="makeSetterName"><xsl:with-param name="attrname" select="$attrname" /></xsl:call-template></xsl:variable>
1038 <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>
1039 <xsl:variable name="javasettertype">
1040 <xsl:call-template name="typeIdl2Java">
1041 <xsl:with-param name="ifname" select="$ifname" />
1042 <xsl:with-param name="method" select="$settername" />
1043 <xsl:with-param name="name" select="$attrname" />
1044 <xsl:with-param name="type" select="$attrtype" />
1045 </xsl:call-template>
1046 </xsl:variable>
1047 <xsl:value-of select="concat(' public void ', $settername, '(', $javasettertype, ' value) {&#10;')" />
1048 <xsl:text> try {&#10;</xsl:text>
1049 <xsl:value-of select="concat(' port.', $jaxwsSetter, '(_this, value);&#10;')" />
1050 <xsl:text> } catch (InvalidObjectFaultMsg e) {&#10;</xsl:text>
1051 <xsl:text> throw new WebServiceException(e);&#10;</xsl:text>
1052 <xsl:text> } catch (RuntimeFaultMsg e) {&#10;</xsl:text>
1053 <xsl:text> throw new WebServiceException(e);&#10;</xsl:text>
1054 <xsl:text> }&#10;</xsl:text>
1055 <xsl:text> }&#10;</xsl:text>
1056 </xsl:if>
1057 </xsl:otherwise>
1058 </xsl:choose>
1059 </xsl:for-each> <!-- attribute -->
1060
1061 <!-- emit real methods -->
1062 <xsl:for-each select="method">
1063 <xsl:variable name="methodname"><xsl:value-of select="@name" /></xsl:variable>
1064 <xsl:variable name="portArg">
1065 <xsl:if test="not($wsmap='global')">
1066 <xsl:value-of select="'_this'"/>
1067 </xsl:if>
1068 </xsl:variable>
1069
1070 <!-- method header: return value "int", method name, soap arguments -->
1071 <!-- skip this method if it has parameters of a type that has wsmap="suppress" -->
1072 <xsl:choose>
1073 <xsl:when test=" (param[@type=($G_setSuppressedInterfaces/@name)])
1074 or (param[@mod='ptr'])" >
1075 <xsl:comment><xsl:value-of select="concat('Skipping method ', $methodname, ' for it has parameters with suppressed types')" /></xsl:comment>
1076 </xsl:when>
1077 <xsl:otherwise>
1078 <xsl:variable name="fHasReturnParms" select="param[@dir='return']" />
1079 <xsl:variable name="fHasOutParms" select="param[@dir='out']" />
1080
1081 <xsl:value-of select="concat('&#10; /* method ', $ifname, '::', $methodname, '(')" />
1082 <xsl:for-each select="param">
1083 <xsl:value-of select="concat('&#10; [', @dir, '] ', @type, ' ', @name)" />
1084 <xsl:if test="@safearray='yes'">
1085 <xsl:text>[]</xsl:text>
1086 </xsl:if>
1087 <xsl:if test="not(position()=last())">
1088 <xsl:text>,</xsl:text>
1089 </xsl:if>
1090 </xsl:for-each>
1091 <xsl:text>)&#10; */&#10;</xsl:text>
1092 <!-- method implementation -->
1093 <xsl:variable name="returnidltype" select="param[@dir='return']/@type" />
1094 <xsl:variable name="returnidlsafearray" select="param[@dir='return']/@safearray" />
1095 <xsl:variable name="returngluetype">
1096 <xsl:choose>
1097 <xsl:when test="$returnidltype">
1098 <xsl:call-template name="typeIdl2Glue">
1099 <xsl:with-param name="ifname" select="$ifname" />
1100 <xsl:with-param name="method" select="$methodname" />
1101 <xsl:with-param name="name" select="@name" />
1102 <xsl:with-param name="type" select="$returnidltype" />
1103 <xsl:with-param name="safearray" select="param[@dir='return']/@safearray" />
1104 </xsl:call-template>
1105 </xsl:when>
1106 <xsl:otherwise>
1107 <xsl:text>void</xsl:text>
1108 </xsl:otherwise>
1109 </xsl:choose>
1110 </xsl:variable>
1111 <xsl:value-of select="concat(' public ', $returngluetype, ' ', $methodname, '(')" />
1112 <!-- make a set of all parameters with in and out direction -->
1113 <xsl:variable name="paramsinout" select="param[@dir='in' or @dir='out']" />
1114 <xsl:for-each select="exsl:node-set($paramsinout)">
1115 <xsl:variable name="paramgluetype">
1116 <xsl:call-template name="typeIdl2Glue">
1117 <xsl:with-param name="ifname" select="$ifname" />
1118 <xsl:with-param name="method" select="$methodname" />
1119 <xsl:with-param name="name" select="@name" />
1120 <xsl:with-param name="type" select="@type" />
1121 <xsl:with-param name="safearray" select="@safearray" />
1122 </xsl:call-template>
1123 </xsl:variable>
1124 <xsl:choose>
1125 <xsl:when test="@dir='out'">
1126 <xsl:value-of select="concat('Holder&lt;', $paramgluetype, '&gt; ', @name)" />
1127 </xsl:when>
1128 <xsl:otherwise>
1129 <xsl:value-of select="concat($paramgluetype, ' ', @name)" />
1130 </xsl:otherwise>
1131 </xsl:choose>
1132 <xsl:if test="not(position()=last())">
1133 <xsl:text>, </xsl:text>
1134 </xsl:if>
1135 </xsl:for-each>
1136 <xsl:text>) {&#10;</xsl:text>
1137 <xsl:text> try {&#10;</xsl:text>
1138 <xsl:if test="param[@dir='out']">
1139 <xsl:for-each select="param[@dir='out']">
1140 <xsl:variable name="paramtype" select="@type" />
1141 <xsl:if test="//interface[@name=$paramtype] or $paramtype='$unknown'">
1142 <xsl:choose>
1143 <xsl:when test="@safearray='yes'">
1144 <xsl:value-of select="concat(' Holder&lt;List&lt;String&gt;&gt; tmp', @name, ' = new Holder&lt;List&lt;String&gt;&gt;(); &#10;')" />
1145 </xsl:when>
1146 <xsl:otherwise>
1147 <xsl:value-of select="concat(' Holder&lt;String&gt; tmp', @name, ' = new Holder&lt;String&gt;(); &#10;')" />
1148 </xsl:otherwise>
1149 </xsl:choose>
1150 </xsl:if>
1151 </xsl:for-each>
1152 </xsl:if>
1153
1154 <xsl:text> </xsl:text>
1155
1156 <!-- make the function call: first have a stack variable for the return value, if any -->
1157 <!-- XSLT doesn't allow variable override in inner blocks -->
1158 <xsl:variable name="retValValue">
1159 <xsl:choose>
1160 <xsl:when test="param[@dir='out']">
1161 <xsl:value-of select="'retVal.value'"/>
1162 </xsl:when>
1163 <xsl:otherwise>
1164 <xsl:value-of select="'retVal'"/>
1165 </xsl:otherwise>
1166 </xsl:choose>
1167 </xsl:variable>
1168
1169 <xsl:if test="$returnidltype">
1170 <xsl:variable name="javarettype">
1171 <xsl:call-template name="typeIdl2Java">
1172 <xsl:with-param name="ifname" select="$ifname" />
1173 <xsl:with-param name="method" select="$methodname" />
1174 <xsl:with-param name="name" select="@name" />
1175 <xsl:with-param name="type" select="$returnidltype" />
1176 <xsl:with-param name="safearray" select="$returnidlsafearray" />
1177 </xsl:call-template>
1178 </xsl:variable>
1179 <xsl:choose>
1180 <xsl:when test="param[@dir='out']">
1181 <!-- create a new object for return value -->
1182 <xsl:value-of select="
1183 concat('Holder&lt;', $javarettype, '&gt;',
1184 ' ', 'retVal = new Holder&lt;', $javarettype,
1185 '&gt;();&#xa; ')"/>
1186 </xsl:when>
1187 <xsl:otherwise>
1188 <xsl:value-of select="$javarettype"/>
1189 <xsl:text> retVal = </xsl:text>
1190 </xsl:otherwise>
1191 </xsl:choose>
1192 </xsl:if>
1193 <!-- function name and arguments -->
1194 <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>
1195 <xsl:value-of select="concat('port.', $jaxwsmethod, '(', $portArg)" />
1196 <xsl:if test="$paramsinout and not($portArg='')">
1197 <xsl:text>, </xsl:text>
1198 </xsl:if>
1199 <!-- 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... -->
1200 <xsl:choose>
1201 <xsl:when test="param[@dir='out'] and param[@dir='return']">
1202 <xsl:for-each select="param">
1203 <xsl:choose>
1204 <xsl:when test="@dir='return'">
1205 <xsl:text>retVal</xsl:text>
1206 </xsl:when>
1207 <xsl:otherwise>
1208 <xsl:call-template name="emitArgInMethodImpl">
1209 <xsl:with-param name="paramname" select="@name" />
1210 <xsl:with-param name="paramtype" select="@type" />
1211 </xsl:call-template>
1212 </xsl:otherwise>
1213 </xsl:choose>
1214 </xsl:for-each>
1215 </xsl:when>
1216 <xsl:otherwise>
1217 <xsl:for-each select="$paramsinout">
1218 <xsl:call-template name="emitArgInMethodImpl">
1219 <xsl:with-param name="paramname" select="@name" />
1220 <xsl:with-param name="paramtype" select="@type" />
1221 </xsl:call-template>
1222 </xsl:for-each>
1223 </xsl:otherwise>
1224 </xsl:choose>
1225 <xsl:text>);&#10;</xsl:text>
1226 <!-- now copy temp out parameters to their actual destination -->
1227 <xsl:for-each select="param[@dir='out']">
1228 <xsl:variable name="paramtype" select="@type" />
1229 <xsl:if test="//interface[@name=$paramtype] or $paramtype='$unknown'">
1230 <xsl:variable name="paramname" select="@name" />
1231 <xsl:variable name="wrapped">
1232 <xsl:call-template name="cookOutParam">
1233 <xsl:with-param name="ifname" select="$ifname" />
1234 <xsl:with-param name="method" select="$methodname" />
1235 <xsl:with-param name="value" select="concat('tmp',@name,'.value')" />
1236 <xsl:with-param name="idltype" select="@type" />
1237 <xsl:with-param name="safearray" select="@safearray" />
1238 </xsl:call-template>
1239 </xsl:variable>
1240 <xsl:value-of select="concat(' ',$paramname,'.value = ',
1241 $wrapped,';&#10;')"/>
1242 </xsl:if>
1243 </xsl:for-each>
1244 <!-- next line with return + glue type -->
1245 <xsl:if test="$returnidltype">
1246 <xsl:variable name="retval">
1247 <xsl:call-template name="cookOutParam">
1248 <xsl:with-param name="ifname" select="$ifname" />
1249 <xsl:with-param name="method" select="$methodname" />
1250 <xsl:with-param name="value" select="$retValValue" />
1251 <xsl:with-param name="idltype" select="$returnidltype" />
1252 <xsl:with-param name="safearray" select="$returnidlsafearray" />
1253 </xsl:call-template>
1254 </xsl:variable>
1255 <xsl:value-of select="concat(' return ', $retval, ';&#10;')"/>
1256 </xsl:if>
1257 <xsl:text> } catch (InvalidObjectFaultMsg e) {&#10;</xsl:text>
1258 <xsl:text> throw new WebServiceException(e);&#10;</xsl:text>
1259 <xsl:text> } catch (RuntimeFaultMsg e) {&#10;</xsl:text>
1260 <xsl:text> throw new WebServiceException(e);&#10;</xsl:text>
1261 <xsl:text> }&#10;</xsl:text>
1262 <xsl:text> }&#10;</xsl:text>
1263 </xsl:otherwise>
1264 </xsl:choose>
1265 </xsl:for-each>
1266
1267 </xsl:otherwise>
1268 </xsl:choose>
1269 <!-- end of class -->
1270 <xsl:text>}&#10;</xsl:text>
1271 <xsl:value-of select="concat('&#10;// ##### ENDFILE &quot;', $filename, '.java&quot;&#10;&#10;')" />
1272 <xsl:call-template name="endFile">
1273 <xsl:with-param name="file" select="concat($filename, '.java')" />
1274 </xsl:call-template>
1275 </xsl:if>
1276 </xsl:for-each>
1277
1278<!-- <xsl:apply-templates /> -->
1279</xsl:template>
1280
1281<!-- - - - - - - - - - - - - - - - - - - - - - -
1282 if
1283 - - - - - - - - - - - - - - - - - - - - - - -->
1284
1285<!--
1286 * ignore all |if|s except those for WSDL target
1287-->
1288<xsl:template match="if">
1289 <xsl:if test="@target='wsdl'">
1290 <xsl:apply-templates/>
1291 </xsl:if>
1292</xsl:template>
1293
1294<!-- - - - - - - - - - - - - - - - - - - - - - -
1295 cpp
1296 - - - - - - - - - - - - - - - - - - - - - - -->
1297
1298<xsl:template match="cpp">
1299<!-- ignore this -->
1300</xsl:template>
1301
1302<!-- - - - - - - - - - - - - - - - - - - - - - -
1303 library
1304 - - - - - - - - - - - - - - - - - - - - - - -->
1305
1306<xsl:template match="library">
1307 <xsl:apply-templates />
1308</xsl:template>
1309
1310<!-- - - - - - - - - - - - - - - - - - - - - - -
1311 class
1312 - - - - - - - - - - - - - - - - - - - - - - -->
1313
1314<xsl:template match="module/class">
1315<!-- TODO swallow for now -->
1316</xsl:template>
1317
1318<!-- - - - - - - - - - - - - - - - - - - - - - -
1319 enum
1320 - - - - - - - - - - - - - - - - - - - - - - -->
1321
1322<xsl:template match="enum">
1323</xsl:template>
1324
1325<!-- - - - - - - - - - - - - - - - - - - - - - -
1326 const
1327 - - - - - - - - - - - - - - - - - - - - - - -->
1328
1329<!--
1330<xsl:template match="const">
1331 <xsl:apply-templates />
1332</xsl:template>
1333-->
1334
1335<!-- - - - - - - - - - - - - - - - - - - - - - -
1336 desc
1337 - - - - - - - - - - - - - - - - - - - - - - -->
1338
1339<xsl:template match="desc">
1340<!-- TODO swallow for now -->
1341</xsl:template>
1342
1343<!-- - - - - - - - - - - - - - - - - - - - - - -
1344 note
1345 - - - - - - - - - - - - - - - - - - - - - - -->
1346
1347<xsl:template match="note">
1348<!-- TODO -->
1349 <xsl:apply-templates />
1350</xsl:template>
1351
1352<!-- - - - - - - - - - - - - - - - - - - - - - -
1353 interface
1354 - - - - - - - - - - - - - - - - - - - - - - -->
1355
1356<xsl:template match="interface">
1357
1358</xsl:template>
1359
1360
1361</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.

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