Class: XmiHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/xmimodel/xmihelper.rb

Overview

A helper for working with XMI files.

Author

Marcus Siqueira ([email protected])

License

Distributes under the same terms as Ruby

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeXmiHelper

Constructor.


13
14
# File 'lib/xmimodel/xmihelper.rb', line 13

def initialize
end

Class Method Details

.action_states(tag) ⇒ Object

Get all the Action State in the tag.

Action State is a representation of an action on a Activity Graph.

The parameter 'tag' needs be a Nokogiri::XML::Element of type 'UML:ActivityGraph'.

Returns an array of objects Nokogiri::XML::Element of type 'UML:ActionState'.

See also:

  • call_events

Raises:

  • (ArgumentError)

27
28
29
30
# File 'lib/xmimodel/xmihelper.rb', line 27

def self.action_states(tag)
	raise ArgumentError.new("Parameter is not a UML:ActivityGraph.") if tag.nil? || tag.name != "ActivityGraph"
	tag.xpath('./UML:StateMachine.top/UML:CompositeState/UML:CompositeState.subvertex/UML:ActionState')		
end

.activity_graph_by_name(document, name) ⇒ Object

Get the Activity Graph by name.

The parameter 'document' can be any Nokogiri::XML::Element of model.

The parameter 'name' cannot be empty.

Returns a object Nokogiri::XML::Element of type 'UML:ActivityGraph'.


40
41
42
# File 'lib/xmimodel/xmihelper.rb', line 40

def self.activity_graph_by_name(document, name)
	tag_by_name(xmi_content(document), "UML:ActivityGraph", name)
end

.activity_graphs(tag) ⇒ Object

Get all the Activity Graphs in the tag.

The parameter 'tag' can be any Nokogiri::XML::Element that contains the tag 'UML:Namespace.ownedElement'.

Returns a object Nokogiri::XML::Element of type 'UML:ActivityGraph'.


50
51
52
# File 'lib/xmimodel/xmihelper.rb', line 50

def self.activity_graphs(tag)
	namespace(tag).xpath('./UML:ActivityGraph')
end

.add_namespace(xml) ⇒ Object

Add a tag UML:Namespace.ownedElement to the parameter xml


57
58
59
60
61
# File 'lib/xmimodel/xmihelper.rb', line 57

def self.add_namespace(xml)
	xml_namespace = Nokogiri::XML::Node.new('Namespace.ownedElement', xml.document)
	xml << xml_namespace
	return xml_namespace
end

.all_associations(tag) ⇒ Object

Get all the Associations in the model.

The parameter 'tag' can be any Nokogiri::XML::Element of model.

Returns an array of all objects Nokogiri::XML::Element of type 'UML:Association'.


69
70
71
# File 'lib/xmimodel/xmihelper.rb', line 69

def self.all_associations(tag)
	xmi_content(tag).xpath("//UML:Association")
end

.all_generalizations(tag) ⇒ Object

Get all the Generalizations in the model.

The parameter 'tag' can be any Nokogiri::XML::Element of model.

Returns an array of all objects 'Nokogiri::XML::Element' of type 'UML:Generalization'.


79
80
81
# File 'lib/xmimodel/xmihelper.rb', line 79

def self.all_generalizations(tag)		
	xmi_content(tag).xpath('//UML:Namespace.ownedElement/UML:Generalization')
end

.all_packages(tag) ⇒ Object

Get all the Packages in the model.

The parameter 'tag' can be any Nokogiri::XML::Element of model.

Returns an array of all objects 'Nokogiri::XML::Element' of type 'UML:Package'.


89
90
91
# File 'lib/xmimodel/xmihelper.rb', line 89

def self.all_packages(tag)
	xmi_content(tag).xpath('//UML:Namespace.ownedElement/UML:Package')
end

.associations(tag) ⇒ Object

Get all the Associations in the model.

The parameter 'tag' can be any Nokogiri::XML::Element that contains the tag 'UML:Namespace.ownedElement'.

Returns an array of objects 'Nokogiri::XML::Element' of type 'UML:Association'.


