VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/java/tools/genjifaces.xsl@ 49905

Last change on this file since 49905 was 46478, checked in by vboxsync, 12 years ago

libs/xpcom: touch up Java XPCOM wrapper generation, new common exception handlin
g model
Main/glue: Java glue code with better exception handling, indentation/coding style fixes both in the XSLT and the generated code, touched up Java sample code showing exception handling and getting all error information, Python indentation/whitespace cleanup
Main/idl: make more interfaces available over the webservice, some minor docs changes, whitespace cleanup
Main/webservice: redo error reporting through exceptions, no longer loses error
information, allow more fine-grained suppression of methods/attributed, touched up C++ webservice sample code to support showing the full error information, build system changes to prepare for incremental Java compilation, indentation fixesFrontends/VBoxShell: minor cleanups, coding style fixes, indentation fixes, elim
inate warnings

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.7 KB
Line 
1<xsl:stylesheet version = '1.0'
2 xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
3 xmlns:vbox="http://www.virtualbox.org/"
4 xmlns:exsl="http://exslt.org/common"
5 extension-element-prefixes="exsl">
6
7<!--
8
9 genjifaces.xsl:
10 XSLT stylesheet that generates Java XPCOM bridge interface code from VirtualBox.xidl.
11
12 Copyright (C) 2010-2013 Oracle Corporation
13
14 This file is part of VirtualBox Open Source Edition (OSE), as
15 available from http://www.virtualbox.org. This file is free software;
16 you can redistribute it and/or modify it under the terms of the GNU
17 General Public License (GPL) as published by the Free Software
18 Foundation, in version 2 as it comes in the "COPYING" file of the
19 VirtualBox OSE distribution. VirtualBox OSE is distributed in the
20 hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
21-->
22
23<xsl:output
24 method="text"
25 version="1.0"
26 encoding="utf-8"
27 indent="no"/>
28
29<!-- - - - - - - - - - - - - - - - - - - - - - -
30 global XSLT variables
31 - - - - - - - - - - - - - - - - - - - - - - -->
32
33<xsl:variable name="G_xsltFilename" select="'genjifaces.xsl'" />
34
35<xsl:template name="uppercase">
36 <xsl:param name="str" select="."/>
37 <xsl:value-of select="translate($str, 'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')" />
38</xsl:template>
39
40<xsl:template name="capitalize">
41 <xsl:param name="str" select="."/>
42 <xsl:value-of select="
43 concat(translate(substring($str,1,1),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ'),
44 substring($str,2))"/>
45</xsl:template>
46
47<xsl:template name="makeGetterName">
48 <xsl:param name="attrname" />
49 <xsl:variable name="capsname">
50 <xsl:call-template name="capitalize">
51 <xsl:with-param name="str" select="$attrname" />
52 </xsl:call-template>
53 </xsl:variable>
54 <xsl:value-of select="concat('get', $capsname)" />
55</xsl:template>
56
57<xsl:template name="makeSetterName">
58 <xsl:param name="attrname" />
59 <xsl:variable name="capsname">
60 <xsl:call-template name="capitalize">
61 <xsl:with-param name="str" select="$attrname" />
62 </xsl:call-template>
63 </xsl:variable>
64 <xsl:value-of select="concat('set', $capsname)" />
65</xsl:template>
66
67<xsl:template name="fileheader">
68 <xsl:param name="name" />
69 <xsl:text>/**
70 * Copyright (C) 2010-2013 Oracle Corporation
71 *
72 * This file is part of VirtualBox Open Source Edition (OSE), as
73 * available from http://www.virtualbox.org. This file is free software;
74 * you can redistribute it and/or modify it under the terms of the GNU
75 * General Public License (GPL) as published by the Free Software
76 * Foundation, in version 2 as it comes in the "COPYING" file of the
77 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
78 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
79 *
80</xsl:text>
81 <xsl:value-of select="concat(' * ',$name)"/>
82<xsl:text>
83 *
84 * DO NOT EDIT! This is a generated file.
85 * Generated from: src/VBox/Main/idl/VirtualBox.xidl (VirtualBox's interface definitions in XML)
86 * Generator: src/VBox/src/libs/xpcom18a4/java/tools/genjifaces.xsl
87 */
88
89</xsl:text>
90</xsl:template>
91
92<xsl:template name="startFile">
93 <xsl:param name="file" />
94
95 <xsl:value-of select="concat('&#10;// ##### BEGINFILE &quot;', $file, '&quot;&#10;&#10;')" />
96 <xsl:call-template name="fileheader">
97 <xsl:with-param name="name" select="$file" />
98 </xsl:call-template>
99
100 <xsl:value-of select=" 'package org.mozilla.interfaces;&#10;&#10;'" />
101</xsl:template>
102
103<xsl:template name="endFile">
104 <xsl:param name="file" />
105 <xsl:value-of select="concat('&#10;// ##### ENDFILE &quot;', $file, '&quot;&#10;&#10;')" />
106</xsl:template>
107
108
109<xsl:template name="emitHandwritten">
110
111 <xsl:call-template name="startFile">
112 <xsl:with-param name="file" select="'nsISupports.java'" />
113 </xsl:call-template>
114
115 <xsl:text><![CDATA[
116public interface nsISupports
117{
118 public static final String NS_ISUPPORTS_IID =
119 "{00000000-0000-0000-c000-000000000046}";
120
121 public nsISupports queryInterface(String arg1);
122}
123]]></xsl:text>
124
125 <xsl:call-template name="endFile">
126 <xsl:with-param name="file" select="'nsISupports.java'" />
127 </xsl:call-template>
128
129 <xsl:call-template name="startFile">
130 <xsl:with-param name="file" select="'nsIComponentManager.java'" />
131 </xsl:call-template>
132
133 <xsl:text><![CDATA[
134public interface nsIComponentManager extends nsISupports
135{
136 public static final String NS_ICOMPONENTMANAGER_IID =
137 "{a88e5a60-205a-4bb1-94e1-2628daf51eae}";
138
139 public nsISupports getClassObject(String arg1, String arg2);
140
141 public nsISupports getClassObjectByContractID(String arg1, String arg2);
142
143 public nsISupports createInstance(String arg1, nsISupports arg2, String arg3);
144
145 public nsISupports createInstanceByContractID(String arg1, nsISupports arg2, String arg3);
146}
147]]></xsl:text>
148
149 <xsl:call-template name="endFile">
150 <xsl:with-param name="file" select="'nsIComponentManager.java'" />
151 </xsl:call-template>
152
153 <xsl:call-template name="startFile">
154 <xsl:with-param name="file" select="'nsIServiceManager.java'" />
155 </xsl:call-template>
156
157 <xsl:text><![CDATA[
158public interface nsIServiceManager extends nsISupports
159{
160 public static final String NS_ISERVICEMANAGER_IID =
161 "{8bb35ed9-e332-462d-9155-4a002ab5c958}";
162
163 public nsISupports getService(String arg1, String arg2);
164
165 public nsISupports getServiceByContractID(String arg1, String arg2);
166
167 public boolean isServiceInstantiated(String arg1, String arg2);
168
169 public boolean isServiceInstantiatedByContractID(String arg1, String arg2);
170}
171]]></xsl:text>
172
173 <xsl:call-template name="endFile">
174 <xsl:with-param name="file" select="'nsIServiceManager.java'" />
175 </xsl:call-template>
176
177 <xsl:call-template name="startFile">
178 <xsl:with-param name="file" select="'nsIExceptionManager.java'" />
179 </xsl:call-template>
180
181 <xsl:text><![CDATA[
182public interface nsIExceptionManager extends nsISupports
183{
184 public static final String NS_IEXCEPTIONMANAGER_IID =
185 "{efc9d00b-231c-4feb-852c-ac017266a415}";
186
187 public nsIException getCurrentException();
188}
189]]></xsl:text>
190
191 <xsl:call-template name="endFile">
192 <xsl:with-param name="file" select="'nsISupports.java'" />
193 </xsl:call-template>
194
195 <xsl:call-template name="startFile">
196 <xsl:with-param name="file" select="'nsIExceptionService.java'" />
197 </xsl:call-template>
198
199 <xsl:text><![CDATA[
200public interface nsIExceptionService extends nsIExceptionManager
201{
202 public static final String NS_IEXCEPTIONSERVICE_IID =
203 "{35a88f54-f267-4414-92a7-191f6454ab52}";
204
205 public nsIExceptionManager getCurrentExceptionManager();
206}
207]]></xsl:text>
208
209 <xsl:call-template name="endFile">
210 <xsl:with-param name="file" select="'nsISupports.java'" />
211 </xsl:call-template>
212
213 <xsl:call-template name="startFile">
214 <xsl:with-param name="file" select="'nsIException.java'" />
215 </xsl:call-template>
216
217 <xsl:text><![CDATA[
218public interface nsIException extends nsISupports
219{
220 public static final String NS_IEXCEPTION_IID =
221 "{f3a8d3b4-c424-4edc-8bf6-8974c983ba78}";
222
223 // No methods - placeholder
224}
225]]></xsl:text>
226
227 <xsl:call-template name="endFile">
228 <xsl:with-param name="file" select="'nsISupports.java'" />
229 </xsl:call-template>
230
231 <xsl:call-template name="startFile">
232 <xsl:with-param name="file" select="'nsIComponentRegistrar.java'" />
233 </xsl:call-template>
234
235 <xsl:text><![CDATA[
236public interface nsIComponentRegistrar extends nsISupports
237{
238 public static final String NS_ICOMPONENTREGISTRAR_IID =
239 "{2417cbfe-65ad-48a6-b4b6-eb84db174392}";
240
241 // No methods - placeholder
242}
243]]></xsl:text>
244
245 <xsl:call-template name="endFile">
246 <xsl:with-param name="file" select="'nsIComponentRegistrar.java'" />
247 </xsl:call-template>
248
249
250 <xsl:call-template name="startFile">
251 <xsl:with-param name="file" select="'nsIFile.java'" />
252 </xsl:call-template>
253
254 <xsl:text><![CDATA[
255public interface nsIFile extends nsISupports
256{
257 public static final String NS_IFILE_IID =
258 "{c8c0a080-0868-11d3-915f-d9d889d48e3c}";
259
260 // No methods - placeholder
261}
262]]></xsl:text>
263
264 <xsl:call-template name="endFile">
265 <xsl:with-param name="file" select="'nsIFile.java'" />
266 </xsl:call-template>
267
268 <xsl:call-template name="startFile">
269 <xsl:with-param name="file" select="'nsILocalFile.java'" />
270 </xsl:call-template>
271
272 <xsl:text><![CDATA[
273public interface nsILocalFile extends nsIFile
274{
275 public static final String NS_ILOCALFILE_IID =
276 "{aa610f20-a889-11d3-8c81-000064657374}";
277
278 // No methods - placeholder
279}
280]]></xsl:text>
281
282 <xsl:call-template name="endFile">
283 <xsl:with-param name="file" select="'nsILocalFile.java'" />
284 </xsl:call-template>
285
286</xsl:template>
287
288<xsl:template name="genEnum">
289 <xsl:param name="enumname" />
290 <xsl:param name="filename" />
291
292 <xsl:call-template name="startFile">
293 <xsl:with-param name="file" select="$filename" />
294 </xsl:call-template>
295
296 <xsl:value-of select="concat('public interface ', $enumname, ' {&#10;&#10;')" />
297
298 <xsl:variable name="uppername">
299 <xsl:call-template name="uppercase">
300 <xsl:with-param name="str" select="$enumname" />
301 </xsl:call-template>
302 </xsl:variable>
303
304 <xsl:value-of select="concat(' public static final String ', $uppername, '_IID = &#10;',
305 ' &quot;{',@uuid, '}&quot;;&#10;&#10;')" />
306
307 <xsl:for-each select="const">
308 <xsl:variable name="enumconst" select="@name" />
309 <xsl:value-of select="concat(' public static final long ', @name, ' = ', @value, 'L;&#10;&#10;')" />
310 </xsl:for-each>
311
312 <xsl:value-of select="'}&#10;&#10;'" />
313
314 <xsl:call-template name="endFile">
315 <xsl:with-param name="file" select="$filename" />
316 </xsl:call-template>
317
318</xsl:template>
319
320<xsl:template name="typeIdl2Back">
321 <xsl:param name="type" />
322 <xsl:param name="safearray" />
323 <xsl:param name="forceelem" />
324
325 <xsl:variable name="needarray" select="($safearray='yes') and not($forceelem='yes')" />
326
327 <xsl:choose>
328 <xsl:when test="$type='unsigned long long'">
329 <!-- stupid, rewrite the bridge -->
330 <xsl:value-of select="'double'" />
331 </xsl:when>
332
333 <xsl:when test="$type='long long'">
334 <xsl:value-of select="'long'" />
335 </xsl:when>
336
337 <xsl:when test="$type='unsigned long'">
338 <xsl:value-of select="'long'" />
339 </xsl:when>
340
341 <xsl:when test="$type='long'">
342 <xsl:value-of select="'int'" />
343 </xsl:when>
344
345 <xsl:when test="$type='unsigned short'">
346 <xsl:value-of select="'int'" />
347 </xsl:when>
348
349 <xsl:when test="$type='short'">
350 <xsl:value-of select="'short'" />
351 </xsl:when>
352
353 <xsl:when test="$type='octet'">
354 <xsl:value-of select="'byte'" />
355 </xsl:when>
356
357 <xsl:when test="$type='boolean'">
358 <xsl:value-of select="'boolean'" />
359 </xsl:when>
360
361 <xsl:when test="$type='$unknown'">
362 <xsl:value-of select="'nsISupports'"/>
363 </xsl:when>
364
365 <xsl:when test="$type='wstring'">
366 <xsl:value-of select="'String'" />
367 </xsl:when>
368
369 <xsl:when test="$type='uuid'">
370 <xsl:value-of select="'String'" />
371 </xsl:when>
372
373 <xsl:when test="//interface[@name=$type]">
374 <xsl:value-of select="$type" />
375 </xsl:when>
376
377 <xsl:when test="//enum[@name=$type]">
378 <xsl:value-of select="'long'" />
379 </xsl:when>
380
381 </xsl:choose>
382
383 <xsl:if test="$needarray">
384 <xsl:value-of select="'[]'" />
385 </xsl:if>
386
387</xsl:template>
388
389<xsl:template name="genIface">
390 <xsl:param name="ifname" />
391 <xsl:param name="filename" />
392
393 <xsl:call-template name="startFile">
394 <xsl:with-param name="file" select="$filename" />
395 </xsl:call-template>
396
397 <xsl:variable name="extendsidl" select="//interface[@name=$ifname]/@extends" />
398
399 <xsl:variable name="extends">
400 <xsl:choose>
401 <xsl:when test="($extendsidl = '$unknown') or ($extendsidl = '$dispatched') or ($extendsidl = '$errorinfo')">
402 <xsl:value-of select="'nsISupports'" />
403 </xsl:when>
404 <xsl:otherwise>
405 <xsl:value-of select="$extendsidl" />
406 </xsl:otherwise>
407 </xsl:choose>
408 </xsl:variable>
409
410 <xsl:value-of select="concat('public interface ', $ifname, ' extends ', $extends, ' {&#10;&#10;')" />
411
412 <xsl:variable name="uppername">
413 <xsl:call-template name="uppercase">
414 <xsl:with-param name="str" select="$ifname" />
415 </xsl:call-template>
416 </xsl:variable>
417
418 <xsl:value-of select="concat(' public static final String ', $uppername, '_IID =&#10;',
419 ' &quot;{',@uuid, '}&quot;;&#10;&#10;')" />
420
421 <xsl:for-each select="attribute">
422 <xsl:variable name="attrname" select="@name" />
423 <xsl:variable name="attrtype" select="@type" />
424
425 <xsl:variable name="gettername">
426 <xsl:call-template name="makeGetterName">
427 <xsl:with-param name="attrname" select="$attrname" />
428 </xsl:call-template>
429 </xsl:variable>
430 <xsl:variable name="backtype">
431 <xsl:call-template name="typeIdl2Back">
432 <xsl:with-param name="type" select="$attrtype" />
433 <xsl:with-param name="safearray" select="@safearray" />
434 </xsl:call-template>
435 </xsl:variable>
436
437 <xsl:variable name="callparam">
438 <xsl:if test="@safearray='yes'">
439 <xsl:value-of select="concat(' long[] ', @name, 'Size')" />
440 </xsl:if>
441 </xsl:variable>
442
443 <xsl:value-of select="concat(' public ', $backtype, ' ', $gettername, '(',$callparam,');&#10;&#10;')" />
444
445 <xsl:if test="not(@readonly='yes')">
446 <xsl:variable name="settername">
447 <xsl:call-template name="makeSetterName">
448 <xsl:with-param name="attrname" select="$attrname" />
449 </xsl:call-template>
450 </xsl:variable>
451 <xsl:value-of select="concat(' public void ', $settername, '(', $backtype, ' arg1);&#10;&#10;')" />
452 </xsl:if>
453
454 </xsl:for-each>
455
456 <xsl:for-each select="method">
457 <xsl:variable name="methodname" select="@name" />
458 <xsl:variable name="returnidltype" select="param[@dir='return']/@type" />
459 <xsl:variable name="returnidlsafearray" select="param[@dir='return']/@safearray" />
460
461 <xsl:variable name="returntype">
462 <xsl:choose>
463 <xsl:when test="$returnidltype">
464 <xsl:call-template name="typeIdl2Back">
465 <xsl:with-param name="type" select="$returnidltype" />
466 <xsl:with-param name="safearray" select="$returnidlsafearray" />
467 </xsl:call-template>
468 </xsl:when>
469 <xsl:otherwise>
470 <xsl:text>void</xsl:text>
471 </xsl:otherwise>
472 </xsl:choose>
473 </xsl:variable>
474
475 <xsl:value-of select="concat(' public ', $returntype, ' ', $methodname, '(')" />
476 <xsl:for-each select="param">
477 <xsl:variable name="paramtype">
478 <xsl:call-template name="typeIdl2Back">
479 <xsl:with-param name="type" select="@type" />
480 <xsl:with-param name="safearray" select="@safearray" />
481 </xsl:call-template>
482 </xsl:variable>
483 <xsl:choose>
484 <xsl:when test="(@safearray='yes') and (@dir='return')">
485 <xsl:value-of select="concat('long[] ', @name)" />
486 </xsl:when>
487 <xsl:when test="(@safearray='yes') and (@dir='out')">
488 <xsl:value-of select="concat('long[] ', @name, 'Size, ', $paramtype, '[] ', @name)" />
489 </xsl:when>
490 <xsl:when test="(@safearray='yes') and (@dir='in') and (@type='octet')">
491 <xsl:value-of select="concat($paramtype, ' ', @name)" />
492 </xsl:when>
493 <xsl:when test="(@safearray='yes') and (@dir='in')">
494 <xsl:value-of select="concat('long ', @name, 'Size, ', $paramtype, ' ', @name)" />
495 </xsl:when>
496 <xsl:when test="@dir='out'">
497 <xsl:value-of select="concat($paramtype, '[] ', @name)" />
498 </xsl:when>
499 <xsl:when test="@dir='in'">
500 <xsl:value-of select="concat($paramtype, ' ', @name)" />
501 </xsl:when>
502 </xsl:choose>
503 <xsl:if test="not(position()=last()) and not(following-sibling::param[1]/@dir='return' and not(following-sibling::param[1]/@safearray='yes'))">
504 <xsl:value-of select="', '" />
505 </xsl:if>
506 </xsl:for-each>
507 <xsl:value-of select=" ');&#10;&#10;'" />
508
509 </xsl:for-each>
510
511 <xsl:value-of select="'}&#10;&#10;'" />
512
513 <xsl:call-template name="endFile">
514 <xsl:with-param name="file" select="$filename" />
515 </xsl:call-template>
516
517</xsl:template>
518
519
520<xsl:template match="/">
521
522 <!-- Handwritten files -->
523 <xsl:call-template name="emitHandwritten"/>
524
525 <!-- Enums -->
526 <xsl:for-each select="//enum">
527 <xsl:call-template name="genEnum">
528 <xsl:with-param name="enumname" select="@name" />
529 <xsl:with-param name="filename" select="concat(@name, '.java')" />
530 </xsl:call-template>
531 </xsl:for-each>
532
533 <!-- Interfaces -->
534 <xsl:for-each select="//interface">
535 <xsl:variable name="self_target" select="current()/ancestor::if/@target"/>
536 <xsl:variable name="module" select="current()/ancestor::module/@name"/>
537
538 <!-- We don't need WSDL-specific interfaces here -->
539 <xsl:if test="not($self_target='wsdl') and not($module)">
540 <xsl:call-template name="genIface">
541 <xsl:with-param name="ifname" select="@name" />
542 <xsl:with-param name="filename" select="concat(@name, '.java')" />
543 </xsl:call-template>
544 </xsl:if>
545
546 </xsl:for-each>
547
548</xsl:template>
549
550</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