summaryrefslogtreecommitdiffstats
path: root/src/libs/xpcom18a4/java/tools/genjifaces.xsl
blob: 05455a4dc2f148ec0722bfb38290f7ab4679e0b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
<xsl:stylesheet version = '1.0'
     xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
     xmlns:vbox="http://www.virtualbox.org/"
     xmlns:exsl="http://exslt.org/common"
     extension-element-prefixes="exsl">

<!--
    genjifaces.xsl:
        XSLT stylesheet that generates Java XPCOM bridge interface code from VirtualBox.xidl.
-->
<!--
    Copyright (C) 2010-2022 Oracle and/or its affiliates.

    This file is part of VirtualBox base platform packages, as
    available from https://www.virtualbox.org.

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation, in version 3 of the
    License.

    This program is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, see <https://www.gnu.org/licenses>.

    SPDX-License-Identifier: GPL-3.0-only
-->

<xsl:output
  method="text"
  version="1.0"
  encoding="utf-8"
  indent="no"/>

<!-- - - - - - - - - - - - - - - - - - - - - - -
  global XSLT variables
 - - - - - - - - - - - - - - - - - - - - - - -->

<xsl:variable name="G_xsltFilename" select="'genjifaces.xsl'" />


<!-- - - - - - - - - - - - - - - - - - - - - - -
  Keys for more efficiently looking up of types.
- - - - - - - - - - - - - - - - - - - - - - -->
<xsl:key name="G_keyEnumsByName" match="//enum[@name]" use="@name"/>
<xsl:key name="G_keyInterfacesByName" match="//interface[@name]" use="@name"/>

<!--
     xsltprocNewlineOutputHack - emits a single new line.

     Hack Alert! This template helps xsltproc split up the output text elements
                 and avoid reallocating them into the MB range. Calls to this
                 template is made occationally while generating larger output
                 file.  It's not necessary for small stuff like header.

                 The trick we're playing on xsltproc has to do with CDATA
                 and/or the escape setting of the xsl:text element.  It forces
                 xsltproc to allocate a new output element, thus preventing
                 things from growing out of proportions and slowing us down.

                 This was successfully employed to reduce a 18+ seconds run to
                 around one second (possibly less due to kmk overhead).
 -->
<xsl:template name="xsltprocNewlineOutputHack">
    <xsl:text disable-output-escaping="yes"><![CDATA[
]]></xsl:text>
</xsl:template>

<xsl:template name="uppercase">
  <xsl:param name="str" select="."/>
  <xsl:value-of select="translate($str, 'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')" />
</xsl:template>