99
100
101
# File 'lib/xmimodel/xmihelper.rb', line 99

def self.associations(tag)
	namespace(tag).xpath("./UML:Association")
end

.associations_by_participant_id(tag, id) ⇒ Object

Get the Associations by id of the any participants of relationship.

The parameter 'tag' can be any Nokogiri::XML::Element of model.

Returns an array of objects 'Nokogiri::XML::Element' of type 'UML:Association'.


109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/xmimodel/xmihelper.rb', line 109

def self.associations_by_participant_id(tag, id)
	
	associations = Array.new

	xmi_content(tag).xpath('//UML:Association').each do |a|

		a.xpath( "./UML:Association.connection/UML:AssociationEnd").each do |ae|
			participant_id = participant_id_by_association_end(ae)

			if (!participant_id.nil?) && participant_id.to_s.eql?(id.to_s) && !associations.include?(a)
				associations << a 
			end
		end	
	end

	return associations		
end

.attribute_by_id(document, id) ⇒ Object

Get the attribute of a class by identification

Returns a object 'Nokogiri::XML::Element' of type UML:Attribute


139
140
141
# File 'lib/xmimodel/xmihelper.rb', line 139

def self.attribute_by_id(document, id)
	type = tag_by_id(document, 'UML:Attribute', id)
end

.attribute_by_name(uml_class, name) ⇒ Object

Get the attribute of a class by name

Returns a object 'Nokogiri::XML::Element' of type UML:Attribute


147
148
149
# File 'lib/xmimodel/xmihelper.rb', line 147

def self.attribute_by_name(uml_class, name)
	tag_by_name(uml_class, "UML:Attribute", name)
end

.attribute_initial_value(uml_attribute) ⇒ Object

Get the initial value of an attribute

Returns a String with the value

Raises:

  • (ArgumentError)

155
156
157
158
159
160
161
162
163
164
# File 'lib/xmimodel/xmihelper.rb', line 155

def self.attribute_initial_value(uml_attribute)
	raise ArgumentError.new("Parameter is not a UML:Attribute tag.") if uml_attribute.name != "Attribute"
	uml_expression = uml_attribute.at_xpath('./UML:Attribute.initialValue/UML:Expression')
	
	if uml_expression.nil?
		return ''
	else 
		return uml_expression.attribute('body').to_s.strip
	end
end

.attribute_type(uml_attribute) ⇒ Object

Return a object 'Nokogiri::XML::Element' of type 'UML:Class' or 'UML:DataType' or a String

Raises:

  • (ArgumentError)

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
# File 'lib/xmimodel/xmihelper.rb', line 168

def self.attribute_type(uml_attribute)
	raise ArgumentError.new("Parameter is not a 'UML:Attribute' or 'UML:Parameter' tag.") if uml_attribute.name != "Attribute" && uml_attribute.name != "Parameter"
	type = uml_attribute.attribute('type').to_s	# Se não possuir o atributo tipo, verifica se possui a tag abaixo com o tipo primitivo		

	if type.nil? || type.empty?

		uml_type = uml_attribute.at_xpath('./UML:StructuralFeature.type/UML:Classifier/XMI.extension/referentPath')
		type = uml_type.attribute('xmi.value').to_s unless uml_type.nil?

		if type.nil? || type.empty?
			uml_type = uml_attribute.at_xpath('./UML:Parameter.type/UML:Classifier/XMI.extension/referentPath')
			type = uml_type.attribute('xmi.value').to_s unless uml_type.nil?
		end

	else
		id = type
		xmi_content = xmi_content(uml_attribute)
		
		clazz = class_by_id(xmi_content, id)
		return clazz unless clazz.nil?

		enum = enumeration_by_id(xmi_content, id)
		return enum unless enum.nil?

		data_type = data_type_by_id(xmi_content, id)
		return data_type unless data_type.nil?

		primitive = primitive_by_id(xmi_content, id)
		return primitive.attribute('name').to_s unless primitive.nil?			
	end		
	type
end

