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-uml2python.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2003-12-13  |  6.3 KB  |  207 lines

  1. <?xml version="1.0"?>
  2. <!-- 
  3.      Transform dia UML objects to Python classes 
  4.  
  5.      Based on The uml2c++ code from
  6.      Matthieu Sozeau <mattam@netcourrier.com>
  7.      Copyright(c) 2003 Holger Lehmann <holger.lehmann@catworkx.de>
  8.  
  9.      This program is free software; you can redistribute it and/or modify
  10.      it under the terms of the GNU General Public License as published by
  11.      the Free Software Foundation; either version 2 of the License, or
  12.      (at your option) any later version.
  13.      
  14.      This program is distributed in the hope that it will be useful,
  15.      but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.      GNU General Public License for more details.
  18.      
  19.      You should have received a copy of the GNU General Public License
  20.      along with this program; if not, write to the Free Software
  21.      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22.  
  23. -->
  24.  
  25. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  26.  
  27.   <xsl:output method="text"/>
  28.  
  29.   <xsl:param name="directory"/>
  30.     
  31.   <xsl:param name="ident">
  32.     <xsl:text>    </xsl:text>
  33.   </xsl:param>
  34.   
  35.   <!-- Visibility indentation -->
  36.   <xsl:param name="visident">
  37.     <xsl:text>  </xsl:text>
  38.   </xsl:param>
  39.  
  40.   <xsl:template match="class">
  41.     <xsl:document href="{$directory}{@name}.py" method="text">
  42.       <xsl:if test="comment">
  43.     <xsl:text># </xsl:text>
  44.     <xsl:value-of select="comment"/>
  45.     <xsl:text> </xsl:text>
  46.       </xsl:if>
  47.  
  48.       <xsl:text>class </xsl:text>
  49.       <xsl:value-of select="@name"/>
  50.       <xsl:text> ( </xsl:text>
  51.       <xsl:if test="@stereotype!=''">
  52.         <xsl:value-of select="@stereotype"/>      
  53.       </xsl:if>
  54.       <xsl:text> ): </xsl:text>
  55.       <xsl:if test="comment!=''">
  56.         <xsl:value-of select="$ident"/>
  57.         <xsl:text>""" </xsl:text>
  58.         <xsl:value-of select="$ident"/>
  59.         <xsl:text>  </xsl:text>
  60.         <xsl:value-of select="comment"/>
  61.         <xsl:text> </xsl:text>
  62.         <xsl:value-of select="$ident"/>
  63.         <xsl:text>""" </xsl:text>
  64.       </xsl:if>
  65.       <xsl:apply-templates select="attributes"/>
  66.       <xsl:text> </xsl:text>
  67.       <xsl:apply-templates select="operations"/>
  68.     </xsl:document>
  69.   </xsl:template>
  70.   
  71.   <xsl:template match="operations|attributes">
  72.     <xsl:if test="*[@visibility='private']">
  73.       <xsl:value-of select="$visident"/>
  74.       <xsl:text>  #private: </xsl:text>
  75.       <xsl:apply-templates select="*[@visibility='private']"/>
  76.       <xsl:text> </xsl:text>
  77.     </xsl:if>
  78.     <xsl:if test="*[@visibility='protected']">
  79.       <xsl:value-of select="$visident"/>
  80.       <xsl:text>  #protected: </xsl:text>
  81.       <xsl:apply-templates select="*[@visibility='protected']"/>
  82.       <xsl:text> </xsl:text>
  83.     </xsl:if>
  84.     <xsl:if test="*[@visibility='public']">
  85.       <xsl:value-of select="$visident"/>
  86.       <xsl:text>  #public: </xsl:text>
  87.       <xsl:apply-templates select="*[@visibility='public']"/>
  88.       <xsl:text> </xsl:text>
  89.     </xsl:if>
  90.     <xsl:if test="*[not(@visibility)]">
  91.       <xsl:apply-templates select="*[not(@visibility)]"/>
  92.       <xsl:text> </xsl:text>
  93.     </xsl:if>
  94.   </xsl:template>
  95.  
  96.  
  97.   <xsl:template match="attribute">
  98.  
  99.     <xsl:value-of select="$ident"/>
  100.     <xsl:value-of select="name"/>
  101.     <xsl:if test="value!=''">
  102.       <xsl:text> = </xsl:text>
  103.       <xsl:value-of select="value"/>
  104.     </xsl:if>
  105.     <xsl:if test="value=''">
  106.       <xsl:text> = None </xsl:text>
  107.     </xsl:if>
  108.     <xsl:text> # </xsl:text>
  109.     <xsl:value-of select="type"/>
  110.     <xsl:if test="comment!=''">
  111.       <xsl:text> </xsl:text>
  112.       <xsl:value-of select="$ident"/>
  113.       <xsl:text>""" </xsl:text>
  114.       <xsl:value-of select="$ident"/>
  115.       <xsl:text>  </xsl:text>
  116.       <xsl:value-of select="comment"/>
  117.       <xsl:text> </xsl:text>
  118.       <xsl:value-of select="$ident"/>
  119.       <xsl:text>"""</xsl:text>
  120.     </xsl:if>
  121.     <xsl:text> </xsl:text>
  122.   </xsl:template>
  123.  
  124.   <xsl:template match="operation">
  125.  
  126.     <xsl:value-of select="$ident"/>
  127.     
  128.     <xsl:value-of select="name"/>
  129.     <xsl:text>(</xsl:text>
  130.     <xsl:for-each select="parameters/*">
  131.       <xsl:text> </xsl:text>
  132.       <xsl:value-of select="name"/>
  133.       <xsl:if test="value">
  134.         <xsl:text> = </xsl:text>
  135.         <xsl:value-of select="value"/>
  136.       </xsl:if>
  137.       <xsl:if test="not(position()=last())">
  138.         <xsl:text>, </xsl:text>        
  139.       </xsl:if>
  140.     </xsl:for-each>
  141.  
  142.     <xsl:text>):</xsl:text>
  143.     <!-- Constructor has no type -->
  144.     <xsl:if test="type">
  145.       <xsl:text> # returns:  </xsl:text>      
  146.       <xsl:value-of select="type"/>
  147.     </xsl:if>
  148.     <xsl:text>   </xsl:text>      
  149.  
  150.     <xsl:value-of select="$ident"/>
  151.     <xsl:text>   """ </xsl:text>
  152.     <xsl:if test="comment!=''">
  153.       <xsl:value-of select="$ident"/>
  154.       <xsl:text>     </xsl:text>
  155.       <xsl:value-of select="comment"/>
  156.       <xsl:text> </xsl:text>
  157.     </xsl:if>
  158.     <xsl:for-each select="parameters/parameter/comment">
  159.       <xsl:value-of select="$ident"/>
  160.       <xsl:text>     @</xsl:text>
  161.       <xsl:value-of select="../name"/>
  162.       <xsl:text>:</xsl:text>
  163.       <xsl:value-of select="../type"/>
  164.       <xsl:if test="../comment!=''">
  165.     <xsl:text> :</xsl:text>
  166.     <xsl:value-of select="../comment"/>
  167.       </xsl:if>
  168.       <xsl:text> </xsl:text>
  169.     </xsl:for-each>
  170.     <xsl:if test="type">
  171.       <xsl:text>         returns:  </xsl:text>      
  172.       <xsl:value-of select="type"/>
  173.       <xsl:text> </xsl:text>
  174.     </xsl:if>
  175.     <xsl:value-of select="$ident"/>
  176.     <xsl:text>    """ </xsl:text>
  177.     <xsl:text>       return None </xsl:text>
  178.  
  179.   </xsl:template>
  180.  
  181.  
  182.   <xsl:template match="text()">    
  183.   </xsl:template>
  184.  
  185.   <xsl:template match="node()|@*">
  186.     <xsl:apply-templates match="node()|@*"/>  
  187.   </xsl:template>
  188.  
  189. </xsl:stylesheet>
  190. <!-- Keep this comment at the end of the file
  191. Local variables:
  192. mode: xml
  193. sgml-omittag:nil
  194. sgml-shorttag:nil
  195. sgml-namecase-general:nil
  196. sgml-general-insert-case:lower
  197. sgml-minimize-attributes:nil
  198. sgml-always-quote-attributes:t
  199. sgml-indent-step:2
  200. sgml-indent-data:t
  201. sgml-parent-document:nil
  202. sgml-exposed-tags:nil
  203. sgml-local-catalogs:nil
  204. sgml-local-ecat-files:nil
  205. End:
  206. -->
  207.