Skip to content

Commit

Permalink
moved Savon::WSDLStream into its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
rubiii committed Jan 28, 2010
1 parent be023be commit 0d1e3bd
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 90 deletions.
2 changes: 1 addition & 1 deletion lib/savon.rb
Expand Up @@ -29,6 +29,6 @@ class SOAPFault < StandardError; end
end

# core files
%w(core_ext wsse soap request response wsdl client).each do |file|
%w(core_ext wsse soap request response wsdl_stream wsdl client).each do |file|
require File.dirname(__FILE__) + "/savon/#{file}"
end
89 changes: 0 additions & 89 deletions lib/savon/wsdl.rb
Expand Up @@ -62,93 +62,4 @@ def stream
end

end

# Savon::WSDLStream
#
# Stream listener for parsing the WSDL document.
class WSDLStream

# The main sections of a WSDL document.
Sections = %w(definitions types message portType binding service)

def initialize
@path, @operations = [], {}
@namespaces = {}
end

# Returns the namespace URI.
attr_reader :namespace_uri

# Returns the SOAP operations.
attr_reader :operations

# Returns the SOAP endpoint.
attr_reader :soap_endpoint

# Hook method called when the stream parser encounters a starting tag.
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 == :binding && tag=="binding"
# ensure that we are in an wsdl/soap namespace
@section = nil unless @namespaces[namespace] == "http://schemas.xmlsoap.org/wsdl/soap/"
end

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

@namespace_uri ||= attrs["targetNamespace"] if @section == :definitions
@soap_endpoint ||= URI(attrs["location"]) if @section == :service && tag == "address"

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

def depth
@path.size
end

# read namespace definitions from given hash
def read_namespaces(attrs)
for key, value in attrs
if key.start_with?("xmlns:")
@namespaces[key.split(':').last] = value
end
end
end

# Hook method called when the stream parser encounters a closing tag.
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

end

# Stores available operations from a given tag +name+ and +attrs+.
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
@input = nil
end
end

# Catches calls to unimplemented hook methods.
def method_missing(method, *args)
end

end
end
88 changes: 88 additions & 0 deletions lib/savon/wsdl_stream.rb
@@ -0,0 +1,88 @@
module Savon

# Savon::WSDLStream
#
# Stream listener for parsing the WSDL document.
class WSDLStream

# The main sections of a WSDL document.
Sections = %w(definitions types message portType binding service)

def initialize
@path, @operations = [], {}
@namespaces = {}
end

# Returns the namespace URI.
attr_reader :namespace_uri

# Returns the SOAP operations.
attr_reader :operations

# Returns the SOAP endpoint.
attr_reader :soap_endpoint

# Hook method called when the stream parser encounters a starting tag.
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 == :binding && tag == "binding"
# ensure that we are in an wsdl/soap namespace
@section = nil unless @namespaces[namespace] == "http://schemas.xmlsoap.org/wsdl/soap/"
end

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

@namespace_uri ||= attrs["targetNamespace"] if @section == :definitions
@soap_endpoint ||= URI(attrs["location"]) if @section == :service && tag == "address"

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

# Returns our current depth in the WSDL document.
def depth
@path.size
end

# Reads namespace definitions from a given +attrs+ Hash.
def read_namespaces(attrs)
attrs.each do |key, value|
@namespaces[key.split(":").last] = value if key.start_with? "xmlns:"
end
end

# Hook method called when the stream parser encounters a closing tag.
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

end

# Stores available operations from a given tag +name+ and +attrs+.
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
@input = nil
end
end

# Catches calls to unimplemented hook methods.
def method_missing(method, *args)
end

end
end

0 comments on commit 0d1e3bd

Please sign in to comment.