.attribute_type_name(uml_attribute) ⇒ Object


201
202
203
204
205
206
207
208
209
210
211
# File 'lib/xmimodel/xmihelper.rb', line 201

def self.attribute_type_name(uml_attribute)
	type = attribute_type(uml_attribute)
	return nil if type.nil?
	return type if type.class.to_s.eql?("String")
	if type.class.to_s.eql?("Nokogiri::XML::Element") 
		return type.attribute("name").to_s if type.name == "DataType"
		return full_class_name(type) if type.name == "Class"
		return full_enumeration_name(type) if type.name == "Enumeration"
	end
	nil
end

.attributes(uml_class) ⇒ Object

Get the attributes of a class.

Returns an array of objects 'Nokogiri::XML::Element' of type UML:Attribute


131
132
133
# File 'lib/xmimodel/xmihelper.rb', line 131

def self.attributes(uml_class)
	uml_class.xpath('./UML:Classifier.feature/UML:Attribute')
end

.call_events(tag) ⇒ Object

Call Events are links between ActionStates (by deferrableEvent propertie) and Operations (methods of a class).

Call Events are actions triggered by a state.

See:

  • action_states

  • operations

  • signal_events


222
223
224
225
226
# File 'lib/xmimodel/xmihelper.rb', line 222

def self.call_events(tag)
	#raise ArgumentError.new("Parameter is not a UML:UseCase tag (#{tag.name}).") if tag.name != "UseCase"
	#tag.xpath('./UML:Classifier.feature/UML:CallEvent')
	namespace(tag).xpath('./UML:CallEvent')
end

.class_by_full_name(document, full_name) ⇒ Object


228
229
230
231
232
233
234
235
236
237
# File 'lib/xmimodel/xmihelper.rb', line 228

def self.class_by_full_name(document, full_name)

	class_name = full_name.split(".").last
	package_name = full_name.clone
	package_name["." + class_name] = ""

	package_xml = package_by_full_name(xmi_content(document), package_name)
	package_xml.at_xpath("./UML:Namespace.ownedElement/UML:Class[@name='#{class_name}']")

end

.class_by_id(document, id) ⇒ Object


239
240
241
# File 'lib/xmimodel/xmihelper.rb', line 239

def self.class_by_id(document, id)
	tag_by_id(document, 'UML:Class', id)
end

.class_by_name(document, name) ⇒ Object


243
244
245
# File 'lib/xmimodel/xmihelper.rb', line 243

def self.class_by_name(document, name)
	tag_by_name(xmi_content(document), "UML:Class", name)
end

.classes(tag) ⇒ Object


247
248
249
# File 'lib/xmimodel/xmihelper.rb', line 247

def self.classes(tag)
	namespace(tag).xpath("./UML:Class")
end

.classes_by_association(document, association) ⇒ Object

Raises:

  • (ArgumentError)

251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/xmimodel/xmihelper.rb', line 251

def self.classes_by_association(document, association)		
	raise ArgumentError.new("Parameter is not a UML:Association tag.") if association.name != 'Association'

	classes = Array.new

	association.xpath( "./UML:Association.connection/UML:AssociationEnd").each do |ae|
		participant_id = participant_id_by_association_end(ae)
		clazz = class_by_id(xmi_content(document), participant_id) unless participant_id.nil? 
		classes << clazz unless clazz.nil?
	end

	classes
end

.data_type_by_id(document, id) ⇒ Object


265
266
267
# File 'lib/xmimodel/xmihelper.rb', line 265

def self.data_type_by_id(document, id)
	tag_by_id(document, 'UML:DataType', id)
end

.data_types(tag) ⇒ Object


269
270
271
# File 'lib/xmimodel/xmihelper.rb', line 269

def self.data_types(tag)
	namespace(tag).xpath("./UML:DataType")		
end

.enumeration_by_id(document, id) ⇒ Object


277
278
279
# File 'lib/xmimodel/xmihelper.rb', line 277

def self.enumeration_by_id(document, id)
	tag_by_id(document, 'UML:Enumeration', id)
