lutaml 0.9.27 → 0.9.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/README.adoc +36 -35
  3. data/bin/plantuml2lutaml +11 -7
  4. data/bin/yaml2lutaml +1 -1
  5. data/exe/lutaml-sysml +4 -2
  6. data/exe/lutaml-wsd2uml +11 -7
  7. data/exe/lutaml-yaml2uml +1 -1
  8. data/lib/lutaml/express/parsers/exp.rb +4 -4
  9. data/lib/lutaml/formatter/graphviz.rb +7 -7
  10. data/lib/lutaml/parser.rb +3 -31
  11. data/lib/lutaml/sysml/allocate.rb +6 -7
  12. data/lib/lutaml/sysml/allocated.rb +6 -6
  13. data/lib/lutaml/sysml/binding_connector.rb +6 -6
  14. data/lib/lutaml/sysml/block.rb +28 -25
  15. data/lib/lutaml/sysml/constraint_block.rb +11 -11
  16. data/lib/lutaml/sysml/copy.rb +5 -5
  17. data/lib/lutaml/sysml/derive_requirement.rb +6 -6
  18. data/lib/lutaml/sysml/nested_connector_end.rb +9 -9
  19. data/lib/lutaml/sysml/refine.rb +6 -6
  20. data/lib/lutaml/sysml/requirement_related.rb +6 -6
  21. data/lib/lutaml/sysml/satisfy.rb +6 -6
  22. data/lib/lutaml/sysml/test_case.rb +20 -19
  23. data/lib/lutaml/sysml/trace.rb +6 -6
  24. data/lib/lutaml/sysml/verify.rb +5 -5
  25. data/lib/lutaml/sysml/version.rb +1 -1
  26. data/lib/lutaml/sysml/xmi_file.rb +455 -415
  27. data/lib/lutaml/sysml.rb +1 -1
  28. data/lib/lutaml/uml/association.rb +4 -3
  29. data/lib/lutaml/uml/data_type.rb +1 -0
  30. data/lib/lutaml/uml/document.rb +4 -1
  31. data/lib/lutaml/uml/formatter/graphviz.rb +11 -13
  32. data/lib/lutaml/uml/has_attributes.rb +2 -2
  33. data/lib/lutaml/uml/has_members.rb +4 -3
  34. data/lib/lutaml/uml/node/class_node.rb +5 -7
  35. data/lib/lutaml/uml/node/field.rb +1 -3
  36. data/lib/lutaml/uml/node/method.rb +1 -3
  37. data/lib/lutaml/uml/node/relationship.rb +1 -3
  38. data/lib/lutaml/uml/operation.rb +6 -6
  39. data/lib/lutaml/uml/package.rb +3 -1
  40. data/lib/lutaml/uml/parsers/attribute.rb +1 -3
  41. data/lib/lutaml/uml/parsers/dsl.rb +11 -10
  42. data/lib/lutaml/uml/parsers/dsl_preprocessor.rb +7 -6
  43. data/lib/lutaml/uml/parsers/yaml.rb +2 -2
  44. data/lib/lutaml/uml/serializers/class.rb +1 -1
  45. data/lib/lutaml/uml/top_element.rb +9 -9
  46. data/lib/lutaml/uml/top_element_attribute.rb +6 -6
  47. data/lib/lutaml/uml/value.rb +6 -6
  48. data/lib/lutaml/version.rb +1 -1
  49. data/lib/lutaml/xmi/liquid_drops/association_drop.rb +31 -11
  50. data/lib/lutaml/xmi/liquid_drops/attribute_drop.rb +29 -11
  51. data/lib/lutaml/xmi/liquid_drops/cardinality_drop.rb +8 -2
  52. data/lib/lutaml/xmi/liquid_drops/constraint_drop.rb +6 -4
  53. data/lib/lutaml/xmi/liquid_drops/data_type_drop.rb +76 -18
  54. data/lib/lutaml/xmi/liquid_drops/diagram_drop.rb +13 -6
  55. data/lib/lutaml/xmi/liquid_drops/enum_drop.rb +16 -7
  56. data/lib/lutaml/xmi/liquid_drops/enum_owned_literal_drop.rb +10 -4
  57. data/lib/lutaml/xmi/liquid_drops/generalization_attribute_drop.rb +2 -0
  58. data/lib/lutaml/xmi/liquid_drops/generalization_drop.rb +10 -3
  59. data/lib/lutaml/xmi/liquid_drops/klass_drop.rb +98 -24
  60. data/lib/lutaml/xmi/liquid_drops/operation_drop.rb +11 -5
  61. data/lib/lutaml/xmi/liquid_drops/package_drop.rb +61 -18
  62. data/lib/lutaml/xmi/liquid_drops/root_drop.rb +14 -4
  63. data/lib/lutaml/xmi/parsers/xmi_base.rb +1031 -0
  64. data/lib/lutaml/xmi/parsers/xml.rb +23 -1018
  65. data/lib/lutaml/xml/parsers/xml.rb +6 -19
  66. data/lib/lutaml/xml.rb +0 -8
  67. data/lutaml.gemspec +2 -1
  68. metadata +32 -23
  69. data/lib/lutaml/express/lutaml_path/document_wrapper.rb +0 -22
  70. data/lib/lutaml/express/lutaml_path/formatter.rb +0 -14
  71. data/lib/lutaml/lutaml_path/document_wrapper.rb +0 -51
  72. data/lib/lutaml/uml/lutaml_path/document_wrapper.rb +0 -15
  73. data/lib/lutaml/xml/lutaml_path/document_wrapper.rb +0 -45
  74. data/lib/lutaml/xml/mapper.rb +0 -448
