Class: WSDL::Schema::Definition

Inherits:
Object
  • Object
show all
Includes:
Log
Defined in:
lib/wsdl/schema/definition.rb

Overview

Represents a parsed XML Schema (XSD) document.

Parses an xs:schema element and provides access to its components: elements, complex types, simple types, attributes, and attribute groups. Also tracks schema imports and includes for resolving cross-schema refs.

Examples:

definition = Schema::Definition.new(schema_node, collection)
definition.target_namespace  # => "http://example.com"
definition.elements['User']  # => Node

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Log

#logger

Constructor Details

#initialize(schema_node, collection, source_location = nil) ⇒ Definition

Creates a new Definition by parsing an XML Schema node.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/wsdl/schema/definition.rb', line 24

def initialize(schema_node, collection, source_location = nil)
  @schema_node = schema_node
  @collection = collection
  @source_location = source_location

  @target_namespace = schema_node['targetNamespace']
  @element_form_default = schema_node['elementFormDefault'] || 'unqualified'

  @elements = {}
  @complex_types = {}
  @simple_types = {}
  @attributes = {}
  @attribute_groups = {}
  @groups = {}
  @imports = {}
  @import_locations = []
  @includes = []

  parse
end

Instance Attribute Details

#attribute_groupsHash{String => Node} (readonly)



67
68
69
# File 'lib/wsdl/schema/definition.rb', line 67

def attribute_groups
  @attribute_groups
end

#attributesHash{String => Node} (readonly)



64
65
66
# File 'lib/wsdl/schema/definition.rb', line 64

def attributes
  @attributes
end

#complex_typesHash{String => Node} (readonly)



58
59
60
# File 'lib/wsdl/schema/definition.rb', line 58

def complex_types
  @complex_types
end

#element_form_defaultString (readonly)



49
50
51
# File 'lib/wsdl/schema/definition.rb', line 49

def element_form_default
  @element_form_default
end

#elementsHash{String => Node} (readonly)



55
56
57
# File 'lib/wsdl/schema/definition.rb', line 55

def elements
  @elements
end

#groupsHash{String => Node} (readonly)



70
71
72
# File 'lib/wsdl/schema/definition.rb', line 70

def groups
  @groups
end

#import_locationsArray<String> (readonly)



76
77
78
# File 'lib/wsdl/schema/definition.rb', line 76

def import_locations
  @import_locations
end

#importsHash{String => String} (readonly)



73
74
75
# File 'lib/wsdl/schema/definition.rb', line 73

def imports
  @imports
end

#includesArray<String> (readonly)



79
80
81
# File 'lib/wsdl/schema/definition.rb', line 79

def includes
  @includes
end

#simple_typesHash{String => Node} (readonly)



61
62
63
# File 'lib/wsdl/schema/definition.rb', line 61

def simple_types
  @simple_types
end

#source_locationString? (readonly)



52
53
54
# File 'lib/wsdl/schema/definition.rb', line 52

def source_location
  @source_location
end

#target_namespaceString? (readonly)



46
47
48
# File 'lib/wsdl/schema/definition.rb', line 46

def target_namespace
  @target_namespace
end

Instance Method Details

#merge(other) ⇒ void

This method returns an undefined value.

Merges another definition's contents into this one.

Used for xs:include processing where the included schema's components should be merged as if defined locally.

Logs a warning if the other definition contains components with the same name as existing ones, since per the XSD spec xs:include components should not conflict.



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/wsdl/schema/definition.rb', line 92

def merge(other)
  merge_with_conflict_detection(@elements, other.elements, :element)
  merge_with_conflict_detection(@complex_types, other.complex_types, :complex_type)
  merge_with_conflict_detection(@simple_types, other.simple_types, :simple_type)
  merge_with_conflict_detection(@attributes, other.attributes, :attribute)
  merge_with_conflict_detection(@attribute_groups, other.attribute_groups, :attribute_group)
  merge_with_conflict_detection(@groups, other.groups, :group)
  @imports.merge!(other.imports)
  @import_locations.concat(other.import_locations)
  @includes.concat(other.includes)
end

#release_dom_references!void

This method returns an undefined value.

Releases all references to the Nokogiri DOM from this definition and every Node it contains.

Called by Collection#release_dom_references! after the Definition IR has been built, so the GC can reclaim the DOM trees while the collection is still reachable on the call stack.

Preserves metadata (#target_namespace, #element_form_default, component hash keys) so the definition remains inspectable.



115
116
117
118
119
# File 'lib/wsdl/schema/definition.rb', line 115

def release_dom_references!
  @schema_node = nil

  each_node(&:release_dom_references!)
end