end

.enumerations(tag) ⇒ Object


273
274
275
# File 'lib/xmimodel/xmihelper.rb', line 273

def self.enumerations(tag)
	namespace(tag).xpath("./UML:Enumeration")
end

.exporter(document) ⇒ Object


281
282
283
# File 'lib/xmimodel/xmihelper.rb', line 281

def self.exporter(document)
	@exporter = document.at_xpath("./XMI/XMI.header/XMI.documentation/XMI.exporter").inner_html
end

.exporter_version(document) ⇒ Object


285
286
287
# File 'lib/xmimodel/xmihelper.rb', line 285

def self.exporter_version(document)
	@exporter_version = document.at_xpath("./XMI/XMI.header/XMI.documentation/XMI.exporterVersion").inner_html
end

.extension_referent_path_value(tag) ⇒ Object

Raises:

  • (ArgumentError)

293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
# File 'lib/xmimodel/xmihelper.rb', line 293

def self.extension_referent_path_value(tag)
	return "" if tag.nil?

	if tag.name != 'XMI.extension'
		tag = tag.at_xpath("./XMI.extension")
	end
	return "" if tag.nil?

	raise ArgumentError.new("Parameter is not a XMI.extension tag or a tag that contains.") if tag.name != 'XMI.extension'
	
	referent_path = tag.at_xpath("./referentPath")
	if referent_path.nil?
		return ""
	else
		return referent_path.attribute("xmi.value").to_s
	end
end

.final_states(tag) ⇒ Object

Raises:

  • (ArgumentError)

686
687
688
689
# File 'lib/xmimodel/xmihelper.rb', line 686

def self.final_states(tag)
	raise ArgumentError.new("Parameter is not a UML:ActivityGraph tag.") if tag.nil? || tag.name != "ActivityGraph"
	tag.xpath('./UML:StateMachine.top/UML:CompositeState/UML:CompositeState.subvertex/UML:FinalState')		
end

.full_class_name(clazz) ⇒ Object

Raises:

  • (ArgumentError)

334
335
336
337
338
339
340
341
342
# File 'lib/xmimodel/xmihelper.rb', line 334

def self.full_class_name(clazz)
	raise ArgumentError.new("Parameter cannot be nil..") if clazz.nil?
	package = parent_package(clazz)
	if package.nil?
		clazz.attribute("name") 
	else
		full_package_name(package) + "." + clazz.attribute("name")
	end
end

.full_enumeration_name(enumeration) ⇒ Object

Raises:

  • (ArgumentError)

344
345
346
347
348
349
350
351
352
# File 'lib/xmimodel/xmihelper.rb', line 344

def self.full_enumeration_name(enumeration)
	raise ArgumentError.new("Parameter cannot be nil..") if enumeration.nil?
	package = parent_package(enumeration)
	if package.nil?
		enumeration.attribute("name") 
	else
		full_package_name(package) + "." + enumeration.attribute("name")
	end
end

.full_package_name(package) ⇒ Object


354
355
356
357
358
359
360
361
362
363
364
# File 'lib/xmimodel/xmihelper.rb', line 354

def self.full_package_name(package)
	
	name = package.attribute("name").to_s
	begin
		package = parent_package(package)

		name = package.attribute("name").to_s + "." + name unless package.nil?
	end while !package.nil?

	name
end

.generalization_by_child(document, id) ⇒ Object


366
367
368
369
370
371
372
373
374
375
376
377
378
379
# File 'lib/xmimodel/xmihelper.rb', line 366

def self.generalization_by_child(document, id)
	
	xmi_content(document).xpath('//UML:Generalization').each do |g|
		child = g.attribute('child')
		if child.nil?
			class_ref = g.at_xpath('./UML:Generalization.child/UML:Class')
			child = class_ref.attribute('xmi.idref') unless class_ref.nil?
		end

		return g if !child.nil? && id == child.to_s
	end

	nil
end

.generalization_child(generalization) ⇒ Object

Returns the child id from the tag 'UML:Generalization'


