Class: XmiHelper
- Inherits:
-
Object
- Object
- XmiHelper
- 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
-
.action_states(tag) ⇒ Object
Get all the Action State in the tag.
-
.activity_graph_by_name(document, name) ⇒ Object
Get the Activity Graph by name.
-
.activity_graphs(tag) ⇒ Object
Get all the Activity Graphs in the tag.
-
.add_namespace(xml) ⇒ Object
Add a tag UML:Namespace.ownedElement to the parameter xml.
-
.all_associations(tag) ⇒ Object
Get all the Associations in the model.
-
.all_generalizations(tag) ⇒ Object
Get all the Generalizations in the model.
-
.all_packages(tag) ⇒ Object
Get all the Packages in the model.
-
.associations(tag) ⇒ Object
Get all the Associations in the model.
-
.associations_by_participant_id(tag, id) ⇒ Object
Get the Associations by id of the any participants of relationship.
-
.attribute_by_id(document, id) ⇒ Object
Get the attribute of a class by identification.
-
.attribute_by_name(uml_class, name) ⇒ Object
Get the attribute of a class by name.
-
.attribute_initial_value(uml_attribute) ⇒ Object
Get the initial value of an attribute.
-
.attribute_type(uml_attribute) ⇒ Object
Return a object ‘Nokogiri::XML::Element’ of type ‘UML:Class’ or ‘UML:DataType’ or a String.
- .attribute_type_name(uml_attribute) ⇒ Object
-
.attributes(uml_class) ⇒ Object
Get the attributes of a class.
-
.call_events(tag) ⇒ Object
Call Events are links between ActionStates (by deferrableEvent propertie) and Operations (methods of a class).
- .class_by_full_name(document, full_name) ⇒ Object
- .class_by_id(document, id) ⇒ Object
- .class_by_name(document, name) ⇒ Object
- .classes(tag) ⇒ Object
- .classes_by_association(document, association) ⇒ Object
- .data_type(document, id) ⇒ Object
- .data_types(tag) ⇒ Object
- .enumeration_by_id(document, id) ⇒ Object
- .enumeratios(tag) ⇒ Object
- .exporter(document) ⇒ Object
- .exporter_version(document) ⇒ Object
- .extension_referent_path_value(tag) ⇒ Object
- .final_states(tag) ⇒ Object
- .full_class_name(clazz) ⇒ Object
- .full_enumeration_name(enumeration) ⇒ Object
- .full_package_name(package) ⇒ Object
- .generalization_by_child(document, id) ⇒ Object
-
.generalization_child(generalization) ⇒ Object
Returns the child id from the tag ‘UML:Generalization’.
-
.generalization_parent(generalization) ⇒ Object
Returns the parent id from the tag ‘UML:Generalization’.
- .guard_condition(tag) ⇒ Object
- .has_namespace?(tag) ⇒ Boolean
- .metamodel_version(document) ⇒ Object
- .multiplicity(tag) ⇒ Object
- .multiplicity_range(tag) ⇒ Object
- .namespace(tag) ⇒ Object
- .operation_by_id(document, id) ⇒ Object
- .operation_by_name(tag, name) ⇒ Object
- .operations(uml_class) ⇒ Object
- .package_by_full_name(document, full_package_name) ⇒ Object
- .package_by_name(tag, package_name) ⇒ Object
- .packages(tag) ⇒ Object
- .parameters(tag) ⇒ Object
- .parent_package(tag) ⇒ Object
- .participant_id_by_association_end(association_end) ⇒ Object
- .pseudo_states(tag) ⇒ Object
-
.signal_events(tag) ⇒ Object
Signal events are methods triggered between one state and another.
- .stereotype_by_href(document, href) ⇒ Object
- .stereotype_by_id(document, id) ⇒ Object
- .stereotypes(document) ⇒ Object
- .tag_definition_by_id(document, id) ⇒ Object
- .tagged_value_by_name(tag, name) ⇒ Object
- .tagged_values(tag) ⇒ Object
- .taggeg_value_data_value(tag) ⇒ Object
-
.taggeg_value_reference_value(tag) ⇒ Object
TaggedValue.
- .taggeg_value_tag_definition(tag) ⇒ Object
- .transitions(tag) ⇒ Object
- .use_case_by_name(document, name) ⇒ Object
- .use_cases(tag) ⇒ Object
- .version ⇒ Object
- .xmi_content(tag) ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ XmiHelper
constructor
Constructor.
Constructor Details
#initialize ⇒ XmiHelper
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
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
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
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/xmimodel/xmihelper.rb', line 168 def self.attribute_type(uml_attribute) raise ArgumentError.new("Parameter is not a 'UML:Attribute' tag.") if uml_attribute.name != "Attribute" 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? 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(xmi_content, id) return data_type unless data_type.nil? end type end |
.attribute_type_name(uml_attribute) ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/xmimodel/xmihelper.rb', line 191 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
212 213 214 |
# File 'lib/xmimodel/xmihelper.rb', line 212 def self.call_events(tag) namespace(tag).xpath("./UML:CallEvent") end |
.class_by_full_name(document, full_name) ⇒ Object
216 217 218 219 220 221 222 223 224 225 |
# File 'lib/xmimodel/xmihelper.rb', line 216 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
227 228 229 |
# File 'lib/xmimodel/xmihelper.rb', line 227 def self.class_by_id(document, id) tag_by_id(document, 'UML:Class', id) end |
.class_by_name(document, name) ⇒ Object
231 232 233 |
# File 'lib/xmimodel/xmihelper.rb', line 231 def self.class_by_name(document, name) tag_by_name(xmi_content(document), "UML:Class", name) end |
.classes(tag) ⇒ Object
235 236 237 |
# File 'lib/xmimodel/xmihelper.rb', line 235 def self.classes(tag) namespace(tag).xpath("./UML:Class") end |
.classes_by_association(document, association) ⇒ Object
239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/xmimodel/xmihelper.rb', line 239 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(document, id) ⇒ Object
253 254 255 |
# File 'lib/xmimodel/xmihelper.rb', line 253 def self.data_type(document, id) tag_by_id(document, 'UML:Enumeration', id) end |
.data_types(tag) ⇒ Object
257 258 259 |
# File 'lib/xmimodel/xmihelper.rb', line 257 def self.data_types(tag) namespace(tag).xpath("./UML:DataType") end |
.enumeration_by_id(document, id) ⇒ Object
265 266 267 |
# File 'lib/xmimodel/xmihelper.rb', line 265 def self.enumeration_by_id(document, id) tag_by_id(document, 'UML:DataType', id) end |
.enumeratios(tag) ⇒ Object
261 262 263 |
# File 'lib/xmimodel/xmihelper.rb', line 261 def self.enumeratios(tag) namespace(tag).xpath("./UML:Enumeration") end |
.exporter(document) ⇒ Object
269 270 271 |
# File 'lib/xmimodel/xmihelper.rb', line 269 def self.exporter(document) @exporter = document.at_xpath("./XMI/XMI.header/XMI.documentation/XMI.exporter").inner_html end |
.exporter_version(document) ⇒ Object
273 274 275 |
# File 'lib/xmimodel/xmihelper.rb', line 273 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
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/xmimodel/xmihelper.rb', line 281 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
668 669 670 671 |
# File 'lib/xmimodel/xmihelper.rb', line 668 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
321 322 323 324 325 326 327 328 329 |
# File 'lib/xmimodel/xmihelper.rb', line 321 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
331 332 333 334 335 336 337 338 339 |
# File 'lib/xmimodel/xmihelper.rb', line 331 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
341 342 343 344 345 346 347 348 349 350 351 |
# File 'lib/xmimodel/xmihelper.rb', line 341 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
353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
# File 'lib/xmimodel/xmihelper.rb', line 353 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’
370 371 372 373 374 375 376 377 |
# File 'lib/xmimodel/xmihelper.rb', line 370 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’
381 382 383 384 385 386 387 388 |
# File 'lib/xmimodel/xmihelper.rb', line 381 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
390 391 392 393 394 395 396 397 398 399 400 |
# File 'lib/xmimodel/xmihelper.rb', line 390 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
299 300 301 302 303 304 305 306 307 308 |
# File 'lib/xmimodel/xmihelper.rb', line 299 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
277 278 279 |
# File 'lib/xmimodel/xmihelper.rb', line 277 def self.(document) @metamodel_version = doc.at_xpath("./XMI/XMI.header/XMI.metamodel").attribute("xmi.version").to_s end |
.multiplicity(tag) ⇒ Object
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 |
# File 'lib/xmimodel/xmihelper.rb', line 613 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
630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 |
# File 'lib/xmimodel/xmihelper.rb', line 630 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
310 311 312 313 314 315 316 317 318 319 |
# File 'lib/xmimodel/xmihelper.rb', line 310 def self.namespace(tag) raise ArgumentError.new("Parameter 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 does not contain a tag 'UML:Namespace.ownedElement'.") end tag end |
.operation_by_id(document, id) ⇒ Object
654 655 656 |
# File 'lib/xmimodel/xmihelper.rb', line 654 def self.operation_by_id(document, id) tag_by_id(document, 'UML:Operation', id) end |
.operation_by_name(tag, name) ⇒ Object
658 659 660 661 |
# File 'lib/xmimodel/xmihelper.rb', line 658 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
648 649 650 651 652 |
# File 'lib/xmimodel/xmihelper.rb', line 648 def self.operations(uml_class) raise ArgumentError.new("Parameter is not a UML:Class tag.") if uml_class.name != "Class" uml_class.xpath('./UML:Classifier.feature/UML:Operation') end |
.package_by_full_name(document, full_package_name) ⇒ Object
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 |
# File 'lib/xmimodel/xmihelper.rb', line 436 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
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 |
# File 'lib/xmimodel/xmihelper.rb', line 406 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
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 |
# File 'lib/xmimodel/xmihelper.rb', line 453 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
486 487 488 489 490 491 492 493 494 495 |
# File 'lib/xmimodel/xmihelper.rb', line 486 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
497 498 499 500 501 502 503 504 505 506 507 508 509 |
# File 'lib/xmimodel/xmihelper.rb', line 497 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
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 |
# File 'lib/xmimodel/xmihelper.rb', line 511 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 |
.pseudo_states(tag) ⇒ Object
663 664 665 666 |
# File 'lib/xmimodel/xmihelper.rb', line 663 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
601 602 603 |
# File 'lib/xmimodel/xmihelper.rb', line 601 def self.signal_events(tag) namespace(tag).xpath("./UML:SignalEvent") end |
.stereotype_by_href(document, href) ⇒ Object
539 540 541 |
# File 'lib/xmimodel/xmihelper.rb', line 539 def self.stereotype_by_href(document, href) stereotype = document.at_xpath("//UML:Stereotype[@href='#{href}']") end |
.stereotype_by_id(document, id) ⇒ Object
543 544 545 |
# File 'lib/xmimodel/xmihelper.rb', line 543 def self.stereotype_by_id(document, id) tag_by_id(document, 'UML:Stereotype', id) end |
.stereotypes(document) ⇒ Object
530 531 532 533 534 535 536 537 |
# File 'lib/xmimodel/xmihelper.rb', line 530 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
552 553 554 |
# File 'lib/xmimodel/xmihelper.rb', line 552 def self.tag_definition_by_id(document, id) tag_by_id(document, 'UML:TagDefinition', id) end |
.tagged_value_by_name(tag, name) ⇒ Object
564 565 566 |
# File 'lib/xmimodel/xmihelper.rb', line 564 def self.tagged_value_by_name(tag, name) tag_by_name(tag, "UML:TaggedValue", name) end |
.tagged_values(tag) ⇒ Object
556 557 558 559 560 561 562 |
# File 'lib/xmimodel/xmihelper.rb', line 556 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
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 |
# File 'lib/xmimodel/xmihelper.rb', line 568 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
587 588 589 590 591 592 |
# File 'lib/xmimodel/xmihelper.rb', line 587 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
594 595 596 597 598 |
# File 'lib/xmimodel/xmihelper.rb', line 594 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
673 674 675 676 |
# File 'lib/xmimodel/xmihelper.rb', line 673 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
605 606 607 |
# File 'lib/xmimodel/xmihelper.rb', line 605 def self.use_case_by_name(document, name) tag_by_name(xmi_content(document), "UML:UseCase", name) end |
.use_cases(tag) ⇒ Object
609 610 611 |
# File 'lib/xmimodel/xmihelper.rb', line 609 def self.use_cases(tag) namespace(tag).xpath("./UML:UseCase") end |
.version ⇒ Object
678 679 680 |
# File 'lib/xmimodel/xmihelper.rb', line 678 def self.version "1.0.0" end |
.xmi_content(tag) ⇒ Object
547 548 549 550 |
# File 'lib/xmimodel/xmihelper.rb', line 547 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 |