expressir 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/macos.yml +38 -0
  3. data/.github/workflows/ubuntu.yml +56 -0
  4. data/.github/workflows/windows.yml +40 -0
  5. data/.gitignore +12 -0
  6. data/.rspec +2 -0
  7. data/.rubocop.yml +508 -0
  8. data/Gemfile +4 -0
  9. data/README.adoc +147 -0
  10. data/Rakefile +6 -0
  11. data/bin/console +12 -0
  12. data/bin/rspec +29 -0
  13. data/bin/setup +8 -0
  14. data/docs/development.md +90 -0
  15. data/exe/expressir +20 -0
  16. data/expressir.gemspec +35 -0
  17. data/lib/expressir.rb +21 -0
  18. data/lib/expressir/cli.rb +27 -0
  19. data/lib/expressir/cli/ui.rb +36 -0
  20. data/lib/expressir/config.rb +23 -0
  21. data/lib/expressir/express.rb +12 -0
  22. data/lib/expressir/express/aggregate_dimension.rb +38 -0
  23. data/lib/expressir/express/attribute.rb +15 -0
  24. data/lib/expressir/express/comment.rb +7 -0
  25. data/lib/expressir/express/defined_type.rb +36 -0
  26. data/lib/expressir/express/derived.rb +65 -0
  27. data/lib/expressir/express/derived_aggregate.rb +43 -0
  28. data/lib/expressir/express/entity.rb +137 -0
  29. data/lib/expressir/express/explicit.rb +70 -0
  30. data/lib/expressir/express/explicit_aggregate.rb +46 -0
  31. data/lib/expressir/express/explicit_or_derived.rb +16 -0
  32. data/lib/expressir/express/global_rule.rb +44 -0
  33. data/lib/expressir/express/interface_specification.rb +51 -0
  34. data/lib/expressir/express/interfaced_item.rb +38 -0
  35. data/lib/expressir/express/inverse.rb +46 -0
  36. data/lib/expressir/express/inverse_aggregate.rb +37 -0
  37. data/lib/expressir/express/model_element.rb +7 -0
  38. data/lib/expressir/express/named_type.rb +19 -0
  39. data/lib/expressir/express/remark.rb +8 -0
  40. data/lib/expressir/express/repository.rb +306 -0
  41. data/lib/expressir/express/schema_definition.rb +96 -0
  42. data/lib/expressir/express/subtype_constraint.rb +14 -0
  43. data/lib/expressir/express/type.rb +26 -0
  44. data/lib/expressir/express/type_aggregate.rb +42 -0
  45. data/lib/expressir/express/type_enum.rb +29 -0
  46. data/lib/expressir/express/type_parser.rb +45 -0
  47. data/lib/expressir/express/type_select.rb +82 -0
  48. data/lib/expressir/express/unique_rule.rb +35 -0
  49. data/lib/expressir/express/where_rule.rb +32 -0
  50. data/lib/expressir/express_parser.rb +30 -0
  51. data/lib/expressir/parser.rb +6 -0
  52. data/lib/expressir/parser/owl_parser.rb +8 -0
  53. data/lib/expressir/version.rb +3 -0
  54. data/original/examples/ap233/ap233e1_arm_lf_stepmod-2010-11-12.exp +9589 -0
  55. data/original/examples/ap233/ap233e1_arm_lf_stepmod-2010-11-12.owl +36619 -0
  56. data/original/examples/ap233/ap233e1_arm_lf_stepmod-2010-11-12.xml +13294 -0
  57. data/original/examples/employment/eclipse/.project +17 -0
  58. data/original/examples/employment/eclipse/Export/Employment.png +0 -0
  59. data/original/examples/employment/eclipse/Express/employment_schema.exp +33 -0
  60. data/original/examples/employment/eclipse/Express/employment_schema.xmi +77 -0
  61. data/original/examples/employment/eclipse/Express/employment_schema.xml +93 -0
  62. data/original/examples/employment/eclipse/Models/Employment.uml +4 -0
  63. data/original/examples/employment/eclipse/Models/Employment.umldi +240 -0
  64. data/original/examples/employment/eclipse/readme.txt +7 -0
  65. data/original/examples/employment/employment_schema.exp +33 -0
  66. data/original/examples/employment/employment_schema.rb +232 -0
  67. data/original/examples/employment/employment_schema.xml +93 -0
  68. data/original/examples/employment/employment_schema___module.rb +46 -0
  69. data/original/examples/employment/employment_schema___p28attr.rb +126 -0
  70. data/original/examples/employment/employment_schema___p28inst.rb +26 -0
  71. data/original/examples/employment/example_employment_data.xml +1 -0
  72. data/original/examples/employment/example_employment_data_copy.xml +1 -0
  73. data/original/examples/employment/example_employment_reader.rb +30 -0
  74. data/original/examples/employment/example_employment_writer.rb +51 -0
  75. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.exp +3710 -0
  76. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.owl +35880 -0
  77. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.xmi +15357 -0
  78. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.xml +9468 -0
  79. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.exp +8404 -0
  80. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.owl +43147 -0
  81. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.xmi +18341 -0
  82. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.xml +11632 -0
  83. data/original/exp2ruby.rb +525 -0
  84. data/original/expsm.rb +34 -0
  85. data/original/mapping_owl.rb +1018 -0
  86. data/original/mapping_sysml.rb +2281 -0
  87. data/original/mapping_uml2.rb +599 -0
  88. data/original/mapping_uml2_eclipse.rb +433 -0
  89. data/original/reeper.rb +134 -0
  90. data/spec/acceptance/express_to_owl_spec.rb +18 -0
  91. data/spec/acceptance/version_spec.rb +12 -0
  92. data/spec/expressir/express/repository_spec.rb +25 -0
  93. data/spec/expressr_spec.rb +5 -0
  94. data/spec/spec_helper.rb +17 -0
  95. data/spec/support/console_helper.rb +29 -0
  96. metadata +239 -0