383
384
385
386
387
388
389
390
# File 'lib/xmimodel/xmihelper.rb', line 383

def self.generalization_child(generalization)
	child = generalization.attribute("child")
	if child.nil?
		class_ref = generalization.at_xpath('./UML:Generalization.child/UML:Class')
		child = class_ref.attribute('xmi.idref') unless class_ref.nil?
	end
	child.to_s
end

.generalization_parent(generalization) ⇒ Object

Returns the parent id from the tag 'UML:Generalization'


394
395
396
397
398
399
400
401
# File 'lib/xmimodel/xmihelper.rb', line 394

def self.generalization_parent(generalization)
	parent = generalization.attribute("parent")
	if parent.nil?
		class_ref = generalization.at_xpath('./UML:Generalization.parent/UML:Class')
		parent = class_ref.attribute('xmi.idref') unless class_ref.nil?
	end
	parent.to_s
end

.guard_condition(tag) ⇒ Object

Raises:

  • (ArgumentError)

403
404
405
406
407
408
409
410
411
412
413
# File 'lib/xmimodel/xmihelper.rb', line 403

def self.guard_condition(tag)
	
	return nil if tag.nil?
	if tag.name == "Transition"
		tag = tag.at_xpath("./UML:Transition.guard/UML:Guard")
	end

	return nil if tag.nil?
	raise ArgumentError.new("Parameter is not a UML:Guard OR UML:Transition tag.") if tag.name != "Guard"	
	tag.at_xpath('./UML:Guard.expression/UML:BooleanExpression')
end

.has_namespace?(tag) ⇒ Boolean

Returns:

  • (Boolean)

311
312
313
314
315
316
317
318
319
320
# File 'lib/xmimodel/xmihelper.rb', line 311

def self.has_namespace?(tag) 
	return false if tag.nil?
	if tag.name != "Namespace.ownedElement"
		tag = tag.at_xpath("./UML:Namespace.ownedElement")
	end
	if tag.nil? or tag.name != "Namespace.ownedElement"
		return false
	end
	return true
end

.metamodel_version(document) ⇒ Object


289
290
291
# File 'lib/xmimodel/xmihelper.rb', line 289

def self.metamodel_version(document)
	@metamodel_version = doc.at_xpath("./XMI/XMI.header/XMI.metamodel").attribute("xmi.version").to_s	
end

.multiplicity(tag) ⇒ Object


631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
# File 'lib/xmimodel/xmihelper.rb', line 631

def self.multiplicity(tag)
	return nil if tag.nil?

	case tag.name
	
	when "Attribute"
		uml_multiplicity = tag.at_xpath('./UML:StructuralFeature.multiplicity/UML:Multiplicity')

	when "AssociationEnd"
		uml_multiplicity = tag.at_xpath('./UML:AssociationEnd.multiplicity/UML:Multiplicity')
	else
		raise ArgumentError.new("Parameter is not a UML:Attribute or UML:AssociationEnd tag.") 
	end

	uml_multiplicity
end

.multiplicity_range(tag) ⇒ Object

Raises:

  • (ArgumentError)

648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
# File 'lib/xmimodel/xmihelper.rb', line 648

def self.multiplicity_range(tag)

	return nil if tag.nil?

	tag = multiplicity(tag) if (tag.name == "Attribute" || tag.name == "AssociationEnd")
	return nil if tag.nil?

	raise ArgumentError.new("Parameter is not a UML:Multiplicity tag.") if tag.name != "Multiplicity"		

	uml_multiplicity_range = tag.at_xpath('./UML:Multiplicity.range/UML:MultiplicityRange')
	
	if uml_multiplicity_range.nil?
		return nil
	else 
		return [Integer(uml_multiplicity_range.attribute('lower').to_s), Integer(uml_multiplicity_range.attribute('upper').to_s)]
	end
end

.namespace(tag) ⇒ Object

Raises:

  • (ArgumentError)

322
323
324
325
326
327
328
329
330
331
332
# File 'lib/xmimodel/xmihelper.rb', line 322

