xmimodel 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/xmimodel.rb +40 -3
- data/lib/xmimodel/action_state.rb +3 -0
- data/lib/xmimodel/activity_graph.rb +8 -7
- data/lib/xmimodel/association.rb +21 -10
- data/lib/xmimodel/association_end.rb +131 -0
- data/lib/xmimodel/attribute.rb +60 -9
- data/lib/xmimodel/clazz.rb +61 -13
- data/lib/xmimodel/data_type.rb +5 -8
- data/lib/xmimodel/final_state.rb +4 -2
- data/lib/xmimodel/generalization.rb +7 -10
- data/lib/xmimodel/namespace.rb +10 -8
- data/lib/xmimodel/operation.rb +8 -8
- data/lib/xmimodel/package.rb +19 -8
- data/lib/xmimodel/parameter.rb +8 -10
- data/lib/xmimodel/pseudo_state.rb +5 -2
- data/lib/xmimodel/signal_event.rb +7 -8
- data/lib/xmimodel/state.rb +8 -7
- data/lib/xmimodel/stereotype.rb +16 -7
- data/lib/xmimodel/tag.rb +36 -0
- data/lib/xmimodel/tagged_value.rb +14 -9
- data/lib/xmimodel/transition.rb +8 -8
- data/lib/xmimodel/use_case.rb +8 -7
- data/lib/xmimodel/xmihelper.rb +11 -1
- metadata +7 -7
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6eedac5a14ed62e48491ffb7ebacffcfd42cdaa4
|
4
|
+
data.tar.gz: 4bc59859d307c43b49fb2a3d6cffd0b4960d9622
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 35fc123beab06f777a05cc4961734588f961e35665243c87bd26e162b719962bd6b94c13ec4ad450e03f89023ea061ffd008460f3593479ed12c16f449ff7a96
|
7
|
+
data.tar.gz: 632da159972894e7d5a66b726752537d33d7d9e3ed6c6d6b909fcad9eeaf5597da925c87d20481fadf803e4de3b76ad8c505bcfdb97a1d755b4e347eb37e3342
|
data/lib/xmimodel.rb
CHANGED
@@ -26,12 +26,16 @@ class XmiModel
|
|
26
26
|
# @return [Array<Association>] All model associations.
|
27
27
|
attr_reader :associations
|
28
28
|
|
29
|
+
attr_reader :model_file_name
|
30
|
+
|
29
31
|
##
|
30
32
|
# Constructor.
|
31
33
|
#
|
32
34
|
# @param [String, #read] Path of model.
|
33
35
|
def initialize(model_file_name)
|
34
36
|
|
37
|
+
@model_file_name = model_file_name
|
38
|
+
|
35
39
|
# Obtem a tag 'XMI.content' que contém todos os objetos que serão tratados
|
36
40
|
f = File.open(model_file_name)
|
37
41
|
doc = Nokogiri::XML(f)
|
@@ -51,7 +55,7 @@ class XmiModel
|
|
51
55
|
uml_package.attribute('name').to_s.empty? ||
|
52
56
|
uml_package.attribute('name').to_s.strip == "Component View" ||
|
53
57
|
uml_package.attribute('name').to_s.strip == "Data types")
|
54
|
-
p = Package.new(uml_package,
|
58
|
+
p = Package.new(uml_package, self)
|
55
59
|
@packages << p
|
56
60
|
end
|
57
61
|
end
|
@@ -70,12 +74,29 @@ class XmiModel
|
|
70
74
|
|
71
75
|
@associations = Array.new
|
72
76
|
XmiHelper.all_associations(xmi_content).each do |xml|
|
73
|
-
|
77
|
+
|
78
|
+
association = Association.new(xml, self)
|
79
|
+
|
80
|
+
association.end_a.participant.associations << association.end_b
|
81
|
+
association.end_b.participant.associations << association.end_a
|
82
|
+
|
83
|
+
@associations << association
|
74
84
|
end
|
75
85
|
|
76
86
|
true
|
77
87
|
end
|
78
88
|
|
89
|
+
##
|
90
|
+
# Get the object of type 'Association' by id.
|
91
|
+
#
|
92
|
+
# @param [String, #read] Id of the state in model file.
|
93
|
+
# @return [Association]
|
94
|
+
def association_by_id(id)
|
95
|
+
raise ArgumentError.new("Parameter 'id' cannot be empty.") if id.nil? or id.empty?
|
96
|
+
objs = @associations.select{|obj| obj.id == id}
|
97
|
+
(!objs.nil? && objs.size > 0) ? objs[0] : nil
|
98
|
+
end
|
99
|
+
|
79
100
|
##
|
80
101
|
# Get the object of type 'Clazz' by full name of class.
|
81
102
|
#
|
@@ -188,10 +209,26 @@ class XmiModel
|
|
188
209
|
@states
|
189
210
|
end
|
190
211
|
|
212
|
+
|
213
|
+
def id_exists?(id)
|
214
|
+
tag = XmiHelper.tag_by_id(@document, '*', id)
|
215
|
+
return !tag.nil?
|
216
|
+
end
|
217
|
+
|
191
218
|
def to_s
|
192
219
|
"'XmiModel #{exporter} #{exporter_version} [Packages: #{packages.size}, Classes: #{classes.size}]'"
|
193
220
|
end
|
194
221
|
|
222
|
+
def to_xml
|
223
|
+
@document.to_xml
|
224
|
+
end
|
225
|
+
|
226
|
+
def save(model_file_name=@model_file_name)
|
227
|
+
f = File.open(model_file_name, 'w')
|
228
|
+
f.write(@document.to_xml)
|
229
|
+
f.close
|
230
|
+
end
|
231
|
+
|
195
232
|
private
|
196
233
|
|
197
234
|
def add_package(packages)
|
@@ -200,6 +237,6 @@ class XmiModel
|
|
200
237
|
@all_packages << p
|
201
238
|
add_package(p.packages) unless p.packages.nil?
|
202
239
|
end
|
203
|
-
end
|
240
|
+
end
|
204
241
|
|
205
242
|
end
|
@@ -1,6 +1,9 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'xmimodel/action_state'
|
2
4
|
require 'xmimodel/final_state'
|
3
5
|
require 'xmimodel/pseudo_state'
|
6
|
+
require 'xmimodel/tag'
|
4
7
|
require 'xmimodel/transition'
|
5
8
|
|
6
9
|
##
|
@@ -8,11 +11,8 @@ require 'xmimodel/transition'
|
|
8
11
|
# It's represented by tag diagram inside of XMI.extension.
|
9
12
|
#
|
10
13
|
#
|
11
|
-
class ActivityGraph
|
14
|
+
class ActivityGraph < Tag
|
12
15
|
|
13
|
-
attr_reader :xml
|
14
|
-
|
15
|
-
attr_reader :id
|
16
16
|
attr_reader :name
|
17
17
|
|
18
18
|
attr_reader :pseudo_states
|
@@ -20,9 +20,10 @@ class ActivityGraph
|
|
20
20
|
attr_reader :final_states
|
21
21
|
attr_reader :transitions
|
22
22
|
|
23
|
-
def initialize(xml,
|
24
|
-
|
25
|
-
|
23
|
+
def initialize(xml, parent_tag)
|
24
|
+
super(xml, parent_tag)
|
25
|
+
|
26
|
+
@use_case = parent_tag.parent_tag
|
26
27
|
|
27
28
|
@id = xml.attribute("xmi.id").to_s
|
28
29
|
@name = xml.attribute("name").to_s
|
data/lib/xmimodel/association.rb
CHANGED
@@ -1,24 +1,35 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
|
2
|
-
|
3
|
+
require 'xmimodel/association_end'
|
4
|
+
require 'xmimodel/tag'
|
3
5
|
|
4
|
-
|
5
|
-
attr_reader :parent
|
6
|
+
class Association < Tag
|
6
7
|
|
7
|
-
attr_reader :id
|
8
8
|
attr_reader :name
|
9
|
+
|
10
|
+
attr_reader :end_a
|
11
|
+
attr_reader :end_b
|
9
12
|
|
10
|
-
# TODO Build AssociationEnd class
|
11
13
|
def initialize(xml, parent)
|
12
|
-
|
13
|
-
@parent = parent
|
14
|
+
super(xml, parent)
|
14
15
|
|
15
|
-
@id = xml.attribute("xmi.id").to_s
|
16
16
|
@name = xml.attribute("name").to_s.strip
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
association_end = xml.xpath('./UML:Association.connection/UML:AssociationEnd')
|
19
|
+
|
20
|
+
@end_a = AssociationEnd.new(association_end, 0, self)
|
21
|
+
@end_b = AssociationEnd.new(association_end, 1, self)
|
20
22
|
end
|
21
23
|
|
24
|
+
# @return [String]
|
25
|
+
def full_name
|
26
|
+
if @name.nil? or @name.empty?
|
27
|
+
"#{@end_a.name}[#{@end_a.participant.full_name}] - #{@end_b.name}[#{@end_b.participant.full_name}]"
|
28
|
+
else
|
29
|
+
"#{@name}(#{@end_a.name}[#{@end_a.participant.full_name}] - #{@end_b.name}[#{@end_b.participant.full_name}])"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
22
33
|
def to_s
|
23
34
|
"Association[#{@name}]"
|
24
35
|
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'xmimodel/tag'
|
4
|
+
|
5
|
+
class AssociationEnd < Tag
|
6
|
+
|
7
|
+
# @return [String]
|
8
|
+
attr_reader :name
|
9
|
+
|
10
|
+
# @return [String]
|
11
|
+
attr_reader :visibility
|
12
|
+
|
13
|
+
# @return [String]
|
14
|
+
attr_reader :is_navigable
|
15
|
+
|
16
|
+
# @return [String]
|
17
|
+
attr_reader :is_specification
|
18
|
+
|
19
|
+
# @return [String]
|
20
|
+
attr_reader :multiplicity_range
|
21
|
+
|
22
|
+
# @return [String]
|
23
|
+
attr_reader :ordering
|
24
|
+
|
25
|
+
# @return [String]
|
26
|
+
attr_reader :aggregation
|
27
|
+
|
28
|
+
# @return [String]
|
29
|
+
attr_reader :target_scope
|
30
|
+
|
31
|
+
# @return [String]
|
32
|
+
attr_reader :changeability
|
33
|
+
|
34
|
+
# @return [Array<Stereotype>] Association end stereotypes.
|
35
|
+
attr_reader :stereotypes
|
36
|
+
|
37
|
+
# @return [Array<TaggedValue>] Association end tagged values.
|
38
|
+
attr_reader :tagged_values
|
39
|
+
|
40
|
+
def initialize(xmls, index, parent_tag)
|
41
|
+
super(xmls[index], parent_tag)
|
42
|
+
|
43
|
+
@xml_a = xmls[0]
|
44
|
+
@xml_b = xmls[1]
|
45
|
+
|
46
|
+
@xmi_model = parent_tag.parent_tag
|
47
|
+
|
48
|
+
@participant_id = @xml.attribute("participant").to_s
|
49
|
+
|
50
|
+
# argoUML
|
51
|
+
if @participant_id.nil? or @participant_id.empty?
|
52
|
+
c = @xml.at_xpath("./UML:AssociationEnd.participant/UML:Class")
|
53
|
+
@participant_id = c.attribute("xmi.idref").to_s unless c.nil?
|
54
|
+
end
|
55
|
+
|
56
|
+
@name = @xml.attribute("name").to_s
|
57
|
+
|
58
|
+
if @name.empty?
|
59
|
+
@name = index == 0 ? "EndA" : "EndB"
|
60
|
+
end
|
61
|
+
|
62
|
+
@visibility = @xml.attribute("visibility").to_s
|
63
|
+
@is_navigable = @xml.attribute("isNavigable").to_s
|
64
|
+
@is_specification = @xml.attribute("isSpecification").to_s
|
65
|
+
@ordering = @xml.attribute("ordering").to_s
|
66
|
+
@aggregation = @xml.attribute("aggregation").to_s
|
67
|
+
@target_scope = @xml.attribute("targetScope").to_s
|
68
|
+
@changeability = @xml.attribute("changeability").to_s
|
69
|
+
|
70
|
+
@multiplicity_range = XmiHelper.multiplicity_range(@xml)
|
71
|
+
|
72
|
+
@stereotypes = Array.new
|
73
|
+
stereotype_id = @xml.attribute("stereotype").to_s
|
74
|
+
if !stereotype_id.empty?
|
75
|
+
stereotype = XmiHelper.stereotype_by_id(@xml, stereotype_id)
|
76
|
+
stereotype = Stereotype.new(stereotype, self)
|
77
|
+
@stereotypes << stereotype
|
78
|
+
end
|
79
|
+
XmiHelper.stereotypes(@xml).each do |uml_stereotype|
|
80
|
+
stereotype = Stereotype.new(uml_stereotype, self)
|
81
|
+
@stereotypes << stereotype
|
82
|
+
end
|
83
|
+
|
84
|
+
@tagged_values = Array.new
|
85
|
+
XmiHelper.tagged_values(@xml).each do |uml_tagged_value|
|
86
|
+
tagged_value = TaggedValue.new(uml_tagged_value, self)
|
87
|
+
@tagged_values << tagged_value
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# @return [Clazz]
|
92
|
+
def participant
|
93
|
+
return nil if @participant_id.nil? or @participant_id.empty?
|
94
|
+
participant = @xmi_model.class_by_id(@participant_id)
|
95
|
+
end
|
96
|
+
|
97
|
+
def ==(obj)
|
98
|
+
return false if obj.nil?
|
99
|
+
if String == obj.class
|
100
|
+
@name == obj
|
101
|
+
elsif AssociationEnd == obj.class
|
102
|
+
@name == obj.name && participant.full_name == obj.participant.full_name
|
103
|
+
else
|
104
|
+
return false
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# @return [Stereotype]
|
109
|
+
def stereotype_by_name(name)
|
110
|
+
stereotype = @stereotypes.select{|obj| obj == name}
|
111
|
+
return stereotype[0] if !stereotype.nil? && stereotype.size > 0
|
112
|
+
nil
|
113
|
+
end
|
114
|
+
|
115
|
+
# @return [TaggedValue]
|
116
|
+
def tagged_value_by_name(tagged_value_name)
|
117
|
+
tagged_value = @tagged_values.select{|obj| obj.name == tagged_value_name}
|
118
|
+
return tagged_value[0] if !tagged_value.nil? && tagged_value.size > 0
|
119
|
+
nil
|
120
|
+
end
|
121
|
+
|
122
|
+
# @return [String]
|
123
|
+
def full_name
|
124
|
+
"#{@parent_tag.full_name}::#{@name}"
|
125
|
+
end
|
126
|
+
|
127
|
+
# @return [String]
|
128
|
+
def to_s
|
129
|
+
"AssociationEnd[#{name} (#{participant.full_name}])"
|
130
|
+
end
|
131
|
+
end
|
data/lib/xmimodel/attribute.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'xmimodel/stereotype'
|
4
|
+
require 'xmimodel/tag'
|
2
5
|
require 'xmimodel/tagged_value'
|
3
6
|
|
4
|
-
class Attribute
|
5
|
-
|
6
|
-
attr_reader :xml
|
7
|
+
class Attribute < Tag
|
7
8
|
|
8
|
-
attr_reader :id
|
9
9
|
attr_reader :name
|
10
10
|
attr_reader :type
|
11
11
|
attr_reader :visibility
|
@@ -17,16 +17,17 @@ class Attribute
|
|
17
17
|
attr_reader :stereotypes
|
18
18
|
attr_reader :tagged_values
|
19
19
|
|
20
|
-
def initialize(xml,
|
21
|
-
|
22
|
-
|
20
|
+
def initialize(xml, parent_tag)
|
21
|
+
super(xml, parent_tag)
|
22
|
+
|
23
|
+
@clazz = parent_tag
|
23
24
|
|
24
|
-
@id = xml.attribute("xmi:id").to_s
|
25
25
|
@name = xml.attribute("name").to_s.strip
|
26
26
|
@visibility = xml.attribute("visibility").to_s
|
27
27
|
@visibility = "private" if @visibility == ""
|
28
28
|
|
29
|
-
@
|
29
|
+
@obj_type = XmiHelper.attribute_type(xml)
|
30
|
+
@type = XmiHelper.attribute_type_name(xml)
|
30
31
|
|
31
32
|
@initial_value = XmiHelper.attribute_initial_value(xml)
|
32
33
|
@multiplicity_range = XmiHelper.multiplicity_range(xml)
|
@@ -44,6 +45,44 @@ class Attribute
|
|
44
45
|
end
|
45
46
|
end
|
46
47
|
|
48
|
+
def add_xml_tagged_value(xml)
|
49
|
+
model_element_tagged_value().inner_html = model_element_tagged_value().inner_html + xml
|
50
|
+
end
|
51
|
+
|
52
|
+
=begin
|
53
|
+
def add_tagged_value(name, value)
|
54
|
+
if tagged_values.include? name
|
55
|
+
tag = tagged_value_by_name name
|
56
|
+
else
|
57
|
+
tagged_value = Nokogiri::XML::Node.new('TaggedValue', self.xml.document)
|
58
|
+
tagged_value['xmi.id'] =
|
59
|
+
tagged_value['name'] = name
|
60
|
+
model_element_tagged_value() << tagged_value
|
61
|
+
end
|
62
|
+
tag.value = value
|
63
|
+
end
|
64
|
+
=end
|
65
|
+
|
66
|
+
def is_enum?
|
67
|
+
return false if @obj_type.nil?
|
68
|
+
if @obj_type.class == Nokogiri::XML::Element
|
69
|
+
return true if @obj_type.name == "Enumeration"
|
70
|
+
|
71
|
+
if @obj_type.name == "Class"
|
72
|
+
id = @obj_type.attribute('xmi.id').to_s
|
73
|
+
@enum_obj = xml_root.class_by_id(id)
|
74
|
+
return @enum_obj.stereotypes.include?("org.andromda.profile::Enumeration")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
false
|
78
|
+
end
|
79
|
+
|
80
|
+
def enum_obj
|
81
|
+
return @enum_obj unless @enum_obj.nil?
|
82
|
+
is_enum?
|
83
|
+
@enum_obj
|
84
|
+
end
|
85
|
+
|
47
86
|
def full_name
|
48
87
|
"#{@clazz.full_name}::#{@name}"
|
49
88
|
end
|
@@ -73,4 +112,16 @@ class Attribute
|
|
73
112
|
"Attribute[#{full_name}]"
|
74
113
|
end
|
75
114
|
|
115
|
+
private
|
116
|
+
|
117
|
+
def model_element_tagged_value
|
118
|
+
return @model_element_tagged_value unless @model_element_tagged_value.nil?
|
119
|
+
@model_element_tagged_value = self.xml.at_xpath('./UML:ModelElement.taggedValue')
|
120
|
+
if @model_element_tagged_value.nil?
|
121
|
+
@model_element_tagged_value = Nokogiri::XML::Node.new('ModelElement.taggedValue', self.xml.document)
|
122
|
+
self.xml << model_element_tagged_value
|
123
|
+
end
|
124
|
+
@model_element_tagged_value
|
125
|
+
end
|
126
|
+
|
76
127
|
end
|
data/lib/xmimodel/clazz.rb
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'xmimodel/attribute'
|
4
|
-
require 'xmimodel/stereotype'
|
5
|
-
require 'xmimodel/tagged_value'
|
6
4
|
require 'xmimodel/operation'
|
5
|
+
require 'xmimodel/tag'
|
6
|
+
require 'xmimodel/tagged_value'
|
7
|
+
require 'xmimodel/stereotype'
|
7
8
|
|
8
|
-
class Clazz
|
9
|
-
|
10
|
-
attr_reader :xml
|
9
|
+
class Clazz < Tag
|
11
10
|
|
12
|
-
attr_reader :id
|
13
11
|
attr_reader :name
|
14
12
|
|
15
13
|
# @return [String] Full Package name of class.
|
@@ -18,26 +16,31 @@ class Clazz
|
|
18
16
|
# @return [Array<Attribute>] Class attributes.
|
19
17
|
attr_reader :attributes
|
20
18
|
|
21
|
-
# @return [Array<
|
19
|
+
# @return [Array<Stereotype>] Class stereotypes.
|
22
20
|
attr_reader :stereotypes
|
23
21
|
|
22
|
+
# @return [Array<TaggedValue>] Class tagged values.
|
24
23
|
attr_reader :tagged_values
|
24
|
+
|
25
25
|
attr_reader :operations
|
26
26
|
|
27
27
|
attr_accessor :children
|
28
28
|
attr_accessor :parent
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
30
|
+
# @return [Array<AssociationEnd>] Class associations end.
|
31
|
+
attr_reader :associations
|
32
|
+
|
33
|
+
def initialize(xml, parent_tag)
|
34
|
+
super(xml, parent_tag)
|
35
|
+
|
36
|
+
@package = parent_tag.parent_tag
|
37
|
+
|
35
38
|
@name = xml.attribute("name").to_s.strip
|
36
39
|
|
37
40
|
@attributes = Array.new
|
38
41
|
XmiHelper.attributes(xml).each do |uml_attribute|
|
39
42
|
attribute = Attribute.new(uml_attribute, self)
|
40
|
-
@attributes << attribute
|
43
|
+
@attributes << attribute
|
41
44
|
end
|
42
45
|
|
43
46
|
@stereotypes = Array.new
|
@@ -67,8 +70,53 @@ class Clazz
|
|
67
70
|
# Será povoado quando tratar dos objetos do tipo Genezalization
|
68
71
|
@children = Array.new
|
69
72
|
|
73
|
+
@associations = Array.new
|
74
|
+
|
70
75
|
end
|
71
76
|
|
77
|
+
def add_xml_attribute(xml_attribute)
|
78
|
+
parent = self.xml.at_xpath('./UML:Classifier.feature')
|
79
|
+
if parent.nil?
|
80
|
+
parent = Nokogiri::XML::Node.new('Classifier.feature', self.xml.document)
|
81
|
+
self.xml << parent
|
82
|
+
end
|
83
|
+
parent.inner_html = parent.inner_html + xml_attribute
|
84
|
+
|
85
|
+
@attributes << Attribute.new(uml_attribute, self)
|
86
|
+
end
|
87
|
+
|
88
|
+
##
|
89
|
+
# @param xml [Nokogiri::XML::Element, #read]
|
90
|
+
def add_xml_stereotype(xml)
|
91
|
+
parent = self.xml.at_xpath('./UML:ModelElement.stereotype')
|
92
|
+
if parent.nil?
|
93
|
+
parent = Nokogiri::XML::Node.new('ModelElement.stereotype', self.xml.document)
|
94
|
+
self.xml << parent
|
95
|
+
end
|
96
|
+
parent.inner_html = parent.inner_html + xml.to_xml
|
97
|
+
|
98
|
+
stereotype = Stereotype.new(xml, self)
|
99
|
+
@stereotypes << stereotype
|
100
|
+
return stereotype
|
101
|
+
end
|
102
|
+
|
103
|
+
##
|
104
|
+
# @param [String, #read] associations_end_name
|
105
|
+
# @param [Clazz, #read] participant
|
106
|
+
# @return [AssociationEnd]
|
107
|
+
def association_end_by_name_and_participant(associations_end_name, participant)
|
108
|
+
obj = @associations.select{|obj| obj.name == associations_end_name && obj.participant == participant}
|
109
|
+
return obj[0] if !obj.nil? && obj.size > 0
|
110
|
+
nil
|
111
|
+
end
|
112
|
+
|
113
|
+
##
|
114
|
+
# @param [Clazz, #read] participant
|
115
|
+
# @return [Array<AssociationEnd>]
|
116
|
+
def associations_end_by_participant(participant)
|
117
|
+
obj = @associations.select{|obj| obj.participant == participant}
|
118
|
+
end
|
119
|
+
|
72
120
|
def attribute_by_id(attribute_id)
|
73
121
|
attribute = @attributes.select{|obj| obj.id == attribute_id}
|
74
122
|
return attribute[0] if !attribute.nil? && attribute.size > 0
|
data/lib/xmimodel/data_type.rb
CHANGED
@@ -1,17 +1,14 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
|
2
|
-
|
3
|
+
require 'xmimodel/tag'
|
3
4
|
|
4
|
-
|
5
|
-
attr_reader :parent
|
5
|
+
class DataType < Tag
|
6
6
|
|
7
|
-
attr_reader :id
|
8
7
|
attr_reader :name
|
9
8
|
|
10
|
-
def initialize(xml,
|
11
|
-
|
12
|
-
@parent = parent
|
9
|
+
def initialize(xml, parent_tag)
|
10
|
+
super(xml, parent_tag)
|
13
11
|
|
14
|
-
@id = xml.attribute("xmi.id").to_s
|
15
12
|
@name = xml.attribute("name").to_s.strip
|
16
13
|
end
|
17
14
|
|
data/lib/xmimodel/final_state.rb
CHANGED
@@ -1,32 +1,29 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
+
require 'xmimodel/tag'
|
4
|
+
|
3
5
|
##
|
4
6
|
# UML:Generalization
|
5
|
-
class Generalization
|
7
|
+
class Generalization < Tag
|
6
8
|
|
7
|
-
attr_reader :xml
|
8
|
-
|
9
|
-
attr_reader :id
|
10
9
|
attr_reader :child
|
11
10
|
attr_reader :parent
|
12
11
|
|
13
|
-
def initialize(xml,
|
14
|
-
|
15
|
-
@xmi_model = xmi_model
|
12
|
+
def initialize(xml, parent_tag)
|
13
|
+
super(xml, parent_tag)
|
16
14
|
|
17
|
-
@id = xml.attribute("xmi.id").to_s
|
18
15
|
@child = XmiHelper.generalization_child(xml)
|
19
16
|
@parent = XmiHelper.generalization_parent(xml)
|
20
17
|
end
|
21
18
|
|
22
19
|
def child_obj
|
23
20
|
return nil if @child.nil? or @child.empty?
|
24
|
-
@child_obj =
|
21
|
+
@child_obj = xml_root.class_by_id(@child)
|
25
22
|
end
|
26
23
|
|
27
24
|
def parent_obj
|
28
25
|
return nil if @parent.nil? or @parent.empty?
|
29
|
-
@parent_obj =
|
26
|
+
@parent_obj = xml_root.class_by_id(@parent)
|
30
27
|
end
|
31
28
|
|
32
29
|
def to_s
|
data/lib/xmimodel/namespace.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'xmimodel/association'
|
2
4
|
require 'xmimodel/attribute'
|
3
5
|
require 'xmimodel/clazz'
|
4
6
|
require 'xmimodel/data_type'
|
5
7
|
require 'xmimodel/use_case'
|
6
8
|
require 'xmimodel/package'
|
9
|
+
require 'xmimodel/tag'
|
7
10
|
|
8
11
|
# UML:Namespace.ownedElement
|
9
|
-
class Namespace
|
10
|
-
|
11
|
-
attr_reader :xml
|
12
|
-
attr_reader :parent
|
12
|
+
class Namespace < Tag
|
13
13
|
|
14
14
|
attr_reader :activity_graphs
|
15
15
|
|
@@ -323,9 +323,8 @@ class Namespace
|
|
323
323
|
attr_reader :Partition
|
324
324
|
=end
|
325
325
|
|
326
|
-
def initialize(xml,
|
327
|
-
|
328
|
-
@parent = parent
|
326
|
+
def initialize(xml, parent_tag)
|
327
|
+
super(xml, parent_tag)
|
329
328
|
|
330
329
|
@activity_graphs = Array.new
|
331
330
|
XmiHelper.activity_graphs(xml).each do |obj|
|
@@ -369,5 +368,8 @@ class Namespace
|
|
369
368
|
@packages << obj
|
370
369
|
end
|
371
370
|
end
|
372
|
-
|
371
|
+
|
372
|
+
def to_s
|
373
|
+
"Namespace"
|
374
|
+
end
|
373
375
|
end
|
data/lib/xmimodel/operation.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
require 'xmimodel/parameter'
|
4
|
+
require 'xmimodel/tag'
|
4
5
|
|
5
|
-
|
6
|
+
class Operation < Tag
|
6
7
|
|
7
|
-
attr_reader :id
|
8
8
|
attr_reader :name
|
9
9
|
attr_reader :visibility
|
10
10
|
|
11
11
|
attr_reader :parameters
|
12
12
|
|
13
|
-
def initialize(xml,
|
14
|
-
|
15
|
-
|
13
|
+
def initialize(xml, parent)
|
14
|
+
super(xml, parent)
|
15
|
+
|
16
|
+
@clazz = parent
|
16
17
|
|
17
|
-
@id = xml.attribute("xmi:id").to_s
|
18
18
|
@name = xml.attribute("name").to_s
|
19
19
|
@visibility = xml.attribute("visibility").to_s
|
20
20
|
@visibility = "private" if @visibility == ""
|
data/lib/xmimodel/package.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'xmimodel/clazz'
|
4
|
-
require 'xmimodel/use_case'
|
5
4
|
require 'xmimodel/namespace'
|
5
|
+
require 'xmimodel/tag'
|
6
|
+
require 'xmimodel/use_case'
|
6
7
|
|
7
|
-
class Package
|
8
|
-
|
9
|
-
attr_reader :xml
|
8
|
+
class Package < Tag
|
10
9
|
|
11
10
|
attr_reader :name
|
12
11
|
attr_reader :full_name
|
@@ -14,10 +13,10 @@ class Package
|
|
14
13
|
|
15
14
|
attr_reader :namespace
|
16
15
|
|
17
|
-
def initialize(xml,
|
16
|
+
def initialize(xml, parent_tag)
|
17
|
+
super(xml, parent_tag)
|
18
18
|
|
19
|
-
@
|
20
|
-
@parent_package = parent.parent unless parent.nil?
|
19
|
+
@parent_package = parent_tag.parent_tag unless parent_tag.nil? or parent_tag.class == XmiModel
|
21
20
|
|
22
21
|
@name = xml.attribute("name").to_s
|
23
22
|
@full_name = XmiHelper.full_package_name(xml)
|
@@ -30,6 +29,11 @@ class Package
|
|
30
29
|
self
|
31
30
|
end
|
32
31
|
|
32
|
+
def add_xml_class(xml)
|
33
|
+
add_namespace() if !XmiHelper.has_namespace?(self.xml)
|
34
|
+
@namespace.xml.inner_html = @namespace.xml.inner_html + xml
|
35
|
+
end
|
36
|
+
|
33
37
|
def activity_graphs
|
34
38
|
return Array.new if @namespace.nil?
|
35
39
|
@namespace.activity_graphs
|
@@ -79,6 +83,13 @@ class Package
|
|
79
83
|
|
80
84
|
def to_s
|
81
85
|
"Package[#{@full_name}]"
|
82
|
-
end
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
def add_namespace
|
91
|
+
xml_namespace = XmiHelper.add_namespace(self.xml)
|
92
|
+
@namespace = Namespace.new(xml_namespace, self)
|
93
|
+
end
|
83
94
|
|
84
95
|
end
|
data/lib/xmimodel/parameter.rb
CHANGED
@@ -1,19 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
|
2
|
-
|
3
|
-
|
4
|
-
attr_reader :xml
|
5
|
-
attr_reader :owner
|
3
|
+
require 'xmimodel/tag'
|
6
4
|
|
7
|
-
|
5
|
+
class Parameter < Tag
|
6
|
+
|
8
7
|
attr_reader :name
|
9
8
|
attr_reader :kind
|
10
9
|
|
11
10
|
attr_reader :stereotypes
|
12
11
|
attr_reader :tagged_values
|
13
12
|
|
14
|
-
def initialize(xml,
|
15
|
-
|
16
|
-
@owner = owner
|
13
|
+
def initialize(xml, parent_tag)
|
14
|
+
super(xml, parent_tag)
|
17
15
|
|
18
16
|
@id = xml.attribute("xmi:id").to_s
|
19
17
|
@name = xml.attribute("name").to_s
|
@@ -45,8 +43,8 @@ class Parameter
|
|
45
43
|
end
|
46
44
|
|
47
45
|
def full_name
|
48
|
-
return "#{@
|
49
|
-
return "#{@
|
46
|
+
return "#{@parent_tag.full_name}::#{@kind}" if (@name.nil? || @name.empty?)
|
47
|
+
return "#{@parent_tag.full_name}::#{@name}"
|
50
48
|
end
|
51
49
|
|
52
50
|
def to_s
|
@@ -1,11 +1,14 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'xmimodel/state'
|
4
|
+
require 'xmimodel/tag'
|
2
5
|
|
3
6
|
class PseudoState < State
|
4
7
|
|
5
8
|
attr_reader :kind
|
6
9
|
|
7
|
-
def initialize(xml,
|
8
|
-
super(xml,
|
10
|
+
def initialize(xml, parent_tag)
|
11
|
+
super(xml, parent_tag)
|
9
12
|
|
10
13
|
@kind = xml.attribute("kind").to_s
|
11
14
|
end
|
@@ -1,21 +1,20 @@
|
|
1
|
-
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
require 'xmimodel/parameter'
|
4
|
+
require 'xmimodel/tag'
|
4
5
|
|
5
|
-
|
6
|
+
class SignalEvent < Tag
|
6
7
|
|
7
|
-
attr_reader :id
|
8
8
|
attr_reader :name
|
9
9
|
|
10
10
|
attr_reader :parameters
|
11
11
|
|
12
12
|
attr_reader :use_case
|
13
13
|
|
14
|
-
def initialize(xml,
|
15
|
-
|
16
|
-
@use_case =
|
14
|
+
def initialize(xml, parent_tag)
|
15
|
+
super(xml, parent_tag)
|
16
|
+
@use_case = parent_tag.parent_tag
|
17
17
|
|
18
|
-
@id = xml.attribute("xmi:id").to_s
|
19
18
|
@name = xml.attribute("name").to_s
|
20
19
|
|
21
20
|
@parameters = Array.new
|
data/lib/xmimodel/state.rb
CHANGED
@@ -1,20 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
|
2
|
-
|
3
|
+
require 'xmimodel/tag'
|
4
|
+
|
5
|
+
class State < Tag
|
3
6
|
|
4
|
-
attr_reader :xml
|
5
7
|
attr_reader :activity_graph
|
6
8
|
|
7
|
-
attr_reader :id
|
8
9
|
attr_reader :name
|
9
10
|
|
10
11
|
attr_reader :stereotypes
|
11
12
|
attr_reader :tagged_values
|
12
13
|
|
13
|
-
def initialize(xml,
|
14
|
-
|
15
|
-
|
14
|
+
def initialize(xml, parent_tag)
|
15
|
+
super(xml, parent_tag)
|
16
|
+
|
17
|
+
@activity_graph = parent_tag
|
16
18
|
|
17
|
-
@id = xml.attribute("xmi.id").to_s
|
18
19
|
@name = xml.attribute("name").to_s
|
19
20
|
|
20
21
|
if @name.nil? || @name.empty?
|
data/lib/xmimodel/stereotype.rb
CHANGED
@@ -1,23 +1,32 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
|
2
|
-
|
3
|
+
require 'xmimodel/tag'
|
4
|
+
|
5
|
+
class Stereotype < Tag
|
3
6
|
|
4
|
-
attr_reader :xml
|
5
7
|
attr_reader :href
|
6
8
|
|
7
|
-
def initialize(xml,
|
8
|
-
|
9
|
-
@owner = owner
|
9
|
+
def initialize(xml, parent_tag)
|
10
|
+
super(xml, parent_tag)
|
10
11
|
|
11
|
-
@id = xml.attribute("xmi.id").to_s
|
12
12
|
@name = xml.attribute("name").to_s
|
13
13
|
@href = xml.attribute("href").to_s
|
14
14
|
@idref = xml.attribute("xmi.idref").to_s
|
15
15
|
end
|
16
16
|
|
17
17
|
def <=>(obj)
|
18
|
-
|
18
|
+
name <=> obj.name
|
19
19
|
end
|
20
20
|
|
21
|
+
def ==(obj)
|
22
|
+
return false if obj.nil?
|
23
|
+
if String == obj.class
|
24
|
+
name == obj
|
25
|
+
else
|
26
|
+
name == obj.name
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
21
30
|
def name
|
22
31
|
return @name unless (@name.nil? or @name.empty?)
|
23
32
|
|
data/lib/xmimodel/tag.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class Tag
|
4
|
+
|
5
|
+
# @return [Nokogiri::XML::Element]
|
6
|
+
attr_reader :xml
|
7
|
+
|
8
|
+
# @return [Tag]
|
9
|
+
attr_reader :parent_tag
|
10
|
+
|
11
|
+
# @return [String]
|
12
|
+
attr_reader :id
|
13
|
+
|
14
|
+
##
|
15
|
+
# Constructor.
|
16
|
+
#
|
17
|
+
# @param xml [Nokogiri::XML::Element]
|
18
|
+
# @param parent_tag [Tag]
|
19
|
+
def initialize(xml, parent_tag)
|
20
|
+
|
21
|
+
raise "Diferente de Tag. #{parent_tag.class}" if !parent_tag.kind_of?(Tag) && parent_tag.class != XmiModel
|
22
|
+
|
23
|
+
@xml = xml
|
24
|
+
@parent_tag = parent_tag
|
25
|
+
|
26
|
+
@id = xml.attribute("xmi.id").to_s
|
27
|
+
end
|
28
|
+
|
29
|
+
def xml_root
|
30
|
+
parent_tag = @parent_tag
|
31
|
+
until parent_tag.class == XmiModel
|
32
|
+
parent_tag = parent_tag.parent_tag
|
33
|
+
end
|
34
|
+
parent_tag
|
35
|
+
end
|
36
|
+
end
|
@@ -1,17 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
|
2
|
-
|
3
|
+
require 'xmimodel/tag'
|
3
4
|
|
4
|
-
|
5
|
+
class TaggedValue < Tag
|
5
6
|
|
6
|
-
attr_reader :id
|
7
7
|
attr_reader :name
|
8
8
|
attr_reader :value
|
9
9
|
|
10
|
-
def initialize(xml,
|
11
|
-
|
12
|
-
@owner = owner
|
10
|
+
def initialize(xml, parent_tag)
|
11
|
+
super(xml, parent_tag)
|
13
12
|
|
14
|
-
@id = xml.attribute("xmi.id").to_s
|
15
13
|
@name = xml.attribute("name").to_s
|
16
14
|
|
17
15
|
if @name.nil? or @name.empty?
|
@@ -26,12 +24,19 @@ class TaggedValue
|
|
26
24
|
|
27
25
|
end
|
28
26
|
|
27
|
+
def value=(new_value)
|
28
|
+
# testar para outros tipos que não sejam o Magic Draw
|
29
|
+
tag = @xml.at_xpath("./UML:TaggedValue.dataValue")
|
30
|
+
tag.inner_html = new_value
|
31
|
+
@value = new_value
|
32
|
+
end
|
33
|
+
|
29
34
|
def ==(obj)
|
30
35
|
return false if obj.nil?
|
31
36
|
if String == obj.class
|
32
|
-
return "#{@name}
|
37
|
+
return "#{@name}".eql?(obj)
|
33
38
|
else
|
34
|
-
return @name.eql?(obj.name)
|
39
|
+
return @name.eql?(obj.name)
|
35
40
|
end
|
36
41
|
end
|
37
42
|
|
data/lib/xmimodel/transition.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'xmimodel/stereotype'
|
4
|
+
require 'xmimodel/tag'
|
2
5
|
require 'xmimodel/tagged_value'
|
3
6
|
|
4
|
-
class Transition
|
5
|
-
|
6
|
-
attr_reader :xml
|
7
|
-
attr_reader :id
|
7
|
+
class Transition < Tag
|
8
8
|
|
9
9
|
attr_reader :activity_graph
|
10
10
|
|
@@ -17,11 +17,11 @@ class Transition
|
|
17
17
|
|
18
18
|
attr_reader :guard_condition
|
19
19
|
|
20
|
-
def initialize(xml,
|
21
|
-
|
22
|
-
|
20
|
+
def initialize(xml, parent_tag)
|
21
|
+
super(xml, parent_tag)
|
22
|
+
|
23
|
+
@activity_graph = parent_tag
|
23
24
|
|
24
|
-
@id = xml.attribute("xmi.id").to_s
|
25
25
|
@trigger = xml.attribute("trigger").to_s
|
26
26
|
@source = xml.attribute("source").to_s
|
27
27
|
@target = xml.attribute("target").to_s
|
data/lib/xmimodel/use_case.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'xmimodel/activity_graph'
|
2
4
|
require 'xmimodel/stereotype'
|
3
5
|
require 'xmimodel/signal_event'
|
6
|
+
require 'xmimodel/tag'
|
4
7
|
require 'xmimodel/tagged_value'
|
5
8
|
|
6
|
-
class UseCase
|
9
|
+
class UseCase < Tag
|
7
10
|
|
8
|
-
attr_reader :xml
|
9
11
|
attr_reader :package
|
10
12
|
|
11
|
-
attr_reader :id
|
12
13
|
attr_reader :name
|
13
14
|
|
14
15
|
attr_reader :stereotypes
|
@@ -16,11 +17,11 @@ class UseCase
|
|
16
17
|
|
17
18
|
#UML:CallEvent
|
18
19
|
|
19
|
-
def initialize(xml,
|
20
|
-
|
21
|
-
|
20
|
+
def initialize(xml, parent_tag)
|
21
|
+
super(xml, parent_tag)
|
22
|
+
|
23
|
+
@package = parent_tag.parent_tag
|
22
24
|
|
23
|
-
@id = xml.attribute("xmi:id").to_s
|
24
25
|
@name = xml.attribute("name").to_s
|
25
26
|
|
26
27
|
if XmiHelper.has_namespace?(xml)
|
data/lib/xmimodel/xmihelper.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
|
2
3
|
require 'nokogiri'
|
3
4
|
|
4
5
|
##
|
@@ -48,7 +49,16 @@ class XmiHelper
|
|
48
49
|
# Returns a object Nokogiri::XML::Element of type 'UML:ActivityGraph'.
|
49
50
|
def self.activity_graphs(tag)
|
50
51
|
namespace(tag).xpath('./UML:ActivityGraph')
|
51
|
-
end
|
52
|
+
end
|
53
|
+
|
54
|
+
##
|
55
|
+
# Add a tag UML:Namespace.ownedElement to the parameter xml
|
56
|
+
#
|
57
|
+
def self.add_namespace(xml)
|
58
|
+
xml_namespace = Nokogiri::XML::Node.new('Namespace.ownedElement', xml.document)
|
59
|
+
xml << xml_namespace
|
60
|
+
return xml_namespace
|
61
|
+
end
|
52
62
|
|
53
63
|
##
|
54
64
|
# Get all the Associations in the model.
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xmimodel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Marcus Siqueira
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-08-28 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: A helper gem for working with XMI files
|
15
14
|
email: marvinsiq@gmail.com
|
@@ -30,37 +29,38 @@ files:
|
|
30
29
|
- lib/xmimodel/transition.rb
|
31
30
|
- lib/xmimodel/stereotype.rb
|
32
31
|
- lib/xmimodel/data_type.rb
|
32
|
+
- lib/xmimodel/association_end.rb
|
33
33
|
- lib/xmimodel/parameter.rb
|
34
34
|
- lib/xmimodel/xmihelper.rb
|
35
35
|
- lib/xmimodel/association.rb
|
36
36
|
- lib/xmimodel/action_state.rb
|
37
|
+
- lib/xmimodel/tag.rb
|
37
38
|
- lib/xmimodel/pseudo_state.rb
|
38
39
|
- lib/xmimodel/tagged_value.rb
|
39
40
|
- lib/xmimodel/clazz.rb
|
40
41
|
- lib/xmimodel/state.rb
|
41
42
|
homepage: https://github.com/marvinsiq/xmimodel
|
42
43
|
licenses: []
|
44
|
+
metadata: {}
|
43
45
|
post_install_message:
|
44
46
|
rdoc_options: []
|
45
47
|
require_paths:
|
46
48
|
- lib
|
47
49
|
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
-
none: false
|
49
50
|
requirements:
|
50
51
|
- - ! '>='
|
51
52
|
- !ruby/object:Gem::Version
|
52
53
|
version: '0'
|
53
54
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
-
none: false
|
55
55
|
requirements:
|
56
56
|
- - ! '>='
|
57
57
|
- !ruby/object:Gem::Version
|
58
58
|
version: '0'
|
59
59
|
requirements: []
|
60
60
|
rubyforge_project:
|
61
|
-
rubygems_version:
|
61
|
+
rubygems_version: 2.0.7
|
62
62
|
signing_key:
|
63
|
-
specification_version:
|
63
|
+
specification_version: 4
|
64
64
|
summary: Xmi Model!
|
65
65
|
test_files: []
|
66
66
|
has_rdoc:
|