Class: Wasabi::Parser
- Inherits:
-
Object
- Object
- Wasabi::Parser
- Defined in:
- lib/wasabi/parser.rb
Overview
Wasabi::Parser
Parses WSDL documents and remembers their important parts.
Instance Attribute Summary collapse
-
#element_form_default ⇒ Object
readonly
Returns the elementFormDefault value.
-
#endpoint ⇒ Object
readonly
Returns the SOAP endpoint.
-
#namespace ⇒ Object
readonly
Returns the target namespace.
-
#namespaces ⇒ Object
readonly
Returns a map from namespace identifier to namespace URI.
-
#operations ⇒ Object
readonly
Returns the SOAP operations.
-
#types ⇒ Object
readonly
Returns a map from a type name to a Hash with type information.
Instance Method Summary collapse
- #find_namespace(type) ⇒ Object
-
#initialize(nokogiri_document) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
- #parse_endpoint ⇒ Object
- #parse_namespaces ⇒ Object
- #parse_operations ⇒ Object
- #parse_types ⇒ Object
- #process_type(type, name) ⇒ Object
Constructor Details
#initialize(nokogiri_document) ⇒ Parser
Returns a new instance of Parser.
12 13 14 15 16 17 18 |
# File 'lib/wasabi/parser.rb', line 12 def initialize(nokogiri_document) @document = nokogiri_document @operations = {} @namespaces = {} @types = {} @element_form_default = :unqualified end |
Instance Attribute Details
#element_form_default ⇒ Object (readonly)
Returns the elementFormDefault value.
36 37 38 |
# File 'lib/wasabi/parser.rb', line 36 def element_form_default @element_form_default end |
#endpoint ⇒ Object (readonly)
Returns the SOAP endpoint.
33 34 35 |
# File 'lib/wasabi/parser.rb', line 33 def endpoint @endpoint end |
#namespace ⇒ Object (readonly)
Returns the target namespace.
21 22 23 |
# File 'lib/wasabi/parser.rb', line 21 def namespace @namespace end |
#namespaces ⇒ Object (readonly)
Returns a map from namespace identifier to namespace URI.
24 25 26 |
# File 'lib/wasabi/parser.rb', line 24 def namespaces @namespaces end |
#operations ⇒ Object (readonly)
Returns the SOAP operations.
27 28 29 |
# File 'lib/wasabi/parser.rb', line 27 def operations @operations end |
#types ⇒ Object (readonly)
Returns a map from a type name to a Hash with type information.
30 31 32 |
# File 'lib/wasabi/parser.rb', line 30 def types @types end |
Instance Method Details
#find_namespace(type) ⇒ Object
137 138 139 140 141 142 |
# File 'lib/wasabi/parser.rb', line 137 def find_namespace(type) schema_namespace = type.at_xpath("ancestor::xs:schema/@targetNamespace", "xs" => "http://www.w3.org/2001/XMLSchema" ) schema_namespace ? schema_namespace.to_s : @namespace end |
#parse ⇒ Object
38 39 40 41 42 43 |
# File 'lib/wasabi/parser.rb', line 38 def parse parse_namespaces parse_endpoint parse_operations parse_types end |
#parse_endpoint ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/wasabi/parser.rb', line 62 def parse_endpoint endpoint = @document.at_xpath( "s0:definitions/s0:service//soap11:address/@location", "s0" => "http://schemas.xmlsoap.org/wsdl/", "soap11" => "http://schemas.xmlsoap.org/wsdl/soap/") endpoint ||= @document.at_xpath( "s0:definitions/s0:service//soap12:address/@location", "s0" => "http://schemas.xmlsoap.org/wsdl/", "soap12" => "http://schemas.xmlsoap.org/wsdl/soap12/") @endpoint = URI(URI.escape(endpoint.to_s)) if endpoint end |
#parse_namespaces ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/wasabi/parser.rb', line 45 def parse_namespaces element_form_default = @document.at_xpath( "s0:definitions/s0:types/xs:schema/@elementFormDefault", "s0" => "http://schemas.xmlsoap.org/wsdl/", "xs" => "http://www.w3.org/2001/XMLSchema") @element_form_default = element_form_default.to_s.to_sym if element_form_default namespace = @document.at_xpath( "s0:definitions/@targetNamespace", "s0" => "http://schemas.xmlsoap.org/wsdl/") @namespace = namespace.to_s if namespace @namespaces = @document.collect_namespaces.inject({}) do |result, (key, value)| result.merge(key.gsub(/xmlns:/, '') => value) end end |
#parse_operations ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/wasabi/parser.rb', line 75 def parse_operations operations = @document.xpath( "s0:definitions/s0:binding/s0:operation", "s0" => "http://schemas.xmlsoap.org/wsdl/") operations.each do |operation| name = operation.attribute("name").to_s soap_action = operation.at_xpath(".//soap11:operation/@soapAction", "soap11" => "http://schemas.xmlsoap.org/wsdl/soap/" ) soap_action ||= operation.at_xpath(".//soap12:operation/@soapAction", "soap12" => "http://schemas.xmlsoap.org/wsdl/soap12/" ) if soap_action soap_action = soap_action.to_s action = soap_action.blank? ? name : soap_action input = name.blank? ? action.split("/").last : name @operations[input.snakecase.to_sym] = { :action => action, :input => input } elsif !@operations[name.snakecase.to_sym] @operations[name.snakecase.to_sym] = { :action => name, :input => name } end end end |
#parse_types ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/wasabi/parser.rb', line 104 def parse_types @document.xpath( "s0:definitions/s0:types/xs:schema/xs:element[@name]", "s0" => "http://schemas.xmlsoap.org/wsdl/", "xs" => "http://www.w3.org/2001/XMLSchema" ).each do |type| process_type(type.at_xpath('./xs:complexType', "xs" => "http://www.w3.org/2001/XMLSchema" ), type.attribute('name').to_s) end @document.xpath( "s0:definitions/s0:types/xs:schema/xs:complexType[@name]", "s0" => "http://schemas.xmlsoap.org/wsdl/", "xs" => "http://www.w3.org/2001/XMLSchema" ).each do |type| process_type(type, type.attribute('name').to_s) end end |
#process_type(type, name) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/wasabi/parser.rb', line 124 def process_type(type, name) return unless type @types[name] ||= { :namespace => find_namespace(type) } type.xpath("./xs:sequence/xs:element", "xs" => "http://www.w3.org/2001/XMLSchema" ).each do |inner_element| @types[name][inner_element.attribute('name').to_s] = { :type => inner_element.attribute('type').to_s } end end |