Ignore:
Timestamp:
18/01/12 11:46:07 (8 years ago)
Author:
mnagni
Message:

Now generate the inner class attributes and table relations which manage the attribute subtyping (at least for no more than the same subtyping attribute for each class)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • mauRepo/xmi2sqlalchemy/trunk/src/main/resources/velocity/python/pythonClass.vm

    r8048 r8064  
    5757${tab}${tab}return self._${attribute.getParentName().toLowerCase()}.${attribute.name} 
    5858#end 
     59#if($attribute.subTypes) 
     60${tab}@property 
     61${tab}def ${attribute.name}(self): 
     62#foreach($type in $attribute.subTypes) 
     63#set ( $assoClass = "$type.associatedClass.name.toLowerCase()") 
     64${tab}${tab}if(self._$assoClass is not None): 
     65${tab}${tab}${tab}return self._$assoClass 
     66#end 
     67${tab}${tab}return None 
     68#end 
     69#end 
     70 
     71#macro(saSetter $type, $sTypes) 
     72#foreach($stype in $sTypes) 
     73#if(!$stype.equals($type)) 
     74${tab}${tab}${tab}self._${stype.associatedClass.name.toLowerCase()}#initAttributeLeft($stype) 
     75#end 
     76#end 
     77#end 
     78 
     79#macro(initAttributeLeft $attrL) 
     80#if($attrL.hasMultiplicity()) = [] 
     81#else = None 
     82#end 
    5983#end 
    6084 
     
    6589${tab}def ${attribute.name}(self, value): 
    6690${tab}${tab}${tab} self._${attribute.getParentName().toLowerCase()}.${attribute.name} = value 
     91#end 
     92#if($attribute.subTypes) 
     93${tab}@${attribute.name}.setter 
     94${tab}def ${attribute.name}(self, value): 
     95#foreach($type in $attribute.subTypes) 
     96#set ( $assoClass = "$type.associatedClass.name") 
     97#set ( $assoClassL = "$type.associatedClass.name.toLowerCase()") 
     98${tab}${tab}if isinstance(value, $assoClass): 
     99${tab}${tab}${tab}self._$assoClassL = value 
     100#saSetter($type, $attribute.subTypes) 
     101#end 
    67102#end 
    68103#end 
     
    77112#end 
    78113 
     114#macro( subTypes $subTypes) 
     115#foreach($type in $subTypes) 
     116${tab}${tab}self._${type.associatedClass.name.toLowerCase()}#initAttributeLeft($type) 
     117#end 
     118#end 
     119 
    79120#macro( attributes $attributes, $parents) 
    80121#if($parents) 
     
    83124#end 
    84125#end 
     126 
    85127#foreach($attribute in $attributes) 
    86 ${tab}${tab}self.${attribute.name} #if($attribute.hasMultiplicity()) = [] 
    87 #else = None 
     128#if($attribute.subTypes) 
     129#subTypes($attribute.subTypes) 
     130#else 
     131${tab}${tab}self.${attribute.name}#initAttributeLeft($attribute) 
    88132#end 
    89133#end 
    90134#end 
     135 
    91136 
    92137#importing($imports) 
Note: See TracChangeset for help on using the changeset viewer.