def self.namespace(tag)
	_tag = tag.name unless tag.nil?
	raise ArgumentError.new("Parameter '#{tag}' cannot be nil..") if tag.nil?
	if tag.name != "Namespace.ownedElement"
		tag = tag.at_xpath("./UML:Namespace.ownedElement")
	end
	if tag.nil? or tag.name != "Namespace.ownedElement"
		raise ArgumentError.new("Parameter '#{_tag}' does not contain a tag 'UML:Namespace.ownedElement'.")
	end
	tag	
end

.operation_by_id(document, id) ⇒ Object


672
673
674
# File 'lib/xmimodel/xmihelper.rb', line 672

def self.operation_by_id(document, id)
	tag_by_id(document, 'UML:Operation', id)
end

.operation_by_name(tag, name) ⇒ Object

Raises:

  • (ArgumentError)

676
677
678
679
# File 'lib/xmimodel/xmihelper.rb', line 676

def self.operation_by_name(tag, name)
	raise ArgumentError.new("Parameter is not a UML:Class tag.") if tag.nil? || tag.name != "Class"
	tag.at_xpath("./UML:Classifier.feature/UML:Operation[@name='#{name}']")
end

.operations(uml_class) ⇒ Object

Raises:

  • (ArgumentError)

666
667
668
669
670
# File 'lib/xmimodel/xmihelper.rb', line 666

def self.operations(uml_class)
	raise ArgumentError.new("Parameter is not a UML:Class tag (#{uml_class.name}).") if uml_class.name != "Class" && uml_class.name != "Enumeration"

	uml_class.xpath('./UML:Classifier.feature/UML:Operation')		
end

.package_by_full_name(document, full_package_name) ⇒ Object


449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
# File 'lib/xmimodel/xmihelper.rb', line 449

def self.package_by_full_name(document, full_package_name)
	package_name = full_package_name.split(".")

	if package_name.length >= 1
		package = package_by_name(xmi_content(document), package_name[0])

		for i in 1..package_name.length - 1
			return nil if (package == nil)

			package = package_by_name(package, package_name[i])
		end
		return package
	end

	nil
end

.package_by_name(tag, package_name) ⇒ Object


419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
# File 'lib/xmimodel/xmihelper.rb', line 419

def self.package_by_name(tag, package_name)

	# se passou um 'UML:Package' navega até o 'UML:Namespace.ownedElement' filho
	if tag.name == "Package"
		tag = tag.at_xpath("./UML:Namespace.ownedElement")
	end

	# deverá ser 'UML:Namespace.ownedElement' ou 'XMI.content'
	if !(tag.nil?) && (tag.name == "Namespace.ownedElement" || tag.name == "XMI.content")

		# procura pelo pacote
		tag.xpath('./UML:Package').each do |package|
			return package if package.attribute('name').to_s == package_name
		end

		# poderá ter uma tag './UML:Model' com mais 'UML:Namespace.ownedElement'
		tag.xpath("./UML:Model").each do |model|
	
			model.xpath('./UML:Namespace.ownedElement').each do |namespace|

				# procura recursivamente dentro do namespace
				p = package_by_name(namespace, package_name)
				return p unless p.nil?
			end	
		end

	end
	nil
end

.packages(tag) ⇒ Object


466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
# File 'lib/xmimodel/xmihelper.rb', line 466

def self.packages(tag)

	packages = Array.new

	if tag.name == "XMI.content"
		tag = tag.at_xpath('./UML:Model/UML:Namespace.ownedElement')

	# se passou um 'UML:Package' navega até o 'UML:Namespace.ownedElement' filho
	elsif tag.name == "Package" || tag.name == "Model"
		tag = tag.at_xpath("./UML:Namespace.ownedElement")
	end	

	# Pacote sem nenhuma classe nem pacotes internos
	return packages if tag.nil?

	# deverá ser 'UML:Namespace.ownedElement' ou 'XMI.content'
	if tag.name == "Namespace.ownedElement" || tag.name == "XMI.content"

		tag.xpath('./UML:Package').each do |package|
			# puts package.attribute "name"
			packages << package
		end
	end

	if packages.size == 0
		tag.xpath('./UML:Model').each do |model|
			packages = packages + XmiHelper.packages(model)
		end
	end

	packages
