Class: XmiModel
- Inherits:
-
Object
- Object
- XmiModel
- Defined in:
- lib/xmimodel.rb
Overview
A helper class for working with XMI Models.
Instance Attribute Summary collapse
-
#associations ⇒ Array<Association>
readonly
All model associations.
- #document ⇒ Nokogiri::XML::Document readonly
-
#exporter ⇒ String
readonly
The contents of the tag ‘XMI.header/XMI.documentation/XMI.exporter’.
-
#exporter_version ⇒ String
readonly
The contents of the tag ‘XMI.header/XMI.documentation/XMI.exporterVersion’.
-
#generalizations ⇒ Array<Generalization>
readonly
All model generalizations.
-
#metamodel_version ⇒ String
readonly
The value of property xmi.version of the tag ‘XMI.header/XMI.metamodel’.
Instance Method Summary collapse
-
#class_by_full_name(full_class_name) ⇒ Clazz
Get the object of type ‘Clazz’ by full name of class.
-
#class_by_id(class_id) ⇒ Clazz
Get the object of type ‘Clazz’ by id.
-
#classes ⇒ Array<Clazz>
Get all model classes.
-
#initialize(model_file_name) ⇒ XmiModel
constructor
Constructor.
-
#package_by_full_name(full_package_name) ⇒ Package
Get the object of type ‘Package’ by full name of package.
-
#packages ⇒ Array<Package>
Get all model packages.
-
#state_by_id(id) ⇒ ActionState, ...
Get the object of type ‘State’ by id.
-
#states ⇒ Array<ActionState, FinalState, PseudoState>
Get all model states.
- #to_s ⇒ Object
Constructor Details
#initialize(model_file_name) ⇒ XmiModel
Constructor.
33 34 35 36 37 38 39 40 41 42 43 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 |
# File 'lib/xmimodel.rb', line 33 def initialize(model_file_name) # Obtem a tag 'XMI.content' que contém todos os objetos que serão tratados f = File.open(model_file_name) doc = Nokogiri::XML(f) @document = doc xmi_content = doc.at_xpath("./XMI/XMI.content") f.close # Header @exporter = XmiHelper.exporter(doc) @exporter_version = XmiHelper.exporter_version(doc) @metamodel_version = XmiHelper.(doc) # Constrói vetor de pacotes @packages = Array.new XmiHelper.packages(xmi_content).each do |uml_package| if ! (uml_package.attribute('name').nil? || uml_package.attribute('name').to_s.empty? || uml_package.attribute('name').to_s.strip == "Component View" || uml_package.attribute('name').to_s.strip == "Data types") p = Package.new(uml_package, nil) @packages << p end end # Constrói vetor de heranças @generalizations = Array.new XmiHelper.all_generalizations(xmi_content).each do |xml| g = Generalization.new(xml, self) g.child_obj.parent = g.parent_obj unless g.child_obj.nil? g.parent_obj.children << g.child_obj unless g.parent_obj.nil? #puts "#{g.child_obj.full_name} - #{g.parent_obj.full_name}" @generalizations << g end @associations = Array.new XmiHelper.all_associations(xmi_content).each do |xml| @associations << Association.new(xml, self) end true end |
Instance Attribute Details
#associations ⇒ Array<Association> (readonly)
Returns All model associations.
27 28 29 |
# File 'lib/xmimodel.rb', line 27 def associations @associations end |
#document ⇒ Nokogiri::XML::Document (readonly)
12 13 14 |
# File 'lib/xmimodel.rb', line 12 def document @document end |
#exporter ⇒ String (readonly)
Returns The contents of the tag ‘XMI.header/XMI.documentation/XMI.exporter’.
15 16 17 |
# File 'lib/xmimodel.rb', line 15 def exporter @exporter end |
#exporter_version ⇒ String (readonly)
Returns The contents of the tag ‘XMI.header/XMI.documentation/XMI.exporterVersion’.
18 19 20 |
# File 'lib/xmimodel.rb', line 18 def exporter_version @exporter_version end |
#generalizations ⇒ Array<Generalization> (readonly)
Returns All model generalizations.
24 25 26 |
# File 'lib/xmimodel.rb', line 24 def generalizations @generalizations end |
#metamodel_version ⇒ String (readonly)
Returns The value of property xmi.version of the tag ‘XMI.header/XMI.metamodel’.
21 22 23 |
# File 'lib/xmimodel.rb', line 21 def @metamodel_version end |
Instance Method Details
#class_by_full_name(full_class_name) ⇒ Clazz
Get the object of type ‘Clazz’ by full name of class.
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/xmimodel.rb', line 84 def class_by_full_name(full_class_name) raise ArgumentError.new("Parameter 'full_class_name' cannot be empty.") if full_class_name.nil? or full_class_name.empty? clazz = classes.select{|c| c.full_name == full_class_name} if !clazz.nil? && clazz.size > 0 clazz[0] else nil end end |
#class_by_id(class_id) ⇒ Clazz
Get the object of type ‘Clazz’ by id.
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/xmimodel.rb', line 100 def class_by_id(class_id) raise ArgumentError.new("#{__method__}: 'class_id' cannot be empty.") if class_id.nil? or class_id.empty? clazz = classes.select{|c| c.id == class_id} if !clazz.nil? && clazz.size > 0 clazz[0] else nil end end |
#classes ⇒ Array<Clazz>
Get all model classes.
115 116 117 118 119 120 121 122 |
# File 'lib/xmimodel.rb', line 115 def classes return @classes unless @classes.nil? @classes = Array.new packages.each do |p| @classes.concat p.classes.sort end @classes end |
#package_by_full_name(full_package_name) ⇒ Package
Get the object of type ‘Package’ by full name of package.
129 130 131 132 133 134 135 136 137 138 |
# File 'lib/xmimodel.rb', line 129 def package_by_full_name(full_package_name) raise ArgumentError.new("Parameter 'full_package_name' cannot be empty.") if full_package_name.nil? or full_package_name.empty? package = packages.select{|p| p.full_name == full_package_name} if !package.nil? && package.size > 0 package[0] else nil end end |
#packages ⇒ Array<Package>
Get all model packages.
144 145 146 147 148 149 150 151 152 |
# File 'lib/xmimodel.rb', line 144 def packages return @all_packages unless @all_packages.nil? @all_packages = Array.new add_package(@packages) @all_packages.sort! @all_packages end |
#state_by_id(id) ⇒ ActionState, ...
Get the object of type ‘State’ by id.
159 160 161 162 163 |
# File 'lib/xmimodel.rb', line 159 def state_by_id(id) raise ArgumentError.new("Parameter 'id' cannot be empty.") if id.nil? or id.empty? objs = states.select{|obj| obj.id == id} (!objs.nil? && objs.size > 0) ? objs[0] : nil end |
#states ⇒ Array<ActionState, FinalState, PseudoState>
Get all model states.
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/xmimodel.rb', line 170 def states return @states unless @states.nil? @states = Array.new packages.each do |p| p.use_cases.each do |u| u.activity_graphs.each do |a| @states.concat a.action_states @states.concat a.final_states @states.concat a.pseudo_states end end p.activity_graphs.each do |a| @states.concat a.action_states @states.concat a.final_states @states.concat a.pseudo_states end end @states end |
#to_s ⇒ Object
191 192 193 |
# File 'lib/xmimodel.rb', line 191 def to_s "'XmiModel #{exporter} #{exporter_version} [Packages: #{packages.size}, Classes: #{classes.size}]'" end |