Class: Lutaml::Xsd::Validation::SchemaResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/xsd/validation/schema_resolver.rb

Overview

SchemaResolver resolves XSD schemas from locations

This class takes schema location hints from XML documents and resolves them to actual XSD schema objects using the SchemaRepository.

Examples:

Resolve schemas from XML document

resolver = SchemaResolver.new(repository)
schemas = resolver.resolve_from_document(xml_document)

Resolve schemas from locations

locations = { "http://example.com" => "schema.xsd" }
schemas = resolver.resolve_from_locations(locations)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repository) ⇒ SchemaResolver

Initialize a new SchemaResolver

Parameters:



27
28
29
# File 'lib/lutaml/xsd/validation/schema_resolver.rb', line 27

def initialize(repository)
  @repository = repository
end

Instance Attribute Details

#repositorySchemaRepository (readonly)

Returns The schema repository.

Returns:



22
23
24
# File 'lib/lutaml/xsd/validation/schema_resolver.rb', line 22

def repository
  @repository
end

Instance Method Details

#can_resolve_all?(document) ⇒ Boolean

Check if all schemas for a document can be resolved

Parameters:

Returns:

  • (Boolean)


90
91
92
93
# File 'lib/lutaml/xsd/validation/schema_resolver.rb', line 90

def can_resolve_all?(document)
  result = resolve_from_document(document)
  result[:unresolved].empty?
end

#missing_schemas(document) ⇒ Array<String>

Get missing schema locations for a document

Parameters:

Returns:

  • (Array<String>)

    List of unresolved locations



99
100
101
102
# File 'lib/lutaml/xsd/validation/schema_resolver.rb', line 99

def missing_schemas(document)
  result = resolve_from_document(document)
  result[:unresolved]
end

#resolve_by_location(_location) ⇒ Schema?

Resolve a single schema by location

Parameters:

  • location (String)

    The schema location

Returns:

  • (Schema, nil)

    The resolved schema or nil



76
77
78
79
80
81
82
83
84
# File 'lib/lutaml/xsd/validation/schema_resolver.rb', line 76

def resolve_by_location(_location)
  # This is a simplified implementation
  # In a real implementation, this would:
  # 1. Check if location is in repository
  # 2. Try to load from file system
  # 3. Try to download if URL
  # 4. Parse and add to repository
  nil
end

#resolve_by_namespace(namespace) ⇒ Schema?

Resolve a single schema by namespace

Parameters:

  • namespace (String)

    The target namespace

Returns:

  • (Schema, nil)

    The resolved schema or nil



66
67
68
69
70
# File 'lib/lutaml/xsd/validation/schema_resolver.rb', line 66

def resolve_by_namespace(namespace)
  @repository.schemas.find do |schema|
    schema.target_namespace == namespace
  end
end

#resolve_from_document(document) ⇒ Hash

Resolve schemas from an XML document

Extracts schema locations from the document and resolves them to schema objects.

Examples:

result = resolver.resolve_from_document(doc)
# => {
#   schemas: [schema1, schema2],
#   unresolved: ["missing.xsd"]
# }

Parameters:

Returns:

  • (Hash)

    Hash with resolved schemas



45
46
47
48
49
50
51
# File 'lib/lutaml/xsd/validation/schema_resolver.rb', line 45

def resolve_from_document(document)
  extractor = SchemaLocationExtractor.new(document)
  locations = extractor.extract_schema_locations
  no_ns_location = extractor.extract_no_namespace_schema_location

  resolve_all_locations(locations, no_ns_location)
end

#resolve_from_locations(locations, no_namespace_location = nil) ⇒ Hash

Resolve schemas from explicit locations

Parameters:

  • locations (Hash<String, String>)

    Map of namespace to location

  • no_namespace_location (String, nil) (defaults to: nil)

    No-namespace schema location

Returns:

  • (Hash)

    Hash with resolved schemas



58
59
60
# File 'lib/lutaml/xsd/validation/schema_resolver.rb', line 58

def resolve_from_locations(locations, no_namespace_location = nil)
  resolve_all_locations(locations, no_namespace_location)
end