Class: Wasabi::Parser
- Inherits:
-
Object
- Object
- Wasabi::Parser
- Includes:
- XPathHelper
- Defined in:
- lib/wasabi/parser.rb
Overview
Wasabi::Parser
Parses WSDL documents and remembers their important parts.
Constant Summary
Constants included from XPathHelper
Instance Attribute Summary collapse
-
#document ⇒ Object
Returns the Nokogiri document.
-
#element_form_default ⇒ Object
Returns the elementFormDefault value.
-
#endpoint ⇒ Object
Returns the SOAP endpoint.
-
#namespace ⇒ Object
Returns the target namespace.
-
#namespaces ⇒ Object
Returns a map from namespace identifier to namespace URI.
-
#operations ⇒ Object
Returns the SOAP operations.
-
#types ⇒ Object
Returns a map from a type name to a Hash with type information.
Instance Method Summary collapse
- #find_namespace(type) ⇒ Object
-
#initialize(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
Methods included from XPathHelper
Constructor Details
#initialize(document) ⇒ Parser
Returns a new instance of Parser.
14 15 16 17 18 19 20 |
# File 'lib/wasabi/parser.rb', line 14 def initialize(document) self.document = document self.operations = {} self.namespaces = {} self.types = {} self.element_form_default = :unqualified end |
Instance Attribute Details
#document ⇒ Object
Returns the Nokogiri document.
23 24 25 |
# File 'lib/wasabi/parser.rb', line 23 def document @document end |
#element_form_default ⇒ Object
Returns the elementFormDefault value.
41 42 43 |
# File 'lib/wasabi/parser.rb', line 41 def element_form_default @element_form_default end |
#endpoint ⇒ Object
Returns the SOAP endpoint.
38 39 40 |
# File 'lib/wasabi/parser.rb', line 38 def endpoint @endpoint end |
#namespace ⇒ Object
Returns the target namespace.
26 27 28 |
# File 'lib/wasabi/parser.rb', line 26 def namespace @namespace end |
#namespaces ⇒ Object
Returns a map from namespace identifier to namespace URI.
29 30 31 |
# File 'lib/wasabi/parser.rb', line 29 def namespaces @namespaces end |
#operations ⇒ Object
Returns the SOAP operations.
32 33 34 |
# File 'lib/wasabi/parser.rb', line 32 def operations @operations end |
#types ⇒ Object
Returns a map from a type name to a Hash with type information.
35 36 37 |
# File 'lib/wasabi/parser.rb', line 35 def types @types end |
Instance Method Details
#find_namespace(type) ⇒ Object
107 108 109 110 |
# File 'lib/wasabi/parser.rb', line 107 def find_namespace(type) schema_namespace = at_xpath(type, "ancestor::xs:schema/@targetNamespace") schema_namespace ? schema_namespace.to_s : @namespace end |
#parse ⇒ Object
43 44 45 46 47 48 |
# File 'lib/wasabi/parser.rb', line 43 def parse parse_namespaces parse_endpoint parse_operations parse_types end |
#parse_endpoint ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/wasabi/parser.rb', line 61 def parse_endpoint endpoint = at_xpath("wsdl:definitions/wsdl:service//soap11:address/@location") endpoint ||= at_xpath("wsdl:definitions/wsdl:service//soap12:address/@location") begin @endpoint = URI(URI.escape(endpoint.to_s)) if endpoint rescue URI::InvalidURIError @endpoint = nil end end |
#parse_namespaces ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/wasabi/parser.rb', line 50 def parse_namespaces element_form_default = at_xpath("wsdl:definitions/wsdl:types/xs:schema/@elementFormDefault") @element_form_default = element_form_default.to_s.to_sym if element_form_default namespace = at_xpath("wsdl:definitions/@targetNamespace") @namespace = namespace.to_s if namespace @namespaces = @document.collect_namespaces. inject({}) { |result, (key, value)| result.merge(key.gsub(/xmlns:/, "") => value) } end |
#parse_operations ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/wasabi/parser.rb', line 72 def parse_operations operations = xpath("wsdl:definitions/wsdl:binding/wsdl:operation") operations.each do |operation| name = operation.attribute("name").to_s soap_action = at_xpath(operation, ".//soap11:operation/@soapAction") soap_action ||= at_xpath(operation, ".//soap12:operation/@soapAction") 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
91 92 93 94 95 96 97 |
# File 'lib/wasabi/parser.rb', line 91 def parse_types xpath("wsdl:definitions/wsdl:types/xs:schema/xs:element[@name]"). each { |type| process_type(at_xpath(type, "./xs:complexType"), type.attribute("name").to_s) } xpath("wsdl:definitions/wsdl:types/xs:schema/xs:complexType[@name]"). each { |type| process_type(type, type.attribute("name").to_s) } end |
#process_type(type, name) ⇒ Object
99 100 101 102 103 104 105 |
# File 'lib/wasabi/parser.rb', line 99 def process_type(type, name) return unless type @types[name] ||= { :namespace => find_namespace(type) } xpath(type, "./xs:sequence/xs:element"). each { |inner| @types[name][inner.attribute("name").to_s] = { :type => inner.attribute("type").to_s } } end |