class WSDL::SOAP::DriverCreator

Attributes

definitions[R]
drivername_postfix[RW]

Public Class Methods

new(definitions, name_creator, modulepath = nil) click to toggle source
# File lib/wsdl/soap/driverCreator.rb, line 27
def initialize(definitions, name_creator, modulepath = nil)
  @definitions = definitions
  @name_creator = name_creator
  @modulepath = modulepath
  @drivername_postfix = ''
end

Public Instance Methods

dump(porttype = nil) click to toggle source
# File lib/wsdl/soap/driverCreator.rb, line 34
def dump(porttype = nil)
  result = "require 'soap/rpc/driver'\n\n"
  if @modulepath
    modulepath = @modulepath.respond_to?(:lines) ? @modulepath.lines : @modulepath # RubyJedi: compatible with Ruby 1.8.6 and above
    modulepath.each do |name|
      result << "module #{name}\n"
    end
    result << "\n"
  end
  if porttype.nil?
    @definitions.porttypes.each do |type|
      result << dump_porttype(type.name)
      result << "\n"
    end
  else
    result << dump_porttype(porttype)
  end
  if @modulepath
    result << "\n"
    modulepath = @modulepath.respond_to?(:lines) ? @modulepath.lines : @modulepath # RubyJedi: compatible with Ruby 1.8.6 and above
    modulepath.each do |name|
      result << "end\n"
    end
  end
  result
end

Private Instance Methods

dump_porttype(porttype) click to toggle source
# File lib/wsdl/soap/driverCreator.rb, line 63
  def dump_porttype(porttype)
    drivername = porttype.name + @drivername_postfix
    qname = XSD::QName.new(porttype.namespace, drivername)
    class_name = mapped_class_basename(qname, @modulepath)
    defined_const = {}
    mdcreator = MethodDefCreator.new(@definitions, @name_creator, @modulepath, defined_const)
    methoddef = mdcreator.dump(porttype)
    binding = @definitions.bindings.find { |item| item.type == porttype }
    if binding.nil? or binding.soapbinding.nil?
      # not bound or not a SOAP binding
      return ''
    end
    c = XSD::CodeGen::ClassDef.new(class_name, "::SOAP::RPC::Driver")
    c.def_code <<-EOD
Methods = [
#{methoddef.gsub(/^/, "  ")}
]
    EOD
    wsdl_name = @definitions.name ? @definitions.name.name : 'default'
    mrname = safeconstname(wsdl_name + 'MappingRegistry')
    c.def_method("initialize", "endpoint_url = nil") do
      %Q[endpoint_url ||= DefaultEndpointUrl\n] +
      %Q[super(endpoint_url, nil)\n] +
      %Q[self.mapping_registry = #{mrname}::EncodedRegistry\n] +
      %Q[self.literal_mapping_registry = #{mrname}::LiteralRegistry\n] +
      %Q[self.options["protocol.http.ssl_config.verify_mode"] = OpenSSL::SSL::VERIFY_NONE\n] +
      %Q[self.options["protocol.http.basic_auth"] << [endpoint_url, DefaultUser, DefaultPass] if defined?(DefaultUser) && defined?(DefaultPass) \n] +
      %Q[init_methods]
    end
    c.def_privatemethod("init_methods") do
      <<-EOD
        Methods.each do |definitions|
          opt = definitions.last
          if opt[:request_style] == :document
            add_document_operation(*definitions)
          else
            add_rpc_operation(*definitions)
            qname = definitions[0]
            name = definitions[2]
            if qname.name != name and qname.name.capitalize == name.capitalize
              ::SOAP::Mapping.define_singleton_method(self, qname.name) do |*arg|
                __send__(name, *arg)
              end
            end
          end
        end
      EOD
    end
    defined_const.each do |ns, tag|
      c.def_const(tag, dq(ns))
    end
    c.dump
  end