lutaml-model 0.8.191 → 0.8.192

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 (73) hide show
  1. checksums.yaml +4 -4
  2. data/lib/compat/opal/generate_boot.rb +5 -4
  3. data/lib/compat/opal/lutaml_model_boot.rb +0 -7
  4. data/lib/lutaml/model/serialize/format_conversion.rb +4 -6
  5. data/lib/lutaml/model/version.rb +1 -1
  6. data/lib/lutaml/xml/adapter/adapter_helpers.rb +3 -3
  7. data/lib/lutaml/xml/adapter/base_adapter.rb +13 -29
  8. data/lib/lutaml/xml/adapter/moxml_adapter.rb +113 -22
  9. data/lib/lutaml/xml/adapter/xml_parser.rb +6 -8
  10. data/lib/lutaml/xml/adapter/xml_serializer.rb +3 -1
  11. data/lib/lutaml/xml/adapter.rb +0 -4
  12. data/lib/lutaml/xml/adapter_element.rb +19 -9
  13. data/lib/lutaml/xml/adapter_loader.rb +26 -11
  14. data/lib/lutaml/xml/builder/base.rb +6 -7
  15. data/lib/lutaml/xml/document.rb +1 -1
  16. data/lib/lutaml/xml/format.rb +0 -10
  17. data/lib/lutaml/xml/leptris/plan_hydrator.rb +2 -2
  18. data/spec/lutaml/model/cdata_spec.rb +11 -27
  19. data/spec/lutaml/model/encoding_spec.rb +6 -6
  20. data/spec/lutaml/model/except_spec.rb +5 -7
  21. data/spec/lutaml/model/mixed_content_spec.rb +22 -25
  22. data/spec/lutaml/model/multiple_mapping_spec.rb +8 -10
  23. data/spec/lutaml/model/ordered_content_spec.rb +5 -8
  24. data/spec/lutaml/model/processing_instruction_spec.rb +6 -9
  25. data/spec/lutaml/model/serialize/attribute_definition_block_form_spec.rb +1 -1
  26. data/spec/lutaml/model/serialize/builder_spec.rb +1 -1
  27. data/spec/lutaml/xml/adapter/base_adapter_regression_spec.rb +5 -8
  28. data/spec/lutaml/xml/adapter/empty_document_diagnostics_spec.rb +3 -4
  29. data/spec/lutaml/xml/adapter/nokogiri_adapter_spec.rb +2 -2
  30. data/spec/lutaml/xml/adapter/oga_adapter_spec.rb +2 -2
  31. data/spec/lutaml/xml/adapter/order_spec.rb +8 -22
  32. data/spec/lutaml/xml/adapter/over_cap_parse_spec.rb +2 -2
  33. data/spec/lutaml/xml/adapter/ox_adapter_spec.rb +2 -2
  34. data/spec/lutaml/xml/adapter/rexml_adapter_spec.rb +2 -2
  35. data/spec/lutaml/xml/adapter/xml_namespace_spec.rb +5 -8
  36. data/spec/lutaml/xml/adapter_loader_spec.rb +15 -3
  37. data/spec/lutaml/xml/adapter_metadata_default_spec.rb +1 -1
  38. data/spec/lutaml/xml/adapter_moxml_engine_spec.rb +1 -2
  39. data/spec/lutaml/xml/builder/builder_spec.rb +28 -20
  40. data/spec/lutaml/xml/default_namespace_spec.rb +4 -5
  41. data/spec/lutaml/xml/entity_fragmentation_spec.rb +2 -2
  42. data/spec/lutaml/xml/mapping_rule_spec.rb +1 -2
  43. data/spec/lutaml/xml/mapping_spec.rb +12 -14
  44. data/spec/lutaml/xml/namespace_missing_prefix_spec.rb +1 -1
  45. data/spec/lutaml/xml/namespace_preservation_spec.rb +11 -11
  46. data/spec/lutaml/xml/namespace_scope_vcard_spec.rb +5 -8
  47. data/spec/lutaml/xml/prefix_control_spec.rb +5 -8
  48. data/spec/lutaml/xml/type_namespace_prefix_spec.rb +2 -2
  49. data/spec/lutaml/xml/xml_adapter_spec.rb +5 -8
  50. data/spec/lutaml/xml/xml_declaration_spec.rb +19 -19
  51. data/spec/spec_helper.rb +2 -2
  52. data/spec/support/test_adapter_config.rb +9 -25
  53. metadata +1 -21
  54. data/lib/lutaml/xml/adapter/leptris_adapter.rb +0 -16
  55. data/lib/lutaml/xml/adapter/nokogiri_adapter.rb +0 -16
  56. data/lib/lutaml/xml/adapter/oga_adapter.rb +0 -20
  57. data/lib/lutaml/xml/adapter/ox_adapter.rb +0 -16
  58. data/lib/lutaml/xml/adapter/rexml_adapter.rb +0 -25
  59. data/lib/lutaml/xml/builder/leptris.rb +0 -13
  60. data/lib/lutaml/xml/builder/nokogiri.rb +0 -13
  61. data/lib/lutaml/xml/builder/oga.rb +0 -13
  62. data/lib/lutaml/xml/builder/ox.rb +0 -13
  63. data/lib/lutaml/xml/builder/rexml.rb +0 -13
  64. data/lib/lutaml/xml/leptris/element.rb +0 -34
  65. data/lib/lutaml/xml/nokogiri/element.rb +0 -34
  66. data/lib/lutaml/xml/nokogiri.rb +0 -10
  67. data/lib/lutaml/xml/oga/element.rb +0 -15
  68. data/lib/lutaml/xml/oga.rb +0 -10
  69. data/lib/lutaml/xml/ox/element.rb +0 -15
  70. data/lib/lutaml/xml/ox.rb +0 -10
  71. data/lib/lutaml/xml/rexml/element.rb +0 -15
  72. data/lib/lutaml/xml/rexml.rb +0 -10
  73. data/lib/tasks/xml_optimization_benchmark.rb +0 -178
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e7b10a03d458c7802e12b80ba1dd59ed0d4f4c75668a69c13d9add36f3722ba
4
- data.tar.gz: 3a8bee4fcd326b8dd9d1ecded4c7e285f35792cd41d03cc01aa67b3fbc0970e1
3
+ metadata.gz: b581eae95a241bdd6eeab2ae5567e6d78f9ec6b326e430f18fb8808fac8a0591
4
+ data.tar.gz: 486149de4589a0c055a92b253edeb7ca87874917b3ab4c1283e90dd4cc011807
5
5
  SHA512:
