Class: Lutaml::Xml::NamespaceInheritanceResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/xml/namespace_inheritance_resolver.rb

Overview

Resolves namespace inheritance between parent and child elements

CRITICAL ARCHITECTURAL PRINCIPLE: PREFIX INHERITANCE - If parent declared namespace with PREFIX format, child MUST preserve that format to avoid declaring the same namespace twice.

Examples:

resolver = NamespaceInheritanceResolver.new
result = resolver.resolve_inheritance(ns_class, parent_plan, child_mapping, needs, options)

Defined Under Namespace

Classes: InheritanceResult

Instance Method Summary collapse

Constructor Details

#initializeNamespaceInheritanceResolver

Initialize resolver



25
# File 'lib/lutaml/xml/namespace_inheritance_resolver.rb', line 25

def initialize; end

Instance Method Details

#resolve_inheritance(ns_class, parent_plan, child_mapping, needs, options, format_chooser) ⇒ InheritanceResult

Resolve namespace inheritance for child element

Determines if child should declare namespace and what format to use based on parent's declaration.

Parameters:

  • XmlNamespace class to inherit

  • parent's declaration plan

  • child element's mapping

  • namespace needs from collector

  • serialization options

  • format decision helper

Returns:

  • inheritance decision result



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/lutaml/xml/namespace_inheritance_resolver.rb', line 39

def resolve_inheritance(ns_class, parent_plan, child_mapping, needs,
  options, format_chooser)
  uri = ns_class.uri
  existing = DeclarationPlanQuery.find_namespace_by_uri(parent_plan,
                                                        uri)

  # No existing declaration in parent - child should declare
  unless existing
    return no_inheritance(ns_class, child_mapping, needs, options,
                          format_chooser)
  end

  # Skip if marked for local declaration only
  if existing[:declared_at] == :local_on_use
    return no_inheritance(ns_class, child_mapping, needs, options,
                          format_chooser)
  end

  # PREFIX INHERITANCE RULE:
  # Parent declared with PREFIX → child MUST preserve PREFIX format
  # Architecture Principle (line 102-114 in original):
  # "If a namespace is hoisted as prefix, all elements in that namespace
  # should also utilize the same prefix"
  if existing[:format] == :prefix
    return InheritanceResult.new(
      should_declare: true,
      format: existing[:format],
      declared_at: existing[:declared_at],
      prefix_override: existing[:prefix],
    )
  end

  # Parent used DEFAULT format - check if we need to redeclare
  default_inheritance(ns_class, existing, parent_plan, child_mapping,
                      needs, options, format_chooser)
end