Welcome to the "trac"-ing site of soap4r!
[soap4r] [httpclient] [openpgp4u] [pkcs1] [logger] [csv] [vtr]

root/branches/1_5/lib/wsdl/soap/clientSkeltonCreator.rb

Revision 2015, 2.5 kB (checked in by nahi, 11 hours ago)
  • ruby-1.8.7 warning cleanups. closes #497.
  • Property svn:eol-style set to native
  • Property svn:keywords set to author date id revision
Line 
1 # WSDL4R - Creating client skelton code from WSDL.
2 # Copyright (C) 2000-2007  NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
3
4 # This program is copyrighted free software by NAKAMURA, Hiroshi.  You can
5 # redistribute it and/or modify it under the same terms of Ruby's license;
6 # either the dual license version in 2003, or any later version.
7
8
9 require 'wsdl/info'
10 require 'wsdl/soap/classDefCreatorSupport'
11
12
13 module WSDL
14 module SOAP
15
16
17 class ClientSkeltonCreator
18   include ClassDefCreatorSupport
19
20   attr_reader :definitions
21
22   def initialize(definitions, name_creator, modulepath = nil)
23     @definitions = definitions
24     @name_creator = name_creator
25     @modulepath = modulepath
26   end
27
28   def dump(service_name)
29     services = @definitions.service(service_name)
30     unless services
31       raise RuntimeError.new("service not defined: #{service_name}")
32     end
33     result = ""
34     if @modulepath
35       result << "\n"
36       result << "module #{@modulepath}\n"
37       result << "\n"
38     end
39     services.ports.each do |port|
40       result << dump_porttype(port.porttype)
41       result << "\n"
42     end
43     if @modulepath
44       result << "\n\n"
45       result << "end\n"
46     end
47     result
48   end
49
50 private
51
52   def dump_porttype(porttype)
53     assigned_method = collect_assigned_method(@definitions, porttype.name, @modulepath)
54     drv_name = mapped_class_basename(porttype.name, @modulepath)
55
56     result = ""
57     result << <<__EOD__
58 endpoint_url = ARGV.shift
59 obj = #{ drv_name }.new(endpoint_url)
60
61 # run ruby with -d to see SOAP wiredumps.
62 obj.wiredump_dev = STDERR if $DEBUG
63
64 __EOD__
65     element_definitions = @definitions.collect_elements
66     binding = porttype.find_binding
67     if binding
68       binding.operations.each do |op_bind|
69         operation = op_bind.find_operation
70         if operation.nil?
71           warn("operation not found for binding: #{op_bind}")
72           next
73         end
74         name = assigned_method[op_bind.boundid] || operation.name
75         result << dump_method_signature(name, operation, element_definitions)
76         result << dump_input_init(operation.input) << "\n"
77         result << dump_operation(name, operation) << "\n\n"
78       end
79     end
80     result
81   end
82
83   def dump_operation(name, operation)
84     input = operation.input
85     "puts obj.#{ safemethodname(name) }#{ dump_inputparam(input) }"
86   end
87
88   def dump_input_init(input)
89     result = input.find_message.parts.collect { |part|
90       safevarname(part.name)
91     }.join(" = ")
92     if result.empty?
93       ""
94     else
95       result << " = nil"
96     end
97     result
98   end
99 end
100
101
102 end
103 end
Note: See TracBrowser for help on using the browser.