xmi 0.3.21 → 0.5.0

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.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/release.yml +13 -6
  3. data/.gitignore +2 -1
  4. data/.rubocop.yml +12 -13
  5. data/.rubocop_todo.yml +150 -13
  6. data/CHANGELOG.md +55 -0
  7. data/CODE_OF_CONDUCT.md +84 -0
  8. data/Gemfile +10 -0
  9. data/README.adoc +319 -6
  10. data/benchmark_parse.rb +60 -0
  11. data/docs/migration.md +141 -0
  12. data/docs/versioning.md +255 -0
  13. data/lib/xmi/add.rb +14 -38
  14. data/lib/xmi/{the_custom_profile.rb → custom_profile.rb} +25 -25
  15. data/lib/xmi/delete.rb +14 -38
  16. data/lib/xmi/difference.rb +14 -38
  17. data/lib/xmi/documentation.rb +16 -101
  18. data/lib/xmi/ea_root.rb +114 -33
  19. data/lib/xmi/extension.rb +6 -6
  20. data/lib/xmi/namespace/dynamic.rb +28 -0
  21. data/lib/xmi/namespace/omg.rb +81 -0
  22. data/lib/xmi/namespace/sparx.rb +39 -0
  23. data/lib/xmi/namespace.rb +9 -0
  24. data/lib/xmi/namespace_detector.rb +138 -0
  25. data/lib/xmi/namespace_registry.rb +119 -0
  26. data/lib/xmi/parsing.rb +113 -0
  27. data/lib/xmi/replace.rb +14 -38
  28. data/lib/xmi/root.rb +49 -213
  29. data/lib/xmi/sparx/connector.rb +241 -0
  30. data/lib/xmi/sparx/custom_profile.rb +19 -0
  31. data/lib/xmi/sparx/diagram.rb +97 -0
  32. data/lib/xmi/sparx/ea_stub.rb +20 -0
  33. data/lib/xmi/{extensions/eauml.rb → sparx/ea_uml.rb} +3 -2
  34. data/lib/xmi/sparx/element.rb +453 -0
  35. data/lib/xmi/sparx/extension.rb +43 -0
  36. data/lib/xmi/{extensions → sparx}/gml.rb +9 -3
  37. data/lib/xmi/sparx/mappings/base_mapping.rb +182 -0
  38. data/lib/xmi/sparx/mappings.rb +10 -0
  39. data/lib/xmi/sparx/primitive_type.rb +18 -0
  40. data/lib/xmi/sparx/root.rb +60 -0
  41. data/lib/xmi/sparx/sys_ph_s.rb +18 -0
  42. data/lib/xmi/sparx.rb +17 -1376
  43. data/lib/xmi/type.rb +37 -0
  44. data/lib/xmi/uml.rb +191 -469
  45. data/lib/xmi/v20110701.rb +81 -0
  46. data/lib/xmi/v20131001.rb +68 -0
  47. data/lib/xmi/v20161101.rb +61 -0
  48. data/lib/xmi/version.rb +1 -1
  49. data/lib/xmi/version_registry.rb +164 -0
  50. data/lib/xmi/versioned.rb +142 -0
  51. data/lib/xmi.rb +83 -11
  52. data/scripts-xmi-profile/profile_xmi_simple.rb +213 -0
  53. data/xmi.gemspec +3 -9
  54. metadata +38 -77
