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.

Parameters:

  • schema_node (Nokogiri::XML::Node)

    the xs:schema element

  • collection (Collection)

    the parent collection for resolving refs

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

    where this schema was loaded from



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# 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 = {}
  @imports = {}
  @includes = []

  parse
end

Instance Attribute Details

#attribute_groupsHash{String => Node} (readonly)

Returns attribute group definitions.

Returns:

  • (Hash{String => Node})

    attribute group definitions



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

def attribute_groups
  @attribute_groups
end

#attributesHash{String => Node} (readonly)

Returns global attribute declarations.

Returns:

  • (Hash{String => Node})

    global attribute declarations



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

def attributes
  @attributes
end

#complex_typesHash{String => Node} (readonly)

Returns complex type definitions.

Returns:

  • (Hash{String => Node})

    complex type definitions



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

def complex_types
  @complex_types
end

#element_form_defaultString (readonly)

Returns 'qualified' or 'unqualified'.

Returns:

  • (String)

    'qualified' or 'unqualified'



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

def element_form_default
  @element_form_default
end

#elementsHash{String => Node} (readonly)

Returns global element declarations.

Returns:

  • (Hash{String => Node})

    global element declarations



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

def elements
  @elements
end

#importsHash{String => String} (readonly)

Returns namespace to schemaLocation mappings.

Returns:

  • (Hash{String => String})

    namespace to schemaLocation mappings



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

def imports
  @imports
end

#includesArray<String> (readonly)

Returns schemaLocation values for includes.

Returns:

  • (Array<String>)

    schemaLocation values for includes



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

def includes
  @includes
end

#simple_typesHash{String => Node} (readonly)

Returns simple type definitions.

Returns:

  • (Hash{String => Node})

    simple type definitions



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

def simple_types
  @simple_types
end

#source_locationString? (readonly)

Returns the location this schema was loaded from.

Returns:

  • (String, nil)

    the location this schema was loaded from



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

def source_location
  @source_location
end

#target_namespaceString? (readonly)

Returns the target namespace URI.

Returns:

  • (String, nil)

    the target namespace URI



44
45
46
# File 'lib/wsdl/schema/definition.rb', line 44

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.

Parameters:



84
85
86
87
88
89
90
91
92
# File 'lib/wsdl/schema/definition.rb', line 84

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)
  @imports.merge!(other.imports)
  @includes.concat(other.includes)
end