VirtualBox

Changeset 21898 in vbox


Ignore:
Timestamp:
Jul 30, 2009 4:39:25 PM (16 years ago)
Author:
vboxsync
Message:

Java WS glue: better struct treatment, allow using struct fields in natural way

Location:
trunk/src/VBox/Main/webservice
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/webservice/glue-jaxws.xsl

    r21819 r21898  
    113113      </xsl:when>
    114114     <xsl:when test="//interface[@name=$name]/@wsmap='struct' or //interface[@name=$origname]/@wsmap='struct'">
    115        <xsl:value-of select="concat($G_virtualBoxPackage,  concat('.', $name))" />
     115        <xsl:value-of select="concat($G_virtualBoxPackage2,  concat('.', $name))" />
    116116     </xsl:when>
    117117     <xsl:when test="//interface[@name=$name]">
     
    191191    </xsl:when>
    192192    <xsl:when test="$type='$unknown'">String</xsl:when>
     193    <xsl:when test="//interface[@name=$type]/@wsmap='struct'">
     194      <xsl:value-of select="concat($G_virtualBoxPackage, '.', $type)" />
     195    </xsl:when>
    193196    <xsl:when test="//interface[@name=$type]/@wsmap='managed'">String</xsl:when>
    194197    <xsl:otherwise>
     
    210213  <xsl:param name="idltype"/>
    211214  <xsl:param name="safearray"/>
     215  <xsl:variable name="isstruct"
     216                select="//interface[@name=$idltype]/@wsmap='struct'" />
    212217  <xsl:choose>
    213218    <xsl:when test="//collection[@name=$idltype]">
     
    233238    <xsl:when test="//interface[@name=$idltype] or $idltype='$unknown'">
    234239      <xsl:choose>
    235         <xsl:when test="//interface[@name=$idltype]/@wsmap='struct' and $safearray='yes'">
    236           <xsl:value-of select="concat('/* 2 */', $value)" />
    237         </xsl:when>
    238         <xsl:when test="//interface[@name=$idltype]/@wsmap='struct'">
    239           <xsl:value-of select="$value" />
    240         </xsl:when>
    241240        <xsl:when test="$safearray='yes'">
    242241          <xsl:variable name="elemtype">
     
    250249            </xsl:call-template>
    251250          </xsl:variable>
    252           <xsl:value-of select="concat('Helper.wrap(',$elemtype, '.class, port, ', $value,')')"/>
     251          <xsl:choose>
     252            <xsl:when test="$isstruct">
     253              <xsl:value-of select="concat('Helper.wrap2(',$elemtype, '.class, port, ', $value,')')"/>
     254            </xsl:when>
     255            <xsl:otherwise>
     256              <xsl:value-of select="concat('Helper.wrap(',$elemtype, '.class, port, ', $value,')')"/>
     257            </xsl:otherwise>
     258          </xsl:choose>
    253259        </xsl:when>
    254260        <xsl:otherwise>
     
    262268             </xsl:call-template>
    263269           </xsl:variable>
    264            <!-- if the MOR string is empty, that means NULL, so return NULL instead of an object then -->
    265            <xsl:value-of select="concat('(', $value, '.length() > 0) ? new ', $gluetype, '(', $value,', port) : null')" />
     270           <xsl:choose>
     271             <xsl:when test="$isstruct">
     272               <xsl:value-of select="concat('(', $value, ' != null) ? new ', $gluetype, '(', $value,', port) : null')" />
     273             </xsl:when>
     274              <xsl:otherwise>             
     275                <!-- if the MOR string is empty, that means NULL, so return NULL instead of an object then -->
     276                <xsl:value-of select="concat('(', $value, '.length() > 0) ? new ', $gluetype, '(', $value,', port) : null')" />
     277              </xsl:otherwise>
     278           </xsl:choose>
    266279        </xsl:otherwise>
    267280      </xsl:choose>
     
    272285  </xsl:choose>
    273286</xsl:template>
     287
     288<xsl:template name="genStructWrapper">
     289  <xsl:param name="ifname" select="@name" />
     290 
     291  <xsl:value-of select="concat('    private ', $G_virtualBoxPackage,'.',$ifname, ' real;&#10;')"/>
     292  <xsl:value-of select="'    private VboxPortType port;&#10;&#10;'"/>
     293
     294   <xsl:value-of select="concat('    public ', $ifname, '(', $G_virtualBoxPackage,'.',$ifname,' real, VboxPortType port) {&#10;      this.real = real; &#10;      this.port = port;  &#10;    }&#10;')"/>
     295  <xsl:for-each select="attribute">
     296    <xsl:variable name="attrname"><xsl:value-of select="@name" /></xsl:variable>
     297    <xsl:variable name="attrtype"><xsl:value-of select="@type" /></xsl:variable>
     298    <xsl:variable name="attrreadonly"><xsl:value-of select="@readonly" /></xsl:variable>
     299    <xsl:variable name="attrsafearray"><xsl:value-of select="@safearray" /></xsl:variable>   
     300     <xsl:choose>
     301       <xsl:when test="$attrreadonly='yes'">
     302         <xsl:value-of select="concat('&#10;    // read-only attribute ', $ifname, '::', $attrname, ' of type ', $attrtype, '&#10;')" />
     303         
     304       </xsl:when>
     305       <xsl:otherwise>
     306         <xsl:value-of select="concat('&#10;    // read/write attribute ', $ifname, '::', $attrname, ' of type ', $attrtype, '&#10;')" />
     307       </xsl:otherwise>
     308     </xsl:choose>
     309
     310     <!-- emit getter method -->
     311     <xsl:variable name="gettername">
     312       <xsl:choose>
     313         <!-- Stupid, but boolean getters called isFoo(), not getFoo() -->
     314         <xsl:when test="$attrtype = 'boolean'">
     315           <xsl:variable name="capsname">
     316             <xsl:call-template name="capitalize">
     317               <xsl:with-param name="str" select="$attrname" />
     318             </xsl:call-template>
     319           </xsl:variable>
     320           <xsl:value-of select="concat('is', $capsname)" />
     321         </xsl:when>
     322         <xsl:otherwise>
     323           <xsl:call-template name="makeGetterName">
     324             <xsl:with-param name="attrname" select="$attrname" />
     325           </xsl:call-template>
     326         </xsl:otherwise>
     327       </xsl:choose>
     328     </xsl:variable>
     329     <xsl:variable name="gluegettertype">
     330       <xsl:call-template name="typeIdl2Glue">
     331         <xsl:with-param name="ifname" select="$ifname" />
     332         <xsl:with-param name="method" select="$gettername" />
     333         <xsl:with-param name="name" select="$attrname" />
     334         <xsl:with-param name="type" select="$attrtype" />
     335         <xsl:with-param name="safearray" select="@safearray" />
     336       </xsl:call-template>
     337     </xsl:variable>
     338     <xsl:variable name="javagettertype">
     339       <xsl:call-template name="typeIdl2Java">
     340         <xsl:with-param name="ifname" select="$ifname" />
     341         <xsl:with-param name="method" select="$gettername" />
     342         <xsl:with-param name="name" select="$attrname" />
     343         <xsl:with-param name="type" select="$attrtype" />
     344         <xsl:with-param name="safearray" select="@safearray" />
     345       </xsl:call-template>
     346     </xsl:variable>
     347     <xsl:value-of select="concat('    public ', $gluegettertype, ' ', $gettername, '() {&#10;')" />
     348     <xsl:value-of select="concat('            ', $javagettertype, ' retVal = real.', $gettername, '();&#10;')" />
     349     <xsl:variable name="wrapped">
     350       <xsl:call-template name="cookOutParam">
     351         <xsl:with-param name="ifname" select="$ifname" />
     352         <xsl:with-param name="method" select="$gettername" />
     353         <xsl:with-param name="value" select="'retVal'" />
     354         <xsl:with-param name="idltype" select="$attrtype" />
     355         <xsl:with-param name="safearray" select="@safearray" />
     356       </xsl:call-template>
     357     </xsl:variable>
     358     <xsl:value-of select="concat('            return ', $wrapped, ';&#10;')" />
     359     <xsl:text>    }&#10;</xsl:text>
     360
     361  </xsl:for-each>
     362 
     363</xsl:template>
     364
    274365
    275366<xsl:template name="emitArgInMethodImpl">
     
    428519    }
    429520
     521
     522    public static <T, T1> List<T> wrap2(Class<T> wrapperClass, VboxPortType pt, List<T1> thisPtrs) {
     523        try {
     524            if(thisPtrs==null)  return Collections.emptyList();
     525
     526            Constructor<T> c = wrapperClass.getConstructor(String.class, VboxPortType.class);
     527            List<T> ret = new ArrayList<T>(thisPtrs.size());
     528            for (T1 thisPtr : thisPtrs) {
     529                ret.add(c.newInstance(thisPtr,pt));
     530            }
     531            return ret;
     532        } catch (NoSuchMethodException e) {
     533            throw new AssertionError(e);
     534        } catch (InstantiationException e) {
     535            throw new AssertionError(e);
     536        } catch (IllegalAccessException e) {
     537            throw new AssertionError(e);
     538        } catch (InvocationTargetException e) {
     539            throw new AssertionError(e);
     540        }
     541    }
     542
    430543    public static <T extends IUnknown> List<String> unwrap(List<T> thisPtrs) {
    431544        if (thisPtrs==null)  return Collections.emptyList();
     
    770883    <xsl:variable name="wscpp" select="@wscpp" />
    771884
    772     <xsl:if test="not($wsmap='suppress') and not($wsmap='struct') and not ($wsmap='global')">
     885    <xsl:if test="not($wsmap='suppress') and not ($wsmap='global')">
    773886      <xsl:call-template name="startFile">
    774887        <xsl:with-param name="file" select="concat($filename, '.java')" />
     
    782895      <xsl:choose>
    783896        <xsl:when test="$wsmap='struct'">
    784 
    785897          <xsl:value-of select="concat('public class ', $ifname, ' {&#10;&#10;')" />
    786 
     898           <xsl:call-template name="genStructWrapper">
     899             <xsl:with-param name="name" select="$ifname" />
     900           </xsl:call-template>
    787901        </xsl:when>
    788902
    789903        <xsl:otherwise>
    790 
    791904          <xsl:variable name="extends" select="//interface[@name=$ifname]/@extends" />
    792905          <xsl:choose>
  • trunk/src/VBox/Main/webservice/samples/java/jax-ws/clienttest.java

    r19245 r21898  
    3131/* Somewhat ugly way to support versioning */
    3232import com.sun.xml.ws.commons.virtualbox{VBOX_API_SUFFIX}.*;
    33 import org.virtualbox{VBOX_API_SUFFIX}.*;
    3433
    3534import java.util.*;
  • trunk/src/VBox/Main/webservice/samples/java/jax-ws/metrictest.java

    r18694 r21898  
    3030 */
    3131import com.sun.xml.ws.commons.virtualbox{VBOX_API_SUFFIX}.*;
    32 import org.virtualbox{VBOX_API_SUFFIX}.*;
    3332
    3433import java.util.*;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette