VirtualBox

source: vbox/trunk/src/VBox/Main/idl/typemap-shared.inc.xsl@ 103795

Last change on this file since 103795 was 98103, checked in by vboxsync, 22 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 21.6 KB
Line 
1<!--
2 typemap-shared.inc.xsl:
3 this gets included from other XSLT stylesheets including those
4 for the webservice, so we can share some definitions that must
5 be the same for all of them (like method prefixes/suffices).
6-->
7<!--
8 Copyright (C) 2006-2023 Oracle and/or its affiliates.
9
10 This file is part of VirtualBox base platform packages, as
11 available from https://www.virtualbox.org.
12
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License
15 as published by the Free Software Foundation, in version 3 of the
16 License.
17
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, see <https://www.gnu.org/licenses>.
25
26 SPDX-License-Identifier: GPL-3.0-only
27-->
28
29
30<xsl:stylesheet
31 version="1.0"
32 targetNamespace="http://schemas.xmlsoap.org/wsdl/"
33 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
34 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
35 xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
36 xmlns:vbox="http://www.virtualbox.org/">
37
38<xsl:variable name="G_xsltIncludeFilename" select="'typemap-shared.inc.xsl'" />
39
40<xsl:variable name="G_lowerCase" select="'abcdefghijklmnopqrstuvwxyz'" />
41<xsl:variable name="G_upperCase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
42<xsl:variable name="G_sNewLine">
43 <xsl:text>
44</xsl:text>
45</xsl:variable>
46
47<!-- List of white space characters that the strip functions will remove -->
48<xsl:variable name="G_sWhiteSpace" select="' &#10;&#13;&#09;'"/>
49
50<!-- target namespace; this must match the xmlns:vbox in stylesheet opening tags! -->
51<xsl:variable name="G_targetNamespace"
52 select='"http://www.virtualbox.org/"' />
53<xsl:variable name="G_targetNamespaceSeparator"
54 select='""' />
55
56<!-- ENCODING SCHEME
57
58 See: http://www-128.ibm.com/developerworks/webservices/library/ws-whichwsdl/
59
60 Essentially "document" style means that each SOAP message is a complete and
61 self-explanatory document that does not rely on outside information for
62 validation.
63
64 By contrast, the (older) "RPC" style allows for much shorter SOAP messages
65 that do not contain validation info like all types that are used, but then
66 again, caller and receiver must have agreed on a valid format in some other way.
67 With RPC, WSDL typically looks like this:
68
69 <message name="myMethodRequest">
70 <part name="x" type="xsd:int"/>
71 <part name="y" type="xsd:float"/>
72 </message>
73
74 This is why today "document" style is preferred. However, with document style,
75 one _cannot_ use "type" in <part> elements. Instead, one must use "element"
76 attributes that refer to <element> items in the type section. Like this:
77
78 <types>
79 <schema>
80 <element name="xElement" type="xsd:int"/>
81 <element name="yElement" type="xsd:float"/>
82 </schema>
83 </types>
84
85 <message name="myMethodRequest">
86 <part name="x" element="xElement"/>
87 <part name="y" element="yElement"/>
88 </message>
89
90 The "encoded" and "literal" sub-styles then only determine whether the
91 individual types in the soap messages carry additional information in
92 attributes. "Encoded" was only used with RPC styles, really, and even that
93 is not widely supported any more.
94
95-->
96<!-- These are the settings: all the other XSLTs react on this and are supposed
97 to be able to generate both valid RPC and document-style code. The only
98 allowed values are 'rpc' or 'document'. -->
99<xsl:variable name="G_basefmt"
100 select='"document"' />
101<xsl:variable name="G_parmfmt"
102 select='"literal"' />
103<!-- <xsl:variable name="G_basefmt"
104 select='"rpc"' />
105<xsl:variable name="G_parmfmt"
106 select='"encoded"' /> -->
107
108<!-- with document style, this is how we name the request and return element structures -->
109<xsl:variable name="G_requestElementVarName"
110 select='"req"' />
111<xsl:variable name="G_responseElementVarName"
112 select='"resp"' />
113<!-- this is how we name the result parameter in messages -->
114<xsl:variable name="G_result"
115 select='"returnval"' />
116
117<!-- we represent interface attributes by creating "get" and "set" methods; these
118 are the prefixes we use for that -->
119<xsl:variable name="G_attributeGetPrefix"
120 select='"get"' />
121<xsl:variable name="G_attributeSetPrefix"
122 select='"set"' />
123<!-- separator between class name and method/attribute name; would be "::" in C++
124 but i'm unsure whether WSDL appreciates that (WSDL only) -->
125<xsl:variable name="G_classSeparator"
126 select='"_"' />
127<!-- for each interface method, we need to create both a "request" and a "response"
128 message; these are the suffixes we append to the method names for that -->
129<xsl:variable name="G_methodRequest"
130 select='"RequestMsg"' />
131<xsl:variable name="G_methodResponse"
132 select='"ResultMsg"' />
133<!-- suffix for element declarations that describe request message parameters (WSDL only) -->
134<xsl:variable name="G_requestMessageElementSuffix"
135 select='""' />
136<!-- suffix for element declarations that describe request message parameters (WSDL only) -->
137<xsl:variable name="G_responseMessageElementSuffix"
138 select='"Response"' />
139<!-- suffix for portType names (WSDL only) -->
140<xsl:variable name="G_portTypeSuffix"
141 select='"PortType"' />
142<!-- suffix for binding names (WSDL only) -->
143<xsl:variable name="G_bindingSuffix"
144 select='"Binding"' />
145<!-- schema type to use for object references; while it is theoretically
146 possible to use a self-defined type (e.g. some vboxObjRef type that's
147 really an int), gSOAP gets a bit nasty and creates complicated structs
148 for function parameters when these types are used as output parameters.
149 So we just use "int" even though it's not as lucid.
150 One setting is for the WSDL emitter, one for the C++ emitter -->
151<!--
152<xsl:variable name="G_typeObjectRef"
153 select='"xsd:unsignedLong"' />
154<xsl:variable name="G_typeObjectRef_gsoapH"
155 select='"ULONG64"' />
156<xsl:variable name="G_typeObjectRef_CPP"
157 select='"WSDLT_ID"' />
158-->
159<xsl:variable name="G_typeObjectRef"
160 select='"xsd:string"' />
161<xsl:variable name="G_typeObjectRef_gsoapH"
162 select='"std::string"' />
163<xsl:variable name="G_typeObjectRef_CPP"
164 select='"std::string"' />
165<!-- and what to call first the object parameter -->
166<xsl:variable name="G_nameObjectRef"
167 select='"_this"' />
168<!-- gSOAP encodes underscores with USCORE so this is used in our C++ code -->
169<xsl:variable name="G_nameObjectRefEncoded"
170 select='"_USCOREthis"' />
171
172<!-- type to represent enums within C++ COM callers -->
173<xsl:variable name="G_funcPrefixInputEnumConverter"
174 select='"EnumSoap2Com_"' />
175<xsl:variable name="G_funcPrefixOutputEnumConverter"
176 select='"EnumCom2Soap_"' />
177
178<!-- type to represent structs within C++ COM callers -->
179<xsl:variable name="G_funcPrefixOutputStructConverter"
180 select='"StructCom2Soap_"' />
181
182<xsl:variable name="G_aSharedTypes">
183 <type idlname="octet" xmlname="unsignedByte" cname="unsigned char" gluename="BYTE" gluefmt="%RU8" javaname="byte" dtracename="uint8_t" />
184 <type idlname="boolean" xmlname="boolean" cname="bool" gluename="BOOL" gluefmt="%RTbool" javaname="Boolean" dtracename="int8_t" />
185 <type idlname="short" xmlname="short" cname="short" gluename="SHORT" gluefmt="%RI16" javaname="Short" dtracename="int16_t" />
186 <type idlname="unsigned short" xmlname="unsignedShort" cname="unsigned short" gluename="USHORT" gluefmt="%RU16" javaname="Integer" dtracename="uint16_t" />
187 <type idlname="long" xmlname="int" cname="int" gluename="LONG" gluefmt="%RI32" javaname="Integer" dtracename="int32_t" />
188 <type idlname="unsigned long" xmlname="unsignedInt" cname="unsigned int" gluename="ULONG" gluefmt="%RU32" javaname="Long" dtracename="uint32_t" />
189 <type idlname="long long" xmlname="long" cname="LONG64" gluename="LONG64" gluefmt="%RI64" javaname="Long" dtracename="int64_t" />
190 <type idlname="unsigned long long" xmlname="unsignedLong" cname="ULONG64" gluename="ULONG64" gluefmt="%RU64" javaname="BigInteger" dtracename="uint64_t" />
191 <type idlname="double" xmlname="double" cname="double" gluename="DOUBLE" gluefmt="%#RX64" javaname="Double" dtracename="double" />
192 <type idlname="float" xmlname="float" cname="float" gluename="FLOAT" gluefmt="%#RX32" javaname="Float" dtracename="float" />
193 <type idlname="wstring" xmlname="string" cname="std::string" gluename="BSTR" gluefmt="%ls" javaname="String" dtracename="const char *"/>
194 <type idlname="uuid" xmlname="string" cname="std::string" gluename="BSTR" gluefmt="%ls" javaname="String" dtracename="const char *"/>
195 <type idlname="result" xmlname="unsignedInt" cname="unsigned int" gluename="HRESULT" gluefmt="%Rhrc" javaname="Long" dtracename="int32_t" />
196</xsl:variable>
197
198<!--
199 warning:
200 -->
201
202<xsl:template name="warning">
203 <xsl:param name="msg" />
204
205 <xsl:message terminate="no">
206 <xsl:value-of select="concat('[', $G_xsltFilename, '] Warning in ', $msg)" />
207 </xsl:message>
208</xsl:template>
209
210<!--
211 fatalError:
212 -->
213
214<xsl:template name="fatalError">
215 <xsl:param name="msg" />
216
217 <xsl:message terminate="yes">
218 <xsl:value-of select="concat('[', $G_xsltFilename, '] Error in ', $msg)" />
219 </xsl:message>
220</xsl:template>
221
222<!--
223 debugMsg
224 -->
225
226<xsl:template name="debugMsg">
227 <xsl:param name="msg" />
228
229 <xsl:if test="$G_argDebug">
230 <xsl:message terminate="no">
231 <xsl:value-of select="concat('[', $G_xsltFilename, '] ', $msg)" />
232 </xsl:message>
233 </xsl:if>
234</xsl:template>
235
236<!--
237 uncapitalize
238 -->
239
240<xsl:template name="uncapitalize">
241 <xsl:param name="str" select="."/>
242 <xsl:value-of select="
243 concat(
244 translate(substring($str,1,1),$G_upperCase,$G_lowerCase),
245 substring($str,2)
246 )
247 "/>
248</xsl:template>
249<!--
250 uncapitalize in the way JAX-WS understands, see #2910
251 -->
252
253<xsl:template name="uncapitalize2">
254 <xsl:param name="str" select="."/>
255 <xsl:variable name="strlen">
256 <xsl:value-of select="string-length($str)"/>
257 </xsl:variable>
258 <xsl:choose>
259 <xsl:when test="$strlen>1">
260 <xsl:choose>
261 <xsl:when test="contains($G_upperCase,substring($str,1,1))
262 and
263 contains($G_upperCase,substring($str,2,1))">
264 <xsl:variable name="cdr">
265 <xsl:call-template name="uncapitalize2">
266 <xsl:with-param name="str" select="substring($str,2)"/>
267 </xsl:call-template>
268 </xsl:variable>
269 <xsl:value-of select="
270 concat(
271 translate(substring($str,1,1),
272 $G_upperCase,
273 $G_lowerCase),
274 $cdr
275 )
276 "/>
277 </xsl:when>
278 <xsl:otherwise>
279 <!--<xsl:value-of select="concat(substring($str,1,1),$cdr)"/>-->
280 <xsl:value-of select="$str"/>
281 </xsl:otherwise>
282 </xsl:choose>
283 </xsl:when>
284 <xsl:when test="$strlen=1">
285 <xsl:value-of select="
286 translate($str,
287 $G_upperCase,
288 $G_lowerCase)
289 "/>
290 </xsl:when>
291 <xsl:otherwise>
292 </xsl:otherwise>
293 </xsl:choose>
294</xsl:template>
295<!--
296 capitalize
297 -->
298
299<xsl:template name="capitalize">
300 <xsl:param name="str" select="."/>
301 <xsl:value-of select="
302 concat(
303 translate(substring($str,1,1),$G_lowerCase,$G_upperCase),
304 substring($str,2)
305 )
306 "/>
307</xsl:template>
308
309<!--
310 makeGetterName:
311 -->
312<xsl:template name="makeGetterName">
313 <xsl:param name="attrname" />
314 <xsl:variable name="capsname"><xsl:call-template name="capitalize"><xsl:with-param name="str" select="$attrname" /></xsl:call-template></xsl:variable>
315 <xsl:value-of select="concat($G_attributeGetPrefix, $capsname)" />
316</xsl:template>
317
318<!--
319 makeSetterName:
320 -->
321<xsl:template name="makeSetterName">
322 <xsl:param name="attrname" />
323 <xsl:variable name="capsname"><xsl:call-template name="capitalize"><xsl:with-param name="str" select="$attrname" /></xsl:call-template></xsl:variable>
324 <xsl:value-of select="concat($G_attributeSetPrefix, $capsname)" />
325</xsl:template>
326
327<!--
328 makeJaxwsMethod: compose idevInterfaceMethod out of IDEVInterface::method
329 -->
330<xsl:template name="makeJaxwsMethod">
331 <xsl:param name="ifname" />
332 <xsl:param name="methodname" />
333 <xsl:variable name="uncapsif"><xsl:call-template name="uncapitalize2"><xsl:with-param name="str" select="$ifname" /></xsl:call-template></xsl:variable>
334 <xsl:variable name="capsmethod"><xsl:call-template name="capitalize"><xsl:with-param name="str" select="$methodname" /></xsl:call-template></xsl:variable>
335 <xsl:value-of select="concat($uncapsif, $capsmethod)" />
336</xsl:template>
337
338
339<!--
340 makeJaxwsMethod2: compose iInterfaceMethod out of IInterface::method
341 -->
342<xsl:template name="makeJaxwsMethod2">
343 <xsl:param name="ifname" />
344 <xsl:param name="methodname" />
345 <xsl:variable name="uncapsif"><xsl:call-template name="uncapitalize"><xsl:with-param name="str" select="$ifname" /></xsl:call-template></xsl:variable>
346 <xsl:variable name="capsmethod"><xsl:call-template name="capitalize"><xsl:with-param name="str" select="$methodname" /></xsl:call-template></xsl:variable>
347 <xsl:value-of select="concat($uncapsif, $capsmethod)" />
348</xsl:template>
349
350<!--
351 emitNewline:
352 -->
353<xsl:template name="emitNewline">
354 <xsl:text>
355</xsl:text>
356</xsl:template>
357
358<!--
359 emitNewlineIndent8:
360 -->
361<xsl:template name="emitNewlineIndent8">
362 <xsl:text>
363 </xsl:text>
364</xsl:template>
365
366<!--
367 escapeUnderscores
368 -->
369<xsl:template name="escapeUnderscores">
370 <xsl:param name="string" />
371 <xsl:if test="contains($string, '_')">
372 <xsl:value-of select="substring-before($string, '_')" />_USCORE<xsl:call-template name="escapeUnderscores"><xsl:with-param name="string"><xsl:value-of select="substring-after($string, '_')" /></xsl:with-param></xsl:call-template>
373 </xsl:if>
374 <xsl:if test="not(contains($string, '_'))"><xsl:value-of select="$string" />
375 </xsl:if>
376</xsl:template>
377
378<!--
379 xsltprocNewlineOutputHack - emits a single new line.
380
381 Hack Alert! This template helps xsltproc split up the output text elements
382 and avoid reallocating them into the MB range. Calls to this
383 template is made occationally while generating larger output
384 file. It's not necessary for small stuff like header.
385
386 The trick we're playing on xsltproc has to do with CDATA
387 and/or the escape setting of the xsl:text element. It forces
388 xsltproc to allocate a new output element, thus preventing
389 things from growing out of proportions and slowing us down.
390
391 This was successfully employed to reduce a 18+ seconds run to
392 around one second (possibly less due to kmk overhead).
393 -->
394<xsl:template name="xsltprocNewlineOutputHack">
395 <xsl:text disable-output-escaping="yes"><![CDATA[
396]]></xsl:text>
397</xsl:template>
398
399
400<!--
401 string-to-upper - translates the string to uppercase.
402 -->
403<xsl:template name="string-to-upper">
404 <xsl:param name="str" select="."/>
405 <xsl:value-of select="translate($str, $G_lowerCase, $G_upperCase)"/>
406</xsl:template>
407
408<!--
409 string-to-lower - translates the string to lowercase.
410 -->
411<xsl:template name="string-to-lower">
412 <xsl:param name="str" select="."/>
413 <xsl:value-of select="translate($str, $G_upperCase, $G_lowerCase)"/>
414</xsl:template>
415
416<!--
417 string-replace - Replace all occurencees of needle in haystack.
418 -->
419<xsl:template name="string-replace">
420 <xsl:param name="haystack"/>
421 <xsl:param name="needle"/>
422 <xsl:param name="replacement"/>
423 <xsl:param name="onlyfirst" select="false"/>
424 <xsl:choose>
425 <xsl:when test="contains($haystack, $needle)">
426 <xsl:value-of select="substring-before($haystack, $needle)"/>
427 <xsl:value-of select="$replacement"/>
428 <xsl:call-template name="string-replace">
429 <xsl:with-param name="haystack" select="substring-after($haystack, $needle)"/>
430 <xsl:with-param name="needle" select="$needle"/>
431 <xsl:with-param name="replacement" select="$replacement"/>
432 </xsl:call-template>
433 </xsl:when>
434 <xsl:otherwise>
435 <xsl:value-of select="$haystack"/>
436 </xsl:otherwise>
437 </xsl:choose>
438</xsl:template>
439
440<!--
441 string-replace-first - Replace the _first_ occurence of needle in haystack.
442 -->
443<xsl:template name="string-replace-first">
444 <xsl:param name="haystack"/>
445 <xsl:param name="needle"/>
446 <xsl:param name="replacement"/>
447 <xsl:choose>
448 <xsl:when test="contains($haystack, $needle)">
449 <xsl:value-of select="substring-before($haystack, $needle)"/>
450 <xsl:value-of select="$replacement"/>
451 <xsl:value-of select="substring-after($haystack, $needle)"/>
452 </xsl:when>
453 <xsl:otherwise>
454 <xsl:value-of select="$haystack"/>
455 </xsl:otherwise>
456 </xsl:choose>
457</xsl:template>
458
459<!--
460 strip-string-right - String trailing white space from a string.
461 -->
462<xsl:template name="strip-string-right">
463 <xsl:param name="text"/>
464
465 <!-- Check for trailing whitespace. -->
466 <xsl:choose>
467 <xsl:when test="contains($G_sWhiteSpace, substring($text, string-length($text), 1))">
468 <xsl:call-template name="strip-string-right">
469 <xsl:with-param name="text" select="substring($text, 1, string-length($text) - 1)"/>
470 </xsl:call-template>
471 </xsl:when>
472
473 <!-- No trailing white space. Return the string. -->
474 <xsl:otherwise>
475 <xsl:value-of select="$text"/>
476 </xsl:otherwise>
477 </xsl:choose>
478</xsl:template>
479
480<!--
481 strip-string-left - String leading white space from a string.
482 -->
483<xsl:template name="strip-string-left">
484 <xsl:param name="text"/>
485
486 <!-- Check for leading white space. To optimize for speed, we check a couple
487 of longer space sequences first. -->
488 <xsl:choose>
489 <xsl:when test="starts-with($text, ' ')"> <!-- 8 leading spaces -->
490 <xsl:call-template name="strip-string-left">
491 <xsl:with-param name="text" select="substring($text, 9)"/>
492 </xsl:call-template>
493 </xsl:when>
494 <xsl:when test="starts-with($text, ' ')"> <!-- 4 leading spaces -->
495 <xsl:call-template name="strip-string-left">
496 <xsl:with-param name="text" select="substring($text, 5)"/>
497 </xsl:call-template>
498 </xsl:when>
499 <xsl:when test="starts-with($text, ' ')"> <!-- 2 leading spaces -->
500 <xsl:call-template name="strip-string-left">
501 <xsl:with-param name="text" select="substring($text, 3)"/>
502 </xsl:call-template>
503 </xsl:when>
504 <xsl:when test="contains($G_sWhiteSpace, substring($text, 1, 1))">
505 <xsl:if test="string-length($text) > 0">
506 <xsl:call-template name="strip-string">
507 <xsl:with-param name="text" select="substring($text, 2)"/>
508 </xsl:call-template>
509 </xsl:if>
510 </xsl:when>
511
512 <!-- No leading white space. Return the string. -->
513 <xsl:otherwise>
514 <xsl:value-of select="$text"/>
515 </xsl:otherwise>
516 </xsl:choose>
517
518</xsl:template>
519
520<!--
521 strip-string - String leading and trailing white space from a string.
522 -->
523<xsl:template name="strip-string">
524 <xsl:param name="text"/>
525
526 <!-- Check for leading white space. To optimize for speed, we check a couple
527 of longer space sequences first. -->
528 <xsl:choose>
529 <xsl:when test="starts-with($text, ' ')"> <!-- 8 leading spaces -->
530 <xsl:call-template name="strip-string">
531 <xsl:with-param name="text" select="substring($text, 9)"/>
532 </xsl:call-template>
533 </xsl:when>
534 <xsl:when test="starts-with($text, ' ')"> <!-- 4 leading spaces -->
535 <xsl:call-template name="strip-string">
536 <xsl:with-param name="text" select="substring($text, 5)"/>
537 </xsl:call-template>
538 </xsl:when>
539 <xsl:when test="starts-with($text, ' ')"> <!-- 2 leading spaces -->
540 <xsl:call-template name="strip-string">
541 <xsl:with-param name="text" select="substring($text, 3)"/>
542 </xsl:call-template>
543 </xsl:when>
544 <xsl:when test="contains($G_sWhiteSpace, substring($text, 1, 1))">
545 <xsl:if test="string-length($text) > 0">
546 <xsl:call-template name="strip-string">
547 <xsl:with-param name="text" select="substring($text, 2)"/>
548 </xsl:call-template>
549 </xsl:if>
550 </xsl:when>
551
552 <!-- Then check for trailing whitespace. -->
553 <xsl:otherwise>
554 <xsl:choose>
555 <xsl:when test="contains($G_sWhiteSpace, substring($text, string-length($text), 1))">
556 <xsl:call-template name="strip-string-right">
557 <xsl:with-param name="text" select="substring($text, 1, string-length($text) - 1)"/>
558 </xsl:call-template>
559 </xsl:when>
560
561 <!-- No leading or trailing white space. Return the string. -->
562 <xsl:otherwise>
563 <xsl:value-of select="$text"/>
564 </xsl:otherwise>
565 </xsl:choose>
566 </xsl:otherwise>
567 </xsl:choose>
568
569</xsl:template>
570
571</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