end

.parameters(tag) ⇒ Object


499
500
501
502
503
504
505
506
507
508
# File 'lib/xmimodel/xmihelper.rb', line 499

def self.parameters(tag)
			
	if tag.name == "SignalEvent"			
		tag.xpath("./UML:Event.parameter/UML:Parameter")
	elsif tag.name == "Operation" 
		tag.xpath("./UML:BehavioralFeature.parameter/UML:Parameter")			
	else
		raise ArgumentError.new("Parameter (#{tag.name}) is not a UML:SignalEvent or UML:Operation tag.") 
	end		
end

.parent_package(tag) ⇒ Object


510
511
512
513
514
515
516
517
518
519
520
521
522
# File 'lib/xmimodel/xmihelper.rb', line 510

def self.parent_package(tag)

	return nil if tag.nil?

	if tag.name == "Class" || tag.name == "Package" ||  tag.name == "Enumeration" 
		namespace = tag.parent if !(tag.parent.nil?) && tag.parent.name == "Namespace.ownedElement"			
	end
	
	if !namespace.nil?			
		return namespace.parent if !(namespace.parent.nil?) && namespace.parent.name == "Package"
	end
	nil
end

.participant_id_by_association_end(association_end) ⇒ Object

Raises:

  • (ArgumentError)

524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
# File 'lib/xmimodel/xmihelper.rb', line 524

def self.participant_id_by_association_end(association_end)

	raise ArgumentError.new("Parameter is not a AssociationEnd tag.") if association_end.name != 'AssociationEnd'

	if association_end.attribute("participant").nil?

		if association_end.attribute("type").nil?
			participant_id = association_end.at_xpath("./UML:AssociationEnd.participant/UML:Class")
			part = participant_id.attribute('xmi.idref') unless participant_id.nil?
		else
			part = association_end.attribute("type")
		end
	else
		part = association_end.attribute("participant")
	end

	return part
end

.primitive_by_id(document, id) ⇒ Object


544
545
546
# File 'lib/xmimodel/xmihelper.rb', line 544

def self.primitive_by_id(document, id)
	tag_by_id(document, 'UML:Primitive', id)
end

.pseudo_states(tag) ⇒ Object

Raises:

  • (ArgumentError)

681
682
683
684
# File 'lib/xmimodel/xmihelper.rb', line 681

def self.pseudo_states(tag)
	raise ArgumentError.new("Parameter is not a UML:ActivityGraph tag.") if tag.nil? || tag.name != "ActivityGraph"
	tag.xpath('./UML:StateMachine.top/UML:CompositeState/UML:CompositeState.subvertex/UML:Pseudostate')
end

.signal_events(tag) ⇒ Object

Signal events are methods triggered between one state and another


619
620
621
# File 'lib/xmimodel/xmihelper.rb', line 619

def self.signal_events(tag)
	namespace(tag).xpath("./UML:SignalEvent")
end

.stereotype_by_href(document, href) ⇒ Object


557
558
559
# File 'lib/xmimodel/xmihelper.rb', line 557

def self.stereotype_by_href(document, href)
	stereotype = document.at_xpath("//UML:Stereotype[@href='#{href}']")
end

.stereotype_by_id(document, id) ⇒ Object


561
562
563
# File 'lib/xmimodel/xmihelper.rb', line 561

def self.stereotype_by_id(document, id)
	tag_by_id(document, 'UML:Stereotype', id)
end

.stereotypes(document) ⇒ Object


548
549
550
551
552
553
554
555
# File 'lib/xmimodel/xmihelper.rb', line 548

def self.stereotypes(document)

	stereotypes = Array.new
	document.xpath('./UML:ModelElement.stereotype/UML:Stereotype').each do |stereotype|
		stereotypes << stereotype
	end
	stereotypes
end

