Class: Lutaml::SysMl::XmiFile

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/sysml/xmi_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeXmiFile

Returns a new instance of XmiFile.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/lutaml/sysml/xmi_file.rb', line 11

def initialize
	@package_list = []
	@model_list = []
	@class_list = []
	@activity_list = []
	@property_list = []
	@port_list = []
	@datatype_list = []
	@instance_list = []
	@realization_list = []
	@abstraction_list = []
	@association_list = []
	@connector_list = []
	@connectorend_list = []
	@constraint_list = []

	@block_list = []
	@constraintblock_list = []
	@requirement_list = []
	@testcase_list = []
	@binding_connector_list = []
	@nested_connectorend_list = []
	@derive_requirement_list = []
	@refine_requirement_list = []
	@trace_requirement_list = []
	@copy_requirement_list = []
	@verify_requirement_list = []
	@satisfy_requirement_list = []
	@allocate_requirement_list = []

	@element_hash = Hash.new
end

Instance Attribute Details

#abstraction_listObject

Returns the value of attribute abstraction_list.



5
6
7
# File 'lib/lutaml/sysml/xmi_file.rb', line 5

def abstraction_list
  @abstraction_list
end

#activity_listObject

Returns the value of attribute activity_list.



5
6
7
# File 'lib/lutaml/sysml/xmi_file.rb', line 5

def activity_list
  @activity_list
end

#allocate_requirement_listObject

Returns the value of attribute allocate_requirement_list.



5
6
7
# File 'lib/lutaml/sysml/xmi_file.rb', line 5

def allocate_requirement_list
  @allocate_requirement_list
end

#association_listObject

Returns the value of attribute association_list.



5
6
7
# File 'lib/lutaml/sysml/xmi_file.rb', line 5

def association_list
  @association_list
end

#binding_connector_listObject

Returns the value of attribute binding_connector_list.



5
6
7
# File 'lib/lutaml/sysml/xmi_file.rb', line 5

def binding_connector_list
  @binding_connector_list
end

#block_listObject

Returns the value of attribute block_list.



5
6
7
# File 'lib/lutaml/sysml/xmi_file.rb', line 5

def block_list
  @block_list
end

#class_listObject

Returns the value of attribute class_list.



5
6
7
# File 'lib/lutaml/sysml/xmi_file.rb', line 5

def class_list
  @class_list
end

#connector_listObject

Returns the value of attribute connector_list.



5
6
7
# File 'lib/lutaml/sysml/xmi_file.rb', line 5

def connector_list
  @connector_list
end

#connectorend_listObject

Returns the value of attribute connectorend_list.



5
6
7
# File 'lib/lutaml/sysml/xmi_file.rb', line 5

def connectorend_list
  @connectorend_list
end

#constraint_listObject

Returns the value of attribute constraint_list.



5
6
7
# File 'lib/lutaml/sysml/xmi_file.rb', line 5

def constraint_list
  @constraint_list
end

#constraintblock_listObject

Returns the value of attribute constraintblock_list.



5
6
7
# File 'lib/lutaml/sysml/xmi_file.rb', line 5

def constraintblock_list
  @constraintblock_list
end

#copy_requirement_listObject

Returns the value of attribute copy_requirement_list.



5
6
7
# File 'lib/lutaml/sysml/xmi_file.rb', line 5

def copy_requirement_list
  @copy_requirement_list
end

#datatype_listObject

Returns the value of attribute datatype_list.



5
6
7
# File 'lib/lutaml/sysml/xmi_file.rb', line 5

def datatype_list
  @datatype_list
end

#derive_requirement_listObject

Returns the value of attribute derive_requirement_list.



5
6
7
# File 'lib/lutaml/sysml/xmi_file.rb', line 5

def derive_requirement_list
  @derive_requirement_list
end

#element_hashObject

Returns the value of attribute element_hash.



5
6
7
# File 'lib/lutaml/sysml/xmi_file.rb', line 5

def element_hash
  @element_hash
end

#instance_listObject

Returns the value of attribute instance_list.



5
6
7
# File 'lib/lutaml/sysml/xmi_file.rb', line 5

def instance_list
  @instance_list