<xsl:template name="capitalize">
  <xsl:param name="str" select="."/>
  <xsl:value-of select="
        concat(translate(substring($str,1,1),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ'),
               substring($str,2))"/>
</xsl:template>

<xsl:template name="makeGetterName">
  <xsl:param name="attrname" />
  <xsl:variable name="capsname">
    <xsl:call-template name="capitalize">
      <xsl:with-param name="str" select="$attrname" />
  </xsl:call-template>
  </xsl:variable>
  <xsl:value-of select="concat('get', $capsname)" />
</xsl:template>

<xsl:template name="makeSetterName">
  <xsl:param name="attrname" />
  <xsl:variable name="capsname">
    <xsl:call-template name="capitalize">
      <xsl:with-param name="str" select="$attrname" />
  </xsl:call-template>
  </xsl:variable>
  <xsl:value-of select="concat('set', $capsname)" />
</xsl:template>

<xsl:template name="fileheader">
  <xsl:param name="name" />
  <xsl:text>/** @file
</xsl:text>
  <xsl:value-of select="concat(' * ',$name)"/>
<xsl:text>
 *
 * DO NOT EDIT! This is a generated file.
 * Generated from: src/VBox/Main/idl/VirtualBox.xidl (VirtualBox's interface definitions in XML)
 * Generator: src/VBox/src/libs/xpcom18a4/java/tools/genjifaces.xsl
 */

/*
 * Copyright (C) 2010-2022 Oracle and/or its affiliates.
 *
 * This file is part of VirtualBox base platform packages, as
 * available from https://www.virtualbox.org.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation, in version 3 of the
 * License.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see &lt;https://www.gnu.org/licenses&gt;.
 *
 * SPDX-License-Identifier: GPL-3.0-only
 */
</xsl:text>
</xsl:template>

<xsl:template name="startFile">
  <xsl:param name="file" />

  <xsl:value-of select="concat('&#10;// ##### BEGINFILE &quot;', $file, '&quot;&#10;&#10;')" />
  <xsl:call-template name="fileheader">
    <xsl:with-param name="name" select="$file" />
  </xsl:call-template>

  <xsl:value-of select="       'package org.mozilla.interfaces;&#10;&#10;'" />
</xsl:template>

<xsl:template name="endFile">
 <xsl:param name="file" />
 <xsl:value-of select="concat('&#10;// ##### ENDFILE &quot;', $file, '&quot;&#10;')" />
 <xsl:call-template name="xsltprocNewlineOutputHack"/>
</xsl:template>


<xsl:template name="emitHandwritten">

 <xsl:call-template name="startFile">
    <xsl:with-param name="file" select="'nsISupports.java'" />
 </xsl:call-template>

 <xsl:text><![CDATA[
public interface nsISupports
{
  public static final String NS_ISUPPORTS_IID =
    "{00000000-0000-0000-c000-000000000046}";

  public nsISupports queryInterface(String arg1);
}
]]></xsl:text>

 <xsl:call-template name="endFile">
   <xsl:with-param name="file" select="'nsISupports.java'" />
 </xsl:call-template>

 <xsl:call-template name="startFile">
    <xsl:with-param name="file" select="'nsIComponentManager.java'" />
 </xsl:call-template>

 <xsl:text><![CDATA[
public interface nsIComponentManager extends nsISupports
{
  public static final String NS_ICOMPONENTMANAGER_IID =
    "{a88e5a60-205a-4bb1-94e1-2628daf51eae}";

  public nsISupports getClassObject(String arg1, String arg2);

  public nsISupports getClassObjectByContractID(String arg1, String arg2);

  public nsISupports createInstance(String arg1, nsISupports arg2, String arg3);

  public nsISupports createInstanceByContractID(String arg1, nsISupports arg2, String arg3);
}
]]></xsl:text>

 <xsl:call-template name="endFile">
   <xsl:with-param name="file" select="'nsIComponentManager.java'" />
 </xsl:call-template>

 <xsl:call-template name="startFile">
    <xsl:with-param name="file" select="'nsIServiceManager.java'" />
 </xsl:call-template>

 <xsl:text><![CDATA[
public interface nsIServiceManager extends nsISupports
{
  public static final String NS_ISERVICEMANAGER_IID =
    "{8bb35ed9-e332-462d-9155-4a002ab5c958}";

  public nsISupports getService(String arg1, String arg2);

  public nsISupports getServiceByContractID(String arg1, String arg2);

  public boolean isServiceInstantiated(String arg1, String arg2);

  public boolean isServiceInstantiatedByContractID(String arg1, String arg2);
}
]]></xsl:text>

 <xsl:call-template name="endFile">
   <xsl:with-param name="file" select="'nsIServiceManager.java'" />
 </xsl:call-template>

 <xsl:call-template name="startFile">
    <xsl:with-param name="file" select="'nsIExceptionManager.java'" />
 </xsl:call-template>

 <xsl:text><![CDATA[
public interface nsIExceptionManager extends nsISupports
{
  public static final String NS_IEXCEPTIONMANAGER_IID =
    "{efc9d00b-231c-4feb-852c-ac017266a415}";

  public nsIException getCurrentException();
}
]]></xsl:text>

 <xsl:call-template name="endFile">
   <xsl:with-param name="file" select="'nsISupports.java'" />
 </xsl:call-template>

 <xsl:call-template name="startFile">
    <xsl:with-param name="file" select="'nsIExceptionService.java'" />
 </xsl:call-template>

 <xsl:text><![CDATA[
public interface nsIExceptionService extends nsIExceptionManager
{
  public static final String NS_IEXCEPTIONSERVICE_IID =
    "{35a88f54-f267-4414-92a7-191f6454ab52}";

  public nsIExceptionManager getCurrentExceptionManager();
}
]]></xsl:text>

 <xsl:call-template name="endFile">
   <xsl:with-param name="file" select="'nsISupports.java'" />
 </xsl:call-template>

 <xsl:call-template name="startFile">
    <xsl:with-param name="file" select="'nsIException.java'" />
 </xsl:call-template>

 <xsl:text><![CDATA[
public interface nsIException extends nsISupports
{
  public static final String NS_IEXCEPTION_IID =
    "{f3a8d3b4-c424-4edc-8bf6-8974c983ba78}";

   // No methods - placeholder
}
]]></xsl:text>

 <xsl:call-template name="endFile">
   <xsl:with-param name="file" select="'nsISupports.java'" />
 </xsl:call-template>

 <xsl:call-template name="startFile">
    <xsl:with-param name="file" select="'nsIComponentRegistrar.java'" />
 </xsl:call-template>

 <xsl:text><![CDATA[
public interface nsIComponentRegistrar extends nsISupports
{
   public static final String NS_ICOMPONENTREGISTRAR_IID =
    "{2417cbfe-65ad-48a6-b4b6-eb84db174392}";

   // No methods - placeholder
}
]]></xsl:text>

 <xsl:call-template name="endFile">
   <xsl:with-param name="file" select="'nsIComponentRegistrar.java'" />
 </xsl:call-template>


 <xsl:call-template name="startFile">
    <xsl:with-param name="file" select="'nsIFile.java'" />
 </xsl:call-template>

 <xsl:text><![CDATA[
public interface nsIFile extends nsISupports
{
  public static final String NS_IFILE_IID =
    "{c8c0a080-0868-11d3-915f-d9d889d48e3c}";

  // No methods - placeholder
}
]]></xsl:text>

 <xsl:call-template name="endFile">
   <xsl:with-param name="file" select="'nsIFile.java'" />
 </xsl:call-template>

 <xsl:call-template name="startFile">
    <xsl:with-param name="file" select="'nsILocalFile.java'" />
 </xsl:call-template>

 <xsl:text><![CDATA[
public interface nsILocalFile extends nsIFile
{
  public static final String NS_ILOCALFILE_IID =
    "{aa610f20-a889-11d3-8c81-000064657374}";

  // No methods - placeholder
}
]]></xsl:text>

 <xsl:call-template name="endFile">
   <xsl:with-param name="file" select="'nsILocalFile.java'" />
 </xsl:call-template>

</xsl:template>

<xsl:template name="genEnum">
  <xsl:param name="enumname" />
  <xsl:param name="filename" />

  <xsl:call-template name="startFile">
    <xsl:with-param name="file" select="$filename" />
  </xsl:call-template>

  <xsl:value-of select="concat('public interface ', $enumname, ' {&#10;&#10;')" />

  <xsl:variable name="uppername">
    <xsl:call-template name="uppercase">
      <xsl:with-param name="str" select="$enumname" />
    </xsl:call-template>
  </xsl:variable>

  <xsl:value-of select="concat('  public static final String ', $uppername, '_IID = &#10;',
                               '     &quot;{',@uuid, '}&quot;;&#10;&#10;')" />

  <xsl:for-each select="const">
    <xsl:variable name="enumconst" select="@name" />
    <xsl:value-of select="concat('  public static final long ', @name, ' = ', @value, 'L;&#10;&#10;')" />
  </xsl:for-each>

  <xsl:value-of select="'}&#10;&#10;'" />

  <xsl:call-template name="endFile">
    <xsl:with-param name="file" select="$filename" />
  </xsl:call-template>

