Class: WSDL::Schema::Collection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/wsdl/schema/collection.rb

Overview

A collection of XML Schema definitions with lookup capabilities.

Aggregates multiple Definition instances and provides unified lookup methods for finding schema components (elements, types, attributes) by namespace and local name.

Examples:

collection = Schema::Collection.new
collection << Schema::Definition.new(schema_node, collection)
collection.find_element('http://example.com', 'User')

Constant Summary collapse

EMPTY_DEFINITIONS =

Shared empty array returned for unknown namespaces to avoid allocation.

Returns:

  • (Array)
[].freeze

Lookups collapse

Instance Method Summary collapse

Constructor Details

#initializeCollection

Creates a new empty collection.



25
26
27
28
# File 'lib/wsdl/schema/collection.rb', line 25

def initialize
  @definitions = []
  @by_namespace = {}
end

Instance Method Details

#<<(definition) ⇒ Collection

Adds a definition to the collection.

Parameters:

  • definition (Definition)

    the schema definition to add

Returns:



34
35
36
37
38
# File 'lib/wsdl/schema/collection.rb', line 34

def <<(definition)
  @definitions << definition
  (@by_namespace[definition.target_namespace] ||= []) << definition
  self
end

#each {|definition| ... } ⇒ Enumerator, Collection

Iterates over each definition in the collection.

Yields:

  • (definition)

    yields each definition

Yield Parameters:

Returns:

  • (Enumerator, Collection)

    enumerator if no block given



57
58
59
# File 'lib/wsdl/schema/collection.rb', line 57

def each(&)
  @definitions.each(&)
end

#find_attribute(namespace, name) ⇒ Node?

Finds a global attribute by namespace and name.

Searches all definitions sharing the namespace per XSD §4.2.3.

Parameters:

  • namespace (String)

    the target namespace URI

  • name (String)

    the local name of the attribute

Returns:

  • (Node, nil)

    the attribute node, or nil if not found



143
144
145
146
147
148
149
# File 'lib/wsdl/schema/collection.rb', line 143

def find_attribute(namespace, name)
  definitions_for_namespace(namespace).each do |definition|
    attribute = definition.attributes[name]
    return attribute if attribute
  end
  nil
end

#find_attribute_group(namespace, name) ⇒ Node?

Finds an attribute group by namespace and name.

Searches all definitions sharing the namespace per XSD §4.2.3.

Parameters:

  • namespace (String)

    the target namespace URI

  • name (String)

    the local name of the attribute group

Returns:

  • (Node, nil)

    the attribute group node, or nil if not found



173
174
175
176
177
178
179
# File 'lib/wsdl/schema/collection.rb', line 173

def find_attribute_group(namespace, name)
  definitions_for_namespace(namespace).each do |definition|
    group = definition.attribute_groups[name]
    return group if group
  end
  nil
end

#find_by_namespace(namespace) ⇒ Definition?

Finds the first definition matching a target namespace.

Parameters:

  • namespace (String, nil)

    the target namespace URI

Returns:

  • (Definition, nil)

    the first matching definition, or nil if not found



185
186
187
# File 'lib/wsdl/schema/collection.rb', line 185

def find_by_namespace(namespace)
  definitions_for_namespace(namespace).first
end

#find_complex_type(namespace, name) ⇒ Node?

Finds a complex type by namespace and name.

Searches all definitions sharing the namespace per XSD §4.2.3.

Parameters:

  • namespace (String)

    the target namespace URI

  • name (String)

    the local name of the type

Returns:

  • (Node, nil)

    the complex type node, or nil if not found



96
97
98
99
100
101
102
# File 'lib/wsdl/schema/collection.rb', line 96

def find_complex_type(namespace, name)
  definitions_for_namespace(namespace).each do |definition|
    type = definition.complex_types[name]
    return type if type
  end
  nil
end

#find_element(namespace, name) ⇒ Node?

Finds a global element by namespace and name.

Searches all definitions sharing the namespace per XSD §4.2.3.

Parameters:

  • namespace (String)

    the target namespace URI

  • name (String)

    the local name of the element

Returns:

  • (Node, nil)

    the element node, or nil if not found



81
82
83
84
85
86
87
# File 'lib/wsdl/schema/collection.rb', line 81

def find_element(namespace, name)
  definitions_for_namespace(namespace).each do |definition|
    element = definition.elements[name]
    return element if element
  end
  nil
end

#find_group(namespace, name) ⇒ Node?

Finds a model group by namespace and name.

Searches all definitions sharing the namespace per XSD §4.2.3.

Parameters:

  • namespace (String)

    the target namespace URI

  • name (String)

    the local name of the group

Returns:

  • (Node, nil)

    the group node, or nil if not found



158
159
160
161
162
163
164
# File 'lib/wsdl/schema/collection.rb', line 158

def find_group(namespace, name)
  definitions_for_namespace(namespace).each do |definition|
    group = definition.groups[name]
    return group if group
  end
  nil
end

#find_simple_type(namespace, name) ⇒ Node?

Finds a simple type by namespace and name.

Searches all definitions sharing the namespace per XSD §4.2.3.

Parameters:

  • namespace (String)

    the target namespace URI

  • name (String)

    the local name of the type

Returns:

  • (Node, nil)

    the simple type node, or nil if not found



111
112
113
114
115
116
117
# File 'lib/wsdl/schema/collection.rb', line 111

def find_simple_type(namespace, name)
  definitions_for_namespace(namespace).each do |definition|
    type = definition.simple_types[name]
    return type if type
  end
  nil
end

#find_type(namespace, name) ⇒ Node?

Finds a type (complex or simple) by namespace and name.

Searches all definitions sharing the namespace per XSD §4.2.3. Complex and simple types share a symbol space within a namespace, so both are checked per definition before moving to the next.

Parameters:

  • namespace (String)

    the target namespace URI

  • name (String)

    the local name of the type

Returns:

  • (Node, nil)

    the type node, or nil if not found



128
129
130
131
132
133
134
# File 'lib/wsdl/schema/collection.rb', line 128

def find_type(namespace, name)
  definitions_for_namespace(namespace).each do |definition|
    type = definition.complex_types[name] || definition.simple_types[name]
    return type if type
  end
  nil
end

#push(definitions) ⇒ Collection

Adds multiple definitions to the collection.

Parameters:

  • definitions (Array<Definition>)

    the definitions to add

Returns:



44
45
46
47
48
49
50
# File 'lib/wsdl/schema/collection.rb', line 44

def push(definitions)
  @definitions.concat(definitions)
  definitions.each do |d|
    (@by_namespace[d.target_namespace] ||= []) << d
  end
  self
end

#release_dom_references!void

This method returns an undefined value.

Releases all references to the Nokogiri DOM from every definition in the collection.

Called by Parser.parse after the Definition IR is built so the GC can reclaim the DOM trees while the collection is still reachable.



68
69
70
# File 'lib/wsdl/schema/collection.rb', line 68

def release_dom_references!
  @definitions.each(&:release_dom_references!)
end