xmi 0.5.3 → 0.5.5
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 +31 -45
- data/README.adoc +0 -15
- data/lib/xmi/custom_profile/abstract.rb +16 -0
- data/lib/xmi/custom_profile/basic_doc.rb +16 -0
- data/lib/xmi/custom_profile/bibliography.rb +16 -0
- data/lib/xmi/custom_profile/edition.rb +18 -0
- data/lib/xmi/custom_profile/enumeration.rb +16 -0
- data/lib/xmi/custom_profile/informative.rb +16 -0
- data/lib/xmi/custom_profile/invariant.rb +16 -0
- data/lib/xmi/custom_profile/number.rb +18 -0
- data/lib/xmi/custom_profile/ocl.rb +16 -0
- data/lib/xmi/custom_profile/persistence.rb +20 -0
- data/lib/xmi/custom_profile/publication_date.rb +18 -0
- data/lib/xmi/custom_profile/year_version.rb +18 -0
- data/lib/xmi/custom_profile.rb +12 -143
- data/lib/xmi/ea_root/code_generation.rb +141 -0
- data/lib/xmi/ea_root/extension_lifecycle.rb +52 -0
- data/lib/xmi/ea_root/namespace_handling.rb +39 -0
- data/lib/xmi/ea_root/xml_parsing.rb +51 -0
- data/lib/xmi/ea_root.rb +16 -403
- 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 +10 -11
- 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/xmi_identity.rb +46 -0
- data/lib/xmi.rb +11 -7
- metadata +84 -3
- data/lib/xmi/index.rb +0 -243
|
@@ -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
|
|
@@ -6,17 +6,12 @@ module Xmi
|
|
|
6
6
|
# Base XML mapping class for Sparx EA XMI documents.
|
|
7
7
|
#
|
|
8
8
|
# This reusable mapping class encapsulates all the XML element → attribute
|
|
9
|
-
# mappings for SparxRoot
|
|
9
|
+
# mappings for SparxRoot.
|
|
10
10
|
#
|
|
11
11
|
# @example Use in a model class
|
|
12
12
|
# class SparxRoot < Root
|
|
13
13
|
# xml SparxMappings::BaseMapping
|
|
14
14
|
# end
|
|
15
|
-
#
|
|
16
|
-
# @example Extend with additional mappings
|
|
17
|
-
# class ExtendedRoot < Root
|
|
18
|
-
# xml SparxMappings::GmlMapping
|
|
19
|
-
# end
|
|
20
15
|
class BaseMapping < Lutaml::Xml::Mapping
|
|
21
16
|
xml do
|
|
22
17
|
# Set the default namespace for element name resolution
|
|
@@ -35,6 +30,8 @@ module Xmi
|
|
|
35
30
|
::Xmi::Namespace::Sparx::CityGml,
|
|
36
31
|
]
|
|
37
32
|
|
|
33
|
+
VM = ::Xmi::VALUE_MAP
|
|
34
|
+
|
|
38
35
|
# Extension element containing Sparx EA-specific metadata
|
|
39
36
|
map_element "Extension", to: :extension
|
|
40
37
|
|
|
@@ -42,139 +39,18 @@ module Xmi
|
|
|
42
39
|
map_element "ModelicaParameter", to: :modelica_parameter
|
|
43
40
|
|
|
44
41
|
# UML import elements (EAUML profile)
|
|
45
|
-
map_element "import", to: :eauml_import,
|
|
46
|
-
value_map: {
|
|
47
|
-
from: {
|
|
48
|
-
nil: :empty,
|
|
49
|
-
empty: :empty,
|
|
50
|
-
omitted: :empty,
|
|
51
|
-
},
|
|
52
|
-
to: {
|
|
53
|
-
nil: :empty,
|
|
54
|
-
empty: :empty,
|
|
55
|
-
omitted: :empty,
|
|
56
|
-
},
|
|
57
|
-
}
|
|
42
|
+
map_element "import", to: :eauml_import, value_map: VM
|
|
58
43
|
|
|
59
|
-
# GML
|
|
44
|
+
# GML elements
|
|
60
45
|
map_element "ApplicationSchema", to: :gml_application_schema,
|
|
61
|
-
value_map:
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
empty: :empty,
|
|
70
|
-
omitted: :empty,
|
|
71
|
-
},
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
# GML CodeList elements
|
|
75
|
-
map_element "CodeList", to: :gml_code_list,
|
|
76
|
-
value_map: {
|
|
77
|
-
from: {
|
|
78
|
-
nil: :empty,
|
|
79
|
-
empty: :empty,
|
|
80
|
-
omitted: :empty,
|
|
81
|
-
},
|
|
82
|
-
to: {
|
|
83
|
-
nil: :empty,
|
|
84
|
-
empty: :empty,
|
|
85
|
-
omitted: :empty,
|
|
86
|
-
},
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
# GML DataType elements
|
|
90
|
-
map_element "DataType", to: :gml_data_type,
|
|
91
|
-
value_map: {
|
|
92
|
-
from: {
|
|
93
|
-
nil: :empty,
|
|
94
|
-
empty: :empty,
|
|
95
|
-
omitted: :empty,
|
|
96
|
-
},
|
|
97
|
-
to: {
|
|
98
|
-
nil: :empty,
|
|
99
|
-
empty: :empty,
|
|
100
|
-
omitted: :empty,
|
|
101
|
-
},
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
# GML Union elements
|
|
105
|
-
map_element "Union", to: :gml_union,
|
|
106
|
-
value_map: {
|
|
107
|
-
from: {
|
|
108
|
-
nil: :empty,
|
|
109
|
-
empty: :empty,
|
|
110
|
-
omitted: :empty,
|
|
111
|
-
},
|
|
112
|
-
to: {
|
|
113
|
-
nil: :empty,
|
|
114
|
-
empty: :empty,
|
|
115
|
-
omitted: :empty,
|
|
116
|
-
},
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
# GML Enumeration elements
|
|
120
|
-
map_element "Enumeration", to: :gml_enumeration,
|
|
121
|
-
value_map: {
|
|
122
|
-
from: {
|
|
123
|
-
nil: :empty,
|
|
124
|
-
empty: :empty,
|
|
125
|
-
omitted: :empty,
|
|
126
|
-
},
|
|
127
|
-
to: {
|
|
128
|
-
nil: :empty,
|
|
129
|
-
empty: :empty,
|
|
130
|
-
omitted: :empty,
|
|
131
|
-
},
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
# GML Type elements
|
|
135
|
-
map_element "Type", to: :gml_type,
|
|
136
|
-
value_map: {
|
|
137
|
-
from: {
|
|
138
|
-
nil: :empty,
|
|
139
|
-
empty: :empty,
|
|
140
|
-
omitted: :empty,
|
|
141
|
-
},
|
|
142
|
-
to: {
|
|
143
|
-
nil: :empty,
|
|
144
|
-
empty: :empty,
|
|
145
|
-
omitted: :empty,
|
|
146
|
-
},
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
# GML FeatureType elements
|
|
150
|
-
map_element "FeatureType", to: :gml_feature_type,
|
|
151
|
-
value_map: {
|
|
152
|
-
from: {
|
|
153
|
-
nil: :empty,
|
|
154
|
-
empty: :empty,
|
|
155
|
-
omitted: :empty,
|
|
156
|
-
},
|
|
157
|
-
to: {
|
|
158
|
-
nil: :empty,
|
|
159
|
-
empty: :empty,
|
|
160
|
-
omitted: :empty,
|
|
161
|
-
},
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
# GML property elements
|
|
165
|
-
map_element "property", to: :gml_property,
|
|
166
|
-
value_map: {
|
|
167
|
-
from: {
|
|
168
|
-
nil: :empty,
|
|
169
|
-
empty: :empty,
|
|
170
|
-
omitted: :empty,
|
|
171
|
-
},
|
|
172
|
-
to: {
|
|
173
|
-
nil: :empty,
|
|
174
|
-
empty: :empty,
|
|
175
|
-
omitted: :empty,
|
|
176
|
-
},
|
|
177
|
-
}
|
|
46
|
+
value_map: VM
|
|
47
|
+
map_element "CodeList", to: :gml_code_list, value_map: VM
|
|
48
|
+
map_element "DataType", to: :gml_data_type, value_map: VM
|
|
49
|
+
map_element "Union", to: :gml_union, value_map: VM
|
|
50
|
+
map_element "Enumeration", to: :gml_enumeration, value_map: VM
|
|
51
|
+
map_element "Type", to: :gml_type, value_map: VM
|
|
52
|
+
map_element "FeatureType", to: :gml_feature_type, value_map: VM
|
|
53
|
+
map_element "property", to: :gml_property, value_map: VM
|
|
178
54
|
end
|
|
179
55
|
end
|
|
180
56
|
end
|
data/lib/xmi/sparx/root.rb
CHANGED
|
@@ -22,20 +22,19 @@ module Xmi
|
|
|
22
22
|
class << self
|
|
23
23
|
# Parse XMI content into Ruby objects.
|
|
24
24
|
#
|
|
25
|
-
#
|
|
26
|
-
#
|
|
27
|
-
# their corresponding UML versions.
|
|
25
|
+
# Uses the ParserPipeline for composable parsing steps:
|
|
26
|
+
# encoding fix → version detection → XML parsing → index building.
|
|
28
27
|
#
|
|
29
28
|
# @param xml_content [String] The raw XMI XML content
|
|
30
29
|
# @return [SparxRoot] The parsed Ruby object with index built
|
|
31
30
|
#
|
|
31
|
+
# @see Xmi::ParserPipeline
|
|
32
32
|
# @see Xmi.parse
|
|
33
33
|
def parse_xml(xml_content)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
root
|
|
38
|
-
root
|
|
34
|
+
ctx = ParserPipeline.run(
|
|
35
|
+
{ xml: xml_content, root_class: self },
|
|
36
|
+
)
|
|
37
|
+
ctx[:root]
|
|
39
38
|
end
|
|
40
39
|
|
|
41
40
|
# Fix invalid UTF-8 encoding in the XML content.
|
|
@@ -59,13 +58,13 @@ module Xmi
|
|
|
59
58
|
xml SparxMappings::BaseMapping
|
|
60
59
|
|
|
61
60
|
# Build index for fast lookups
|
|
62
|
-
# @return [
|
|
61
|
+
# @return [Sparx::Index]
|
|
63
62
|
def build_index
|
|
64
|
-
@index =
|
|
63
|
+
@index = Index.new(self)
|
|
65
64
|
end
|
|
66
65
|
|
|
67
66
|
# Access the index (builds on first access if needed)
|
|
68
|
-
# @return [
|
|
67
|
+
# @return [Sparx::Index]
|
|
69
68
|
def index
|
|
70
69
|
@index || build_index
|
|
71
70
|
end
|
data/lib/xmi/sparx.rb
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Xmi
|
|
4
|
+
module Uml
|
|
5
|
+
class AnnotatedElement < Lutaml::Model::Serializable
|
|
6
|
+
attribute :idref, ::Xmi::Type::XmiIdRef
|
|
7
|
+
|
|
8
|
+
xml do
|
|
9
|
+
root "annotatedElement"
|
|
10
|
+
namespace ::Xmi::Namespace::Omg::Uml
|
|
11
|
+
|
|
12
|
+
map_attribute "idref", to: :idref
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|