6
- metadata.gz: 353c5e1fbb2e53f1f4013f0d8e33b72aa345dfc29c98ce306060233f97a1403bf978bfeef4bf8d03fb0318758ac3a4e0d47fb1bc614662a2a6be4f65b687b50f
7
- data.tar.gz: 57aca3cc29495f7418d9d8c31932c5655359448ae54c8480177c577f26bd9f971a19787b2deaab7929cb8411cf3f254cc85290d2db81b523bd0a56475c3b74b1
6
+ metadata.gz: da52dc805fd13bd4eb536360b974c8c1bc2218117461527fa572c6635ea2ac623076052462c3bce02df0ccb16f5b3e0701e193fa79a106c1f9a71fc88400dfeb
7
+ data.tar.gz: 801147f11f17e9b74c2861f8baa471b9155bd6788f43db2768c7c8d41a4b1742553917476615a54dd531cd5593208c268a63f815f6b9df9acee00a2944248c77
@@ -19,11 +19,12 @@ REPO_ROOT = Pathname.new(File.expand_path("../../..", __dir__))
19
19
  LIB = REPO_ROOT.join("lib")
20
20
 
21
21
  # Patterns excluded under Opal because they pull in native-only deps
22
- # (Nokogiri/Ox C extensions, Thor CLI, etc.). REXML is pure Ruby and
23
- # ships in the bundled gem + moxml's lib/compat/opal/rexml/* shadows,
24
- # so it is NOT excluded — it is a fully working second Opal adapter.
22
+ # (Nokogiri/Ox C extensions, Thor CLI, etc.). The one XML adapter
23
+ # (moxml_adapter) resolves engine classes through LAZY requires, so it
24
+ # is boot-safe. REXML is pure Ruby and ships in the bundled gem +
25
+ # moxml's lib/compat/opal/rexml/* shadows, so it is NOT excluded — it
26
+ # is a fully working second Opal adapter.
25
27
  NATIVE_ONLY_PATTERNS = [
26
- %r{(nokogiri|ox)_adapter\z},
27
28
  %r{/schema/(relaxng|xsd)\b},
28
29
  %r{/schema_builder/(nokogiri|oga)\b},
29
30
  %r{/schema/builder/(nokogiri|oga)\b},
@@ -200,13 +200,11 @@ require "lutaml/xml/namespace_scope_config"
200
200
  require "lutaml/xml/namespace_type_resolver"
201
201
  require "lutaml/xml/namespace_usage"
202
202
  require "lutaml/xml/nested_collection_attribute"
203
- require "lutaml/xml/oga"
204
203
  require "lutaml/xml/parse_session"
205
204
  require "lutaml/xml/parsed_namespace_declaration"
206
205
  require "lutaml/xml/parsed_namespace_set"
207
206
  require "lutaml/xml/polymorphic_value_handler"
208
207
  require "lutaml/xml/qualified_inheritance_strategy"
209
- require "lutaml/xml/rexml"
210
208
  require "lutaml/xml/schema"
211
209
  require "lutaml/xml/schema_location"
212
210
  require "lutaml/xml/serialization"
@@ -478,9 +476,7 @@ require "lutaml/xml/adapter/base_adapter"
478
476
  require "lutaml/xml/adapter/moxml_adapter"
479
477
  require "lutaml/xml/adapter/namespace_data"
480
478
  require "lutaml/xml/adapter/namespace_uri_collector"
481
- require "lutaml/xml/adapter/oga_adapter"
482
479
  require "lutaml/xml/adapter/plan_based_builder"
483
- require "lutaml/xml/adapter/rexml_adapter"
484
480
  require "lutaml/xml/adapter/xml_parser"
485
481
  require "lutaml/xml/adapter/xml_serializer"
486
482
  require "lutaml/xml/builder/base"
@@ -500,9 +496,6 @@ require "lutaml/xml/error/namespace_mismatch_error"
500
496
  require "lutaml/xml/error/schema_validation_error"
501
497
  require "lutaml/xml/error/xml_configuration_error"
502
498
  require "lutaml/xml/error/xml_error"
503
- require "lutaml/xml/oga/element"
504
- require "lutaml/xml/ox/element"
505
- require "lutaml/xml/rexml/element"
506
499
  require "lutaml/xml/serialization/format_conversion"
507
500
  require "lutaml/xml/serialization/instance_methods"
508
501
  require "lutaml/xml/serialization/model_import_ext"
@@ -173,11 +173,10 @@ module Lutaml
173
173
  # rewrites :prefix to :use_prefix before this gate.
174
174
  options.key?(:prefix) || options.key?(:use_prefix)
175
175
 
176
- # The deferred (:moxml) lane resolves through to its engine
177
- # here; concrete adapters answer themselves (#1224).
176
+ # The deferred (:moxml) lane resolves its engine at call
177
+ # time; a pinned lane answers its own engine (#1224).
178
178
  adapter = Lutaml::Model::Config.adapter_for(:xml)
179
- return nil unless adapter&.engine_adapter_class&.name.to_s
180
- .end_with?("LeptrisAdapter")
179
+ return nil unless adapter&.engine_name == :leptris
181
180
 
182
181
  register = extract_register_id(nil)
183
182
  plan = Lutaml::Xml::Leptris::PlanCompiler.compile(self, register)
@@ -211,8 +210,7 @@ module Lutaml
211
210
  return nil if model && model != self
212
211
 
213
212
  adapter = Lutaml::Model::Config.adapter_for(:xml)
214
- return nil unless adapter&.engine_adapter_class&.name.to_s
215
- .end_with?("LeptrisAdapter")
213
+ return nil unless adapter&.engine_name == :leptris
216
214
 
217
215
  register = extract_register_id(nil)
218
216
  plan = Lutaml::Xml::Leptris::PlanCompiler.compile(self, register)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lutaml
4
4
  module Model
5
- VERSION = "0.8.191"
5
+ VERSION = "0.8.192"
6
6
  end
7
7
  end
@@ -5,11 +5,11 @@ module Lutaml
5
5
  module Adapter
6
6
  # Shared helper methods for XML adapters.
7
7
  #
8
- # This module provides common functionality used by both OgaAdapter
9
- # and RexmlAdapter to reduce code duplication.
8
+ # This module provides common node helpers (naming and node-type
9
+ # classification over moxml nodes) used by the adapter.
10
10
  #
11
11
  # @example Including in an adapter
12
- # class OgaAdapter < BaseAdapter
12
+ # class MoxmlAdapter < BaseAdapter
13
13
  # extend AdapterHelpers
14
14
  # end
15
15
  module AdapterHelpers
@@ -3,16 +3,12 @@
3
3
  module Lutaml
4
4
  module Xml
5
5
  module Adapter
6
- # Base class for XML adapters providing shared functionality.
6
+ # Base class for the XML adapter providing shared functionality.
7
7
  #
8
- # This class extracts common code from NokogiriAdapter, OxAdapter,
9
- # OgaAdapter, and RexmlAdapter to reduce duplication and ensure
10
- # consistent behavior across adapters.
11
- #
12
- # Subclasses must implement:
13
- # - MOXML_ADAPTER - Moxml adapter implementation for parsing
14
- # - BUILDER_CLASS - Builder implementation for serialization
15
- # - PARSED_ELEMENT_CLASS - Adapter element class returned by parsing
8
+ # MoxmlAdapter is the one concrete lane; the engine contract
9
+ # (moxml adapter class, parse-error class, empty-document error
10
+ # shape) resolves per engine through its ENGINE_CONFIGS, so the
11
+ # defaults here are the engine-independent fallbacks.
16
12
  #
17
13
  # @abstract Subclass and implement required methods
18
14
  class BaseAdapter < Document
@@ -29,32 +25,20 @@ module Lutaml
29
25
  "The XML may be empty, contain only whitespace, " \
30
26
  "or consist only of an XML declaration."
31
27
  EMPTY_DOCUMENT_ERROR_TYPE = :invalid_format
32
- PARSE_ERROR_CLASS = nil
33
28
 
34
- # Deferred-resolution seams (#1224): the adapter contract the
35
- # parse/serialize machinery reads. Concrete adapters answer
36
- # from their constants; the deferred (:moxml) lane overrides
37
- # these to resolve the engine at call time.
29
+ # The adapter contract the parse/serialize machinery reads.
30
+ # MoxmlAdapter resolves every answer from the serving engine;
31
+ # the defaults here keep the contract total on this base.
38
32
  def self.parsed_element_class
39
- self::PARSED_ELEMENT_CLASS
40
- end
41
-
42
- def self.moxml_adapter_class
43
- self::MOXML_ADAPTER
33
+ Lutaml::Xml::AdapterElement
44
34
  end
45
35
 
46
- def self.parse_error_class_or_nil
47
- self::PARSE_ERROR_CLASS
36
+ def self.empty_document_error_message
37
+ EMPTY_DOCUMENT_ERROR_MESSAGE
48
38
  end
49
39
 
50
- # The lutaml adapter class of the engine actually serving this
51
- # lane. Concrete adapters are their own engine; the deferred
52
- # (:moxml) lane overrides this alongside the seams above.
53
- # Callers that must know the concrete engine class by name (the
54
- # leptris plan fast-path gates) ask here instead of
55
- # string-matching the resolved adapter class.
56
- def self.engine_adapter_class
57
- self
40
+ def self.empty_document_error_type
41
+ EMPTY_DOCUMENT_ERROR_TYPE
58
42
  end
59
43
 
60
44
  # Convert a Formal Public Identifier (FPI) to a URN per RFC 3151.
@@ -5,42 +5,133 @@ require "moxml"
5
5
  module Lutaml
6
6
  module Xml
7
7
  module Adapter
8
- # The deferred (facade) lane (#1224): the `:moxml` adapter type.
9
- # The ENGINE resolves at call time from moxml's runtime answer —
10
- # the engine stays a deployment decision owned by moxml, the way
11
- # detection has always treated it ("moxml is the authority on
12
- # XML adapter availability"). Resolution caches per engine name:
13
- # a bundle that pins moxml's default to leptris gets the
14
- # leptris lane, a nokogiri pin gets nokogiri, without
15
- # re-resolving per parse.
8
+ # THE XML adapter: one moxml-backed lane, engine as data.
9
+ #
10
+ # Every XML parse/serialize rides this class; the ENGINE is a
11
+ # deployment decision resolved as follows:
12
+ #
13
+ # - The class itself is the DEFERRED (facade) lane (#1224): the
14
+ # engine resolves at call time from moxml's runtime answer.
15
+ # - `for_engine(engine)` returns a memoized pinned subclass for
16
+ # an explicit engine selection (AdapterResolver type pins such
17
+ # as :nokogiri, and per-operation overrides such as
18
+ # `from_xml ..., adapter: :ox`).
19
+ #
20
+ # The per-engine adapter classes this replaces were constant
21
+ # shells differing only in the engine triple (moxml adapter,
22
+ # builder, element class); the per-engine builder subclasses
23
+ # differed by one symbol. The engine contract now lives in
24
+ # ENGINE_CONFIGS and the single AdapterElement serves every
25
+ # engine.
16
26
  class MoxmlAdapter < BaseAdapter
17
27
  class << self
18
- def resolved_adapter
19
- engine = Moxml::Config.runtime_default_adapter
20
- @resolved ||= {}
21
- @resolved[engine] ||= begin
22
- # the loader's normalization shape: :leptris ->
23
- # "leptris_adapter" -> Lutaml::Xml::Adapter::LeptrisAdapter
24
- type_name = "#{engine}_adapter"
25
- Lutaml::Xml::AdapterLoader.load_adapter_file(:xml, type_name)
26
- Lutaml::Xml::AdapterLoader.class_for(:xml, type_name)
28
+ # Engine registry: the lazy requires keep this file free of
29
+ # native-only dependencies at load time (the Opal boot
30
+ # requires this file unconditionally). `parse_error` is the
31
+ # engine error class the parse boundary rescues into a
32
+ # format error (nil = ride moxml's own error surface); the
33
+ # rexml entry carries the historical empty-document error
34
+ # contract (:parse_exception / REXML::ParseException).
35
+ ENGINE_CONFIGS = {
36
+ nokogiri: {
37
+ requires: ["moxml/adapter/nokogiri"],
38
+ moxml_adapter: "Moxml::Adapter::Nokogiri",
39
+ parse_error: nil,
40
+ },
41
+ leptris: {
42
+ requires: ["moxml/adapter/leptris"],
43
+ moxml_adapter: "Moxml::Adapter::Leptris",
44
+ parse_error: "Moxml::ParseError",
45
+ },
46
+ oga: {
47
+ requires: ["oga", "moxml/adapter/oga"],
48
+ moxml_adapter: "Moxml::Adapter::Oga",
49
+ parse_error: nil,
50
+ },
51
+ ox: {
52
+ requires: ["moxml/adapter/ox"],
53
+ moxml_adapter: "Moxml::Adapter::Ox",
54
+ parse_error: "Moxml::ParseError",
55
+ },
56
+ rexml: {
57
+ requires: ["rexml/document", "moxml/adapter/rexml"],
58
+ moxml_adapter: "Moxml::Adapter::Rexml",
59
+ parse_error: nil,
60
+ empty_document_error_message: "Malformed XML: Unable to parse " \
61
+ "the provided XML document. The document structure is invalid " \
62
+ "or incomplete.",
63
+ empty_document_error_type: :parse_exception,
64
+ },
65
+ }.freeze
66
+
67
+ # The pinned adapter class for an engine. Memoized per
68
+ # process: a bundle that pins :leptris keeps the leptris
69
+ # lane, a :nokogiri pin keeps nokogiri, without re-resolving
70
+ # per parse.
71
+ def for_engine(engine)
72
+ engine = engine.to_sym
73
+ return self if engine == :moxml
74
+
75
+ @for_engine_mutex ||= Mutex.new
76
+ @for_engine_mutex.synchronize do
77
+ @for_engine ||= {}
78
+ @for_engine[engine] ||= begin
79
+ unless ENGINE_CONFIGS.key?(engine)
80
+ raise ArgumentError,
81
+ "unknown XML engine: `:#{engine}` (known engines: " \
82
+ "#{ENGINE_CONFIGS.keys.map { |e| ":#{e}" }.join(', ')})"
83
+ end
84
+
85
+ engine_name = engine
86
+ Class.new(self) do
87
+ @__engine = engine_name
88
+ end
89
+ end
90
+ end
91
+ end
92
+
93
+ # The engine serving this lane: the pin for a for_engine
94
+ # subclass; the deferred lane resolves at call time from
95
+ # moxml's runtime answer.
96
+ def engine_name
97
+ if instance_variable_defined?(:@__engine) && @__engine
98
+ @__engine
99
+ else
100
+ Lutaml::Xml.moxml_engine
27
101
  end
28
102
  end
29
103
 
104
+ # The lane identity keyed by consumers and specs
105
+ # (expected_<type>_* helpers) — the engine name, not the
106
+ # anonymous-subclass inspection the base class-name
107
+ # derivation would answer.
108
+ def type
109
+ engine_name.to_s
110
+ end
111
+
30
112
  def parsed_element_class
31
- resolved_adapter.parsed_element_class
113
+ Lutaml::Xml::AdapterElement
32
114
  end
33
115
 
34
116
  def moxml_adapter_class
35
- resolved_adapter.moxml_adapter_class
117
+ config = ENGINE_CONFIGS.fetch(engine_name)
118
+ config[:requires].each { |path| require path }
119
+ Object.const_get(config[:moxml_adapter])
36
120
  end
37
121
 
38
122
  def parse_error_class_or_nil
39
- resolved_adapter.parse_error_class_or_nil
123
+ name = ENGINE_CONFIGS.fetch(engine_name)[:parse_error]
124
+ name && Object.const_get(name)
125
+ end
126
+
127
+ def empty_document_error_message
128
+ ENGINE_CONFIGS.fetch(engine_name)[:empty_document_error_message] ||
129
+ super
40
130
  end
41
131
 
42
- def engine_adapter_class
43
- resolved_adapter
132
+ def empty_document_error_type
133
+ ENGINE_CONFIGS.fetch(engine_name)[:empty_document_error_type] ||
134
+ super
44
135
  end
45
136
  end
46
137
  end
@@ -8,12 +8,10 @@ module Lutaml
8
8
  # Extracted from BaseAdapter — parsing is a distinct lifecycle phase
9
9
  # with no instance state dependency.
10
10
  #
11
- # Subclasses must define:
12
- # - MOXML_ADAPTER — Moxml adapter class for parsing
13
- # - PARSED_ELEMENT_CLASS — element wrapper class
14
- # - PARSE_ERROR_CLASS — error class to rescue (nil to skip)
15
- # - EMPTY_DOCUMENT_ERROR_MESSAGE — error message for empty docs
16
- # - EMPTY_DOCUMENT_ERROR_TYPE — :invalid_format or :parse_exception
11
+ # The engine contract the parse boundary reads (the moxml adapter
12
+ # class, the parse-error class, the empty-document error shape)
13
+ # resolves through the adapter's seams — MoxmlAdapter answers
14
+ # from its ENGINE_CONFIGS per serving engine.
17
15
  module XmlParser
18
16
  def parse(xml, options = {})
19
17
  parse_encoding = encoding(xml, options)
@@ -70,12 +68,12 @@ module Lutaml
70
68
  end
71
69
 
72
70
  def raise_empty_document_error(parse_errors = nil)
73
- message = self::EMPTY_DOCUMENT_ERROR_MESSAGE
71
+ message = empty_document_error_message
74
72
  if parse_errors && !parse_errors.empty?
75
73
  message += " (the XML engine reported: #{parse_errors.join('; ')})"
76
74
  end
77
75
 
78
- case self::EMPTY_DOCUMENT_ERROR_TYPE
76
+ case empty_document_error_type
79
77
  when :parse_exception
80
78
  require "rexml/document"
81
79
  raise REXML::ParseException.new(message)
@@ -87,7 +87,9 @@ module Lutaml
87
87
  builder_options[:force_declaration] = true
88
88
  end
89
89
 
90
- builder = self.class::BUILDER_CLASS.build(builder_options) do |xml|
90
+ builder = Builder::Base.build(
91
+ builder_options.merge(engine: self.class.engine_name),
92
+ ) do |xml|
91
93
  if root.is_a?(self.class.parsed_element_class)
92
94
  root.build_xml(xml)
93
95
  else
@@ -12,16 +12,12 @@ module Lutaml
12
12
  autoload :PlanBasedBuilder, "#{__dir__}/adapter/plan_based_builder"
13
13
  autoload :NamespaceUriCollector,
14
14
  "#{__dir__}/adapter/namespace_uri_collector"
15
- autoload :OgaAdapter, "#{__dir__}/adapter/oga_adapter"
16
- autoload :RexmlAdapter, "#{__dir__}/adapter/rexml_adapter"
17
15
  # Plain autoload (in addition to the native table): the Opal boot
18
16
  # generator harvests `autoload :Name, "path"` declarations only,
19
17
  # so the facade must appear here to ride the sequential boot.
20
18
  autoload :MoxmlAdapter, "#{__dir__}/adapter/moxml_adapter"
21
19
  Lutaml::Model::RuntimeCompatibility.autoload_native(
22
20
  self,
23
- NokogiriAdapter: "#{__dir__}/adapter/nokogiri_adapter",
24
- OxAdapter: "#{__dir__}/adapter/ox_adapter",
25
21
  MoxmlAdapter: "#{__dir__}/adapter/moxml_adapter",
26
22
  )
27
23
  end
@@ -2,14 +2,16 @@
2
2
 
3
3
  module Lutaml
4
4
  module Xml
5
- # Base element wrapper for moxml-backed XML adapters.
6
- # NokogiriElement, Ox::Element, Oga::Element, Rexml::Element
7
- # all inherit from this class.
5
+ # THE element wrapper for moxml-backed XML parsing — every engine
6
+ # wraps its nodes in this one class (the per-engine wrappers this
7
+ # replaces carried identical logic; their raw-content handling is
8
+ # folded here so all engines share it).
8
9
  class AdapterElement < XmlElement
9
10
  NamespaceData = Lutaml::Xml::Adapter::NamespaceData
10
11
 
11
12
  def initialize(node, parent: nil, default_namespace: nil)
12
13
  @moxml_node = node
14
+ @raw_text = node.raw_content if node.is_a?(Moxml::Text)
13
15
 
14
16
  node_type = case node
15
17
  when Moxml::Cdata then :cdata
@@ -119,18 +121,26 @@ module Lutaml
119
121
  private
120
122
 
121
123
  def build_element_xml(builder)
122
- builder.create_and_add_element(name,
123
- attributes: build_attributes(self)) do |xml|
124
- children.each { |child| child.build_xml(xml) }
124
+ if namespace_prefix
125
+ builder.create_and_add_element(name,
126
+ prefix: namespace_prefix,
127
+ attributes: build_attributes(self)) do |xml|
128
+ children.each { |child| child.build_xml(xml) }
129
+ end
130
+ else
131
+ builder.create_and_add_element(name,
132
+ attributes: build_attributes(self)) do |xml|
133
+ children.each { |child| child.build_xml(xml) }
134
+ end
125
135
  end
126
136
  end
127
137
 
128
138
  def build_text_for_xml
129
- @text
139
+ @raw_text || @text
130
140
  end
131
141
 
132
142
  def adapter_class
133
- raise NotImplementedError, "#{self.class} must implement #adapter_class"
143
+ Lutaml::Xml::Adapter::MoxmlAdapter
134
144
  end
135
145
 
136
146
  # Shared frozen empties: the parse path hands these straight into
@@ -183,7 +193,7 @@ module Lutaml
183
193
  end
184
194
 
185
195
  def attribute_value_for_build(attr)
186
- attr.value
196
+ attr.raw_value
187
197
  end
188
198
 
189
199
  def parse_children(node, default_namespace: nil)
@@ -4,31 +4,40 @@ module Lutaml
4
4
  module Xml
5
5
  # Adapter loader for XML format.
6
6
  #
7
- # Handles XML-specific adapter file loading and class resolution.
7
+ # Every XML adapter type resolves to the ONE moxml adapter lane:
8
+ # the file is shared, and the type symbol selects the ENGINE on
9
+ # MoxmlAdapter (:moxml keeps the deferred call-time resolution).
8
10
  # Registered with FormatRegistry so Configuration can delegate
9
11
  # XML adapter loading without hardcoded XML references.
10
12
  module AdapterLoader
13
+ # The one adapter file backing every XML type.
14
+ ADAPTER_FILE = "moxml_adapter"
15
+
11
16
  # Load the XML adapter file
12
17
  #
13
18
  # @param _adapter [String] The adapter format name ("xml")
14
- # @param type [String] The normalized type name (e.g., "nokogiri_adapter")
15
- def self.load_adapter_file(_adapter, type)
19
+ # @param _type [String] The normalized type name (e.g.,
20
+ # "nokogiri_adapter") — informational; all types share the
21
+ # one adapter file
22
+ def self.load_adapter_file(_adapter, _type)
16
23
  adapter_path = if Lutaml::Model.opal?
17
- "lutaml/xml/adapter/#{type}"
24
+ "lutaml/xml/adapter/#{ADAPTER_FILE}"
18
25
  else
19
- File.join(File.dirname(__FILE__), "adapter", type)
26
+ File.join(File.dirname(__FILE__), "adapter",
27
+ ADAPTER_FILE)
20
28
  end
21
29
  require adapter_path
22
30
  rescue LoadError => e
23
- # Chain the cause: a known adapter whose underlying engine gem is
24
- # missing (e.g. no nokogiri in the Gemfile) must not present as a
25
- # bare unknown-type error — the LoadError names the real gap.
26
- raise Lutaml::Model::UnknownAdapterTypeError.new("xml", type),
31
+ raise Lutaml::Model::UnknownAdapterTypeError.new("xml", ADAPTER_FILE),
27
32
  cause: e
28
33
  end
29
34
 
30
35
  # Load the Moxml adapter for XML
31
36
  #
37
+ # The engine preload for an explicit type pin: a missing engine
38
+ # gem (e.g. no nokogiri in the Gemfile) surfaces here chained as
39
+ # an UnknownAdapterTypeError, not as a bare LoadError.
40
+ #
32
41
  # @param type_name [Symbol] The adapter type (:nokogiri, :ox, etc.)
33
42
  # @param _adapter_name [Symbol] The format name (:xml)
34
43
  def self.load_moxml_adapter(type_name, _adapter_name)
@@ -38,15 +47,21 @@ module Lutaml
38
47
  return if type_name.to_sym == :moxml
39
48
 
40
49
  Moxml::Adapter.load(type_name)
50
+ rescue LoadError => e
51
+ raise Lutaml::Model::UnknownAdapterTypeError.new("xml",
52
+ type_name),
53
+ cause: e
41
54
  end
42
55
 
43
- # Resolve the adapter class for XML
56
+ # Resolve the adapter class for XML: the type symbol pins the
57
+ # engine on the shared lane.
44
58
  #
45
59
  # @param _adapter [String] The adapter format name ("xml")
46
60
  # @param type [String] The normalized type name (e.g., "nokogiri_adapter")
47
61
  # @return [Class] The adapter class
48
62
  def self.class_for(_adapter, type)
49
- Lutaml::Xml::Adapter.const_get(to_class_name(type))
63
+ engine = type.to_s.delete_suffix("_adapter").to_sym
64
+ Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(engine)
50
65
  end
51
66
 
52
67
  # Convert string to class name
@@ -6,14 +6,18 @@ module Lutaml
6
6
  module Xml
7
7
  module Builder
8
8
  # Base builder for XML construction using moxml.
9
- # All adapter-specific builders inherit from this class.
9
+ # The one builder for every engine: the ENGINE is an argument
10
+ # (the serving adapter's engine_name), not a subclass identity —
11
+ # the per-engine builder classes this replaces differed by one
12
+ # symbol.
10
13
  #
11
14
  # The builder creates XML documents through moxml's document model.
12
15
  # Declaration, doctype, indentation, and line endings are handled
13
16
  # by moxml — no manual string assembly.
14
17
  class Base
15
18
  def self.build(options = {})
16
- context = Moxml.new(moxml_backend)
19
+ engine = options.delete(:engine) || Lutaml::Xml.moxml_engine
20
+ context = Moxml.new(engine)
17
21
  if Lutaml::Model.opal?
18
22
  context.config.namespace_validation_mode = :lenient
19
23
  end
@@ -67,11 +71,6 @@ module Lutaml
67
71
  instance
68
72
  end
69
73
 
70
- # Override in subclass to set the moxml backend
71
- def self.moxml_backend
72
- nil
73
- end
74
-
75
74
  attr_reader :doc
76
75
  attr_accessor :encoding, :declaration_mode
77
76
 
@@ -270,7 +270,7 @@ module Lutaml
270
270
  # Check if a child node is an EntityReference
271
271
  def entity_reference_node?(child)
272
272
  return false unless defined?(::Nokogiri)
273
- return false unless child.is_a?(Lutaml::Xml::NokogiriElement)
273
+ return false unless child.is_a?(Lutaml::Xml::AdapterElement)
274
274
 
275
275
  node = child.adapter_node
276
276
  defined?(::Nokogiri) && node.is_a?(::Nokogiri::XML::EntityReference) && node.entity_reference?
@@ -177,16 +177,6 @@ module Lutaml
177
177
  autoload :TypeNamespace, "#{__dir__}/type_namespace"
178
178
  autoload :TransformationSupport, "#{__dir__}/transformation_support"
179
179
  autoload :SharedDsl, "#{__dir__}/shared_dsl"
180
-
181
- autoload :Oga, "#{__dir__}/oga"
182
- autoload :Rexml, "#{__dir__}/rexml"
183
- Lutaml::Model::RuntimeCompatibility.autoload_native(
184
- self,
185
- NokogiriElement: "#{__dir__}/nokogiri/element",
186
- Nokogiri: "#{__dir__}/nokogiri",
187
- Ox: "#{__dir__}/ox",
188
- LeptrisElement: "#{__dir__}/leptris/element",
189
- )
190
180
  end
191
181
  end
192
182
 
@@ -624,7 +624,7 @@ module Lutaml
624
624
  end
625
625
 
626
626
  def bridge_element(node)
627
- Lutaml::Xml::LeptrisElement.new(
627
+ Lutaml::Xml::AdapterElement.new(
628
628
  Moxml::Node.wrap(node, bridge_context),
629
629
  )
630
630
  end
@@ -699,7 +699,7 @@ module Lutaml
699
699
  # wrapper element. Ancestor namespace context is absent (the
700
700
  # compiler only defers on namespace-free model chains).
701
701
  def fragment_element(raw)
702
- Lutaml::Xml::Adapter::LeptrisAdapter.parse(raw).root
702
+ Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:leptris).parse(raw).root
703
703
  end
704
704
 
705
705
  # Attribute names claimed by exactly one attr row — the only