@@ -0,0 +1,182 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Xmi
4
+ module Sparx
5
+ module SparxMappings
6
+ # Base XML mapping class for Sparx EA XMI documents.
7
+ #
8
+ # This reusable mapping class encapsulates all the XML element → attribute
9
+ # mappings for SparxRoot, eliminating the previous eval hack.
10
+ #
11
+ # @example Use in a model class
12
+ # class SparxRoot < Root
13
+ # xml SparxMappings::BaseMapping
14
+ # end
15
+ #
16
+ # @example Extend with additional mappings
17
+ # class ExtendedRoot < Root
18
+ # xml SparxMappings::GmlMapping
19
+ # end
20
+ class BaseMapping < Lutaml::Xml::Mapping
21
+ xml do
22
+ # Set the default namespace for element name resolution
23
+ namespace ::Xmi::Namespace::Omg::Xmi
24
+
25
+ namespace_scope [
26
+ ::Xmi::Namespace::Omg::Xmi,
27
+ ::Xmi::Namespace::Omg::Uml,
28
+ ::Xmi::Namespace::Omg::UmlDi,
29
+ ::Xmi::Namespace::Omg::UmlDc,
30
+ ::Xmi::Namespace::Sparx::Extension,
31
+ ::Xmi::Namespace::Sparx::SysPhS,
32
+ ::Xmi::Namespace::Sparx::Gml,
33
+ ::Xmi::Namespace::Sparx::EaUml,
34
+ ::Xmi::Namespace::Sparx::CustomProfile,
35
+ ::Xmi::Namespace::Sparx::CityGml,
36
+ ]
37
+
38
+ # Extension element containing Sparx EA-specific metadata
39
+ map_element "Extension", to: :extension
40
+
41
+ # Modelica parameter elements (SysPhS profile)
42
+ map_element "ModelicaParameter", to: :modelica_parameter
43
+
44
+ # 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
+ }
58
+
59
+ # GML ApplicationSchema elements
60
+ map_element "ApplicationSchema", to: :gml_application_schema,
61
+ value_map: {
62
+ from: {
63
+ nil: :empty,
64
+ empty: :empty,
65
+ omitted: :empty,
66
+ },
67
+ to: {
68
+ nil: :empty,
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
+ }
178
+ end
179
+ end
180
+ end
181
+ end
182
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Xmi
4
+ module Sparx
5
+ module SparxMappings
6
+ # Reusable XML mapping classes for Sparx EA XMI documents.
7
+ autoload :BaseMapping, "xmi/sparx/mappings/base_mapping"
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Xmi
4
+ module Sparx
5
+ module PrimitiveType
6
+ class PrimitiveTypes < Lutaml::Model::Serializable
7
+ attribute :packaged_element, Uml::PackagedElement, collection: true
8
+
9
+ xml do
10
+ root "primitivetypes"
11
+
12
+ map_element "packagedElement", to: :packaged_element,
13
+ value_map: VALUE_MAP
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Xmi
4
+ module Sparx
5
+ class SparxRoot < Root
6
+ attribute :modelica_parameter, SysPhS
7
+
8
+ attribute :eauml_import, EaUml::Import, collection: true
9
+ attribute :gml_application_schema, Gml::ApplicationSchema,
10
+ collection: true
11
+ attribute :gml_code_list, Gml::CodeList, collection: true
12
+ attribute :gml_data_type, Gml::CodeList, collection: true
13
+ attribute :gml_union, Gml::CodeList, collection: true
14
+ attribute :gml_enumeration, Gml::CodeList, collection: true
15
+ attribute :gml_type, Gml::CodeList, collection: true
16
+ attribute :gml_feature_type, Gml::CodeList, collection: true
17
+ attribute :gml_property, Gml::Property, collection: true
18
+
19
+ attribute :extension, Extension
20
+ attribute :model, Uml::UmlModel
21
+
22
+ class << self
23
+ # Parse XMI content into Ruby objects.
24
+ #
25
+ # This method uses automatic version detection to handle different XMI
26
+ # namespace versions (e.g., XMI 20110701, 20131001, 20161101) and
27
+ # their corresponding UML versions.
28
+ #
29
+ # @param xml_content [String] The raw XMI XML content
30
+ # @return [SparxRoot] The parsed Ruby object
31
+ #
32
+ # @see Xmi.parse
33
+ def parse_xml(xml_content)
34
+ xml_content = fix_encoding(xml_content)
35
+ Xmi.init_versioning!
36
+ Xmi::VersionRegistry.parse_with_detected_version(xml_content, self)
37
+ end
38
+
39
+ # Fix invalid UTF-8 encoding in the XML content.
40
+ #
41
+ # Some EA-generated XMI files contain invalid UTF-8 byte sequences
42
+ # that would cause parsing failures. This method replaces invalid
43
+ # bytes with placeholder characters.
44
+ #
45
+ # @param xml_content [String] The raw XML content
46
+ # @return [String] The XML content with valid UTF-8 encoding
47
+ def fix_encoding(xml_content)
48
+ return xml_content if xml_content.valid_encoding?
49
+
50
+ xml_content
51
+ .encode("UTF-16be", invalid: :replace, replace: "?")
52
+ .encode("UTF-8")
53
+ end
54
+ end
55
+
56
+ # Use the reusable BaseMapping class instead of eval hack
57
+ xml SparxMappings::BaseMapping
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Xmi
4
+ module Sparx
5
+ class SysPhS < Lutaml::Model::Serializable
6
+ attribute :base_package, :string
7
+ attribute :name, :string
8
+
9
+ xml do
10
+ root "ModelicaParameter"
11
+ namespace ::Xmi::Namespace::Sparx::SysPhS
12
+
13
+ map_attribute "base_Package", to: :base_package
14
+ map_attribute "name", to: :name
15
+ end
16
+ end
17
+ end
18
+ end