@@ -0,0 +1,2281 @@
1
+ require 'erb'
2
+ require 'uuid'
3
+ require 'nokogiri'
4
+ include Nokogiri
5
+
6
+ # EXPRESS to SysML Mapping
7
+ # Version 0.5
8
+ #
9
+ # This function navigates the EXPRESS STEPMod Model Ruby Classes
10
+ # and performs a structural EXPRESS-to-SysML (1.4) mapping using Ruby ERB templates.
11
+ # The output is in XMI 2.1 or 2.5 syntax in a file named <schema>.xmi if one schema input and 'Model.xmi' if more than one schema input.
12
+ #
13
+ # Real, Number, Integer, Boolean, String -> New Primitive Type
14
+ # Binary, Logical -> New PrimitiveType
15
+ # Schema -> Package
16
+ # Entity (subtype of) -> Class (Generalization) + Block stereotype
17
+ # Select Type -> Class & Generalization + Block/value and <<Auxillary>> stereotype
18
+ # Agg Type -> Collapsed into attribute if just used, converted into class with elements if part of aggregation or select type
19
+ # Enum Type -> Enumeration and EnumerationLiteral
20
+ # Explicit Attribute (Optional) Primitive or Enum -> Property owned by Class (with lower)
21
+ # Explicit Attribute (Optional) Entity -> Property owned by Class (with lower) plus Association owning other end property
22
+ # Explicit Attribute 1-D SET, BAG, LIST of Select or Entity -> Property owned by Class (with lower)
23
+ # plus Association owning other end property and multiplicity, unique and ordered set
24
+ # Explicit Attribute 1-D SET, BAG, LIST of Primitive or Enum -> Property owned by Class and multiplicity, unique and ordered set
25
+ # Higher level aggregations create intermediary blocks
26
+ # Explicit Attribute of Entity/Select/Builtin Redeclaration (Renamed) -> Property with (new) name that redefines inherited Property
27
+ # Inverse Attribute -> Association end adjustment
28
+ # Inverse Attribute Redeclaration (Renamed) -> Property with (new) name that redefines inherited Property
29
+ # USE or REFERENCE (even with named items) -> UML PackageImport between Packages
30
+ #
31
+ #######################################################################################
32
+
33
+ def get_uuid(id)
34
+ if $uuidsRequired
35
+ uuidmap = $uuidxml.xpath('//uuidmap[@id="' + id + '"]').first
36
+ if !uuidmap.nil?
37
+ $olduuids.delete uuidmap
38
+ return ' xmi:uuid="' + uuidmap.attributes["uuid"].to_s.strip + '"'
39
+ else
40
+ theUUID = $uuid.generate
41
+ uuidtext = theUUID.to_s.strip
42
+ uuidmap = Nokogiri::XML::Node.new("uuidmap", $uuidxml)
43
+ uuidmap['id'] = id
44
+ uuidmap['uuid'] = theUUID
45
+ $uuidxml.root.add_child uuidmap
46
+ return ' xmi:uuid="' + theUUID + '"'
47
+ end
48
+ else
49
+ return ""
50
+ end
51
+ end
52
+
53
+ def get_where(id,rule)
54
+ if !$wherexml.nil?
55
+ wheremap = $wherexml.xpath('//wheremap[@id="' + id + '"]').first
56
+ if !wheremap.nil?
57
+ return wheremap.at("OCL").inner_html
58
+ else
59
+ wheremap = Nokogiri::XML::Node.new("wheremap", $wherexml)
60
+ wheremap['id'] = id
61
+ express = Nokogiri::XML::Node.new("EXPRESS", $wherexml)
62
+ express.content = rule
63
+ wheremap.add_child express
64
+ ocl = Nokogiri::XML::Node.new("OCL", $wherexml)
65
+ wheremap.add_child ocl
66
+ $wherexml.root.add_child wheremap
67
+ return ""
68
+ end
69
+ else
70
+ return ""
71
+ end
72
+ end
73
+
74
+ def put_ops(name, file)
75
+ # operation template
76
+ operation_template = %{<ownedOperation xmi:id="<%= xmiid %>"<%= get_uuid(xmiid) %> xmi:type="uml:Operation">
77
+ <name><%= op_name %></name>
78
+ <ownedRule xmi:id="<%= xmiid %>-body"<%= get_uuid(xmiid+'-body') %> xmi:type="uml:Constraint">
79
+ <specification xmi:id="<%= xmiid %>-spec"<%= get_uuid(xmiid+'-spec') %> xmi:type="uml:OpaqueExpression">
80
+ <body><%= op_ocl %></body>
81
+ <language>OCL2.0</language>
82
+ </specification>
83
+ </ownedRule>}
84
+
85
+ parameter_template = %{<ownedParameter xmi:id="<%= par_xmiid %>"<%= get_uuid(par_xmiid) %> xmi:type="uml:Parameter">
86
+ <name><%= par_name %></name>
87
+ <type xmi:idref="<%= par_type %>"/>
88
+ </ownedParameter>}
89
+
90
+ return_template = %{<ownedParameter xmi:id="<%= xmiid %>-return"<%= get_uuid(xmiid+'-return') %> xmi:type="uml:Parameter">
91
+ <direction>return</direction>
92
+ <type xmi:idref="<%= ret_type %>"/>
93
+ </ownedParameter>}
94
+
95
+ operation_end = %{</ownedOperation>}
96
+
97
+ if !$opsxml.nil?
98
+ ops = $opsxml.xpath('//operation[@for="' + name + '"]')
99
+ for op in ops
100
+ body = op.at('body')
101
+ if !body.nil?
102
+ op_ocl = body.content
103
+ op_name = op['name']
104
+ ret_type = op['type']
105
+ xmiid = '_2_op_' + name + '_' + op_name
106
+ res = ERB.new(operation_template)
107
+ t = res.result(binding)
108
+ file.puts t
109
+
110
+ params = op.xpath('./param')
111
+ for param in params
112
+ par_name = param['name']
113
+ par_xmiid = xmiid + '-' + par_name
114
+ par_type = param['type']
115
+ res = ERB.new(parameter_template)
116
+ t = res.result(binding)
117
+ file.puts t
118
+ end
119
+ res = ERB.new(return_template)
120
+ t = res.result(binding)
121
+ file.puts t
122
+ res = ERB.new(operation_end)
123
+ t = res.result(binding)
124
+ file.puts t
125
+ else
126
+ puts 'Operation ' + name + '.' + op['name'] + ' has no body - ignored!'
127
+ end
128
+ end
129
+ end
130
+ end
131
+
132
+ def isEncapsulated (type, attrib)
133
+ encapsulated = false
134
+ rules = type.wheres.select {|w| w.name == "encapsulated"}
135
+ if rules.length > 0
136
+ for rule in rules
137
+ if rule.expression == "SIZEOF(USEDIN(SELF, '')) = 1"
138
+ encapsulated = true
139
+ elsif rule.expression == "SIZEOF(QUERY(elem <* SELF | SIZEOF(USEDIN(elem, '')) = 1)) = SIZEOF(SELF)"
140
+ encapsulated = true
141
+ elsif rule.expression[0..24] == "SIZEOF(USEDIN(SELF, '') -"
142
+ encapsulated = !(rule.expression[25..-1].include? ("." + attrib.entity.name.upcase + "." + attrib.name.upcase))
143
+ else
144
+ puts "Unknown encapsulated rule: " + rule.expression
145
+ end
146
+ if encapsulated
147
+ break
148
+ end
149
+ end
150
+ end
151
+ if (type.kind_of? EXPSM::Entity) && !encapsulated
152
+ for supertype in type.supertypes_array
153
+ encapsulated = isEncapsulated(supertype, attrib)
154
+ if encapsulated
155
+ break
156
+ end
157
+ end
158
+ end
159
+ return encapsulated
160
+ end
161
+
162
+ def isEncapsulatedInto (parent, entity, attrib)
163
+ encapsulated = false
164
+ rules = parent.wheres.select {|w| w.name == "encapsulateInto"}
165
+ if rules.length > 0
166
+ for rule in rules
167
+ ruleString = rule.expression.upcase
168
+ if ruleString[0..6] == "EXISTS("
169
+ closeParen = ruleString.index(')')
170
+ if ruleString[closeParen..-1].include? " XOR (SIZEOF(TYPEOF(SELF) *"
171
+ if !ruleString[closeParen+28..-1].include? ('.'+entity.name.upcase+'''')
172
+ encapsulated = (ruleString[6..closeParen].include? ('('+attrib.name.upcase+')'))
173
+ end
174
+ else
175
+ encapsulated = (ruleString[6..closeParen].include? ('('+attrib.name.upcase+')'))
176
+ end
177
+ else
178
+ puts "Unknown encapsulateInto rule: " + rule.expression
179
+ end
180
+ if encapsulated
181
+ break
182
+ end
183
+ end
184
+ end
185
+ if !encapsulated
186
+ for supertype in parent.supertypes_array
187
+ encapsulated = isEncapsulatedInto(supertype, entity, attrib)
188
+ if encapsulated
189
+ break
190
+ end
191
+ end
192
+ end
193
+ return encapsulated
194
+ end
195
+
196
+ def map_from_express(mapinput, passedArgs)
197
+ # Enter file name here to override defaults (<schema>.xmi if one schema, and Model.xmi if more than one)
198
+ output_xmi_filename = nil
199
+
200
+ noprune = false
201
+ schemaId = false
202
+ $uuidsRequired = true
203
+ xmiVersion = "2.1"
204
+ dtHandle = "local"
205
+ outPath = nil
206
+ for arg in passedArgs
207
+ argarray = arg.split('=')
208
+ case argarray[0]
209
+ when "noprune" then noprune = true
210
+ when "nouuids" then $uuidsRequired = false
211
+ when "path" then outPath = argarray[1]
212
+ when "schemaid" then schemaId = true
213
+ when "xmi" then xmiVersion = argarray[1]
214
+ when "types" then dtHandle = argarray[1]
215
+ end
216
+ end
217
+
218
+ case xmiVersion
219
+ when "2.1" then $StandardProfile = "StandardProfileL2"
220
+ when "2.5" then $StandardProfile = "StandardProfile"
221
+ else
222
+ puts "XMI version "+xmiVersion+" is not handled!"
223
+ exit
224
+ end
225
+
226
+ case dtHandle
227
+ when "local"
228
+ puts "Data types will generated within the package structure"
229
+ when "ignore"
230
+ puts "Data types will not be generated"
231
+ when "export"
232
+ puts "Data types will be exported to DataTypes.xmi"
233
+ else
234
+ puts "Data type handling option: "+dtHandle+" not valid!"
235
+ exit
236
+ end
237
+
238
+ if dtHandle != "local"
239
+ if outPath.nil?
240
+ puts "path must be specified when type=" + dtHandle
241
+ exit
242
+ end
243
+ end
244
+
245
+ uuidSafe = nil
246
+ uuidOldSafe = nil
247
+ if $uuidsRequired
248
+ $uuid = UUID.new
249
+ if File.exists?("UUIDs.xml")
250
+ uuidfile = File.open("UUIDs.xml")
251
+ $uuidxml = Nokogiri::XML(uuidfile, &:noblanks)
252
+ uuidfile.close
253
+ else
254
+ $uuidxml = Nokogiri::XML::Builder.new { |b| b.uuids }.doc
255
+ end
256
+ $olduuids = $uuidxml.xpath('//uuidmap')
257
+ end
258
+
259
+ if File.exists?("WhereRuleMapping.xml")
260
+ wherefile = File.open("WhereRuleMapping.xml")
261
+ $wherexml = Nokogiri::XML(wherefile, &:noblanks)
262
+ wherefile.close
263
+ end
264
+
265
+ if File.exists?("Operators.xml")
266
+ opsfile = File.open("Operators.xml")
267
+ $opsxml = Nokogiri::XML(opsfile, &:noblanks)
268
+ opsfile.close
269
+ end
270
+
271
+ # datatypes for builtin types that have been exported
272
+ datatype_hash = Hash.new
273
+
274
+ # XMI File Start Template (includes datatypes for builtin with no direct UML equivalent)
275
+ overall_start_template = %{<?xml version="1.0" encoding="UTF-8"?><%
276
+ if xmiVersion == "2.1" %>
277
+ <xmi:XMI xmi:version="2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" xmlns:uml="http://www.omg.org/spec/UML/20090901" xmlns:StandardProfileL2="http://schema.omg.org/spec/UML/2.3/StandardProfileL2.xmi" xmlns:sysml="http://www.omg.org/spec/SysML/20100301/SysML-profile"><%
278
+ else %>
279
+ <xmi:XMI xmlns:uml='http://www.omg.org/spec/UML/20131001' xmlns:xmi='http://www.omg.org/spec/XMI/20131001' xmlns:StandardProfile='http://www.omg.org/spec/UML/20131001/StandardProfile' xmlns:sysml='http://www.omg.org/spec/SysML/20150709/SysML'><%
280
+ end
281
+ $dtprefix=''
282
+ if !outPath.nil?
283
+ pathElements = outPath.split('/')
284
+ if dtHandle=='local'
285
+ for elem in pathElements
286
+ $dtprefix = $dtprefix + elem[0]
287
+ end
288
+ $dtprefix = $dtprefix + '_'
289
+ end
290
+ end %>}
291
+
292
+ # Package Structure Start
293
+ package_start = %{<%
294
+ if outPath.nil?
295
+ name = "SysMLfromEXPRESS"
296
+ else
297
+ pathElements = outPath.split('/')
298
+ name = pathElements[-1]
299
+ end %>
300
+ <uml:Package xmi:id="_0_<%= name %>"<%= get_uuid('_0_'+name) %> xmi:type="uml:Package">
301
+ <name><%= name %></name>}
302
+
303
+ # Apply SysML profile
304
+ apply_sysml = %{<profileApplication xmi:id="_profileApplication0"<%= get_uuid('_profileApplication0') %> xmi:type="uml:ProfileApplication"><%
305
+ if xmiVersion == "2.1" %>
306
+ <appliedProfile href="http://www.omg.org/spec/SysML/20100301/SysML-profile.uml#_0"/><%
307
+ else %>
308
+ <appliedProfile href="http://www.omg.org/spec/SysML/20150709/SysML.xmi#_SysML__0"/><%
309
+ end %>
310
+ </profileApplication>}
311
+
312
+ # Package end
313
+ package_end = %{</uml:Package>}
314
+
315
+ # XMI File End Template
316
+ overall_end_template = %{</xmi:XMI>}
317
+
318
+ #DATA TYPEs
319
+ data_types = %{<packagedElement xmi:id="<%= $dtprefix %>BINARY"<%= get_uuid($dtprefix+'BINARY') %> xmi:type="uml:PrimitiveType">
320
+ <name>Binary</name>
321
+ </packagedElement>
322
+ <packagedElement xmi:id="<%= $dtprefix %>STRING"<%= get_uuid($dtprefix+'STRING') %> xmi:type="uml:PrimitiveType">
323
+ <name>String</name>
324
+ </packagedElement>
325
+ <packagedElement xmi:id="<%= $dtprefix %>NUMBER"<%= get_uuid($dtprefix+'NUMBER') %> xmi:type="uml:PrimitiveType">
326
+ <name>Number</name>
327
+ <isAbstract>true</isAbstract>
328
+ </packagedElement>
329
+ <packagedElement xmi:id="<%= $dtprefix %>REAL"<%= get_uuid($dtprefix+'REAL') %> xmi:type="uml:PrimitiveType">
330
+ <name>Real</name>
331
+ <generalization xmi:id="_generalization-<%= $dtprefix %>REAL_NUMBER"<%= get_uuid('_generalization-'+$dtprefix+'REAL_NUMBER') %> xmi:type="uml:Generalization">
332
+ <general xmi:idref="<%= $dtprefix %>NUMBER"/>
333
+ </generalization>
334
+ </packagedElement>
335
+ <packagedElement xmi:id="<%= $dtprefix %>INTEGER"<%= get_uuid($dtprefix+'INTEGER') %> xmi:type="uml:PrimitiveType">
336
+ <name>Integer</name>
337
+ <generalization xmi:id="_generalization-<%= $dtprefix %>INTEGER_REAL"<%= get_uuid('_generalization-'+$dtprefix+'INTEGER_REAL') %> xmi:type="uml:Generalization">
338
+ <general xmi:idref="<%= $dtprefix %>REAL"/>
339
+ </generalization>
340
+ </packagedElement>
341
+ <packagedElement xmi:id="<%= $dtprefix %>LOGICAL"<%= get_uuid($dtprefix+'LOGICAL') %> xmi:type="uml:Enumeration">
342
+ <name>Logical</name>
343
+ <ownedLiteral xmi:id="<%= $dtprefix %>UNKNOWN"<%= get_uuid($dtprefix+'UNKNOWN') %> xmi:type="uml:EnumerationLiteral">
344
+ <name>Unknown</name>
345
+ </ownedLiteral>
346
+ </packagedElement>
347
+ <packagedElement xmi:id="<%= $dtprefix %>BOOLEAN"<%= get_uuid($dtprefix+'BOOLEAN') %> xmi:type="uml:Enumeration">
348
+ <name>Boolean</name>
349
+ <generalization xmi:id="<%= $dtprefix %>_generalization-<%= $dtprefix %>BOOLEAN-LOGICAL"<%= get_uuid('_generalization-'+$dtprefix+'BOOLEAN-LOGICAL') %> xmi:type="uml:Generalization">
350
+ <general xmi:idref="<%= $dtprefix %>LOGICAL"/>
351
+ </generalization>
352
+ <ownedLiteral xmi:id="<%= $dtprefix %>TRUE"<%= get_uuid($dtprefix+'TRUE') %> xmi:type="uml:EnumerationLiteral">
353
+ <name>True</name>
354
+ </ownedLiteral>
355
+ <ownedLiteral xmi:id="<%= $dtprefix %>FALSE"<%= get_uuid($dtprefix+'FALSE') %> xmi:type="uml:EnumerationLiteral">
356
+ <name>False</name>
357
+ </ownedLiteral>
358
+ </packagedElement>}
359
+
360
+ #DATA TYPE end
361
+ data_type_stereos = %{<sysml:ValueType xmi:id="<%= $dtprefix %>LOGICAL_VT"<%= get_uuid($dtprefix+'LOGICAL_VT') %>>
362
+ <base_DataType xmi:idref="<%= $dtprefix %>LOGICAL"/>
363
+ </sysml:ValueType>
364
+ <sysml:ValueType xmi:id="<%= $dtprefix %>BOOLEAN_VT"<%= get_uuid($dtprefix+'BOOLEAN_VT') %>>
365
+ <base_DataType xmi:idref="<%= $dtprefix %>BOOLEAN"/>
366
+ </sysml:ValueType>
367
+ <sysml:ValueType xmi:id="<%= $dtprefix %>NUMBER_VT"<%= get_uuid($dtprefix+'NUMBER_VT') %>>
368
+ <base_DataType xmi:idref="<%= $dtprefix %>NUMBER"/>
369
+ </sysml:ValueType>
370
+ <sysml:ValueType xmi:id="<%= $dtprefix %>REAL_VT"<%= get_uuid($dtprefix+'REAL_VT') %>>
371
+ <base_DataType xmi:idref="<%= $dtprefix %>REAL"/>
372
+ </sysml:ValueType>
373
+ <sysml:ValueType xmi:id="<%= $dtprefix %>INTEGER_VT"<%= get_uuid($dtprefix+'INTEGER_VT') %>>
374
+ <base_DataType xmi:idref="<%= $dtprefix %>INTEGER"/>
375
+ </sysml:ValueType>
376
+ <sysml:ValueType xmi:id="<%= $dtprefix %>STRING_VT"<%= get_uuid($dtprefix+'STRING_VT') %>>
377
+ <base_DataType xmi:idref="<%= $dtprefix %>STRING"/>
378
+ </sysml:ValueType>
379
+ <sysml:ValueType xmi:id="<%= $dtprefix %>BINARY_VT"<%= get_uuid($dtprefix+'BINARY_VT') %>>
380
+ <base_DataType xmi:idref="<%= $dtprefix %>BINARY"/>
381
+ </sysml:ValueType>}
382
+
383
+ # SCHEMA Start Template
384
+ schema_start_template = %{<% if schema_list.size > 1 %><packagedElement<% else %><uml:Package<% end %> xmi:id="<%= xmiid %>"<%= get_uuid(xmiid) %> xmi:type="uml:Package">
385
+ <name><%= schema.name %></name>}
386
+
387
+ # SCHEMA INTERFACE Template
388
+ schema_interface_template = %{<packageImport xmi:id="<%= xmiid %>"<%= get_uuid(xmiid) %> xmi:type="uml:PackageImport">
389
+ <importedPackage xmi:idref="_1_<%= interfaced_schema.foreign_schema_id %>"/>
390
+ </packageImport>}
391
+
392
+ # SCHEMA End Template
393
+ schema_end_template = %{<% if schema_list.size > 1 %></packagedElement><% else %></uml:Package><% end %>}
394
+
395
+ # ENTITY Block Template
396
+ entity_block_template = %{<sysml:Block xmi:id="<%= xmiid %>"<%= get_uuid(xmiid) %>>
397
+ <base_Class xmi:idref="<%= baseClass %>"/>
398
+ </sysml:Block>}
399
+
400
+ # ENTITY Start Template
401
+ entity_start_template = %{<packagedElement xmi:id="<%= xmiid %>"<%= get_uuid(xmiid) %> xmi:type="uml:Class">
402
+ <name><%= entity.name %></name><% if entity.isAbs %>
403
+ <isAbstract>true</isAbstract><% end %>}
404
+
405
+ # SUBTYPE OF Template
406
+ supertype_template = %{<generalization xmi:id="<%= xmiid %>"<%= get_uuid(xmiid) %> xmi:type="uml:Generalization">
407
+ <general xmi:idref="<%= xmiid_general %>"/>
408
+ </generalization>}
409
+
410
+ # ENTITY End Template
411
+ entity_end_template = %{</packagedElement>}
412
+
413
+ # ENUMERATION Start Template
414
+ enum_start_template = %{<packagedElement xmi:id="<%= xmiid %>"<%= get_uuid(xmiid) %> xmi:type="uml:Enumeration">
415
+ <name><%= enum.name %></name><% if !general.nil?
416
+ if !datatype_hash[general].nil? %>
417
+ <generalization xmi:id="<%= gen_xmiid %>"<%= get_uuid(gen_xmiid) %> xmi:type="uml:Generalization">
418
+ <general href="<%= datatype_hash[general] %>"/>
419
+ </generalization><% else %>
420
+ <generalization xmi:id="<%= gen_xmiid %>"<%= get_uuid(gen_xmiid) %> xmi:type="uml:Generalization">
421
+ <general xmi:idref="<%= xmiid_general %>"/>
422
+ </generalization>
423
+ <% end
424
+ end%>}
425
+
426
+ # ENUMERATION ITEM Template
427
+ enum_item_template = %{<ownedLiteral xmi:id="<%= enumitem_xmiid %>"<%= get_uuid(enumitem_xmiid) %> xmi:type="uml:EnumerationLiteral">
428
+ <name><%= enumitem %></name>
429
+ </ownedLiteral>}
430
+
431
+ # ENUMERATION End Template
432
+ enum_end_template = %{</packagedElement>}
433
+
434
+ # SELECT Start Template
435
+ select_start_template = %{<packagedElement xmi:id="<%= xmiid %>"<%= get_uuid(xmiid) %> xmi:type="<% if selectTypeType[type.name] == "Type" %>uml:DataType<% else %>uml:Class<% end %>">
436
+ <name><%= type.name %></name>
437
+ <isAbstract>true</isAbstract>}
438
+
439
+ # SELECT End Template
440
+ select_end_template = %{</packagedElement>}
441
+
442
+ # SELECT Stereotype Template
443
+ select_stereotype_template = %{<<%= $StandardProfile %>:Auxiliary xmi:id="<%= xmiid %>"<%= get_uuid(xmiid) %>>
444
+ <base_Class xmi:idref="<%= baseClass %>"/>
445
+ </<%= $StandardProfile %>:Auxiliary>}
446
+
447
+ # Template covering the output file contents for each attribute that is an entity
448
+ attribute_entity_template = %{<ownedAttribute xmi:id="<%= xmiid %>"<%= get_uuid(xmiid) %> xmi:type="uml:Property">
449
+ <name><%= attr.name %></name><% if islist %>
450
+ <isOrdered>true</isOrdered><% end %><% if !isset %>
451
+ <isUnique>false</isUnique><% end %>
452
+ <type xmi:idref="<%= domain_xmiid %>"/><% if (direct_inverse and !encapsulatedInto) or encapsulated %>
453
+ <aggregation>composite</aggregation><% end %>
454
+ <association xmi:idref="<%= assoc_xmiid %>"/><% if attr.redeclare_entity %>
455
+ <redefinedProperty xmi:idref="<%= redefined_xmiid %>"/><% end %>}
456
+
457
+ # INVERSE ATTRIBUTE Template
458
+ inverse_attribute_template = %{<ownedAttribute xmi:id="<%= xmiid %>"<%= get_uuid(xmiid) %> xmi:type="uml:Property">
459
+ <name><%= inverse.name %></name><% if !isset %>
460
+ <isUnique>false</isUnique><% end %>
461
+ <isReadOnly>true</isReadOnly><% if encapsulatedInto %>
462
+ <aggregation>composite</aggregation><% end %>
463
+ <type xmi:idref="<%= domain_xmiid %>"/>
464
+ <association xmi:idref="<%= assoc_xmiid %>"/><% if inverse.redeclare_entity %>
465
+ <redefinedProperty xmi:idref="<%= redefined_xmiid %>"/><% end %>}
466
+
467
+ #Template covering multiplicities
468
+ multiplicity = %{<% dummy = nil
469
+ if lower == '0' %><lowerValue xmi:id="<%= xmiid %>-lowerValue"<%= get_uuid(xmiid + '-lowerValue') %> xmi:type="uml:LiteralInteger"/><%
470
+ else
471
+ if lower != '1' %><lowerValue xmi:id="<%= xmiid %>-lowerValue"<%= get_uuid(xmiid + '-lowerValue') %> xmi:type=<% if /\\d+/ === lower %>"uml:LiteralInteger"<% else %>"uml:LiteralString"<% end %>>
472
+ <value><%= lower %></value>
473
+ </lowerValue><%
474
+ else
475
+ dummy = get_uuid(xmiid + '-lowerValue')
476
+ end
477
+ end %><% if dummy.nil? %>
478
+ <% end %><% if upper != '1' %><upperValue xmi:id="<%= xmiid %>-upperValue"<%= get_uuid(xmiid + '-upperValue') %> xmi:type=<% if /(\\d+|\\*)/ === upper %>"uml:LiteralUnlimitedNatural"<% else %>"uml:LiteralString"<% end %>>
479
+ <value><%= upper %></value>
480
+ </upperValue><%
481
+ else
482
+ dummy = get_uuid(xmiid + '-upperValue')
483
+ end %>}
484
+
485
+ #Template covering attribute wrapup
486
+ attribute_end = %{</ownedAttribute>}
487
+
488
+
489
+ # EXPLICIT ATTRIBUTE ENTITY Create Association Template
490
+ attribute_entity_association_template = %{<packagedElement xmi:id="<%= xmiid %>"<%= get_uuid(xmiid) %> xmi:type="uml:Association">
491
+ <memberEnd xmi:idref="<%= attr_xmiid %>"/><%
492
+ if !inverse_exists %>
493
+ <memberEnd xmi:idref="<%= xmiid + '-end' %>"/>
494
+ <ownedEnd xmi:id="<%= xmiid %>-end"<%= get_uuid(xmiid+'-end') %> xmi:type="uml:Property"><% if encapsulatedInto %>
495
+ <aggregation>composite</aggregation><% end %>
496
+ <type xmi:idref="<%= owner_xmiid %>"/>
497
+ <association xmi:idref="<%= xmiid %>"/>
498
+ <lowerValue xmi:id="<%= xmiid %>-end-lowerValue"<%= get_uuid(xmiid+'-end-lowerValue') %> xmi:type="uml:LiteralInteger"/><%
499
+ if encapsulated
500
+ dummy = get_uuid(xmiid+'-end-upperValue')
501
+ else %>
502
+ <upperValue xmi:id="<%= xmiid %>-end-upperValue"<%= get_uuid(xmiid+'-end-upperValue') %> xmi:type="uml:LiteralUnlimitedNatural">
503
+ <value>*</value>
504
+ </upperValue><%
505
+ end %>
506
+ </ownedEnd><%
507
+ else %><memberEnd xmi:idref="<%= iattr_xmiid %>"/><%
508
+ end %><%
509
+ if general_exists %>
510
+ <generalization xmi:id="<%= general_xmiid %>"<%= get_uuid(general_xmiid) %> xmi:type="uml:Generalization">
511
+ <general xmi:idref="<%= redefined_xmiid %>"/>
512
+ </generalization><%
513
+ end %>
514
+ </packagedElement>}
515
+
516
+
517
+ # INVERSE ATTRIBUTE ENTITY Create Association Template
518
+ inverse_entity_association_template = %{<packagedElement xmi:id="<%= xmiid %>"<%= get_uuid(xmiid) %> xmi:type="uml:Association">
519
+ <memberEnd xmi:idref="<%= xmiid + '-end' %>"/>
520
+ <memberEnd xmi:idref="<%= iattr_xmiid %>"/>
521
+ <ownedEnd xmi:id="<%= xmiid %>-end"<%= get_uuid(xmiid+'-end') %> xmi:type="uml:Property">
522
+ <type xmi:idref="<%= owner_xmiid %>"/>
523
+ <association xmi:idref="<%= xmiid %>"/><% xmiid = xmiid + '-end' %>}
524
+
525
+ inverse_entity_association_end = %{</ownedEnd>
526
+ <generalization xmi:id="<%= general_xmiid %>"<%= get_uuid(general_xmiid) %> xmi:type="uml:Generalization">
527
+ <general xmi:idref="<%= redefined_xmiid %>"/>
528
+ </generalization>
529
+ </packagedElement>}
530
+
531
+
532
+ # EXPLICIT ATTRIBUTE SIMPLE TYPE Template
533
+ attribute_builtin_template = %{<ownedAttribute xmi:id="<%= xmiid %>"<%= get_uuid(xmiid) %> xmi:type="uml:Property">
534
+ <name><%= attr.name %></name><% if islist %>
535
+ <isOrdered>true</isOrdered><% end %><% if !isset %>
536
+ <isUnique>false</isUnique><% end %>
537
+ <aggregation>composite</aggregation><% if attr.redeclare_entity %>
538
+ <redefinedProperty xmi:idref="<%= redefined_xmiid %>"/><% end %><% if !nestedAggs[domain_name].nil? %>
539
+ <type xmi:idref="<%= prefix+domain_name %>"/><% else if !datatype_hash[domain_name].nil? %>
540
+ <type href="<%= datatype_hash[domain_name] %>"/><% else %>
541
+ <type xmi:idref="<%= $dtprefix+domain_name %>"/><% end end %>}
542
+
543
+
544
+ # EXPLICIT ATTRIBUTE ENUM and TYPE Template
545
+ attribute_enum_type_template = %{<ownedAttribute xmi:id="<%= xmiid %>"<%= get_uuid(xmiid) %> xmi:type="uml:Property">
546
+ <name><%= attr.name %></name>
547
+ <type xmi:idref="<%= type_xmiid %>"/><% if islist %>
548
+ <isOrdered>true</isOrdered><% end %><% if !isset %>
549
+ <isUnique>false</isUnique><% end %>
550
+ <aggregation>composite</aggregation>}
551
+
552
+ # Lower bound constraint template
553
+ bound_constraint = %{<ownedRule xmi:id="<%= xmiid %>"<%= get_uuid(xmiid) %> xmi:type="uml:Constraint">
554
+ <name><%= name %>_LB</name>
555
+ <constrainedElement xmi:idref="<%= xmiid_entity %>"/>
556
+ <specification xmi:id="<%= xmiid %>-spec"<%= get_uuid(xmiid+'-spec') %> xmi:type="uml:OpaqueExpression">
557
+ <body><%= name %>-&gt;isEmpty() or <%= name %>-&gt;size() &gt;= <%= bound %></body>
558
+ <language>OCL2.0</language>
559
+ </specification>
560
+ </ownedRule>}
561
+
562
+ # UNIQUE rule template
563
+ unique_template = %{<ownedRule xmi:id="<%= xmiid %>"<%= get_uuid(xmiid) %> xmi:type="uml:Constraint">
564
+ <name><%= unique.name %></name>
565
+ <constrainedElement xmi:idref="<%= xmiid_entity %>"/>
566
+ <specification xmi:id="<%= xmiid %>-spec"<%= get_uuid(xmiid+'-spec') %> xmi:type="uml:OpaqueExpression">
567
+ <body><%= entity.name %>::allInstances()-&gt;isUnique(<%= unique_text %>)</body>
568
+ <language>OCL2.0</language>
569
+ </specification>
570
+ </ownedRule>}
571
+
572
+ # WHERE rule template
573
+ where_template = %{<ownedRule xmi:id="<%= xmiid %>"<%= get_uuid(xmiid) %> xmi:type="uml:Constraint">
574
+ <name><%= where.name %></name>
575
+ <constrainedElement xmi:idref="<%= xmiidref %>"/>
576
+ <specification xmi:id="<%= xmiid %>-spec"<%= get_uuid(xmiid+'-spec') %> xmi:type="uml:OpaqueExpression">
577
+ <body><%= where_ocl %></body>
578
+ <language>OCL2.0</language>
579
+ </specification>
580
+ </ownedRule>}
581
+
582
+ # TYPE Template
583
+ type_template = %{<packagedElement xmi:id="<%= xmiid %>"<%= get_uuid(xmiid) %> xmi:type="uml:PrimitiveType">
584
+ <name><%= type.name %></name><% if !datatype_hash[type.domain].nil? %>
585
+ <generalization xmi:id="_supertype<%= xmiid %>"<%= get_uuid('_supertype'+xmiid) %> xmi:type="uml:Generalization">
586
+ <general href="<%= datatype_hash[type.domain] %>"/>
587
+ </generalization><% else %>
588
+ <generalization xmi:id="_supertype<%= xmiid %>"<%= get_uuid('_supertype'+xmiid) %> xmi:type="uml:Generalization">
589
+ <general xmi:idref="<%= $dtprefix+xmiid_general %>"/>
590
+ </generalization>
591
+ <% end %>}
592
+
593
+ # ProxyTYPE Start Template
594
+ proxy_start_template = %{<packagedElement xmi:id="<%= xmiid %>"<%= get_uuid(xmiid) %> xmi:type="uml:Class">
595
+ <name><%= type.name %>Proxy</name>
596
+ <ownedAttribute xmi:id="<%= xmiid %>_value"<%= get_uuid(xmiid + "_value") %> xmi:type="uml:Property">
597
+ <name>value</name>
598
+ <type xmi:idref="<%= xmiid_type %>"/>
599
+ <aggregation>composite</aggregation>
600
+ </ownedAttribute><%
601
+ dummy = get_uuid(xmiid + "_value-lowerValue")
602
+ dummy = get_uuid(xmiid + "_value-upperValue")
603
+ %>}
604
+
605
+ # AggTYPE Start Template
606
+ aggtype_start_template = %{<packagedElement xmi:id="<%= xmiid %>"<%= get_uuid(xmiid) %> xmi:type="uml:Class">
607
+ <name><%= type_name %></name>}
608
+
609
+ aggtype_attribute = %{<ownedAttribute xmi:id="<%= xmiid %>"<%= get_uuid(xmiid) %> xmi:type="uml:Property">
610
+ <name>elements</name><% if islist %>
611
+ <isOrdered>true</isOrdered><% end %><% if !isset %>
612
+ <isUnique>false</isUnique><% end %><% if datatype_hash[type.domain].nil? %>
613
+ <type xmi:idref="<%= xmiid_type %>"/><% else %>
614
+ <type href="<%= datatype_hash[type.domain] %>"/><% end %><% if associationNeeded %>
615
+ <association xmi:idref="<%= assoc_xmiid %>"/><% else %>
616
+ <aggregation>composite</aggregation><% end %>}
617
+
618
+ aggtype_association = %{<packagedElement xmi:id="<%= assoc_xmiid %>"<%= get_uuid(assoc_xmiid) %> xmi:type="uml:Association">
619
+ <memberEnd xmi:idref="<%= xmiid %>"/>
620
+ <memberEnd xmi:idref="<%= assoc_xmiid + '-end' %>"/>
621
+ <ownedEnd xmi:id="<%= assoc_xmiid %>-end"<%= get_uuid(assoc_xmiid+'-end') %> xmi:type="uml:Property">
622
+ <type xmi:idref="<%= xmiid_type %>"/>
623
+ <association xmi:idref="<%= assoc_xmiid %>"/>
624
+ <lowerValue xmi:id="<%= assoc_xmiid %>-end-lowerValue"<%= get_uuid(assoc_xmiid+'-end-lowerValue') %> xmi:type="uml:LiteralInteger"/>
625
+ </ownedEnd>
626
+ </packagedElement>}
627
+
628
+ # TYPE Stereotype Template
629
+ type_stereotype_template = %{<<%= $StandardProfile %>:Type xmi:id="<%= xmiid %>"<%= get_uuid(xmiid) %>>
630
+ <base_Class xmi:idref="<%= baseClass %>"/>
631
+ </<%= $StandardProfile %>:Type>}
632
+
633
+ #TYPE end Template
634
+ type_end_template=%{</packagedElement>}
635
+
636
+ # TYPE ValueType Template
637
+ valuetype_template = %{<sysml:ValueType xmi:id="<%= xmiid %>"<%= get_uuid(xmiid) %>>
638
+ <base_DataType xmi:idref="<%= baseType %>"/>
639
+ </sysml:ValueType>}
640
+
641
+ #############################################################################################
642
+ # Set up list of schemas to process, input may be a repository containing schemas or a single schema
643
+ #############################################################################################
644
+
645
+ if mapinput.kind_of? EXPSM::Repository
646
+ schema_list = mapinput.schemas
647
+ elsif mapinput.kind_of? EXPSM::SchemaDefinition
648
+ schema_list = [mapinput]
649
+ else
650
+ puts "ERROR : map_from_express input no Repository instance or Schema instance"
651
+ exit
652
+ end
653
+
654
+ # Set up XMI output file
655
+
656
+ if schema_list.size == 1
657
+ if output_xmi_filename.nil?
658
+ schema = schema_list[0]
659
+ output_xmi_filename = schema.name.to_s + ".xmi"
660
+ end
661
+ if schemaId
662
+ get_prefix = lambda {|schema| '_' + schema.name + '-'}
663
+ else
664
+ get_prefix = lambda {|schema| '_'}
665
+ end
666
+ else
667
+ if output_xmi_filename.nil?
668
+ output_xmi_filename = 'Model.xmi'
669
+ end
670
+ get_prefix = lambda {|schema| '_' + schema.name + '-'}
671
+ end
672
+
673
+ file = File.new(output_xmi_filename, "w")
674
+ puts 'reeper : Writing output to file ' + output_xmi_filename
675
+
676
+ # Evaluate and write file start template
677
+ res = ERB.new(overall_start_template)
678
+ t = res.result(binding)
679
+ file.puts t
680
+
681
+ if dtHandle != "local"
682
+ pathElements = outPath.split('/')
683
+ relPath = "DataTypes.xmi"
684
+ for elem in pathElements
685
+ relPath = "../" + relPath
686
+ end
687
+ datatype_hash["LOGICAL"] = relPath + "#LOGICAL"
688
+ datatype_hash["BOOLEAN"] = relPath + "#BOOLEAN"
689
+ datatype_hash["NUMBER"] = relPath + "#NUMBER"
690
+ datatype_hash["REAL"] = relPath + "#REAL"
691
+ datatype_hash["INTEGER"] = relPath + "#INTEGER"
692
+ datatype_hash["STRING"] = relPath + "#STRING"
693
+ datatype_hash["BINARY"] = relPath + "#BINARY"
694
+ end
695
+
696
+ # sort out data types
697
+ if dtHandle != "ignore"
698
+ if dtHandle == "local"
699
+ dtfile = file
700
+ else
701
+ dtfile = File.new("DataTypes.xmi","w")
702
+ res = ERB.new(overall_start_template)
703
+ t = res.result(binding)
704
+ dtfile.puts t
705
+ if $uuidsRequired
706
+ uuidSafe = $uuidxml
707
+ uuidOldSafe = $olduuids
708
+ if File.exists?("DataTypes_UUIDs.xml")
709
+ uuidfile = File.open("DataTypes_UUIDs.xml")
710
+ $uuidxml = Nokogiri::XML(uuidfile, &:noblanks)
711
+ uuidfile.close
712
+ else
713
+ $uuidxml = Nokogiri::XML::Builder.new { |b| b.uuids }.doc
714
+ end
715
+ $olduuids = $uuidxml.xpath('//uuidmap')
716
+ end
717
+ xmiid = "_0_" + $dtprefix + "DataTypes"
718
+ dtfile.puts '<uml:Package xmi:id="'+ xmiid +'"' + get_uuid(xmiid) +' xmi:type="uml:Package">'
719
+ dtfile.puts '<name>DataTypes</name>'
720
+ res = ERB.new(apply_sysml)
721
+ t = res.result(binding)
722
+ dtfile.puts t
723
+ end
724
+ res = ERB.new(data_types)
725
+ t = res.result(binding)
726
+ dtfile.puts t
727
+ if dtHandle == "export"
728
+ dtfile.puts '</uml:Package>'
729
+ end
730
+ if !uuidSafe.nil?
731
+ tmp = uuidSafe
732
+ uuidSafe = $uuidxml
733
+ $uuidxml = tmp
734
+ tmp = uuidOldSafe
735
+ uuidOldSafe = $olduuids
736
+ $olduuids = tmp
737
+ end
738
+ end
739
+
740
+ # Set up list of all EXPRESS Inverses in all schemas
741
+ all_inverse_list = []
742
+ direct_inverses = []
743
+ # Set up list of all EXPRESS Selects in all schemas
744
+ all_select_list = []
745
+ renamed_select_list = []
746
+ # setup global proxy type handling
747
+ typeProxies = Hash.new
748
+
749
+ # build all_select_list
750
+ for schema in schema_list
751
+ select_list = schema.contents.find_all{ |e| e.instance_of? EXPSM::TypeSelect }
752
+ all_select_list = all_select_list + select_list
753
+ type_list = schema.contents.find_all{ |e| e.instance_of? EXPSM::Type and !e.isBuiltin}
754
+ for type in type_list
755
+ superselect = NamedType.find_by_name( type.domain )
756
+ while (superselect.instance_of? EXPSM::Type and !superselect.isBuiltin)
757
+ superselect = NamedType.find_by_name(superselect.domain)
758
+ end
759
+ if superselect.kind_of? EXPSM::TypeSelect
760
+ renamed_select_list << type
761
+ end
762
+ end
763
+ end
764
+
765
+ # Set up storage for handling Aggregate and Select Types correctly
766
+ aggTypes = Hash.new
767
+ specialSelects = Hash.new
768
+
769
+ # determine Aggregate and Select types needing special consideration
770
+ for schema in schema_list
771
+ entity_list = schema.contents.find_all{ |e| e.kind_of? EXPSM::Entity }
772
+ for entity in entity_list
773
+ attr_list = entity.attributes.find_all{ |e| e.kind_of? EXPSM::Explicit }
774
+ for attr in attr_list
775
+ if attr.instance_of? EXPSM::ExplicitAggregate
776
+ orig_domain = NamedType.find_by_name( attr.domain )
777
+ if orig_domain.class.to_s == "EXPSM::TypeAggregate"
778
+ if aggTypes[attr.domain].nil?
779
+ aggTypes[attr.domain] = orig_domain
780
+ end
781
+ end
782
+ end
783
+ if attr.redeclare_entity
784
+ attr_domain = NamedType.find_by_name(attr.domain)
785
+ if attr_domain.instance_of? EXPSM::TypeSelect
786
+ supertype = NamedType.find_by_name( attr.redeclare_entity )
787
+ if attr.redeclare_oldname
788
+ redeclOf = supertype.find_attr_by_name( attr.redeclare_oldname )
789
+ else
790
+ redeclOf = supertype.find_attr_by_name( attr.name )
791
+ end
792
+ redecl_domain = NamedType.find_by_name( redeclOf.domain )
793
+ case redecl_domain.class.to_s
794
+ when 'EXPSM::Entity', 'EXPSM::TypeSelect'
795
+ if specialSelects[attr.domain].nil?
796
+ specialSelects[attr.domain] = [redecl_domain]
797
+ else
798
+ if !specialSelects[attr.domain].include?(redecl_domain)
799
+ specialSelects[attr.domain].push(redecl_domain)
800
+ end
801
+ end
802
+ end
803
+ end
804
+ end
805
+ end
806
+ end
807
+ end
808
+
809
+ # Set up storage for handling select types correctly
810
+ selectTypeType = Hash.new
811
+
812
+ # determine the type of select
813
+ # - entity if only contains entities
814
+ # - type if only contains types
815
+ # - hybrid if a mixture
816
+ # - remove if a single object in list
817
+ unknownSelect = all_select_list.dup
818
+ for select in unknownSelect
819
+ if (select.selectitems_array.size == 1 && !noprune)
820
+ if !select.selectitems_array[0].kind_of? EXPSM::TypeSelect
821
+ puts select.name + " is pruned since it only contains one element"
822
+ selectTypeType[select.name] = "Remove"
823
+ end
824
+ end
825
+ entcount = 0
826
+ typcount = 0
827
+ select.selectitems_array.each do |e|
828
+ case e.class.to_s
829
+ when "EXPSM::Entity" then entcount += 1
830
+ when "EXPSM::Type" then typcount += 1
831
+ when "EXPSM::TypeEnum" then typcount += 1
832
+ when "EXPSM::TypeAggregate"
833
+ if selectTypeType[select.name] != "Remove"
834
+ entcount += 1
835
+ if aggTypes[e.name].nil?
836
+ aggTypes[e.name] = e
837
+ end
838
+ end
839
+ when "EXPSM::TypeSelect"
840
+ case selectTypeType[e.name]
841
+ when "Entity" then entcount += 1
842
+ when "Type" then typcount += 1
843
+ when "Hybrid" then selectTypeType[select.name] = "Hybrid"
844
+ when "Remove"
845
+ case e.selectitems_array[0].class.to_s
846
+ when "EXPSM::Entity" then entcount += 1
847
+ when "EXPSM::Type" then typcount += 1
848
+ end
849
+ end
850
+ else
851
+ puts "unknown class " + e.class.to_s + " for " + select.name
852
+ end
853
+ end
854
+
855
+ if selectTypeType[select.name].nil?
856
+ case select.selectitems_array.size
857
+ when entcount then selectTypeType[select.name] = "Entity"
858
+ when typcount then selectTypeType[select.name] = "Type"
859
+ else
860
+ if (entcount > 0) && (typcount > 0)
861
+ selectTypeType[select.name] = "Hybrid"
862
+ else
863
+ unknownSelect.push select
864
+ end
865
+ end
866
+ end
867
+ if selectTypeType[select.name] == "Hybrid"
868
+ puts select.name + " is Hybrid select - proxy block(s) generated."
869
+ end
870
+ end
871
+
872
+ # process subsetted select types
873
+ selectSubset = Hash.new
874
+ selectSubs = Hash.new
875
+ for select in renamed_select_list
876
+ superselect = NamedType.find_by_name( select.domain )
877
+ if superselect.kind_of? EXPSM::TypeSelect
878
+ temp = []
879
+ superselect.selectitems_array.each{|e|
880
+ if e.kind_of? EXPSM::TypeSelect
881
+ e.selectitems_array.each{|inner|
882
+ if inner.kind_of? EXPSM::TypeSelect
883
+ puts "select of select select for " + superselect.name
884
+ else
885
+ temp << inner.name
886
+ end}
887
+ else
888
+ temp << e.name
889
+ end}
890
+ if selectSubset[superselect.name].nil?
891
+ selectSubset[superselect.name] = temp.dup
892
+ end
893
+ select.wheres.each{|rule| ruleString = rule.expression.upcase
894
+ if ruleString[0..5] == "NOT ('"
895
+ startPos = ruleString.index('.',6) + 1
896
+ endPos = ruleString.index("'",startPos) - 1
897
+ removeName = ruleString[startPos..endPos]
898
+ temp.reject!{|e| e.upcase == removeName}
899
+ else
900
+ puts "Unexpected expression: " + rule.expression
901
+ end
902
+ }
903
+ selectSubset[select.name] = temp
904
+ selectSubset[superselect.name] = selectSubset[superselect.name] - temp
905
+ if selectSubs[superselect.name].nil?
906
+ selectSubs[superselect.name] = [select.name]
907
+ else
908
+ selectSubs[superselect.name] << select.name
909
+ end
910
+ selectTypeType[select.name] = selectTypeType[superselect.name]
911
+ else
912
+ puts "ERROR: Unhandled select subset for " + superselect.name
913
+ end
914
+ end
915
+
916
+ if schema_list.size > 1
917
+ res = ERB.new(package_start)
918
+ t = res.result(binding)
919
+ file.puts t
920
+
921
+ #Apply sysml profile
922
+ res = ERB.new(apply_sysml)
923
+ t = res.result(binding)
924
+ file.puts t
925
+ end
926
+
927
+ for schema in schema_list
928
+ # Set up storage for handling nested Aggregates correctly
929
+ nestedAggs = Hash.new
930
+ nestedTypes = Hash.new
931
+ prefix = get_prefix.call(schema)
932
+
933
+ entity_list = schema.contents.find_all{ |e| e.kind_of? EXPSM::Entity }
934
+ for entity in entity_list
935
+ entity_inverse_list = entity.attributes.find_all{ |e| e.kind_of? EXPSM::Inverse }
936
+ for inverse in entity_inverse_list
937
+ all_inverse_list.push inverse
938
+ end
939
+ end
940
+
941
+ # Evaluate and write schema start template
942
+ xmiid = '_1_' + schema.name
943
+ res = ERB.new(schema_start_template)
944
+ t = res.result(binding)
945
+ file.puts t
946
+
947
+ if schema_list.size == 1
948
+ #Apply sysml profile
949
+ res = ERB.new(apply_sysml)
950
+ t = res.result(binding)
951
+ file.puts t
952
+ end
953
+
954
+ interfaced_schema_list = schema.contents.find_all{ |e| e.instance_of? EXPSM::InterfaceSpecification}
955
+ for interfaced_schema in interfaced_schema_list
956
+ # Evaluate and write schema interface template
957
+ xmiid = '_2_' + schema.name + '-' + interfaced_schema.foreign_schema_id
958
+ res = ERB.new(schema_interface_template)
959
+ t = res.result(binding)
960
+ file.puts t
961
+ end
962
+
963
+ # Map EXPRESS TYPE of Builtin
964
+ type_list = schema.contents.find_all{ |e| e.instance_of? EXPSM::Type and e.isBuiltin}
965
+ for type in type_list
966
+ xmiid = prefix + type.name
967
+ xmiid_type = xmiid
968
+ xmiid_general = type.domain
969
+ if ["BOOLEAN", "LOGICAL"].include?(type.domain)
970
+ enum = type
971
+ general = type.domain
972
+ gen_xmiid = '_supertype' + xmiid
973
+ res = ERB.new(enum_start_template)
974
+ t = res.result(binding)
975
+ file.puts t
976
+ else
977
+ res = ERB.new(type_template)
978
+ t = res.result(binding)
979
+ file.puts t
980
+ end
981
+
982
+ # Map TYPE Select has Type as item
983
+ for select in type.selectedBy
984
+ # sort out what type of select we are dealing with
985
+ case selectTypeType[select.name]
986
+ when "Type"
987
+ superName = select.name
988
+ subset = selectSubset[superName]
989
+ if !subset.nil?
990
+ if !subset.include?(type.name)
991
+ selectSubs[superName].each{|e|
992
+ if selectSubset[e].include?(type.name)
993
+ superName = e
994
+ end}
995
+ end
996
+ end
997
+ xmiid = '_2_selectitem' + prefix + type.name + '-' + superName
998
+ xmiid_general = prefix + superName
999
+ res = ERB.new(supertype_template)
1000
+ t = res.result(binding)
1001
+ file.puts t
1002
+ when "Hybrid"
1003
+ typeProxy = typeProxies[type.name]
1004
+ if typeProxy.nil?
1005
+ typeProxies[type.name] = type
1006
+ end
1007
+ when "Remove"
1008
+ # do nothing
1009
+ end
1010
+ end
1011
+
1012
+ # Map EXPRESS Where rules
1013
+ whererules = type.wheres.select {|w| w.name[0..10] != "encapsulate"}
1014
+ if whererules.size > 0
1015
+ for where in whererules
1016
+ xmiid = '_3_whr' + prefix + type.name + '-' + where.name.to_s
1017
+ where_ocl = get_where(xmiid, where.expression)
1018
+ if where_ocl.size > 0
1019
+ xmiidref = xmiid_type
1020
+ res = ERB.new(where_template)
1021
+ t = res.result(binding)
1022
+ file.puts t
1023
+ else
1024
+ puts "Where rule " + type.name + "." + where.name + " not mapped to OCL - ignored!"
1025
+ end
1026
+ end
1027
+ end
1028
+
1029
+ put_ops(type.name, file)
1030
+
1031
+ res = ERB.new(type_end_template)
1032
+ t = res.result(binding)
1033
+ file.puts t
1034
+ end
1035
+
1036
+ # Map EXPRESS TYPE of TYPE
1037
+ type_list = schema.contents.find_all{ |e| e.instance_of? EXPSM::Type and !e.isBuiltin}
1038
+ for type in type_list
1039
+ domain = NamedType.find_by_name( type.domain )
1040
+ xmiid = prefix + type.name
1041
+ xmiid_type = xmiid
1042
+ # deal with special cases
1043
+ case domain.class.to_s
1044
+ when "EXPSM::TypeSelect"
1045
+ res = ERB.new(select_start_template)
1046
+ t = res.result(binding)
1047
+ file.puts t
1048
+
1049
+ xmiid = '_2_superselect' + prefix + type.name + '-' + type.domain
1050
+ xmiid_general = prefix + type.domain
1051
+ res = ERB.new(supertype_template)
1052
+ t = res.result(binding)
1053
+ file.puts t
1054
+
1055
+ when "EXPSM::TypeEnum"
1056
+ enum = type
1057
+ gen_xmiid = '_2_superenum' + prefix + type.name + '-' + type.domain
1058
+ xmiid_general = prefix + type.domain
1059
+ general = type.domain
1060
+ res = ERB.new(enum_start_template)
1061
+ t = res.result(binding)
1062
+ file.puts t
1063
+
1064
+ else
1065
+ xmiid_general = prefix + type.domain
1066
+ res = ERB.new(type_template)
1067
+ t = res.result(binding)
1068
+ file.puts t
1069
+ end
1070
+
1071
+ # Map TYPE Select has Type as item
1072
+ if selectTypeType[type.name] == "Type"
1073
+ for select in type.selectedBy
1074
+ case selectTypeType[select.name]
1075
+ when "Type"
1076
+ superName = select.name
1077
+ subset = selectSubset[superName]
1078
+ if !subset.nil?
1079
+ if !subset.include?(type.name)
1080
+ selectSubs[superName].each{|e|
1081
+ if selectSubset[e].include?(type.name)
1082
+ superName = e
1083
+ end}
1084
+ end
1085
+ end
1086
+ xmiid = '_2_selectitem' + prefix + type.name + '-' + superName
1087
+ xmiid_general = prefix + superName
1088
+ res = ERB.new(supertype_template)
1089
+ t = res.result(binding)
1090
+ file.puts t
1091
+ when "Hybrid"
1092
+ typeProxy = typeProxies[type.name]
1093
+ if typeProxy.nil?
1094
+ typeProxies[type.name] = type
1095
+ end
1096
+ when "Remove"
1097
+ # do nothing
1098
+ end
1099
+ end
1100
+ else
1101
+ for select in type.selectedBy
1102
+ if selectTypeType[select.name] != "Remove"
1103
+ superName = select.name
1104
+ subset = selectSubset[superName]
1105
+ if !subset.nil?
1106
+ if !subset.include?(type.name)
1107
+ selectSubs[superName].each{|e|
1108
+ if selectSubset[e].include?(type.name)
1109
+ superName = e
1110
+ end}
1111
+ end
1112
+ end
1113
+ xmiid = '_2_selectitem' + prefix + type.name + '-' + superName
1114
+ xmiid_general = prefix + superName
1115
+ res = ERB.new(supertype_template)
1116
+ t = res.result(binding)
1117
+ file.puts t
1118
+ end
1119
+ end
1120
+ end
1121
+
1122
+ case domain.class.to_s
1123
+ when "EXPSM::TypeSelect"
1124
+ when "EXPSM::TypeEnum"
1125
+ #Map EXPRESS Where rules
1126
+ whererules = type.wheres.select {|w| w.name[0..10] != "encapsulate"}
1127
+ if whererules.size > 0
1128
+ for where in whererules
1129
+ xmiid = '_3_whr' + prefix + type.name + '-' + where.name.to_s
1130
+ where_ocl = where.expression.gsub("<>", "&lt;&gt;")
1131
+ xmiidref = xmiid_type
1132
+ res = ERB.new(where_template)
1133
+ t = res.result(binding)
1134
+ file.puts t
1135
+ end
1136
+ end
1137
+ else
1138
+ #Map EXPRESS Where rules
1139
+ whererules = type.wheres.select {|w| w.name[0..10] != "encapsulate"}
1140
+ if whererules.size > 0
1141
+ for where in whererules
1142
+ xmiid = '_3_whr' + prefix + type.name + '-' + where.name.to_s
1143
+ where_ocl = get_where(xmiid, where.expression)
1144
+ if where_ocl.size > 0
1145
+ xmiidref = xmiid_type
1146
+ res = ERB.new(where_template)
1147
+ t = res.result(binding)
1148
+ file.puts t
1149
+ else
1150
+ puts "Where rule " + type.name + "." + where.name + " not mapped to OCL - ignored!"
1151
+ end
1152
+ end
1153
+ end
1154
+
1155
+ put_ops(type.name, file)
1156
+ end
1157
+
1158
+ res = ERB.new(type_end_template)
1159
+ t = res.result(binding)
1160
+ file.puts t
1161
+ end
1162
+
1163
+ aggTypes.each_value do |type|
1164
+ if type.schema == schema
1165
+ # Evaluate and write aggType start template
1166
+ # initialize default cardinailty constraints
1167
+ isset = true
1168
+ islist = false
1169
+
1170
+ upper = type.dimensions[0].upper
1171
+ if upper == '?'
1172
+ upper = '*'
1173
+ end
1174
+ lower = type.dimensions[0].lower
1175
+ if type.dimensions[0].aggrtype == 'ARRAY'
1176
+ puts 'Warning ARRAY not fully supported for '+type.name
1177
+ upper = (upper.to_i - lower.to_i + 1).to_s
1178
+ lower = upper
1179
+ end
1180
+ if type.dimensions[0].aggrtype == 'LIST'
1181
+ islist = true
1182
+ end
1183
+ if type.dimensions[0].aggrtype == 'BAG'
1184
+ isset = false
1185
+ end
1186
+ if type.dimensions[0].aggrtype == 'LIST' and !type.dimensions[0].isUnique
1187
+ isset = false
1188
+ end
1189
+
1190
+ xmiid = prefix + type.name
1191
+ associationNeeded = false
1192
+ if type.isBuiltin
1193
+ xmiid_type = $dtprefix + type.domain
1194
+ else
1195
+ xmiid_type = prefix + type.domain
1196
+
1197
+ domain = NamedType.find_by_name( type.domain )
1198
+ case domain.class.to_s
1199
+ when "EXPSM::Entity"
1200
+ associationNeeded = true
1201
+ when "EXPSM::Type"
1202
+ case selectTypeType[type.domain]
1203
+ when "Entity", "Hybrid"
1204
+ associationNeeded = true
1205
+ end
1206
+ when "EXPSM::TypeAggregate"
1207
+ if !aggTypes[type.domain].nil?
1208
+ associationNeeded = true
1209
+ end
1210
+ when "EXPSM::TypeSelect"
1211
+ case selectTypeType[type.domain]
1212
+ when "Entity", "Hybrid"
1213
+ associationNeeded = true
1214
+ end
1215
+ end
1216
+ end
1217
+
1218
+ type_name = type.name
1219
+ res = ERB.new(aggtype_start_template)
1220
+ t = res.result(binding)
1221
+ file.puts t
1222
+
1223
+ # Map TYPE Select has Entity as item
1224
+ for select in type.selectedBy
1225
+ superName = select.name
1226
+ subset = selectSubset[superName]
1227
+ if !subset.nil?
1228
+ if !subset.include?(type.name)
1229
+ selectSubs[superName].each{|e|
1230
+ if selectSubset[e].include?(type.name)
1231
+ superName = e
1232
+ end}
1233
+ end
1234
+ end
1235
+ xmiid = '_2_selectitem' + prefix + type.name + '-' + superName
1236
+ xmiid_general = prefix + superName
1237
+ res = ERB.new(supertype_template)
1238
+ t = res.result(binding)
1239
+ file.puts t
1240
+ end
1241
+
1242
+ if associationNeeded
1243
+ assoc_xmiid = '_1_association' + prefix + type.name + '-elements'
1244
+ end
1245
+
1246
+ xmiid = '_2_attr' + prefix + type.name + "-elements"
1247
+ res = ERB.new(aggtype_attribute)
1248
+ t = res.result(binding)
1249
+ file.puts t
1250
+
1251
+ res = ERB.new(multiplicity,0,"<>")
1252
+ t = res.result(binding)
1253
+ if !t.nil? && t.size>0
1254
+ file.puts t
1255
+ end
1256
+
1257
+ res = ERB.new(attribute_end)
1258
+ t = res.result(binding)
1259
+ file.puts t
1260
+
1261
+ res = ERB.new(type_end_template)
1262
+ t = res.result(binding)
1263
+ file.puts t
1264
+
1265
+ if associationNeeded
1266
+ res = ERB.new(aggtype_association)
1267
+ t = res.result(binding)
1268
+ file.puts t
1269
+ end
1270
+ end
1271
+ end
1272
+
1273
+ # Map EXPRESS Enumeration Types
1274
+ enum_list = schema.contents.find_all{ |e| e.instance_of? EXPSM::TypeEnum }
1275
+ for enum in enum_list
1276
+
1277
+ superenum = enum.extends_item
1278
+ general = nil
1279
+ if !superenum.nil?
1280
+ if superenum.kind_of? EXPSM::TypeEnum
1281
+ # Write Enum Item template for parent (maps to UML same as EXPRESS supertype)
1282
+ gen_xmiid = '_2_superenum' + prefix + enum.name + '-' + superenum.name
1283
+ xmiid_general = get_prefix.call(superenum.schema) + superenum.name
1284
+ general = superenum.name
1285
+ end
1286
+ end
1287
+ # Evaluate and write TYPE Enum start template
1288
+ xmiid = prefix + enum.name
1289
+ res = ERB.new(enum_start_template)
1290
+ t = res.result(binding)
1291
+ file.puts t
1292
+
1293
+ # Map TYPE Select has Enum as item
1294
+ for select in enum.selectedBy
1295
+ # sort out what type of select we are dealing with
1296
+ case selectTypeType[select.name]
1297
+ when "Type"
1298
+ superName = select.name
1299
+ subset = selectSubset[superName]
1300
+ if !subset.nil?
1301
+ if !subset.include?(enum.name)
1302
+ selectSubs[superName].each{|e|
1303
+ if selectSubset[e].include?(enum.name)
1304
+ superName = e
1305
+ end}
1306
+ end
1307
+ end
1308
+ xmiid = '_2_selectitem' + prefix + enum.name + '-' + superName
1309
+ xmiid_general = prefix + superName
1310
+ res = ERB.new(supertype_template)
1311
+ t = res.result(binding)
1312
+ file.puts t
1313
+ when "Hybrid"
1314
+ typeProxy = typeProxies[enum.name]
1315
+ if typeProxy.nil?
1316
+ typeProxies[enum.name] = enum
1317
+ end
1318
+ when "Remove"
1319
+ # do nothing
1320
+ end
1321
+ end
1322
+
1323
+ # Evaluate and write Enum Item template for each item
1324
+ enumitem_name_list = enum.items.scan(/\w+/)
1325
+ for enumitem in enumitem_name_list
1326
+ enumitem_xmiid = '_1_enumitem' + prefix + enum.name + '-' + enumitem
1327
+ res = ERB.new(enum_item_template)
1328
+ t = res.result(binding)
1329
+ file.puts t
1330
+ end
1331
+
1332
+ # Evaluate and write TYPE Enum end template
1333
+ res = ERB.new(enum_end_template)
1334
+ t = res.result(binding)
1335
+ file.puts t
1336
+ end
1337
+
1338
+ # Map EXPRESS TYPE Selects
1339
+ select_list = schema.contents.find_all{ |e| e.instance_of? EXPSM::TypeSelect }
1340
+ for type in select_list
1341
+ if selectTypeType[type.name] != "Remove"
1342
+ # Evaluate and write TYPE Select start template
1343
+ xmiid = prefix + type.name
1344
+ res = ERB.new(select_start_template)
1345
+ t = res.result(binding)
1346
+ file.puts t
1347
+
1348
+ # Deal with ad-hoc subtype constraints on entities
1349
+ superentities = specialSelects[type.name]
1350
+ if !superentities.nil?
1351
+ superentities.each {|superentity|
1352
+ xmiid = '_2_superentity' + prefix + type.name + '-' + superentity.name
1353
+ xmiid_general = get_prefix.call(superentity.schema) + superentity.name
1354
+ res = ERB.new(supertype_template)
1355
+ t = res.result(binding)
1356
+ file.puts t}
1357
+ end
1358
+
1359
+ superselect = type.extends_item
1360
+ if !superselect.nil?
1361
+ if superselect.kind_of? EXPSM::TypeSelect
1362
+ if !superentities.include?(superselect)
1363
+ # Write Select Item template for parent (maps to UML same as EXPRESS supertype)
1364
+ xmiid = '_2_superselect' + prefix + type.name + '-' + superselect.name
1365
+ xmiid_general = get_prefix.call(superselect.schema) + superselect.name
1366
+ res = ERB.new(supertype_template)
1367
+ t = res.result(binding)
1368
+ file.puts t
1369
+ end
1370
+ end
1371
+ end
1372
+
1373
+ # Evaluate and write Select Item template for each item (maps to UML same as EXPRESS supertype)
1374
+ if selectTypeType[type.name] == "Type"
1375
+ for superselect in type.selectedBy
1376
+ case selectTypeType[superselect.name]
1377
+ when "Hybrid"
1378
+ typeProxy = typeProxies[type.name]
1379
+ if typeProxy.nil?
1380
+ typeProxies[type.name] = type
1381
+ end
1382
+ when "Remove"
1383
+ # do nothing
1384
+ else
1385
+ superName = superselect.name
1386
+ subset = selectSubset[superselect.name]
1387
+ if !subset.nil?
1388
+ if !subset.include?(type.name)
1389
+ selectSubs[superselect.name].each{|e|
1390
+ if selectSubset[e].include?(type.name)
1391
+ superName = e
1392
+ end}
1393
+ end
1394
+ end
1395
+ if superentities.nil? || superentities.all?{|superentity| superentity.name != superName}
1396
+ xmiid = '_2_selectitem' + prefix + type.name + '-' + superName
1397
+ xmiid_general = prefix + superName
1398
+ res = ERB.new(supertype_template)
1399
+ t = res.result(binding)
1400
+ file.puts t
1401
+ end
1402
+ end
1403
+ end
1404
+ else
1405
+ for superselect in type.selectedBy
1406
+ if selectTypeType[superselect.name] !="Remove"
1407
+ superName = superselect.name
1408
+ subset = selectSubset[superselect.name]
1409
+ if !subset.nil?
1410
+ if !subset.include?(type.name)
1411
+ selectSubs[superselect.name].each{|e|
1412
+ if selectSubset[e].include?(type.name)
1413
+ superName = e
1414
+ end}
1415
+ end
1416
+ end
1417
+ if superentities.nil? || superentities.all?{|superentity| superentity.name != superName}
1418
+ xmiid = '_2_selectitem' + prefix + type.name + '-' + superName
1419
+ xmiid_general = prefix + superName
1420
+ res = ERB.new(supertype_template)
1421
+ t = res.result(binding)
1422
+ file.puts t
1423
+ end
1424
+ end
1425
+ end
1426
+ end
1427
+
1428
+ # Evaluate and write TYPE Select end template
1429
+ res = ERB.new(select_end_template)
1430
+ t = res.result(binding)
1431
+ file.puts t
1432
+ end
1433
+ end
1434
+
1435
+ typeProxies.each_value do |type|
1436
+ if type.schema == schema
1437
+ # Evaluate and write proxy start template
1438
+ xmiid_type = prefix + type.name
1439
+ xmiid = xmiid_type + "_Proxy"
1440
+ res = ERB.new(proxy_start_template)
1441
+ t = res.result(binding)
1442
+ file.puts t
1443
+
1444
+ # Map TYPE Select has Entity as item
1445
+ for select in type.selectedBy
1446
+ if selectTypeType[select.name] == "Hybrid"
1447
+ superName = select.name
1448
+ subset = selectSubset[superName]
1449
+ if !subset.nil?
1450
+ if !subset.include?(type.name)
1451
+ selectSubs[superName].each{|e|
1452
+ if selectSubset[e].include?(type.name)
1453
+ superName = e
1454
+ end}
1455
+ end
1456
+ end
1457
+ xmiid = '_2_selectitem' + prefix + type.name + '-' + superName
1458
+ xmiid_general = prefix + superName
1459
+ res = ERB.new(supertype_template)
1460
+ t = res.result(binding)
1461
+ file.puts t
1462
+ end
1463
+ end
1464
+
1465
+ res = ERB.new(type_end_template)
1466
+ t = res.result(binding)
1467
+ file.puts t
1468
+ end
1469
+ end
1470
+
1471
+ entity_list = schema.contents.find_all{ |e| e.kind_of? EXPSM::Entity }
1472
+
1473
+ # Map EXPRESS Explicit Attribute resulting UML Association (the Association is referenced from Class resulting from Entity)
1474
+ for entity in entity_list
1475
+ attr_list = entity.attributes.find_all{ |e| e.kind_of? EXPSM::Explicit }
1476
+ for attr in attr_list
1477
+
1478
+ domain_name = attr.domain
1479
+ orig_domain = NamedType.find_by_name(domain_name)
1480
+ attr_domain = orig_domain
1481
+ agg_domain = nil
1482
+ attrType = nil
1483
+ associationNeeded = false
1484
+ begin
1485
+ unchanged = true
1486
+ case attr_domain.class.to_s
1487
+ when "EXPSM::Entity"
1488
+ associationNeeded = true
1489
+ when "EXPSM::Type"
1490
+ case selectTypeType[domain_name]
1491
+ when "Entity", "Hybrid"
1492
+ associationNeeded = true
1493
+ end
1494
+ #ignore unhandled named aggregations
1495
+ when "EXPSM::TypeAggregate"
1496
+ if aggTypes[domain_name].nil?
1497
+ attrType = attr_domain
1498
+ agg_domain = attr_domain
1499
+ if attr_domain.isBuiltin
1500
+ domain_name = attr_domain.domain
1501
+ attr_domain = nil
1502
+ else
1503
+ domain_name = attr_domain.domain
1504
+ attr_domain = NamedType.find_by_name(domain_name)
1505
+ unchanged = false
1506
+ end
1507
+ else
1508
+ associationNeeded = true
1509
+ end
1510
+ when "EXPSM::TypeSelect"
1511
+ case selectTypeType[domain_name]
1512
+ when "Entity", "Hybrid"
1513
+ associationNeeded = true
1514
+ # ignore removed select types
1515
+ when "Remove"
1516
+ attr_domain = attr_domain.selectitems_array[0]
1517
+ domain_name = attr_domain.name
1518
+ unchanged = false
1519
+ end
1520
+ end
1521
+ end until unchanged
1522
+
1523
+ if attr.instance_of? EXPSM::ExplicitAggregate
1524
+ attrType = attr
1525
+ end
1526
+
1527
+ if !attrType.nil?
1528
+ if attrType.rank > 1
1529
+ associationNeeded = true
1530
+ for i in 2..attrType.rank
1531
+ domain_name = attrType.dimensions[i-1].aggrtype+domain_name
1532
+ end
1533
+ end
1534
+ end
1535
+
1536
+ if associationNeeded
1537
+ xmiid = '_1_association' + prefix + entity.name + '-' + attr.name
1538
+ attr_xmiid = '_2_attr' + prefix + entity.name + '-' + attr.name
1539
+ owner_xmiid = prefix + entity.name
1540
+ if attr_domain.nil?
1541
+ domain_xmiid = prefix + domain_name
1542
+ else
1543
+ domain_xmiid = get_prefix.call(attr_domain.schema) + attr_domain.name
1544
+ end
1545
+
1546
+ general_exists = false
1547
+ if attr.redeclare_entity
1548
+ general_exists = true
1549
+ redeclare_entity = NamedType.find_by_name( attr.redeclare_entity )
1550
+ general_xmiid = '_2_general' + prefix + entity.name + '-' + attr.name
1551
+ if attr.redeclare_oldname
1552
+ redefined_xmiid = '_1_association' + get_prefix.call(redeclare_entity.schema) + attr.redeclare_entity + '-' + attr.redeclare_oldname
1553
+ else
1554
+ redefined_xmiid = '_1_association' + get_prefix.call(redeclare_entity.schema) + attr.redeclare_entity + '-' + attr.name
1555
+ end
1556
+ end
1557
+
1558
+ # check if inverse refers to this attribute, affects how association is written
1559
+ inverse_exists = false
1560
+ direct_inverse = false
1561
+ for inverse in all_inverse_list
1562
+ if inverse.reverseAttr == attr
1563
+ if attr.domain == inverse.entity.name
1564
+ iattr_xmiid = '_2_attr' + get_prefix.call(inverse.entity.schema) + inverse.entity.name + '-' + inverse.name
1565
+ direct_inverses.push inverse
1566
+ all_inverse_list.delete inverse
1567
+ if !inverse.instance_of? EXPSM::InverseAggregate
1568
+ direct_inverse = true
1569
+ end
1570
+ inverse_exists = true
1571
+ end
1572
+ end
1573
+ end
1574
+
1575
+ encapsulated = false
1576
+ if !attr_domain.nil?
1577
+ if attr_domain == orig_domain
1578
+ encapsulated = isEncapsulated(attr_domain, attr)
1579
+ else
1580
+ if !agg_domain.nil?
1581
+ encapsulated = isEncapsulated(agg_domain, attr)
1582
+ end
1583
+ if !encapsulated
1584
+ encapsulated = isEncapsulated(attr_domain, attr)
1585
+ if !encapsulated
1586
+ encapsulated = isEncapsulated(orig_domain, attr)
1587
+ end
1588
+ end
1589
+ end
1590
+ end
1591
+
1592
+ encapsulatedInto = false
1593
+ if !inverse_exists
1594
+ encapsulatedInto = isEncapsulatedInto(entity, entity, attr)
1595
+ end
1596
+
1597
+ res = ERB.new(attribute_entity_association_template)
1598
+ t = res.result(binding)
1599
+ file.puts t
1600
+ end
1601
+ end
1602
+ end
1603
+
1604
+ # Map EXPRESS Inverse Attribute resulting UML Association (the Association is referenced from Class resulting from Entity)
1605
+ for inverse in all_inverse_list
1606
+ if inverse.entity.schema == schema
1607
+ temp_id = get_prefix.call(inverse.entity.schema) + inverse.entity.name + '-' + inverse.name
1608
+ xmiid = '_1_association' + temp_id
1609
+ owner_xmiid = get_prefix.call(inverse.entity.schema) + inverse.entity.name
1610
+ iattr_xmiid = '_2_attr' + temp_id
1611
+
1612
+ general_xmiid = '_2_general' + temp_id
1613
+ redefined_xmiid = '_1_association' + get_prefix.call(inverse.reverseAttr.entity.schema) + inverse.reverseAttr.entity.name + '-' + inverse.reverseAttr_id
1614
+
1615
+ lower = '1'
1616
+ upper = '1'
1617
+ if inverse.reverseAttr.instance_of? EXPSM::ExplicitAggregate
1618
+ if inverse.reverseAttr.rank == 1
1619
+ upper = inverse.reverseAttr.dimensions[0].upper
1620
+ if upper == '?'
1621
+ upper = '*'
1622
+ end
1623
+ lower = inverse.reverseAttr.dimensions[0].lower
1624
+ end
1625
+ end
1626
+ if inverse.reverseAttr.isOptional
1627
+ lower = '0'
1628
+ end
1629
+ res = ERB.new(inverse_entity_association_template)
1630
+ t = res.result(binding)
1631
+ file.puts t
1632
+
1633
+ res = ERB.new(multiplicity,0,"<>")
1634
+ t = res.result(binding)
1635
+ if !t.nil? && t.size>0
1636
+ file.puts t
1637
+ end
1638
+
1639
+ res = ERB.new(inverse_entity_association_end)
1640
+ t = res.result(binding)
1641
+ file.puts t
1642
+ end
1643
+ end
1644
+
1645
+ # Map EXPRESS Entity Types
1646
+ for entity in entity_list
1647
+ lowBounds = Hash.new
1648
+
1649
+ # Evaluate and write ENTITY start template
1650
+ xmiid = prefix + entity.name
1651
+ xmiid_entity = xmiid
1652
+ res = ERB.new(entity_start_template)
1653
+ t = res.result(binding)
1654
+ file.puts t
1655
+
1656
+
1657
+ # Map Entity is SUBTYPE OF (i.e. list of supertypes)
1658
+ for supertype in entity.supertypes_array
1659
+ xmiid = '_2_supertype' + prefix + entity.name + '-' + supertype.name
1660
+ xmiid_general = get_prefix.call(supertype.schema) + supertype.name
1661
+ res = ERB.new(supertype_template)
1662
+ t = res.result(binding)
1663
+ file.puts t
1664
+ end
1665
+
1666
+ # Map TYPE Select has Entity as item
1667
+ for select in entity.selectedBy
1668
+ if selectTypeType[select.name] != "Remove"
1669
+ superName = select.name
1670
+ subset = selectSubset[superName]
1671
+ if !subset.nil?
1672
+ if !subset.include?(entity.name)
1673
+ selectSubs[superName].each{|e|
1674
+ if selectSubset[e].include?(entity.name)
1675
+ superName = e
1676
+ end}
1677
+ end
1678
+ end
1679
+ xmiid = '_2_selectitem' + prefix + entity.name + '-' + superName
1680
+ xmiid_general = prefix + superName
1681
+ res = ERB.new(supertype_template)
1682
+ t = res.result(binding)
1683
+ file.puts t
1684
+ else
1685
+ # if in a select list that has been removed make it a subtype of all selects that include the removed select
1686
+ for superselect in all_select_list
1687
+ if superselect.selectitems_array.include?(select)
1688
+ superName = superselect.name
1689
+ subset = selectSubset[superName]
1690
+ if !subset.nil?
1691
+ if !subset.include?(select.name)
1692
+ selectSubs[superName].each{|e|
1693
+ if selectSubset[e].include?(select.name)
1694
+ superName = e
1695
+ end}
1696
+ end
1697
+ end
1698
+ puts entity.name + " added to " + superName
1699
+ puts " following removal of " + select.name
1700
+ xmiid = '_2_selectitem' + prefix + entity.name + '-' + superName
1701
+ xmiid_general = prefix + superName
1702
+ res = ERB.new(supertype_template)
1703
+ t = res.result(binding)
1704
+ file.puts t
1705
+ end
1706
+ end
1707
+ end
1708
+ end
1709
+
1710
+ # Map EXPRESS Explicit Attributes
1711
+ attr_list = entity.attributes.find_all{ |e| e.kind_of? EXPSM::Explicit }
1712
+ for attr in attr_list
1713
+ xmiid = '_2_attr' + prefix + entity.name + '-' + attr.name
1714
+
1715
+ # set up references resulting from attribute being a redeclaration
1716
+ if attr.redeclare_entity
1717
+ redeclare_entity = NamedType.find_by_name( attr.redeclare_entity )
1718
+ if attr.redeclare_oldname
1719
+ redefined_xmiid = '_2_attr' + get_prefix.call(redeclare_entity.schema) + attr.redeclare_entity + '-' + attr.redeclare_oldname
1720
+ else
1721
+ redefined_xmiid = '_2_attr' + get_prefix.call(redeclare_entity.schema) + attr.redeclare_entity + '-' + attr.name
1722
+ end
1723
+ end
1724
+
1725
+ # initialize default cardinailty constraints
1726
+ lower = '1'
1727
+ upper = '1'
1728
+ isset = true
1729
+ islist = false
1730
+
1731
+ domain_name = attr.domain
1732
+ orig_domain = NamedType.find_by_name( attr.domain )
1733
+ attr_domain = orig_domain
1734
+ agg_domain = nil
1735
+ attrType = nil
1736
+ associationNeeded = false
1737
+ begin
1738
+ unchanged = true
1739
+ case attr_domain.class.to_s
1740
+ when "EXPSM::Entity"
1741
+ associationNeeded = true
1742
+ when "EXPSM::Type"
1743
+ case selectTypeType[attr_domain.name]
1744
+ when "Entity", "Hybrid"
1745
+ associationNeeded = true
1746
+ end
1747
+ #ignore unhandled named aggregations
1748
+ when "EXPSM::TypeAggregate"
1749
+ if aggTypes[attr.domain].nil?
1750
+ attrType = attr_domain
1751
+ agg_domain = attr_domain
1752
+ if attr_domain.isBuiltin
1753
+ domain_name = attr_domain.domain
1754
+ attr_domain = nil
1755
+ else
1756
+ newDomain = NamedType.find_by_name( attr_domain.domain )
1757
+ attr_domain = newDomain
1758
+ domain_name = attr_domain.name
1759
+ unchanged = false
1760
+ end
1761
+ else
1762
+ associationNeeded = true
1763
+ end
1764
+ when "EXPSM::TypeSelect"
1765
+ case selectTypeType[attr_domain.name]
1766
+ when "Entity", "Hybrid"
1767
+ associationNeeded = true
1768
+ # ignore removed select types
1769
+ when "Remove"
1770
+ attr_domain = attr_domain.selectitems_array[0]
1771
+ domain_name = attr_domain.name
1772
+ unchanged = false
1773
+ end
1774
+ end
1775
+ end until unchanged
1776
+
1777
+ # set up cardinailty constraints from attribute being a 1-D aggregate
1778
+ # or a type defined to be a 1-D aggregate
1779
+ if attr.instance_of? EXPSM::ExplicitAggregate
1780
+ attrType = attr
1781
+ end
1782
+
1783
+ if !attrType.nil?
1784
+ upper = attrType.dimensions[0].upper
1785
+ if upper == '?'
1786
+ upper = '*'
1787
+ end
1788
+ lower = attrType.dimensions[0].lower
1789
+ if attrType.dimensions[0].aggrtype == 'ARRAY'
1790
+ puts 'Warning ARRAY not fully supported for '+attr.name
1791
+ end
1792
+ if attrType.dimensions[0].aggrtype == 'LIST'
1793
+ islist = true
1794
+ end
1795
+ if attrType.dimensions[0].aggrtype == 'BAG'
1796
+ isset = false
1797
+ end
1798
+ if attrType.dimensions[0].aggrtype == 'LIST' and !attrType.dimensions[0].isUnique
1799
+ isset = false
1800
+ end
1801
+ if attrType.rank > 1
1802
+ associationNeeded = true
1803
+ for i in 2..attrType.rank
1804
+ domain_name = attrType.dimensions[i-1].aggrtype+domain_name+lower+upper
1805
+ nestedAggs[domain_name] = attrType.dimensions[i-1]
1806
+ nestedTypes[domain_name] = attrType
1807
+ end
1808
+ end
1809
+ end
1810
+ if attr.isOptional
1811
+ case lower
1812
+ when '0','1'
1813
+ else
1814
+ lowBounds[attr.name] = lower
1815
+ end
1816
+ lower = '0'
1817
+ end
1818
+
1819
+ # Map EXPRESS Explicit Attributes that need an association
1820
+ if associationNeeded
1821
+ if attr_domain.nil?
1822
+ domain_xmiid = prefix + domain_name
1823
+ else
1824
+ domain_xmiid = get_prefix.call(attr_domain.schema) + domain_name
1825
+ end
1826
+ assoc_xmiid = '_1_association' + prefix + entity.name + '-' + attr.name
1827
+
1828
+ direct_inverse = false
1829
+ encapsulatedInto = false
1830
+ for inverse in direct_inverses
1831
+ if inverse.reverseAttr == attr
1832
+ if !inverse.instance_of? EXPSM::InverseAggregate
1833
+ direct_inverse = true
1834
+ encapsulatedInto = isEncapsulatedInto(entity, entity, attr)
1835
+ end
1836
+ end
1837
+ end
1838
+
1839
+ if !attr_domain.nil?
1840
+ if attr_domain == orig_domain
1841
+ encapsulated = isEncapsulated(attr_domain, attr)
1842
+ else
1843
+ if !agg_domain.nil?
1844
+ encapsulated = isEncapsulated(agg_domain, attr)
1845
+ else
1846
+ encapsulated = false
1847
+ end
1848
+ if !encapsulated
1849
+ encapsulated = isEncapsulated(attr_domain, attr)
1850
+ if !encapsulated
1851
+ encapsulated = isEncapsulated(orig_domain, attr)
1852
+ end
1853
+ end
1854
+ end
1855
+ end
1856
+
1857
+ res = ERB.new(attribute_entity_template,0,"<>")
1858
+ t = res.result(binding)
1859
+ file.puts t
1860
+ else
1861
+ # Map EXPRESS Explicit Attributes of Builtin
1862
+ if attr.isBuiltin or (attr_domain.nil?)
1863
+ res = ERB.new(attribute_builtin_template,0,"<>")
1864
+ t = res.result(binding)
1865
+ file.puts t
1866
+ else
1867
+ # Map EXPRESS Explicit Attributes of TYPE, TYPE Enum and TYPE Select (type)
1868
+ type_xmiid = get_prefix.call(attr_domain.schema) + domain_name
1869
+ res = ERB.new(attribute_enum_type_template,0,"<>")
1870
+ t = res.result(binding)
1871
+ file.puts t
1872
+ end
1873
+ end
1874
+
1875
+ res = ERB.new(multiplicity,0,"<>")
1876
+ t = res.result(binding)
1877
+ if !t.nil? && t.size>0
1878
+ file.puts t
1879
+ end
1880
+
1881
+ res = ERB.new(attribute_end)
1882
+ t = res.result(binding)
1883
+ file.puts t
1884
+ end
1885
+
1886
+ #Map EXPRESS Inverse Attributes
1887
+ inverse_attr_list = entity.attributes.find_all{ |e| e.kind_of? EXPSM::Inverse }
1888
+ for inverse in inverse_attr_list
1889
+ xmiid = '_2_attr' + prefix + entity.name + '-' + inverse.name
1890
+ # set up references resulting from attribute being a redeclaration
1891
+ if inverse.redeclare_entity
1892
+ if inverse.redeclare_oldname
1893
+ redefined_xmiid = '_2_attr' + prefix + inverse.redeclare_entity + '-' + inverse.redeclare_oldname
1894
+ else
1895
+ redefined_xmiid = '_2_attr' + prefix + inverse.redeclare_entity + '-' + inverse.name
1896
+ end
1897
+ end
1898
+
1899
+ lower = '1'
1900
+ upper = '1'
1901
+ isset = true
1902
+ if inverse.instance_of? EXPSM::InverseAggregate
1903
+ lower = '0'
1904
+ upper = '*'
1905
+ if inverse.upper != '?'
1906
+ upper = inverse.upper
1907
+ end
1908
+ if inverse.lower != '0'
1909
+ lower = inverse.lower
1910
+ end
1911
+ if inverse.aggrtype == 'BAG'
1912
+ isset = false
1913
+ end
1914
+ end
1915
+ domain_xmiid = prefix + inverse.reverseEntity.name
1916
+ if all_inverse_list.include?(inverse)
1917
+ assoc_xmiid = '_1_association' + get_prefix.call(inverse.reverseEntity.schema) + entity.name + '-' + inverse.name
1918
+ else
1919
+ if inverse.reverseAttr.domain == entity.name
1920
+ assoc_xmiid = '_1_association' + get_prefix.call(inverse.reverseEntity.schema) + inverse.reverseEntity.name + '-' + inverse.reverseAttr_id
1921
+ else
1922
+ assoc_xmiid = '_1_association' + get_prefix.call(inverse.reverseEntity.schema) + entity.name + '-' + inverse.reverseAttr_id
1923
+ end
1924
+ end
1925
+
1926
+ encapsulatedInto = isEncapsulatedInto(inverse.reverseEntity, inverse.reverseEntity, inverse.reverseAttr)
1927
+
1928
+ res = ERB.new(inverse_attribute_template)
1929
+ t = res.result(binding)
1930
+ file.puts t
1931
+
1932
+ res = ERB.new(multiplicity,0,"<>")
1933
+ t = res.result(binding)
1934
+ if !t.nil? && t.size>0
1935
+ file.puts t
1936
+ end
1937
+
1938
+ res = ERB.new(attribute_end)
1939
+ t = res.result(binding)
1940
+ file.puts t
1941
+ end
1942
+
1943
+ # Create lower bound constraints where required
1944
+ lowBounds.each do |name, bound|
1945
+ xmiid = '_3_lb' + prefix + entity.name + '-' + name
1946
+ res = ERB.new(bound_constraint)
1947
+ t = res.result(binding)
1948
+ file.puts t
1949
+ end
1950
+
1951
+ # Map EXPRESS Unique rules
1952
+ if entity.uniques.size > 0
1953
+ for unique in entity.uniques
1954
+ xmiid = '_3_uniq' + prefix + entity.name + '-' + unique.name
1955
+ if unique.attributes.size == 1
1956
+ unique_text = unique.attributes[0]
1957
+ else
1958
+ unique_text = 'Sequence{'+ unique.attributes.join(', ') +'}'
1959
+ end
1960
+ res = ERB.new(unique_template)
1961
+ t = res.result(binding)
1962
+ file.puts t
1963
+ end
1964
+ end
1965
+
1966
+ # Map EXPRESS Where rules
1967
+ whererules = entity.wheres.select {|w| w.name[0..10] != "encapsulate"}
1968
+ if whererules.size > 0
1969
+ for where in whererules
1970
+ xmiid = '_3_whr' + prefix + entity.name + '-' + where.name.to_s
1971
+ where_ocl = get_where(xmiid, where.expression)
1972
+ if where_ocl.size > 0
1973
+ xmiidref = xmiid_entity
1974
+ res = ERB.new(where_template)
1975
+ t = res.result(binding)
1976
+ file.puts t
1977
+ else
1978
+ puts "Where rule " + entity.name + "." + where.name.to_s + " not mapped to OCL - ignored!"
1979
+ end
1980
+ end
1981
+ end
1982
+
1983
+ # Evaluate and write ENTITY end template
1984
+ res = ERB.new(entity_end_template)
1985
+ t = res.result(binding)
1986
+ file.puts t
1987
+ end
1988
+
1989
+ nestedAggs.each do |type_name, dimension|
1990
+ # Evaluate and write aggType start template
1991
+ # initialize default cardinailty constraints
1992
+ isset = true
1993
+ islist = false
1994
+
1995
+ upper = dimension.upper
1996
+ if upper == '?'
1997
+ upper = '*'
1998
+ end
1999
+ lower = dimension.lower
2000
+ if dimension.aggrtype == 'LIST'
2001
+ islist = true
2002
+ end
2003
+ if dimension.aggrtype == 'BAG'
2004
+ isset = false
2005
+ end
2006
+ if dimension.aggrtype == 'LIST' and !dimension.isUnique
2007
+ isset = false
2008
+ end
2009
+
2010
+ xmiid = prefix + type_name
2011
+ type = nestedTypes[type_name]
2012
+ associationNeeded = false
2013
+
2014
+ if type.isBuiltin
2015
+ xmiid_type = $dtprefix + type.domain
2016
+ else
2017
+ xmiid_type = prefix + type.domain
2018
+
2019
+ domain = NamedType.find_by_name( type.domain )
2020
+ case domain.class.to_s
2021
+ when "EXPSM::Entity"
2022
+ associationNeeded = true
2023
+ when "EXPSM::Type"
2024
+ case selectTypeType[type.domain]
2025
+ when "Entity", "Hybrid"
2026
+ associationNeeded = true
2027
+ end
2028
+ when "EXPSM::TypeAggregate"
2029
+ if !aggTypes[type.domain].nil?
2030
+ associationNeeded = true
2031
+ end
2032
+ when "EXPSM::TypeSelect"
2033
+ case selectTypeType[type.domain]
2034
+ when "Entity", "Hybrid"
2035
+ associationNeeded = true
2036
+ end
2037
+ end
2038
+ end
2039
+ res = ERB.new(aggtype_start_template)
2040
+ t = res.result(binding)
2041
+ file.puts t
2042
+
2043
+ if associationNeeded
2044
+ assoc_xmiid = '_1_association' + prefix + type.name + '-elements'
2045
+ end
2046
+
2047
+ xmiid = '_2_attr' + prefix + type.name + "-elements"
2048
+ res = ERB.new(aggtype_attribute)
2049
+ t = res.result(binding)
2050
+ file.puts t
2051
+
2052
+ res = ERB.new(multiplicity,0,"<>")
2053
+ t = res.result(binding)
2054
+ if !t.nil? && t.size>0
2055
+ file.puts t
2056
+ end
2057
+
2058
+ res = ERB.new(attribute_end)
2059
+ t = res.result(binding)
2060
+ file.puts t
2061
+
2062
+ res = ERB.new(type_end_template)
2063
+ t = res.result(binding)
2064
+ file.puts t
2065
+
2066
+ if associationNeeded
2067
+ res = ERB.new(aggtype_association)
2068
+ t = res.result(binding)
2069
+ file.puts t
2070
+ end
2071
+ end
2072
+
2073
+ # Evaluate and write SCHEMA end template
2074
+ res = ERB.new(schema_end_template)
2075
+ t = res.result(binding)
2076
+ file.puts t
2077
+ end
2078
+
2079
+ if schema_list.size > 1
2080
+ res = ERB.new(package_end)
2081
+ t = res.result(binding)
2082
+ file.puts t
2083
+ end
2084
+
2085
+ # Map EXPRESS Entity Types to blocks
2086
+ for schema in schema_list
2087
+ prefix = get_prefix.call(schema)
2088
+
2089
+ entity_list = schema.contents.find_all{ |e| e.kind_of? EXPSM::Entity }
2090
+
2091
+ for entity in entity_list
2092
+ # Evaluate and write ENTITY Block template
2093
+ baseClass = prefix + entity.name
2094
+ xmiid = baseClass + '-Block'
2095
+ res = ERB.new(entity_block_template)
2096
+ t = res.result(binding)
2097
+ file.puts t
2098
+ end
2099
+
2100
+ type_list = schema.contents.find_all{ |e| e.instance_of? EXPSM::TypeEnum}
2101
+ for type in type_list
2102
+ # Evaluate and write TYPE ValueType template
2103
+ baseType = prefix + type.name
2104
+ xmiid = baseType + '-ValueType'
2105
+ res = ERB.new(valuetype_template)
2106
+ t = res.result(binding)
2107
+ file.puts t
2108
+ end
2109
+
2110
+ type_list = schema.contents.find_all{ |e| e.instance_of? EXPSM::Type and e.isBuiltin}
2111
+ for type in type_list
2112
+ # Evaluate and write TYPE ValueType template
2113
+ baseType = prefix + type.name
2114
+ xmiid = baseType + '-ValueType'
2115
+ res = ERB.new(valuetype_template)
2116
+ t = res.result(binding)
2117
+ file.puts t
2118
+ end
2119
+
2120
+ type_list = schema.contents.find_all{ |e| e.instance_of? EXPSM::Type and !e.isBuiltin}
2121
+ for type in type_list
2122
+ superselect = NamedType.find_by_name( type.domain )
2123
+ if !superselect.kind_of? EXPSM::TypeSelect
2124
+ # Evaluate and write TYPE ValueType template
2125
+ baseType = prefix + type.name
2126
+ xmiid = baseType + '-ValueType'
2127
+ res = ERB.new(valuetype_template)
2128
+ t = res.result(binding)
2129
+ file.puts t
2130
+ end
2131
+ end
2132
+ end
2133
+
2134
+ for select in all_select_list
2135
+ case selectTypeType[select.name]
2136
+ when "Type"
2137
+ # Evaluate and write TYPE ValueType template
2138
+ baseType = prefix + select.name
2139
+ xmiid = baseType + '-ValueType'
2140
+ res = ERB.new(valuetype_template)
2141
+ t = res.result(binding)
2142
+ file.puts t
2143
+ xmiid = baseType + '-Auxiliary'
2144
+ res = ERB.new(select_stereotype_template)
2145
+ t = res.result(binding)
2146
+ file.puts t
2147
+ when "Remove"
2148
+ # do nothing
2149
+ else
2150
+ # Evaluate and write ENTITY Block template
2151
+ baseClass = prefix + select.name
2152
+ xmiid = baseClass + '-Block'
2153
+ res = ERB.new(entity_block_template)
2154
+ t = res.result(binding)
2155
+ file.puts t
2156
+ xmiid = baseClass + '-Auxiliary'
2157
+ res = ERB.new(select_stereotype_template)
2158
+ t = res.result(binding)
2159
+ file.puts t
2160
+ end
2161
+ end
2162
+
2163
+ selectSubset.each_key do |select|
2164
+ if selectSubs[select].nil?
2165
+ case selectTypeType[select]
2166
+ when "Type"
2167
+ # Evaluate and write TYPE ValueType template
2168
+ baseType = prefix + select
2169
+ xmiid = baseType + '-ValueType'
2170
+ res = ERB.new(valuetype_template)
2171
+ t = res.result(binding)
2172
+ file.puts t
2173
+ xmiid = baseType + '-Auxiliary'
2174
+ res = ERB.new(select_stereotype_template)
2175
+ t = res.result(binding)
2176
+ file.puts t
2177
+ when "Remove"
2178
+ # do nothing
2179
+ else
2180
+ # Evaluate and write ENTITY Block template
2181
+ baseClass = prefix + select
2182
+ xmiid = baseClass + '-Block'
2183
+ res = ERB.new(entity_block_template)
2184
+ t = res.result(binding)
2185
+ file.puts t
2186
+ xmiid = baseClass + '-Auxiliary'
2187
+ res = ERB.new(select_stereotype_template)
2188
+ t = res.result(binding)
2189
+ file.puts t
2190
+ end
2191
+ end
2192
+ end
2193
+
2194
+ typeProxies.each_value do |type|
2195
+ # Evaluate and write ENTITY Block template
2196
+ baseClass = prefix + type.name + "_Proxy"
2197
+ xmiid = baseClass + '-Block'
2198
+ res = ERB.new(entity_block_template)
2199
+ t = res.result(binding)
2200
+ file.puts t
2201
+ xmiid = baseClass + '-Type'
2202
+ res = ERB.new(type_stereotype_template)
2203
+ t = res.result(binding)
2204
+ file.puts t
2205
+ end
2206
+
2207
+ aggTypes.each_value do |type|
2208
+ # Evaluate and write ENTITY Block template
2209
+ baseClass = prefix + type.name
2210
+ xmiid = baseClass + '-Block'
2211
+ res = ERB.new(entity_block_template)
2212
+ t = res.result(binding)
2213
+ file.puts t
2214
+ xmiid = baseClass + '-Type'
2215
+ res = ERB.new(type_stereotype_template)
2216
+ t = res.result(binding)
2217
+ file.puts t
2218
+ end
2219
+
2220
+ nestedTypes.each_key do |type_name|
2221
+ # Evaluate and write ENTITY Block template
2222
+ baseClass = prefix + type_name
2223
+ xmiid = baseClass + '-Block'
2224
+ res = ERB.new(entity_block_template)
2225
+ t = res.result(binding)
2226
+ file.puts t
2227
+ xmiid = baseClass + '-Type'
2228
+ res = ERB.new(type_stereotype_template)
2229
+ t = res.result(binding)
2230
+ file.puts t
2231
+ end
2232
+
2233
+ if dtHandle != "ignore"
2234
+ if dtHandle == "export"
2235
+ if !uuidSafe.nil?
2236
+ tmp = uuidSafe
2237
+ uuidSafe = $uuidxml
2238
+ $uuidxml = tmp
2239
+ tmp = uuidOldSafe
2240
+ uuidOldSafe = $olduuids
2241
+ $olduuids = tmp
2242
+ end
2243
+ end
2244
+ res = ERB.new(data_type_stereos)
2245
+ t = res.result(binding)
2246
+ dtfile.puts t
2247
+ if dtHandle == "export"
2248
+ res = ERB.new(overall_end_template)
2249
+ t = res.result(binding)
2250
+ dtfile.puts t
2251
+ if !uuidSafe.nil?
2252
+ for uuidmap in $olduuids
2253
+ uuidmap.remove
2254
+ end
2255
+ File.open("DataTypes_UUIDs.xml","w"){|file| $uuidxml.write_xml_to file}
2256
+ $uuidxml = uuidSafe
2257
+ $olduuids = uuidOldSafe
2258
+ end
2259
+ dtfile.close
2260
+ end
2261
+ end
2262
+
2263
+ # Evaluate and write file end template
2264
+ res = ERB.new(overall_end_template)
2265
+ t = res.result(binding)
2266
+ file.puts t
2267
+
2268
+ file.close
2269
+
2270
+ if $uuidsRequired
2271
+ for uuidmap in $olduuids
2272
+ uuidmap.remove
2273
+ end
2274
+ File.open("UUIDs.xml","w"){|file| $uuidxml.write_xml_to file}
2275
+ end
2276
+
2277
+ if !$wherexml.nil?
2278
+ File.open("WhereRuleMapping.xml","w"){|file| $wherexml.write_xml_to file}
2279
+ end
2280
+ end
2281
+