ea 0.6.159 → 0.6.161
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +13 -47
- data/lib/ea/export/xsd/class_mapping.rb +4 -4
- data/lib/ea/export/xsd/generator.rb +21 -12
- data/lib/ea/mdg/stereotype_alias_registry.rb +6 -6
- data/lib/ea/qea/database.rb +49 -0
- data/lib/ea/qea/factory/generalization_builder.rb +17 -17
- data/lib/ea/qea/infrastructure/table_reader.rb +26 -4
- data/lib/ea/qea/models/ea_datatype.rb +2 -2
- data/lib/ea/qea/models/ea_document.rb +2 -2
- data/lib/ea/qea/models/ea_script.rb +2 -2
- data/lib/ea/qea/services/configuration.rb +5 -7
- data/lib/ea/qea/services/database_loader.rb +31 -11
- data/lib/ea/qea/validation/formatters/text_formatter.rb +4 -4
- data/lib/ea/qea/validation/validation_engine.rb +4 -4
- data/lib/ea/qea/validation/validation_result.rb +4 -4
- data/lib/ea/qea/verification/comparison_result.rb +1 -1
- data/lib/ea/rules/general_attribute_mapping.rb +35 -0
- data/lib/ea/rules/namespacing.rb +27 -0
- data/lib/ea/rules.rb +10 -0
- data/lib/ea/sources/multiplicity.rb +41 -0
- data/lib/ea/sources/qea/relationship_builder.rb +6 -40
- data/lib/ea/sources/xmi/constraint_builder.rb +18 -18
- data/lib/ea/sources/xmi/diagram_builder/association_class_metadata.rb +50 -12
- data/lib/ea/sources/xmi/diagram_builder/connector_metadata.rb +59 -7
- data/lib/ea/sources/xmi/diagram_builder/font_settings.rb +2 -2
- data/lib/ea/sources/xmi/diagram_builder/umldi_edges/property_roles.rb +7 -5
- data/lib/ea/sources/xmi/diagram_builder/umldi_edges.rb +16 -10
- data/lib/ea/sources/xmi/extension_types.rb +2 -2
- data/lib/ea/sources/xmi/instance_builder.rb +6 -4
- data/lib/ea/sources/xmi/note_builder.rb +1 -1
- data/lib/ea/sources/xmi/reception_builder.rb +2 -2
- data/lib/ea/sources/xmi/relationship_builder.rb +6 -24
- data/lib/ea/sources/xmi/tag_builder.rb +2 -2
- data/lib/ea/sources/xmi/umldi_keyword_extractor.rb +2 -2
- data/lib/ea/sources.rb +1 -0
- data/lib/ea/svg/ea_emitter/document.rb +12 -1
- data/lib/ea/svg/ea_emitter/element/package_shape_renderer.rb +4 -4
- data/lib/ea/svg/ea_emitter/elements.rb +1 -1
- data/lib/ea/svg/parity/checker.rb +21 -10
- data/lib/ea/svg/parity/differ.rb +4 -2
- data/lib/ea/svg/parity/suite.rb +1 -1
- data/lib/ea/transformers/qea_to_xmi/transformer.rb +3 -7
- data/lib/ea/version.rb +1 -1
- data/lib/ea/xmi/liquid_drops/connector_drop.rb +2 -2
- data/lib/ea/xmi/parser.rb +39 -46
- data/lib/ea/xmi.rb +1 -1
- data/lib/ea/xml.rb +44 -0
- data/lib/ea.rb +2 -0
- metadata +23 -18
|
@@ -160,7 +160,7 @@ module Ea
|
|
|
160
160
|
# @return [Boolean]
|
|
161
161
|
def valid?(validators: nil)
|
|
162
162
|
result = validate(validators: validators)
|
|
163
|
-
!result.
|
|
163
|
+
!result.errors?
|
|
164
164
|
end
|
|
165
165
|
|
|
166
166
|
# Builds validation context from document and database
|
|
@@ -346,20 +346,20 @@ module Ea
|
|
|
346
346
|
puts result.summary
|
|
347
347
|
puts
|
|
348
348
|
|
|
349
|
-
if result.
|
|
349
|
+
if result.errors?
|
|
350
350
|
puts "ERRORS (#{result.errors.size}):"
|
|
351
351
|
puts
|
|
352
352
|
display_messages_by_category(result.errors)
|
|
353
353
|
end
|
|
354
354
|
|
|
355
|
-
if result.
|
|
355
|
+
if result.warnings?
|
|
356
356
|
puts
|
|
357
357
|
puts "WARNINGS (#{result.warnings.size}):"
|
|
358
358
|
puts
|
|
359
359
|
display_messages_by_category(result.warnings)
|
|
360
360
|
end
|
|
361
361
|
|
|
362
|
-
if result.
|
|
362
|
+
if result.info? && @options[:verbose]
|
|
363
363
|
puts
|
|
364
364
|
puts "INFO (#{result.info.size}):"
|
|
365
365
|
puts
|
|
@@ -60,21 +60,21 @@ module Ea
|
|
|
60
60
|
# Checks if there are any error messages
|
|
61
61
|
#
|
|
62
62
|
# @return [Boolean]
|
|
63
|
-
def
|
|
63
|
+
def errors?
|
|
64
64
|
@messages.any?(&:error?)
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
# Checks if there are any warning messages
|
|
68
68
|
#
|
|
69
69
|
# @return [Boolean]
|
|
70
|
-
def
|
|
70
|
+
def warnings?
|
|
71
71
|
@messages.any?(&:warning?)
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
# Checks if there are any info messages
|
|
75
75
|
#
|
|
76
76
|
# @return [Boolean]
|
|
77
|
-
def
|
|
77
|
+
def info?
|
|
78
78
|
@messages.any?(&:info?)
|
|
79
79
|
end
|
|
80
80
|
|
|
@@ -82,7 +82,7 @@ module Ea
|
|
|
82
82
|
#
|
|
83
83
|
# @return [Boolean]
|
|
84
84
|
def valid?
|
|
85
|
-
!
|
|
85
|
+
!errors?
|
|
86
86
|
end
|
|
87
87
|
|
|
88
88
|
# Returns all error messages
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ea
|
|
4
|
+
module Rules
|
|
5
|
+
# Shared construction of Lutaml::Uml::GeneralAttribute rows for
|
|
6
|
+
# both the QEA factory and the XMI parser — one place for the
|
|
7
|
+
# field list and the boolean coercions (is_derived normalizes
|
|
8
|
+
# boolean-or-nil, has_association mirrors the presence of an
|
|
9
|
+
# association reference). The definition is taken verbatim: each
|
|
10
|
+
# walker resolves and strips it according to its own source
|
|
11
|
+
# semantics.
|
|
12
|
+
module GeneralAttributeMapping
|
|
13
|
+
module_function
|
|
14
|
+
|
|
15
|
+
# @param fields [Hash] :id, :name, :type, :xmi_id, :cardinality,
|
|
16
|
+
# :definition, :association, :type_ns, :is_derived
|
|
17
|
+
# @return [Lutaml::Uml::GeneralAttribute]
|
|
18
|
+
def build(fields)
|
|
19
|
+
association = fields[:association]
|
|
20
|
+
Lutaml::Uml::GeneralAttribute.new(
|
|
21
|
+
id: fields[:id],
|
|
22
|
+
name: fields[:name],
|
|
23
|
+
type: fields[:type],
|
|
24
|
+
xmi_id: fields[:xmi_id],
|
|
25
|
+
cardinality: fields[:cardinality],
|
|
26
|
+
definition: fields[:definition],
|
|
27
|
+
association: association,
|
|
28
|
+
type_ns: fields[:type_ns],
|
|
29
|
+
is_derived: fields[:is_derived] == true,
|
|
30
|
+
has_association: !association.nil?
|
|
31
|
+
)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ea
|
|
4
|
+
module Rules
|
|
5
|
+
# EA namespacing rule for attribute type references. Types in the
|
|
6
|
+
# "core" and "gml" namespaces resolve against the classifier's own
|
|
7
|
+
# upper-level package namespace; any other namespace string is
|
|
8
|
+
# kept as-is; a missing namespace falls back to the upper package.
|
|
9
|
+
module Namespacing
|
|
10
|
+
module_function
|
|
11
|
+
|
|
12
|
+
# @param type_ns [String, nil] attribute type namespace
|
|
13
|
+
# @param upper_klass [String, nil] the classifier's upper-level
|
|
14
|
+
# package namespace
|
|
15
|
+
# @return [String, nil] resolved namespace
|
|
16
|
+
def resolve_name_ns(type_ns, upper_klass)
|
|
17
|
+
ns = case type_ns
|
|
18
|
+
when "core", "gml"
|
|
19
|
+
upper_klass
|
|
20
|
+
else
|
|
21
|
+
type_ns
|
|
22
|
+
end
|
|
23
|
+
ns || upper_klass
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
data/lib/ea/rules.rb
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ea
|
|
4
|
+
# EA-domain semantic rules shared across input formats (QEA rows and
|
|
5
|
+
# Sparx XMI). Format-specific traversal lives in Qea::Rules.
|
|
6
|
+
module Rules
|
|
7
|
+
autoload :GeneralAttributeMapping, "ea/rules/general_attribute_mapping"
|
|
8
|
+
autoload :Namespacing, "ea/rules/namespacing"
|
|
9
|
+
end
|
|
10
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ea
|
|
4
|
+
module Sources
|
|
5
|
+
# Multiplicity-string parsing shared by the QEA and XMI source
|
|
6
|
+
# adapters. EA multiplicity text is "lower..upper", "*" meaning
|
|
7
|
+
# unbounded (parsed as -1); blank or absent text means the
|
|
8
|
+
# multiplicity was never specified (parsed as nil, which renderers
|
|
9
|
+
# use to suppress the label).
|
|
10
|
+
module Multiplicity
|
|
11
|
+
module_function
|
|
12
|
+
|
|
13
|
+
# @param cardinality [String, nil] raw multiplicity text
|
|
14
|
+
# @return [Integer, nil] lower bound, or nil when unspecified
|
|
15
|
+
def lower(cardinality)
|
|
16
|
+
text = raw(cardinality)
|
|
17
|
+
return nil unless text
|
|
18
|
+
|
|
19
|
+
Integer(text.split("..").first, exception: false)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# @param cardinality [String, nil] raw multiplicity text
|
|
23
|
+
# @return [Integer, nil] upper bound (-1 unbounded),
|
|
24
|
+
# or nil when unspecified
|
|
25
|
+
def upper(cardinality)
|
|
26
|
+
text = raw(cardinality)
|
|
27
|
+
return nil unless text
|
|
28
|
+
|
|
29
|
+
up = text.split("..").last
|
|
30
|
+
up == "*" ? -1 : Integer(up, exception: false)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# @param cardinality [Object] raw value from the source
|
|
34
|
+
# @return [String, nil] stripped text, nil when blank
|
|
35
|
+
def raw(cardinality)
|
|
36
|
+
text = cardinality.to_s.strip
|
|
37
|
+
text.empty? ? nil : text
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -72,12 +72,12 @@ module Ea
|
|
|
72
72
|
target_id: id_for_object_id(row.end_object_id),
|
|
73
73
|
source_role_name: row.sourcerole,
|
|
74
74
|
target_role_name: row.destrole,
|
|
75
|
-
source_multiplicity_lower:
|
|
76
|
-
source_multiplicity_upper:
|
|
77
|
-
target_multiplicity_lower:
|
|
78
|
-
target_multiplicity_upper:
|
|
79
|
-
source_multiplicity_raw:
|
|
80
|
-
target_multiplicity_raw:
|
|
75
|
+
source_multiplicity_lower: Sources::Multiplicity.lower(row.sourcecard),
|
|
76
|
+
source_multiplicity_upper: Sources::Multiplicity.upper(row.sourcecard),
|
|
77
|
+
target_multiplicity_lower: Sources::Multiplicity.lower(row.destcard),
|
|
78
|
+
target_multiplicity_upper: Sources::Multiplicity.upper(row.destcard),
|
|
79
|
+
source_multiplicity_raw: Sources::Multiplicity.raw(row.sourcecard),
|
|
80
|
+
target_multiplicity_raw: Sources::Multiplicity.raw(row.destcard),
|
|
81
81
|
source_aggregation: source_aggregation_for(row),
|
|
82
82
|
target_aggregation: aggregation_from(row.destisaggregate),
|
|
83
83
|
source_navigable: navigable?(row.sourceisnavigable, row.direction,
|
|
@@ -93,40 +93,6 @@ module Ea
|
|
|
93
93
|
IdNormalizer.from_guid(obj.ea_guid)
|
|
94
94
|
end
|
|
95
95
|
|
|
96
|
-
# Returns nil when cardinality is absent so the renderer can
|
|
97
|
-
# distinguish "no multiplicity specified" from an explicit
|
|
98
|
-
# "1". EA only renders the "1" label when the modeller set it
|
|
99
|
-
# explicitly (SourceCard/DestCard = "1").
|
|
100
|
-
# Verbatim cardinality text. Blank cards stay nil so the
|
|
101
|
-
# renderer keeps suppressing unspecified multiplicities.
|
|
102
|
-
def raw_card(cardinality)
|
|
103
|
-
text = cardinality.to_s.strip
|
|
104
|
-
text.empty? ? nil : text
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
def parse_lower(cardinality)
|
|
108
|
-
return nil if cardinality.nil? || cardinality.empty?
|
|
109
|
-
|
|
110
|
-
begin
|
|
111
|
-
Integer(cardinality.split("..").first)
|
|
112
|
-
rescue StandardError
|
|
113
|
-
nil
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
def parse_upper(cardinality)
|
|
118
|
-
return nil if cardinality.nil? || cardinality.empty?
|
|
119
|
-
|
|
120
|
-
upper = cardinality.split("..").last
|
|
121
|
-
return -1 if upper == "*"
|
|
122
|
-
|
|
123
|
-
begin
|
|
124
|
-
Integer(upper)
|
|
125
|
-
rescue StandardError
|
|
126
|
-
nil
|
|
127
|
-
end
|
|
128
|
-
end
|
|
129
|
-
|
|
130
96
|
# EA stores the aggregate end in t_connector.SourceIsAggregate/
|
|
131
97
|
# DestIsAggregate (0 none, 1 shared, 2 composite) — NOT in
|
|
132
98
|
# DestAccess, which carries the accessibility string
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "leptris"
|
|
4
4
|
|
|
5
5
|
module Ea
|
|
6
6
|
module Sources
|
|
@@ -32,28 +32,28 @@ module Ea
|
|
|
32
32
|
@seen_owners = {}
|
|
33
33
|
@blocks_seen = {}
|
|
34
34
|
@skip_block = false
|
|
35
|
-
File.
|
|
35
|
+
Leptris::XML::Pull.parse(File.read(xmi_path)).each { |event| visit(event) }
|
|
36
36
|
@grouped
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
-
def visit(
|
|
40
|
-
case
|
|
41
|
-
when
|
|
39
|
+
def visit(event)
|
|
40
|
+
case event.type
|
|
41
|
+
when :end_element
|
|
42
42
|
@owner = nil if @path.pop == "element"
|
|
43
|
-
when
|
|
44
|
-
enter(
|
|
45
|
-
@path.push(
|
|
43
|
+
when :start_element
|
|
44
|
+
enter(event)
|
|
45
|
+
@path.push(event.name)
|
|
46
46
|
end
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
-
def enter(
|
|
50
|
-
if
|
|
51
|
-
@owner = first_block_owner(
|
|
52
|
-
elsif
|
|
49
|
+
def enter(event)
|
|
50
|
+
if event.name == "element" && @path.last == "elements"
|
|
51
|
+
@owner = first_block_owner(event.attrs&.fetch("xmi:idref", nil))
|
|
52
|
+
elsif event.name == "constraints" && @owner && @path.last == "element"
|
|
53
53
|
@skip_block = @blocks_seen.key?(@owner)
|
|
54
54
|
@blocks_seen[@owner] = true
|
|
55
|
-
elsif
|
|
56
|
-
(@grouped[@owner] ||= []) << constraint(
|
|
55
|
+
elsif event.name == "constraint" && @owner && !@skip_block && @path.last(2) == %w[element constraints]
|
|
56
|
+
(@grouped[@owner] ||= []) << constraint(event)
|
|
57
57
|
end
|
|
58
58
|
end
|
|
59
59
|
|
|
@@ -69,10 +69,10 @@ module Ea
|
|
|
69
69
|
def constraint(node)
|
|
70
70
|
Ea::Model::Constraint.new(
|
|
71
71
|
id: IdNormalizer.synthetic_id(@owner, "constraint", @grouped[@owner].to_a.size.to_s),
|
|
72
|
-
name: node.
|
|
73
|
-
kind: node.
|
|
74
|
-
body: node.
|
|
75
|
-
status: node.
|
|
72
|
+
name: node.attrs&.fetch("name", nil).to_s,
|
|
73
|
+
kind: node.attrs&.fetch("type", nil).to_s,
|
|
74
|
+
body: node.attrs&.fetch("description", nil).to_s,
|
|
75
|
+
status: node.attrs&.fetch("status", nil).to_s
|
|
76
76
|
)
|
|
77
77
|
end
|
|
78
78
|
end
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "moxml"
|
|
4
|
+
require "leptris"
|
|
4
5
|
|
|
5
6
|
module Ea
|
|
6
7
|
module Sources
|
|
@@ -76,21 +77,59 @@ module Ea
|
|
|
76
77
|
|
|
77
78
|
def scan_metadata
|
|
78
79
|
data = { connectors: {}, proxies: {}, classes: [] }
|
|
79
|
-
|
|
80
|
-
|
|
80
|
+
@capture = nil
|
|
81
|
+
# Single streaming pass over the XMI: reconstruct each
|
|
82
|
+
# <element>/<connector>'s outer XML from the pull stream and
|
|
83
|
+
# parse it as a subtree for the attribute lookups below.
|
|
84
|
+
Leptris::XML::Pull.parse(File.read(@xmi_path)).each do |event|
|
|
85
|
+
case event.type
|
|
86
|
+
when :start_element
|
|
87
|
+
if @capture
|
|
88
|
+
@capture[:depth] += 1
|
|
89
|
+
@capture[:xml] << write_start(event)
|
|
90
|
+
elsif %w[element connector].include?(event.name)
|
|
91
|
+
@capture = { kind: event.name, depth: 1, xml: +write_start(event) }
|
|
92
|
+
end
|
|
93
|
+
when :end_element
|
|
94
|
+
next unless @capture
|
|
95
|
+
|
|
96
|
+
@capture[:xml] << "</#{event.name}>"
|
|
97
|
+
@capture[:depth] -= 1
|
|
98
|
+
if @capture[:depth].zero?
|
|
99
|
+
subtree = Moxml.parse(scrub(@capture[:xml])).root
|
|
100
|
+
send("read_#{@capture[:kind]}", subtree, data)
|
|
101
|
+
@capture = nil
|
|
102
|
+
end
|
|
103
|
+
when :text
|
|
104
|
+
@capture[:xml] << escape_text(event.text) if @capture
|
|
105
|
+
end
|
|
81
106
|
end
|
|
82
107
|
data
|
|
83
108
|
end
|
|
84
109
|
|
|
85
|
-
|
|
86
|
-
|
|
110
|
+
# EA XMI files occasionally carry bytes outside the declared
|
|
111
|
+
# encoding; the nokogiri outer-xml path tolerated them, so scrub
|
|
112
|
+
# the reconstructed fragment the same way before parsing.
|
|
113
|
+
def scrub(buffer)
|
|
114
|
+
buffer.encode("UTF-8", invalid: :replace, undef: :replace)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def write_start(event)
|
|
118
|
+
attrs = (event.attrs || {}).map do |key, value|
|
|
119
|
+
%( #{key}="#{escape_attribute(value)}")
|
|
120
|
+
end.join
|
|
121
|
+
"<#{event.name}#{attrs}>"
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def escape_attribute(value)
|
|
125
|
+
value.to_s.gsub("&", "&").gsub("<", "<").gsub('"', """)
|
|
126
|
+
end
|
|
87
127
|
|
|
88
|
-
|
|
89
|
-
|
|
128
|
+
def escape_text(text)
|
|
129
|
+
text.to_s.gsub("&", "&").gsub("<", "<").gsub(">", ">")
|
|
90
130
|
end
|
|
91
131
|
|
|
92
|
-
def read_element(
|
|
93
|
-
element = Nokogiri::XML(node.outer_xml).root
|
|
132
|
+
def read_element(element, data)
|
|
94
133
|
id = attr(element, "idref")
|
|
95
134
|
return unless id
|
|
96
135
|
|
|
@@ -99,8 +138,7 @@ module Ea
|
|
|
99
138
|
data[:proxies][id] = attr(element, "classifier") if type == "uml:ProxyConnector"
|
|
100
139
|
end
|
|
101
140
|
|
|
102
|
-
def read_connector(
|
|
103
|
-
connector = Nokogiri::XML(node.outer_xml).root
|
|
141
|
+
def read_connector(connector, data)
|
|
104
142
|
id = attr(connector, "idref")
|
|
105
143
|
return unless id
|
|
106
144
|
|
|
@@ -114,7 +152,7 @@ module Ea
|
|
|
114
152
|
end
|
|
115
153
|
|
|
116
154
|
def attr(node, name)
|
|
117
|
-
node&.
|
|
155
|
+
node&.attributes&.find { |attribute| attribute.name == name }&.value
|
|
118
156
|
end
|
|
119
157
|
|
|
120
158
|
def guid_key(subject)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "moxml"
|
|
4
|
+
require "leptris"
|
|
4
5
|
|
|
5
6
|
module Ea
|
|
6
7
|
module Sources
|
|
@@ -50,17 +51,68 @@ module Ea
|
|
|
50
51
|
def read_role_stereotypes
|
|
51
52
|
return {} unless @xmi_path
|
|
52
53
|
|
|
53
|
-
File.
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
capture_connectors(File.read(@xmi_path)).each_with_object({}) do |connector, roles|
|
|
55
|
+
read_connector_roles(connector, roles)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Single streaming pass over the XMI: reconstruct each
|
|
60
|
+
# <connector>'s outer XML from the pull stream and parse it as a
|
|
61
|
+
# subtree for the role lookups below.
|
|
62
|
+
def capture_connectors(xml)
|
|
63
|
+
connectors = []
|
|
64
|
+
buffer = nil
|
|
65
|
+
depth = 0
|
|
56
66
|
|
|
57
|
-
|
|
67
|
+
Leptris::XML::Pull.parse(xml).each do |event|
|
|
68
|
+
case event.type
|
|
69
|
+
when :start_element
|
|
70
|
+
if buffer
|
|
71
|
+
buffer << write_start(event)
|
|
72
|
+
depth += 1
|
|
73
|
+
elsif event.name == "connector"
|
|
74
|
+
buffer = +write_start(event)
|
|
75
|
+
depth = 1
|
|
76
|
+
end
|
|
77
|
+
when :end_element
|
|
78
|
+
next unless buffer
|
|
79
|
+
|
|
80
|
+
buffer << "</#{event.name}>"
|
|
81
|
+
depth -= 1
|
|
82
|
+
if depth.zero?
|
|
83
|
+
connectors << Moxml.parse(scrub(buffer)).root
|
|
84
|
+
buffer = nil
|
|
85
|
+
end
|
|
86
|
+
when :text
|
|
87
|
+
buffer << escape_text(event.text) if buffer
|
|
58
88
|
end
|
|
59
89
|
end
|
|
90
|
+
connectors
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# EA XMI files occasionally carry bytes outside the declared
|
|
94
|
+
# encoding; the nokogiri outer-xml path tolerated them, so scrub
|
|
95
|
+
# the reconstructed fragment the same way before parsing.
|
|
96
|
+
def scrub(buffer)
|
|
97
|
+
buffer.encode("UTF-8", invalid: :replace, undef: :replace)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def write_start(event)
|
|
101
|
+
attrs = (event.attrs || {}).map do |key, value|
|
|
102
|
+
%( #{key}="#{escape_attribute(value)}")
|
|
103
|
+
end.join
|
|
104
|
+
"<#{event.name}#{attrs}>"
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def escape_attribute(value)
|
|
108
|
+
value.to_s.gsub("&", "&").gsub("<", "<").gsub('"', """)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def escape_text(text)
|
|
112
|
+
text.to_s.gsub("&", "&").gsub("<", "<").gsub(">", ">")
|
|
60
113
|
end
|
|
61
114
|
|
|
62
|
-
def read_connector_roles(
|
|
63
|
-
connector = Nokogiri::XML(node.outer_xml).root
|
|
115
|
+
def read_connector_roles(connector, roles)
|
|
64
116
|
id = connector.at_xpath("@*[local-name()='idref']")&.value
|
|
65
117
|
return unless id
|
|
66
118
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "moxml"
|
|
4
4
|
|
|
5
5
|
module Ea
|
|
6
6
|
module Sources
|
|
@@ -52,7 +52,7 @@ module Ea
|
|
|
52
52
|
def saved_objects
|
|
53
53
|
return [] unless @xmi_path
|
|
54
54
|
|
|
55
|
-
doc =
|
|
55
|
+
doc = Ea::Xml.parse_file(@xmi_path)
|
|
56
56
|
doc.xpath("//*[local-name()='Extension']/*[local-name()='elements']/*[local-name()='element']")
|
|
57
57
|
end
|
|
58
58
|
end
|
|
@@ -21,8 +21,10 @@ module Ea
|
|
|
21
21
|
@property_roles ||= begin
|
|
22
22
|
document = @doc
|
|
23
23
|
declared = declared_properties(document)
|
|
24
|
-
document.xpath("//*[local-name()=\"Diagram\"]")
|
|
25
|
-
|
|
24
|
+
document.xpath("//*[local-name()=\"Diagram\"]")
|
|
25
|
+
.each_with_object({}) do |diagram, hash|
|
|
26
|
+
hash[diagram["id"] || diagram["xmi:id"]] =
|
|
27
|
+
diagram_property_roles(diagram, declared)
|
|
26
28
|
end
|
|
27
29
|
end
|
|
28
30
|
end
|
|
@@ -34,7 +36,7 @@ module Ea
|
|
|
34
36
|
document.xpath("//*[@association][@xmi:id]", "xmi" => "http://www.omg.org/spec/XMI/20131001")
|
|
35
37
|
.filter_map do |node|
|
|
36
38
|
pair = [node["xmi:id"], node["association"]]
|
|
37
|
-
pair if node.
|
|
39
|
+
pair if node.at_xpath("@*[local-name()='type']")&.value == "uml:Property" && members.include?(pair)
|
|
38
40
|
end.to_set
|
|
39
41
|
end
|
|
40
42
|
|
|
@@ -50,13 +52,13 @@ module Ea
|
|
|
50
52
|
|
|
51
53
|
def unique_edges(diagram)
|
|
52
54
|
diagram.xpath("./ownedElement[@modelElement]")
|
|
53
|
-
.select { |node| node.
|
|
55
|
+
.select { |node| node.at_xpath("@*[local-name()='type']")&.value.to_s.end_with?("UMLEdge") }
|
|
54
56
|
.group_by { |edge| edge["modelElement"] }
|
|
55
57
|
.select { |_, edges| edges.one? }.transform_values(&:first)
|
|
56
58
|
end
|
|
57
59
|
|
|
58
60
|
def role_key(label)
|
|
59
|
-
return unless label.
|
|
61
|
+
return unless label.at_xpath("@*[local-name()='type']")&.value.to_s.end_with?("UMLAssociationEndLabel")
|
|
60
62
|
|
|
61
63
|
case label["xmi:id"] || label["id"]
|
|
62
64
|
when /\AEAID_SEL/ then :source_role
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "moxml"
|
|
4
4
|
|
|
5
5
|
module Ea
|
|
6
6
|
module Sources
|
|
@@ -41,15 +41,20 @@ module Ea
|
|
|
41
41
|
|
|
42
42
|
private
|
|
43
43
|
|
|
44
|
+
# NodeSet#to_h is not Enumerable-backed across XML adapters —
|
|
45
|
+
# build the id-keyed maps with an explicit reduction instead.
|
|
44
46
|
def ends
|
|
45
|
-
@ends ||= doc.xpath("//*[local-name()=\"Diagram\"]")
|
|
46
|
-
|
|
47
|
+
@ends ||= doc.xpath("//*[local-name()=\"Diagram\"]")
|
|
48
|
+
.each_with_object({}) do |diagram, hash|
|
|
49
|
+
hash[diagram["id"] || diagram["xmi:id"]] = diagram_ends(diagram)
|
|
47
50
|
end
|
|
48
51
|
end
|
|
49
52
|
|
|
50
53
|
def label_bounds
|
|
51
|
-
@label_bounds ||= doc.xpath("//*[local-name()=\"Diagram\"]")
|
|
52
|
-
|
|
54
|
+
@label_bounds ||= doc.xpath("//*[local-name()=\"Diagram\"]")
|
|
55
|
+
.each_with_object({}) do |diagram, hash|
|
|
56
|
+
hash[diagram["id"] || diagram["xmi:id"]] =
|
|
57
|
+
diagram_label_bounds(diagram)
|
|
53
58
|
end
|
|
54
59
|
end
|
|
55
60
|
|
|
@@ -77,7 +82,7 @@ module Ea
|
|
|
77
82
|
end
|
|
78
83
|
|
|
79
84
|
def label_key(label)
|
|
80
|
-
type = label.
|
|
85
|
+
type = label.at_xpath("@*[local-name()='type']")&.value.to_s
|
|
81
86
|
role = (label["id"] || label["xmi:id"]).to_s
|
|
82
87
|
end_name = { "EAID_SEL" => "source", "EAID_SML" => "source",
|
|
83
88
|
"EAID_TEL" => "target", "EAID_TML" => "target" }
|
|
@@ -97,15 +102,16 @@ module Ea
|
|
|
97
102
|
# one edge of the diagram, whatever that edge carries.
|
|
98
103
|
def unique_edges(diagram)
|
|
99
104
|
diagram.xpath("./ownedElement[@modelElement]")
|
|
100
|
-
.select { |node| node.
|
|
105
|
+
.select { |node| node.at_xpath("@*[local-name()='type']")&.value.to_s.end_with?("UMLEdge") }
|
|
101
106
|
.group_by { |edge| edge["modelElement"] }
|
|
102
107
|
.select { |_, same| same.one? }
|
|
103
108
|
.transform_values(&:first)
|
|
104
109
|
end
|
|
105
110
|
|
|
106
111
|
def routes
|
|
107
|
-
@routes ||= doc.xpath("//*[local-name()=\"Diagram\"]")
|
|
108
|
-
|
|
112
|
+
@routes ||= doc.xpath("//*[local-name()=\"Diagram\"]")
|
|
113
|
+
.each_with_object({}) do |diagram, hash|
|
|
114
|
+
hash[diagram["id"] || diagram["xmi:id"]] = diagram_routes(diagram)
|
|
109
115
|
end
|
|
110
116
|
end
|
|
111
117
|
|
|
@@ -121,7 +127,7 @@ module Ea
|
|
|
121
127
|
end
|
|
122
128
|
|
|
123
129
|
def doc
|
|
124
|
-
|
|
130
|
+
Ea::Xml.parse_file(@xmi_path)
|
|
125
131
|
end
|
|
126
132
|
end
|
|
127
133
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "moxml"
|
|
4
4
|
|
|
5
5
|
module Ea
|
|
6
6
|
module Sources
|
|
@@ -17,7 +17,7 @@ module Ea
|
|
|
17
17
|
def self.from_path(xmi_path)
|
|
18
18
|
return empty if xmi_path.nil?
|
|
19
19
|
|
|
20
|
-
new(
|
|
20
|
+
new(Ea::Xml.parse_file(xmi_path))
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def self.empty
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "moxml"
|
|
4
4
|
|
|
5
5
|
module Ea
|
|
6
6
|
module Sources
|
|
@@ -88,9 +88,11 @@ module Ea
|
|
|
88
88
|
def extension_runstates
|
|
89
89
|
return {} if xmi_path.nil?
|
|
90
90
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
Ea::Xml.parse_file(xmi_path)
|
|
92
|
+
.xpath(RUNSTATE_XPATH)
|
|
93
|
+
.each_with_object({}) do |node, acc|
|
|
94
|
+
acc[node.parent["xmi:idref"]] = node["runstate"]
|
|
95
|
+
end
|
|
94
96
|
end
|
|
95
97
|
end
|
|
96
98
|
end
|