-
Notifications
You must be signed in to change notification settings - Fork 2
/
nodeIdClassGenerator.py
157 lines (132 loc) · 4.17 KB
/
nodeIdClassGenerator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import csv
import os.path
def readNodeIdCsv(file):
file_path = os.path.abspath(file)
nodeIdList = []
with open(file_path, newline='') as csvfile:
nodeIdReader = csv.reader(csvfile, delimiter=',', quotechar='|')
for row in nodeIdReader:
nodeId = {}
nodeId["name"] = row[0]
nodeId["id"] = row[1]
nodeId["type"] = row[2]
nodeIdList.append(nodeId)
# end for
# end with
return nodeIdList
# end def
def createJavaNodeIdListMembers(nodeIdList, type_filter=[]):
idListentry = '\t\t\tadd(new NodeId("{name}","{id}","{type}"));'
memberString = ""
for node in nodeIdList:
if(node["type"] in type_filter or len(type_filter) == 0):
memberString += idListentry.format(**node) + "\n"
#end if
#end for
return memberString
#end def
def createJavaNodeIdListClass(nodeIdList, className, type_filter=[]):
classContent_upperPart = """import java.util.ArrayList;
public class """+className+"""
{
ArrayList<NodeId> id_list = new ArrayList<NodeId>() {
{
"""
classContent_lowerPart = """
}
};
public static String getDataTypeNodeId(String typeName)
{
for(NodeId node : id_list)
{
if(node.name == typeName)
{
return node.id;
}
}
return "";
}
public static Boolean dataTypeNodeIdExists(String typeName)
{
for(NodeId node : id_list)
{
if(node.name == typeName)
{
return true;
}
}
return false;
}
public static void addDataType(String name, String id)
{
id_list.add(new NodeId(name, id, "DataType"));
}
}
class NodeId
{
String name;
String id;
String type;
public NodeId(String name, String id, String type)
{
this.name = name;
this.id = id;
this.type = type;
}
}
"""
classContent = classContent_upperPart
classContent += createJavaNodeIdListMembers(nodeIdList, type_filter)
classContent += classContent_lowerPart
return classContent
# end def
def createJavaDataTypeNodeIdList(csv_file, java_file, class_name):
if(not java_file.endswith(".java")):
java_file = os.path.join(java_file, "DataTypeNodeIdList.java")
# end if
nodeIdList = readNodeIdCsv(csv_file)
javaContent = createJavaNodeIdListClass(nodeIdList, class_name, ["DataType"])
with open(java_file, "w") as javaFileObj:
javaFileObj.write(javaContent)
# end with
# end def
def createJavaReferenceTypeNodeIdList(csv_file, java_file, class_name):
if(not java_file.endswith(".java")):
java_file = os.path.join(java_file, "ReferenceTypeNodeIdList.java")
# end if
nodeIdList = readNodeIdCsv(csv_file)
javaContent = createJavaNodeIdListClass(nodeIdList, class_name, ["ReferenceType"])
with open(java_file, "w") as javaFileObj:
javaFileObj.write(javaContent)
# end with
# end def
def createJavaObjectTypeNodeIdList(csv_file, java_file, class_name):
if(not java_file.endswith(".java")):
java_file = os.path.join(java_file, "ObjectTypeNodeIdList.java")
# end if
nodeIdList = readNodeIdCsv(csv_file)
javaContent = createJavaNodeIdListClass(nodeIdList, class_name, ["ObjectType"])
with open(java_file, "w") as javaFileObj:
javaFileObj.write(javaContent)
# end with
# end def
def createJavaObjectNodeIdList(csv_file, java_file, class_name):
if(not java_file.endswith(".java")):
java_file = os.path.join(java_file, "ObjectNodeIdList.java")
# end if
nodeIdList = readNodeIdCsv(csv_file)
javaContent = createJavaNodeIdListClass(nodeIdList, class_name, ["Object"])
with open(java_file, "w") as javaFileObj:
javaFileObj.write(javaContent)
# end with
# end def
def createJavaVariableTypeNodeIdList(csv_file, java_file, class_name):
if(not java_file.endswith(".java")):
java_file = os.path.join(java_file, "VariableTypeNodeIdList.java")
# end if
nodeIdList = readNodeIdCsv(csv_file)
javaContent = createJavaNodeIdListClass(nodeIdList, class_name, ["VariableType"])
with open(java_file, "w") as javaFileObj:
javaFileObj.write(javaContent)
# end with
# end def