end

#model_listObject

Returns the value of attribute model_list.



5
6
7
# File 'lib/lutaml/sysml/xmi_file.rb', line 5

def model_list
  @model_list
end

#nested_connectorend_listObject

Returns the value of attribute nested_connectorend_list.



5
6
7
# File 'lib/lutaml/sysml/xmi_file.rb', line 5

def nested_connectorend_list
  @nested_connectorend_list
end

#package_listObject

Returns the value of attribute package_list.



5
6
7
# File 'lib/lutaml/sysml/xmi_file.rb', line 5

def package_list
  @package_list
end

#port_listObject

Returns the value of attribute port_list.



5
6
7
# File 'lib/lutaml/sysml/xmi_file.rb', line 5

def port_list
  @port_list
end

#property_listObject

Returns the value of attribute property_list.



5
6
7
# File 'lib/lutaml/sysml/xmi_file.rb', line 5

def property_list
  @property_list
end

#realization_listObject

Returns the value of attribute realization_list.



5
6
7
# File 'lib/lutaml/sysml/xmi_file.rb', line 5

def realization_list
  @realization_list
end

#refine_requirement_listObject

Returns the value of attribute refine_requirement_list.



5
6
7
# File 'lib/lutaml/sysml/xmi_file.rb', line 5

def refine_requirement_list
  @refine_requirement_list
end

#requirement_listObject

Returns the value of attribute requirement_list.



5
6
7
# File 'lib/lutaml/sysml/xmi_file.rb', line 5

def requirement_list
  @requirement_list
end

#satisfy_requirement_listObject

Returns the value of attribute satisfy_requirement_list.



5
6
7
# File 'lib/lutaml/sysml/xmi_file.rb', line 5

def satisfy_requirement_list
  @satisfy_requirement_list
end

#testcase_listObject

Returns the value of attribute testcase_list.



5
6
7
# File 'lib/lutaml/sysml/xmi_file.rb', line 5

def testcase_list
  @testcase_list
end

#trace_requirement_listObject

Returns the value of attribute trace_requirement_list.



5
6
7
# File 'lib/lutaml/sysml/xmi_file.rb', line 5

def trace_requirement_list
  @trace_requirement_list
end

#verify_requirement_listObject

Returns the value of attribute verify_requirement_list.



5
6
7
# File 'lib/lutaml/sysml/xmi_file.rb', line 5

def verify_requirement_list
  @verify_requirement_list
end

Instance Method Details

#parse(filename) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
# File 'lib/lutaml/sysml/xmi_file.rb', line 44

