Class: Lutaml::Xml::NamespaceInheritanceResolver
- Inherits:
-
Object
- Object
- Lutaml::Xml::NamespaceInheritanceResolver
- 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.
Defined Under Namespace
Classes: InheritanceResult
Instance Method Summary collapse
-
#initialize ⇒ NamespaceInheritanceResolver
constructor
Initialize resolver.
-
#resolve_inheritance(ns_class, parent_plan, child_mapping, needs, options, format_chooser) ⇒ InheritanceResult
Resolve namespace inheritance for child element.
Constructor Details
#initialize ⇒ NamespaceInheritanceResolver
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.
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, , 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, , 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, , 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, , format_chooser) end |