</xsl:template>

<xsl:template name="typeIdl2Back">
  <xsl:param name="type" />
  <xsl:param name="safearray" />
  <xsl:param name="forceelem" />

  <xsl:variable name="needarray" select="($safearray='yes') and not($forceelem='yes')" />

  <xsl:choose>
    <xsl:when test="$type='unsigned long long'">
      <!-- stupid, rewrite the bridge -->
      <xsl:value-of select="'double'" />
    </xsl:when>

    <xsl:when test="$type='long long'">
      <xsl:value-of select="'long'" />
    </xsl:when>

    <xsl:when test="$type='unsigned long'">
      <xsl:value-of select="'long'" />
    </xsl:when>

    <xsl:when test="$type='long'">
      <xsl:value-of select="'int'" />
    </xsl:when>

    <xsl:when test="$type='unsigned short'">
      <xsl:value-of select="'int'" />
    </xsl:when>

    <xsl:when test="$type='short'">
      <xsl:value-of select="'short'" />
    </xsl:when>

    <xsl:when test="$type='octet'">
      <xsl:value-of select="'byte'" />
    </xsl:when>

    <xsl:when test="$type='boolean'">
      <xsl:value-of select="'boolean'" />
    </xsl:when>

    <xsl:when test="$type='$unknown'">
      <xsl:value-of select="'nsISupports'"/>
    </xsl:when>

    <xsl:when test="$type='wstring'">
      <xsl:value-of select="'String'" />
    </xsl:when>

    <xsl:when test="$type='uuid'">
      <xsl:value-of select="'String'" />
    </xsl:when>

    <xsl:when test="count(key('G_keyInterfacesByName', $type)) > 0">
      <xsl:value-of select="$type" />
    </xsl:when>

    <xsl:when test="count(key('G_keyEnumsByName', $type)) > 0">
      <xsl:value-of select="'long'" />
    </xsl:when>

  </xsl:choose>

  <xsl:if test="$needarray">
    <xsl:value-of select="'[]'" />
  </xsl:if>