def parse (filename)
	xmifile = File.new(filename, "r")
	inxml = Nokogiri::XML(xmifile)

	xmi_elements = inxml.xpath('//xmi:XMI')
	if xmi_elements.size == 0
		puts "ERROR : File contains no 'xmi:XMI' XML elements :  #{filename}, may not be XMI file."
		xmifile.close
		exit
	end

	#setup xmi namespace
	xmiNS = inxml.root.namespace_definitions.find{|ns| ns.prefix=="xmi"}

	## Step 1: Find UML and SysML Core Objects in XMI file and create as instance of metamodel

	for xml_node in inxml.xpath('//*' )
		element_new = nil

		if xml_node.name.to_s == 'packagedElement' and xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:Package'
			element_new = Lutaml::Uml::Package.new
			package_list.push element_new
		end

		if xml_node.name.to_s == 'Model'
			element_new = Lutaml::Uml::Model.new
			model_list.push element_new
			element_new.viewpoint = xml_node['viewpoint']
			element_new.href = xml_node['href']
		end

		if xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:Class'
			element_new = Lutaml::Uml::Class.new
			if xml_node['isAbstract'] != nil
				element_new.is_abstract = xml_node['isAbstract'] == 'true'
			end
			class_list.push element_new
		end

		if xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:Activity'
			element_new = Lutaml::Uml::Activity.new
			activity_list.push element_new
		end

		if xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:Property'
			element_new = Lutaml::Uml::Property.new
			property_list.push element_new
		end

		if xml_node.attribute_with_ns('type',xmiNS.href).to_s== 'uml:InstanceSpecification'
			element_new = Lutaml::Uml::Instance.new
			instance_list.push element_new
		end

		if xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:DataType'
			element_new = Lutaml::Uml::DataType.new
			datatype_list.push element_new
		end

		if xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:Port'
			element_new = Lutaml::Uml::Port.new
			port_list.push element_new
		end

		if xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:Connector'
			element_new = Lutaml::Uml::Connector.new
			connector_list.push element_new
		end

		if xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:ConnectorEnd'
			element_new = Lutaml::Uml::ConnectorEnd.new
			connectorend_list.push element_new
		end

		if xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:Constraint'
			element_new = Lutaml::Uml::Constraint.new
			constraint_list.push element_new
		end

		if xml_node.name.to_s == 'Block'
			element_new = SYSML::Block.new
			block_list.push element_new
		end

		if xml_node.name.to_s == 'Template'
			element_new = SYSML::Block.new
			block_list.push element_new
		end

		if xml_node.name.to_s == 'ConstraintBlock'
			element_new = SYSML::ConstraintBlock.new
			constraintblock_list.push element_new
		end

		if xml_node.name.to_s.index('Requirement') or xml_node.name.to_s == 'designConstraint'
			if xml_node.name.to_s != 'RequirementRelated'
				element_new = SYSML::Requirement.new
				requirement_list.push element_new
				element_new.id = xml_node.attribute_with_ns('id',xmiNS.href).to_s.strip
				element_new.text = xml_node['Text']
				if xml_node.name != 'Requirement'
					element_new.stereotype.push xml_node.name
				end
			end
		end

		if xml_node.name.to_s == 'TestCase'
			element_new = SYSML::TestCase.new
			testcase_list.push element_new
		end

		if xml_node.name.to_s == 'BindingConnector'
			element_new = SYSML::BindingConnector.new
			binding_connector_list.push element_new
		end

		if xml_node.name.to_s == 'NestedConnectorEnd'
			element_new = SYSML::NestedConnectorEnd.new
			nested_connectorend_list.push element_new
		end

		if xml_node.name.to_s == 'DeriveReqt'
			element_new = SYSML::DeriveRequirement.new
			derive_requirement_list.push element_new
		end
		if xml_node.name.to_s == 'refine'
			element_new = SYSML::Refine.new
			refine_requirement_list.push element_new
		end
		if xml_node.name.to_s == 'trace'
			element_new = SYSML::Trace.new
			trace_requirement_list.push element_new
		end
		if xml_node.name.to_s == 'Copy'
			element_new = SYSML::Copy.new
			copy_requirement_list.push element_new
		end
		if xml_node.name.to_s == 'Verify'
			element_new = SYSML::Verify.new
			verify_requirement_list.push element_new
		end
		if xml_node.name.to_s == 'Allocate'
			element_new = SYSML::Allocate.new
			allocate_requirement_list.push element_new
		end

		if xml_node.name.to_s == 'Satisfy'
			element_new = SYSML::Satisfy.new
			satisfy_requirement_list.push element_new
		end

		if xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:Abstraction'
			element_new = Lutaml::Uml::Abstraction.new
			abstraction_list.push element_new
		end

		if xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:Realization'
			element_new = Lutaml::Uml::Realization.new
			realization_list.push element_new
		end

		if xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:Association'
			element_new = Lutaml::Uml::Association.new
			association_list.push element_new
		end

		if element_new != nil
			new_xmi_id_node = xml_node.attribute_with_ns('id',xmiNS.href)
			new_xmi_uuid_node = xml_node.attribute_with_ns('uuid',xmiNS.href)
			new_name_node = xml_node['name']
			new_href_node = xml_node['href']

			if new_xmi_id_node != nil
				element_new.xmi_id = new_xmi_id_node.to_s
				element_hash[element_new.xmi_id] = element_new
			end

			if new_xmi_uuid_node != nil
				element_new.xmi_uuid = new_xmi_uuid_node.to_s
			end

			if new_name_node != nil
				element_new.name = xml_node['name'].strip
			end

			if new_href_node != nil
				element_new.href = new_href_node.to_s
				if new_xmi_id_node == nil
					element_hash[element_new.href] = element_new
				end
				if xml_node.at('xmi:Extension/referenceExtension') != nil
					element_new.name = xml_node.at('xmi:Extension/referenceExtension')['referentPath']
				end
			end

			if (xml_node.parent != nil and
					xml_node.parent.attribute_with_ns('id',xmiNS.href) != nil and
					element_hash[xml_node.parent.attribute_with_ns('id',xmiNS.href).to_s] != nil)

				parent = element_hash[xml_node.parent.attribute_with_ns('id',xmiNS.href).to_s]
				element_new.namespace = parent
				if parent.kind_of? Lutaml::Uml::Package
					parent.contents.push element_new
				end
			end
		end
	end

	for xml_node in inxml.xpath('//*')

		if (xml_node.attribute_with_ns('id',xmiNS.href) != nil and
			element_hash[xml_node.attribute_with_ns('id',xmiNS.href).to_s] != nil)

			this_thing = element_hash[xml_node.attribute_with_ns('id',xmiNS.href).to_s]
		end

		if xml_node.name.to_s == 'nestedClassifier' and xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:Class'
			owning_class_xmi_id = xml_node.parent.attribute_with_ns('id',xmiNS.href).to_s
			owned_class_xmi_id = xml_node.attribute_with_ns('id',xmiNS.href).to_s
			owning_class = element_hash[owning_class_xmi_id]
			owned_class = element_hash[owned_class_xmi_id]
			owning_class.nested_classifier.push owned_class
		end

		if xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:Realization'
			this_thing = element_hash[xml_node.attribute_with_ns('id',xmiNS.href).to_s]
			supplier_xmi_id = xml_node.at('supplier')['idref']
			client_xmi_id = xml_node.at('client')['idref']
			this_thing.supplier.push element_hash[supplier_xmi_id]
			this_thing.client.push element_hash[client_xmi_id]
		end

		if xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:Abstraction'
			this_thing = element_hash[xml_node.attribute_with_ns('id',xmiNS.href).to_s]
			supplier_xmi_id = xml_node.at('supplier')['idref']
			client_xmi_id = xml_node.at('client')['idref']
			this_thing.supplier.push element_hash[supplier_xmi_id]
			this_thing.client.push element_hash[client_xmi_id]
		end

		if xml_node.name.to_s == 'Block'
			this_thing = element_hash[xml_node.attribute_with_ns('id',xmiNS.href).to_s]
			base_class_xmi_id = xml_node['base_Class']
			this_thing.base_class = element_hash[base_class_xmi_id]
		end

		if xml_node.name.to_s == 'Template'
			this_thing = element_hash[xml_node.attribute_with_ns('id',xmiNS.href).to_s]
			base_class_xmi_id = xml_node['base_Class']
			this_thing.base_class = element_hash[base_class_xmi_id]
			this_thing.base_class.stereotype.push 'Template'
		end

		if xml_node.name.to_s == 'ConstraintBlock'
			this_thing = element_hash[xml_node.attribute_with_ns('id',xmiNS.href).to_s]
			base_class_xmi_id = xml_node['base_Class']
			this_thing.base_class = element_hash[base_class_xmi_id]
		end

	if xml_node.name.to_s.index('Requirement') or xml_node.name.to_s == 'designConstraint'
			if xml_node.name.to_s != 'RequirementRelated'
				this_thing = element_hash[xml_node.attribute_with_ns('id',xmiNS.href).to_s]
				base_class_xmi_id = xml_node['base_Class']
				this_thing.base_class = element_hash[base_class_xmi_id]
				this_thing.refined_by = element_hash[xml_node['RefinedBy']]
				this_thing.derived_from = element_hash[xml_node['DerivedFrom']]
				this_thing.traced_to = element_hash[xml_node['TracedTo']]
			end
		end

		if xml_node.name.to_s == 'TestCase'
			this_thing = element_hash[xml_node.attribute_with_ns('id',xmiNS.href).to_s]
			this_thing.base_behavior = element_hash[xml_node['base_Behavior']]
			this_thing.verifies = element_hash[xml_node['Verifies']]
		end

		if xml_node.name.to_s == 'BindingConnector'
			this_thing = element_hash[xml_node.attribute_with_ns('id',xmiNS.href).to_s]
			base_connector_xmi_id = xml_node['base_Connector']
			this_thing.base_connector = element_hash[base_connector_xmi_id]
		end

		if xml_node.name.to_s == 'NestedConnectorEnd'
			this_thing = element_hash[xml_node.attribute_with_ns('id',xmiNS.href).to_s]
			base_connectorend_xmi_id = xml_node['base_ConnectorEnd']
			this_thing.base_connectorend = element_hash[base_connectorend_xmi_id]
			if xml_node['propertyPath'] != nil
				this_thing.property_path.push element_hash[xml_node['propertyPath']]
			else
				for prop_path in xml_node.xpath('./propertyPath')
					#to deal with href = '#xmi:id' i.e. local references
					href_parts = prop_path['href'].split('#')
					if href_parts[0].size == 0
						prop = element_hash[href_parts[1]]
					else
						prop = element_hash[prop_path['href']]
					end
					this_thing.property_path.push prop
				end
			end
		end

		if xml_node.name.to_s == 'Satisfy'
			this_thing = element_hash[xml_node.attribute_with_ns('id',xmiNS.href).to_s]
			base_realization_xmi_id = xml_node['base_Realization']
			this_thing.base_realization = element_hash[base_realization_xmi_id]
		end

		if ['DeriveReqt', 'refine', 'trace', 'Copy', 'Verify', 'Allocate', ''].include? xml_node.name.to_s
			this_thing = element_hash[xml_node.attribute_with_ns('id',xmiNS.href).to_s]
			base_abstraction_xmi_id = xml_node['base_Abstraction']
			this_thing.base_abstraction = element_hash[base_abstraction_xmi_id]
		end

		if xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:Association'
			this_thing = element_hash[xml_node.attribute_with_ns('id',xmiNS.href).to_s]
			member_end_list = xml_node.xpath('./memberEnd')
			for item in member_end_list
				this_thing.member_end.push element_hash[item['idref']]
			end
			owned_end_list = xml_node.xpath('./ownedEnd')
			for item in owned_end_list
				this_thing.owned_end.push element_hash[item.attribute_with_ns('id',xmiNS.href).to_s]
			end
		end

		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'
			if not ['definingFeature', 'partWithPort', 'propertyPath', 'role'].include? xml_node.name.to_s
				this_thing = element_hash[xml_node.attribute_with_ns('id',xmiNS.href).to_s]
				if xml_node['association'] != nil
					this_thing.association = element_hash[xml_node['association']]
				end
				if xml_node['aggregation'] != nil
					this_thing.aggregation = xml_node['aggregation']
				end
				if xml_node['visibility'] != nil
					this_thing.visibility = xml_node['visibility']
				end

				if xml_node.at('lowerValue') != nil

					if xml_node.at('lowerValue')['value'] != nil
						this_thing.lowerValue = xml_node.at('lowerValue')['value']
					else
						this_thing.lowerValue = '0'
					end
				end
				if xml_node.at('upperValue') != nil
					this_thing.upperValue = xml_node.at('upperValue')['value']
				end
			end
		end

		if xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:Connector'
			this_thing = element_hash[xml_node.attribute_with_ns('id',xmiNS.href).to_s]
			connector_end_list = xml_node.xpath('./end')
			for end_xml_node in connector_end_list
				this_thing.connector_end.push element_hash[end_xml_node.attribute_with_ns('id',xmiNS.href).to_s]
			end
		end

		if xml_node.attribute_with_ns('type',xmiNS.href).to_s == 'uml:ConnectorEnd'
			this_thing = element_hash[xml_node.attribute_with_ns('id',xmiNS.href).to_s]
			this_thing.connector = element_hash[xml_node.parent.attribute_with_ns('id',xmiNS.href).to_s]
			this_thing.role = element_hash[xml_node['role']]
			if this_thing.role == nil
				this_thing.role = element_hash[xml_node.at('role')['href']]
			end
			this_thing.part_with_port = element_hash[xml_node['part_with_port']]
		end
	end
end