.tag_definition_by_id(document, id) ⇒ Object


570
571
572
# File 'lib/xmimodel/xmihelper.rb', line 570

def self.tag_definition_by_id(document, id)
	tag_by_id(document, 'UML:TagDefinition', id)
end

.tagged_value_by_name(tag, name) ⇒ Object


582
583
584
# File 'lib/xmimodel/xmihelper.rb', line 582

def self.tagged_value_by_name(tag, name)
	tag_by_name(tag, "UML:TaggedValue", name)
end

.tagged_values(tag) ⇒ Object


574
575
576
577
578
579
580
# File 'lib/xmimodel/xmihelper.rb', line 574

def self.tagged_values(tag)
	t = Array.new
	tag.xpath('./UML:ModelElement.taggedValue/UML:TaggedValue').each do |tagged_value|
		t << tagged_value
	end
	t
end

.taggeg_value_data_value(tag) ⇒ Object

Raises:

  • (ArgumentError)

586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
# File 'lib/xmimodel/xmihelper.rb', line 586

def self.taggeg_value_data_value(tag)
	return "" if tag.nil?

	if tag.name == 'TaggedValue'		#tag_id = tag.attribute("xmi.id").to_s

		tag = tag.at_xpath("./UML:TaggedValue.dataValue")
	end

	if tag.nil?		#puts "[WARN] - TaggedValue '#{tag_id}' sem tag UML:TaggedValue.dataValue"

		return ""
	end

	raise ArgumentError.new("Parameter is not a UML:TaggedValue.dataValue tag or a tag that contains.") if tag.name != 'TaggedValue.dataValue'

	tag.inner_html
end

.taggeg_value_reference_value(tag) ⇒ Object

TaggedValue

Raises:

  • (ArgumentError)

605
606
607
608
609
610
# File 'lib/xmimodel/xmihelper.rb', line 605

def self.taggeg_value_reference_value(tag)
	return "" if tag.nil?
	raise ArgumentError.new("Parameter is not a UML:TaggedValue tag.") if tag.name != 'TaggedValue'
	tag = tag.at_xpath("./UML:TaggedValue.referenceValue/UML:ModelElement/XMI.extension")
	extension_referent_path_value(tag)
end

.taggeg_value_tag_definition(tag) ⇒ Object

Raises:

  • (ArgumentError)

612
613
614
615
616
# File 'lib/xmimodel/xmihelper.rb', line 612

def self.taggeg_value_tag_definition(tag)
	return "" if tag.nil?
	raise ArgumentError.new("Parameter is not a UML:TaggedValue tag.") if tag.name != 'TaggedValue'
	tag = tag.at_xpath("./UML:TaggedValue.type/UML:TagDefinition")
end

.transitions(tag) ⇒ Object

Raises:

  • (ArgumentError)

691
692
693
694
# File 'lib/xmimodel/xmihelper.rb', line 691

def self.transitions(tag)
	raise ArgumentError.new("Parameter is not a UML:ActivityGraph tag.") if tag.nil? || tag.name != "ActivityGraph"
	tag.xpath('./UML:StateMachine.transitions/UML:Transition')				
end

.use_case_by_name(document, name) ⇒ Object


623
624
625
# File 'lib/xmimodel/xmihelper.rb', line 623

def self.use_case_by_name(document, name)
	tag_by_name(xmi_content(document), "UML:UseCase", name)
end

.use_cases(tag) ⇒ Object


627
628
629
# File 'lib/xmimodel/xmihelper.rb', line 627

def self.use_cases(tag)
	namespace(tag).xpath("./UML:UseCase")		
end

.versionObject


696
697
698
# File 'lib/xmimodel/xmihelper.rb', line 696

def self.version
	"1.0.0"
end

.xmi_content(tag) ⇒ Object


565
566
567
568
# File 'lib/xmimodel/xmihelper.rb', line 565

def self.xmi_content(tag)
	return tag if tag.nil? or tag.name == "XMI.content"
	xmi_content = tag.document.at_xpath("./XMI/XMI.content")
end