Class: Savon::WSDL::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/savon/wsdl/parser.rb

Overview

Savon::WSDL::Parser

Serves as a stream listener for parsing WSDL documents.

Constant Summary collapse

Sections =

The main sections of a WSDL document.

%w(definitions types message portType binding service)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



15
16
17
18
19
20
# File 'lib/savon/wsdl/parser.rb', line 15

def initialize
  @path = []
  @operations = {}
  @namespaces = {}
  @element_form_default = :unqualified
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object

Catches calls to unimplemented hook methods.



97
98
# File 'lib/savon/wsdl/parser.rb', line 97

def method_missing(method, *args)
end

Instance Attribute Details

#element_form_defaultObject (readonly)

Returns the elementFormDefault value.



32
33
34
# File 'lib/savon/wsdl/parser.rb', line 32

def element_form_default
  @element_form_default
end

#endpointObject (readonly)

Returns the SOAP endpoint.



29
30
31
# File 'lib/savon/wsdl/parser.rb', line 29

def endpoint
  @endpoint
end

#namespaceObject (readonly)

Returns the namespace URI.



23
24
25
# File 'lib/savon/wsdl/parser.rb', line 23

def namespace
  @namespace
end

#operationsObject (readonly)

Returns the SOAP operations.



26
27
28
# File 'lib/savon/wsdl/parser.rb', line 26

def operations
  @operations
end

Instance Method Details

#depthObject

Returns our current depth in the WSDL document.



60
61
62
# File 'lib/savon/wsdl/parser.rb', line 60

def depth
  @path.size
end

#operation_from(tag, attrs) ⇒ Object

Stores available operations from a given tag name and attrs.



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/savon/wsdl/parser.rb', line 84

def operation_from(tag, attrs)
  @input = attrs["name"] if attrs["name"]

  if attrs["soapAction"]
    @action = !attrs["soapAction"].blank? ? attrs["soapAction"] : @input
    @input = @action.split("/").last if !@input || @input.empty?

    @operations[@input.snakecase.to_sym] = { :action => @action, :input => @input }
    @input, @action = nil, nil
  end
end

#read_namespaces(attrs) ⇒ Object

Reads namespace definitions from a given attrs Hash.



65
66
67
68
69
# File 'lib/savon/wsdl/parser.rb', line 65

def read_namespaces(attrs)
  attrs.each do |key, value|
    @namespaces[key.strip_namespace] = value if key.starts_with? "xmlns:"
  end
end

#tag_end(tag) ⇒ Object

Hook method called when the stream parser encounters a closing tag.



72
73
74
75
76
77
78
79
80
81
# File 'lib/savon/wsdl/parser.rb', line 72

def tag_end(tag)
  @path.pop

  if @section == :binding && @input && tag.strip_namespace == "operation"
    # no soapAction attribute found till now
    operation_from tag, "soapAction" => @input
  end

  @section = :definitions if Sections.include?(tag) && depth <= 1
end

#tag_start(tag, attrs) ⇒ Object

Hook method called when the stream parser encounters a starting tag.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/savon/wsdl/parser.rb', line 35

def tag_start(tag, attrs)
  # read xml namespaces if root element
  read_namespaces(attrs) if @path.empty?

  tag, namespace = tag.split(":").reverse
  @path << tag

  if @section == :types && tag == "schema"
    @element_form_default = attrs["elementFormDefault"].to_sym if attrs["elementFormDefault"]
  end

  if @section == :binding && tag == "binding"
    # ensure that we are in an wsdl/soap namespace
    @section = nil unless @namespaces[namespace].starts_with? "http://schemas.xmlsoap.org/wsdl/soap"
  end

  @section = tag.to_sym if Sections.include?(tag) && depth <= 2

  @namespace ||= attrs["targetNamespace"] if @section == :definitions
  @endpoint ||= URI(URI.escape(attrs["location"])) if @section == :service && tag == "address"

  operation_from tag, attrs if @section == :binding && tag == "operation"
end