lutaml 0.11.7 → 0.11.8
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.yml +20 -0
- data/.rubocop_todo.yml +0 -1
- data/Gemfile +32 -5
- data/README.adoc +3 -3
- data/README.md +6 -8
- data/Rakefile +41 -1
- data/bin/console +0 -1
- data/exe/lutaml-lml +6 -0
- data/exe/lutaml-lml-lsp +11 -0
- data/lib/compat/opal/generate_boot.rb +132 -0
- data/lib/compat/opal/js_bundle_entry.rb +42 -0
- data/lib/compat/opal/lutaml_model_boot.rb +540 -0
- data/lib/compat/opal/monitor.rb +31 -0
- data/lib/compat/opal/moxml/adapter/customized_rexml/entity_reference.rb +9 -0
- data/lib/compat/opal/moxml/adapter/customized_rexml/formatter.rb +225 -0
- data/lib/compat/opal/moxml/adapter/customized_rexml.rb +11 -0
- data/lib/compat/opal/moxml_boot.rb +68 -0
- data/lib/compat/opal/objectspace_shim.rb +23 -0
- data/lib/compat/opal/rexml/namespace.rb +59 -0
- data/lib/compat/opal/rexml/parsers/baseparser.rb +1016 -0
- data/lib/compat/opal/rexml/source.rb +214 -0
- data/lib/compat/opal/rexml/text.rb +426 -0
- data/lib/compat/opal/rexml/xmltokens.rb +45 -0
- data/lib/compat/opal/rexml_compat.rb +85 -0
- data/lib/compat/opal/yaml_compat.rb +32 -0
- data/lib/lutaml/hash_format/adapter/document.rb +10 -0
- data/lib/lutaml/hash_format/adapter/mapping.rb +17 -0
- data/lib/lutaml/hash_format/adapter/mapping_rule.rb +9 -0
- data/lib/lutaml/hash_format/adapter/standard_adapter.rb +17 -0
- data/lib/lutaml/hash_format/adapter/transform.rb +9 -0
- data/lib/lutaml/hash_format/adapter.rb +13 -0
- data/lib/lutaml/hash_format/format.rb +29 -0
- data/lib/lutaml/hash_format/type/serializers.rb +24 -0
- data/lib/lutaml/hash_format.rb +7 -0
- data/lib/lutaml/json/adapter/document.rb +13 -0
- data/lib/lutaml/json/adapter/mapping.rb +17 -0
- data/lib/lutaml/json/adapter/mapping_rule.rb +9 -0
- data/lib/lutaml/json/adapter/multi_json_adapter.rb +45 -0
- data/lib/lutaml/json/adapter/oj_adapter.rb +41 -0
- data/lib/lutaml/json/adapter/standard_adapter.rb +43 -0
- data/lib/lutaml/json/adapter/transform.rb +9 -0
- data/lib/lutaml/json/adapter/yeptris_adapter.rb +74 -0
- data/lib/lutaml/json/adapter.rb +21 -0
- data/lib/lutaml/json/format.rb +61 -0
- data/lib/lutaml/json/generator_options.rb +62 -0
- data/lib/lutaml/json/schema/json_schema.rb +62 -0
- data/lib/lutaml/json/schema.rb +9 -0
- data/lib/lutaml/json/type/serializers.rb +72 -0
- data/lib/lutaml/json.rb +7 -0
- data/lib/lutaml/jsonl/adapter/document.rb +14 -0
- data/lib/lutaml/jsonl/adapter/mapping.rb +17 -0
- data/lib/lutaml/jsonl/adapter/mapping_rule.rb +9 -0
- data/lib/lutaml/jsonl/adapter/standard_adapter.rb +34 -0
- data/lib/lutaml/jsonl/adapter/transform.rb +26 -0
- data/lib/lutaml/jsonl/adapter.rb +13 -0
- data/lib/lutaml/jsonl/format.rb +22 -0
- data/lib/lutaml/jsonl.rb +7 -0
- data/lib/lutaml/jsonld/adapter.rb +31 -0
- data/lib/lutaml/jsonld.rb +20 -0
- data/lib/lutaml/key_value/adapter/hash/document.rb +13 -0
- data/lib/lutaml/key_value/adapter/hash/mapping.rb +17 -0
- data/lib/lutaml/key_value/adapter/hash/mapping_rule.rb +9 -0
- data/lib/lutaml/key_value/adapter/hash/standard_adapter.rb +19 -0
- data/lib/lutaml/key_value/adapter/hash/transform.rb +10 -0
- data/lib/lutaml/key_value/adapter/hash.rb +15 -0
- data/lib/lutaml/key_value/adapter/json/document.rb +16 -0
- data/lib/lutaml/key_value/adapter/json/mapping.rb +22 -0
- data/lib/lutaml/key_value/adapter/json/mapping_rule.rb +14 -0
- data/lib/lutaml/key_value/adapter/json/multi_json_adapter.rb +54 -0
- data/lib/lutaml/key_value/adapter/json/oj_adapter.rb +46 -0
- data/lib/lutaml/key_value/adapter/json/standard_adapter.rb +47 -0
- data/lib/lutaml/key_value/adapter/json/transform.rb +14 -0
- data/lib/lutaml/key_value/adapter/json/yeptris_adapter.rb +15 -0
- data/lib/lutaml/key_value/adapter/json.rb +24 -0
- data/lib/lutaml/key_value/adapter/jsonl/document.rb +16 -0
- data/lib/lutaml/key_value/adapter/jsonl/mapping.rb +17 -0
- data/lib/lutaml/key_value/adapter/jsonl/mapping_rule.rb +9 -0
- data/lib/lutaml/key_value/adapter/jsonl/standard_adapter.rb +36 -0
- data/lib/lutaml/key_value/adapter/jsonl/transform.rb +26 -0
- data/lib/lutaml/key_value/adapter/jsonl.rb +17 -0
- data/lib/lutaml/key_value/adapter/toml/document.rb +13 -0
- data/lib/lutaml/key_value/adapter/toml/mapping.rb +26 -0
- data/lib/lutaml/key_value/adapter/toml/mapping_rule.rb +9 -0
- data/lib/lutaml/key_value/adapter/toml/teptris_adapter.rb +36 -0
- data/lib/lutaml/key_value/adapter/toml/toml_rb_adapter.rb +34 -0
- data/lib/lutaml/key_value/adapter/toml/tomlib_adapter.rb +40 -0
- data/lib/lutaml/key_value/adapter/toml/transform.rb +10 -0
- data/lib/lutaml/key_value/adapter/toml.rb +22 -0
- data/lib/lutaml/key_value/adapter/yaml/document.rb +12 -0
- data/lib/lutaml/key_value/adapter/yaml/mapping.rb +17 -0
- data/lib/lutaml/key_value/adapter/yaml/mapping_rule.rb +9 -0
- data/lib/lutaml/key_value/adapter/yaml/standard_adapter.rb +35 -0
- data/lib/lutaml/key_value/adapter/yaml/transform.rb +10 -0
- data/lib/lutaml/key_value/adapter/yaml/yeptris_adapter.rb +15 -0
- data/lib/lutaml/key_value/adapter/yaml.rb +17 -0
- data/lib/lutaml/key_value/adapter/yamls/document.rb +16 -0
- data/lib/lutaml/key_value/adapter/yamls/mapping.rb +17 -0
- data/lib/lutaml/key_value/adapter/yamls/mapping_rule.rb +9 -0
- data/lib/lutaml/key_value/adapter/yamls/standard_adapter.rb +37 -0
- data/lib/lutaml/key_value/adapter/yamls/transform.rb +26 -0
- data/lib/lutaml/key_value/adapter/yamls.rb +17 -0
- data/lib/lutaml/key_value/adapter.rb +14 -0
- data/lib/lutaml/key_value/data_model/element.rb +225 -0
- data/lib/lutaml/key_value/data_model.rb +14 -0
- data/lib/lutaml/key_value/document.rb +28 -0
- data/lib/lutaml/key_value/format.rb +26 -0
- data/lib/lutaml/key_value/mapping.rb +393 -0
- data/lib/lutaml/key_value/mapping_rule.rb +95 -0
- data/lib/lutaml/key_value/transform.rb +1223 -0
- data/lib/lutaml/key_value/transformation/collection_serializer.rb +572 -0
- data/lib/lutaml/key_value/transformation/rule_compiler.rb +299 -0
- data/lib/lutaml/key_value/transformation/value_serializer.rb +399 -0
- data/lib/lutaml/key_value/transformation.rb +1276 -0
- data/lib/lutaml/key_value/transformation_builder.rb +30 -0
- data/lib/lutaml/key_value.rb +7 -0
- data/lib/lutaml/lml/association_label_resolver.rb +52 -0
- data/lib/lutaml/lml/cli.rb +506 -0
- data/lib/lutaml/lml/data_processor/attribute_processing.rb +133 -0
- data/lib/lutaml/lml/data_processor/collection_processing.rb +37 -0
- data/lib/lutaml/lml/data_processor/instance_processing.rb +77 -0
- data/lib/lutaml/lml/data_processor/value_declaration_processing.rb +70 -0
- data/lib/lutaml/lml/data_processor/value_processing.rb +103 -0
- data/lib/lutaml/lml/data_processor/view_processing.rb +26 -0
- data/lib/lutaml/lml/data_processor.rb +59 -0
- data/lib/lutaml/lml/diagnostic.rb +149 -0
- data/lib/lutaml/lml/document_builder.rb +481 -0
- data/lib/lutaml/lml/entity_types.rb +30 -0
- data/lib/lutaml/lml/executor/adapter_helpers.rb +45 -0
- data/lib/lutaml/lml/executor/condition_evaluator.rb +169 -0
- data/lib/lutaml/lml/executor/csv_adapter.rb +88 -0
- data/lib/lutaml/lml/executor/format_adapter.rb +54 -0
- data/lib/lutaml/lml/executor/xml_adapter.rb +102 -0
- data/lib/lutaml/lml/executor.rb +96 -0
- data/lib/lutaml/lml/format/adapter/document.rb +11 -0
- data/lib/lutaml/lml/format/adapter/mapping.rb +31 -0
- data/lib/lutaml/lml/format/adapter/standard_adapter.rb +162 -0
- data/lib/lutaml/lml/format/adapter/transform.rb +11 -0
- data/lib/lutaml/lml/format.rb +29 -0
- data/lib/lutaml/lml/formatter/base.rb +79 -0
- data/lib/lutaml/lml/formatter/canonical.rb +736 -0
- data/lib/lutaml/lml/formatter/elk.rb +45 -0
- data/lib/lutaml/lml/formatter/svg_pdf/path_parser.rb +134 -0
- data/lib/lutaml/lml/formatter/svg_pdf.rb +285 -0
- data/lib/lutaml/lml/formatter.rb +11 -0
- data/lib/lutaml/lml/grammar/lml.artifact.json +14993 -0
- data/lib/lutaml/lml/grammar/lml.parg +389 -0
- data/lib/lutaml/lml/grammar.rb +60 -0
- data/lib/lutaml/lml/has_attributes.rb +14 -0
- data/lib/lutaml/lml/import_resolver.rb +96 -0
- data/lib/lutaml/lml/layout/elk_engine.rb +15 -0
- data/lib/lutaml/lml/layout/elk_graph_builder.rb +129 -0
- data/lib/lutaml/lml/layout/elk_svg_markers.rb +45 -0
- data/lib/lutaml/lml/layout/elk_svg_renderer.rb +119 -0
- data/lib/lutaml/lml/layout/engine.rb +17 -0
- data/lib/lutaml/lml/layout.rb +12 -0
- data/lib/lutaml/lml/literal_value.rb +32 -0
- data/lib/lutaml/lml/lsp/conversions.rb +78 -0
- data/lib/lutaml/lml/lsp/keywords.rb +43 -0
- data/lib/lutaml/lml/lsp/server.rb +378 -0
- data/lib/lutaml/lml/lsp/store.rb +68 -0
- data/lib/lutaml/lml/lsp/transport.rb +53 -0
- data/lib/lutaml/lml/lsp.rb +16 -0
- data/lib/lutaml/lml/model_compiler/enums.rb +172 -0
- data/lib/lutaml/lml/model_compiler/hydration.rb +123 -0
- data/lib/lutaml/lml/model_compiler/serialization_mappings.rb +188 -0
- data/lib/lutaml/lml/model_compiler/string_formats.rb +42 -0
- data/lib/lutaml/lml/model_compiler/validation.rb +65 -0
- data/lib/lutaml/lml/model_compiler.rb +323 -0
- data/lib/lutaml/lml/models/action.rb +10 -0
- data/lib/lutaml/lml/models/association.rb +29 -0
- data/lib/lutaml/lml/models/cardinality.rb +10 -0
- data/lib/lutaml/lml/models/collection.rb +11 -0
- data/lib/lutaml/lml/models/constraint.rb +23 -0
- data/lib/lutaml/lml/models/data_type.rb +41 -0
- data/lib/lutaml/lml/models/derived_field.rb +14 -0
- data/lib/lutaml/lml/models/diagram.rb +20 -0
- data/lib/lutaml/lml/models/document.rb +84 -0
- data/lib/lutaml/lml/models/enum.rb +38 -0
- data/lib/lutaml/lml/models/fidelity.rb +10 -0
- data/lib/lutaml/lml/models/group.rb +11 -0
- data/lib/lutaml/lml/models/instance.rb +26 -0
- data/lib/lutaml/lml/models/instance_collection.rb +16 -0
- data/lib/lutaml/lml/models/instances_export.rb +10 -0
- data/lib/lutaml/lml/models/instances_import.rb +11 -0
- data/lib/lutaml/lml/models/mapping.rb +15 -0
- data/lib/lutaml/lml/models/mapping_rule.rb +16 -0
- data/lib/lutaml/lml/models/member_field.rb +14 -0
- data/lib/lutaml/lml/models/namespace.rb +16 -0
- data/lib/lutaml/lml/models/operation.rb +26 -0
- data/lib/lutaml/lml/models/operation_parameter.rb +12 -0
- data/lib/lutaml/lml/models/package.rb +26 -0
- data/lib/lutaml/lml/models/primitive_type.rb +33 -0
- data/lib/lutaml/lml/models/reference.rb +23 -0
- data/lib/lutaml/lml/models/serialization_mapping.rb +19 -0
- data/lib/lutaml/lml/models/string_format.rb +16 -0
- data/lib/lutaml/lml/models/top_element_attribute.rb +116 -0
- data/lib/lutaml/lml/models/uml_class.rb +85 -0
- data/lib/lutaml/lml/models/value.rb +15 -0
- data/lib/lutaml/lml/models/view_filter.rb +11 -0
- data/lib/lutaml/lml/models/view_import.rb +11 -0
- data/lib/lutaml/lml/parser.rb +19 -0
- data/lib/lutaml/lml/pipeline.rb +73 -0
- data/lib/lutaml/lml/positioned.rb +13 -0
- data/lib/lutaml/lml/preprocessor.rb +130 -0
- data/lib/lutaml/lml/quoting.rb +60 -0
- data/lib/lutaml/lml/source.rb +49 -0
- data/lib/lutaml/lml/source_position.rb +20 -0
- data/lib/lutaml/lml/symbol_index.rb +200 -0
- data/lib/lutaml/lml/transform.rb +119 -0
- data/lib/lutaml/lml/types/text_type.rb +28 -0
- data/lib/lutaml/lml/types.rb +10 -0
- data/lib/lutaml/lml/validator.rb +458 -0
- data/lib/lutaml/lml/version.rb +10 -0
- data/lib/lutaml/lml/view_resolution.rb +32 -0
- data/lib/lutaml/lml/view_resolver.rb +48 -0
- data/lib/lutaml/lml/yaml_parser.rb +17 -0
- data/lib/lutaml/lml.rb +130 -0
- data/lib/lutaml/model/adapter_resolver.rb +487 -0
- data/lib/lutaml/model/adapter_scope.rb +64 -0
- data/lib/lutaml/model/attribute.rb +1511 -0
- data/lib/lutaml/model/attribute_validator.rb +290 -0
- data/lib/lutaml/model/cached_type_resolver/concurrent_map_cache.rb +48 -0
- data/lib/lutaml/model/cached_type_resolver/mutex_hash_cache.rb +53 -0
- data/lib/lutaml/model/cached_type_resolver.rb +145 -0
- data/lib/lutaml/model/choice.rb +343 -0
- data/lib/lutaml/model/cli.rb +85 -0
- data/lib/lutaml/model/collection.rb +740 -0
- data/lib/lutaml/model/collection_handler.rb +157 -0
- data/lib/lutaml/model/comparable_model.rb +710 -0
- data/lib/lutaml/model/comparable_nil.rb +9 -0
- data/lib/lutaml/model/comparison.rb +15 -0
- data/lib/lutaml/model/compiled_rule.rb +242 -0
- data/lib/lutaml/model/config.rb +169 -0
- data/lib/lutaml/model/configuration.rb +138 -0
- data/lib/lutaml/model/consolidation/attribute_grouper.rb +44 -0
- data/lib/lutaml/model/consolidation/dispatcher.rb +45 -0
- data/lib/lutaml/model/consolidation/engine.rb +33 -0
- data/lib/lutaml/model/consolidation/pattern_chunker.rb +87 -0
- data/lib/lutaml/model/consolidation_map.rb +68 -0
- data/lib/lutaml/model/consolidation_rule/dispatch_block.rb +34 -0
- data/lib/lutaml/model/consolidation_rule/gather_rule.rb +17 -0
- data/lib/lutaml/model/consolidation_rule/pattern_content_rule.rb +15 -0
- data/lib/lutaml/model/consolidation_rule/pattern_element_rule.rb +17 -0
- data/lib/lutaml/model/consolidation_rule.rb +27 -0
- data/lib/lutaml/model/constants.rb +11 -0
- data/lib/lutaml/model/context_registry.rb +208 -0
- data/lib/lutaml/model/deep_dupable.rb +16 -0
- data/lib/lutaml/model/error/choice_lower_bound_error.rb +9 -0
- data/lib/lutaml/model/error/choice_upper_bound_error.rb +9 -0
- data/lib/lutaml/model/error/collection_count_out_of_range_error.rb +29 -0
- data/lib/lutaml/model/error/collection_true_missing_error.rb +16 -0
- data/lib/lutaml/model/error/element_count_out_of_range_error.rb +35 -0
- data/lib/lutaml/model/error/format_adapter_not_specified_error.rb +25 -0
- data/lib/lutaml/model/error/fraction_digits_error.rb +20 -0
- data/lib/lutaml/model/error/import_model_with_root_error.rb +9 -0
- data/lib/lutaml/model/error/incorrect_mapping_argument_error.rb +6 -0
- data/lib/lutaml/model/error/incorrect_sequence_error.rb +9 -0
- data/lib/lutaml/model/error/invalid_attribute_name_error.rb +15 -0
- data/lib/lutaml/model/error/invalid_attribute_options_error.rb +16 -0
- data/lib/lutaml/model/error/invalid_attribute_type_error.rb +98 -0
- data/lib/lutaml/model/error/invalid_choice_range_error.rb +18 -0
- data/lib/lutaml/model/error/invalid_format_error.rb +11 -0
- data/lib/lutaml/model/error/invalid_value_error.rb +18 -0
- data/lib/lutaml/model/error/length_error.rb +19 -0
- data/lib/lutaml/model/error/liquid_class_not_found_error.rb +9 -0
- data/lib/lutaml/model/error/liquid_drop_already_registered_error.rb +11 -0
- data/lib/lutaml/model/error/liquid_not_enabled_error.rb +9 -0
- data/lib/lutaml/model/error/mapping_already_exists_error.rb +6 -0
- data/lib/lutaml/model/error/mapping_attribute_missing_error.rb +6 -0
- data/lib/lutaml/model/error/mapping_attribute_type_error.rb +6 -0
- data/lib/lutaml/model/error/max_exclusive_error.rb +19 -0
- data/lib/lutaml/model/error/max_inclusive_error.rb +20 -0
- data/lib/lutaml/model/error/max_length_error.rb +20 -0
- data/lib/lutaml/model/error/min_exclusive_error.rb +19 -0
- data/lib/lutaml/model/error/min_inclusive_error.rb +20 -0
- data/lib/lutaml/model/error/min_length_error.rb +20 -0
- data/lib/lutaml/model/error/mixed_content_collection_error.rb +17 -0
- data/lib/lutaml/model/error/multiple_mappings_error.rb +6 -0
- data/lib/lutaml/model/error/no_attributes_defined_liquid_error.rb +9 -0
- data/lib/lutaml/model/error/no_mapping_found_error.rb +9 -0
- data/lib/lutaml/model/error/no_root_mapping_error.rb +10 -0
- data/lib/lutaml/model/error/no_root_namespace_error.rb +10 -0
- data/lib/lutaml/model/error/ordered_content_mapping_error.rb +17 -0
- data/lib/lutaml/model/error/pattern_not_matched_error.rb +17 -0
- data/lib/lutaml/model/error/polymorphic_error.rb +14 -0
- data/lib/lutaml/model/error/register/not_registrable_class_error.rb +11 -0
- data/lib/lutaml/model/error/required_attribute_missing_error.rb +9 -0
- data/lib/lutaml/model/error/restriction_error.rb +8 -0
- data/lib/lutaml/model/error/reverse_transform_block_not_defined_error.rb +6 -0
- data/lib/lutaml/model/error/reverse_transformation_declaration_error.rb +6 -0
- data/lib/lutaml/model/error/sorting_configuration_conflict_error.rb +9 -0
- data/lib/lutaml/model/error/total_digits_error.rb +20 -0
- data/lib/lutaml/model/error/transform_block_not_defined_error.rb +6 -0
- data/lib/lutaml/model/error/type/invalid_value_error.rb +21 -0
- data/lib/lutaml/model/error/type/max_bound_error.rb +20 -0
- data/lib/lutaml/model/error/type/max_exclusive_error.rb +20 -0
- data/lib/lutaml/model/error/type/max_length_error.rb +20 -0
- data/lib/lutaml/model/error/type/min_bound_error.rb +20 -0
- data/lib/lutaml/model/error/type/min_exclusive_error.rb +20 -0
- data/lib/lutaml/model/error/type/min_length_error.rb +20 -0
- data/lib/lutaml/model/error/type/pattern_not_matched_error.rb +18 -0
- data/lib/lutaml/model/error/type.rb +19 -0
- data/lib/lutaml/model/error/type_error.rb +9 -0
- data/lib/lutaml/model/error/type_not_enabled_error.rb +9 -0
- data/lib/lutaml/model/error/type_only_mapping_error.rb +13 -0
- data/lib/lutaml/model/error/type_only_namespace_error.rb +12 -0
- data/lib/lutaml/model/error/undefined_attribute_error.rb +9 -0
- data/lib/lutaml/model/error/union_schema_unsupported_error.rb +11 -0
- data/lib/lutaml/model/error/unknown_adapter_type_error.rb +95 -0
- data/lib/lutaml/model/error/unknown_discriminator_error.rb +11 -0
- data/lib/lutaml/model/error/unknown_mapping_error.rb +18 -0
- data/lib/lutaml/model/error/unknown_sequence_mapping_error.rb +9 -0
- data/lib/lutaml/model/error/unknown_type_error.rb +32 -0
- data/lib/lutaml/model/error/unresolvable_type_error.rb +27 -0
- data/lib/lutaml/model/error/unsupported_version_error.rb +14 -0
- data/lib/lutaml/model/error/validation_error.rb +20 -0
- data/lib/lutaml/model/error/validation_failed_error.rb +9 -0
- data/lib/lutaml/model/error.rb +8 -0
- data/lib/lutaml/model/errors.rb +38 -0
- data/lib/lutaml/model/evolution_steps.rb +85 -0
- data/lib/lutaml/model/finalization_cache.rb +51 -0
- data/lib/lutaml/model/format_registry.rb +218 -0
- data/lib/lutaml/model/global_context.rb +476 -0
- data/lib/lutaml/model/global_register.rb +142 -0
- data/lib/lutaml/model/hash.rb +15 -0
- data/lib/lutaml/model/import_registry.rb +250 -0
- data/lib/lutaml/model/instrumentation.rb +304 -0
- data/lib/lutaml/model/json.rb +25 -0
- data/lib/lutaml/model/json_adapter.rb +8 -0
- data/lib/lutaml/model/jsonl.rb +15 -0
- data/lib/lutaml/model/liquefiable.rb +198 -0
- data/lib/lutaml/model/liquid/indexed_access.rb +33 -0
- data/lib/lutaml/model/liquid/mapping.rb +30 -0
- data/lib/lutaml/model/liquid.rb +10 -0
- data/lib/lutaml/model/lml/document.rb +109 -0
- data/lib/lutaml/model/lml/exporter.rb +328 -0
- data/lib/lutaml/model/lml/rejected_error.rb +32 -0
- data/lib/lutaml/model/lml/round_trip.rb +49 -0
- data/lib/lutaml/model/lml.rb +40 -0
- data/lib/lutaml/model/mapping/listener.rb +126 -0
- data/lib/lutaml/model/mapping/mapping.rb +209 -0
- data/lib/lutaml/model/mapping/mapping_rule.rb +673 -0
- data/lib/lutaml/model/mapping/model_mapping.rb +133 -0
- data/lib/lutaml/model/mapping/model_mapping_rule.rb +57 -0
- data/lib/lutaml/model/mapping_hash.rb +80 -0
- data/lib/lutaml/model/model_transformer.rb +101 -0
- data/lib/lutaml/model/one_entry_cache.rb +57 -0
- data/lib/lutaml/model/organization.rb +29 -0
- data/lib/lutaml/model/register/model_tree_importer.rb +88 -0
- data/lib/lutaml/model/register/namespace_binding.rb +92 -0
- data/lib/lutaml/model/register.rb +589 -0
- data/lib/lutaml/model/registrable.rb +8 -0
- data/lib/lutaml/model/render_policy.rb +166 -0
- data/lib/lutaml/model/restriction_validation.rb +437 -0
- data/lib/lutaml/model/runtime_compatibility.rb +144 -0
- data/lib/lutaml/model/schema/base_schema.rb +77 -0
- data/lib/lutaml/model/schema/class_loader.rb +59 -0
- data/lib/lutaml/model/schema/compiled_output.rb +83 -0
- data/lib/lutaml/model/schema/decorators/attribute.rb +116 -0
- data/lib/lutaml/model/schema/decorators/choices.rb +29 -0
- data/lib/lutaml/model/schema/decorators/class_definition.rb +84 -0
- data/lib/lutaml/model/schema/decorators/definition_collection.rb +97 -0
- data/lib/lutaml/model/schema/decorators.rb +15 -0
- data/lib/lutaml/model/schema/definitions/attribute.rb +32 -0
- data/lib/lutaml/model/schema/definitions/choice.rb +20 -0
- data/lib/lutaml/model/schema/definitions/facet.rb +40 -0
- data/lib/lutaml/model/schema/definitions/group_import.rb +22 -0
- data/lib/lutaml/model/schema/definitions/member_walk.rb +33 -0
- data/lib/lutaml/model/schema/definitions/model.rb +40 -0
- data/lib/lutaml/model/schema/definitions/namespace.rb +24 -0
- data/lib/lutaml/model/schema/definitions/restricted_type.rb +32 -0
- data/lib/lutaml/model/schema/definitions/sequence.rb +19 -0
- data/lib/lutaml/model/schema/definitions/simple_content.rb +22 -0
- data/lib/lutaml/model/schema/definitions/transform_facet.rb +21 -0
- data/lib/lutaml/model/schema/definitions/type_ref.rb +20 -0
- data/lib/lutaml/model/schema/definitions/union_type.rb +28 -0
- data/lib/lutaml/model/schema/definitions/xml_root.rb +20 -0
- data/lib/lutaml/model/schema/definitions.rb +24 -0
- data/lib/lutaml/model/schema/file_writer.rb +73 -0
- data/lib/lutaml/model/schema/generator/definition.rb +98 -0
- data/lib/lutaml/model/schema/generator/definitions_collection.rb +117 -0
- data/lib/lutaml/model/schema/generator/properties_collection.rb +65 -0
- data/lib/lutaml/model/schema/generator/property.rb +182 -0
- data/lib/lutaml/model/schema/generator/ref.rb +24 -0
- data/lib/lutaml/model/schema/generator.rb +15 -0
- data/lib/lutaml/model/schema/helpers/template_helper.rb +49 -0
- data/lib/lutaml/model/schema/helpers.rb +11 -0
- data/lib/lutaml/model/schema/json_schema.rb +17 -0
- data/lib/lutaml/model/schema/json_schema_parser.rb +91 -0
- data/lib/lutaml/model/schema/module_nesting.rb +31 -0
- data/lib/lutaml/model/schema/namespace_naming.rb +46 -0
- data/lib/lutaml/model/schema/registry_generator.rb +115 -0
- data/lib/lutaml/model/schema/renderer.rb +38 -0
- data/lib/lutaml/model/schema/renderers/base.rb +41 -0
- data/lib/lutaml/model/schema/renderers/mappings.rb +78 -0
- data/lib/lutaml/model/schema/renderers/member_decls.rb +121 -0
- data/lib/lutaml/model/schema/renderers/model.rb +133 -0
- data/lib/lutaml/model/schema/renderers/namespace.rb +30 -0
- data/lib/lutaml/model/schema/renderers/registration.rb +64 -0
- data/lib/lutaml/model/schema/renderers/required_files_calculator.rb +94 -0
- data/lib/lutaml/model/schema/renderers/restricted_type.rb +218 -0
- data/lib/lutaml/model/schema/renderers/union.rb +83 -0
- data/lib/lutaml/model/schema/renderers.rb +20 -0
- data/lib/lutaml/model/schema/rnc_compiler/source_resolver.rb +51 -0
- data/lib/lutaml/model/schema/rnc_compiler.rb +64 -0
- data/lib/lutaml/model/schema/rng_compiler/define_classifier.rb +94 -0
- data/lib/lutaml/model/schema/rng_compiler/element_visitor.rb +412 -0
- data/lib/lutaml/model/schema/rng_compiler/member_collector.rb +30 -0
- data/lib/lutaml/model/schema/rng_compiler/rng_helpers.rb +160 -0
- data/lib/lutaml/model/schema/rng_compiler/value_type_resolver.rb +129 -0
- data/lib/lutaml/model/schema/rng_compiler.rb +225 -0
- data/lib/lutaml/model/schema/schema_builder/nokogiri.rb +41 -0
- data/lib/lutaml/model/schema/schema_builder/oga.rb +92 -0
- data/lib/lutaml/model/schema/shared_methods.rb +24 -0
- data/lib/lutaml/model/schema/templates/model.erb +9 -0
- data/lib/lutaml/model/schema/templates.rb +164 -0
- data/lib/lutaml/model/schema/xml_compiler/element_order.rb +42 -0
- data/lib/lutaml/model/schema/xml_compiler/registry_generator.rb +51 -0
- data/lib/lutaml/model/schema/xml_compiler/spec_builder/complex_types.rb +198 -0
- data/lib/lutaml/model/schema/xml_compiler/spec_builder/members.rb +249 -0
- data/lib/lutaml/model/schema/xml_compiler/spec_builder/simple_types.rb +185 -0
- data/lib/lutaml/model/schema/xml_compiler/spec_builder.rb +186 -0
- data/lib/lutaml/model/schema/xml_compiler/supported_data_types.rb +100 -0
- data/lib/lutaml/model/schema/xml_compiler.rb +109 -0
- data/lib/lutaml/model/schema/yaml_schema.rb +17 -0
- data/lib/lutaml/model/schema.rb +88 -0
- data/lib/lutaml/model/schema_location.rb +18 -0
- data/lib/lutaml/model/sequence.rb +220 -0
- data/lib/lutaml/model/serializable.rb +46 -0
- data/lib/lutaml/model/serialization_adapter.rb +24 -0
- data/lib/lutaml/model/serialize/attribute_definition.rb +897 -0
- data/lib/lutaml/model/serialize/builder.rb +258 -0
- data/lib/lutaml/model/serialize/conversion_caching.rb +129 -0
- data/lib/lutaml/model/serialize/deserialization_context.rb +51 -0
- data/lib/lutaml/model/serialize/enum_handling.rb +171 -0
- data/lib/lutaml/model/serialize/format_conversion.rb +624 -0
- data/lib/lutaml/model/serialize/initialization.rb +825 -0
- data/lib/lutaml/model/serialize/model_import.rb +425 -0
- data/lib/lutaml/model/serialize/transformation_builder.rb +128 -0
- data/lib/lutaml/model/serialize/value_mapping.rb +173 -0
- data/lib/lutaml/model/serialize.rb +533 -0
- data/lib/lutaml/model/services/base.rb +13 -0
- data/lib/lutaml/model/services/logger.rb +57 -0
- data/lib/lutaml/model/services/rule_value_extractor.rb +95 -0
- data/lib/lutaml/model/services/transformer.rb +143 -0
- data/lib/lutaml/model/services/type/validator/number.rb +25 -0
- data/lib/lutaml/model/services/type/validator/string.rb +53 -0
- data/lib/lutaml/model/services/type/validator/symbol.rb +30 -0
- data/lib/lutaml/model/services/type/validator.rb +69 -0
- data/lib/lutaml/model/services/type.rb +9 -0
- data/lib/lutaml/model/services/validator.rb +143 -0
- data/lib/lutaml/model/services.rb +10 -0
- data/lib/lutaml/model/store.rb +239 -0
- data/lib/lutaml/model/toml.rb +40 -0
- data/lib/lutaml/model/transform/xml_transform.rb +5 -0
- data/lib/lutaml/model/transform.rb +229 -0
- data/lib/lutaml/model/transformation.rb +89 -0
- data/lib/lutaml/model/transformation_builder.rb +55 -0
- data/lib/lutaml/model/transformation_registry.rb +327 -0
- data/lib/lutaml/model/type/base64_binary.rb +58 -0
- data/lib/lutaml/model/type/boolean.rb +35 -0
- data/lib/lutaml/model/type/date.rb +75 -0
- data/lib/lutaml/model/type/date_time.rb +60 -0
- data/lib/lutaml/model/type/date_time_with_timezone.rb +28 -0
- data/lib/lutaml/model/type/date_with_timezone.rb +28 -0
- data/lib/lutaml/model/type/day_time_duration.rb +35 -0
- data/lib/lutaml/model/type/decimal.rb +64 -0
- data/lib/lutaml/model/type/duration.rb +82 -0
- data/lib/lutaml/model/type/email_address.rb +28 -0
- data/lib/lutaml/model/type/float.rb +33 -0
- data/lib/lutaml/model/type/hash.rb +74 -0
- data/lib/lutaml/model/type/hex_binary.rb +56 -0
- data/lib/lutaml/model/type/hostname.rb +30 -0
- data/lib/lutaml/model/type/integer.rb +62 -0
- data/lib/lutaml/model/type/ip_v4_address.rb +27 -0
- data/lib/lutaml/model/type/ip_v6_address.rb +47 -0
- data/lib/lutaml/model/type/metaschema_pattern.rb +34 -0
- data/lib/lutaml/model/type/non_negative_integer.rb +25 -0
- data/lib/lutaml/model/type/positive_integer.rb +25 -0
- data/lib/lutaml/model/type/qname.rb +85 -0
- data/lib/lutaml/model/type/reference.rb +76 -0
- data/lib/lutaml/model/type/string.rb +62 -0
- data/lib/lutaml/model/type/symbol.rb +67 -0
- data/lib/lutaml/model/type/time.rb +52 -0
- data/lib/lutaml/model/type/time_without_date.rb +50 -0
- data/lib/lutaml/model/type/token.rb +25 -0
- data/lib/lutaml/model/type/uninitialized_class_guard.rb +36 -0
- data/lib/lutaml/model/type/uri.rb +51 -0
- data/lib/lutaml/model/type/uri_reference.rb +29 -0
- data/lib/lutaml/model/type/uuid.rb +25 -0
- data/lib/lutaml/model/type/value.rb +364 -0
- data/lib/lutaml/model/type/year_month_duration.rb +29 -0
- data/lib/lutaml/model/type.rb +199 -0
- data/lib/lutaml/model/type_context.rb +294 -0
- data/lib/lutaml/model/type_registry.rb +165 -0
- data/lib/lutaml/model/type_resolver.rb +187 -0
- data/lib/lutaml/model/type_substitution.rb +117 -0
- data/lib/lutaml/model/uninitialized_class.rb +70 -0
- data/lib/lutaml/model/union.rb +363 -0
- data/lib/lutaml/model/utils.rb +352 -0
- data/lib/lutaml/model/validation/concerns/has_issues.rb +27 -0
- data/lib/lutaml/model/validation/context.rb +36 -0
- data/lib/lutaml/model/validation/issue.rb +62 -0
- data/lib/lutaml/model/validation/layer_result.rb +34 -0
- data/lib/lutaml/model/validation/profile.rb +66 -0
- data/lib/lutaml/model/validation/registry.rb +60 -0
- data/lib/lutaml/model/validation/remediation.rb +33 -0
- data/lib/lutaml/model/validation/remediation_result.rb +20 -0
- data/lib/lutaml/model/validation/report.rb +39 -0
- data/lib/lutaml/model/validation/rule.rb +59 -0
- data/lib/lutaml/model/validation.rb +137 -0
- data/lib/lutaml/model/validation_framework.rb +77 -0
- data/lib/lutaml/model/value_policy.rb +27 -0
- data/lib/lutaml/model/value_transformer.rb +25 -0
- data/lib/lutaml/model/version.rb +7 -0
- data/lib/lutaml/model/yaml.rb +15 -0
- data/lib/lutaml/model/yamls.rb +15 -0
- data/lib/lutaml/model.rb +309 -0
- data/lib/lutaml/rdf/context.rb +69 -0
- data/lib/lutaml/rdf/error.rb +7 -0
- data/lib/lutaml/rdf/iri.rb +44 -0
- data/lib/lutaml/rdf/language_tagged.rb +11 -0
- data/lib/lutaml/rdf/linked_data_transform.rb +249 -0
- data/lib/lutaml/rdf/literal.rb +62 -0
- data/lib/lutaml/rdf/mapping.rb +86 -0
- data/lib/lutaml/rdf/mapping_rule.rb +52 -0
- data/lib/lutaml/rdf/member_rule.rb +55 -0
- data/lib/lutaml/rdf/namespace.rb +58 -0
- data/lib/lutaml/rdf/namespace_set.rb +69 -0
- data/lib/lutaml/rdf/namespaces/dcterms_namespace.rb +12 -0
- data/lib/lutaml/rdf/namespaces/owl_namespace.rb +12 -0
- data/lib/lutaml/rdf/namespaces/rdf_namespace.rb +14 -0
- data/lib/lutaml/rdf/namespaces/rdfs_namespace.rb +12 -0
- data/lib/lutaml/rdf/namespaces/skos_namespace.rb +12 -0
- data/lib/lutaml/rdf/namespaces/xsd_namespace.rb +12 -0
- data/lib/lutaml/rdf/namespaces.rb +14 -0
- data/lib/lutaml/rdf/term_definition.rb +39 -0
- data/lib/lutaml/rdf/transform.rb +45 -0
- data/lib/lutaml/rdf.rb +22 -0
- data/lib/lutaml/toml/adapter/document.rb +10 -0
- data/lib/lutaml/toml/adapter/mapping.rb +26 -0
- data/lib/lutaml/toml/adapter/mapping_rule.rb +9 -0
- data/lib/lutaml/toml/adapter/teptris_adapter.rb +14 -0
- data/lib/lutaml/toml/adapter/toml_rb_adapter.rb +32 -0
- data/lib/lutaml/toml/adapter/tomlib_adapter.rb +48 -0
- data/lib/lutaml/toml/adapter/transform.rb +9 -0
- data/lib/lutaml/toml/adapter.rb +20 -0
- data/lib/lutaml/toml/format.rb +48 -0
- data/lib/lutaml/toml/type/serializers.rb +71 -0
- data/lib/lutaml/toml.rb +7 -0
- data/lib/lutaml/turtle/adapter.rb +35 -0
- data/lib/lutaml/turtle/mapping.rb +7 -0
- data/lib/lutaml/turtle/transform.rb +250 -0
- data/lib/lutaml/turtle.rb +22 -0
- data/lib/lutaml/version.rb +1 -1
- data/lib/lutaml/xml/adapter/adapter_helpers.rb +108 -0
- data/lib/lutaml/xml/adapter/base_adapter.rb +249 -0
- data/lib/lutaml/xml/adapter/leptris_adapter.rb +16 -0
- data/lib/lutaml/xml/adapter/namespace_data.rb +56 -0
- data/lib/lutaml/xml/adapter/namespace_uri_collector.rb +71 -0
- data/lib/lutaml/xml/adapter/nokogiri_adapter.rb +16 -0
- data/lib/lutaml/xml/adapter/oga_adapter.rb +20 -0
- data/lib/lutaml/xml/adapter/ox_adapter.rb +16 -0
- data/lib/lutaml/xml/adapter/plan_based_builder.rb +944 -0
- data/lib/lutaml/xml/adapter/rexml_adapter.rb +25 -0
- data/lib/lutaml/xml/adapter/xml_parser.rb +89 -0
- data/lib/lutaml/xml/adapter/xml_serializer.rb +334 -0
- data/lib/lutaml/xml/adapter.rb +24 -0
- data/lib/lutaml/xml/adapter_element.rb +339 -0
- data/lib/lutaml/xml/adapter_loader.rb +56 -0
- data/lib/lutaml/xml/attribute_namespace_resolver.rb +139 -0
- data/lib/lutaml/xml/blank_namespace.rb +51 -0
- data/lib/lutaml/xml/blank_namespace_handler.rb +50 -0
- data/lib/lutaml/xml/builder/base.rb +258 -0
- data/lib/lutaml/xml/builder/leptris.rb +13 -0
- data/lib/lutaml/xml/builder/nokogiri.rb +13 -0
- data/lib/lutaml/xml/builder/oga.rb +13 -0
- data/lib/lutaml/xml/builder/ox.rb +13 -0
- data/lib/lutaml/xml/builder/rexml.rb +13 -0
- data/lib/lutaml/xml/builder.rb +18 -0
- data/lib/lutaml/xml/configurable.rb +215 -0
- data/lib/lutaml/xml/data_model.rb +295 -0
- data/lib/lutaml/xml/decisions/decision.rb +120 -0
- data/lib/lutaml/xml/decisions/decision_context.rb +225 -0
- data/lib/lutaml/xml/decisions/decision_engine.rb +67 -0
- data/lib/lutaml/xml/decisions/decision_rule.rb +54 -0
- data/lib/lutaml/xml/decisions/element_prefix_resolver.rb +85 -0
- data/lib/lutaml/xml/decisions/rules/attribute_usage_rule.rb +37 -0
- data/lib/lutaml/xml/decisions/rules/default_preference_rule.rb +62 -0
- data/lib/lutaml/xml/decisions/rules/element_form_default_rule.rb +66 -0
- data/lib/lutaml/xml/decisions/rules/element_form_default_unqualified_rule.rb +73 -0
- data/lib/lutaml/xml/decisions/rules/element_form_option_rule.rb +83 -0
- data/lib/lutaml/xml/decisions/rules/explicit_option_rule.rb +57 -0
- data/lib/lutaml/xml/decisions/rules/format_preservation_rule.rb +74 -0
- data/lib/lutaml/xml/decisions/rules/hoisted_on_parent_rule.rb +60 -0
- data/lib/lutaml/xml/decisions/rules/inherit_from_parent_rule.rb +52 -0
- data/lib/lutaml/xml/decisions/rules/inherit_parent_prefix_rule.rb +69 -0
- data/lib/lutaml/xml/decisions/rules/namespace_scope_rule.rb +54 -0
- data/lib/lutaml/xml/decisions/rules/reuse_parent_prefix_rule.rb +78 -0
- data/lib/lutaml/xml/decisions/rules/used_prefix_rule.rb +70 -0
- data/lib/lutaml/xml/decisions/rules.rb +39 -0
- data/lib/lutaml/xml/decisions.rb +15 -0
- data/lib/lutaml/xml/declaration_handler.rb +115 -0
- data/lib/lutaml/xml/declaration_plan/attribute_node.rb +81 -0
- data/lib/lutaml/xml/declaration_plan/element_node.rb +101 -0
- data/lib/lutaml/xml/declaration_plan.rb +480 -0
- data/lib/lutaml/xml/declaration_plan_query.rb +105 -0
- data/lib/lutaml/xml/declaration_planner.rb +1914 -0
- data/lib/lutaml/xml/doctype_extractor.rb +51 -0
- data/lib/lutaml/xml/document.rb +385 -0
- data/lib/lutaml/xml/element.rb +108 -0
- data/lib/lutaml/xml/element_prefix_resolver.rb +50 -0
- data/lib/lutaml/xml/encoding_normalizer.rb +54 -0
- data/lib/lutaml/xml/error/invalid_namespace_error.rb +46 -0
- data/lib/lutaml/xml/error/invalid_xsd_type_error.rb +43 -0
- data/lib/lutaml/xml/error/namespace_mismatch_error.rb +53 -0
- data/lib/lutaml/xml/error/schema_validation_error.rb +25 -0
- data/lib/lutaml/xml/error/xml_configuration_error.rb +17 -0
- data/lib/lutaml/xml/error/xml_error.rb +21 -0
- data/lib/lutaml/xml/format.rb +364 -0
- data/lib/lutaml/xml/format_chooser.rb +214 -0
- data/lib/lutaml/xml/hoisting_algorithm.rb +234 -0
- data/lib/lutaml/xml/html_entities.rb +290 -0
- data/lib/lutaml/xml/leptris/element.rb +34 -0
- data/lib/lutaml/xml/leptris/native_emission.rb +295 -0
- data/lib/lutaml/xml/leptris/plan_compiler.rb +652 -0
- data/lib/lutaml/xml/leptris/plan_hydrator.rb +827 -0
- data/lib/lutaml/xml/leptris/plan_order.rb +72 -0
- data/lib/lutaml/xml/leptris/plan_serializer.rb +711 -0
- data/lib/lutaml/xml/leptris/plan_walk.rb +36 -0
- data/lib/lutaml/xml/leptris.rb +48 -0
- data/lib/lutaml/xml/listener.rb +33 -0
- data/lib/lutaml/xml/mapping.rb +1746 -0
- data/lib/lutaml/xml/mapping_rule.rb +688 -0
- data/lib/lutaml/xml/model_transform.rb +1824 -0
- data/lib/lutaml/xml/namespace.rb +445 -0
- data/lib/lutaml/xml/namespace_class_registry.rb +144 -0
- data/lib/lutaml/xml/namespace_collector.rb +649 -0
- data/lib/lutaml/xml/namespace_declaration.rb +202 -0
- data/lib/lutaml/xml/namespace_declaration_builder.rb +67 -0
- data/lib/lutaml/xml/namespace_declaration_data.rb +179 -0
- data/lib/lutaml/xml/namespace_inheritance_resolver.rb +142 -0
- data/lib/lutaml/xml/namespace_inheritance_strategy.rb +26 -0
- data/lib/lutaml/xml/namespace_needs.rb +255 -0
- data/lib/lutaml/xml/namespace_resolution_strategy.rb +230 -0
- data/lib/lutaml/xml/namespace_resolver.rb +219 -0
- data/lib/lutaml/xml/namespace_scope_config.rb +110 -0
- data/lib/lutaml/xml/namespace_type_resolver.rb +135 -0
- data/lib/lutaml/xml/namespace_usage.rb +121 -0
- data/lib/lutaml/xml/nested_collection_attribute.rb +95 -0
- data/lib/lutaml/xml/nokogiri/element.rb +34 -0
- data/lib/lutaml/xml/nokogiri.rb +10 -0
- data/lib/lutaml/xml/oga/element.rb +15 -0
- data/lib/lutaml/xml/oga.rb +10 -0
- data/lib/lutaml/xml/ox/element.rb +15 -0
- data/lib/lutaml/xml/ox.rb +10 -0
- data/lib/lutaml/xml/parse_session.rb +139 -0
- data/lib/lutaml/xml/parsed_namespace_declaration.rb +129 -0
- data/lib/lutaml/xml/parsed_namespace_set.rb +149 -0
- data/lib/lutaml/xml/polymorphic_value_handler.rb +41 -0
- data/lib/lutaml/xml/qualified_inheritance_strategy.rb +27 -0
- data/lib/lutaml/xml/rexml/element.rb +15 -0
- data/lib/lutaml/xml/rexml.rb +10 -0
- data/lib/lutaml/xml/schema/builder/nokogiri.rb +41 -0
- data/lib/lutaml/xml/schema/builder/oga.rb +92 -0
- data/lib/lutaml/xml/schema/builder.rb +59 -0
- data/lib/lutaml/xml/schema/builtin_types.rb +112 -0
- data/lib/lutaml/xml/schema/relaxng_schema.rb +83 -0
- data/lib/lutaml/xml/schema/xsd/all.rb +31 -0
- data/lib/lutaml/xml/schema/xsd/annotation.rb +31 -0
- data/lib/lutaml/xml/schema/xsd/any.rb +33 -0
- data/lib/lutaml/xml/schema/xsd/any_attribute.rb +29 -0
- data/lib/lutaml/xml/schema/xsd/appinfo.rb +25 -0
- data/lib/lutaml/xml/schema/xsd/attribute.rb +78 -0
- data/lib/lutaml/xml/schema/xsd/attribute_group.rb +89 -0
- data/lib/lutaml/xml/schema/xsd/base.rb +270 -0
- data/lib/lutaml/xml/schema/xsd/choice.rb +68 -0
- data/lib/lutaml/xml/schema/xsd/complex_content.rb +39 -0
- data/lib/lutaml/xml/schema/xsd/complex_type.rb +159 -0
- data/lib/lutaml/xml/schema/xsd/documentation.rb +26 -0
- data/lib/lutaml/xml/schema/xsd/element.rb +117 -0
- data/lib/lutaml/xml/schema/xsd/enumeration.rb +25 -0
- data/lib/lutaml/xml/schema/xsd/errors/enhanced_error.rb +142 -0
- data/lib/lutaml/xml/schema/xsd/errors/error_context.rb +67 -0
- data/lib/lutaml/xml/schema/xsd/errors/message_builder.rb +103 -0
- data/lib/lutaml/xml/schema/xsd/errors/suggestion.rb +67 -0
- data/lib/lutaml/xml/schema/xsd/errors/troubleshooters/namespace_troubleshooter.rb +96 -0
- data/lib/lutaml/xml/schema/xsd/errors/troubleshooters/troubleshooting_handler.rb +70 -0
- data/lib/lutaml/xml/schema/xsd/errors.rb +148 -0
- data/lib/lutaml/xml/schema/xsd/extension_complex_content.rb +63 -0
- data/lib/lutaml/xml/schema/xsd/extension_simple_content.rb +48 -0
- data/lib/lutaml/xml/schema/xsd/field.rb +25 -0
- data/lib/lutaml/xml/schema/xsd/file_validation_result.rb +55 -0
- data/lib/lutaml/xml/schema/xsd/fraction_digits.rb +29 -0
- data/lib/lutaml/xml/schema/xsd/glob.rb +105 -0
- data/lib/lutaml/xml/schema/xsd/group.rb +79 -0
- data/lib/lutaml/xml/schema/xsd/import.rb +33 -0
- data/lib/lutaml/xml/schema/xsd/include.rb +31 -0
- data/lib/lutaml/xml/schema/xsd/key.rb +32 -0
- data/lib/lutaml/xml/schema/xsd/keyref.rb +34 -0
- data/lib/lutaml/xml/schema/xsd/length.rb +27 -0
- data/lib/lutaml/xml/schema/xsd/list.rb +29 -0
- data/lib/lutaml/xml/schema/xsd/max_exclusive.rb +25 -0
- data/lib/lutaml/xml/schema/xsd/max_inclusive.rb +23 -0
- data/lib/lutaml/xml/schema/xsd/max_length.rb +25 -0
- data/lib/lutaml/xml/schema/xsd/min_exclusive.rb +25 -0
- data/lib/lutaml/xml/schema/xsd/min_inclusive.rb +23 -0
- data/lib/lutaml/xml/schema/xsd/min_length.rb +25 -0
- data/lib/lutaml/xml/schema/xsd/namespace_mapping.rb +37 -0
- data/lib/lutaml/xml/schema/xsd/namespace_uri_remapping.rb +79 -0
- data/lib/lutaml/xml/schema/xsd/notation.rb +31 -0
- data/lib/lutaml/xml/schema/xsd/pattern.rb +25 -0
- data/lib/lutaml/xml/schema/xsd/redefine.rb +35 -0
- data/lib/lutaml/xml/schema/xsd/restriction_complex_content.rb +56 -0
- data/lib/lutaml/xml/schema/xsd/restriction_simple_content.rb +84 -0
- data/lib/lutaml/xml/schema/xsd/restriction_simple_type.rb +64 -0
- data/lib/lutaml/xml/schema/xsd/schema.rb +379 -0
- data/lib/lutaml/xml/schema/xsd/schema_file_validation_results.rb +55 -0
- data/lib/lutaml/xml/schema/xsd/schema_location_mapping.rb +74 -0
- data/lib/lutaml/xml/schema/xsd/schema_name_resolver.rb +32 -0
- data/lib/lutaml/xml/schema/xsd/schema_path.rb +207 -0
- data/lib/lutaml/xml/schema/xsd/schema_validator.rb +259 -0
- data/lib/lutaml/xml/schema/xsd/selector.rb +27 -0
- data/lib/lutaml/xml/schema/xsd/sequence.rb +68 -0
- data/lib/lutaml/xml/schema/xsd/serialized_schema.rb +185 -0
- data/lib/lutaml/xml/schema/xsd/simple_content.rb +61 -0
- data/lib/lutaml/xml/schema/xsd/simple_type.rb +37 -0
- data/lib/lutaml/xml/schema/xsd/total_digits.rb +29 -0
- data/lib/lutaml/xml/schema/xsd/type_index_entry.rb +40 -0
- data/lib/lutaml/xml/schema/xsd/type_resolution_result.rb +112 -0
- data/lib/lutaml/xml/schema/xsd/union.rb +30 -0
- data/lib/lutaml/xml/schema/xsd/unique.rb +31 -0
- data/lib/lutaml/xml/schema/xsd/validation_error.rb +48 -0
- data/lib/lutaml/xml/schema/xsd/validation_result.rb +86 -0
- data/lib/lutaml/xml/schema/xsd/version.rb +11 -0
- data/lib/lutaml/xml/schema/xsd/white_space.rb +27 -0
- data/lib/lutaml/xml/schema/xsd.rb +164 -0
- data/lib/lutaml/xml/schema/xsd_namespace.rb +29 -0
- data/lib/lutaml/xml/schema/xsd_schema.rb +1002 -0
- data/lib/lutaml/xml/schema.rb +16 -0
- data/lib/lutaml/xml/schema_location.rb +155 -0
- data/lib/lutaml/xml/serialization/collection_ext.rb +61 -0
- data/lib/lutaml/xml/serialization/format_conversion.rb +433 -0
- data/lib/lutaml/xml/serialization/instance_methods.rb +323 -0
- data/lib/lutaml/xml/serialization/model_import_ext.rb +40 -0
- data/lib/lutaml/xml/serialization.rb +15 -0
- data/lib/lutaml/xml/shared_dsl.rb +119 -0
- data/lib/lutaml/xml/transform.rb +6 -0
- data/lib/lutaml/xml/transformation/custom_method_wrapper.rb +258 -0
- data/lib/lutaml/xml/transformation/element_builder.rb +697 -0
- data/lib/lutaml/xml/transformation/order_reconciler.rb +282 -0
- data/lib/lutaml/xml/transformation/ordered_applier.rb +529 -0
- data/lib/lutaml/xml/transformation/rule_applier.rb +403 -0
- data/lib/lutaml/xml/transformation/rule_compiler.rb +556 -0
- data/lib/lutaml/xml/transformation/skip_logic.rb +70 -0
- data/lib/lutaml/xml/transformation/value_serializer.rb +137 -0
- data/lib/lutaml/xml/transformation.rb +454 -0
- data/lib/lutaml/xml/transformation_builder.rb +28 -0
- data/lib/lutaml/xml/transformation_support.rb +15 -0
- data/lib/lutaml/xml/type/configurable.rb +153 -0
- data/lib/lutaml/xml/type/serializers.rb +105 -0
- data/lib/lutaml/xml/type/value_xml_mapping.rb +94 -0
- data/lib/lutaml/xml/type_namespace/collector.rb +101 -0
- data/lib/lutaml/xml/type_namespace/declaration.rb +61 -0
- data/lib/lutaml/xml/type_namespace/planner.rb +121 -0
- data/lib/lutaml/xml/type_namespace/reference.rb +71 -0
- data/lib/lutaml/xml/type_namespace/resolver.rb +43 -0
- data/lib/lutaml/xml/type_namespace.rb +13 -0
- data/lib/lutaml/xml/type_namespace_resolver.rb +76 -0
- data/lib/lutaml/xml/unqualified_inheritance_strategy.rb +34 -0
- data/lib/lutaml/xml/w3c/registration.rb +66 -0
- data/lib/lutaml/xml/w3c.rb +398 -0
- data/lib/lutaml/xml/xml_attribute.rb +58 -0
- data/lib/lutaml/xml/xml_element.rb +498 -0
- data/lib/lutaml/xml/xml_namespace.rb +72 -0
- data/lib/lutaml/xml/xml_orderable.rb +17 -0
- data/lib/lutaml/xml/xsd_validator.rb +66 -0
- data/lib/lutaml/xml.rb +7 -0
- data/lib/lutaml/yaml/adapter/document.rb +12 -0
- data/lib/lutaml/yaml/adapter/mapping.rb +17 -0
- data/lib/lutaml/yaml/adapter/mapping_rule.rb +9 -0
- data/lib/lutaml/yaml/adapter/standard_adapter.rb +35 -0
- data/lib/lutaml/yaml/adapter/transform.rb +9 -0
- data/lib/lutaml/yaml/adapter/yeptris_adapter.rb +107 -0
- data/lib/lutaml/yaml/adapter.rb +18 -0
- data/lib/lutaml/yaml/format.rb +31 -0
- data/lib/lutaml/yaml/schema/yaml_schema.rb +65 -0
- data/lib/lutaml/yaml/schema.rb +9 -0
- data/lib/lutaml/yaml/type/serializers.rb +60 -0
- data/lib/lutaml/yaml.rb +7 -0
- data/lib/lutaml/yamlld/adapter.rb +20 -0
- data/lib/lutaml/yamlld.rb +25 -0
- data/lib/lutaml/yamls/adapter/document.rb +14 -0
- data/lib/lutaml/yamls/adapter/mapping.rb +30 -0
- data/lib/lutaml/yamls/adapter/mapping_rule.rb +9 -0
- data/lib/lutaml/yamls/adapter/standard_adapter.rb +56 -0
- data/lib/lutaml/yamls/adapter/transform.rb +124 -0
- data/lib/lutaml/yamls/adapter/yamls_sequence.rb +20 -0
- data/lib/lutaml/yamls/adapter/yamls_sequence_rule.rb +48 -0
- data/lib/lutaml/yamls/adapter.rb +15 -0
- data/lib/lutaml/yamls/format.rb +22 -0
- data/lib/lutaml/yamls.rb +7 -0
- data/lib/lutaml.rb +11 -5
- data/lib/tasks/benchmark_runner.rb +161 -0
- data/lib/tasks/memory_profile.rb +176 -0
- data/lib/tasks/performance.rake +80 -0
- data/lib/tasks/performance_benchmark.rb +499 -0
- data/lib/tasks/performance_comparator.rb +130 -0
- data/lib/tasks/performance_helpers.rb +149 -0
- data/lib/tasks/performance_probe.rake +33 -0
- data/lib/tasks/performance_probe.rb +106 -0
- data/lib/tasks/performance_probe_plan_walk.rb +58 -0
- data/lib/tasks/performance_probe_xml.rb +54 -0
- data/lib/tasks/xml_compiler_benchmark.rb +226 -0
- data/lib/tasks/xml_optimization_benchmark.rb +178 -0
- data/lutaml.gemspec +16 -8
- metadata +902 -83
- data/.github/workflows/docs.yml +0 -86
- data/.github/workflows/links.yml +0 -113
- data/.github/workflows/rake.yml +0 -23
- data/.github/workflows/release.yml +0 -37
- data/.gitignore +0 -29
- data/CLAUDE.md +0 -62
- data/docs/.github/workflows/docs.yml +0 -66
- data/docs/.github/workflows/links.yml +0 -78
- data/docs/CONTINUATION_PLAN.md +0 -168
- data/docs/Gemfile +0 -13
- data/docs/MIGRATION_GUIDE.md +0 -202
- data/docs/README.md +0 -252
- data/docs/REFACTOR_PLAN.md +0 -214
- data/docs/_config.yml +0 -144
- data/docs/_guides/cli-usage.adoc +0 -43
- data/docs/_guides/diagram-generation.adoc +0 -316
- data/docs/_guides/index.adoc +0 -136
- data/docs/_guides/parsing/express-parsing.adoc +0 -42
- data/docs/_guides/parsing/index.adoc +0 -78
- data/docs/_guides/parsing/qea-parsing.adoc +0 -47
- data/docs/_guides/parsing/xmi-parsing.adoc +0 -40
- data/docs/_guides/repository-management.adoc +0 -44
- data/docs/_guides/sysml-modeling.adoc +0 -37
- data/docs/_guides/uml-modeling.adoc +0 -115
- data/docs/_pages/concepts/diagram-generation.adoc +0 -337
- data/docs/_pages/concepts/lur-format.adoc +0 -711
- data/docs/_pages/concepts/qea-parsing.adoc +0 -418
- data/docs/_pages/concepts/uml-models.adoc +0 -43
- data/docs/_pages/core/architecture.adoc +0 -329
- data/docs/_pages/core/installation.adoc +0 -321
- data/docs/_pages/core/overview.adoc +0 -197
- data/docs/_pages/index.adoc +0 -49
- data/docs/_pages/uml-syntax.adoc +0 -1011
- data/docs/_references/api/parsers.adoc +0 -61
- data/docs/_references/api/presenters.adoc +0 -43
- data/docs/_references/api/repository.adoc +0 -67
- data/docs/_references/cli/commands.adoc +0 -72
- data/docs/_references/configuration/diagram-styles.adoc +0 -716
- data/docs/_references/configuration/index.adoc +0 -53
- data/docs/_references/configuration/package-metadata.adoc +0 -416
- data/docs/_references/formats/index.adoc +0 -43
- data/docs/_references/formats/lur-format.adoc +0 -39
- data/docs/_references/formats/lutaml-syntax.adoc +0 -379
- data/docs/_references/formats/qea-structure.adoc +0 -1364
- data/docs/_references/index.adoc +0 -198
- data/docs/_tutorials/documentation-site.adoc +0 -47
- data/docs/_tutorials/first-lur-package.adoc +0 -45
- data/docs/_tutorials/generating-diagrams.adoc +0 -42
- data/docs/_tutorials/getting-started.adoc +0 -45
- data/docs/_tutorials/index.adoc +0 -100
- data/docs/_tutorials/querying-models.adoc +0 -44
- data/docs/examples/build_package.rb +0 -12
- data/docs/examples/build_site.rb +0 -12
- data/docs/examples/city_model.rb +0 -21
- data/docs/examples/present_class.rb +0 -10
- data/docs/examples/query_model.rb +0 -12
- data/docs/examples/render_diagram.rb +0 -11
- data/docs/index.adoc +0 -64
- data/docs/lychee.toml +0 -50
- data/lib/lutaml/express/parsers/exp.rb +0 -28
- data/lib/lutaml/express.rb +0 -10
- data/scripts/check-site-urls.rb +0 -54
- data/scripts/check-vendor-link.py +0 -64
|
@@ -0,0 +1,1824 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Xml
|
|
5
|
+
# ModelTransform is the XML transform handler for the model layer.
|
|
6
|
+
# It inherits from Lutaml::Model::Transform and implements XML-specific
|
|
7
|
+
# data_to_model and model_to_data methods.
|
|
8
|
+
#
|
|
9
|
+
# This class bridges the model layer and the XML module:
|
|
10
|
+
# - Inherits from Lutaml::Model::Transform (model's format-agnostic base)
|
|
11
|
+
# - Delegates to Lutaml::Xml::Transformation for actual XML serialization
|
|
12
|
+
# - Used by model's serialization pipeline via Transform.for(:xml)
|
|
13
|
+
#
|
|
14
|
+
class ModelTransform < ::Lutaml::Model::Transform
|
|
15
|
+
require "cgi" unless Lutaml::Model.opal?
|
|
16
|
+
|
|
17
|
+
# Per (model class, register): compiled records for the mapping
|
|
18
|
+
# rules — attribute, derived/valid flags, and #765 group-skip —
|
|
19
|
+
# keyed on the mapping's finalize version so late changes rebuild.
|
|
20
|
+
# The loop body used to re-derive these per parsed instance.
|
|
21
|
+
# Concurrent::Map under threaded MRI, plain Hash under Opal
|
|
22
|
+
# (Concurrent is unavailable there); class identity keys either.
|
|
23
|
+
# Concurrent is required here (not at boot) so its first load never
|
|
24
|
+
# happens inside RubyGems' unresolved-tree resolution (see
|
|
25
|
+
# TransformationRegistry#initialize).
|
|
26
|
+
RULE_RECORDS = if Lutaml::Model.opal?
|
|
27
|
+
{}
|
|
28
|
+
else
|
|
29
|
+
Lutaml::Model::RuntimeCompatibility
|
|
30
|
+
.require_native("concurrent")
|
|
31
|
+
Concurrent::Map.new # rubocop:disable Lint/HashCompareByIdentity
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Namespaced rule name -> [local_name, rule_uri]. Pure string
|
|
35
|
+
# splitting, deterministic per spelling, shared across parses.
|
|
36
|
+
# Concurrent::Map under threaded MRI, plain Hash under Opal.
|
|
37
|
+
NAMESPACED_NAME_PARTS = if Lutaml::Model.opal?
|
|
38
|
+
{}
|
|
39
|
+
else
|
|
40
|
+
Lutaml::Model::RuntimeCompatibility.require_native("concurrent")
|
|
41
|
+
Concurrent::Map.new
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Rule name -> its local suffix after the last colon. The
|
|
45
|
+
# cross-namespace fallback probes this suffix per rule name per
|
|
46
|
+
# child per element (11M substring mints on a 2M-node parse);
|
|
47
|
+
# the suffix is static per spelling, so it is shared here with
|
|
48
|
+
# the same backing as NAMESPACED_NAME_PARTS.
|
|
49
|
+
RULE_LOCAL_NAMES = if Lutaml::Model.opal?
|
|
50
|
+
{}
|
|
51
|
+
else
|
|
52
|
+
Lutaml::Model::RuntimeCompatibility.require_native("concurrent")
|
|
53
|
+
Concurrent::Map.new
|
|
54
|
+
end
|
|
55
|
+
include NestedCollectionAttribute
|
|
56
|
+
|
|
57
|
+
# Performance: Frozen empty hash to reduce allocations
|
|
58
|
+
EMPTY_HASH = {}.freeze
|
|
59
|
+
|
|
60
|
+
# ":".getbyte(0) — getbyte comparisons avoid the per-candidate
|
|
61
|
+
# string slice in namespace-prefix checks on the lenient paths.
|
|
62
|
+
COLON_BYTE = 58
|
|
63
|
+
|
|
64
|
+
def data_to_model(data, _format, options = {})
|
|
65
|
+
# Use child's own default register if it has one
|
|
66
|
+
# This ensures versioned schemas (e.g., MML v2 with lutaml_default_register = :mml_v2)
|
|
67
|
+
# are instantiated with their native context
|
|
68
|
+
# TODO.max-perf/32: constant per (model class, register) — the
|
|
69
|
+
# transform itself is cached per that pair, so resolve once.
|
|
70
|
+
child_register = @xml_child_register ||= Lutaml::Model::Register
|
|
71
|
+
.resolve_for_child(
|
|
72
|
+
model_class, lutaml_register
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
instance_is_serialize = model_class.include?(::Lutaml::Model::Serialize)
|
|
76
|
+
if instance_is_serialize
|
|
77
|
+
# TODO.max-perf/17: the same child element was being re-hydrated
|
|
78
|
+
# per matching rule (593k instantiations for 12k elements on the
|
|
79
|
+
# ISO-13849 profile). Memoize one instance per (element, class)
|
|
80
|
+
# for the whole parse; the memo travels in the propagated
|
|
81
|
+
# deserialization options.
|
|
82
|
+
# Nested identity maps keyed on the element object itself —
|
|
83
|
+
# flat object_id pairs could collide after GC id reuse on
|
|
84
|
+
# long parses (#808 audit).
|
|
85
|
+
memo = options[:__lutaml_child_memo] ||= {}.compare_by_identity
|
|
86
|
+
per_class = (memo[data] ||= {}.compare_by_identity)
|
|
87
|
+
if (existing = per_class[model_class])
|
|
88
|
+
return existing
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
instance = model_class.allocate_for_deserialization(child_register)
|
|
92
|
+
per_class[model_class] = instance
|
|
93
|
+
else
|
|
94
|
+
instance = model_class.new
|
|
95
|
+
register_accessor_methods_for(instance, child_register)
|
|
96
|
+
end
|
|
97
|
+
# Set @__xml_namespace_prefix on root model for doubly-defined namespace support.
|
|
98
|
+
# This is read during serialization to determine if the root element should use
|
|
99
|
+
# an explicit prefix from the input XML.
|
|
100
|
+
# Check the XmlElement's namespace_prefix (not the model's):
|
|
101
|
+
# - Nil/empty: root uses default format (doubly-defined case)
|
|
102
|
+
# - Set: root has explicit prefix (mixed content case)
|
|
103
|
+
root_element = if data.is_a?(::Lutaml::Xml::XmlElement)
|
|
104
|
+
data
|
|
105
|
+
else
|
|
106
|
+
data.root
|
|
107
|
+
end
|
|
108
|
+
if root_element && instance_is_serialize
|
|
109
|
+
root_ns_prefix = if root_element.namespace_prefix_explicit && root_element.namespace_prefix
|
|
110
|
+
root_element.namespace_prefix
|
|
111
|
+
else
|
|
112
|
+
root_element.xml_namespace_prefix
|
|
113
|
+
end
|
|
114
|
+
if root_ns_prefix && !root_ns_prefix.empty?
|
|
115
|
+
instance.xml_namespace_prefix = root_ns_prefix
|
|
116
|
+
end
|
|
117
|
+
# Track original namespace URI for namespace alias support.
|
|
118
|
+
#
|
|
119
|
+
# When root element's namespace URI differs from the model's canonical URI,
|
|
120
|
+
# it's an alias that should be preserved during serialization.
|
|
121
|
+
root_ns_uri = root_element.namespace_uri
|
|
122
|
+
if root_ns_uri
|
|
123
|
+
model_ns_class = instance.class.mappings_for(:xml)&.namespace_class
|
|
124
|
+
if model_ns_class && model_ns_class.uri != root_ns_uri
|
|
125
|
+
# root_ns_uri differs from canonical - preserve it (alias or other)
|
|
126
|
+
instance.original_namespace_uri = root_ns_uri
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# Namespace declaration plan for round-trip fidelity.
|
|
131
|
+
# Only needed for root elements (no lutaml_parent in options).
|
|
132
|
+
# Three modes: :lazy (default), :eager, :skip.
|
|
133
|
+
if !options.key?(:lutaml_parent)
|
|
134
|
+
# Default :eager — the plan data is tiny, but :lazy pins the
|
|
135
|
+
# adapter root element on every parsed instance, which keeps the
|
|
136
|
+
# entire native DOM (moxml wrappers + engine nodes) alive until
|
|
137
|
+
# first serialization. Models that are never serialized retain
|
|
138
|
+
# the DOM forever: a 10.5MB XMI held 578MB of wrappers this
|
|
139
|
+
# way. :lazy remains available for parse-serialize-immediately
|
|
140
|
+
# workflows that want to skip the namespace walk.
|
|
141
|
+
plan_mode = options.fetch(:import_declaration_plan, :eager)
|
|
142
|
+
case plan_mode
|
|
143
|
+
when :skip
|
|
144
|
+
# Skip plan building entirely (fastest)
|
|
145
|
+
when :eager
|
|
146
|
+
input_declaration_plan = build_input_declaration_plan(root_element)
|
|
147
|
+
instance.import_declaration_plan = input_declaration_plan if input_declaration_plan
|
|
148
|
+
when :lazy
|
|
149
|
+
# Store element reference for lazy plan building on first to_xml.
|
|
150
|
+
# No recursive walk during deserialization — plan is built on demand.
|
|
151
|
+
# Element reference is released after first serialization.
|
|
152
|
+
instance.pending_plan_root_element = root_element
|
|
153
|
+
else
|
|
154
|
+
raise ArgumentError,
|
|
155
|
+
"import_declaration_plan must be :eager, :lazy, or :skip, got #{plan_mode.inspect}"
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
root_and_parent_assignment(instance, options)
|
|
160
|
+
apply_xml_mapping(ParseSession.new(data, instance, options,
|
|
161
|
+
child_register))
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
# Build a DeclarationPlan from the parsed element tree's namespace declarations.
|
|
165
|
+
#
|
|
166
|
+
# Walks the entire element tree to capture ALL xmlns declarations from input XML,
|
|
167
|
+
# including unused ones (like xmlns:xi for XInclude) and declarations on child elements.
|
|
168
|
+
# The plan preserves WHERE each namespace was declared and its original format/URI.
|
|
169
|
+
#
|
|
170
|
+
# @param root_element [XmlElement] The parsed root element
|
|
171
|
+
# @return [DeclarationPlan, nil] The plan or nil if no namespaces
|
|
172
|
+
def build_input_declaration_plan(root_element)
|
|
173
|
+
return nil unless root_element
|
|
174
|
+
|
|
175
|
+
# Walk the element tree collecting namespaces with their declaration locations
|
|
176
|
+
namespaces_with_locations = collect_element_namespaces(root_element)
|
|
177
|
+
return nil if namespaces_with_locations.nil? || namespaces_with_locations.empty?
|
|
178
|
+
|
|
179
|
+
# Get the mapping for namespace resolution
|
|
180
|
+
xml_mapping = mappings_for(:xml)
|
|
181
|
+
|
|
182
|
+
# Create location-aware DeclarationPlan
|
|
183
|
+
DeclarationPlan.from_input_with_locations(namespaces_with_locations,
|
|
184
|
+
xml_mapping)
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
# Recursively collect namespace declarations from all elements in the tree.
|
|
188
|
+
#
|
|
189
|
+
# Each element may declare namespaces via xmlns attributes. The path array tracks
|
|
190
|
+
# the element names from root to current element. Root has path [], its children
|
|
191
|
+
# have path ["childName"], etc. This matches DeclarationPlan.from_input_with_locations
|
|
192
|
+
# expectations where root path is [] and child paths are built by appending.
|
|
193
|
+
#
|
|
194
|
+
# @param element [XmlElement] The element to collect from
|
|
195
|
+
# Recursively collect namespace declarations from all elements in the tree.
|
|
196
|
+
#
|
|
197
|
+
# Each element may declare namespaces via xmlns attributes. The path array tracks
|
|
198
|
+
# the element names from root to current element. Root has path [], its children
|
|
199
|
+
# have path ["childName"], etc. This matches DeclarationPlan.from_input_with_locations
|
|
200
|
+
# expectations where root path is [] and child paths are built by appending.
|
|
201
|
+
#
|
|
202
|
+
# Available as both class method (for lazy plan building from instance context)
|
|
203
|
+
# and instance method (for use within ModelTransform).
|
|
204
|
+
#
|
|
205
|
+
# @param element [XmlElement] The element to collect from
|
|
206
|
+
# @param path [Array<String>] Element path from root (empty for root element)
|
|
207
|
+
# @param result [Hash] Accumulated result { path_array => { key => { uri:, prefix:, format: } } }
|
|
208
|
+
# @param visited [Set] Set of visited element object_ids to prevent cycles
|
|
209
|
+
# @return [Hash] { [path_array] => { key => { uri:, prefix:, format: } } }
|
|
210
|
+
def self.collect_element_namespaces(element, path = [], result = nil,
|
|
211
|
+
visited = nil)
|
|
212
|
+
result ||= {}
|
|
213
|
+
visited ||= Set.new
|
|
214
|
+
return result unless element
|
|
215
|
+
return result if visited.include?(element.object_id)
|
|
216
|
+
|
|
217
|
+
visited.add(element.object_id)
|
|
218
|
+
|
|
219
|
+
# Collect this element's own namespace declarations
|
|
220
|
+
own_ns = element.own_namespaces
|
|
221
|
+
if own_ns&.any?
|
|
222
|
+
input_namespaces = {}
|
|
223
|
+
own_ns.each do |prefix, ns_data|
|
|
224
|
+
key = prefix.nil? ? :default : prefix
|
|
225
|
+
input_namespaces[key] = {
|
|
226
|
+
uri: ns_data.uri,
|
|
227
|
+
prefix: prefix,
|
|
228
|
+
format: prefix.nil? ? :default : :prefix,
|
|
229
|
+
}
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
# The path array is shared and mutated during the descent;
|
|
233
|
+
# snapshot it as a result key only where a declaration lives.
|
|
234
|
+
result[path.dup] = input_namespaces unless input_namespaces.empty?
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
# Recurse into children with path extended by child local name
|
|
238
|
+
# Use local name (without prefix) since serialization lookup uses
|
|
239
|
+
# xml_element.name which is the local name without namespace prefix
|
|
240
|
+
element.children.each do |child|
|
|
241
|
+
next if child.is_a?(String) # Skip text nodes
|
|
242
|
+
|
|
243
|
+
# Strip namespace prefix if present (e.g., "c:childName" -> "childName")
|
|
244
|
+
# to match the key format used during serialization lookup
|
|
245
|
+
full_name = child.name.to_s
|
|
246
|
+
child_local_name = if full_name.include?(":")
|
|
247
|
+
full_name.split(":",
|
|
248
|
+
2).last
|
|
249
|
+
else
|
|
250
|
+
full_name
|
|
251
|
+
end
|
|
252
|
+
path.push(child_local_name)
|
|
253
|
+
collect_element_namespaces(child, path, result, visited)
|
|
254
|
+
path.pop
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
result
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
# Instance method delegates to class method
|
|
261
|
+
def collect_element_namespaces(...)
|
|
262
|
+
self.class.collect_element_namespaces(...)
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
def model_to_data(model, _format, options = {})
|
|
266
|
+
# Check if model class has a pre-compiled transformation
|
|
267
|
+
model_class = model.class
|
|
268
|
+
if model_class.is_a?(Class) && model_class.include?(::Lutaml::Model::Serialize)
|
|
269
|
+
transformation = model_class.transformation_for(
|
|
270
|
+
:xml, lutaml_register, mapping: @lutaml_mapping_override
|
|
271
|
+
)
|
|
272
|
+
|
|
273
|
+
# If transformation exists and is an Xml::Transformation, use it
|
|
274
|
+
if transformation.is_a?(::Lutaml::Xml::Transformation)
|
|
275
|
+
return transformation.transform(model, options)
|
|
276
|
+
end
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
# Fallback to returning model for classes without transformation
|
|
280
|
+
model
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
private
|
|
284
|
+
|
|
285
|
+
def apply_xml_mapping(session)
|
|
286
|
+
doc = session.doc
|
|
287
|
+
instance = session.instance
|
|
288
|
+
options = session.options
|
|
289
|
+
effective_register = session.register
|
|
290
|
+
instance_is_serialize = session.instance_is_serialize
|
|
291
|
+
|
|
292
|
+
# Performance: Resolve xml_mapping once — used for both rules and metadata
|
|
293
|
+
# An explicit mapping (#176 profiles) governs the rules and the
|
|
294
|
+
# metadata alike; its own catch-all rule applies.
|
|
295
|
+
xml_mapping = options[:mappings] || mappings_for(:xml, effective_register)
|
|
296
|
+
mappings = xml_mapping.mappings(effective_register)
|
|
297
|
+
# Catch-all rule (map_any_element): iterated like any other,
|
|
298
|
+
# claiming every child no explicit rule matches. Skipped when
|
|
299
|
+
# absent — the unconditional array concat minted one fresh
|
|
300
|
+
# Array per hydrated instance against the frozen cached list.
|
|
301
|
+
catch_all = xml_mapping.any_element_rule
|
|
302
|
+
mappings = mappings + [catch_all] if catch_all
|
|
303
|
+
default_namespace = options[:default_namespace]
|
|
304
|
+
ordered_option = options[:ordered]
|
|
305
|
+
mixed_content_option = options[:mixed_content]
|
|
306
|
+
encoding = options[:encoding]
|
|
307
|
+
doctype = options[:doctype]
|
|
308
|
+
|
|
309
|
+
instance.encoding = encoding
|
|
310
|
+
instance.doctype = doctype if doctype
|
|
311
|
+
|
|
312
|
+
# Transfer XML declaration info if present (Issue #1)
|
|
313
|
+
if (xml_decl = doc.xml_declaration)
|
|
314
|
+
instance.xml_declaration = xml_decl
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
return instance unless doc
|
|
318
|
+
|
|
319
|
+
validate_document!(doc, options)
|
|
320
|
+
|
|
321
|
+
set_instance_ordering(instance, doc, ordered_option,
|
|
322
|
+
mixed_content_option, xml_mapping,
|
|
323
|
+
instance_is_serialize)
|
|
324
|
+
set_schema_location(instance, doc, xml_mapping, effective_register)
|
|
325
|
+
|
|
326
|
+
defaults_used = []
|
|
327
|
+
|
|
328
|
+
# Performance: Get namespace_uri once if needed for default_namespace
|
|
329
|
+
namespace_uri = xml_mapping&.namespace_uri
|
|
330
|
+
|
|
331
|
+
# Performance: Pre-build Set of child namespaced names for fast rule matching.
|
|
332
|
+
# This allows skipping value_for_rule for ~91% of rules that have no matching child.
|
|
333
|
+
child_names_set = nil
|
|
334
|
+
if doc.is_a?(::Lutaml::Xml::XmlElement) || doc.is_a?(::Lutaml::Xml::Document)
|
|
335
|
+
ec = doc.element_children
|
|
336
|
+
unless ec.empty?
|
|
337
|
+
child_names_set = Set.new
|
|
338
|
+
ec.each do |child|
|
|
339
|
+
child_names_set.add(child.namespaced_name)
|
|
340
|
+
child_names_set.add(child.unprefixed_name)
|
|
341
|
+
end
|
|
342
|
+
end
|
|
343
|
+
end
|
|
344
|
+
|
|
345
|
+
# lutaml-model#765: several plain element rules may target one
|
|
346
|
+
# collection attribute (spelling tolerance, e.g. editorial-group vs
|
|
347
|
+
# editorialgroup). The first rule of such a group performs matching
|
|
348
|
+
# widened to every spelling so content merges in document order;
|
|
349
|
+
# the remaining rules are no-ops so their assignment cannot
|
|
350
|
+
# silently overwrite the merged value.
|
|
351
|
+
# Grouping is cached on the mapping DSL (per register); only the
|
|
352
|
+
# collection filter runs here.
|
|
353
|
+
grouped_plain_rules = xml_mapping.plain_element_rules_by_attr(
|
|
354
|
+
effective_register,
|
|
355
|
+
)
|
|
356
|
+
|
|
357
|
+
serializable = instance.class.include?(Lutaml::Model::Serialize)
|
|
358
|
+
records = if serializable
|
|
359
|
+
compiled_rule_records(instance.class, effective_register,
|
|
360
|
+
grouped_plain_rules)
|
|
361
|
+
end
|
|
362
|
+
# Loop invariants: the entity-decode flag is a per-(class, register)
|
|
363
|
+
# fact and the attributes hash is memoized per register — both were
|
|
364
|
+
# re-asked per rule application (942k + 751k calls per ISO-13849
|
|
365
|
+
# parse).
|
|
366
|
+
decode_entities_flag = decode_html_entities_for(instance,
|
|
367
|
+
effective_register)
|
|
368
|
+
deserialize_attributes = attributes
|
|
369
|
+
mappings.each do |rule|
|
|
370
|
+
record = records&.[](rule)
|
|
371
|
+
|
|
372
|
+
# #903/#922: replay-or-drop unmatched rules; never clobber
|
|
373
|
+
# a mid-parse custom-writer assignment.
|
|
374
|
+
next if replay_unmatched_rule(child_names_set, record, rule,
|
|
375
|
+
instance, defaults_used,
|
|
376
|
+
xml_mapping)
|
|
377
|
+
|
|
378
|
+
rule_to = rule.to
|
|
379
|
+
|
|
380
|
+
if record
|
|
381
|
+
attr = record.attr
|
|
382
|
+
next if record.derived
|
|
383
|
+
next if record.group_skip
|
|
384
|
+
|
|
385
|
+
raise "Attribute '#{rule_to}' not found in #{context}" unless record.valid
|
|
386
|
+
else
|
|
387
|
+
attr = attribute_for_rule(rule)
|
|
388
|
+
next if attr&.derived?
|
|
389
|
+
|
|
390
|
+
group = grouped_plain_rules[rule_to]
|
|
391
|
+
next if group && group.size > 1 && attr&.collection? &&
|
|
392
|
+
!group.first.equal?(rule)
|
|
393
|
+
|
|
394
|
+
raise "Attribute '#{rule_to}' not found in #{context}" unless valid_rule?(
|
|
395
|
+
rule, attr
|
|
396
|
+
)
|
|
397
|
+
end
|
|
398
|
+
|
|
399
|
+
# Performance: Use pre-computed frozen Hash for static namespace overrides.
|
|
400
|
+
# Falls back to per-element hash only for the dynamic namespace_uri case.
|
|
401
|
+
new_opts = rule.static_namespace_option ||
|
|
402
|
+
if default_namespace.nil? && namespace_uri
|
|
403
|
+
{ default_namespace: namespace_uri }
|
|
404
|
+
else
|
|
405
|
+
options
|
|
406
|
+
end
|
|
407
|
+
|
|
408
|
+
value = if !rule.attribute? && rule.name.nil? &&
|
|
409
|
+
xml_mapping.any_element_rule.equal?(rule)
|
|
410
|
+
# map_any_element: every child element no explicit
|
|
411
|
+
# element rule claims, in document order (claimed
|
|
412
|
+
# set + scalar text extraction live in
|
|
413
|
+
# any_element_members). A name-less MappingRule is
|
|
414
|
+
# otherwise indistinguishable from a content rule;
|
|
415
|
+
# name-derived lookup re-finds by name, losing
|
|
416
|
+
# order and double-picking.
|
|
417
|
+
any_element_members(
|
|
418
|
+
doc, xml_mapping, attr, effective_register
|
|
419
|
+
)
|
|
420
|
+
elsif rule.raw_mapping?
|
|
421
|
+
scoped_raw_inner_xml(doc, xml_mapping)
|
|
422
|
+
elsif rule.content_mapping?
|
|
423
|
+
rule.cdata ? doc.cdata : doc.text
|
|
424
|
+
elsif (group = grouped_plain_rules[rule_to]) &&
|
|
425
|
+
group.size > 1 && attr&.collection?
|
|
426
|
+
# First rule of a #765 group: match every spelling of
|
|
427
|
+
# the group so the children merge in document order.
|
|
428
|
+
raise "GROUPED-BODY" if ENV["CATCHDBG"] && rule.name.nil?
|
|
429
|
+
|
|
430
|
+
if child_names_set &&
|
|
431
|
+
group.drop(1).none? do |s|
|
|
432
|
+
child_matches_rule?(s, child_names_set,
|
|
433
|
+
default_namespace)
|
|
434
|
+
end && !child_matches_rule?(rule, child_names_set,
|
|
435
|
+
default_namespace)
|
|
436
|
+
::Lutaml::Model::UninitializedClass.instance
|
|
437
|
+
else
|
|
438
|
+
extra_names = group.drop(1).flat_map do |s|
|
|
439
|
+
resolve_rule_names_with_type(s, attr, new_opts,
|
|
440
|
+
effective_register,
|
|
441
|
+
attr&.type(effective_register))
|
|
442
|
+
end
|
|
443
|
+
value_for_rule(session, rule, new_opts, attr,
|
|
444
|
+
extra_names)
|
|
445
|
+
end
|
|
446
|
+
elsif child_names_set && !rule.attribute? && rule.name &&
|
|
447
|
+
!child_matches_rule?(rule, child_names_set,
|
|
448
|
+
default_namespace)
|
|
449
|
+
raise "FASTSKIP-BODY" if ENV["CATCHDBG"] && rule.name.nil?
|
|
450
|
+
|
|
451
|
+
# Pre-match: no child element matches this rule.
|
|
452
|
+
# Skip expensive value_for_rule, handle defaults inline.
|
|
453
|
+
# NOTE: do not "read the instance" here (to_value_for) —
|
|
454
|
+
# the compiled getters materialize lazy collections on
|
|
455
|
+
# first read, which tripled parse allocations when tried.
|
|
456
|
+
if writer_populated?(record, instance)
|
|
457
|
+
instance.value_set_for(rule_to)
|
|
458
|
+
next
|
|
459
|
+
end
|
|
460
|
+
if instance.using_default?(rule_to) || rule.render_default
|
|
461
|
+
defaults_used << rule_to
|
|
462
|
+
attr&.default(effective_register) || rule.to_value_for(instance)
|
|
463
|
+
else
|
|
464
|
+
# The attribute already holds an explicit value --
|
|
465
|
+
# assigned by a matched rule or by a custom writer
|
|
466
|
+
# mid-parse (lutaml-model#922). An unmatched rule
|
|
467
|
+
# must not overwrite it with nil.
|
|
468
|
+
next
|
|
469
|
+
end
|
|
470
|
+
else
|
|
471
|
+
raise "ELSE-BODY" if ENV["CATCHDBG"] && rule.name.nil?
|
|
472
|
+
|
|
473
|
+
# Performance: Pass cached attr to avoid recomputing attribute_for_rule
|
|
474
|
+
val = value_for_rule(session, rule, new_opts, attr)
|
|
475
|
+
|
|
476
|
+
if (val.nil? || ::Lutaml::Model::Utils.uninitialized?(val)) &&
|
|
477
|
+
(instance.using_default?(rule_to) || rule.render_default)
|
|
478
|
+
defaults_used << rule_to
|
|
479
|
+
attr&.default(effective_register) || rule.to_value_for(instance)
|
|
480
|
+
else
|
|
481
|
+
val
|
|
482
|
+
end
|
|
483
|
+
end
|
|
484
|
+
|
|
485
|
+
# Performance: Skip post-processing for truly omitted rules.
|
|
486
|
+
# Only skip when value_map would keep UninitializedClass (treat_omitted == :omitted)
|
|
487
|
+
# AND no defaults are needed. Rules with treat_omitted: :nil still need processing.
|
|
488
|
+
if ::Lutaml::Model::Utils.uninitialized?(value) &&
|
|
489
|
+
!rule.treat_omitted?(new_opts) &&
|
|
490
|
+
!rule.render_default &&
|
|
491
|
+
!instance.using_default?(rule_to)
|
|
492
|
+
next
|
|
493
|
+
end
|
|
494
|
+
|
|
495
|
+
from_map = rule.value_map(:from, new_opts)
|
|
496
|
+
value = apply_value_map(value, from_map, attr)
|
|
497
|
+
value = normalize_xml_value(value, rule, attr, new_opts,
|
|
498
|
+
effective_register)
|
|
499
|
+
value = decode_html_entities_value(value, decode_entities_flag)
|
|
500
|
+
value = rule.transform_value(attr, value, :from, :xml)
|
|
501
|
+
# An over-count is normally left for `.validate` to report. A mapped
|
|
502
|
+
# PORO has no `.validate`, so deferring there would discard the
|
|
503
|
+
# violation entirely — check it while there is still someone to tell.
|
|
504
|
+
if !instance_is_serialize && attr && !attr.collection? &&
|
|
505
|
+
!rule.content_mapping?
|
|
506
|
+
# singular_tolerance: :first collapses an over-ingested
|
|
507
|
+
# collection to its leading value before the writer sees it
|
|
508
|
+
# (#971) — the reduced scalar then flows through
|
|
509
|
+
# deserialize and serializes as a single element.
|
|
510
|
+
value = value.first if attr.tolerates_singular_overflow?(value)
|
|
511
|
+
attr.valid_collection!(value, context)
|
|
512
|
+
end
|
|
513
|
+
rule.deserialize(instance, value, deserialize_attributes, context,
|
|
514
|
+
options[:context])
|
|
515
|
+
|
|
516
|
+
instance.value_set_for(rule_to)
|
|
517
|
+
end
|
|
518
|
+
|
|
519
|
+
defaults_used.each do |attr_name|
|
|
520
|
+
instance.using_default_for(attr_name)
|
|
521
|
+
end
|
|
522
|
+
|
|
523
|
+
apply_processing_instruction_deserialization(doc, instance, xml_mapping,
|
|
524
|
+
effective_register)
|
|
525
|
+
|
|
526
|
+
apply_all_attributes_deserialization(doc, instance, xml_mapping)
|
|
527
|
+
|
|
528
|
+
run_consolidation(instance, effective_register, instance_is_serialize)
|
|
529
|
+
|
|
530
|
+
instance
|
|
531
|
+
end
|
|
532
|
+
|
|
533
|
+
# #1031: wildcard attribute families. After the explicit attribute
|
|
534
|
+
# rules have consumed their names, every remaining unprefixed
|
|
535
|
+
# attribute matching the rule's pattern lands in the target Hash —
|
|
536
|
+
# names claimed by explicit rules never leak into it.
|
|
537
|
+
def apply_all_attributes_deserialization(doc, instance, xml_mapping)
|
|
538
|
+
rule = xml_mapping.all_attributes_rule
|
|
539
|
+
return if rule.nil?
|
|
540
|
+
|
|
541
|
+
element = doc.is_a?(::Lutaml::Xml::XmlElement) ? doc : doc.root
|
|
542
|
+
return if element.nil?
|
|
543
|
+
|
|
544
|
+
claimed = attribute_names_claimed_by_rules(xml_mapping)
|
|
545
|
+
remainder = {}
|
|
546
|
+
element.attributes.each_value do |attr|
|
|
547
|
+
name = attr.unprefixed_name.to_s
|
|
548
|
+
next if claimed.include?(name)
|
|
549
|
+
next if rule.matching && !rule.matching.match?(name)
|
|
550
|
+
|
|
551
|
+
remainder[name] = attr.value
|
|
552
|
+
end
|
|
553
|
+
return if remainder.empty?
|
|
554
|
+
|
|
555
|
+
instance.public_send(:"#{rule.to}=", remainder)
|
|
556
|
+
instance.value_set_for(rule.to) if instance.is_a?(::Lutaml::Model::Serialize)
|
|
557
|
+
end
|
|
558
|
+
|
|
559
|
+
# Attribute names claimed by explicit map_attribute rules, plus the
|
|
560
|
+
# engine-handled schemaLocation (which renders through
|
|
561
|
+
# raw_schema_location, not the remainder).
|
|
562
|
+
def attribute_names_claimed_by_rules(xml_mapping)
|
|
563
|
+
names = %w[schemaLocation]
|
|
564
|
+
xml_mapping.mapping_attributes_hash.each_value do |rule_or_array|
|
|
565
|
+
Array(rule_or_array).each { |rule| names << rule.name.to_s }
|
|
566
|
+
end
|
|
567
|
+
names
|
|
568
|
+
end
|
|
569
|
+
|
|
570
|
+
def validate_document!(doc, options)
|
|
571
|
+
return unless doc.is_a?(Array)
|
|
572
|
+
|
|
573
|
+
raise ::Lutaml::Model::CollectionTrueMissingError(
|
|
574
|
+
context,
|
|
575
|
+
options[:caller_class],
|
|
576
|
+
)
|
|
577
|
+
end
|
|
578
|
+
|
|
579
|
+
def set_instance_ordering(instance, doc, ordered_option,
|
|
580
|
+
mixed_content_option, xml_mapping = nil,
|
|
581
|
+
instance_is_serialize = nil)
|
|
582
|
+
# #909: read-only consumers skip the per-instance order summaries
|
|
583
|
+
# entirely — element_order stays nil and to_xml falls back to
|
|
584
|
+
# mapping-defined order for untracked instances.
|
|
585
|
+
return unless Lutaml::Model::Config.instance.element_order_tracking
|
|
586
|
+
|
|
587
|
+
# dup: XmlElement#order hands back a frozen cache shared with the
|
|
588
|
+
# DOM. The model's copy has to stay mutable so callers can maintain
|
|
589
|
+
# element_order themselves.
|
|
590
|
+
instance.element_order = doc.root.order
|
|
591
|
+
if instance_is_serialize && doc.root.is_a?(::Lutaml::Xml::XmlElement)
|
|
592
|
+
instance.attribute_order = doc.root.attribute_order
|
|
593
|
+
end
|
|
594
|
+
|
|
595
|
+
# For Serialize instances, ordered?/mixed? delegate to class mapping.
|
|
596
|
+
# For non-Serialize model classes (model Id), @ordered/@mixed are needed
|
|
597
|
+
# as the fallback in InstanceMethods#ordered?/#mixed?.
|
|
598
|
+
if instance_is_serialize.nil?
|
|
599
|
+
instance_is_serialize = instance.is_a?(Lutaml::Model::Serialize)
|
|
600
|
+
end
|
|
601
|
+
unless instance_is_serialize
|
|
602
|
+
xml_mapping ||= mappings_for(:xml)
|
|
603
|
+
instance.ordered = xml_mapping.ordered? || ordered_option
|
|
604
|
+
instance.mixed = xml_mapping.mixed_content? || mixed_content_option
|
|
605
|
+
end
|
|
606
|
+
end
|
|
607
|
+
|
|
608
|
+
def set_schema_location(instance, doc, xml_mapping, register)
|
|
609
|
+
return if xml_mapping&.schema_location_mapped?(register)
|
|
610
|
+
|
|
611
|
+
schema_location = doc.attributes.values.find do |a|
|
|
612
|
+
a.unprefixed_name == "schemaLocation"
|
|
613
|
+
end
|
|
614
|
+
|
|
615
|
+
return if schema_location.nil?
|
|
616
|
+
|
|
617
|
+
# Store raw schemaLocation string as metadata
|
|
618
|
+
# SchemaLocation class is for programmatic creation with XmlNamespace classes only
|
|
619
|
+
# When parsing XML, we just preserve the string value as-is
|
|
620
|
+
instance.raw_schema_location = schema_location.value
|
|
621
|
+
end
|
|
622
|
+
|
|
623
|
+
def apply_processing_instruction_deserialization(doc, instance, xml_mapping,
|
|
624
|
+
_effective_register)
|
|
625
|
+
pi_mappings = xml_mapping.processing_instruction_mappings
|
|
626
|
+
return if pi_mappings.empty?
|
|
627
|
+
|
|
628
|
+
doc_pis = if doc.is_a?(::Lutaml::Xml::XmlElement)
|
|
629
|
+
doc.processing_instructions
|
|
630
|
+
elsif doc.is_a?(::Lutaml::Xml::Document)
|
|
631
|
+
doc.root.processing_instructions
|
|
632
|
+
else
|
|
633
|
+
[]
|
|
634
|
+
end || []
|
|
635
|
+
|
|
636
|
+
pi_attr = Lutaml::Xml::DataModel::XmlProcessingInstruction
|
|
637
|
+
|
|
638
|
+
pi_mappings.each do |pi_mapping|
|
|
639
|
+
matching_pis = doc_pis.select { |pi| pi.target == pi_mapping.target }
|
|
640
|
+
next if matching_pis.empty?
|
|
641
|
+
|
|
642
|
+
attr_def = attributes[pi_mapping.to]
|
|
643
|
+
|
|
644
|
+
value = if attr_def&.collection?
|
|
645
|
+
matching_pis.map(&:content)
|
|
646
|
+
else
|
|
647
|
+
result = {}
|
|
648
|
+
matching_pis.each do |pi|
|
|
649
|
+
parsed = pi_attr.parse_pseudo_attributes(pi.content)
|
|
650
|
+
result.merge!(parsed)
|
|
651
|
+
end
|
|
652
|
+
result.empty? ? nil : result
|
|
653
|
+
end
|
|
654
|
+
|
|
655
|
+
next if value.nil?
|
|
656
|
+
|
|
657
|
+
instance.public_send(:"#{pi_mapping.to}=", value)
|
|
658
|
+
instance.value_set_for(pi_mapping.to) if instance.is_a?(::Lutaml::Model::Serialize)
|
|
659
|
+
end
|
|
660
|
+
end
|
|
661
|
+
|
|
662
|
+
# Whether no OTHER attribute rule in the mapping claims the same
|
|
663
|
+
# local name. A sole claimant is namespace-flexible on the local-
|
|
664
|
+
# name fallback: real-world documents qualify such attributes in
|
|
665
|
+
# the element's namespace, a foreign extension namespace, or not
|
|
666
|
+
# at all (OOXML w:val on w15: elements — lutaml-model#790). When
|
|
667
|
+
# a sibling claims the name, matching stays strict so each rule
|
|
668
|
+
# keeps its own namespace (#744, #758).
|
|
669
|
+
def attribute_rule_sole_local_claimant?(instance, rule,
|
|
670
|
+
effective_register)
|
|
671
|
+
klass = instance.class
|
|
672
|
+
return true unless klass.include?(Lutaml::Model::Serialize)
|
|
673
|
+
|
|
674
|
+
mapping = klass.mappings_for(:xml, effective_register)
|
|
675
|
+
return true unless mapping
|
|
676
|
+
|
|
677
|
+
mapping.sole_local_attribute_claimant?(rule, effective_register)
|
|
678
|
+
end
|
|
679
|
+
|
|
680
|
+
def value_for_xml_attribute(doc, rule, rule_names,
|
|
681
|
+
flexible_local: false, session: nil)
|
|
682
|
+
# For attributes, rule_names may contain namespaced names, but find_attribute_value
|
|
683
|
+
# expects prefix:name or just name, so we need to convert namespaced names to prefix format.
|
|
684
|
+
#
|
|
685
|
+
# Namespaced name formats:
|
|
686
|
+
# - URI format: "http://.../namespace:attr" or "urn:...:attr"
|
|
687
|
+
# - Simple prefix format: "my-ns:attr" (namespace URI is a simple string, not a URI)
|
|
688
|
+
# - Unprefixed: "attr" (no namespace)
|
|
689
|
+
# Performance: most rules carry a single name — skip the map and
|
|
690
|
+
# its result array entirely on that path.
|
|
691
|
+
if rule_names.size == 1
|
|
692
|
+
rn = rule_names[0]
|
|
693
|
+
converted = convert_rule_name_to_attribute_name(doc, rn,
|
|
694
|
+
session: session)
|
|
695
|
+
value = doc.root.find_attribute_value(converted || rn)
|
|
696
|
+
else
|
|
697
|
+
attribute_names = rule_names.map do |rn|
|
|
698
|
+
converted = convert_rule_name_to_attribute_name(doc, rn,
|
|
699
|
+
session: session)
|
|
700
|
+
converted || rn
|
|
701
|
+
end
|
|
702
|
+
|
|
703
|
+
value = doc.root.find_attribute_value(attribute_names)
|
|
704
|
+
end
|
|
705
|
+
|
|
706
|
+
# Fallback: if value is nil, try to match by local name only.
|
|
707
|
+
# This handles the case where the namespace prefix is not declared in the document
|
|
708
|
+
# (e.g., v:ext without xmlns:v="...").
|
|
709
|
+
if value.nil? && rule_names.any? { |rn| rn.include?(":") }
|
|
710
|
+
value = find_attribute_by_local_name(doc, rule_names,
|
|
711
|
+
flexible_local: flexible_local,
|
|
712
|
+
session: session)
|
|
713
|
+
end
|
|
714
|
+
|
|
715
|
+
value = value&.split(rule.delimiter) if rule.delimiter
|
|
716
|
+
|
|
717
|
+
value = rule.as_list[:import].call(value) if rule.as_list && rule.as_list[:import]
|
|
718
|
+
|
|
719
|
+
value
|
|
720
|
+
end
|
|
721
|
+
|
|
722
|
+
# Convert a rule name (URI:localname or prefix:localname) to an attribute name
|
|
723
|
+
# that can be used to find the attribute in the document.
|
|
724
|
+
#
|
|
725
|
+
# @param doc [XmlElement] the parsed XML document root
|
|
726
|
+
# @param rule_name [String] the rule name (e.g., "urn:...:ext", "http://.../ns:val", "my-ns:val")
|
|
727
|
+
# @return [String, nil] the attribute name to look up, or nil if no conversion needed
|
|
728
|
+
def convert_rule_name_to_attribute_name(doc, rule_name, session: nil)
|
|
729
|
+
return nil unless rule_name.include?(":")
|
|
730
|
+
|
|
731
|
+
# Pure function of (element attributes, spelling) — the same
|
|
732
|
+
# conversions repeat per rule application (~450k find/slice
|
|
733
|
+
# allocations per ISO-13849 parse before this memo).
|
|
734
|
+
conversions = session&.rule_name_resolution(doc.root)
|
|
735
|
+
if conversions
|
|
736
|
+
return conversions[rule_name] if conversions.key?(rule_name)
|
|
737
|
+
|
|
738
|
+
converted = convert_rule_name_uncached(doc, rule_name, session)
|
|
739
|
+
conversions[rule_name] = converted
|
|
740
|
+
else
|
|
741
|
+
convert_rule_name_uncached(doc, rule_name, session)
|
|
742
|
+
end
|
|
743
|
+
end
|
|
744
|
+
|
|
745
|
+
def convert_rule_name_uncached(doc, rule_name, session)
|
|
746
|
+
# URI-vs-prefix detection works on the whole rule name: the
|
|
747
|
+
# namespace part is a prefix of rule_name, so "://" anywhere in
|
|
748
|
+
# the name means a URI-form namespace, and a "urn:" namespace
|
|
749
|
+
# makes the whole name start with "urn:". Slicing the parts out
|
|
750
|
+
# first would allocate two strings per call on this hot path.
|
|
751
|
+
is_uri_format = rule_name.include?("://") || rule_name.start_with?("urn:")
|
|
752
|
+
|
|
753
|
+
last_colon_index = rule_name.rindex(":")
|
|
754
|
+
if is_uri_format
|
|
755
|
+
# URI format: find the attribute whose resolved namespace and
|
|
756
|
+
# local name spell the rule name. Comparison is by namespace
|
|
757
|
+
# prefix + local suffix so prefixed attributes (whose
|
|
758
|
+
# namespaced_name is "prefix:local", never "uri:local") still
|
|
759
|
+
# match, and unprefixed_name is not called per attribute
|
|
760
|
+
# (it splits prefixed names and allocates). The split reuses
|
|
761
|
+
# match_attribute_by_local_name's per-spelling memo.
|
|
762
|
+
parts = NAMESPACED_NAME_PARTS[rule_name]
|
|
763
|
+
unless parts
|
|
764
|
+
parts = [rule_name[(last_colon_index + 1)..],
|
|
765
|
+
rule_name[0...last_colon_index]]
|
|
766
|
+
NAMESPACED_NAME_PARTS[rule_name] = parts
|
|
767
|
+
end
|
|
768
|
+
local_name = parts[0]
|
|
769
|
+
if session
|
|
770
|
+
candidates = session.element_local_attribute_index(doc.root)[local_name]
|
|
771
|
+
# No candidate carries this local name: nothing in the
|
|
772
|
+
# element can match, the scan is skipped entirely.
|
|
773
|
+
# getbyte, not a [i] slice — the slice allocated one
|
|
774
|
+
# string per probed candidate (~380k per ISO-13849 parse).
|
|
775
|
+
matched = candidates&.find do |attr|
|
|
776
|
+
ns = attr.namespace
|
|
777
|
+
next false if ns.nil? || ns.length > last_colon_index
|
|
778
|
+
next false unless rule_name.start_with?(ns) &&
|
|
779
|
+
rule_name.getbyte(ns.length) == COLON_BYTE
|
|
780
|
+
|
|
781
|
+
attr.unprefixed_name == local_name
|
|
782
|
+
end
|
|
783
|
+
else
|
|
784
|
+
matched = doc.root.attributes.each_value.find do |attr|
|
|
785
|
+
ns = attr.namespace
|
|
786
|
+
next false if ns.nil? || ns.length > last_colon_index
|
|
787
|
+
next false unless rule_name.start_with?(ns) &&
|
|
788
|
+
rule_name.getbyte(ns.length) == COLON_BYTE
|
|
789
|
+
|
|
790
|
+
attr.unprefixed_name == local_name
|
|
791
|
+
end
|
|
792
|
+
end
|
|
793
|
+
matched&.name
|
|
794
|
+
else
|
|
795
|
+
# Simple prefix format: look up the actual prefix from document's namespace declarations
|
|
796
|
+
# The namespace_part is the namespace URI declared in the document (e.g., "my-ns").
|
|
797
|
+
# Find the corresponding prefix (e.g., "my") and build "my:val".
|
|
798
|
+
namespace_part = rule_name[0...last_colon_index]
|
|
799
|
+
local_name = rule_name[(last_colon_index + 1)..]
|
|
800
|
+
|
|
801
|
+
ns_data = doc.root.namespaces.values.find do |nd|
|
|
802
|
+
nd.uri == namespace_part
|
|
803
|
+
end
|
|
804
|
+
return nil unless ns_data&.prefix
|
|
805
|
+
|
|
806
|
+
"#{ns_data.prefix}:#{local_name}"
|
|
807
|
+
end
|
|
808
|
+
end
|
|
809
|
+
|
|
810
|
+
# Fallback: find attribute by local name only when namespace prefix is unresolved.
|
|
811
|
+
#
|
|
812
|
+
# @param doc [XmlElement] the parsed XML document root
|
|
813
|
+
# @param rule_names [Array<String>] the rule names to match
|
|
814
|
+
# @return [String, nil] the attribute value or nil
|
|
815
|
+
def find_attribute_by_local_name(doc, rule_names,
|
|
816
|
+
flexible_local: false, session: nil)
|
|
817
|
+
root_index = session&.element_local_attribute_index(doc.root)
|
|
818
|
+
# Matched VALUE per (element, spelling, flexible flag) — pure
|
|
819
|
+
# while the element is parse-frozen.
|
|
820
|
+
memo = if session
|
|
821
|
+
session.lenient_local_matches(doc.root,
|
|
822
|
+
flexible_local)
|
|
823
|
+
else
|
|
824
|
+
nil
|
|
825
|
+
end
|
|
826
|
+
|
|
827
|
+
rule_names.each do |rule_name|
|
|
828
|
+
next unless rule_name.include?(":")
|
|
829
|
+
|
|
830
|
+
resolved = if memo&.key?(rule_name)
|
|
831
|
+
memo[rule_name]
|
|
832
|
+
else
|
|
833
|
+
match = match_attribute_by_local_name(
|
|
834
|
+
doc, rule_name, root_index, flexible_local
|
|
835
|
+
)
|
|
836
|
+
memo[rule_name] = match if memo
|
|
837
|
+
match
|
|
838
|
+
end
|
|
839
|
+
return resolved if resolved
|
|
840
|
+
end
|
|
841
|
+
nil
|
|
842
|
+
end
|
|
843
|
+
|
|
844
|
+
def match_attribute_by_local_name(doc, rule_name, root_index, flexible_local)
|
|
845
|
+
# Splitting a namespaced rule name is pure string work repeated
|
|
846
|
+
# per element; memoized per spelling (bounded by the model's
|
|
847
|
+
# distinct rule names).
|
|
848
|
+
parts = NAMESPACED_NAME_PARTS[rule_name]
|
|
849
|
+
unless parts
|
|
850
|
+
last_colon_index = rule_name.rindex(":")
|
|
851
|
+
parts = [rule_name[(last_colon_index + 1)..], rule_name[0...last_colon_index]]
|
|
852
|
+
NAMESPACED_NAME_PARTS[rule_name] = parts
|
|
853
|
+
end
|
|
854
|
+
local_name, rule_uri = parts
|
|
855
|
+
|
|
856
|
+
candidates = root_index&.[](local_name)
|
|
857
|
+
# The index carries every local form of every attribute on the
|
|
858
|
+
# element — a miss means no attribute can match, so the full
|
|
859
|
+
# each_value scan below is dead whenever the index exists.
|
|
860
|
+
return nil if root_index && !candidates
|
|
861
|
+
|
|
862
|
+
matched = if candidates
|
|
863
|
+
candidates.select do |attr|
|
|
864
|
+
local_name_match?(attr, local_name, rule_uri,
|
|
865
|
+
flexible_local)
|
|
866
|
+
end
|
|
867
|
+
else
|
|
868
|
+
doc.root.attributes.each_value.select do |attr|
|
|
869
|
+
local_name_match?(attr, local_name, rule_uri,
|
|
870
|
+
flexible_local)
|
|
871
|
+
end
|
|
872
|
+
end
|
|
873
|
+
# Attribute identity is (namespace URI, local name) — #841. The
|
|
874
|
+
# lenient probe is a recovery mechanism for the single
|
|
875
|
+
# undeclared-prefix case; several distinct matches are an
|
|
876
|
+
# ambiguity the document order must not arbitrate.
|
|
877
|
+
if matched.size > 1
|
|
878
|
+
identities = matched.map(&:namespaced_name).join(", ")
|
|
879
|
+
warn "[Lutaml::Model] ambiguous attribute for rule " \
|
|
880
|
+
"#{rule_name.inspect}: #{identities} all match by local " \
|
|
881
|
+
"name on <#{doc.root.unprefixed_name}>; no value bound"
|
|
882
|
+
return nil
|
|
883
|
+
end
|
|
884
|
+
matched.first&.value
|
|
885
|
+
end
|
|
886
|
+
|
|
887
|
+
# Namespace discipline of the lenient local-name fallback
|
|
888
|
+
# (#744/#758/#790): sole claimants bind any qualification; shared
|
|
889
|
+
# names must resolve to the rule's namespace.
|
|
890
|
+
def local_name_match?(attr, local_name, rule_uri, flexible_local)
|
|
891
|
+
if flexible_local
|
|
892
|
+
attr.unprefixed_name == local_name ||
|
|
893
|
+
attr_name_local(attr) == local_name
|
|
894
|
+
elsif attr.namespace.nil?
|
|
895
|
+
return false if attr.namespace_prefix.nil? && !attr.name.include?(":")
|
|
896
|
+
|
|
897
|
+
attr.unprefixed_name == local_name ||
|
|
898
|
+
attr_name_local(attr) == local_name
|
|
899
|
+
else
|
|
900
|
+
attr.namespace == rule_uri && attr.unprefixed_name == local_name
|
|
901
|
+
end
|
|
902
|
+
end
|
|
903
|
+
|
|
904
|
+
def attr_name_local(attr)
|
|
905
|
+
(colon = attr.name.rindex(":")) ? attr.name[(colon + 1)..] : attr.name
|
|
906
|
+
end
|
|
907
|
+
|
|
908
|
+
# lutaml-model#154: decode HTML entities for mappings that opted in
|
|
909
|
+
# (`html_entities` in the xml block). Values stay untouched
|
|
910
|
+
# otherwise — XML keeps undefined entities literal by design.
|
|
911
|
+
# lutaml-model#223: with coexisting map_all, the raw capture is
|
|
912
|
+
# the verbatim subtree MINUS the children claimed by element
|
|
913
|
+
# rules (they hydrate their own attributes). Standalone map_all
|
|
914
|
+
# (no element rules) keeps the full inner_xml.
|
|
915
|
+
def scoped_raw_inner_xml(doc, xml_mapping)
|
|
916
|
+
claimed = []
|
|
917
|
+
xml_mapping&.elements&.each do |element_rule|
|
|
918
|
+
Array(element_rule.name).each { |n| claimed << n.to_s }
|
|
919
|
+
end
|
|
920
|
+
return doc.root.inner_xml if claimed.empty?
|
|
921
|
+
|
|
922
|
+
doc.root.element_children.reject do |child|
|
|
923
|
+
claimed.include?(child.unprefixed_name) ||
|
|
924
|
+
claimed.include?(child.name)
|
|
925
|
+
end.map(&:inner_xml_or_self).join
|
|
926
|
+
end
|
|
927
|
+
|
|
928
|
+
def decode_html_entities_value(value, enabled)
|
|
929
|
+
return value if value.nil? || !value.is_a?(String)
|
|
930
|
+
return value unless enabled
|
|
931
|
+
return value if Lutaml::Model.opal?
|
|
932
|
+
|
|
933
|
+
Lutaml::Xml::HtmlEntities.decode(value)
|
|
934
|
+
end
|
|
935
|
+
|
|
936
|
+
Record = Struct.new(:attr, :derived, :group_skip, :valid,
|
|
937
|
+
:unmatched_mode, :replay_writer,
|
|
938
|
+
:unmatched_names, :raw_reader)
|
|
939
|
+
|
|
940
|
+
def compiled_rule_records(model_class, register, grouped_plain_rules)
|
|
941
|
+
return {}.compare_by_identity unless model_class.include?(Lutaml::Model::Serialize)
|
|
942
|
+
|
|
943
|
+
mapping = model_class.mappings_for(:xml, register)
|
|
944
|
+
version = mapping&.rule_records_version.to_i
|
|
945
|
+
per_class = RULE_RECORDS[model_class.object_id] # rubocop:disable Lint/HashCompareByIdentity
|
|
946
|
+
unless per_class
|
|
947
|
+
per_class = Lutaml::Model.opal? ? {} : Concurrent::Map.new
|
|
948
|
+
RULE_RECORDS[model_class.object_id] = per_class # rubocop:disable Lint/HashCompareByIdentity
|
|
949
|
+
end
|
|
950
|
+
cached = per_class[register]
|
|
951
|
+
return cached.records if cached && cached.version == version
|
|
952
|
+
|
|
953
|
+
records = {}.compare_by_identity
|
|
954
|
+
mapping&.mappings(register)&.each do |rule| # rubocop:disable Style/SafeNavigationChain,Style/SafeNavigation
|
|
955
|
+
attr = attribute_for_rule_static(model_class, rule, register)
|
|
956
|
+
group = grouped_plain_rules[rule.to]
|
|
957
|
+
# #903: for a plain rule, what an unmatched visit writes is
|
|
958
|
+
# known statically. The fast-skip branch hands the attribute's
|
|
959
|
+
# uninitialized sentinel to the pipeline; with no value-map
|
|
960
|
+
# overrides and no transformers every step is identity except
|
|
961
|
+
# apply_value_map, which maps the :omitted key: the default
|
|
962
|
+
# map (:nil) yields nil and the visit writes nil through the
|
|
963
|
+
# setter; an explicit omitted: :omitted map treats it as
|
|
964
|
+
# treat_omitted? == false and the omission gate ends the
|
|
965
|
+
# visit untouched. Both endings replay without the walk:
|
|
966
|
+
# :write_nil (setter write + flag churn) or :drop (nothing).
|
|
967
|
+
# Everything else -- defaults, aliases, custom from:,
|
|
968
|
+
# delegates, when_attribute dispatch, transformers, value
|
|
969
|
+
# maps beyond those two -- keeps its visit.
|
|
970
|
+
unmatched_mode = nil
|
|
971
|
+
replay_writer = nil
|
|
972
|
+
if attr && !attr.derived? &&
|
|
973
|
+
!rule.render_default && !rule.multiple_mappings? &&
|
|
974
|
+
!rule.has_custom_method_for_deserialization? &&
|
|
975
|
+
!rule.delegate &&
|
|
976
|
+
!(rule.when_attribute && !rule.when_attribute.empty?)
|
|
977
|
+
rule_transform = rule.transform
|
|
978
|
+
attr_transform = attr.transform
|
|
979
|
+
no_transforms =
|
|
980
|
+
(rule_transform.nil? ||
|
|
981
|
+
(rule_transform.respond_to?(:empty?) &&
|
|
982
|
+
rule_transform.empty?)) &&
|
|
983
|
+
(attr_transform.nil? ||
|
|
984
|
+
(attr_transform.respond_to?(:empty?) &&
|
|
985
|
+
attr_transform.empty?))
|
|
986
|
+
rule_default = attr.default(register)
|
|
987
|
+
if no_transforms &&
|
|
988
|
+
(rule_default.nil? ||
|
|
989
|
+
rule_default.is_a?(::Lutaml::Model::UninitializedClass)) &&
|
|
990
|
+
rule.class.transform_dispatch(rule, attr) == :assign
|
|
991
|
+
if group && group.size > 1 && attr.collection? &&
|
|
992
|
+
!group.first.equal?(rule)
|
|
993
|
+
# Non-first spelling of a #765 group: the visit is a
|
|
994
|
+
# guarded next (the first member does the merged match).
|
|
995
|
+
unmatched_mode = :drop
|
|
996
|
+
else
|
|
997
|
+
omitted_val = rule.value_map(:from)[:omitted]
|
|
998
|
+
if omitted_val == :nil
|
|
999
|
+
unmatched_mode = :write_nil
|
|
1000
|
+
elsif omitted_val == :omitted
|
|
1001
|
+
unmatched_mode = :drop
|
|
1002
|
+
end
|
|
1003
|
+
end
|
|
1004
|
+
end
|
|
1005
|
+
end
|
|
1006
|
+
# A first group member does the merged match for every
|
|
1007
|
+
# spelling, so its name-miss test spans the whole group.
|
|
1008
|
+
unmatched_names = if group && group.size > 1
|
|
1009
|
+
group.map { |r| r.name.to_s }
|
|
1010
|
+
else
|
|
1011
|
+
[rule.name.to_s]
|
|
1012
|
+
end
|
|
1013
|
+
if unmatched_mode == :write_nil
|
|
1014
|
+
replay_writer =
|
|
1015
|
+
rule.class.parsed_assign_writer(model_class, rule.to)
|
|
1016
|
+
unmatched_mode = nil unless replay_writer
|
|
1017
|
+
end
|
|
1018
|
+
records[rule] = Record.new(
|
|
1019
|
+
attr,
|
|
1020
|
+
attr&.derived? || false,
|
|
1021
|
+
!!(group && group.size > 1 && attr&.collection? &&
|
|
1022
|
+
!group.first.equal?(rule)),
|
|
1023
|
+
!!(attr || rule.custom_methods[:from]),
|
|
1024
|
+
unmatched_mode,
|
|
1025
|
+
replay_writer,
|
|
1026
|
+
unmatched_names,
|
|
1027
|
+
# lutaml-model#922: raw-state reader for the attribute,
|
|
1028
|
+
# when the compiled init seeds it (plain names -- the same
|
|
1029
|
+
# set compile_state_defaults! writes). Delegated rules name
|
|
1030
|
+
# an attribute on the delegate object, not on this
|
|
1031
|
+
# instance, so they get no raw reader.
|
|
1032
|
+
if attr && rule.delegate.nil? &&
|
|
1033
|
+
rule.to.to_s.match?(/\A[a-zA-Z_][a-zA-Z0-9_]*\z/)
|
|
1034
|
+
:"__lutaml_raw_#{rule.to}"
|
|
1035
|
+
end,
|
|
1036
|
+
)
|
|
1037
|
+
end
|
|
1038
|
+
entry = Struct.new(:version, :records).new(version, records)
|
|
1039
|
+
per_class[register] = entry
|
|
1040
|
+
records
|
|
1041
|
+
end
|
|
1042
|
+
|
|
1043
|
+
def attribute_for_rule_static(model_class, rule, register)
|
|
1044
|
+
if rule.delegate
|
|
1045
|
+
delegate_attr = model_class.attributes(register)[rule.delegate]
|
|
1046
|
+
delegate_type = delegate_attr&.type(register)
|
|
1047
|
+
delegate_type&.attributes(register)&.[](rule.to) # rubocop:disable Style/SafeNavigationChain
|
|
1048
|
+
else
|
|
1049
|
+
model_class.attributes(register)[rule.to]
|
|
1050
|
+
end
|
|
1051
|
+
rescue StandardError
|
|
1052
|
+
nil
|
|
1053
|
+
end
|
|
1054
|
+
|
|
1055
|
+
def decode_html_entities_for(instance, register)
|
|
1056
|
+
# Asked per rule application (942k per ISO-13849 parse) for a
|
|
1057
|
+
# per-(class, register) fact; the transform instance itself is
|
|
1058
|
+
# cached per (model class, register), so the memo lives here.
|
|
1059
|
+
per_class = (@decode_html_entities_cache ||= {}.compare_by_identity)
|
|
1060
|
+
per_register = (per_class[instance.class] ||= {})
|
|
1061
|
+
return per_register[register] if per_register.key?(register)
|
|
1062
|
+
|
|
1063
|
+
klass = instance.class
|
|
1064
|
+
per_register[register] = klass.is_a?(Class) &&
|
|
1065
|
+
klass.include?(Lutaml::Model::Serialize) &&
|
|
1066
|
+
(klass.mappings_for(:xml, register)&.decode_html_entities? || false)
|
|
1067
|
+
end
|
|
1068
|
+
|
|
1069
|
+
# Serializable type class → its XML namespace class, asked per
|
|
1070
|
+
# (rule × element) in value_for_rule / resolve_rule_names_with_type
|
|
1071
|
+
# for a per-type static.
|
|
1072
|
+
def type_namespace_class_of(type_class)
|
|
1073
|
+
cache = (@type_ns_class_cache ||= {}.compare_by_identity)
|
|
1074
|
+
return cache[type_class] if cache.key?(type_class)
|
|
1075
|
+
|
|
1076
|
+
cache[type_class] = type_class.mappings_for(:xml)&.namespace_class
|
|
1077
|
+
end
|
|
1078
|
+
|
|
1079
|
+
# lutaml-model#88: fail closed for `unmatched: :raise`. An
|
|
1080
|
+
# occurrence no rule on the wire name claims — no discriminator
|
|
1081
|
+
# match, no plain sibling — is exactly the data the default policy
|
|
1082
|
+
# silently drops.
|
|
1083
|
+
def check_unmatched_discriminators!(children, rule, rule_names, session)
|
|
1084
|
+
plain_names = session.plain_element_rule_names
|
|
1085
|
+
return if rule_names.any? { |name| plain_names[name] }
|
|
1086
|
+
|
|
1087
|
+
group = rule_names.filter_map do |name|
|
|
1088
|
+
session.when_attribute_siblings_by_name[name]
|
|
1089
|
+
end.flatten
|
|
1090
|
+
tested = group.flat_map { |sibling| sibling.when_attribute.keys }
|
|
1091
|
+
.uniq.map(&:to_s)
|
|
1092
|
+
children.each do |child|
|
|
1093
|
+
next if group.any? { |sibling| sibling.matches_when_attribute?(child) }
|
|
1094
|
+
|
|
1095
|
+
values = tested.filter_map do |name|
|
|
1096
|
+
value = child.find_attribute_value(name)
|
|
1097
|
+
"#{name}=#{value.inspect}" if value
|
|
1098
|
+
end
|
|
1099
|
+
raise ::Lutaml::Model::UnknownDiscriminatorError,
|
|
1100
|
+
"Element <#{rule.name}> (#{values.join(', ')}) is claimed by " \
|
|
1101
|
+
"no rule: it matches no when_attribute discriminator and no " \
|
|
1102
|
+
"plain rule shares the name. Cover the value, add a plain " \
|
|
1103
|
+
"rule, or opt out with unmatched: :drop"
|
|
1104
|
+
end
|
|
1105
|
+
nil
|
|
1106
|
+
end
|
|
1107
|
+
|
|
1108
|
+
def value_for_rule(session, rule, options, cached_attr = nil,
|
|
1109
|
+
extra_rule_names = nil)
|
|
1110
|
+
doc = session.doc
|
|
1111
|
+
instance = session.instance
|
|
1112
|
+
instance_is_serialize = session.instance_is_serialize
|
|
1113
|
+
effective_register = session.register
|
|
1114
|
+
|
|
1115
|
+
# Performance: Use cached attr from caller if available
|
|
1116
|
+
attr = cached_attr || attribute_for_rule(rule)
|
|
1117
|
+
attr_type = attr&.type(effective_register)
|
|
1118
|
+
|
|
1119
|
+
# Performance: Cache rule properties accessed in hot loop
|
|
1120
|
+
rule_name_str = rule.name.to_s
|
|
1121
|
+
rule_namespace_set = rule.namespace_set?
|
|
1122
|
+
rule_namespace_param = rule_namespace_set ? rule.namespace_param : nil
|
|
1123
|
+
rule_namespace = rule_namespace_set ? rule.namespace : nil
|
|
1124
|
+
options[:default_namespace]
|
|
1125
|
+
|
|
1126
|
+
rule_names = if rule.attribute?
|
|
1127
|
+
resolve_attribute_rule_names(rule, attr, options,
|
|
1128
|
+
effective_register,
|
|
1129
|
+
instance, instance_is_serialize)
|
|
1130
|
+
else
|
|
1131
|
+
resolve_rule_names_with_type(rule, attr, options,
|
|
1132
|
+
effective_register, attr_type)
|
|
1133
|
+
end
|
|
1134
|
+
# lutaml-model#765: widened matching for the first rule of a
|
|
1135
|
+
# shared-attribute group — children of sibling spellings must be
|
|
1136
|
+
# selected too, in document order. Deduped: sibling resolution can
|
|
1137
|
+
# yield the same spelling twice, and the child index would then
|
|
1138
|
+
# return the same children again.
|
|
1139
|
+
rule_names = rule_names.concat(extra_rule_names).uniq if extra_rule_names
|
|
1140
|
+
|
|
1141
|
+
if rule.attribute?
|
|
1142
|
+
value = value_for_xml_attribute(
|
|
1143
|
+
doc, rule, rule_names,
|
|
1144
|
+
flexible_local: attribute_rule_sole_local_claimant?(
|
|
1145
|
+
instance, rule, effective_register
|
|
1146
|
+
),
|
|
1147
|
+
session: session
|
|
1148
|
+
)
|
|
1149
|
+
return decode_html_entities_value(value, decode_html_entities_for(
|
|
1150
|
+
instance, effective_register
|
|
1151
|
+
))
|
|
1152
|
+
end
|
|
1153
|
+
|
|
1154
|
+
# Performance: Pre-compute type-related values used in the hot loop
|
|
1155
|
+
attr_type_is_serializable = attr_type && attr_type <= ::Lutaml::Model::Serialize
|
|
1156
|
+
attr_type_is_class = attr_type.is_a?(Class) && attr_type.include?(::Lutaml::Model::Serialize)
|
|
1157
|
+
|
|
1158
|
+
# Pre-compute namespace class for prefix matching (only needed if attr_type is Serializable)
|
|
1159
|
+
type_ns_prefix_str = nil
|
|
1160
|
+
type_ns_all_uris = nil
|
|
1161
|
+
if attr_type_is_serializable
|
|
1162
|
+
type_ns_class = if attr_type_is_class
|
|
1163
|
+
type_namespace_class_of(attr_type)
|
|
1164
|
+
else
|
|
1165
|
+
attr.type_namespace_class(effective_register)
|
|
1166
|
+
end
|
|
1167
|
+
type_ns_prefix_str = type_ns_class&.prefix_default&.to_s
|
|
1168
|
+
type_ns_all_uris = type_ns_class&.all_uris
|
|
1169
|
+
# Adopt the parsed document's namespace (memoized on the session):
|
|
1170
|
+
# when the whole document is out-of-namespace, treat it as an
|
|
1171
|
+
# implicit alias so lenient parsing is lossless (#754).
|
|
1172
|
+
adopted_uri = session.adopted_namespace_uri
|
|
1173
|
+
if adopted_uri && !type_ns_all_uris&.include?(adopted_uri)
|
|
1174
|
+
type_ns_all_uris = (type_ns_all_uris || []) + [adopted_uri]
|
|
1175
|
+
end
|
|
1176
|
+
end
|
|
1177
|
+
|
|
1178
|
+
# Pre-compute model's namespace class for simple-type alias matching
|
|
1179
|
+
# (Third branch in select loop — memoized on the session)
|
|
1180
|
+
model_ns_class = if instance_is_serialize &&
|
|
1181
|
+
!rule_namespace_set && !attr_type_is_serializable
|
|
1182
|
+
session.xml_mapping&.namespace_class
|
|
1183
|
+
end
|
|
1184
|
+
# Includes the adopted document namespace (#754): a prefixed child
|
|
1185
|
+
# in the document's (foreign) namespace must still bind by local
|
|
1186
|
+
# name, or its content is silently dropped.
|
|
1187
|
+
model_ns_all_uris = model_ns_class ? session.model_namespace_uris : nil
|
|
1188
|
+
|
|
1189
|
+
# Performance: Use cached element children from XmlElement
|
|
1190
|
+
# This avoids O(children * rules) scans by pre-filtering once per element
|
|
1191
|
+
element_children = doc.element_children
|
|
1192
|
+
|
|
1193
|
+
# Early exit if no element children - avoid scanning for each rule
|
|
1194
|
+
return ::Lutaml::Model::UninitializedClass.instance if element_children.empty?
|
|
1195
|
+
|
|
1196
|
+
# Performance: Use child index for O(1) exact matching when available.
|
|
1197
|
+
# Profiling shows that when the index returns no match and no child has
|
|
1198
|
+
# the same local name, the full select scan also returns empty 100% of the time.
|
|
1199
|
+
child_index = doc.element_children_index
|
|
1200
|
+
if child_index && !rule_namespace_set
|
|
1201
|
+
# Performance: Build indexed list without filter_map allocation
|
|
1202
|
+
indexed = []
|
|
1203
|
+
rule_names.each do |rn|
|
|
1204
|
+
found = child_index[rn]
|
|
1205
|
+
indexed << found if found
|
|
1206
|
+
end
|
|
1207
|
+
if indexed.empty?
|
|
1208
|
+
# Check if any child has same local name (namespace alias case)
|
|
1209
|
+
rule_local = rule_name_str
|
|
1210
|
+
has_local_match = child_index.keys.any? do |k|
|
|
1211
|
+
k.end_with?(":#{rule_local}") || k == rule_local
|
|
1212
|
+
end
|
|
1213
|
+
return ::Lutaml::Model::UninitializedClass.instance unless has_local_match
|
|
1214
|
+
|
|
1215
|
+
children = nil # fall through to select for alias matching
|
|
1216
|
+
else
|
|
1217
|
+
children = indexed.flatten(1)
|
|
1218
|
+
# #765 widened matching: rule_names spans several spellings, so
|
|
1219
|
+
# the flatten above yields rule-name order; restore document
|
|
1220
|
+
# order for the merged group.
|
|
1221
|
+
if extra_rule_names
|
|
1222
|
+
position = element_children.each_with_index.to_h
|
|
1223
|
+
children = children.sort_by { |c| position[c] }
|
|
1224
|
+
end
|
|
1225
|
+
end
|
|
1226
|
+
else
|
|
1227
|
+
children = nil
|
|
1228
|
+
end
|
|
1229
|
+
|
|
1230
|
+
children ||= element_children.select do |child|
|
|
1231
|
+
# Handle explicit namespace: nil with prefix: nil
|
|
1232
|
+
# When both namespace: nil and prefix: nil are set, this means "no namespace constraint"
|
|
1233
|
+
# The child element can declare its own namespace and should still match by local name
|
|
1234
|
+
if rule_namespace_set && rule_namespace.nil? &&
|
|
1235
|
+
rule_namespace_param.nil?
|
|
1236
|
+
# Match by unprefixed name only, regardless of child's namespace
|
|
1237
|
+
next child.unprefixed_name == rule_name_str
|
|
1238
|
+
end
|
|
1239
|
+
|
|
1240
|
+
# First try exact namespace match
|
|
1241
|
+
next true if rule_names.include?(child.namespaced_name)
|
|
1242
|
+
|
|
1243
|
+
# Second: alias-aware matching for nested models
|
|
1244
|
+
# When child's namespace URI is an alias of the rule's namespace class,
|
|
1245
|
+
# match by local name. This enables parsing XML with alias URIs
|
|
1246
|
+
# (e.g., "http://.../") against the canonical namespace class
|
|
1247
|
+
# (e.g., "http://.../reqif.xsd").
|
|
1248
|
+
child_uri = child.namespace_uri
|
|
1249
|
+
if child_uri && type_ns_all_uris && attr_type_is_serializable && type_ns_all_uris.include?(child_uri) &&
|
|
1250
|
+
child.unprefixed_name == rule_name_str
|
|
1251
|
+
next true
|
|
1252
|
+
end
|
|
1253
|
+
|
|
1254
|
+
# Third: alias-aware matching for simple types
|
|
1255
|
+
# When rule has no explicit namespace but model's namespace class has aliases,
|
|
1256
|
+
# match by local name if child's URI is an alias of the model's namespace.
|
|
1257
|
+
# This handles cases like <a:item xmlns:a="http://example.com/items/">
|
|
1258
|
+
# where the model has namespace with canonical URI "http://example.com/items".
|
|
1259
|
+
if child_uri && model_ns_all_uris && model_ns_all_uris.include?(child_uri) &&
|
|
1260
|
+
child.unprefixed_name == rule_name_str
|
|
1261
|
+
next true
|
|
1262
|
+
end
|
|
1263
|
+
|
|
1264
|
+
# Fourth: try to match by prefix when child has xmlns="" (explicit blank namespace)
|
|
1265
|
+
# This handles the case where elements have prefixed names but are in blank namespace
|
|
1266
|
+
# e.g., <GML:ApplicationSchema xmlns=""> should match the rule expecting GML namespace
|
|
1267
|
+
child_ns_prefix = child.namespace_prefix
|
|
1268
|
+
# Match by prefix AND local name to avoid matching unrelated elements
|
|
1269
|
+
# with the same namespace prefix (e.g., xsd:attributeGroup should not
|
|
1270
|
+
# match a rule for xsd:attribute)
|
|
1271
|
+
if child_ns_prefix && attr_type_is_serializable && type_ns_prefix_str && child_ns_prefix == type_ns_prefix_str &&
|
|
1272
|
+
child.unprefixed_name == rule_name_str
|
|
1273
|
+
next true
|
|
1274
|
+
end
|
|
1275
|
+
|
|
1276
|
+
# Fallback: if the child has a different namespace and attr_type is Serializable,
|
|
1277
|
+
# match by unprefixed name (child declares its own namespace)
|
|
1278
|
+
#
|
|
1279
|
+
# CRITICAL: Only use fallback for unqualified children (no prefix).
|
|
1280
|
+
# Children with explicit prefixes should NOT match via fallback, even if xmlns="" is set.
|
|
1281
|
+
# This ensures that GML:ApplicationSchema doesn't match CityGML:ApplicationSchema just because
|
|
1282
|
+
# they have the same unprefixed name.
|
|
1283
|
+
if attr_type_is_serializable
|
|
1284
|
+
# Only match by unprefixed name if child doesn't have an explicit namespace prefix
|
|
1285
|
+
# This prevents cross-namespace matching when elements have the same local name
|
|
1286
|
+
!child_ns_prefix && rule_names.any? do |rn|
|
|
1287
|
+
(RULE_LOCAL_NAMES[rn] ||= begin
|
|
1288
|
+
colon = rn.rindex(":")
|
|
1289
|
+
colon ? rn[(colon + 1)..] : rn
|
|
1290
|
+
end) == child.unprefixed_name
|
|
1291
|
+
end
|
|
1292
|
+
elsif !rule_namespace_set && (!child_ns_prefix || rule.raw == :element)
|
|
1293
|
+
# For simple types (String, etc.) with no namespace constraint,
|
|
1294
|
+
# match by unprefixed name. Handles elements in foreign namespaces
|
|
1295
|
+
# (e.g., SVG inside <image>). raw_element rules match regardless
|
|
1296
|
+
# of prefix — the intent is to capture any element with that name.
|
|
1297
|
+
child.unprefixed_name == rule_name_str
|
|
1298
|
+
else
|
|
1299
|
+
false
|
|
1300
|
+
end
|
|
1301
|
+
end
|
|
1302
|
+
|
|
1303
|
+
# lutaml-model#88: attribute-value discriminator — among the
|
|
1304
|
+
# name-matched occurrences, keep only those whose sibling
|
|
1305
|
+
# attributes carry the expected values. A plain rule sharing the
|
|
1306
|
+
# name with discriminator rules gets the complement — occurrences
|
|
1307
|
+
# no discriminator claimed — so each occurrence is captured
|
|
1308
|
+
# exactly once, mirroring ordered-serialization routing.
|
|
1309
|
+
if rule.when_attribute?
|
|
1310
|
+
if rule.unmatched == :raise
|
|
1311
|
+
check_unmatched_discriminators!(children, rule, rule_names, session)
|
|
1312
|
+
end
|
|
1313
|
+
children = children.select do |child|
|
|
1314
|
+
rule.matches_when_attribute?(child)
|
|
1315
|
+
end
|
|
1316
|
+
else
|
|
1317
|
+
siblings = session.when_attribute_siblings_by_name
|
|
1318
|
+
unless siblings.empty?
|
|
1319
|
+
claimed = rule_names.filter_map { |n| siblings[n] }.flatten
|
|
1320
|
+
unless claimed.empty?
|
|
1321
|
+
children = children.reject do |child|
|
|
1322
|
+
claimed.any? { |sibling| sibling.matches_when_attribute?(child) }
|
|
1323
|
+
end
|
|
1324
|
+
end
|
|
1325
|
+
end
|
|
1326
|
+
end
|
|
1327
|
+
|
|
1328
|
+
# Performance: Cache rule method check before loop to avoid repeated method calls
|
|
1329
|
+
rule_has_custom_method = rule.has_custom_method_for_deserialization?
|
|
1330
|
+
if rule_has_custom_method || attr_type == ::Lutaml::Model::Type::Hash
|
|
1331
|
+
return_child = attr_type == ::Lutaml::Model::Type::Hash || !attr.collection? if attr
|
|
1332
|
+
# A custom `from:` receives the over-count in the same shape a custom
|
|
1333
|
+
# `to:` already gets for a collection.
|
|
1334
|
+
return children if attr && !attr.collection? && children.size > 1
|
|
1335
|
+
|
|
1336
|
+
return return_child ? children.first : children
|
|
1337
|
+
end
|
|
1338
|
+
|
|
1339
|
+
return handle_cdata(children) if rule.cdata
|
|
1340
|
+
return ::Lutaml::Model::UninitializedClass.instance if children.empty?
|
|
1341
|
+
|
|
1342
|
+
values = attr.build_collection
|
|
1343
|
+
|
|
1344
|
+
instance.value_set_for(attr.name)
|
|
1345
|
+
|
|
1346
|
+
# Performance: Use pre-computed flag instead of is_a? check
|
|
1347
|
+
parent_ns_prefix = instance_is_serialize ? instance.xml_namespace_prefix : nil
|
|
1348
|
+
|
|
1349
|
+
# Performance: Avoid options.except allocation when :mappings not present
|
|
1350
|
+
base_cast_options = if options.key?(:mappings)
|
|
1351
|
+
options.except(:mappings)
|
|
1352
|
+
else
|
|
1353
|
+
options.dup
|
|
1354
|
+
end
|
|
1355
|
+
base_cast_options[:polymorphic] = rule.polymorphic if rule.polymorphic
|
|
1356
|
+
base_cast_options[:lutaml_parent] = instance
|
|
1357
|
+
base_cast_options[:lutaml_root] = instance.lutaml_root || instance
|
|
1358
|
+
base_cast_options[:resolved_type] = attr_type
|
|
1359
|
+
|
|
1360
|
+
nested_mapping = nested_collection_attribute_mapping(attr, attr_type, effective_register)
|
|
1361
|
+
|
|
1362
|
+
children.each do |child|
|
|
1363
|
+
if !rule_has_custom_method &&
|
|
1364
|
+
(attr_type_is_serializable ||
|
|
1365
|
+
(attr&.union? && ::Lutaml::Model::Type::Union.xml_structured?(child)))
|
|
1366
|
+
cast_child = if attr_type_is_serializable
|
|
1367
|
+
nested_collection_attribute_node(child, nested_mapping)
|
|
1368
|
+
else
|
|
1369
|
+
child
|
|
1370
|
+
end
|
|
1371
|
+
|
|
1372
|
+
# Performance: Build cast_options efficiently (dup + []= cheaper than merge)
|
|
1373
|
+
cast_options = if (child_namespace_uri = cast_child.namespace_uri)
|
|
1374
|
+
ns_type = attr.type_with_namespace(effective_register,
|
|
1375
|
+
child_namespace_uri)
|
|
1376
|
+
cast_options = base_cast_options.dup
|
|
1377
|
+
cast_options[:namespace_uri] = child_namespace_uri
|
|
1378
|
+
cast_options[:resolved_type] = ns_type
|
|
1379
|
+
cast_options
|
|
1380
|
+
else
|
|
1381
|
+
base_cast_options
|
|
1382
|
+
end
|
|
1383
|
+
|
|
1384
|
+
cast_result = attr.cast(cast_child, :xml, effective_register,
|
|
1385
|
+
cast_options)
|
|
1386
|
+
|
|
1387
|
+
# Track original namespace prefix for doubly-defined namespace support.
|
|
1388
|
+
# When parsing <a:item> and <b:item> (same URI, different prefixes),
|
|
1389
|
+
# we need to preserve which prefix was used for round-trip fidelity.
|
|
1390
|
+
# Store on the PARENT model instance keyed by attribute name.
|
|
1391
|
+
# Set for ALL attributes (both Serializable and non-Serializable).
|
|
1392
|
+
ns_prefix = explicit_namespace_prefix(child)
|
|
1393
|
+
if ns_prefix && instance_is_serialize
|
|
1394
|
+
prefixes = instance.xml_ns_prefixes || {}
|
|
1395
|
+
prefixes[attr.name] = ns_prefix
|
|
1396
|
+
instance.xml_ns_prefixes = prefixes
|
|
1397
|
+
end
|
|
1398
|
+
|
|
1399
|
+
# Track original alias URI for namespace alias support.
|
|
1400
|
+
# When parsing XML with alias URIs (e.g., "http://.../") against a namespace
|
|
1401
|
+
# class with canonical URI (e.g., "http://.../reqif.xsd"), store the original
|
|
1402
|
+
# alias URI so it can be serialized back correctly.
|
|
1403
|
+
child_uri = cast_child.namespace_uri
|
|
1404
|
+
if child_uri && attr_type_is_serializable
|
|
1405
|
+
child_mapping = cast_result.class.mappings_for(:xml)
|
|
1406
|
+
child_ns_class = child_mapping&.namespace_class
|
|
1407
|
+
if child_ns_class && child_ns_class.uri != child_uri
|
|
1408
|
+
# Child's URI differs from canonical - it's an alias
|
|
1409
|
+
cast_result.original_namespace_uri = child_uri
|
|
1410
|
+
end
|
|
1411
|
+
end
|
|
1412
|
+
|
|
1413
|
+
# Set @__xml_namespace_prefix on nested Serializable model instances
|
|
1414
|
+
# for doubly-defined namespace support.
|
|
1415
|
+
#
|
|
1416
|
+
# Key distinction between doubly-defined and mixed content:
|
|
1417
|
+
# - Doubly-defined: parent's XmlElement uses default format (no explicit prefix).
|
|
1418
|
+
# Parent's @__xml_namespace_prefix is nil. Child should use input prefix.
|
|
1419
|
+
# - Mixed content: parent's XmlElement has explicit prefix (e.g., "examplecom:").
|
|
1420
|
+
# Parent's @__xml_namespace_prefix is set. Child should use its own namespace.
|
|
1421
|
+
#
|
|
1422
|
+
# Check if parent model has @__xml_namespace_prefix set:
|
|
1423
|
+
# - Nil/empty: doubly-defined case -> set @__xml_namespace_prefix on child
|
|
1424
|
+
# - Set: mixed content case -> don't set (child has its own namespace)
|
|
1425
|
+
# Performance: Use cached parent_ns_prefix instead of re-fetching
|
|
1426
|
+
cast_child_ns_prefix = nested_collection_attribute_prefix(child, cast_child, ns_prefix)
|
|
1427
|
+
if attr_type_is_serializable && cast_child_ns_prefix &&
|
|
1428
|
+
(parent_ns_prefix.nil? || parent_ns_prefix.to_s.empty?)
|
|
1429
|
+
cast_result.xml_namespace_prefix = cast_child_ns_prefix
|
|
1430
|
+
end
|
|
1431
|
+
|
|
1432
|
+
values << cast_result
|
|
1433
|
+
elsif rule.raw == :element
|
|
1434
|
+
values << child.to_xml
|
|
1435
|
+
elsif rule.raw == :content || attr.raw?
|
|
1436
|
+
values << inner_xml_of(child)
|
|
1437
|
+
else
|
|
1438
|
+
return nil if rule.render_nil_as_nil? && child.nil_element?
|
|
1439
|
+
|
|
1440
|
+
child_text = child.nil_element? ? nil : child&.text
|
|
1441
|
+
child_cdata = child&.cdata
|
|
1442
|
+
text = if child_text.is_a?(Array) || child_cdata.is_a?(Array)
|
|
1443
|
+
# Mixed content - child elements handle their own text aggregation
|
|
1444
|
+
nil
|
|
1445
|
+
else
|
|
1446
|
+
child_text&.+ child_cdata
|
|
1447
|
+
end
|
|
1448
|
+
values << text
|
|
1449
|
+
|
|
1450
|
+
# Track namespace prefix for doubly-defined namespace support.
|
|
1451
|
+
# Store on parent model instance keyed by attribute name.
|
|
1452
|
+
ns_prefix = if child.namespace_prefix_explicit &&
|
|
1453
|
+
child.namespace_prefix
|
|
1454
|
+
child.namespace_prefix
|
|
1455
|
+
else
|
|
1456
|
+
# Only set ns_prefix for @__xml_ns_prefixes lookup when child's
|
|
1457
|
+
# XmlElement is explicit. For inherited namespaces (child's XmlElement
|
|
1458
|
+
# is nil), leave ns_prefix as-is so @__xml_ns_prefixes is not set.
|
|
1459
|
+
nil
|
|
1460
|
+
end
|
|
1461
|
+
if ns_prefix && instance_is_serialize
|
|
1462
|
+
# Skip Serializable attribute types (already handled in Serializable branch)
|
|
1463
|
+
# attr_type_is_serializable is false here, so attr_type is not Serializable
|
|
1464
|
+
prefixes = instance.xml_ns_prefixes || {}
|
|
1465
|
+
prefixes[attr.name] = ns_prefix
|
|
1466
|
+
instance.xml_ns_prefixes = prefixes
|
|
1467
|
+
end
|
|
1468
|
+
end
|
|
1469
|
+
end
|
|
1470
|
+
|
|
1471
|
+
normalized_value_for_attr(values, attr)
|
|
1472
|
+
end
|
|
1473
|
+
|
|
1474
|
+
def handle_cdata(children)
|
|
1475
|
+
values = children.map do |child|
|
|
1476
|
+
child.cdata_children&.map(&:text)
|
|
1477
|
+
end.flatten
|
|
1478
|
+
|
|
1479
|
+
children.count > 1 ? values : values.first
|
|
1480
|
+
end
|
|
1481
|
+
|
|
1482
|
+
def normalized_value_for_attr(values, attr)
|
|
1483
|
+
# for xml collection: true cases like
|
|
1484
|
+
# <store><items /></store>
|
|
1485
|
+
# <store><items xsi:nil="true"/></store>
|
|
1486
|
+
# <store><items></items></store>
|
|
1487
|
+
#
|
|
1488
|
+
# these are considered empty collection
|
|
1489
|
+
return [] if attr&.collection? && [[nil], [""]].include?(values)
|
|
1490
|
+
return values if attr&.collection?
|
|
1491
|
+
|
|
1492
|
+
# Keep the over-count (don't collapse via .first) so it reaches the
|
|
1493
|
+
# attribute slot and `.validate` can report the cardinality violation.
|
|
1494
|
+
return values if values.is_a?(Array) && values.size > 1
|
|
1495
|
+
|
|
1496
|
+
values.is_a?(Array) ? values.first : values
|
|
1497
|
+
end
|
|
1498
|
+
|
|
1499
|
+
def normalize_xml_value(value, rule, attr, options = {},
|
|
1500
|
+
effective_register = lutaml_register)
|
|
1501
|
+
# Fast path: skip when value is nil, uninitialized, or already correct type
|
|
1502
|
+
return value if value.nil? || ::Lutaml::Model::Utils.uninitialized?(value)
|
|
1503
|
+
|
|
1504
|
+
collection_class = attr&.collection_class || Array
|
|
1505
|
+
value = [value].compact if !value.nil? && attr&.collection? && !value.is_a?(collection_class)
|
|
1506
|
+
|
|
1507
|
+
return value unless cast_value?(attr, rule)
|
|
1508
|
+
|
|
1509
|
+
attr.cast(value, :xml, effective_register, options)
|
|
1510
|
+
end
|
|
1511
|
+
|
|
1512
|
+
def cast_value?(attr, rule)
|
|
1513
|
+
attr && rule.castable?
|
|
1514
|
+
end
|
|
1515
|
+
|
|
1516
|
+
def ensure_utf8(value)
|
|
1517
|
+
case value
|
|
1518
|
+
when String
|
|
1519
|
+
value.encode("UTF-8", invalid: :replace, undef: :replace,
|
|
1520
|
+
replace: "")
|
|
1521
|
+
when Array
|
|
1522
|
+
value.map { |v| ensure_utf8(v) }
|
|
1523
|
+
when ::Hash
|
|
1524
|
+
value.transform_keys do |k|
|
|
1525
|
+
ensure_utf8(k)
|
|
1526
|
+
end.transform_values do |v|
|
|
1527
|
+
ensure_utf8(v)
|
|
1528
|
+
end
|
|
1529
|
+
else
|
|
1530
|
+
value
|
|
1531
|
+
end
|
|
1532
|
+
end
|
|
1533
|
+
|
|
1534
|
+
def inner_xml_of(node)
|
|
1535
|
+
case node
|
|
1536
|
+
when ::Lutaml::Xml::DataModel::XmlElement
|
|
1537
|
+
node.inner_xml
|
|
1538
|
+
else
|
|
1539
|
+
node.children.map(&:to_xml).join
|
|
1540
|
+
end
|
|
1541
|
+
end
|
|
1542
|
+
|
|
1543
|
+
# Match names for an attribute rule, mirroring how serialization
|
|
1544
|
+
# qualifies the same attribute (MappingRule#attribute_match_names):
|
|
1545
|
+
# a rule serialized with a prefix matches only attributes in its
|
|
1546
|
+
# namespace; a rule serialized unprefixed matches only namespace-less
|
|
1547
|
+
# attributes.
|
|
1548
|
+
def resolve_attribute_rule_names(rule, attr, options, effective_register,
|
|
1549
|
+
instance, instance_is_serialize)
|
|
1550
|
+
return rule.namespaced_names(options[:default_namespace]) if attr.nil? ||
|
|
1551
|
+
rule.multiple_mappings?
|
|
1552
|
+
|
|
1553
|
+
if instance_is_serialize
|
|
1554
|
+
parent_ns_class, form_default = parent_attribute_context(instance)
|
|
1555
|
+
else
|
|
1556
|
+
parent_ns_class = nil
|
|
1557
|
+
form_default = :unqualified
|
|
1558
|
+
end
|
|
1559
|
+
names = rule.attribute_match_names(attr, effective_register,
|
|
1560
|
+
parent_ns_class, form_default,
|
|
1561
|
+
options[:default_namespace])
|
|
1562
|
+
|
|
1563
|
+
# #786 lenient alias (["uri:name", "name"] from a type-qualified
|
|
1564
|
+
# rule): the unprefixed form must not steal the value when a
|
|
1565
|
+
# sibling namespace-less rule owns the bare local name (#744
|
|
1566
|
+
# disjointness). No sibling — the alias keeps 0.8.19 leniency.
|
|
1567
|
+
if names.size == 2 && !names[1].include?(":") &&
|
|
1568
|
+
instance_is_serialize &&
|
|
1569
|
+
unqualified_sibling_attribute_rule?(instance, rule,
|
|
1570
|
+
effective_register)
|
|
1571
|
+
names = names.first(1)
|
|
1572
|
+
end
|
|
1573
|
+
names
|
|
1574
|
+
end
|
|
1575
|
+
|
|
1576
|
+
# Whether another attribute rule with the same local name resolves
|
|
1577
|
+
# namespace-less (no rule namespace, no value-type namespace) —
|
|
1578
|
+
# the #744 owner of the unprefixed source form.
|
|
1579
|
+
def unqualified_sibling_attribute_rule?(instance, rule,
|
|
1580
|
+
effective_register)
|
|
1581
|
+
mapping = instance.class.mappings_for(:xml, effective_register)
|
|
1582
|
+
return false unless mapping
|
|
1583
|
+
|
|
1584
|
+
attrs = instance.class.attributes(effective_register)
|
|
1585
|
+
mapping.mappings.any? do |sib|
|
|
1586
|
+
next false unless sib.attribute? && !sib.equal?(rule)
|
|
1587
|
+
next false unless sib.name.to_s == rule.name.to_s
|
|
1588
|
+
next false if sib.namespace_set?
|
|
1589
|
+
|
|
1590
|
+
sib_attr = attrs[sib.to]
|
|
1591
|
+
type_ns = sib_attr&.type_namespace_class(effective_register)
|
|
1592
|
+
type_ns.nil? || type_ns == :blank
|
|
1593
|
+
end
|
|
1594
|
+
end
|
|
1595
|
+
|
|
1596
|
+
# [namespace_class, attribute_form_default] for the instance's model,
|
|
1597
|
+
# keyed on the model class. Attribute rules of one element share the
|
|
1598
|
+
# model, so a 1-entry cache avoids a mappings_for lookup per rule.
|
|
1599
|
+
def parent_attribute_context(instance)
|
|
1600
|
+
klass = instance.class
|
|
1601
|
+
if @parent_ns_klass == klass && @parent_ns_value
|
|
1602
|
+
return @parent_ns_value
|
|
1603
|
+
end
|
|
1604
|
+
|
|
1605
|
+
ns_class = klass.mappings_for(:xml)&.namespace_class
|
|
1606
|
+
value = [ns_class,
|
|
1607
|
+
ns_class&.attribute_form_default || :unqualified]
|
|
1608
|
+
@parent_ns_klass = klass
|
|
1609
|
+
@parent_ns_value = value
|
|
1610
|
+
value
|
|
1611
|
+
end
|
|
1612
|
+
|
|
1613
|
+
# Resolve rule names with type namespace support
|
|
1614
|
+
#
|
|
1615
|
+
# @param rule [MappingRule] the mapping rule
|
|
1616
|
+
# @param attr [Attribute, nil] the attribute
|
|
1617
|
+
# @param options [Hash] options including default_namespace
|
|
1618
|
+
# @param effective_register [Symbol] the register to use for type resolution
|
|
1619
|
+
# @return [Array<String>] possible namespaced names for matching
|
|
1620
|
+
def resolve_rule_names_with_type(rule, attr, options, effective_register,
|
|
1621
|
+
precomputed_type = nil)
|
|
1622
|
+
# If rule has explicit namespace or no type namespace, use standard logic
|
|
1623
|
+
if rule.namespace_set? || !attr
|
|
1624
|
+
return rule.namespaced_names(options[:default_namespace])
|
|
1625
|
+
end
|
|
1626
|
+
|
|
1627
|
+
# Check if attribute type has namespace
|
|
1628
|
+
type_ns_uri = attr.type_namespace_uri(effective_register)
|
|
1629
|
+
|
|
1630
|
+
if type_ns_uri
|
|
1631
|
+
# Use type namespace URI for matching (child.namespaced_name uses URI:localname format)
|
|
1632
|
+
["#{type_ns_uri}:#{rule.name}"]
|
|
1633
|
+
elsif precomputed_type.is_a?(Class) &&
|
|
1634
|
+
precomputed_type.include?(::Lutaml::Model::Serialize)
|
|
1635
|
+
# Use pre-computed type directly — avoids redundant attr.type() call
|
|
1636
|
+
attr_type_ns_class = type_namespace_class_of(precomputed_type)
|
|
1637
|
+
if attr_type_ns_class
|
|
1638
|
+
return ["#{attr_type_ns_class.uri}:#{rule.name}"]
|
|
1639
|
+
end
|
|
1640
|
+
|
|
1641
|
+
rule.namespaced_names(options[:default_namespace])
|
|
1642
|
+
elsif attr_type_is_serializable(attr, effective_register)
|
|
1643
|
+
# For Serializable models without pre-computed type, resolve it
|
|
1644
|
+
attr_type = attr.type(effective_register)
|
|
1645
|
+
attr_type_class = if attr_type.is_a?(Class) && attr_type.include?(::Lutaml::Model::Serialize)
|
|
1646
|
+
attr_type
|
|
1647
|
+
else
|
|
1648
|
+
attr.type_namespace_class(effective_register)
|
|
1649
|
+
end
|
|
1650
|
+
if attr_type_class
|
|
1651
|
+
attr_type_ns_class = if attr_type_class.is_a?(Class) &&
|
|
1652
|
+
attr_type_class.include?(::Lutaml::Model::Serialize)
|
|
1653
|
+
type_namespace_class_of(attr_type_class)
|
|
1654
|
+
end
|
|
1655
|
+
if attr_type_ns_class
|
|
1656
|
+
return ["#{attr_type_ns_class.uri}:#{rule.name}"]
|
|
1657
|
+
end
|
|
1658
|
+
end
|
|
1659
|
+
# Use existing logic
|
|
1660
|
+
rule.namespaced_names(options[:default_namespace])
|
|
1661
|
+
else
|
|
1662
|
+
# Use existing logic
|
|
1663
|
+
rule.namespaced_names(options[:default_namespace])
|
|
1664
|
+
end
|
|
1665
|
+
end
|
|
1666
|
+
|
|
1667
|
+
# map_any_element members: every child element no explicit
|
|
1668
|
+
# element rule claims, in document order; scalar targets take
|
|
1669
|
+
# the captured elements' text — the same normalize step scalar
|
|
1670
|
+
# elements get (the cast pipeline receives strings, not wrappers
|
|
1671
|
+
# whose to_s is their inspect); Serializable targets keep the
|
|
1672
|
+
# wrappers and cast into instances.
|
|
1673
|
+
def any_element_members(doc, mapping, attr, register)
|
|
1674
|
+
claimed = Set.new(
|
|
1675
|
+
mapping.mappings(register)
|
|
1676
|
+
.select { |r| !r.attribute? && r.name }
|
|
1677
|
+
.flat_map { |r| [r.name.to_s] },
|
|
1678
|
+
)
|
|
1679
|
+
unclaimed = doc.element_children.reject do |child|
|
|
1680
|
+
claimed.include?(child.unprefixed_name)
|
|
1681
|
+
end
|
|
1682
|
+
return unclaimed if attr.nil? ||
|
|
1683
|
+
attr_type_is_serializable(attr, register)
|
|
1684
|
+
|
|
1685
|
+
unclaimed.map do |child|
|
|
1686
|
+
child_text = child.nil_element? ? nil : child&.text
|
|
1687
|
+
child_cdata = child&.cdata
|
|
1688
|
+
text = if child_text.is_a?(Array) || child_cdata.is_a?(Array)
|
|
1689
|
+
nil
|
|
1690
|
+
else
|
|
1691
|
+
child_text&.+ child_cdata
|
|
1692
|
+
end
|
|
1693
|
+
text.nil? ? child : text
|
|
1694
|
+
end
|
|
1695
|
+
end
|
|
1696
|
+
|
|
1697
|
+
def attr_type_is_serializable(attr, effective_register)
|
|
1698
|
+
attr&.serializable_type?(effective_register) || false
|
|
1699
|
+
end
|
|
1700
|
+
|
|
1701
|
+
# Run consolidation on any Collection attributes that have organization.
|
|
1702
|
+
# This is called as a post-processing step after all mappings are applied.
|
|
1703
|
+
#
|
|
1704
|
+
# @param instance [Serializable] the deserialized model instance
|
|
1705
|
+
# @param register [Symbol] the register id
|
|
1706
|
+
def run_consolidation(instance, register, instance_is_serialize = nil)
|
|
1707
|
+
return unless instance_is_serialize || instance.is_a?(::Lutaml::Model::Serialize)
|
|
1708
|
+
|
|
1709
|
+
instance.class.attributes.each_value do |attr|
|
|
1710
|
+
next unless attr.collection?
|
|
1711
|
+
next unless attr.custom_collection?
|
|
1712
|
+
|
|
1713
|
+
collection = instance.public_send(attr.name)
|
|
1714
|
+
next unless collection.is_a?(::Lutaml::Model::Collection)
|
|
1715
|
+
next unless collection.class.organization
|
|
1716
|
+
|
|
1717
|
+
mappings = collection.class.mappings_for(:xml, register)
|
|
1718
|
+
next unless mappings.is_a?(::Lutaml::Xml::Mapping)
|
|
1719
|
+
next if mappings.consolidation_maps.empty?
|
|
1720
|
+
|
|
1721
|
+
mappings.consolidation_maps.each do |map|
|
|
1722
|
+
org = collection.class.organization
|
|
1723
|
+
resolved_map = if map.group_class
|
|
1724
|
+
map
|
|
1725
|
+
else
|
|
1726
|
+
::Lutaml::Model::ConsolidationMap.new(
|
|
1727
|
+
by: map.by,
|
|
1728
|
+
to: map.to,
|
|
1729
|
+
group_class: org.group_class,
|
|
1730
|
+
rules: map.rules,
|
|
1731
|
+
)
|
|
1732
|
+
end
|
|
1733
|
+
::Lutaml::Model::Consolidation::Engine.run(
|
|
1734
|
+
collection, resolved_map, collection.collection
|
|
1735
|
+
)
|
|
1736
|
+
end
|
|
1737
|
+
end
|
|
1738
|
+
end
|
|
1739
|
+
|
|
1740
|
+
# Check if any child element in the pre-built Set matches the rule.
|
|
1741
|
+
# Conservative: may return true (false positive) when namespace aliasing
|
|
1742
|
+
# is involved, but never returns false when value_for_rule would find a match.
|
|
1743
|
+
#
|
|
1744
|
+
# @param rule [MappingRule] the mapping rule to check
|
|
1745
|
+
# @param child_names_set [Set] Set of child namespaced_name and unprefixed_name
|
|
1746
|
+
# @param default_namespace [String, nil] the default namespace
|
|
1747
|
+
# @return [Boolean] true if a matching child likely exists
|
|
1748
|
+
# #903: for an unmatched named element rule whose record classed
|
|
1749
|
+
# it, replay what the visit would write without the walk: :drop
|
|
1750
|
+
# (the visit ended at the omission gate or was a guarded next)
|
|
1751
|
+
# writes nothing; :write_nil replays the nil the default value
|
|
1752
|
+
# map produces, plus the flag churn. Returns true when handled.
|
|
1753
|
+
# lutaml-model#922: whether the attribute holds anything other
|
|
1754
|
+
# than its initialized marker (uninitialized sentinel / lazy
|
|
1755
|
+
# collection) — i.e. a custom writer populated it mid-parse.
|
|
1756
|
+
def writer_populated?(record, instance)
|
|
1757
|
+
return false unless record&.raw_reader
|
|
1758
|
+
|
|
1759
|
+
!raw_initialized?(record, instance)
|
|
1760
|
+
end
|
|
1761
|
+
|
|
1762
|
+
# True when the attribute still holds the value the compiled init
|
|
1763
|
+
# seeded (uninitialized sentinel / lazy collection) — i.e. nothing
|
|
1764
|
+
# has written it since.
|
|
1765
|
+
def raw_initialized?(record, instance)
|
|
1766
|
+
raw = instance.public_send(record.raw_reader)
|
|
1767
|
+
raw.equal?(::Lutaml::Model::UninitializedClass.instance) ||
|
|
1768
|
+
raw.equal?(::Lutaml::Model::Serialize::LAZY_EMPTY_COLLECTION)
|
|
1769
|
+
end
|
|
1770
|
+
|
|
1771
|
+
def replay_unmatched_rule(child_names_set, record, rule, instance,
|
|
1772
|
+
defaults_used, xml_mapping)
|
|
1773
|
+
return false unless child_names_set && record
|
|
1774
|
+
|
|
1775
|
+
mode = record.unmatched_mode
|
|
1776
|
+
return false unless mode
|
|
1777
|
+
return false if rule.attribute? || rule.content_mapping? ||
|
|
1778
|
+
rule.raw_mapping? || !rule.name ||
|
|
1779
|
+
xml_mapping.any_element_rule.equal?(rule)
|
|
1780
|
+
|
|
1781
|
+
matched = record.unmatched_names.any? do |n|
|
|
1782
|
+
child_names_set.include?(n)
|
|
1783
|
+
end
|
|
1784
|
+
return false if matched
|
|
1785
|
+
|
|
1786
|
+
return true if mode == :drop
|
|
1787
|
+
|
|
1788
|
+
# The visited path picks the default branch only while the
|
|
1789
|
+
# attribute still reads as default-valued; once another rule
|
|
1790
|
+
# or a custom writer set it mid-parse, the omission gate ends
|
|
1791
|
+
# the visit with no write. Mirror that: replay writes only
|
|
1792
|
+
# while unset, and drops otherwise (a custom writer may have
|
|
1793
|
+
# populated the attribute — relaton's ICS Isoics-fallback
|
|
1794
|
+
# pattern).
|
|
1795
|
+
rule_to = rule.to
|
|
1796
|
+
unless instance.using_default?(rule_to)
|
|
1797
|
+
return true
|
|
1798
|
+
end
|
|
1799
|
+
|
|
1800
|
+
# lutaml-model#922: a custom writer may have populated the
|
|
1801
|
+
# attribute mid-parse without going through the tracker (the
|
|
1802
|
+
# compiled setters are direct ivar writes), so the tracked
|
|
1803
|
+
# flag above can lie. The raw state is the truth: still at its
|
|
1804
|
+
# initialized marker (sentinel / lazy collection) means unset
|
|
1805
|
+
# -- the visited path wrote the default there; anything else
|
|
1806
|
+
# is a writer assignment this replay must not clobber.
|
|
1807
|
+
return true unless raw_initialized?(record, instance)
|
|
1808
|
+
|
|
1809
|
+
defaults_used << rule_to
|
|
1810
|
+
instance.public_send(record.replay_writer, nil)
|
|
1811
|
+
instance.value_set_for(rule_to)
|
|
1812
|
+
true
|
|
1813
|
+
end
|
|
1814
|
+
|
|
1815
|
+
def child_matches_rule?(rule, child_names_set, default_namespace)
|
|
1816
|
+
rule_names = rule.namespaced_names(default_namespace)
|
|
1817
|
+
# Array#intersect? requires an Array argument; child_names_set may
|
|
1818
|
+
# be a Set, so use the block form which works for any includable.
|
|
1819
|
+
rule_names.any? { |rn| child_names_set.include?(rn) } ||
|
|
1820
|
+
child_names_set.include?(rule.name.to_s)
|
|
1821
|
+
end
|
|
1822
|
+
end
|
|
1823
|
+
end
|
|
1824
|
+
end
|