@@ -1,417 +1,457 @@
1
1
  module Lutaml::SysMl
2
-
3
- class XmiFile
4
-
5
- attr_accessor :package_list, :model_list, :class_list, :activity_list, :property_list, :port_list, :datatype_list, :instance_list,
6
- :realization_list, :abstraction_list, :association_list , :connector_list, :connectorend_list, :constraint_list, :block_list , :constraintblock_list,
7
- :requirement_list, :testcase_list, :binding_connector_list, :nested_connectorend_list, :derive_requirement_list,
8
- :refine_requirement_list, :trace_requirement_list, :copy_requirement_list, :verify_requirement_list, :satisfy_requirement_list ,
9
- :allocate_requirement_list, :element_hash
10
-
11
- def initialize
12
- @package_list = []
13
- @model_list = []
14
- @class_list = []
15
- @activity_list = []
16
- @property_list = []
17
- @port_list = []
18
- @datatype_list = []
19
- @instance_list = []
20
- @realization_list = []
21
- @abstraction_list = []
22
- @association_list = []
23
- @connector_list = []
24
- @connectorend_list = []
25
- @constraint_list = []
26
-
27
- @block_list = []
28
- @constraintblock_list = []
29
- @requirement_list = []
30
- @testcase_list = []
31
- @binding_connector_list = []
32
- @nested_connectorend_list = []
33
- @derive_requirement_list = []
34
- @refine_requirement_list = []
35
- @trace_requirement_list = []
36
- @copy_requirement_list = []
37
- @verify_requirement_list = []
38
- @satisfy_requirement_list = []
39
- @allocate_requirement_list = []
40
-
41
- @element_hash = Hash.new
42
- end
43
-
44
- def parse (filename)
45
- xmifile = File.new(filename, "r")
46
- inxml = Nokogiri::XML(xmifile)
47
-
48
- xmi_elements = inxml.xpath('//xmi:XMI')
49
- if xmi_elements.size == 0
50
- puts "ERROR : File contains no 'xmi:XMI' XML elements : #{filename}, may not be XMI file."
51
- xmifile.close
52
- exit
53
- end
54
-
55
- #setup xmi namespace
56
- xmiNS = inxml.root.namespace_definitions.find{|ns| ns.prefix=="xmi"}
57
-
58
- ## Step 1: Find UML and SysML Core Objects in XMI file and create as instance of metamodel
59
-
60
- for xml_node in inxml.xpath('//*' )
61
- element_new = nil
62
-
63
- if xml_node.name.to_s == 'packagedElement' and xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:Package'
64
- element_new = Lutaml::Uml::Package.new
65
- package_list.push element_new
66
- end
67
-
68
- if xml_node.name.to_s == 'Model'
69
- element_new = Lutaml::Uml::Model.new
70
- model_list.push element_new
71
- element_new.viewpoint = xml_node['viewpoint']
72
- element_new.href = xml_node['href']
73
- end
74
-
75
- if xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:Class'
76
- element_new = Lutaml::Uml::Class.new
77
- if xml_node['isAbstract'] != nil
78
- element_new.is_abstract = xml_node['isAbstract'] == 'true'
79
- end
80
- class_list.push element_new
81
- end
82
-
83
- if xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:Activity'
84
- element_new = Lutaml::Uml::Activity.new
85
- activity_list.push element_new
86
- end
87
-
88
- if xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:Property'
89
- element_new = Lutaml::Uml::Property.new
90
- property_list.push element_new
91
- end
92
-
93
- if xml_node.attribute_with_ns('type',xmiNS.href).to_s== 'uml:InstanceSpecification'
94
- element_new = Lutaml::Uml::Instance.new
95
- instance_list.push element_new
96
- end
97
-
98
- if xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:DataType'
99
- element_new = Lutaml::Uml::DataType.new
100
- datatype_list.push element_new
101
- end
102
-
103
- if xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:Port'
104
- element_new = Lutaml::Uml::Port.new
105
- port_list.push element_new
106
- end
107
-
108
- if xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:Connector'
109
- element_new = Lutaml::Uml::Connector.new
110
- connector_list.push element_new
111
- end
112
-
113
- if xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:ConnectorEnd'
114
- element_new = Lutaml::Uml::ConnectorEnd.new
115
- connectorend_list.push element_new
116
- end
117
-
118
- if xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:Constraint'
119
- element_new = Lutaml::Uml::Constraint.new
120
- constraint_list.push element_new
121
- end
122
-
123
- if xml_node.name.to_s == 'Block'
124
- element_new = SYSML::Block.new
125
- block_list.push element_new
126
- end
127
-
128
- if xml_node.name.to_s == 'Template'
129
- element_new = SYSML::Block.new
130
- block_list.push element_new
131
- end
132
-
133
- if xml_node.name.to_s == 'ConstraintBlock'
134
- element_new = SYSML::ConstraintBlock.new
135
- constraintblock_list.push element_new
136
- end
137
-
138
- if xml_node.name.to_s.index('Requirement') or xml_node.name.to_s == 'designConstraint'
139
- if xml_node.name.to_s != 'RequirementRelated'
140
- element_new = SYSML::Requirement.new
141
- requirement_list.push element_new
142
- element_new.id = xml_node.attribute_with_ns('id',xmiNS.href).to_s.strip
143
- element_new.text = xml_node['Text']
144
- if xml_node.name != 'Requirement'
145
- element_new.stereotype.push xml_node.name
146
- end
147
- end
148
- end
149
-
150
- if xml_node.name.to_s == 'TestCase'
151
- element_new = SYSML::TestCase.new
152
- testcase_list.push element_new
153
- end
154
-
155
- if xml_node.name.to_s == 'BindingConnector'
156
- element_new = SYSML::BindingConnector.new
157
- binding_connector_list.push element_new
158
- end
159
-
160
- if xml_node.name.to_s == 'NestedConnectorEnd'
161
- element_new = SYSML::NestedConnectorEnd.new
162
- nested_connectorend_list.push element_new
163
- end
164
-
165
- if xml_node.name.to_s == 'DeriveReqt'
166
- element_new = SYSML::DeriveRequirement.new
167
- derive_requirement_list.push element_new
168
- end
169
- if xml_node.name.to_s == 'refine'
170
- element_new = SYSML::Refine.new
171
- refine_requirement_list.push element_new
172
- end
173
- if xml_node.name.to_s == 'trace'
174
- element_new = SYSML::Trace.new
175
- trace_requirement_list.push element_new
176
- end
177
- if xml_node.name.to_s == 'Copy'
178
- element_new = SYSML::Copy.new
179
- copy_requirement_list.push element_new
180
- end
181
- if xml_node.name.to_s == 'Verify'
182
- element_new = SYSML::Verify.new
183
- verify_requirement_list.push element_new
184
- end
185
- if xml_node.name.to_s == 'Allocate'
186
- element_new = SYSML::Allocate.new
187
- allocate_requirement_list.push element_new
188
- end
189
-
190
- if xml_node.name.to_s == 'Satisfy'
191
- element_new = SYSML::Satisfy.new
192
- satisfy_requirement_list.push element_new
193
- end
194
-
195
- if xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:Abstraction'
196
- element_new = Lutaml::Uml::Abstraction.new
197
- abstraction_list.push element_new
198
- end
199
-
200
- if xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:Realization'
201
- element_new = Lutaml::Uml::Realization.new
202
- realization_list.push element_new
203
- end
204
-
205
- if xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:Association'
206
- element_new = Lutaml::Uml::Association.new
207
- association_list.push element_new
208
- end
209
-
210
- if element_new != nil
211
- new_xmi_id_node = xml_node.attribute_with_ns('id',xmiNS.href)
212
- new_xmi_uuid_node = xml_node.attribute_with_ns('uuid',xmiNS.href)
213
- new_name_node = xml_node['name']
214
- new_href_node = xml_node['href']
215
-
216
- if new_xmi_id_node != nil
217
- element_new.xmi_id = new_xmi_id_node.to_s
218
- element_hash[element_new.xmi_id] = element_new
219
- end
220
-
221
- if new_xmi_uuid_node != nil
222
- element_new.xmi_uuid = new_xmi_uuid_node.to_s
223
- end
224
-
225
- if new_name_node != nil
226
- element_new.name = xml_node['name'].strip
227
- end
228
-
229
- if new_href_node != nil
230
- element_new.href = new_href_node.to_s
231
- if new_xmi_id_node == nil
232
- element_hash[element_new.href] = element_new
233
- end
234
- if xml_node.at('xmi:Extension/referenceExtension') != nil
235
- element_new.name = xml_node.at('xmi:Extension/referenceExtension')['referentPath']
236
- end
237
- end
238
-
239
- if (xml_node.parent != nil and
240
- xml_node.parent.attribute_with_ns('id',xmiNS.href) != nil and
241
- element_hash[xml_node.parent.attribute_with_ns('id',xmiNS.href).to_s] != nil)
242
-
243
- parent = element_hash[xml_node.parent.attribute_with_ns('id',xmiNS.href).to_s]
244
- element_new.namespace = parent
245
- if parent.kind_of? Lutaml::Uml::Package
246
- parent.contents.push element_new
247
- end
248
- end
249
- end
250
- end
251
-
252
- for xml_node in inxml.xpath('//*')
253
-
254
- if (xml_node.attribute_with_ns('id',xmiNS.href) != nil and
255
- element_hash[xml_node.attribute_with_ns('id',xmiNS.href).to_s] != nil)
256
-
257
- this_thing = element_hash[xml_node.attribute_with_ns('id',xmiNS.href).to_s]
258
- end
259
-
260
- if xml_node.name.to_s == 'nestedClassifier' and xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:Class'
261
- owning_class_xmi_id = xml_node.parent.attribute_with_ns('id',xmiNS.href).to_s
262
- owned_class_xmi_id = xml_node.attribute_with_ns('id',xmiNS.href).to_s
263
- owning_class = element_hash[owning_class_xmi_id]
264
- owned_class = element_hash[owned_class_xmi_id]
265
- owning_class.nested_classifier.push owned_class
266
- end
267
-
268
- if xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:Realization'
269
- this_thing = element_hash[xml_node.attribute_with_ns('id',xmiNS.href).to_s]
270
- supplier_xmi_id = xml_node.at('supplier')['idref']
271
- client_xmi_id = xml_node.at('client')['idref']
272
- this_thing.supplier.push element_hash[supplier_xmi_id]
273
- this_thing.client.push element_hash[client_xmi_id]
274
- end
275
-
276
- if xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:Abstraction'
277
- this_thing = element_hash[xml_node.attribute_with_ns('id',xmiNS.href).to_s]
278
- supplier_xmi_id = xml_node.at('supplier')['idref']
279
- client_xmi_id = xml_node.at('client')['idref']
280
- this_thing.supplier.push element_hash[supplier_xmi_id]
281
- this_thing.client.push element_hash[client_xmi_id]
282
- end
283
-
284
- if xml_node.name.to_s == 'Block'
285
- this_thing = element_hash[xml_node.attribute_with_ns('id',xmiNS.href).to_s]
286
- base_class_xmi_id = xml_node['base_Class']
287
- this_thing.base_class = element_hash[base_class_xmi_id]
288
- end
289
-
290
- if xml_node.name.to_s == 'Template'
291
- this_thing = element_hash[xml_node.attribute_with_ns('id',xmiNS.href).to_s]
292
- base_class_xmi_id = xml_node['base_Class']
293
- this_thing.base_class = element_hash[base_class_xmi_id]
294
- this_thing.base_class.stereotype.push 'Template'
295
- end
296
-
297
- if xml_node.name.to_s == 'ConstraintBlock'
298
- this_thing = element_hash[xml_node.attribute_with_ns('id',xmiNS.href).to_s]
299
- base_class_xmi_id = xml_node['base_Class']
300
- this_thing.base_class = element_hash[base_class_xmi_id]
301
- end
302
-
303
- if xml_node.name.to_s.index('Requirement') or xml_node.name.to_s == 'designConstraint'
304
- if xml_node.name.to_s != 'RequirementRelated'
305
- this_thing = element_hash[xml_node.attribute_with_ns('id',xmiNS.href).to_s]
306
- base_class_xmi_id = xml_node['base_Class']
307
- this_thing.base_class = element_hash[base_class_xmi_id]
308
- this_thing.refined_by = element_hash[xml_node['RefinedBy']]
309
- this_thing.derived_from = element_hash[xml_node['DerivedFrom']]
310
- this_thing.traced_to = element_hash[xml_node['TracedTo']]
311
- end
312
- end
313
-
314
- if xml_node.name.to_s == 'TestCase'
315
- this_thing = element_hash[xml_node.attribute_with_ns('id',xmiNS.href).to_s]
316
- this_thing.base_behavior = element_hash[xml_node['base_Behavior']]
317
- this_thing.verifies = element_hash[xml_node['Verifies']]
318
- end
319
-
320
- if xml_node.name.to_s == 'BindingConnector'
321
- this_thing = element_hash[xml_node.attribute_with_ns('id',xmiNS.href).to_s]
322
- base_connector_xmi_id = xml_node['base_Connector']
323
- this_thing.base_connector = element_hash[base_connector_xmi_id]
324
- end
325
-
326
- if xml_node.name.to_s == 'NestedConnectorEnd'
327
- this_thing = element_hash[xml_node.attribute_with_ns('id',xmiNS.href).to_s]
328
- base_connectorend_xmi_id = xml_node['base_ConnectorEnd']
329
- this_thing.base_connectorend = element_hash[base_connectorend_xmi_id]
330
- if xml_node['propertyPath'] != nil
331
- this_thing.property_path.push element_hash[xml_node['propertyPath']]
332
- else
333
- for prop_path in xml_node.xpath('./propertyPath')
334
- #to deal with href = '#xmi:id' i.e. local references
335
- href_parts = prop_path['href'].split('#')
336
- if href_parts[0].size == 0
337
- prop = element_hash[href_parts[1]]
338
- else
339
- prop = element_hash[prop_path['href']]
340
- end
341
- this_thing.property_path.push prop
342
- end
343
- end
344
- end
345
-
346
- if xml_node.name.to_s == 'Satisfy'
347
- this_thing = element_hash[xml_node.attribute_with_ns('id',xmiNS.href).to_s]
348
- base_realization_xmi_id = xml_node['base_Realization']
349
- this_thing.base_realization = element_hash[base_realization_xmi_id]
350
- end
351
-
352
- if ['DeriveReqt', 'refine', 'trace', 'Copy', 'Verify', 'Allocate', ''].include? xml_node.name.to_s
353
- this_thing = element_hash[xml_node.attribute_with_ns('id',xmiNS.href).to_s]
354
- base_abstraction_xmi_id = xml_node['base_Abstraction']
355
- this_thing.base_abstraction = element_hash[base_abstraction_xmi_id]
356
- end
357
-
358
- if xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:Association'
359
- this_thing = element_hash[xml_node.attribute_with_ns('id',xmiNS.href).to_s]
360
- member_end_list = xml_node.xpath('./memberEnd')
361
- for item in member_end_list
362
- this_thing.member_end.push element_hash[item['idref']]
363
- end
364
- owned_end_list = xml_node.xpath('./ownedEnd')
365
- for item in owned_end_list
366
- this_thing.owned_end.push element_hash[item.attribute_with_ns('id',xmiNS.href).to_s]
367
- end
368
- end
369
-
370
- if xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:Property' or xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:Port'
371
- if not ['definingFeature', 'partWithPort', 'propertyPath', 'role'].include? xml_node.name.to_s
372
- this_thing = element_hash[xml_node.attribute_with_ns('id',xmiNS.href).to_s]
373
- if xml_node['association'] != nil
374
- this_thing.association = element_hash[xml_node['association']]
375
- end
376
- if xml_node['aggregation'] != nil
377
- this_thing.aggregation = xml_node['aggregation']
378
- end
379
- if xml_node['visibility'] != nil
380
- this_thing.visibility = xml_node['visibility']
381
- end
382
-
383
- if xml_node.at('lowerValue') != nil
384
-
385
- if xml_node.at('lowerValue')['value'] != nil
386
- this_thing.lowerValue = xml_node.at('lowerValue')['value']
387
- else
388
- this_thing.lowerValue = '0'
389
- end
390
- end
391
- if xml_node.at('upperValue') != nil
392
- this_thing.upperValue = xml_node.at('upperValue')['value']
393
- end
394
- end
395
- end
396
-
397
- if xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:Connector'
398
- this_thing = element_hash[xml_node.attribute_with_ns('id',xmiNS.href).to_s]
399
- connector_end_list = xml_node.xpath('./end')
400
- for end_xml_node in connector_end_list
401
- this_thing.connector_end.push element_hash[end_xml_node.attribute_with_ns('id',xmiNS.href).to_s]
402
- end
403
- end
404
-
405
- if xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:ConnectorEnd'
406
- this_thing = element_hash[xml_node.attribute_with_ns('id',xmiNS.href).to_s]
407
- this_thing.connector = element_hash[xml_node.parent.attribute_with_ns('id',xmiNS.href).to_s]
408
- this_thing.role = element_hash[xml_node['role']]
409
- if this_thing.role == nil
410
- this_thing.role = element_hash[xml_node.at('role')['href']]
411
- end
412
- this_thing.part_with_port = element_hash[xml_node['part_with_port']]
413
- end
414
- end
415
- end
416
- end
2
+ class XmiFile
3
+ attr_accessor :package_list, :model_list, :class_list, :activity_list, :property_list, :port_list, :datatype_list, :instance_list,
4
+ :realization_list, :abstraction_list, :association_list, :connector_list, :connectorend_list, :constraint_list, :block_list, :constraintblock_list,
5
+ :requirement_list, :testcase_list, :binding_connector_list, :nested_connectorend_list, :derive_requirement_list,
6
+ :refine_requirement_list, :trace_requirement_list, :copy_requirement_list, :verify_requirement_list, :satisfy_requirement_list,
7
+ :allocate_requirement_list, :element_hash
8
+
9
+ def initialize
10
+ @package_list = []
11
+ @model_list = []
12
+ @class_list = []
13
+ @activity_list = []
14
+ @property_list = []
15
+ @port_list = []
16
+ @datatype_list = []
17
+ @instance_list = []
18
+ @realization_list = []
19
+ @abstraction_list = []
20
+ @association_list = []
21
+ @connector_list = []
22
+ @connectorend_list = []
23
+ @constraint_list = []
24
+
25
+ @block_list = []
26
+ @constraintblock_list = []
27
+ @requirement_list = []
28
+ @testcase_list = []
29
+ @binding_connector_list = []
30
+ @nested_connectorend_list = []
31
+ @derive_requirement_list = []
32
+ @refine_requirement_list = []
33
+ @trace_requirement_list = []
34
+ @copy_requirement_list = []
35
+ @verify_requirement_list = []
36
+ @satisfy_requirement_list = []
37
+ @allocate_requirement_list = []
38
+
39
+ @element_hash = Hash.new
40
+ end
41
+
42
+ def parse(filename)
43
+ xmifile = File.new(filename, "r")
44
+ inxml = Nokogiri::XML(xmifile)
45
+
46
+ xmi_elements = inxml.xpath("//xmi:XMI")
47
+ if xmi_elements.size == 0
48
+ puts "ERROR : File contains no 'xmi:XMI' XML elements : #{filename}, may not be XMI file."
49
+ xmifile.close
50
+ exit
51
+ end
52
+
53
+ # setup xmi namespace
54
+ xmiNS = inxml.root.namespace_definitions.find { |ns| ns.prefix == "xmi" }
55
+
56
+ ## Step 1: Find UML and SysML Core Objects in XMI file and create as instance of metamodel
57
+
58
+ for xml_node in inxml.xpath("//*")
59
+ element_new = nil
60
+
61
+ if xml_node.name.to_s == "packagedElement" and xml_node.attribute_with_ns(
62
+ "type", xmiNS.href
63
+ ).to_s == "uml:Package"
64
+ element_new = Lutaml::Uml::Package.new
65
+ package_list.push element_new
66
+ end
67
+
68
+ if xml_node.name.to_s == "Model"
69
+ element_new = Lutaml::Uml::Model.new
70
+ model_list.push element_new
71
+ element_new.viewpoint = xml_node["viewpoint"]
72
+ element_new.href = xml_node["href"]
73
+ end
74
+
75
+ if xml_node.attribute_with_ns("type", xmiNS.href).to_s == "uml:Class"
76
+ element_new = Lutaml::Uml::Class.new
77
+ if !xml_node["isAbstract"].nil?
78
+ element_new.is_abstract = xml_node["isAbstract"] == "true"
79
+ end
80
+ class_list.push element_new
81
+ end
82
+
83
+ if xml_node.attribute_with_ns("type",
84
+ xmiNS.href).to_s == "uml:Activity"
85
+ element_new = Lutaml::Uml::Activity.new
86
+ activity_list.push element_new
87
+ end
88
+
89
+ if xml_node.attribute_with_ns("type",
90
+ xmiNS.href).to_s == "uml:Property"
91
+ element_new = Lutaml::Uml::Property.new
92
+ property_list.push element_new
93
+ end
94
+
95
+ if xml_node.attribute_with_ns("type",
96
+ xmiNS.href).to_s == "uml:InstanceSpecification"
97
+ element_new = Lutaml::Uml::Instance.new
98
+ instance_list.push element_new
99
+ end
100
+
101
+ if xml_node.attribute_with_ns("type",
102
+ xmiNS.href).to_s == "uml:DataType"
103
+ element_new = Lutaml::Uml::DataType.new
104
+ datatype_list.push element_new
105
+ end
106
+
107
+ if xml_node.attribute_with_ns("type", xmiNS.href).to_s == "uml:Port"
108
+ element_new = Lutaml::Uml::Port.new
109
+ port_list.push element_new
110
+ end
111
+
112
+ if xml_node.attribute_with_ns("type",
113
+ xmiNS.href).to_s == "uml:Connector"
114
+ element_new = Lutaml::Uml::Connector.new
115
+ connector_list.push element_new
116
+ end
117
+
118
+ if xml_node.attribute_with_ns("type",
119
+ xmiNS.href).to_s == "uml:ConnectorEnd"
120
+ element_new = Lutaml::Uml::ConnectorEnd.new
121
+ connectorend_list.push element_new
122
+ end
123
+
124
+ if xml_node.attribute_with_ns("type",
125
+ xmiNS.href).to_s == "uml:Constraint"
126
+ element_new = Lutaml::Uml::Constraint.new
127
+ constraint_list.push element_new
128
+ end
129
+
130
+ if xml_node.name.to_s == "Block"
131
+ element_new = SYSML::Block.new
132
+ block_list.push element_new
133
+ end
134
+
135
+ if xml_node.name.to_s == "Template"
136
+ element_new = SYSML::Block.new
137
+ block_list.push element_new
138
+ end
139
+
140
+ if xml_node.name.to_s == "ConstraintBlock"
141
+ element_new = SYSML::ConstraintBlock.new
142
+ constraintblock_list.push element_new
143
+ end
144
+
145
+ if (xml_node.name.to_s.index("Requirement") or xml_node.name.to_s == "designConstraint") && xml_node.name.to_s !=("RequirementRelated")
146
+ element_new = SYSML::Requirement.new
147
+ requirement_list.push element_new
148
+ element_new.id = xml_node.attribute_with_ns("id",
149
+ xmiNS.href).to_s.strip
150
+ element_new.text = xml_node["Text"]
151
+ if xml_node.name != "Requirement"
152
+ element_new.stereotype.push xml_node.name
153
+ end
154
+ end
155
+
156
+ if xml_node.name.to_s == "TestCase"
157
+ element_new = SYSML::TestCase.new
158
+ testcase_list.push element_new
159
+ end
160
+
161
+ if xml_node.name.to_s == "BindingConnector"
162
+ element_new = SYSML::BindingConnector.new
163
+ binding_connector_list.push element_new
164
+ end
165
+
166
+ if xml_node.name.to_s == "NestedConnectorEnd"
167
+ element_new = SYSML::NestedConnectorEnd.new
168
+ nested_connectorend_list.push element_new
169
+ end
170
+
171
+ if xml_node.name.to_s == "DeriveReqt"
172
+ element_new = SYSML::DeriveRequirement.new
173
+ derive_requirement_list.push element_new
174
+ end
175
+ if xml_node.name.to_s == "refine"
176
+ element_new = SYSML::Refine.new
177
+ refine_requirement_list.push element_new
178
+ end
179
+ if xml_node.name.to_s == "trace"
180
+ element_new = SYSML::Trace.new
181
+ trace_requirement_list.push element_new
182
+ end
183
+ if xml_node.name.to_s == "Copy"
184
+ element_new = SYSML::Copy.new
185
+ copy_requirement_list.push element_new
186
+ end
187
+ if xml_node.name.to_s == "Verify"
188
+ element_new = SYSML::Verify.new
189
+ verify_requirement_list.push element_new
190
+ end
191
+ if xml_node.name.to_s == "Allocate"
192
+ element_new = SYSML::Allocate.new
193
+ allocate_requirement_list.push element_new
194
+ end
195
+
196
+ if xml_node.name.to_s == "Satisfy"
197
+ element_new = SYSML::Satisfy.new
198
+ satisfy_requirement_list.push element_new
199
+ end
200
+
201
+ if xml_node.attribute_with_ns("type",
202
+ xmiNS.href).to_s == "uml:Abstraction"
203
+ element_new = Lutaml::Uml::Abstraction.new
204
+ abstraction_list.push element_new
205
+ end
206
+
207
+ if xml_node.attribute_with_ns("type",
208
+ xmiNS.href).to_s == "uml:Realization"
209
+ element_new = Lutaml::Uml::Realization.new
210
+ realization_list.push element_new
211
+ end
212
+
213
+ if xml_node.attribute_with_ns("type",
214
+ xmiNS.href).to_s == "uml:Association"
215
+ element_new = Lutaml::Uml::Association.new
216
+ association_list.push element_new
217
+ end
218
+
219
+ if !element_new.nil?
220
+ new_xmi_id_node = xml_node.attribute_with_ns("id", xmiNS.href)
221
+ new_xmi_uuid_node = xml_node.attribute_with_ns("uuid", xmiNS.href)
222
+ new_name_node = xml_node["name"]
223
+ new_href_node = xml_node["href"]
224
+
225
+ if !new_xmi_id_node.nil?
226
+ element_new.xmi_id = new_xmi_id_node.to_s
227
+ element_hash[element_new.xmi_id] = element_new
228
+ end
229
+
230
+ if !new_xmi_uuid_node.nil?
231
+ element_new.xmi_uuid = new_xmi_uuid_node.to_s
232
+ end
233
+
234
+ if !new_name_node.nil?
235
+ element_new.name = xml_node["name"].strip
236
+ end
237
+
238
+ if !new_href_node.nil?
239
+ element_new.href = new_href_node.to_s
240
+ if new_xmi_id_node == nil
241
+ element_hash[element_new.href] = element_new
242
+ end
243
+ if !xml_node.at("xmi:Extension/referenceExtension").nil?
244
+ element_new.name = xml_node.at("xmi:Extension/referenceExtension")["referentPath"]
245
+ end
246
+ end
247
+
248
+ if !xml_node.parent.nil? and
249
+ xml_node.parent.attribute_with_ns("id", xmiNS.href) != nil and
250
+ element_hash[xml_node.parent.attribute_with_ns("id",
251
+ xmiNS.href).to_s] != nil
252
+
253
+ parent = element_hash[xml_node.parent.attribute_with_ns("id",
254
+ xmiNS.href).to_s]
255
+ element_new.namespace = parent
256
+ if parent.is_a? Lutaml::Uml::Package
257
+ parent.contents.push element_new
258
+ end
259
+ end
260
+ end
261
+ end
262
+
263
+ for xml_node in inxml.xpath("//*")
264
+
265
+ if xml_node.attribute_with_ns("id", xmiNS.href) != nil and
266
+ element_hash[xml_node.attribute_with_ns("id",
267
+ xmiNS.href).to_s] != nil
268
+
269
+ this_thing = element_hash[xml_node.attribute_with_ns("id",
270
+ xmiNS.href).to_s]
271
+ end
272
+
273
+ if xml_node.name.to_s == "nestedClassifier" and xml_node.attribute_with_ns(
274
+ "type", xmiNS.href
275
+ ).to_s == "uml:Class"
276
+ owning_class_xmi_id = xml_node.parent.attribute_with_ns("id",
277
+ xmiNS.href).to_s
278
+ owned_class_xmi_id = xml_node.attribute_with_ns("id",
279
+ xmiNS.href).to_s
280
+ owning_class = element_hash[owning_class_xmi_id]
281
+ owned_class = element_hash[owned_class_xmi_id]
282
+ owning_class.nested_classifier.push owned_class
283
+ end
284
+
285
+ if xml_node.attribute_with_ns("type",
286
+ xmiNS.href).to_s == "uml:Realization"
287
+ this_thing = element_hash[xml_node.attribute_with_ns("id",
288
+ xmiNS.href).to_s]
289
+ supplier_xmi_id = xml_node.at("supplier")["idref"]
290
+ client_xmi_id = xml_node.at("client")["idref"]
291
+ this_thing.supplier.push element_hash[supplier_xmi_id]
292
+ this_thing.client.push element_hash[client_xmi_id]
293
+ end
294
+
295
+ if xml_node.attribute_with_ns("type",
296
+ xmiNS.href).to_s == "uml:Abstraction"
297
+ this_thing = element_hash[xml_node.attribute_with_ns("id",
298
+ xmiNS.href).to_s]
299
+ supplier_xmi_id = xml_node.at("supplier")["idref"]
300
+ client_xmi_id = xml_node.at("client")["idref"]
301
+ this_thing.supplier.push element_hash[supplier_xmi_id]
302
+ this_thing.client.push element_hash[client_xmi_id]
303
+ end
304
+
305
+ if xml_node.name.to_s == "Block"
306
+ this_thing = element_hash[xml_node.attribute_with_ns("id",
307
+ xmiNS.href).to_s]
308
+ base_class_xmi_id = xml_node["base_Class"]
309
+ this_thing.base_class = element_hash[base_class_xmi_id]
310
+ end
311
+
312
+ if xml_node.name.to_s == "Template"
313
+ this_thing = element_hash[xml_node.attribute_with_ns("id",
314
+ xmiNS.href).to_s]
315
+ base_class_xmi_id = xml_node["base_Class"]
316
+ this_thing.base_class = element_hash[base_class_xmi_id]
317
+ this_thing.base_class.stereotype.push "Template"
318
+ end
319
+
320
+ if xml_node.name.to_s == "ConstraintBlock"
321
+ this_thing = element_hash[xml_node.attribute_with_ns("id",
322
+ xmiNS.href).to_s]
323
+ base_class_xmi_id = xml_node["base_Class"]
324
+ this_thing.base_class = element_hash[base_class_xmi_id]
325
+ end
326
+
327
+ if (xml_node.name.to_s.index("Requirement") or xml_node.name.to_s == "designConstraint") && xml_node.name.to_s !=("RequirementRelated")
328
+ this_thing = element_hash[xml_node.attribute_with_ns("id",
329
+ xmiNS.href).to_s]
330
+ base_class_xmi_id = xml_node["base_Class"]
331
+ this_thing.base_class = element_hash[base_class_xmi_id]
332
+ this_thing.refined_by = element_hash[xml_node["RefinedBy"]]
333
+ this_thing.derived_from = element_hash[xml_node["DerivedFrom"]]
334
+ this_thing.traced_to = element_hash[xml_node["TracedTo"]]
335
+ end
336
+
337
+ if xml_node.name.to_s == "TestCase"
338
+ this_thing = element_hash[xml_node.attribute_with_ns("id",
339
+ xmiNS.href).to_s]
340
+ this_thing.base_behavior = element_hash[xml_node["base_Behavior"]]
341
+ this_thing.verifies = element_hash[xml_node["Verifies"]]
342
+ end
343
+
344
+ if xml_node.name.to_s == "BindingConnector"
345
+ this_thing = element_hash[xml_node.attribute_with_ns("id",
346
+ xmiNS.href).to_s]
347
+ base_connector_xmi_id = xml_node["base_Connector"]
348
+ this_thing.base_connector = element_hash[base_connector_xmi_id]
349
+ end
350
+
351
+ if xml_node.name.to_s == "NestedConnectorEnd"
352
+ this_thing = element_hash[xml_node.attribute_with_ns("id",
353
+ xmiNS.href).to_s]
354
+ base_connectorend_xmi_id = xml_node["base_ConnectorEnd"]
355
+ this_thing.base_connectorend = element_hash[base_connectorend_xmi_id]
356
+ if xml_node["propertyPath"] == nil
357
+ for prop_path in xml_node.xpath("./propertyPath")
358
+ # to deal with href = '#xmi:id' i.e. local references
359
+ href_parts = prop_path["href"].split("#")
360
+ prop = if href_parts[0].size == 0
361
+ element_hash[href_parts[1]]
362
+ else
363
+ element_hash[prop_path["href"]]
364
+ end
365
+ this_thing.property_path.push prop
366
+ end
367
+ else
368
+ this_thing.property_path.push element_hash[xml_node["propertyPath"]]
369
+ end
370
+ end
371
+
372
+ if xml_node.name.to_s == "Satisfy"
373
+ this_thing = element_hash[xml_node.attribute_with_ns("id",
374
+ xmiNS.href).to_s]
375
+ base_realization_xmi_id = xml_node["base_Realization"]
376
+ this_thing.base_realization = element_hash[base_realization_xmi_id]
377
+ end
378
+
379
+ if ["DeriveReqt", "refine", "trace", "Copy", "Verify", "Allocate",
380
+ ""].include? xml_node.name.to_s
381
+ this_thing = element_hash[xml_node.attribute_with_ns("id",
382
+ xmiNS.href).to_s]
383
+ base_abstraction_xmi_id = xml_node["base_Abstraction"]
384
+ this_thing.base_abstraction = element_hash[base_abstraction_xmi_id]
385
+ end
386
+
387
+ if xml_node.attribute_with_ns("type",
388
+ xmiNS.href).to_s == "uml:Association"
389
+ this_thing = element_hash[xml_node.attribute_with_ns("id",
390
+ xmiNS.href).to_s]
391
+ member_end_list = xml_node.xpath("./memberEnd")
392
+ for item in member_end_list
393
+ this_thing.member_end.push element_hash[item["idref"]]
394
+ end
395
+ owned_end_list = xml_node.xpath("./ownedEnd")
396
+ for item in owned_end_list
397
+ this_thing.owned_end.push element_hash[item.attribute_with_ns("id",
398
+ xmiNS.href).to_s]
399
+ end
400
+ end
401
+
402
+ if (["uml:Property", "uml:Port"].include?(xml_node.attribute_with_ns("type",
403
+ xmiNS.href).to_s)) && not ["definingFeature", "partWithPort", "propertyPath",
404
+ "role"].include? xml_node.name.to_s
405
+ this_thing = element_hash[xml_node.attribute_with_ns("id",
406
+ xmiNS.href).to_s]
407
+ if !xml_node["association"].nil?
408
+ this_thing.association = element_hash[xml_node["association"]]
409
+ end
410
+ if !xml_node["aggregation"].nil?
411
+ this_thing.aggregation = xml_node["aggregation"]
412
+ end
413
+ if !xml_node["visibility"].nil?
414
+ this_thing.visibility = xml_node["visibility"]
415
+ end
416
+
417
+ if !xml_node.at("lowerValue").nil?
418
+
419
+ this_thing.lowerValue = if xml_node.at("lowerValue")["value"] == nil
420
+ "0"
421
+ else
422
+ xml_node.at("lowerValue")["value"]
423
+ end
424
+ end
425
+ if !xml_node.at("upperValue").nil?
426
+ this_thing.upperValue = xml_node.at("upperValue")["value"]
427
+ end
428
+ end
429
+
430
+ if xml_node.attribute_with_ns("type",
431
+ xmiNS.href).to_s == "uml:Connector"
432
+ this_thing = element_hash[xml_node.attribute_with_ns("id",
433
+ xmiNS.href).to_s]
434
+ connector_end_list = xml_node.xpath("./end")
435
+ for end_xml_node in connector_end_list
436
+ this_thing.connector_end.push element_hash[end_xml_node.attribute_with_ns(
437
+ "id", xmiNS.href
438
+ ).to_s]
439
+ end
440
+ end
441
+
442
+ if xml_node.attribute_with_ns("type",
443
+ xmiNS.href).to_s == "uml:ConnectorEnd"
444
+ this_thing = element_hash[xml_node.attribute_with_ns("id",
445
+ xmiNS.href).to_s]
446
+ this_thing.connector = element_hash[xml_node.parent.attribute_with_ns("id",
447
+ xmiNS.href).to_s]
448
+ this_thing.role = element_hash[xml_node["role"]]
449
+ if this_thing.role == nil
450
+ this_thing.role = element_hash[xml_node.at("role")["href"]]
451
+ end
452
+ this_thing.part_with_port = element_hash[xml_node["part_with_port"]]
453
+ end
454
+ end
455
+ end
456
+ end
417
457
  end