source: mauRepo/xmi2sqlalchemy/trunk/src/main/resources/velocity/python/pythonClass.vm @ 8040

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/mauRepo/xmi2sqlalchemy/trunk/src/main/resources/velocity/python/pythonClass.vm@8040
Revision 8040, 3.4 KB checked in by mnagni, 8 years ago (diff)

Again uncompleted deployment in DB. Tomorrow have to check better the primaryjoins!

  • Property svn:executable set to *
Line 
1##########################################################################
2## pythonClass.vm
3## The form expects the following context attributes
4## classModel - an instance of ClassModel class
5## imports    - a Map<String, Set<String>> defining the modules to import
6## stereotype - an instance of UMLClass
7##########################################################################
8
9#set ($object = "object")
10#set ($newline = '\n')
11#macro( superclass $superclasses, $stereotype)
12#if($superclasses.size() == 0 && !$stereotype)
13$object#elseif($stereotype && $superclasses.size() == 0)
14${stereotype.name}#elseif($superclasses.size() > 0)
15#foreach( $classModel in $superclasses)
16${classModel.associatedClass.name}#if($foreach.hasNext),#end
17#end
18#end
19#end
20
21#macro( asEnumeration $asEnumeration)
22#foreach($item in $asEnumeration.simpleKeyValues)
23${tab}en_${item.key.replaceAll("[()]", "")} = "${item.value}"
24#end
25#end
26
27#macro( asCodeList $asCodeList)
28#foreach($item in $asCodeList.simpleKeyValues)
29${tab}cl_${item.key.replaceAll("[()]", "")} = "${item.value}"
30#end
31#end
32
33#macro( asUnion $classModel)
34${tab}types = {#unionDictionary($classModel.attributeModel)}
35#end
36
37#macro (unionDictionary $attributeModel)
38#foreach($item in $attributeModel)
39'${item.name}':#substituteClassType(${item.associatedType.associatedClass.name})#if($foreach.hasNext),#end 
40#end
41#end
42
43
44#macro( importing $toImport)
45#foreach( $key in $toImport.keySet())   
46from $key import #foreach( $item in $toImport.get($key)) $item#if($foreach.hasNext),#end
47
48#end
49#end
50#end
51
52#macro (getter $attribute)
53#set ( $methodName = "$display.capitalize( $attribute.name )")
54#if($attribute.parentName)
55${tab}@property
56${tab}def ${attribute.name}(self):
57${tab}${tab}return self._${attribute.parentName.toLowerCase()}.${attribute.name}
58#end
59#end
60
61#macro (setter $attribute)
62#set ( $methodName = "$display.capitalize( $attribute.name )")
63#if($attribute.parentName)
64${tab}@${attribute.name}.setter
65${tab}def ${attribute.name}(self, value):
66${tab}${tab}${tab} self._${attribute.parentName.toLowerCase()}.${attribute.name} = value
67#end
68#end
69
70#macro ( dogettersetter $attributes)
71#foreach($attribute in $attributes)
72
73#getter($attribute)
74
75#setter($attribute)
76#end
77#end
78
79#macro( attributes $attributes, $parents)
80#if($parents)
81#foreach( $parent in $parents)
82${tab}${tab}self._${parent.associatedClass.name.toLowerCase()} = ${parent.associatedClass.name}()       
83#end
84#foreach($attribute in $attributes)
85${tab}${tab}self.${attribute.name}
86#end
87#end
88#end
89
90#importing($imports)
91
92'''
93Created on $date
94
95@author: mnagni
96'''
97
98class ${classModel.associatedClass.name}(#superclass($classModel.parents, $stereotype)):
99${tab}'''
100${tab}${tab}Represents a data entity defined in a UML diagram and supposed to
101${tab}${tab}be persisted in a relational database.
102 
103${tab}${tab}This class has been genererated automatically using the Apache Velocity project.
104${tab}'''
105#if($classModel.isEnumeration())
106#asEnumeration($classModel)
107#elseif ($classModel.isCodeList())
108#asCodeList($classModel)
109#elseif ($classModel.isUnion())
110#asUnion($classModel)
111#else
112${tab}'''
113${tab}${tab}Please note that any access to the inner attributes should be done using
114${tab}${tab}the given get/set methods and NOT accessing them directly.
115${tab}'''
116${tab}def __init__(self):
117#end
118#if (!($classModel.isEnumeration() || $classModel.isCodeList() || $classModel.isUnion()))
119#attributes($attributes, $classModel.parents)
120${tab}${tab}super(${classModel.associatedClass.name}, self).__init__()
121#dogettersetter($attributes)
122#end
Note: See TracBrowser for help on using the repository browser.