</xsl:template>

<xsl:template name="genIface">
  <xsl:param name="ifname" />
  <xsl:param name="filename" />

  <xsl:call-template name="startFile">
    <xsl:with-param name="file" select="$filename" />
  </xsl:call-template>

  <xsl:variable name="extendsidl" select="key('G_keyInterfacesByName', $ifname)/@extends" />

  <xsl:variable name="extends">
    <xsl:choose>
      <xsl:when test="($extendsidl = '$unknown') or ($extendsidl = '$dispatched') or ($extendsidl = '$errorinfo')">
        <xsl:value-of select="'nsISupports'" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$extendsidl" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <xsl:value-of select="concat('public interface ', $ifname, ' extends ', $extends, ' {&#10;&#10;')" />

  <xsl:variable name="uppername">
    <xsl:call-template name="uppercase">
      <xsl:with-param name="str" select="$ifname" />
    </xsl:call-template>
  </xsl:variable>

  <xsl:value-of select="concat('  public static final String ', $uppername, '_IID =&#10;',
                               '    &quot;{',@uuid, '}&quot;;&#10;&#10;')" />

  <xsl:for-each select="attribute">
    <xsl:variable name="attrname" select="@name" />
    <xsl:variable name="attrtype" select="@type" />

    <xsl:variable name="gettername">
      <xsl:call-template name="makeGetterName">
        <xsl:with-param name="attrname" select="$attrname" />
      </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="backtype">
      <xsl:call-template name="typeIdl2Back">
        <xsl:with-param name="type" select="$attrtype" />
        <xsl:with-param name="safearray" select="@safearray" />
      </xsl:call-template>
    </xsl:variable>

    <xsl:variable name="callparam">
      <xsl:if test="@safearray='yes'">
        <xsl:value-of select="concat('  long[] ',  @name, 'Size')" />
      </xsl:if>
    </xsl:variable>

    <xsl:value-of select="concat('  public ', $backtype, ' ', $gettername, '(',$callparam,');&#10;&#10;')" />

    <xsl:if test="not(@readonly='yes')">
      <xsl:variable name="settername">
        <xsl:call-template name="makeSetterName">
          <xsl:with-param name="attrname" select="$attrname" />
        </xsl:call-template>
      </xsl:variable>
      <xsl:value-of select="concat('  public void ',  $settername, '(', $backtype, ' arg1);&#10;&#10;')" />
    </xsl:if>

  </xsl:for-each>

  <xsl:for-each select="method">
    <xsl:variable name="methodname" select="@name" />
    <xsl:variable name="returnidltype" select="param[@dir='return']/@type" />
    <xsl:variable name="returnidlsafearray" select="param[@dir='return']/@safearray" />

    <xsl:variable name="returntype">
      <xsl:choose>
        <xsl:when test="$returnidltype">
          <xsl:call-template name="typeIdl2Back">
            <xsl:with-param name="type" select="$returnidltype" />
            <xsl:with-param name="safearray" select="$returnidlsafearray" />
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>void</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <xsl:value-of select="concat('  public ', $returntype, ' ', $methodname, '(')" />
    <xsl:for-each select="param">
      <xsl:variable name="paramtype">
        <xsl:call-template name="typeIdl2Back">
          <xsl:with-param name="type" select="@type" />
          <xsl:with-param name="safearray" select="@safearray" />
        </xsl:call-template>
      </xsl:variable>
      <xsl:choose>
        <xsl:when test="(@safearray='yes') and (@dir='return')">
          <xsl:value-of select="concat('long[] ', @name)" />
        </xsl:when>
        <xsl:when test="(@safearray='yes') and (@dir='out')">
          <xsl:value-of select="concat('long[] ', @name, 'Size, ', $paramtype, '[] ', @name)" />
        </xsl:when>
        <xsl:when test="(@safearray='yes') and (@dir='in') and (@type='octet')">
          <xsl:value-of select="concat($paramtype, ' ', @name)" />
        </xsl:when>
        <xsl:when test="(@safearray='yes') and (@dir='in')">
          <xsl:value-of select="concat('long ', @name, 'Size, ', $paramtype, ' ', @name)" />
        </xsl:when>
        <xsl:when test="@dir='out'">
          <xsl:value-of select="concat($paramtype, '[] ', @name)" />
        </xsl:when>
         <xsl:when test="@dir='in'">
           <xsl:value-of select="concat($paramtype, ' ', @name)" />
         </xsl:when>
      </xsl:choose>
      <xsl:if test="not(position()=last()) and not(following-sibling::param[1]/@dir='return' and not(following-sibling::param[1]/@safearray='yes'))">
        <xsl:value-of select="', '" />
      </xsl:if>
    </xsl:for-each>
    <xsl:value-of select="       ');&#10;&#10;'" />

  </xsl:for-each>

  <xsl:value-of select="'}&#10;&#10;'" />

  <xsl:call-template name="endFile">
    <xsl:with-param name="file" select="$filename" />
  </xsl:call-template>

</xsl:template>


<xsl:template match="/">

  <!-- Handwritten files -->
  <xsl:call-template name="emitHandwritten"/>

   <!-- Enums -->
  <xsl:for-each select="//enum">
    <xsl:call-template name="genEnum">
      <xsl:with-param name="enumname" select="@name" />
      <xsl:with-param name="filename" select="concat(@name, '.java')" />
    </xsl:call-template>
  </xsl:for-each>

  <!-- Interfaces -->
  <xsl:for-each select="//interface">
    <xsl:variable name="self_target" select="current()/ancestor::if/@target"/>
    <xsl:variable name="module" select="current()/ancestor::module/@name"/>

    <!-- We don't need WSDL-specific nor MIDL-specific interfaces here -->
    <xsl:if test="not($self_target='wsdl') and not($self_target='midl') and not($module)">
      <xsl:call-template name="genIface">
        <xsl:with-param name="ifname" select="@name" />
        <xsl:with-param name="filename" select="concat(@name, '.java')" />
      </xsl:call-template>
    </xsl:if>

  </xsl:for-each>

</xsl:template>

</xsl:stylesheet>