home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 February / PCpro_2005_02.ISO / files / opensource / Dia_0.94 / dia-setup-0.94.exe / dia-uml2idl.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2002-06-24  |  5.7 KB  |  183 lines

  1. <?xml version="1.0"?>
  2. <!-- 
  3.      Transform dia UML objects to IDL interfaces
  4.      
  5.      Copyright(c) 2002 Matthieu Sozeau <mattam@netcourrier.com>     
  6.  
  7.      This program is free software; you can redistribute it and/or modify
  8.      it under the terms of the GNU General Public License as published by
  9.      the Free Software Foundation; either version 2 of the License, or
  10.      (at your option) any later version.
  11.      
  12.      This program is distributed in the hope that it will be useful,
  13.      but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.      GNU General Public License for more details.
  16.      
  17.      You should have received a copy of the GNU General Public License
  18.      along with this program; if not, write to the Free Software
  19.      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20.  
  21. -->
  22.  
  23. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  24.   version="1.0">
  25.  
  26.   <xsl:output method="text"/>
  27.  
  28.   <xsl:param name="directory"/>
  29.  
  30.   <xsl:param name="ident">
  31.     <xsl:text>    </xsl:text>
  32.   </xsl:param>
  33.  
  34.   <!-- Interface indentation -->
  35.   <xsl:param name="interident">
  36.     <xsl:text>  </xsl:text>
  37.   </xsl:param>
  38.  
  39.   <xsl:param name="warn">true</xsl:param>
  40.  
  41.   <!-- Default type -->
  42.   <xsl:param name="type" select="'void'"/>
  43.   
  44.   <!-- Default kind of argument passing -->
  45.   <xsl:param name="kind" select="'inout'"/>
  46.  
  47.   <xsl:template match="package">
  48.     <xsl:text>module </xsl:text>
  49.     <xsl:value-of select="name"/>
  50.     <xsl:text> { </xsl:text>
  51.     <xsl:apply-templates/>
  52.     <xsl:text> }; </xsl:text>
  53.   </xsl:template>
  54.  
  55.   
  56.   <xsl:template match="class">
  57.     <xsl:document href="{$directory}{@name}.idl" method="text">
  58.       <xsl:if test="comment">
  59.     <xsl:text>/*     </xsl:text>
  60.     <xsl:value-of select="comment"/>
  61.     <xsl:text>  */ </xsl:text>
  62.       </xsl:if>
  63.       <xsl:text> </xsl:text>    
  64.       <xsl:value-of select="$interident"/>
  65.       <xsl:text>interface </xsl:text>
  66.       <xsl:value-of select="@name"/>
  67.       <xsl:if test="not(@stereotype='')">
  68.       <xsl:text> : </xsl:text>
  69.     <xsl:value-of select="@stereotype"/>      
  70.       </xsl:if>
  71.       <xsl:text> { </xsl:text>
  72.       <xsl:apply-templates select="attributes"/>
  73.       <xsl:text> </xsl:text>
  74.       <xsl:apply-templates select="operations"/>
  75.       <xsl:text> </xsl:text>
  76.       <xsl:value-of select="$interident"/>
  77.       <xsl:text>}; </xsl:text>
  78.     </xsl:document>
  79.   </xsl:template>
  80.   
  81.   <xsl:template match="operations|attributes">
  82.     <xsl:if test="*[@visibility='private']">
  83.       <xsl:apply-templates select="*[@visibility='private']"/>
  84.     </xsl:if>
  85.     <xsl:if test="*[@visibility='protected']">
  86.       <xsl:apply-templates select="*[@visibility='protected']"/>
  87.     </xsl:if>
  88.     <xsl:if test="*[@visibility='public']">
  89.       <xsl:apply-templates select="*[@visibility='public']"/>
  90.     </xsl:if>
  91.     <xsl:if test="*[not(@visibility)]">
  92.       <xsl:apply-templates select="*[not(@visibility)]"/>
  93.     </xsl:if>
  94.   </xsl:template>
  95.  
  96.  
  97.   <xsl:template match="attribute">
  98.     <xsl:if test="comment!=''">
  99.       <xsl:text> </xsl:text>
  100.       <xsl:value-of select="$ident"/>
  101.       <xsl:text>/* </xsl:text>
  102.       <xsl:value-of select="$ident"/>
  103.       <xsl:text> * </xsl:text>
  104.       <xsl:value-of select="comment"/>
  105.       <xsl:text> </xsl:text>
  106.       <xsl:value-of select="$ident"/>
  107.       <xsl:text> */ </xsl:text>
  108.     </xsl:if>
  109.  
  110.     <xsl:value-of select="$ident"/>
  111.  
  112.     <xsl:value-of select="type"/>
  113.     <xsl:text> </xsl:text>
  114.     <xsl:value-of select="name"/>
  115.     <xsl:if test="value">
  116.       <xsl:text> = </xsl:text>
  117.       <xsl:value-of select="value"/>
  118.     </xsl:if>
  119.     <xsl:text>; </xsl:text>
  120.   </xsl:template>
  121.  
  122.   <xsl:template match="operation">
  123.     <xsl:if test="comment!=''">
  124.       <xsl:text> </xsl:text>
  125.       <xsl:value-of select="$ident"/>
  126.       <xsl:text>/* </xsl:text>
  127.       <xsl:value-of select="$ident"/>
  128.       <xsl:text> * </xsl:text>
  129.       <xsl:value-of select="comment"/>
  130.       <xsl:text> </xsl:text>
  131.       <xsl:for-each select="parameters/parameter/comment">
  132.     <xsl:value-of select="$ident"/>
  133.     <xsl:text> * @</xsl:text>
  134.     <xsl:value-of select="../name"/>
  135.     <xsl:text> </xsl:text>
  136.       </xsl:for-each>
  137.       <xsl:value-of select="$ident"/>
  138.       <xsl:text> */ </xsl:text>
  139.     </xsl:if>
  140.  
  141.     <xsl:value-of select="$ident"/>
  142.  
  143.     <xsl:if test="type=''">
  144.       <xsl:if test="$warn='true'">
  145.         <xsl:message>// Defaulting type to <xsl:value-of select="$type"/> for <xsl:value-of select="name"/>().</xsl:message>
  146.       </xsl:if>
  147.       <xsl:value-of select="$type"/>
  148.     </xsl:if>
  149.     
  150.     <xsl:value-of select="type"/>      
  151.     <xsl:text> </xsl:text>  
  152.  
  153.     <xsl:value-of select="name"/>
  154.  
  155.     <xsl:text>(</xsl:text>
  156.     <xsl:for-each select="parameters/*">
  157.       <xsl:if test="not(@kind)">
  158.         <xsl:if test="$warn='true'">
  159.           <xsl:message>// Defaulting argument passing kind to <xsl:value-of select="$kind"/> for <xsl:value-of select="name"/>.</xsl:message>    
  160.         </xsl:if>
  161.         <xsl:value-of select="$kind"/>
  162.       </xsl:if>
  163.       <xsl:value-of select="@kind"/>
  164.       <xsl:text> </xsl:text>
  165.       <xsl:value-of select="type"/>
  166.       <xsl:text> </xsl:text>
  167.       <xsl:value-of select="name"/>
  168.       <xsl:if test="not(position()=last())">
  169.         <xsl:text>, </xsl:text>        
  170.       </xsl:if>
  171.     </xsl:for-each>
  172.     <xsl:text>); </xsl:text>
  173.   </xsl:template>
  174.  
  175.  
  176.   <xsl:template match="text()">    
  177.   </xsl:template>
  178.  
  179.   <xsl:template match="node()|@*">
  180.     <xsl:apply-templates match="node()|@*"/>  
  181.   </xsl:template>
  182.  
  183. </xsl:stylesheet>