/tools/Ruby/lib/ruby/1.8/wsdl/soap/clientSkeltonCreator.rb

http://github.com/agross/netopenspace · Ruby · 78 lines · 53 code · 19 blank · 6 comment · 2 complexity · dc3772965932b5792e74d74e3f27bc86 MD5 · raw file

  1. # WSDL4R - Creating client skelton code from WSDL.
  2. # Copyright (C) 2002, 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
  3. # This program is copyrighted free software by NAKAMURA, Hiroshi. You can
  4. # redistribute it and/or modify it under the same terms of Ruby's license;
  5. # either the dual license version in 2003, or any later version.
  6. require 'wsdl/info'
  7. require 'wsdl/soap/classDefCreatorSupport'
  8. module WSDL
  9. module SOAP
  10. class ClientSkeltonCreator
  11. include ClassDefCreatorSupport
  12. attr_reader :definitions
  13. def initialize(definitions)
  14. @definitions = definitions
  15. end
  16. def dump(service_name)
  17. result = ""
  18. @definitions.service(service_name).ports.each do |port|
  19. result << dump_porttype(port.porttype.name)
  20. result << "\n"
  21. end
  22. result
  23. end
  24. private
  25. def dump_porttype(name)
  26. drv_name = create_class_name(name)
  27. result = ""
  28. result << <<__EOD__
  29. endpoint_url = ARGV.shift
  30. obj = #{ drv_name }.new(endpoint_url)
  31. # run ruby with -d to see SOAP wiredumps.
  32. obj.wiredump_dev = STDERR if $DEBUG
  33. __EOD__
  34. @definitions.porttype(name).operations.each do |operation|
  35. result << dump_method_signature(operation)
  36. result << dump_input_init(operation.input) << "\n"
  37. result << dump_operation(operation) << "\n\n"
  38. end
  39. result
  40. end
  41. def dump_operation(operation)
  42. name = operation.name
  43. input = operation.input
  44. "puts obj.#{ safemethodname(name.name) }#{ dump_inputparam(input) }"
  45. end
  46. def dump_input_init(input)
  47. result = input.find_message.parts.collect { |part|
  48. safevarname(part.name)
  49. }.join(" = ")
  50. if result.empty?
  51. ""
  52. else
  53. result << " = nil"
  54. end
  55. result
  56. end
  57. end
  58. end
  59. end