xmi 0.5.2 → 0.5.4
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/.github/workflows/rake.yml +5 -1
- data/.rubocop_todo.yml +52 -9
- data/lib/xmi/extension.rb +4 -12
- data/lib/xmi/parser_pipeline.rb +70 -0
- data/lib/xmi/root.rb +3 -12
- data/lib/xmi/sparx/connector/appearance.rb +27 -0
- data/lib/xmi/sparx/connector/connector.rb +52 -0
- data/lib/xmi/sparx/connector/end_base.rb +56 -0
- data/lib/xmi/sparx/connector/end_constraint.rb +33 -0
- data/lib/xmi/sparx/connector/end_modifiers.rb +19 -0
- data/lib/xmi/sparx/connector/end_role.rb +21 -0
- data/lib/xmi/sparx/connector/end_style.rb +17 -0
- data/lib/xmi/sparx/connector/end_type.rb +21 -0
- data/lib/xmi/sparx/connector/labels.rb +27 -0
- data/lib/xmi/sparx/connector/model.rb +19 -0
- data/lib/xmi/sparx/connector/properties.rb +19 -0
- data/lib/xmi/sparx/connector.rb +15 -233
- data/lib/xmi/sparx/element/association.rb +58 -0
- data/lib/xmi/sparx/element/attribute.rb +58 -0
- data/lib/xmi/sparx/element/bounds.rb +19 -0
- data/lib/xmi/sparx/element/code.rb +19 -0
- data/lib/xmi/sparx/element/containment.rb +19 -0
- data/lib/xmi/sparx/element/coords.rb +19 -0
- data/lib/xmi/sparx/element/documentation.rb +17 -0
- data/lib/xmi/sparx/element/element.rb +62 -0
- data/lib/xmi/sparx/element/extended_properties.rb +21 -0
- data/lib/xmi/sparx/element/flags.rb +29 -0
- data/lib/xmi/sparx/element/links.rb +22 -0
- data/lib/xmi/sparx/element/model.rb +26 -0
- data/lib/xmi/sparx/element/package_properties.rb +21 -0
- data/lib/xmi/sparx/element/paths.rb +17 -0
- data/lib/xmi/sparx/element/project.rb +29 -0
- data/lib/xmi/sparx/element/properties.rb +41 -0
- data/lib/xmi/sparx/element/stereotype.rb +17 -0
- data/lib/xmi/sparx/element/style.rb +17 -0
- data/lib/xmi/sparx/element/styleex.rb +17 -0
- data/lib/xmi/sparx/element/tag.rb +32 -0
- data/lib/xmi/sparx/element/times.rb +23 -0
- data/lib/xmi/sparx/element/xrefs.rb +17 -0
- data/lib/xmi/sparx/element.rb +28 -445
- data/lib/xmi/sparx/extension.rb +4 -12
- data/lib/xmi/sparx/gml/application_schema.rb +26 -0
- data/lib/xmi/sparx/gml/code_list.rb +23 -0
- data/lib/xmi/sparx/gml/data_type.rb +18 -0
- data/lib/xmi/sparx/gml/enumeration.rb +18 -0
- data/lib/xmi/sparx/gml/feature_type.rb +21 -0
- data/lib/xmi/sparx/gml/property.rb +24 -0
- data/lib/xmi/sparx/gml/shared_attributes.rb +39 -0
- data/lib/xmi/sparx/gml/type.rb +18 -0
- data/lib/xmi/sparx/gml/union.rb +18 -0
- data/lib/xmi/sparx/gml.rb +10 -125
- data/lib/xmi/sparx/index.rb +248 -0
- data/lib/xmi/sparx/mappings/base_mapping.rb +13 -137
- data/lib/xmi/sparx/root.rb +20 -7
- data/lib/xmi/sparx.rb +1 -0
- data/lib/xmi/uml/annotated_element.rb +16 -0
- data/lib/xmi/uml/association_generalization.rb +20 -0
- data/lib/xmi/uml/bounds.rb +43 -0
- data/lib/xmi/uml/default_value.rb +42 -0
- data/lib/xmi/uml/diagram.rb +25 -0
- data/lib/xmi/uml/member_end.rb +16 -0
- data/lib/xmi/uml/owned_attribute.rb +31 -0
- data/lib/xmi/uml/owned_comment.rb +29 -0
- data/lib/xmi/uml/owned_element.rb +33 -0
- data/lib/xmi/uml/owned_end.rb +34 -0
- data/lib/xmi/uml/owned_literal.rb +23 -0
- data/lib/xmi/uml/owned_operation.rb +22 -0
- data/lib/xmi/uml/owned_parameter.rb +29 -0
- data/lib/xmi/uml/package_import.rb +30 -0
- data/lib/xmi/uml/packaged_element.rb +49 -0
- data/lib/xmi/uml/precondition.rb +22 -0
- data/lib/xmi/uml/profile.rb +43 -0
- data/lib/xmi/uml/profile_application.rb +34 -0
- data/lib/xmi/uml/specification.rb +20 -0
- data/lib/xmi/uml/type.rb +18 -0
- data/lib/xmi/uml/uml_model.rb +29 -0
- data/lib/xmi/uml.rb +27 -502
- data/lib/xmi/version.rb +1 -1
- data/lib/xmi/version_registry.rb +2 -1
- data/lib/xmi/xmi_identity.rb +46 -0
- data/lib/xmi.rb +11 -6
- metadata +68 -2
data/lib/xmi/sparx/extension.rb
CHANGED
|
@@ -3,12 +3,8 @@
|
|
|
3
3
|
module Xmi
|
|
4
4
|
module Sparx
|
|
5
5
|
class Extension < Lutaml::Model::Serializable
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
attribute :uuid, ::Xmi::Type::XmiUuid
|
|
9
|
-
attribute :href, :string
|
|
10
|
-
attribute :idref, ::Xmi::Type::XmiIdRef
|
|
11
|
-
attribute :type, ::Xmi::Type::XmiType
|
|
6
|
+
include XmiIdentity::Attributes
|
|
7
|
+
|
|
12
8
|
attribute :extender, :string
|
|
13
9
|
attribute :extender_id, :string
|
|
14
10
|
attribute :elements, Element::Elements
|
|
@@ -22,12 +18,8 @@ module Xmi
|
|
|
22
18
|
root "Extension"
|
|
23
19
|
namespace ::Xmi::Namespace::Omg::Xmi
|
|
24
20
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
map_attribute "uuid", to: :uuid
|
|
28
|
-
map_attribute "href", to: :href
|
|
29
|
-
map_attribute "idref", to: :idref
|
|
30
|
-
map_attribute "type", to: :type
|
|
21
|
+
XmiIdentity.apply_xml_mappings(self)
|
|
22
|
+
|
|
31
23
|
map_attribute "extender", to: :extender
|
|
32
24
|
map_attribute "extenderID", to: :extender_id
|
|
33
25
|
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Xmi
|
|
4
|
+
module Sparx
|
|
5
|
+
module Gml
|
|
6
|
+
class ApplicationSchema < Lutaml::Model::Serializable
|
|
7
|
+
attribute :version, :string
|
|
8
|
+
attribute :xsd_document, :string
|
|
9
|
+
attribute :altered_xmlns, :string
|
|
10
|
+
attribute :target_namespace, :string
|
|
11
|
+
attribute :base_package, :string
|
|
12
|
+
|
|
13
|
+
xml do
|
|
14
|
+
root "ApplicationSchema"
|
|
15
|
+
namespace ::Xmi::Namespace::Sparx::Gml
|
|
16
|
+
|
|
17
|
+
map_attribute "version", to: :version
|
|
18
|
+
map_attribute "xsdDocument", to: :xsd_document
|
|
19
|
+
map_attribute "altered_xmlns", to: :altered_xmlns
|
|
20
|
+
map_attribute "targetNamespace", to: :target_namespace
|
|
21
|
+
map_attribute "base_Package", to: :base_package
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Xmi
|
|
4
|
+
module Sparx
|
|
5
|
+
module Gml
|
|
6
|
+
class CodeList < Lutaml::Model::Serializable
|
|
7
|
+
include HasBaseClass
|
|
8
|
+
|
|
9
|
+
attribute :as_dictionary, :string
|
|
10
|
+
attribute :default_code_space, :string
|
|
11
|
+
|
|
12
|
+
xml do
|
|
13
|
+
root "CodeList"
|
|
14
|
+
namespace ::Xmi::Namespace::Sparx::Gml
|
|
15
|
+
|
|
16
|
+
HasBaseClass.apply_xml_mappings(self)
|
|
17
|
+
map_attribute "asDictionary", to: :as_dictionary
|
|
18
|
+
map_attribute "defaultCodeSpace", to: :default_code_space
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Xmi
|
|
4
|
+
module Sparx
|
|
5
|
+
module Gml
|
|
6
|
+
class DataType < Lutaml::Model::Serializable
|
|
7
|
+
include HasCollectionProperties
|
|
8
|
+
|
|
9
|
+
xml do
|
|
10
|
+
root "DataType"
|
|
11
|
+
namespace ::Xmi::Namespace::Sparx::Gml
|
|
12
|
+
|
|
13
|
+
HasCollectionProperties.apply_xml_mappings(self)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Xmi
|
|
4
|
+
module Sparx
|
|
5
|
+
module Gml
|
|
6
|
+
class Enumeration < Lutaml::Model::Serializable
|
|
7
|
+
attribute :base_enumeration, :string
|
|
8
|
+
|
|
9
|
+
xml do
|
|
10
|
+
root "Enumeration"
|
|
11
|
+
namespace ::Xmi::Namespace::Sparx::Gml
|
|
12
|
+
|
|
13
|
+
map_attribute "base_Enumeration", to: :base_enumeration
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Xmi
|
|
4
|
+
module Sparx
|
|
5
|
+
module Gml
|
|
6
|
+
class FeatureType < Lutaml::Model::Serializable
|
|
7
|
+
include HasCollectionProperties
|
|
8
|
+
|
|
9
|
+
attribute :by_value_property_type, :string
|
|
10
|
+
|
|
11
|
+
xml do
|
|
12
|
+
root "FeatureType"
|
|
13
|
+
namespace ::Xmi::Namespace::Sparx::Gml
|
|
14
|
+
|
|
15
|
+
HasCollectionProperties.apply_xml_mappings(self)
|
|
16
|
+
map_attribute "byValuePropertyType", to: :by_value_property_type
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Xmi
|
|
4
|
+
module Sparx
|
|
5
|
+
module Gml
|
|
6
|
+
class Property < Lutaml::Model::Serializable
|
|
7
|
+
attribute :sequence_number, :string
|
|
8
|
+
attribute :base_property, :string
|
|
9
|
+
attribute :is_metadata, :string
|
|
10
|
+
attribute :inline_or_by_reference, :string
|
|
11
|
+
|
|
12
|
+
xml do
|
|
13
|
+
root "property"
|
|
14
|
+
namespace ::Xmi::Namespace::Sparx::Gml
|
|
15
|
+
|
|
16
|
+
map_attribute "sequenceNumber", to: :sequence_number
|
|
17
|
+
map_attribute "base_Property", to: :base_property
|
|
18
|
+
map_attribute "isMetadata", to: :is_metadata
|
|
19
|
+
map_attribute "inlineOrByReference", to: :inline_or_by_reference
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Xmi
|
|
4
|
+
module Sparx
|
|
5
|
+
module Gml
|
|
6
|
+
# Shared attribute modules for GML stereotype classes.
|
|
7
|
+
# Reduces duplication across DataType, Type, FeatureType, etc.
|
|
8
|
+
|
|
9
|
+
module HasBaseClass
|
|
10
|
+
def self.included(klass)
|
|
11
|
+
klass.class_eval do
|
|
12
|
+
attribute :base_class, :string
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.apply_xml_mappings(mapping)
|
|
17
|
+
mapping.map_attribute "base_Class", to: :base_class
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
module HasCollectionProperties
|
|
22
|
+
def self.included(klass)
|
|
23
|
+
klass.class_eval do
|
|
24
|
+
include HasBaseClass
|
|
25
|
+
|
|
26
|
+
attribute :is_collection, :string
|
|
27
|
+
attribute :no_property_type, :string
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def self.apply_xml_mappings(mapping)
|
|
32
|
+
HasBaseClass.apply_xml_mappings(mapping)
|
|
33
|
+
mapping.map_attribute "isCollection", to: :is_collection
|
|
34
|
+
mapping.map_attribute "noPropertyType", to: :no_property_type
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Xmi
|
|
4
|
+
module Sparx
|
|
5
|
+
module Gml
|
|
6
|
+
class Type < Lutaml::Model::Serializable
|
|
7
|
+
include HasCollectionProperties
|
|
8
|
+
|
|
9
|
+
xml do
|
|
10
|
+
root "Type"
|
|
11
|
+
namespace ::Xmi::Namespace::Sparx::Gml
|
|
12
|
+
|
|
13
|
+
HasCollectionProperties.apply_xml_mappings(self)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Xmi
|
|
4
|
+
module Sparx
|
|
5
|
+
module Gml
|
|
6
|
+
class Union < Lutaml::Model::Serializable
|
|
7
|
+
include HasCollectionProperties
|
|
8
|
+
|
|
9
|
+
xml do
|
|
10
|
+
root "Union"
|
|
11
|
+
namespace ::Xmi::Namespace::Sparx::Gml
|
|
12
|
+
|
|
13
|
+
HasCollectionProperties.apply_xml_mappings(self)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
data/lib/xmi/sparx/gml.rb
CHANGED
|
@@ -3,131 +3,16 @@
|
|
|
3
3
|
module Xmi
|
|
4
4
|
module Sparx
|
|
5
5
|
module Gml
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
root "ApplicationSchema"
|
|
17
|
-
namespace ::Xmi::Namespace::Sparx::Gml
|
|
18
|
-
|
|
19
|
-
map_attribute "version", to: :version
|
|
20
|
-
map_attribute "xsdDocument", to: :xsd_document
|
|
21
|
-
map_attribute "altered_xmlns", to: :altered_xmlns
|
|
22
|
-
map_attribute "targetNamespace", to: :target_namespace
|
|
23
|
-
map_attribute "base_Package", to: :base_package
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
class CodeList < Lutaml::Model::Serializable
|
|
28
|
-
attribute :as_dictionary, :string
|
|
29
|
-
attribute :default_code_space, :string
|
|
30
|
-
attribute :base_class, :string
|
|
31
|
-
|
|
32
|
-
xml do
|
|
33
|
-
root "CodeList"
|
|
34
|
-
namespace ::Xmi::Namespace::Sparx::Gml
|
|
35
|
-
|
|
36
|
-
map_attribute "asDictionary", to: :as_dictionary
|
|
37
|
-
map_attribute "defaultCodeSpace", to: :default_code_space
|
|
38
|
-
map_attribute "base_Class", to: :base_class
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
class DataType < Lutaml::Model::Serializable
|
|
43
|
-
attribute :is_collection, :string
|
|
44
|
-
attribute :no_property_type, :string
|
|
45
|
-
attribute :base_class, :string
|
|
46
|
-
|
|
47
|
-
xml do
|
|
48
|
-
root "DataType"
|
|
49
|
-
namespace ::Xmi::Namespace::Sparx::Gml
|
|
50
|
-
|
|
51
|
-
map_attribute "isCollection", to: :is_collection
|
|
52
|
-
map_attribute "noPropertyType", to: :no_property_type
|
|
53
|
-
map_attribute "base_Class", to: :base_class
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
class Union < Lutaml::Model::Serializable
|
|
58
|
-
attribute :is_collection, :string
|
|
59
|
-
attribute :no_property_type, :string
|
|
60
|
-
attribute :base_class, :string
|
|
61
|
-
|
|
62
|
-
xml do
|
|
63
|
-
root "Union"
|
|
64
|
-
namespace ::Xmi::Namespace::Sparx::Gml
|
|
65
|
-
|
|
66
|
-
map_attribute "isCollection", to: :is_collection
|
|
67
|
-
map_attribute "noPropertyType", to: :no_property_type
|
|
68
|
-
map_attribute "base_Class", to: :base_class
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
class Enumeration < Lutaml::Model::Serializable
|
|
73
|
-
attribute :base_enumeration, :string
|
|
74
|
-
|
|
75
|
-
xml do
|
|
76
|
-
root "Enumeration"
|
|
77
|
-
namespace ::Xmi::Namespace::Sparx::Gml
|
|
78
|
-
|
|
79
|
-
map_attribute "base_Enumeration", to: :base_enumeration
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
class Type < Lutaml::Model::Serializable
|
|
84
|
-
attribute :is_collection, :string
|
|
85
|
-
attribute :no_property_type, :string
|
|
86
|
-
attribute :base_class, :string
|
|
87
|
-
|
|
88
|
-
xml do
|
|
89
|
-
root "Type"
|
|
90
|
-
namespace ::Xmi::Namespace::Sparx::Gml
|
|
91
|
-
|
|
92
|
-
map_attribute "isCollection", to: :is_collection
|
|
93
|
-
map_attribute "noPropertyType", to: :no_property_type
|
|
94
|
-
map_attribute "base_Class", to: :base_class
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
class FeatureType < Lutaml::Model::Serializable
|
|
99
|
-
attribute :is_collection, :string
|
|
100
|
-
attribute :no_property_type, :string
|
|
101
|
-
attribute :base_class, :string
|
|
102
|
-
attribute :by_value_property_type, :string
|
|
103
|
-
|
|
104
|
-
xml do
|
|
105
|
-
root "FeatureType"
|
|
106
|
-
namespace ::Xmi::Namespace::Sparx::Gml
|
|
107
|
-
|
|
108
|
-
map_attribute "isCollection", to: :is_collection
|
|
109
|
-
map_attribute "noPropertyType", to: :no_property_type
|
|
110
|
-
map_attribute "base_Class", to: :base_class
|
|
111
|
-
map_attribute "byValuePropertyType", to: :by_value_property_type
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
class Property < Lutaml::Model::Serializable
|
|
116
|
-
attribute :sequence_number, :string
|
|
117
|
-
attribute :base_property, :string
|
|
118
|
-
attribute :is_metadata, :string
|
|
119
|
-
attribute :inline_or_by_reference, :string
|
|
120
|
-
|
|
121
|
-
xml do
|
|
122
|
-
root "property"
|
|
123
|
-
namespace ::Xmi::Namespace::Sparx::Gml
|
|
124
|
-
|
|
125
|
-
map_attribute "sequenceNumber", to: :sequence_number
|
|
126
|
-
map_attribute "base_Property", to: :base_property
|
|
127
|
-
map_attribute "isMetadata", to: :is_metadata
|
|
128
|
-
map_attribute "inlineOrByReference", to: :inline_or_by_reference
|
|
129
|
-
end
|
|
130
|
-
end
|
|
6
|
+
autoload :HasBaseClass, "xmi/sparx/gml/shared_attributes"
|
|
7
|
+
autoload :HasCollectionProperties, "xmi/sparx/gml/shared_attributes"
|
|
8
|
+
autoload :ApplicationSchema, "xmi/sparx/gml/application_schema"
|
|
9
|
+
autoload :CodeList, "xmi/sparx/gml/code_list"
|
|
10
|
+
autoload :DataType, "xmi/sparx/gml/data_type"
|
|
11
|
+
autoload :Union, "xmi/sparx/gml/union"
|
|
12
|
+
autoload :Enumeration, "xmi/sparx/gml/enumeration"
|
|
13
|
+
autoload :Type, "xmi/sparx/gml/type"
|
|
14
|
+
autoload :FeatureType, "xmi/sparx/gml/feature_type"
|
|
15
|
+
autoload :Property, "xmi/sparx/gml/property"
|
|
131
16
|
end
|
|
132
17
|
end
|
|
133
18
|
end
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Xmi
|
|
4
|
+
module Sparx
|
|
5
|
+
# Builds all commonly needed indexes from a parsed SparxRoot in a single
|
|
6
|
+
# targeted walk, avoiding the generic map_id_name approach that visits every
|
|
7
|
+
# attribute of every node.
|
|
8
|
+
#
|
|
9
|
+
# Indexes built:
|
|
10
|
+
# - id_name_map: { xmi_id => name } for all nodes with both id and name
|
|
11
|
+
# - packaged_elements: flat array of all PackagedElement instances
|
|
12
|
+
# - packaged_by_id: { xmi_id => PackagedElement }
|
|
13
|
+
# - packaged_by_type: { "uml:Class" => [...], "uml:Package" => [...], ... }
|
|
14
|
+
# - upper_level_map: { xmi_id => parent PackagedElement }
|
|
15
|
+
# - elements_by_idref: { idref => Extension::Element::Element }
|
|
16
|
+
# - connectors_by_idref: { idref => Connector::Connector }
|
|
17
|
+
# - attributes_by_idref: { idref => Extension::Element::Attribute }
|
|
18
|
+
# - owned_attrs_by_type_idref: { type_idref => [OwnedAttribute, ...] }
|
|
19
|
+
class Index
|
|
20
|
+
attr_reader :id_name_map, :packaged_elements, :packaged_by_id,
|
|
21
|
+
:packaged_by_type, :upper_level_map, :elements_by_idref,
|
|
22
|
+
:connectors_by_idref, :attributes_by_idref,
|
|
23
|
+
:owned_attrs_by_type_idref
|
|
24
|
+
|
|
25
|
+
PackagedElement = ::Xmi::Uml::PackagedElement
|
|
26
|
+
|
|
27
|
+
# @param root [Xmi::Sparx::SparxRoot] parsed XMI model
|
|
28
|
+
def initialize(root)
|
|
29
|
+
@id_name_map = {}
|
|
30
|
+
@packaged_elements = []
|
|
31
|
+
@packaged_by_id = {}
|
|
32
|
+
@packaged_by_type = {}
|
|
33
|
+
@upper_level_map = {}
|
|
34
|
+
@elements_by_idref = {}
|
|
35
|
+
@connectors_by_idref = {}
|
|
36
|
+
@attributes_by_idref = {}
|
|
37
|
+
@owned_attrs_by_type_idref = {}
|
|
38
|
+
|
|
39
|
+
build(root)
|
|
40
|
+
freeze
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Lookup name by XMI ID
|
|
44
|
+
# @param xmi_id [String] XMI identifier
|
|
45
|
+
# @return [String, nil]
|
|
46
|
+
def lookup_name(xmi_id)
|
|
47
|
+
@id_name_map[xmi_id]
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Find packaged element by XMI ID
|
|
51
|
+
# @param id [String]
|
|
52
|
+
# @return [Xmi::Uml::PackagedElement, nil]
|
|
53
|
+
def find_packaged_element(id)
|
|
54
|
+
@packaged_by_id[id]
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Find parent of a packaged element
|
|
58
|
+
# @param id [String] child XMI ID
|
|
59
|
+
# @return [Xmi::Uml::PackagedElement, nil]
|
|
60
|
+
def find_parent(id)
|
|
61
|
+
@upper_level_map[id]
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Find extension element by idref
|
|
65
|
+
# @param idref [String]
|
|
66
|
+
# @return [Xmi::Sparx::Element::Element, nil]
|
|
67
|
+
def find_element(idref)
|
|
68
|
+
@elements_by_idref[idref]
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Find connector by idref
|
|
72
|
+
# @param idref [String]
|
|
73
|
+
# @return [Xmi::Sparx::Connector::Connector, nil]
|
|
74
|
+
def find_connector(idref)
|
|
75
|
+
@connectors_by_idref[idref]
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# Find extension attribute by idref
|
|
79
|
+
# @param idref [String]
|
|
80
|
+
# @return [Xmi::Sparx::Element::Attribute, nil]
|
|
81
|
+
def find_attribute(idref)
|
|
82
|
+
@attributes_by_idref[idref]
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Find owned attributes whose uml_type.idref matches
|
|
86
|
+
# @param type_idref [String]
|
|
87
|
+
# @return [Array<Xmi::Uml::OwnedAttribute>]
|
|
88
|
+
def find_owned_attrs_by_type(type_idref)
|
|
89
|
+
@owned_attrs_by_type_idref[type_idref] || []
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# Find packaged elements by UML type
|
|
93
|
+
# @param type [String] e.g. "uml:Class", "uml:Package"
|
|
94
|
+
# @return [Array<Xmi::Uml::PackagedElement>]
|
|
95
|
+
def packaged_elements_of_type(type)
|
|
96
|
+
@packaged_by_type[type] || []
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Find first packaged element by name and allowed types
|
|
100
|
+
# @param name [String]
|
|
101
|
+
# @param types [Array<String>] e.g. ["uml:Class", "uml:AssociationClass"]
|
|
102
|
+
# @return [Xmi::Uml::PackagedElement, nil]
|
|
103
|
+
def find_packaged_by_name_and_types(name, types)
|
|
104
|
+
types.each do |type|
|
|
105
|
+
elements = @packaged_by_type[type]
|
|
106
|
+
next unless elements
|
|
107
|
+
|
|
108
|
+
found = elements.find { |e| e.name == name }
|
|
109
|
+
return found if found
|
|
110
|
+
end
|
|
111
|
+
nil
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
private
|
|
115
|
+
|
|
116
|
+
def build(root)
|
|
117
|
+
model = root.model
|
|
118
|
+
if model
|
|
119
|
+
id = model.id if model.respond_to?(:id)
|
|
120
|
+
@id_name_map[id] = model.name if id && model.name
|
|
121
|
+
walk_packaged_elements(model.packaged_element, nil)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
ext = root.extension
|
|
125
|
+
return unless ext
|
|
126
|
+
|
|
127
|
+
index_extension_elements(ext.elements)
|
|
128
|
+
index_extension_connectors(ext.connectors)
|
|
129
|
+
|
|
130
|
+
primitives = ext.primitive_types
|
|
131
|
+
walk_packaged_elements(primitives.packaged_element, nil) if primitives
|
|
132
|
+
|
|
133
|
+
index_extension_profiles(ext.profiles)
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def walk_packaged_elements(elements, parent) # rubocop:disable Metrics/MethodLength
|
|
137
|
+
return unless elements
|
|
138
|
+
|
|
139
|
+
id_name_map = @id_name_map
|
|
140
|
+
packaged_by_id = @packaged_by_id
|
|
141
|
+
packaged_by_type = @packaged_by_type
|
|
142
|
+
upper_level_map = @upper_level_map
|
|
143
|
+
packaged_elements = @packaged_elements
|
|
144
|
+
owned_attrs_by_type = @owned_attrs_by_type_idref
|
|
145
|
+
|
|
146
|
+
elements.each do |pe|
|
|
147
|
+
next unless pe.is_a?(PackagedElement)
|
|
148
|
+
|
|
149
|
+
pe_id = pe.id
|
|
150
|
+
pe_type = pe.type
|
|
151
|
+
pe_name = pe.name
|
|
152
|
+
|
|
153
|
+
packaged_elements << pe
|
|
154
|
+
packaged_by_id[pe_id] = pe if pe_id
|
|
155
|
+
(packaged_by_type[pe_type] ||= []) << pe if pe_type
|
|
156
|
+
upper_level_map[pe_id] = parent if parent && pe_id
|
|
157
|
+
id_name_map[pe_id] = pe_name if pe_id && pe_name
|
|
158
|
+
|
|
159
|
+
# Inline owned attribute indexing
|
|
160
|
+
attrs = pe.owned_attribute
|
|
161
|
+
if attrs && !attrs.empty?
|
|
162
|
+
attrs.each do |oa|
|
|
163
|
+
oa_id = oa.id
|
|
164
|
+
id_name_map[oa_id] = oa.name if oa_id && oa.name
|
|
165
|
+
oa_type = oa.uml_type
|
|
166
|
+
if oa.association && oa_type && oa_type.idref
|
|
167
|
+
(owned_attrs_by_type[oa_type.idref] ||= []) << oa
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
# Inline owned operation indexing
|
|
173
|
+
ops = pe.owned_operation
|
|
174
|
+
if ops && !ops.empty?
|
|
175
|
+
ops.each do |oo|
|
|
176
|
+
oo_id = oo.id
|
|
177
|
+
id_name_map[oo_id] = oo.name if oo_id && oo.name
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
# Inline owned literal indexing
|
|
182
|
+
lits = pe.owned_literal
|
|
183
|
+
if lits && !lits.empty?
|
|
184
|
+
lits.each do |ol|
|
|
185
|
+
ol_id = ol.id
|
|
186
|
+
id_name_map[ol_id] = ol.name if ol_id && ol.name
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
# Recurse into children
|
|
191
|
+
walk_packaged_elements(pe.packaged_element, pe)
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
def index_extension_elements(elements)
|
|
196
|
+
return unless elements
|
|
197
|
+
|
|
198
|
+
element_list = elements.element
|
|
199
|
+
return unless element_list
|
|
200
|
+
|
|
201
|
+
element_list.each do |e|
|
|
202
|
+
idref = e.idref
|
|
203
|
+
next unless idref
|
|
204
|
+
|
|
205
|
+
@elements_by_idref[idref] = e
|
|
206
|
+
|
|
207
|
+
props = e.properties
|
|
208
|
+
@id_name_map[idref] = props.name if props&.name
|
|
209
|
+
|
|
210
|
+
attrs_obj = e.attributes
|
|
211
|
+
next unless attrs_obj
|
|
212
|
+
|
|
213
|
+
attr_list = attrs_obj.attribute
|
|
214
|
+
next unless attr_list
|
|
215
|
+
|
|
216
|
+
attr_list.each do |a|
|
|
217
|
+
@attributes_by_idref[a.idref] = a if a.idref
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
def index_extension_connectors(connectors)
|
|
223
|
+
return unless connectors
|
|
224
|
+
|
|
225
|
+
conn_list = connectors.connector
|
|
226
|
+
return unless conn_list
|
|
227
|
+
|
|
228
|
+
conn_list.each do |c|
|
|
229
|
+
@connectors_by_idref[c.idref] = c if c.idref
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
def index_extension_profiles(profiles)
|
|
234
|
+
return unless profiles
|
|
235
|
+
|
|
236
|
+
profile_list = profiles.profile
|
|
237
|
+
return unless profile_list
|
|
238
|
+
|
|
239
|
+
profile_list.each do |profile|
|
|
240
|
+
if profile.respond_to?(:packaged_element)
|
|
241
|
+
walk_packaged_elements(profile.packaged_element,
|
|
242
|
+
nil)
|
|
243
|
+
end
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
end
|
|
248
|
+
end
|