VirtualBox

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

Last change on this file since 73768 was 69379, checked in by vboxsync, 7 years ago

Main/idl: scm updates

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

© 2023 Oracle
ContactPrivacy policyTerms of Use