* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
<xsl:value-of select="concat(' * ',$name)"/>
* DO NOT EDIT! This is a generated file.
<xsl:template name="startFile">
<xsl:param name="file" />
<xsl:param name="package" />
<xsl:value-of select="concat(' // ##### BEGINFILE "', $G_vboxDirPrefix, $file, '" ')" />
<xsl:call-template name="fileheader">
<xsl:with-param name="name" select="$file" />
<xsl:value-of select="concat('package ',$package,'; ')" />
<xsl:value-of select="concat('import ',$G_virtualBoxPackageCom,'.*; ')" />
<xsl:when test="$G_vboxGlueStyle='xpcom'">
<xsl:when test="$G_vboxGlueStyle='mscom'">
<xsl:when test="$G_vboxGlueStyle='jaxws'">
<xsl:call-template name="fatalError">
<xsl:with-param name="msg" select="'no header rule (startFile)'" />
<xsl:template name="endFile">
<xsl:param name="file" />
<xsl:value-of select="concat(' // ##### ENDFILE "', $file, '" ')" />
<xsl:template name="string-replace">
<xsl:param name="haystack"/>
<xsl:param name="needle"/>
<xsl:param name="replacement"/>
<xsl:when test="contains($haystack,$needle)">
<xsl:value-of select="substring-before($haystack,$needle)"/>
<xsl:value-of select="$replacement"/>
<xsl:call-template name="string-replace">
<xsl:with-param name="haystack" select="substring-after($haystack,$needle)"/>
<xsl:with-param name="needle" select="$needle"/>
<xsl:with-param name="replacement" select="$replacement"/>
<xsl:value-of select="$haystack"/>
<xsl:template match="*/text()">
<!-- TODO: strip out @c/@a for now. long term solution is changing that to a
tag in the xidl file, and translate it when generating doxygen etc. -->
<xsl:variable name="rep1">
<xsl:call-template name="string-replace">
<xsl:with-param name="haystack" select="."/>
<xsl:with-param name="needle" select="'@c'"/>
<xsl:with-param name="replacement" select="''"/>
<xsl:variable name="rep2">
<xsl:call-template name="string-replace">
<xsl:with-param name="haystack" select="$rep1"/>
<xsl:with-param name="needle" select="'@a'"/>
<xsl:with-param name="replacement" select="''"/>
<xsl:variable name="rep3">
<xsl:call-template name="string-replace">
<xsl:with-param name="haystack" select="$rep2"/>
<xsl:with-param name="needle" select="'@todo'"/>
<xsl:with-param name="replacement" select="'TODO'"/>
<xsl:value-of select="$rep3"/>
* all sub-elements that are not explicitly matched are considered to be
* html tags and copied w/o modifications
<xsl:template match="desc//*">
<xsl:variable name="tagname" select="local-name()"/>
<xsl:value-of select="concat('<',$tagname,'>')"/>
<xsl:value-of select="concat('</',$tagname,'>')"/>
<xsl:template name="emit_refsig">
<xsl:param name="context"/>
<xsl:param name="identifier"/>
<xsl:when test="//enum[@name=$context]/const[@name=$identifier]">
<xsl:value-of select="$identifier"/>
<xsl:when test="//interface[@name=$context]/method[@name=$identifier]">
<xsl:value-of select="$identifier"/>
<xsl:for-each select="//interface[@name=$context]/method[@name=$identifier]/param">
<xsl:if test="@dir!='return'">
<xsl:if test="position() > 1">
<xsl:when test="@dir='out'">
<xsl:text>Holder</xsl:text>
<xsl:call-template name="typeIdl2Glue">
<xsl:with-param name="type" select="@type"/>
<xsl:with-param name="safearray" select="@safearray"/>
<xsl:with-param name="skiplisttype" select="'yes'"/>
<xsl:when test="//interface[@name=$context]/attribute[@name=$identifier]">
<xsl:call-template name="makeGetterName">
<xsl:with-param name="attrname" select="$identifier" />
<xsl:call-template name="fatalError">
<xsl:with-param name="msg" select="concat('unknown reference destination in @see/@link: context=',$context,' identifier=',$identifier)" />
<xsl:template match="desc//link">
<xsl:text>{@link </xsl:text>
<xsl:apply-templates select="." mode="middle"/>
<xsl:template match="link" mode="middle">
<xsl:variable name="linktext">
<xsl:value-of select="translate(@to,'_','#')"/>
<xsl:when test="substring($linktext,1,1)='#'">
<xsl:variable name="context">
<xsl:when test="local-name(../..)='interface' or local-name(../..)='enum'">
<xsl:value-of select="../../@name"/>
<xsl:when test="local-name(../../..)='interface' or local-name(../../..)='enum'">
<xsl:value-of select="../../../@name"/>
<xsl:when test="local-name(../../../..)='interface' or local-name(../../../..)='enum'">
<xsl:value-of select="../../../../@name"/>
<xsl:when test="local-name(../../../../..)='interface' or local-name(../../../../..)='enum'">
<xsl:value-of select="../../../../../@name"/>
<xsl:when test="local-name(../../../../../..)='interface' or local-name(../../../../../..)='enum'">
<xsl:value-of select="../../../../../../@name"/>
<xsl:call-template name="fatalError">
<xsl:with-param name="msg" select="concat('cannot determine context for identifier ',$linktext)" />
<xsl:variable name="linkname">
<xsl:value-of select="substring($linktext,2)"/>
<xsl:call-template name="emit_refsig">
<xsl:with-param name="context" select="$context"/>
<xsl:with-param name="identifier" select="$linkname"/>
<xsl:when test="contains($linktext,'::')">
<xsl:variable name="context">
<xsl:value-of select="substring-before($linktext,'::')"/>
<xsl:variable name="linkname">
<xsl:value-of select="substring-after($linktext,'::')"/>
<xsl:value-of select="concat($G_virtualBoxPackage,'.',$context,'#')"/>
<xsl:call-template name="emit_refsig">
<xsl:with-param name="context" select="$context"/>
<xsl:with-param name="identifier" select="$linkname"/>
<xsl:value-of select="concat($G_virtualBoxPackage,'.',$linktext)"/>
<xsl:if test="not(@internal='yes')">
<xsl:text> NOTE: </xsl:text>
<xsl:text> </xsl:text>
<!-- TODO: quirk in our xidl file: only one <see> tag with <link> nested
into it, translate this to multiple @see lines and strip the rest.
Should be replaced in the xidl by multiple <see> without nested tag -->
<xsl:text> </xsl:text>
<xsl:apply-templates match="link"/>
<xsl:text>@see </xsl:text>
<xsl:apply-templates select="." mode="middle"/>
<xsl:text> </xsl:text>
* common comment prologue (handles group IDs)
<xsl:template match="desc" mode="begin">
<xsl:param name="id" select="@group | preceding::descGroup[1]/@id"/>
<xsl:text>/** </xsl:text>
<xsl:value-of select="concat(' @ingroup ',$id,' ')"/>
* common middle part of the comment block
<xsl:template match="desc" mode="middle">
<xsl:apply-templates select="text() | *[not(self::note or self::see)]"/>
<xsl:apply-templates select="note"/>
<xsl:apply-templates select="see"/>
* result part of the comment block
<xsl:template match="desc" mode="results">
<xsl:text> Expected result codes: </xsl:text>
<xsl:text><table> </xsl:text>
<xsl:for-each select="result">
<xsl:text><tr></xsl:text>
<xsl:value-of select="concat('<td>@link ::',@name,' ',@name,'</td>')"/>
<xsl:value-of select="concat('<td>',@name,'</td>')"/>
<xsl:text><td></xsl:text>
<xsl:apply-templates select="text() | *[not(self::note or self::see or
<xsl:text></td><tr> </xsl:text>
<xsl:text></table> </xsl:text>
* translates the string to uppercase
<xsl:template name="uppercase">
<xsl:param name="str" select="."/>
translate($str,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')
<xsl:template match="desc" mode="interface">
<xsl:apply-templates select="." mode="begin"/>
<xsl:apply-templates select="." mode="middle"/>
<xsl:text> Interface ID: <tt>{</xsl:text>
<xsl:call-template name="uppercase">
<xsl:with-param name="str" select="../@uuid"/>
<xsl:text>}</tt> */ </xsl:text>
* comment for attribute getters
<xsl:template match="desc" mode="attribute_get">
<xsl:apply-templates select="." mode="begin"/>
<xsl:apply-templates select="text() | *[not(self::note or self::see or self::result)]"/>
<xsl:apply-templates select="." mode="results"/>
<xsl:apply-templates select="note"/>
<xsl:text> @return </xsl:text>
<xsl:call-template name="typeIdl2Glue">
<xsl:with-param name="type" select="../@type"/>
<xsl:with-param name="safearray" select="../@safearray"/>
<xsl:text> </xsl:text>
<xsl:apply-templates select="see"/>
<xsl:text> */ </xsl:text>
* comment for attribute setters
<xsl:template match="desc" mode="attribute_set">
<xsl:apply-templates select="." mode="begin"/>
<xsl:apply-templates select="text() | *[not(self::note or self::see or self::result)]"/>
<xsl:apply-templates select="." mode="results"/>
<xsl:apply-templates select="note"/>
<xsl:text> @param value </xsl:text>
<xsl:call-template name="typeIdl2Glue">
<xsl:with-param name="type" select="../@type"/>
<xsl:with-param name="safearray" select="../@safearray"/>
<xsl:text> </xsl:text>
<xsl:apply-templates select="see"/>
<xsl:text> */ </xsl:text>
<xsl:template match="desc" mode="method">
<xsl:apply-templates select="." mode="begin"/>
<xsl:apply-templates select="text() | *[not(self::note or self::see or self::result)]"/>
<xsl:for-each select="../param">
<xsl:apply-templates select="desc"/>
<xsl:apply-templates select="." mode="results"/>
<xsl:apply-templates select="note"/>
<xsl:apply-templates select="see"/>
<xsl:text> */ </xsl:text>
* comment for method parameters
<xsl:if test="text() | *[not(self::note or self::see)]">
<xsl:when test="../@dir='return'">
<xsl:text> @return </xsl:text>
<xsl:text> @param </xsl:text>
<xsl:value-of select="../@name"/>
<xsl:apply-templates select="text() | *[not(self::note or self::see)]"/>
<xsl:text> </xsl:text>
<xsl:template match="desc" mode="enum">
<xsl:apply-templates select="." mode="begin"/>
<xsl:apply-templates select="." mode="middle"/>
<xsl:text> Interface ID: <tt>{</xsl:text>
<xsl:call-template name="uppercase">
<xsl:with-param name="str" select="../@uuid"/>
<xsl:text>}</tt> */ </xsl:text>
* comment for enum values
<xsl:template match="desc" mode="enum_const">
<xsl:apply-templates select="." mode="begin"/>
<xsl:apply-templates select="." mode="middle"/>
<xsl:text> */ </xsl:text>
* ignore descGroups by default (processed in /idl)
<xsl:template match="descGroup"/>
<!-- actual code generation -->
<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:with-param name="package" select="$G_virtualBoxPackage" />
<xsl:apply-templates select="desc" mode="enum"/>
<xsl:value-of select="concat('public enum ', $enumname, ' { ')" />
<xsl:for-each select="const">
<xsl:apply-templates select="desc" mode="enum_const"/>
<xsl:variable name="enumconst" select="@name" />
<xsl:value-of select="concat(' ', $enumconst, '(', @value, ')')" />
<xsl:when test="not(position()=last())">
<xsl:text>, </xsl:text>
<xsl:text>; </xsl:text>
<xsl:text> </xsl:text>
<xsl:text> private final int value; </xsl:text>
<xsl:value-of select="concat(' ', $enumname, '(int v) { ')" />
<xsl:text> value = v; </xsl:text>
<xsl:text> } </xsl:text>
<xsl:text> public int value() { </xsl:text>
<xsl:text> return value; </xsl:text>
<xsl:text> } </xsl:text>
<xsl:value-of select="concat(' public static ', $enumname, ' fromValue(long v) { ')" />
<xsl:value-of select="concat(' for (', $enumname, ' c: ', $enumname, '.values()) { ')" />
<xsl:text> if (
c.value == (int)v) { </xsl:text>
<xsl:text> return c; </xsl:text>
<xsl:text> } </xsl:text>
<xsl:text> } </xsl:text>
<xsl:text> throw new IllegalArgumentException(
Long.toString(v)); </xsl:text>
<xsl:text> } </xsl:text>
<xsl:value-of select="concat(' public static ', $enumname, ' fromValue(String v) { ')" />
<xsl:value-of select="concat(' return valueOf(',$enumname, '.class, v); ')" />
<xsl:value-of select=" ' } '" />
<xsl:text>} </xsl:text>
<xsl:call-template name="endFile">
<xsl:with-param name="file" select="$filename" />
<xsl:template name="startExcWrapper">
<xsl:value-of select="' try { '" />
<xsl:template name="endExcWrapper">
<xsl:when test="$G_vboxGlueStyle='xpcom'">
<xsl:value-of select="' throw new VBoxException(e,
e.getMessage()); '" />
<xsl:value-of select="' } '" />
<xsl:when test="$G_vboxGlueStyle='mscom'">
<xsl:value-of select="' throw new VBoxException(e,
e.getMessage()); '" />
<xsl:value-of select="' } '" />
<xsl:when test="$G_vboxGlueStyle='jaxws'">
<xsl:value-of select="' } catch (InvalidObjectFaultMsg e) { '" />
<xsl:value-of select="' throw new VBoxException(e,
e.getMessage()); '" />
<xsl:value-of select="' } catch (RuntimeFaultMsg e) { '" />
<xsl:value-of select="' throw new VBoxException(e,
e.getMessage()); '" />
<xsl:value-of select="' } '" />
<xsl:call-template name="fatalError">
<xsl:with-param name="msg" select="'no header rule (startFile)'" />
<xsl:template name="wrappedName">
<xsl:param name="ifname" />
<xsl:when test="$G_vboxGlueStyle='xpcom'">
<xsl:when test="$G_vboxGlueStyle='mscom'">
<xsl:when test="$G_vboxGlueStyle='jaxws'">
<xsl:value-of select="'String'" />
<xsl:call-template name="fatalError">
<xsl:with-param name="msg" select="'no wrapper naming rule defined (wrappedName)'" />
<xsl:template name="fullClassName">
<xsl:param name="name" />
<xsl:param name="origname" />
<xsl:param name="collPrefix" />
<xsl:when test="//enum[@name=$name] or //enum[@name=$origname]">
<xsl:value-of select="concat($G_virtualBoxPackage, concat('.', $name))" />
<xsl:when test="//interface[@name=$name]">
<xsl:value-of select="concat($G_virtualBoxPackage, concat('.', $name))" />
<xsl:call-template name="fatalError">
<xsl:with-param name="msg" select="concat('fullClassName: Type "', $name, '" is not supported.')" />
<xsl:template name="typeIdl2Glue">
<xsl:param name="type" />
<xsl:param name="safearray" />
<xsl:param name="forceelem" />
<xsl:param name="skiplisttype" />
<xsl:variable name="needarray" select="($safearray='yes') and not($forceelem='yes')" />
<xsl:variable name="needlist" select="($needarray) and not($type='octet')" />
<xsl:if test="($needlist)">
<xsl:value-of select="'List'" />
<xsl:if test="not($skiplisttype='yes')">
<xsl:value-of select="'<'" />
<xsl:if test="not($needlist) or not($skiplisttype='yes')">
<xsl:variable name="javatypefield" select="exsl:node-set($G_aSharedTypes)/type[@idlname=$type]/@javaname" />
<xsl:when test="string-length($javatypefield)">
<xsl:value-of select="$javatypefield" />
<!-- not a standard type: then it better be one of the types defined in the XIDL -->
<xsl:when test="$type='$unknown'">IUnknown</xsl:when>
<xsl:call-template name="fullClassName">
<xsl:with-param name="name" select="$type" />
<xsl:with-param name="collPrefix" select="''"/>
<xsl:when test="($needlist)">
<xsl:if test="not($skiplisttype='yes')">
<xsl:value-of select="'>'" />
<xsl:when test="($needarray)">
<xsl:value-of select="'[]'" />
typeIdl2Back: converts $type into a type as used by the backend.
<xsl:template name="typeIdl2Back">
<xsl:param name="type" />
<xsl:param name="safearray" />
<xsl:param name="forceelem" />
<xsl:when test="($G_vboxGlueStyle='xpcom')">
<xsl:variable name="needarray" select="($safearray='yes') and not($forceelem='yes')" />
<xsl:when test="$type='long long'">
<xsl:value-of select="'long'" />
<xsl:when test="$type='unsigned long'">
<xsl:value-of select="'long'" />
<xsl:when test="$type='long'">
<xsl:value-of select="'int'" />
<xsl:when test="$type='unsigned short'">
<xsl:value-of select="'int'" />
<xsl:when test="$type='short'">
<xsl:value-of select="'short'" />
<xsl:when test="$type='octet'">
<xsl:value-of select="'byte'" />
<xsl:when test="$type='boolean'">
<xsl:value-of select="'boolean'" />
<xsl:when test="$type='$unknown'">
<xsl:value-of select="'nsISupports'"/>
<xsl:when test="$type='wstring'">
<xsl:value-of select="'String'" />
<xsl:when test="$type='uuid'">
<xsl:value-of select="'String'" />
<xsl:when test="//interface[@name=$type]/@wsmap='struct'">
<xsl:call-template name="wrappedName">
<xsl:with-param name="ifname" select="$type" />
<xsl:when test="//interface[@name=$type]">
<xsl:call-template name="wrappedName">
<xsl:with-param name="ifname" select="$type" />
<xsl:when test="//enum[@name=$type]">
<xsl:value-of select="'long'" />
<xsl:call-template name="fullClassName">
<xsl:with-param name="name" select="$type" />
<xsl:if test="$needarray">
<xsl:value-of select="'[]'" />
<xsl:when test="($G_vboxGlueStyle='mscom')">
<xsl:value-of select="'Variant'"/>
<xsl:when test="($G_vboxGlueStyle='jaxws')">
<xsl:variable name="needarray" select="($safearray='yes' and not($type='octet')) and not($forceelem='yes')" />
<xsl:if test="$needarray">
<xsl:value-of select="'List<'" />
<xsl:when test="$type='$unknown'">
<xsl:value-of select="'String'" />
<xsl:when test="//interface[@name=$type]/@wsmap='managed'">
<xsl:value-of select="'String'" />
<xsl:when test="//interface[@name=$type]/@wsmap='struct'">
<xsl:value-of select="concat($G_virtualBoxPackageCom, '.', $type)" />
<xsl:when test="//enum[@name=$type]">
<xsl:value-of select="concat($G_virtualBoxPackageCom, '.', $type)" />
<!-- we encode byte arrays as Base64 strings. -->
<xsl:when test="$type='octet'">
<xsl:value-of select="'/*base64*/String'" />
<xsl:when test="$type='long long'">
<xsl:value-of select="'Long'" />
<xsl:when test="$type='unsigned long'">
<xsl:value-of select="'Long'" />
<xsl:when test="$type='long'">
<xsl:value-of select="'Integer'" />
<xsl:when test="$type='unsigned short'">
<xsl:value-of select="'Integer'" />
<xsl:when test="$type='short'">
<xsl:value-of select="'Short'" />
<xsl:when test="$type='boolean'">
<xsl:value-of select="'Boolean'" />
<xsl:when test="$type='wstring'">
<xsl:value-of select="'String'" />
<xsl:when test="$type='uuid'">
<xsl:value-of select="'String'" />
<xsl:call-template name="fatalError">
<xsl:with-param name="msg" select="concat('Unhandled type ', $type,' (typeIdl2Back)')" />
<xsl:if test="$needarray">
<xsl:value-of select="'>'" />
<xsl:call-template name="fatalError">
<xsl:with-param name="msg" select="'Write typeIdl2Back for this style (typeIdl2Back)'" />
<xsl:template name="cookOutParamXpcom">
<xsl:param name="value"/>
<xsl:param name="idltype"/>
<xsl:param name="safearray"/>
<xsl:variable name="isstruct"
select="//interface[@name=$idltype]/@wsmap='struct'" />
<xsl:variable name="gluetype">
<xsl:call-template name="typeIdl2Glue">
<xsl:with-param name="type" select="$idltype" />
<xsl:with-param name="safearray" select="$safearray" />
<xsl:variable name="elemgluetype">
<xsl:if test="$safearray='yes'">
<xsl:call-template name="typeIdl2Glue">
<xsl:with-param name="type" select="$idltype" />
<xsl:with-param name="safearray" select="'no'" />
<xsl:with-param name="forceelem" select="'yes'" />
<xsl:when test="//interface[@name=$idltype] or $idltype='$unknown'">
<xsl:when test="$safearray='yes'">
<xsl:variable name="elembacktype">
<xsl:call-template name="typeIdl2Back">
<xsl:with-param name="type" select="$idltype" />
<xsl:with-param name="safearray" select="$safearray" />
<xsl:with-param name="forceelem" select="'yes'" />
<xsl:value-of select="concat('
Helper.wrap2(',$elemgluetype, '.class, ', $elembacktype, '.class, ', $value,')')"/>
<xsl:value-of select="concat('(', $value, ' != null) ? new ', $gluetype, '(', $value,') : null')" />
<xsl:when test="//enum[@name=$idltype]">
<xsl:when test="$safearray='yes'">
<xsl:variable name="elembacktype">
<xsl:call-template name="typeIdl2Back">
<xsl:with-param name="type" select="$idltype" />
<xsl:with-param name="safearray" select="$safearray" />
<xsl:with-param name="forceelem" select="'yes'" />
<xsl:value-of select="concat('
Helper.wrapEnum(',$elemgluetype, '.class, ', $value,')')"/>
<xsl:value-of select="concat($gluetype,'.fromValue(', $value,')')"/>
<xsl:when test="($safearray='yes') and ($idltype='octet')">
<xsl:value-of select="$value"/>
<xsl:when test="$safearray='yes'">
<xsl:value-of select="concat('
Helper.wrap(', $value,')')"/>
<xsl:value-of select="$value"/>
<xsl:template name="cookOutParamMscom">
<xsl:param name="value"/>
<xsl:param name="idltype"/>
<xsl:param name="safearray"/>
<xsl:variable name="gluetype">
<xsl:call-template name="typeIdl2Glue">
<xsl:with-param name="type" select="$idltype" />
<xsl:with-param name="safearray" select="$safearray" />
<xsl:when test="$safearray='yes'">
<xsl:variable name="elemgluetype">
<xsl:call-template name="typeIdl2Glue">
<xsl:with-param name="type" select="$idltype" />
<xsl:with-param name="safearray" select="'no'" />
<xsl:with-param name="forceelem" select="'yes'" />
<xsl:when test="($idltype='octet')">
<xsl:value-of select="concat('
Helper.wrap(', $elemgluetype, '.class, ', $value,'.toSafeArray())')"/>
<xsl:when test="//interface[@name=$idltype] or $idltype='$unknown'">
<xsl:value-of select="concat('
Helper.wrapDispatch(',$gluetype, '.class, ', $value,'.getDispatch())')"/>
<xsl:when test="//enum[@name=$idltype]">
<xsl:value-of select="concat($gluetype,'.fromValue(', $value,'.getInt())')"/>
<xsl:when test="$idltype='wstring'">
<xsl:value-of select="concat($value,'.getString()')"/>
<xsl:when test="$idltype='uuid'">
<xsl:value-of select="concat($value,'.getString()')"/>
<xsl:when test="$idltype='boolean'">
<xsl:value-of select="concat($value,'.toBoolean()')"/>
<xsl:when test="$idltype='unsigned short'">
<xsl:value-of select="concat('(int)', $value,'.getShort()')"/>
<xsl:when test="$idltype='short'">
<xsl:value-of select="concat($value,'.getShort()')"/>
<xsl:when test="$idltype='long'">
<xsl:value-of select="concat($value,'.getInt()')"/>
<xsl:when test="$idltype='unsigned long'">
<xsl:value-of select="concat('(long)', $value,'.getInt()')"/>
<xsl:when test="$idltype='long'">
<xsl:value-of select="concat($value,'.getInt()')"/>
<xsl:when test="$idltype='long long'">
<xsl:value-of select="concat($value,'.getLong()')"/>
<xsl:call-template name="fatalError">
<xsl:with-param name="msg" select="concat('Unhandled type' , $idltype, ' (cookOutParamMscom)')" />
<xsl:template name="cookOutParamJaxws">
<xsl:param name="value"/>
<xsl:param name="idltype"/>
<xsl:param name="safearray"/>
<xsl:variable name="isstruct"
select="//interface[@name=$idltype]/@wsmap='struct'" />
<xsl:variable name="gluetype">
<xsl:call-template name="typeIdl2Glue">
<xsl:with-param name="type" select="$idltype" />
<xsl:with-param name="safearray" select="$safearray" />
<xsl:when test="$safearray='yes'">
<xsl:variable name="elemgluetype">
<xsl:call-template name="typeIdl2Glue">
<xsl:with-param name="type" select="$idltype" />
<xsl:with-param name="safearray" select="''" />
<xsl:with-param name="forceelem" select="'yes'" />
<xsl:variable name="elembacktype">
<xsl:call-template name="typeIdl2Back">
<xsl:with-param name="type" select="$idltype" />
<xsl:with-param name="safearray" select="''" />
<xsl:with-param name="forceelem" select="'yes'" />
<xsl:when test="$isstruct">
<xsl:value-of select="concat('
Helper.wrap2(',$elemgluetype, '.class, ', $elembacktype, '.class, port, ', $value,')')"/>
<xsl:when test="//enum[@name=$idltype]">
<xsl:value-of select="concat('
Helper.convertEnums(',$elembacktype, '.class, ', $elemgluetype, '.class, ', $value,')')"/>
<xsl:when test="//interface[@name=$idltype] or $idltype='$unknown'">
<xsl:value-of select="concat('
Helper.wrap(',$elemgluetype,'.class, port, ', $value,')')"/>
<xsl:when test="$idltype='octet'">
<xsl:value-of select="$value" />
<xsl:when test="//enum[@name=$idltype]">
<xsl:value-of select="concat($gluetype,'.fromValue(', $value,'.value())')"/>
<xsl:when test="$idltype='boolean'">
<xsl:value-of select="$value"/>
<xsl:when test="$idltype='long long'">
<xsl:value-of select="$value"/>
<xsl:when test="$idltype='unsigned long long'">
<xsl:value-of select="$value"/>
<xsl:when test="$idltype='long'">
<xsl:value-of select="$value"/>
<xsl:when test="$idltype='unsigned long'">
<xsl:value-of select="$value"/>
<xsl:when test="$idltype='short'">
<xsl:value-of select="$value"/>
<xsl:when test="$idltype='unsigned short'">
<xsl:value-of select="$value"/>
<xsl:when test="$idltype='wstring'">
<xsl:value-of select="$value"/>
<xsl:when test="$idltype='uuid'">
<xsl:value-of select="$value"/>
<xsl:when test="$isstruct">
<xsl:value-of select="concat('(', $value, ' != null) ? new ', $gluetype, '(', $value,', port) : null')" />
<xsl:when test="//interface[@name=$idltype] or $idltype='$unknown'">
<!-- if the MOR string is empty, that means NULL, so return NULL instead of an object then -->
<xsl:value-of select="concat('(', $value, '.length() > 0) ? new ', $gluetype, '(', $value,', port) : null')" />
<xsl:call-template name="fatalError">
<xsl:with-param name="msg" select="concat('Unhandled type ', $idltype, ' (cookOutParamJaxws)')" />
<xsl:template name="cookOutParam">
<xsl:param name="value"/>
<xsl:param name="idltype"/>
<xsl:param name="safearray"/>
<xsl:when test="($G_vboxGlueStyle='xpcom')">
<xsl:call-template name="cookOutParamXpcom">
<xsl:with-param name="value" select="$value" />
<xsl:with-param name="idltype" select="$idltype" />
<xsl:with-param name="safearray" select="$safearray" />
<xsl:when test="($G_vboxGlueStyle='mscom')">
<xsl:call-template name="cookOutParamMscom">
<xsl:with-param name="value" select="$value" />
<xsl:with-param name="idltype" select="$idltype" />
<xsl:with-param name="safearray" select="$safearray" />
<xsl:when test="($G_vboxGlueStyle='jaxws')">
<xsl:call-template name="cookOutParamJaxws">
<xsl:with-param name="value" select="$value" />
<xsl:with-param name="idltype" select="$idltype" />
<xsl:with-param name="safearray" select="$safearray" />
<xsl:call-template name="fatalError">
<xsl:with-param name="msg" select="'Unhandled style(cookOutParam)'" />
<xsl:template name="cookInParamXpcom">
<xsl:param name="value"/>
<xsl:param name="idltype"/>
<xsl:param name="safearray"/>
<xsl:variable name="isstruct"
select="//interface[@name=$idltype]/@wsmap='struct'" />
<xsl:variable name="gluetype">
<xsl:call-template name="typeIdl2Glue">
<xsl:with-param name="type" select="$idltype" />
<xsl:with-param name="safearray" select="$safearray" />
<xsl:variable name="backtype">
<xsl:call-template name="typeIdl2Back">
<xsl:with-param name="type" select="$idltype" />
<xsl:with-param name="safearray" select="$safearray" />
<xsl:variable name="elemgluetype">
<xsl:if test="$safearray='yes'">
<xsl:call-template name="typeIdl2Glue">
<xsl:with-param name="type" select="$idltype" />
<xsl:with-param name="safearray" select="'no'" />
<xsl:with-param name="forceelem" select="'yes'" />
<xsl:when test="//interface[@name=$idltype]">
<xsl:when test="$safearray='yes'">
<xsl:variable name="elembacktype">
<xsl:call-template name="typeIdl2Back">
<xsl:with-param name="type" select="$idltype" />
<xsl:with-param name="safearray" select="$safearray" />
<xsl:with-param name="forceelem" select="'yes'" />
<xsl:value-of select="concat('
Helper.unwrap2(',$elemgluetype, '.class, ', $elembacktype, '.class, ', $value,')')"/>
<xsl:value-of select="concat('(', $value, ' != null) ? ', $value, '.getTypedWrapped() : null')" />
<xsl:when test="$idltype='$unknown'">
<xsl:when test="$safearray='yes'">
<xsl:value-of select="concat('(', $value, ' != null) ? (nsISupports)', $value, '.getWrapped() : null')" />
<xsl:when test="//enum[@name=$idltype]">
<xsl:when test="$safearray='yes'">
<xsl:value-of select="concat('
Helper.unwrapEnum(', $elemgluetype, '.class,', $value,')')"/>
<xsl:value-of select="concat($value,'.value()')"/>
<xsl:when test="($idltype='octet') and ($safearray='yes')">
<xsl:value-of select="$value"/>
<xsl:when test="$safearray='yes'">
<xsl:value-of select="$value"/>
<xsl:template name="cookInParamMscom">
<xsl:param name="value"/>
<xsl:param name="idltype"/>
<xsl:param name="safearray"/>
<xsl:variable name="gluetype">
<xsl:call-template name="typeIdl2Glue">
<xsl:with-param name="type" select="$idltype" />
<xsl:with-param name="safearray" select="$safearray" />
<xsl:variable name="backtype">
<xsl:call-template name="typeIdl2Back">
<xsl:with-param name="type" select="$idltype" />
<xsl:with-param name="safearray" select="$safearray" />
<xsl:variable name="elemgluetype">
<xsl:if test="$safearray='yes'">
<xsl:call-template name="typeIdl2Glue">
<xsl:with-param name="type" select="$idltype" />
<xsl:with-param name="safearray" select="'no'" />
<xsl:with-param name="forceelem" select="'yes'" />
<xsl:when test="//interface[@name=$idltype]">
<xsl:when test="$safearray='yes'">
<xsl:variable name="elembacktype">
<xsl:call-template name="typeIdl2Back">
<xsl:with-param name="type" select="$idltype" />
<xsl:with-param name="safearray" select="$safearray" />
<xsl:with-param name="forceelem" select="'yes'" />
<xsl:value-of select="concat('
Helper.unwrap2(',$elemgluetype, '.class, ', $elembacktype, '.class, ', $value,')')"/>
<xsl:value-of select="concat('(', $value, ' != null) ? ', $value, '.getTypedWrapped() : null')" />
<xsl:when test="$idltype='$unknown'">
<xsl:when test="$safearray='yes'">
<xsl:value-of select="concat('(', $value, ' != null) ? (Dispatch)', $value, '.getWrapped() : null')" />
<xsl:when test="//enum[@name=$idltype]">
<xsl:when test="$safearray='yes'">
<xsl:value-of select="concat('
Helper.unwrapEnum(', $elemgluetype, '.class,',$value,')')"/>
<xsl:value-of select="concat($value,'.value()')"/>
<xsl:when test="$idltype='boolean'">
<xsl:when test="$safearray='yes'">
<xsl:value-of select="concat('new Variant(',$value,')')"/>
<xsl:when test="($idltype='short') or ($idltype='unsigned short')">
<xsl:when test="$safearray='yes'">
<xsl:value-of select="concat('new Variant(',$value,')')"/>
<xsl:when test="($idltype='long') or ($idltype='unsigned long')">
<xsl:when test="$safearray='yes'">
<xsl:value-of select="concat('new Variant(',$value,')')"/>
<xsl:when test="($idltype='wstring') or ($idltype='uuid')">
<xsl:when test="$safearray='yes'">
<xsl:value-of select="concat('new Variant(',$value,')')"/>
<xsl:when test="($idltype='unsigned long long') or ($idltype='long long')">
<xsl:when test="$safearray='yes'">
<xsl:value-of select="concat('new Variant(',$value,'.longValue())')"/>
<xsl:when test="($idltype='octet') and ($safearray='yes')">
<xsl:call-template name="fatalError">
<xsl:with-param name="msg" select="concat('Unhandled type: ', $idltype)" />
<xsl:template name="cookInParamJaxws">
<xsl:param name="value"/>
<xsl:param name="idltype"/>
<xsl:param name="safearray"/>
<xsl:variable name="isstruct"
select="//interface[@name=$idltype]/@wsmap='struct'" />
<xsl:variable name="gluetype">
<xsl:call-template name="typeIdl2Glue">
<xsl:with-param name="type" select="$idltype" />
<xsl:with-param name="safearray" select="$safearray" />
<xsl:variable name="elemgluetype">
<xsl:if test="$safearray='yes'">
<xsl:call-template name="typeIdl2Glue">
<xsl:with-param name="type" select="$idltype" />
<xsl:with-param name="safearray" select="'no'" />
<xsl:with-param name="forceelem" select="'yes'" />
<xsl:when test="//interface[@name=$idltype] or $idltype='$unknown'">
<xsl:when test="@safearray='yes'">
<xsl:value-of select="concat('((', $value, ' == null) ? null :', $value, '.getWrapped())')" />
<xsl:when test="//enum[@name=$idltype]">
<xsl:when test="$safearray='yes'">
<xsl:variable name="elembacktype">
<xsl:call-template name="typeIdl2Back">
<xsl:with-param name="type" select="$idltype" />
<xsl:with-param name="safearray" select="'no'" />
<xsl:with-param name="forceelem" select="'yes'" />
<xsl:value-of select="concat('
Helper.convertEnums(', $elemgluetype, '.class,', $elembacktype, '.class,', $value,')')"/>
<xsl:variable name="backtype">
<xsl:call-template name="typeIdl2Back">
<xsl:with-param name="type" select="$idltype" />
<xsl:with-param name="safearray" select="'no'" />
<xsl:with-param name="forceelem" select="'yes'" />
<xsl:value-of select="concat($backtype, '.fromValue(', $value, '.name())')"/>
<xsl:when test="($idltype='octet') and ($safearray='yes')">
<xsl:value-of select="$value"/>
<xsl:template name="cookInParam">
<xsl:param name="value"/>
<xsl:param name="idltype"/>
<xsl:param name="safearray"/>
<xsl:when test="($G_vboxGlueStyle='xpcom')">
<xsl:call-template name="cookInParamXpcom">
<xsl:with-param name="value" select="$value" />
<xsl:with-param name="idltype" select="$idltype" />
<xsl:with-param name="safearray" select="$safearray" />
<xsl:when test="($G_vboxGlueStyle='mscom')">
<xsl:call-template name="cookInParamMscom">
<xsl:with-param name="value" select="$value" />
<xsl:with-param name="idltype" select="$idltype" />
<xsl:with-param name="safearray" select="$safearray" />
<xsl:when test="($G_vboxGlueStyle='jaxws')">
<xsl:call-template name="cookInParamJaxws">
<xsl:with-param name="value" select="$value" />
<xsl:with-param name="idltype" select="$idltype" />
<xsl:with-param name="safearray" select="$safearray" />
<xsl:call-template name="fatalError">
<xsl:with-param name="msg" select="'Unhandled style (cookInParam)'" />
<!-- Invoke backend method, including parameter conversion -->
<xsl:template name="genBackMethodCall">
<xsl:param name="ifname"/>
<xsl:param name="methodname"/>
<xsl:param name="retval"/>
<xsl:when test="($G_vboxGlueStyle='xpcom')">
<xsl:value-of select="' '" />
<xsl:if test="param[@dir='return']">
<xsl:value-of select="concat($retval, ' = ')" />
<xsl:value-of select="concat('getTypedWrapped().', $methodname,'(')"/>
<xsl:for-each select="param">
<xsl:when test="@dir='return'">
<xsl:if test="@safearray='yes'">
<xsl:value-of select="'null'" />
<xsl:when test="@dir='out'">
<xsl:if test="@safearray='yes'">
<xsl:value-of select="'null, '" />
<xsl:value-of select="concat('tmp_', @name)" />
<xsl:when test="@dir='in'">
<xsl:if test="(@safearray='yes') and not(@type = 'octet')">
<xsl:value-of select="concat(@name,'.size(), ')" />
<xsl:variable name="unwrapped">
<xsl:call-template name="cookInParam">
<xsl:with-param name="value" select="@name" />
<xsl:with-param name="idltype" select="@type" />
<xsl:with-param name="safearray" select="@safearray" />
<xsl:value-of select="$unwrapped"/>
<xsl:call-template name="fatalError">
<xsl:with-param name="msg" select="concat('Unsupported param dir: ', @dir, '".')" />
<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:value-of select="'); '"/>
<xsl:when test="($G_vboxGlueStyle='mscom')">
<xsl:value-of select="' '" />
<xsl:if test="param[@dir='return']">
<xsl:value-of select="concat($retval, ' = ')" />
<xsl:value-of select="concat('
Helper.invoke(getTypedWrapped(), "', $methodname, '" ')"/>
<xsl:for-each select="param[not(@dir='return')]">
<xsl:value-of select="', '"/>
<xsl:when test="@dir='out'">
<xsl:value-of select="concat('tmp_', @name)" />
<xsl:when test="@dir='in'">
<xsl:variable name="unwrapped">
<xsl:call-template name="cookInParam">
<xsl:with-param name="value" select="@name" />
<xsl:with-param name="idltype" select="@type" />
<xsl:with-param name="safearray" select="@safearray" />
<xsl:value-of select="$unwrapped"/>
<xsl:value-of select="'); '"/>
<xsl:when test="($G_vboxGlueStyle='jaxws')">
<xsl:variable name="jaxwsmethod">
<xsl:call-template name="makeJaxwsMethod">
<xsl:with-param name="ifname" select="$ifname" />
<xsl:with-param name="methodname" select="$methodname" />
<xsl:variable name="portArg">
<xsl:if test="not(//interface[@name=$ifname]/@wsmap='global')">
<xsl:value-of select="'obj'"/>
<xsl:variable name="paramsinout" select="param[@dir='in' or @dir='out']" />
<xsl:value-of select="' '" />
<xsl:if test="param[@dir='return'] and not(param[@dir='out'])">
<xsl:value-of select="concat($retval, ' = ')" />
<xsl:value-of select="concat('port.', $jaxwsmethod, '(', $portArg)" />
<xsl:if test="$paramsinout and not($portArg='')">
<xsl:value-of select="', '"/>
<!-- 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... -->
<xsl:when test="param[@dir='out'] and param[@dir='return']">
<xsl:for-each select="param">
<xsl:when test="@dir='return'">
<xsl:value-of select="$retval"/>
<xsl:when test="@dir='out'">
<xsl:value-of select="concat('tmp_', @name)" />
<xsl:call-template name="cookInParam">
<xsl:with-param name="value" select="@name" />
<xsl:with-param name="idltype" select="@type" />
<xsl:with-param name="safearray" select="@safearray" />
<xsl:if test="not(position()=last())">
<xsl:value-of select="', '"/>
<xsl:for-each select="$paramsinout">
<xsl:when test="@dir='return'">
<xsl:value-of select="$retval"/>
<xsl:when test="@dir='out'">
<xsl:value-of select="concat('tmp_', @name)" />
<xsl:call-template name="cookInParam">
<xsl:with-param name="value" select="@name" />
<xsl:with-param name="idltype" select="@type" />
<xsl:with-param name="safearray" select="@safearray" />
<xsl:if test="not(position()=last())">
<xsl:value-of select="', '"/>
<xsl:value-of select="'); '"/>
<xsl:call-template name="fatalError">
<xsl:with-param name="msg" select="'Style unknown (genBackMethodCall)'" />
<xsl:template name="genGetterCall">
<xsl:param name="ifname"/>
<xsl:param name="gettername"/>
<xsl:param name="backtype"/>
<xsl:param name="retval"/>
<xsl:when test="$G_vboxGlueStyle='xpcom'">
<xsl:value-of select="concat(' ', $backtype, ' ', $retval,' = getTypedWrapped().', $gettername,'(')" />
<xsl:if test="@safearray">
<xsl:value-of select="'null'" />
<xsl:value-of select="'); '" />
<xsl:when test="$G_vboxGlueStyle='mscom'">
<xsl:value-of select="concat(' ', $backtype, ' ', $retval,' =
Dispatch.get(getTypedWrapped(), "', @name,'"); ')" />
<xsl:when test="$G_vboxGlueStyle='jaxws'">
<xsl:variable name="jaxwsGetter">
<xsl:call-template name="makeJaxwsMethod">
<xsl:with-param name="ifname" select="$ifname" />
<xsl:with-param name="methodname" select="$gettername" />
<xsl:value-of select="concat(' ', $backtype, ' ', $retval,' = port.', $jaxwsGetter, '(obj); ')" />
<xsl:call-template name="fatalError">
<xsl:with-param name="msg" select="'Style unknown (genGetterCall)'" />
<xsl:template name="genSetterCall">
<xsl:param name="ifname"/>
<xsl:param name="settername"/>
<xsl:param name="value"/>
<xsl:when test="$G_vboxGlueStyle='xpcom'">
<xsl:value-of select="concat(' getTypedWrapped().', $settername, '(', $value,'); ')" />
<xsl:when test="$G_vboxGlueStyle='mscom'">
<xsl:value-of select="concat('
Dispatch.put(getTypedWrapped(), "', @name,'", ',$value, '); ')" />
<xsl:when test="$G_vboxGlueStyle='jaxws'">
<xsl:variable name="jaxwsSetter">
<xsl:call-template name="makeJaxwsMethod">
<xsl:with-param name="ifname" select="$ifname" />
<xsl:with-param name="methodname" select="$settername" />
<xsl:value-of select="concat(' port.', $jaxwsSetter, '(obj, ', $value,'); ')" />
<xsl:call-template name="fatalError">
<xsl:with-param name="msg" select="'Style unknown (genSetterCall)'" />
<xsl:template name="genStructWrapperJaxws">
<xsl:param name="ifname"/>
<xsl:value-of select="concat(' private ', $G_virtualBoxPackageCom,'.',$ifname, ' real; ')"/>
<xsl:value-of select="' private VboxPortType port; '"/>
<xsl:value-of select="concat(' public ', $ifname, '(', $G_virtualBoxPackageCom,'.',$ifname,' real, VboxPortType port) {
this.real = real;
this.port = port; } ')"/>
<xsl:for-each select="attribute">
<xsl:variable name="attrname"><xsl:value-of select="@name" /></xsl:variable>
<xsl:variable name="attrtype"><xsl:value-of select="@type" /></xsl:variable>
<xsl:variable name="attrreadonly"><xsl:value-of select="@readonly" /></xsl:variable>
<xsl:variable name="attrsafearray"><xsl:value-of select="@safearray" /></xsl:variable>
<xsl:if test="not($attrreadonly)">
<xsl:call-template name="fatalError">
<xsl:with-param name="msg" select="'Non read-only struct (genStructWrapperJaxws)'" />
<xsl:variable name="backgettername">
<!-- Stupid, but backend boolean getters called isFoo(), not getFoo() -->
<xsl:when test="$attrtype = 'boolean'">
<xsl:variable name="capsname">
<xsl:call-template name="capitalize">
<xsl:with-param name="str" select="$attrname" />
<xsl:value-of select="concat('is', $capsname)" />
<xsl:call-template name="makeGetterName">
<xsl:with-param name="attrname" select="$attrname" />
<xsl:variable name="gluegettername">
<xsl:call-template name="makeGetterName">
<xsl:with-param name="attrname" select="$attrname" />
<xsl:variable name="gluegettertype">
<xsl:call-template name="typeIdl2Glue">
<xsl:with-param name="type" select="$attrtype" />
<xsl:with-param name="safearray" select="@safearray" />
<xsl:variable name="backgettertype">
<xsl:call-template name="typeIdl2Back">
<xsl:with-param name="type" select="$attrtype" />
<xsl:with-param name="safearray" select="@safearray" />
<xsl:value-of select="concat(' public ', $gluegettertype, ' ', $gluegettername, '() { ')" />
<xsl:value-of select="concat(' ', $backgettertype, ' retVal = real.', $backgettername, '(); ')" />
<xsl:variable name="wrapped">
<xsl:call-template name="cookOutParam">
<xsl:with-param name="value" select="'retVal'" />
<xsl:with-param name="idltype" select="$attrtype" />
<xsl:with-param name="safearray" select="@safearray" />
<xsl:value-of select="concat(' return ', $wrapped, '; ')" />
<xsl:value-of select=" ' } '" />
<!-- Interface method wrapper -->
<xsl:template name="genMethod">
<xsl:param name="ifname"/>
<xsl:param name="methodname"/>
<xsl:when test="(param[@mod='ptr']) or (($G_vboxGlueStyle='jaxws') and (param[@type=($G_setSuppressedInterfaces/@name)]))" >
<xsl:value-of select="concat('Skipping method ', $methodname, ' for it has parameters with suppressed types')" />
<xsl:variable name="hasReturnParms" select="param[@dir='return']" />
<xsl:variable name="hasOutParms" select="param[@dir='out']" />
<xsl:variable name="returnidltype" select="param[@dir='return']/@type" />
<xsl:variable name="returnidlsafearray" select="param[@dir='return']/@safearray" />
<xsl:variable name="returngluetype">
<xsl:when test="$returnidltype">
<xsl:call-template name="typeIdl2Glue">
<xsl:with-param name="type" select="$returnidltype" />
<xsl:with-param name="safearray" select="$returnidlsafearray" />
<xsl:text>void</xsl:text>
<xsl:variable name="retValValue">
<xsl:when test="(param[@dir='out']) and ($G_vboxGlueStyle='jaxws')">
<xsl:value-of select="'retVal'"/>
<xsl:apply-templates select="desc" mode="method"/>
<xsl:value-of select="concat(' public ', $returngluetype, ' ', $methodname, '(')" />
<xsl:variable name="paramsinout" select="param[@dir='in' or @dir='out']" />
<xsl:for-each select="exsl:node-set($paramsinout)">
<xsl:variable name="paramgluetype">
<xsl:call-template name="typeIdl2Glue">
<xsl:with-param name="type" select="@type" />
<xsl:with-param name="safearray" select="@safearray" />
<xsl:when test="@dir='out'">
<xsl:value-of select="concat('Holder<', $paramgluetype, '> ', @name)" />
<xsl:value-of select="concat($paramgluetype, ' ', @name)" />
<xsl:if test="not(position()=last())">
<xsl:value-of select="', '" />
<xsl:value-of select="') { '"/>
<xsl:call-template name="startExcWrapper"/>
<!-- declare temp out params -->
<xsl:for-each select="param[@dir='out']">
<xsl:variable name="backouttype">
<xsl:call-template name="typeIdl2Back">
<xsl:with-param name="type" select="@type" />
<xsl:with-param name="safearray" select="@safearray" />
<xsl:when test="$G_vboxGlueStyle='xpcom'">
<xsl:when test="$G_vboxGlueStyle='mscom'">
<xsl:value-of select="concat(' Variant tmp_', @name, ' = new Variant(); ')"/>
<xsl:when test="$G_vboxGlueStyle='jaxws'">
<xsl:call-template name="fatalError">
<xsl:with-param name="msg" select="'Handle out param (genMethod)'" />
<!-- declare return param, if any -->
<xsl:if test="$hasReturnParms">
<xsl:variable name="backrettype">
<xsl:call-template name="typeIdl2Back">
<xsl:with-param name="type" select="$returnidltype" />
<xsl:with-param name="safearray" select="$returnidlsafearray" />
<xsl:when test="(param[@dir='out']) and ($G_vboxGlueStyle='jaxws')">
<xsl:value-of select="concat(' ', $backrettype, ' retVal; ')"/>
<xsl:call-template name="genBackMethodCall">
<xsl:with-param name="ifname" select="$ifname" />
<xsl:with-param name="methodname" select="$methodname" />
<xsl:with-param name="retval" select="'retVal'" />
<!-- return out params -->
<xsl:for-each select="param[@dir='out']">
<xsl:variable name="varval">
<xsl:when test="$G_vboxGlueStyle='xpcom'">
<xsl:value-of select="concat('tmp_',@name,'[0]')" />
<xsl:when test="$G_vboxGlueStyle='mscom'">
<xsl:value-of select="concat('tmp_',@name)" />
<xsl:when test="$G_vboxGlueStyle='jaxws'">
<xsl:value-of select="concat('tmp_',@name,'.value')" />
<xsl:call-template name="fatalError">
<xsl:with-param name="msg" select="'Style unknown (genMethod, outparam)'" />
<xsl:variable name="wrapped">
<xsl:call-template name="cookOutParam">
<xsl:with-param name="value" select="$varval" />
<xsl:with-param name="idltype" select="@type" />
<xsl:with-param name="safearray" select="@safearray" />
<xsl:value-of select="concat(' ', @name, '.value = ',$wrapped,'; ')"/>
<xsl:if test="$hasReturnParms">
<!-- actual 'return' statement -->
<xsl:variable name="wrapped">
<xsl:call-template name="cookOutParam">
<xsl:with-param name="value" select="$retValValue" />
<xsl:with-param name="idltype" select="$returnidltype" />
<xsl:with-param name="safearray" select="$returnidlsafearray" />
<xsl:value-of select="concat(' return ', $wrapped, '; ')" />
<xsl:call-template name="endExcWrapper"/>
<xsl:value-of select="' } '"/>
<!-- Callback interface method -->
<xsl:template name="genCbMethodDecl">
<xsl:param name="ifname"/>
<xsl:param name="methodname"/>
<xsl:when test="(param[@mod='ptr'])" >
<xsl:value-of select="concat('Skipping method ', $methodname, ' for it has parameters with suppressed types')" />
<xsl:variable name="returnidltype" select="param[@dir='return']/@type" />
<xsl:variable name="returnidlsafearray" select="param[@dir='return']/@safearray" />
<xsl:variable name="returngluetype">
<xsl:when test="$returnidltype">
<xsl:call-template name="typeIdl2Glue">
<xsl:with-param name="type" select="$returnidltype" />
<xsl:with-param name="safearray" select="$returnidlsafearray" />
<xsl:text>void</xsl:text>
<xsl:value-of select="concat(' public ', $returngluetype, ' ', $methodname, '(')" />
<xsl:variable name="paramsinout" select="param[@dir='in' or @dir='out']" />
<xsl:for-each select="exsl:node-set($paramsinout)">
<xsl:variable name="paramgluetype">
<xsl:call-template name="typeIdl2Glue">
<xsl:with-param name="type" select="@type" />
<xsl:with-param name="safearray" select="@safearray" />
<xsl:when test="@dir='out'">
<xsl:value-of select="concat('Holder<', $paramgluetype, '> ', @name)" />
<xsl:value-of select="concat($paramgluetype, ' ', @name)" />
<xsl:if test="not(position()=last())">
<xsl:value-of select="'); '"/>
<!-- queryInterface wrapper -->
<xsl:template name="genQI">
<xsl:param name="ifname"/>
<xsl:param name="uuid" />
<xsl:value-of select="concat(' public static ', $ifname, ' queryInterface(IUnknown obj) { ')" />
<xsl:when test="$G_vboxGlueStyle='xpcom'">
<xsl:variable name="backtype">
<xsl:call-template name="typeIdl2Back">
<xsl:with-param name="type" select="$ifname" />
<xsl:value-of select=" ' nsISupports nsobj = obj != null ? (nsISupports)
obj.getWrapped() : null; '"/>
<xsl:value-of select=" ' if (nsobj == null) return null; '"/>
<xsl:value-of select="concat(' ',$backtype, ' qiobj =
Helper.queryInterface(nsobj, "{',$uuid,'}", ',$backtype,'.class); ')" />
<xsl:value-of select="concat(' return qiobj == null ? null : new ', $ifname, '(qiobj); ')" />
<xsl:when test="$G_vboxGlueStyle='mscom'">
<xsl:when test="$G_vboxGlueStyle='jaxws'">
<!-- bad, need to check that we really can be casted to this type -->
<xsl:call-template name="fatalError">
<xsl:with-param name="msg" select="'Style unknown (genQI)'" />
<xsl:value-of select=" ' } '" />
<xsl:template name="genCbMethodImpl">
<xsl:param name="ifname"/>
<xsl:param name="methodname"/>
<xsl:when test="(param[@mod='ptr'])" >
<xsl:value-of select="concat('Skipping method ', $methodname, ' for it has parameters with suppressed types')" />
<xsl:variable name="hasReturnParms" select="param[@dir='return']" />
<xsl:variable name="hasOutParms" select="param[@dir='out']" />
<xsl:variable name="returnidltype" select="param[@dir='return']/@type" />
<xsl:variable name="returnidlsafearray" select="param[@dir='return']/@safearray" />
<xsl:variable name="returnbacktype">
<xsl:when test="$returnidltype">
<xsl:call-template name="typeIdl2Back">
<xsl:with-param name="type" select="$returnidltype" />
<xsl:with-param name="safearray" select="$returnidlsafearray" />
<xsl:text>void</xsl:text>
<xsl:variable name="paramsinout" select="param[@dir='in' or @dir='out']" />
<xsl:when test="$G_vboxGlueStyle='xpcom'">
<xsl:value-of select="concat(' public ', $returnbacktype, ' ', $methodname, '(')" />
<xsl:for-each select="exsl:node-set($paramsinout)">
<xsl:variable name="parambacktype">
<xsl:call-template name="typeIdl2Back">
<xsl:with-param name="type" select="@type" />
<xsl:with-param name="safearray" select="@safearray" />
<xsl:when test="@dir='out'">
<xsl:value-of select="concat($parambacktype, '[] ', @name)" />
<xsl:if test="@safearray">
<xsl:value-of select="concat('long len_',@name,', ')" />
<xsl:value-of select="concat($parambacktype, ' ', @name)" />
<xsl:if test="not(position()=last())">
<xsl:value-of select="') { '"/>
<xsl:when test="$G_vboxGlueStyle='mscom'">
<xsl:variable name="capsname">
<xsl:call-template name="capitalize">
<xsl:with-param name="str" select="$methodname" />
<xsl:value-of select="concat(' public ', $returnbacktype, ' ', $capsname, '(')" />
<xsl:value-of select="'Variant _args[]'"/>
<xsl:value-of select="') { '"/>
<xsl:for-each select="exsl:node-set($paramsinout)">
<xsl:variable name="parambacktype">
<xsl:call-template name="typeIdl2Back">
<xsl:with-param name="type" select="@type" />
<xsl:with-param name="safearray" select="@safearray" />
<xsl:value-of select="concat(' ', $parambacktype, ' ', @name, '=_args[', count(preceding-sibling::param),']; ')" />
<xsl:call-template name="fatalError">
<xsl:with-param name="msg" select="'Style unknown (genSetterCall)'" />
<!-- declare temp out params -->
<xsl:for-each select="param[@dir='out']">
<xsl:variable name="glueouttype">
<xsl:call-template name="typeIdl2Glue">
<xsl:with-param name="type" select="@type" />
<xsl:with-param name="safearray" select="@safearray" />
<xsl:value-of select="concat(' Holder<', $glueouttype, '> tmp_', @name, ' = new Holder<', $glueouttype, '>(); ')"/>
<!-- declare return param, if any -->
<xsl:if test="$hasReturnParms">
<xsl:variable name="gluerettype">
<xsl:call-template name="typeIdl2Glue">
<xsl:with-param name="type" select="$returnidltype" />
<xsl:with-param name="safearray" select="$returnidlsafearray" />
<xsl:value-of select="concat(' ', $gluerettype, ' retVal = ')"/>
<xsl:value-of select="concat(' sink.', $methodname,'(')"/>
<xsl:for-each select="param[not(@dir='return')]">
<xsl:when test="@dir='out'">
<xsl:value-of select="concat('tmp_', @name)" />
<xsl:when test="@dir='in'">
<xsl:variable name="wrapped">
<xsl:call-template name="cookOutParam">
<xsl:with-param name="value" select="@name" />
<xsl:with-param name="idltype" select="@type" />
<xsl:with-param name="safearray" select="@safearray" />
<xsl:value-of select="$wrapped"/>
<xsl:call-template name="fatalError">
<xsl:with-param name="msg" select="concat('Unsupported param dir: ', @dir, '".')" />
<xsl:if test="not(position()=last())">
<xsl:value-of select="', '"/>
<xsl:value-of select="'); '"/>
<!-- return out params -->
<xsl:for-each select="param[@dir='out']">
<xsl:variable name="unwrapped">
<xsl:call-template name="cookInParam">
<xsl:with-param name="value" select="concat('tmp_',@name,'.value')" />
<xsl:with-param name="idltype" select="@type" />
<xsl:with-param name="safearray" select="@safearray" />
<xsl:when test="$G_vboxGlueStyle='xpcom'">
<xsl:value-of select="concat(' ', @name, '[0] = ',$unwrapped,'; ')"/>
<xsl:when test="$G_vboxGlueStyle='mscom'">
<xsl:value-of select="concat(' _args[',count(preceding-sibling::param),'] = ',$unwrapped,'; ')"/>
<xsl:if test="$hasReturnParms">
<!-- actual 'return' statement -->
<xsl:variable name="unwrapped">
<xsl:call-template name="cookInParam">
<xsl:with-param name="value" select="'retVal'" />
<xsl:with-param name="idltype" select="$returnidltype" />
<xsl:with-param name="safearray" select="$returnidlsafearray" />
<xsl:value-of select="concat(' return ', $unwrapped, '; ')" />
<xsl:value-of select="' } '"/>
<!-- Interface method -->
<xsl:template name="genIfaceWrapper">
<xsl:param name="ifname"/>
<xsl:variable name="wrappedType">
<xsl:call-template name="wrappedName">
<xsl:with-param name="ifname" select="$ifname" />
<xsl:when test="($G_vboxGlueStyle='jaxws')">
<xsl:value-of select="concat(' public ', $ifname, '(String wrapped, VboxPortType port) { ')" />
<xsl:value-of select=" ' super(wrapped, port); '"/>
<xsl:value-of select=" ' } '"/>
<xsl:when test="($G_vboxGlueStyle='xpcom') or ($G_vboxGlueStyle='mscom')">
<xsl:value-of select="concat(' public ', $ifname, '(', $wrappedType,' wrapped) { ')" />
<xsl:value-of select=" ' super(wrapped); '"/>
<xsl:value-of select=" ' } '"/>
<!-- Typed wrapped object accessor -->
<xsl:value-of select="concat(' public ', $wrappedType, ' getTypedWrapped() { ')" />
<xsl:value-of select="concat(' return (', $wrappedType, ') getWrapped(); ')" />
<xsl:value-of select=" ' } '" />
<xsl:call-template name="fatalError">
<xsl:with-param name="msg" select="'Style unknown (root, ctr)'" />
<xsl:for-each select="attribute[not(@mod='ptr')]">
<xsl:variable name="attrname"><xsl:value-of select="@name" /></xsl:variable>
<xsl:variable name="attrtype"><xsl:value-of select="@type" /></xsl:variable>
<xsl:variable name="attrreadonly"><xsl:value-of select="@readonly" /></xsl:variable>
<xsl:variable name="attrsafearray"><xsl:value-of select="@safearray" /></xsl:variable>
<xsl:when test="($G_vboxGlueStyle='jaxws') and ($attrtype=($G_setSuppressedInterfaces/@name))">
<xsl:value-of select="concat(' // skip attribute ',$attrname, ' of suppressed type ', $attrtype, ' ')" />
<!-- emit getter method -->
<xsl:apply-templates select="desc" mode="attribute_get"/>
<xsl:variable name="gettername">
<xsl:call-template name="makeGetterName">
<xsl:with-param name="attrname" select="$attrname" />
<xsl:variable name="gluetype">
<xsl:call-template name="typeIdl2Glue">
<xsl:with-param name="type" select="$attrtype" />
<xsl:with-param name="safearray" select="@safearray" />
<xsl:variable name="backtype">
<xsl:call-template name="typeIdl2Back">
<xsl:with-param name="type" select="$attrtype" />
<xsl:with-param name="safearray" select="@safearray" />
<xsl:variable name="wrapped">
<xsl:call-template name="cookOutParam">
<xsl:with-param name="value" select="'retVal'" />
<xsl:with-param name="idltype" select="$attrtype" />
<xsl:with-param name="safearray" select="@safearray" />
<xsl:value-of select="concat(' public ', $gluetype, ' ', $gettername, '() { ')" />
<xsl:call-template name="startExcWrapper"/>
<!-- Actual getter implementation -->
<xsl:call-template name="genGetterCall">
<xsl:with-param name="ifname" select="$ifname" />
<xsl:with-param name="gettername" select="$gettername" />
<xsl:with-param name="backtype" select="$backtype" />
<xsl:with-param name="retval" select="'retVal'" />
<xsl:value-of select="concat(' return ', $wrapped, '; ')" />
<xsl:call-template name="endExcWrapper"/>
<xsl:value-of select= "' } '" />
<xsl:if test="not(@readonly='yes')">
<!-- emit setter method -->
<xsl:apply-templates select="desc" mode="attribute_set"/>
<xsl:variable name="settername"><xsl:call-template name="makeSetterName"><xsl:with-param name="attrname" select="$attrname" /></xsl:call-template></xsl:variable>
<xsl:variable name="unwrapped">
<xsl:call-template name="cookInParam">
<xsl:with-param name="ifname" select="$ifname" />
<xsl:with-param name="value" select="'value'" />
<xsl:with-param name="idltype" select="$attrtype" />
<xsl:with-param name="safearray" select="@safearray" />
<xsl:value-of select="concat(' public void ', $settername, '(', $gluetype, ' value) { ')" />
<xsl:call-template name="startExcWrapper"/>
<!-- Actual setter implementation -->
<xsl:call-template name="genSetterCall">
<xsl:with-param name="ifname" select="$ifname" />
<xsl:with-param name="settername" select="$settername" />
<xsl:with-param name="value" select="$unwrapped" />
<xsl:call-template name="endExcWrapper"/>
<xsl:value-of select= "' } '" />
<!-- emit queryInterface() *to* this class -->
<xsl:call-template name="genQI">
<xsl:with-param name="ifname" select="$ifname" />
<xsl:with-param name="uuid" select="@uuid" />
<xsl:for-each select="method">
<xsl:call-template name="genMethod">
<xsl:with-param name="ifname" select="$ifname" />
<xsl:with-param name="methodname" select="@name" />
<xsl:template name="genIface">
<xsl:param name="ifname" />
<xsl:param name="filename" />
<xsl:variable name="wsmap" select="@wsmap" />
<xsl:call-template name="startFile">
<xsl:with-param name="file" select="$filename" />
<xsl:with-param name="package" select="$G_virtualBoxPackage" />
<xsl:apply-templates select="desc" mode="interface"/>
<xsl:when test="($wsmap='struct') and ($G_vboxGlueStyle='jaxws')">
<xsl:value-of select="concat('public class ', $ifname, ' { ')" />
<xsl:call-template name="genStructWrapperJaxws">
<xsl:with-param name="ifname" select="$ifname" />
<xsl:variable name="extends" select="//interface[@name=$ifname]/@extends" />
<xsl:when test="($extends = '$unknown') or ($extends = '$dispatched') or ($extends = '$errorinfo')">
<xsl:value-of select="concat('public class ', $ifname, ' extends IUnknown { ')" />
<xsl:when test="//interface[@name=$extends]">
<xsl:value-of select="concat('public class ', $ifname, ' extends ', $extends, ' { ')" />
<xsl:call-template name="fatalError">
<xsl:with-param name="msg" select="concat('Interface generation: interface "', $ifname, '" has invalid "extends" value ', $extends, '.')" />
<xsl:call-template name="genIfaceWrapper">
<xsl:with-param name="ifname" select="$ifname" />
<xsl:value-of select="'} '" />
<xsl:call-template name="endFile">
<xsl:with-param name="file" select="$filename" />
<xsl:template name="genCb">
<xsl:param name="ifname" />
<xsl:param name="filename" />
<xsl:param name="filenameimpl" />
<xsl:call-template name="startFile">
<xsl:with-param name="file" select="$filename" />
<xsl:with-param name="package" select="$G_virtualBoxPackage" />
<xsl:value-of select="concat('public interface ', $ifname, ' { ')" />
<!-- emit methods declarations-->
<xsl:for-each select="method">
<xsl:call-template name="genCbMethodDecl">
<xsl:with-param name="ifname" select="$ifname" />
<xsl:with-param name="methodname" select="@name" />
<xsl:value-of select="'} '" />
<xsl:call-template name="endFile">
<xsl:with-param name="file" select="$filename" />
<xsl:call-template name="startFile">
<xsl:with-param name="file" select="$filenameimpl" />
<xsl:with-param name="package" select="$G_virtualBoxPackage" />
<xsl:variable name="backtype">
<xsl:call-template name="typeIdl2Back">
<xsl:with-param name="type" select="$ifname" />
<!-- emit glue methods body -->
<xsl:when test="$G_vboxGlueStyle='xpcom'">
<xsl:value-of select="concat('class ', $ifname, 'Impl extends nsISupportsBase implements ', $backtype, ' { ')" />
<xsl:when test="$G_vboxGlueStyle='mscom'">
<xsl:value-of select="concat('public class ', $ifname, 'Impl { ')" />
<xsl:value-of select="concat(' ', $ifname, ' sink; ')" />
<xsl:value-of select="concat(' ', $ifname, 'Impl(', $ifname,' sink) { ')" />
<xsl:value-of select="'
this.sink = sink; '" />
<xsl:value-of select="' } '" />
<!-- emit methods implementations -->
<xsl:for-each select="method">
<xsl:call-template name="genCbMethodImpl">
<xsl:with-param name="ifname" select="$ifname" />
<xsl:with-param name="methodname" select="@name" />
<xsl:value-of select="'} '" />
<xsl:call-template name="endFile">
<xsl:with-param name="file" select="$filenameimpl" />
<xsl:template name="emitHandwritten">
<xsl:call-template name="startFile">
<xsl:with-param name="package" select="$G_virtualBoxPackage" />
<xsl:call-template name="endFile">
<xsl:call-template name="startFile">
<xsl:with-param name="package" select="$G_virtualBoxPackage" />
public class VBoxException extends RuntimeException
private Throwable wrapped;
public VBoxException(Throwable wrapped, String msg)
public Throwable getWrapped()
public String getMessage()
<xsl:call-template name="endFile">
<xsl:template name="emitHandwrittenXpcom">
<xsl:call-template name="startFile">
<xsl:with-param name="package" select="$G_virtualBoxPackageCom" />
public IUnknown(Object obj)
public Object getWrapped()
public void setWrapped(Object obj)
<xsl:call-template name="endFile">
<xsl:call-template name="startFile">
<xsl:with-param name="package" select="$G_virtualBoxPackageCom" />
public static List<Short> wrap(byte[] vals) {
public static List<Integer> wrap(int[] vals) {
List<Integer> ret = new ArrayList<Integer>(
vals.length);
public static List<Long> wrap(long[] vals) {
public static List<String> wrap(String[] vals) {
public static <T> List<T> wrap(Class<T> wrapperClass, T[] thisPtrs) {
for (T thisPtr : thisPtrs) {
public static <T> List<T> wrapEnum(Class<T> wrapperClass, long values[]) {
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
} catch (InstantiationException e) {
throw new AssertionError(e);
} catch (IllegalAccessException e) {
throw new AssertionError(e);
} catch (InvocationTargetException e) {
throw new AssertionError(e);
public static short[] unwrap(List<Short> vals) {
public static int[] unwrap(List<Integer> vals) {
public static long[] unwrap(List<Long> vals) {
public static boolean[] unwrap(List<Boolean> vals) {
public static String[] unwrap(List<String> vals) {
public static <T extends Enum <T>> long[] unwrapEnum(Class<T> enumClass, List<T> values) {
if (values == null) return null;
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
} catch(SecurityException e) {
throw new AssertionError(e);
} catch (IllegalAccessException e) {
throw new AssertionError(e);
} catch (IllegalArgumentException e) {
throw new AssertionError(e);
} catch (InvocationTargetException e) {
throw new AssertionError(e);
public static <T1, T2> List<T1> wrap2(Class<T1> wrapperClass1, Class<T2> wrapperClass2, T2[] thisPtrs) {
for (T2 thisPtr : thisPtrs) {
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
} catch (InstantiationException e) {
throw new AssertionError(e);
} catch (IllegalAccessException e) {
throw new AssertionError(e);
} catch (InvocationTargetException e) {
throw new AssertionError(e);
@SuppressWarnings( "unchecked")
public static <T> T[] unwrap(Class<T> wrapperClass, List<T> thisPtrs) {
@SuppressWarnings( "unchecked" )
public static <T> T queryInterface(Object obj, String uuid, Class<T> iface)
return (T)queryInterface(obj, uuid);
public static Object queryInterface(Object obj, String uuid)
/* Kind of ugly, but does the job of casting */
@SuppressWarnings("unchecked")
public static <T1 extends IUnknown,T2> T2[] unwrap2(Class<T1> wrapperClass1, Class<T2> wrapperClass2, List<T1> thisPtrs) {
if (thisPtrs==null) return null;
for (T1 obj : thisPtrs) {
<xsl:call-template name="endFile">
<xsl:call-template name="startFile">
<xsl:with-param name="package" select="$G_virtualBoxPackage" />
public class VirtualBoxManager
private IVirtualBox vbox;
private nsIComponentManager componentManager;
private VirtualBoxManager(Mozilla mozilla)
public void connect(String url, String username, String passwd)
throw new RuntimeException("Connect doesn't make sense for local bindings");
throw new RuntimeException("Disconnect doesn't make sense for local bindings");
public static void initPerThread()
public static void deinitPerThread()
public IVirtualBox getVBox()
public ISession getSessionObject()
public ISession openMachineSession(IMachine m) throws Exception
ISession s = getSessionObject();
public void closeMachineSession(ISession s)
private static boolean hasInstance = false;
private static boolean isMozillaInited = false;
public static synchronized VirtualBoxManager createInstance(String home)
throw new VBoxException(null, "only one instance at the time allowed");
if (home == null || "".equals(home))
throw new RuntimeException("
vbox.home Java property must be defined to use XPCOM bridge");
File grePath = new File(home);
return new VirtualBoxManager(mozilla);
public IEventListener createListener(Object sink)
return new IEventListener(new EventListenerImpl(sink));
// cleanup, we don't do that, as XPCOM bridge doesn't cleanly
// shuts down, so we prefer to avoid native shutdown
public boolean progressBar(IProgress p, int wait)
public boolean startVm(String name, String type, int timeout)
ISession session = getSessionObject();
public void waitForEvents(long tmo)
<xsl:call-template name="endFile">
<xsl:call-template name="startFile">
<xsl:with-param name="package" select="$G_virtualBoxPackage" />
EventListenerImpl(Object obj)
if (obj != null && handleEvent != null)
<xsl:call-template name="endFile">
<xsl:call-template name="startFile">
<xsl:with-param name="package" select="$G_virtualBoxPackage" />
]]></xsl:text><xsl:call-template name="endFile">
<xsl:template name="emitHandwrittenMscom">
<xsl:call-template name="startFile">
<xsl:with-param name="package" select="$G_virtualBoxPackageCom" />
public IUnknown(Object obj)
public Object getWrapped()
public void setWrapped(Object obj)
<xsl:call-template name="endFile">
<xsl:call-template name="startFile">
<xsl:with-param name="package" select="$G_virtualBoxPackageCom" />
public static List<Short> wrap(short[] vals) {
if (vals==null) return null;
public static List<Integer> wrap(int[] vals) {
if (vals == null) return null;
List<Integer> ret = new ArrayList<Integer>(
vals.length);
public static List<Long> wrap(long[] vals) {
if (vals==null) return null;
public static List<String> wrap(String[] vals) {
if (vals==null) return null;
public static <T> T wrapDispatch(Class<T> wrapperClass, Dispatch d)
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
} catch (InstantiationException e) {
throw new AssertionError(e);
} catch (IllegalAccessException e) {
throw new AssertionError(e);
} catch (InvocationTargetException e) {
throw new AssertionError(e);
@SuppressWarnings("unchecked")
public static <T> Object wrapVariant(Class<T> wrapperClass, Variant v)
throw new RuntimeException("unhandled variant type "+vt);
public static byte[] wrapBytes(SafeArray sa) {
if (sa==null) return null;
byte[] ret = new byte[saLen];
// come upo with more effective approach!!!
@SuppressWarnings("unchecked")
public static <T> List<T> wrap(Class<T> wrapperClass, SafeArray sa) {
if (sa==null) return null;
List<T> ret = new ArrayList<T>(saLen);
ret.add((T)wrapVariant(wrapperClass, v));
public static <T> List<T> wrapEnum(Class<T> wrapperClass, SafeArray sa) {
if (sa==null) return null;
List<T> ret = new ArrayList<T>(saLen);
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
} catch (InstantiationException e) {
throw new AssertionError(e);
} catch (IllegalAccessException e) {
throw new AssertionError(e);
} catch (InvocationTargetException e) {
throw new AssertionError(e);
public static SafeArray unwrapInt(List<Integer> vals) {
if (vals==null) return null;
public static SafeArray unwrapLong(List<Long> vals) {
if (vals==null) return null;
public static SafeArray unwrapBool(List<Boolean> vals) {
if (vals==null) return null;
public static SafeArray unwrapBytes(byte[] vals) {
if (vals==null) return null;
public static <T extends Enum <T>> SafeArray unwrapEnum(Class<T> enumClass, List<T> values) {
if (values == null) return null;
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
} catch(SecurityException e) {
throw new AssertionError(e);
} catch (IllegalAccessException e) {
throw new AssertionError(e);
} catch (IllegalArgumentException e) {
throw new AssertionError(e);
} catch (InvocationTargetException e) {
throw new AssertionError(e);
public static SafeArray unwrapString(List<String> vals) {
public static <T1, T2> List<T1> wrap2(Class<T1> wrapperClass1, Class<T2> wrapperClass2, T2[] thisPtrs) {
if (thisPtrs==null) return null;
for (T2 thisPtr : thisPtrs) {
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
} catch (InstantiationException e) {
throw new AssertionError(e);
} catch (IllegalAccessException e) {
throw new AssertionError(e);
} catch (InvocationTargetException e) {
throw new AssertionError(e);
@SuppressWarnings("unchecked")
public static <T> T[] unwrap(Class<T> wrapperClass, List<T> thisPtrs) {
if (thisPtrs==null) return null;
@SuppressWarnings("unchecked")
public static <T1 extends IUnknown,T2> T2[] unwrap2(Class<T1> wrapperClass1, Class<T2> wrapperClass2, List<T1> thisPtrs) {
if (thisPtrs==null) return null;
for (T1 obj : thisPtrs) {
/* We have very long invoke lists sometimes */
public static Variant invoke(Dispatch d, String method, Object ... args)
<xsl:call-template name="endFile">
<xsl:call-template name="startFile">
<xsl:with-param name="package" select="$G_virtualBoxPackage" />
public class VirtualBoxManager
private IVirtualBox vbox;
private VirtualBoxManager()
public static void initPerThread()
public static void deinitPerThread()
public void connect(String url, String username, String passwd)
throw new RuntimeException("Connect doesn't make sense for local bindings");
throw new RuntimeException("Disconnect doesn't make sense for local bindings");
public IVirtualBox getVBox()
public ISession getSessionObject()
public ISession openMachineSession(IMachine m)
ISession s = getSessionObject();
public void closeMachineSession(ISession s)
private static boolean hasInstance = false;
public static synchronized VirtualBoxManager createInstance(String home)
throw new VBoxException(null, "only one instance at the time allowed");
return new VirtualBoxManager();
public boolean progressBar(IProgress p, int wait)
public boolean startVm(String name, String type, int timeout)
ISession session = getSessionObject();
public void waitForEvents(long tmo)
} catch (InterruptedException ie) {
<xsl:call-template name="endFile">
<xsl:template name="emitHandwrittenJaxws">
<xsl:call-template name="startFile">
<xsl:with-param name="package" select="$G_virtualBoxPackageCom" />
protected final VboxPortType port;
public IUnknown(String obj, VboxPortType port)
public final String getWrapped()
public final VboxPortType getRemoteWSPort()
public synchronized void releaseRemote() throws WebServiceException
} catch (InvalidObjectFaultMsg e) {
throw new WebServiceException(e);
} catch (RuntimeFaultMsg e) {
throw new WebServiceException(e);
<xsl:call-template name="endFile">
<xsl:call-template name="startFile">
<xsl:with-param name="package" select="$G_virtualBoxPackageCom" />
public static <T> List<T> wrap(Class<T> wrapperClass, VboxPortType pt, List<String> thisPtrs) {
if(thisPtrs==null) return null;
for (String thisPtr : thisPtrs) {
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
} catch (InstantiationException e) {
throw new AssertionError(e);
} catch (IllegalAccessException e) {
throw new AssertionError(e);
} catch (InvocationTargetException e) {
throw new AssertionError(e);
public static <T1, T2> List<T1> wrap2(Class<T1> wrapperClass1, Class<T2> wrapperClass2, VboxPortType pt, List<T2> thisPtrs) {
if(thisPtrs==null) return null;
for (T2 thisPtr : thisPtrs) {
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
} catch (InstantiationException e) {
throw new AssertionError(e);
} catch (IllegalAccessException e) {
throw new AssertionError(e);
} catch (InvocationTargetException e) {
throw new AssertionError(e);
public static <T extends IUnknown> List<String> unwrap(List<T> thisPtrs) {
if (thisPtrs==null) return null;
@SuppressWarnings("unchecked" )
public static <T1 extends Enum <T1>, T2 extends Enum <T2>> List<T2> convertEnums(Class<T1> fromClass,
// static method is called with null this
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
} catch (IllegalAccessException e) {
throw new AssertionError(e);
} catch (InvocationTargetException e) {
throw new AssertionError(e);
private static final char[] valToChar = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray();
private static final int[] charToVal = new int[256];
/* Initialize recoding alphabet. */
charToVal[valToChar[i]] = i;
public static String encodeBase64(byte[] data)
char[] result = new char[resultLen];
int dataIndex = 0, stringIndex = 0;
for (int i = 0; i < fullTriplets; i++)
int ch1 = data[dataIndex++] & 0xff;
result[stringIndex++] = valToChar[ch1 >> 2];
int ch2 = data[dataIndex++] & 0xff;
result[stringIndex++] = valToChar[((ch1 << 4) & 0x3f) | (ch2 >> 4)];
int ch3 = data[dataIndex++] & 0xff;
result[stringIndex++] = valToChar[((ch2 << 2) & 0x3f) | (ch3 >> 6)];
result[stringIndex++] = valToChar[ch3 & 0x3f];
int ch1 = data[dataIndex++] & 0xff;
result[stringIndex++] = valToChar[ch1 >> 2];
result[stringIndex++] = valToChar[(ch1 << 4) & 0x3f];
result[stringIndex++] = '=';
result[stringIndex++] = '=';
int ch1 = data[dataIndex++] & 0xff;
result[stringIndex++] = valToChar[ch1 >> 2];
int ch2 = data[dataIndex++] & 0xff;
result[stringIndex++] = valToChar[((ch1 << 4) & 0x3f) | (ch2 >> 4)];
result[stringIndex++] = valToChar[(ch2 << 2) & 0x3f];
result[stringIndex++] = '=';
throw new RuntimeException("bug!");
return new String(result);
private static int skipInvalid(String str, int stringIndex)
public static byte[] decodeBase64(String str)
int validChars = 0, padChars = 0;
if ((validChars * 3 % 4) != 0)
throw new RuntimeException("invalid encoded string "+str);
int resultLength = validChars * 3 / 4 - padChars;
byte[] result = new byte[resultLength];
int dataIndex = 0, stringIndex = 0;
int quadraplets = validChars / 4;
for (int i=0; i<quadraplets; i++)
stringIndex = skipInvalid(str, stringIndex);
stringIndex = skipInvalid(str, stringIndex);
stringIndex = skipInvalid(str, stringIndex);
stringIndex = skipInvalid(str, stringIndex);
result[dataIndex++] = (byte)(((charToVal[ch1] << 2) | charToVal[ch2] >> 4) & 0xff);
/* we check this to ensure that we don't override data with '=' padding. */
result[dataIndex++] = (byte)(((charToVal[ch2] << 4) | charToVal[ch3] >> 2) & 0xff);
result[dataIndex++] = (byte)(((charToVal[ch3] << 6) | charToVal[ch4]) & 0xff);
<xsl:call-template name="endFile">
<xsl:call-template name="startFile">
<xsl:with-param name="package" select="$G_virtualBoxPackage" />
private final static String wsdlFile = <xsl:value-of select="$G_virtualBoxWsdl" />;
private Map<VboxPortType, Integer> known;
private boolean initStarted;
PortPool(boolean usePreinit)
known = new HashMap<VboxPortType, Integer>();
new Thread(new Runnable()
// need to sync on something else but 'this'
} catch (InterruptedException e) {
private synchronized void preinit()
VboxPortType port = getPort();
synchronized VboxPortType getPort()
VboxPortType port = null;
if ((value & 0x10000) == 0)
throw new LinkageError(wsdlFile+" not found, but it should have been in the jar");
svc = new VboxService(wsdl,
// reuse this object 0x10 times
synchronized void releasePort(VboxPortType port)
if (val == null || val == 0)
// decrement TTL, and throw away port if used too much times
v = ttl; // set new TTL and clear busy bit
public class VirtualBoxManager
private static PortPool pool = new PortPool(true);
protected VboxPortType port;
private IVirtualBox vbox;
private VirtualBoxManager()
public static void initPerThread()
public static void deinitPerThread()
public void connect(String url, String username, String passwd)
((BindingProvider)port).getRequestContext().
// we have to throw smth derived from RuntimeException
public void connect(String url, String username, String passwd,
Map<String, Object> requestContext, Map<String, Object> responseContext)
((BindingProvider)port).getRequestContext();
if (requestContext != null)
((BindingProvider)port).getRequestContext().putAll(requestContext);
if (responseContext != null)
((BindingProvider)port).getResponseContext().putAll(responseContext);
((BindingProvider)port).getRequestContext().
// we have to throw smth derived from RuntimeException
} catch (InvalidObjectFaultMsg e) {
} catch (RuntimeFaultMsg e) {
public IVirtualBox getVBox()
public ISession getSessionObject()
throw new RuntimeException("connect first");
return new ISession(handle, port);
} catch (InvalidObjectFaultMsg e) {
} catch (RuntimeFaultMsg e) {
public ISession openMachineSession(IMachine m) throws Exception
ISession s = getSessionObject();
public void closeMachineSession(ISession s)
public static synchronized VirtualBoxManager createInstance(String home)
return new VirtualBoxManager();
public IEventListener createListener(Object sink)
throw new RuntimeException("no active listeners here");
public boolean progressBar(IProgress p, int wait)
public boolean startVm(String name, String type, int timeout)
ISession session = getSessionObject();
public void waitForEvents(long tmo)
<xsl:call-template name="endFile">
<xsl:if test="not($G_vboxApiSuffix)">
<xsl:call-template name="fatalError">
<xsl:with-param name="msg" select="'G_vboxApiSuffix must be given'" />
<!-- Handwritten files -->
<xsl:call-template name="emitHandwritten"/>
<xsl:when test="$G_vboxGlueStyle='xpcom'">
<xsl:call-template name="emitHandwrittenXpcom"/>
<xsl:when test="$G_vboxGlueStyle='mscom'">
<xsl:call-template name="emitHandwrittenMscom"/>
<xsl:when test="$G_vboxGlueStyle='jaxws'">
<xsl:call-template name="emitHandwrittenJaxws"/>
<xsl:call-template name="fatalError">
<xsl:with-param name="msg" select="'Style unknown (root)'" />
<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:for-each select="//interface">
<xsl:variable name="self_target" select="current()/ancestor::if/@target"/>
<xsl:variable name="module" select="current()/ancestor::module/@name"/>
<xsl:when test="$G_vboxGlueStyle='jaxws'">
<xsl:if test="not($module) and not(@wsmap='suppress') and not(@wsmap='global')">
<xsl:call-template name="genIface">
<xsl:with-param name="ifname" select="@name" />
<xsl:with-param name="filename" select="concat(@name, '.java')" />
<!-- We don't need WSDL-specific interfaces here -->
<xsl:if test="not($self_target='wsdl') and not($module)">
<xsl:call-template name="genIface">
<xsl:with-param name="ifname" select="@name" />
<xsl:with-param name="filename" select="concat(@name, '.java')" />