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

root/tags/RELEASE_1_5_6/bin/wsdl2ruby.rb

Revision 1746, 3.3 kB (checked in by nahi, 2 years ago)

'--type client' wrongly overwrote --classdef definition. closes #282.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to author date id revision
Line 
1 #!/usr/bin/env ruby
2
3 require 'getoptlong'
4 require 'logger'
5 require 'wsdl/soap/wsdl2ruby'
6
7
8 class WSDL2RubyApp < Logger::Application
9 private
10
11   OptSet = [
12     ['--wsdl','-w', GetoptLong::REQUIRED_ARGUMENT],
13     ['--module_path','-m', GetoptLong::REQUIRED_ARGUMENT],
14     ['--type','-t', GetoptLong::REQUIRED_ARGUMENT],
15     ['--classdef','-e', GetoptLong::OPTIONAL_ARGUMENT],
16     ['--mapping_registry','-r', GetoptLong::OPTIONAL_ARGUMENT],
17     ['--client_skelton','-c', GetoptLong::OPTIONAL_ARGUMENT],
18     ['--servant_skelton','-s', GetoptLong::OPTIONAL_ARGUMENT],
19     ['--cgi_stub','-g', GetoptLong::OPTIONAL_ARGUMENT],
20     ['--standalone_server_stub','-a', GetoptLong::OPTIONAL_ARGUMENT],
21     ['--driver','-d', GetoptLong::OPTIONAL_ARGUMENT],
22     ['--force','-f', GetoptLong::NO_ARGUMENT],
23     ['--quiet','-q', GetoptLong::NO_ARGUMENT],
24   ]
25
26   def initialize
27     super('app')
28     STDERR.sync = true
29     self.level = Logger::FATAL
30   end
31
32   def run
33     @worker = WSDL::SOAP::WSDL2Ruby.new
34     @worker.logger = @log
35     location, opt = parse_opt(GetoptLong.new(*OptSet))
36     usage_exit unless location
37     @worker.location = location
38     if opt['quiet']
39       self.level = Logger::FATAL
40     else
41       self.level = Logger::INFO
42     end
43     @worker.opt.update(opt)
44     @worker.run
45     0
46   end
47
48   def usage_exit
49     puts <<__EOU__
50 Usage: #{ $0 } --wsdl wsdl_location [options]
51   wsdl_location: filename or URL
52
53 Example:
54   For server side:
55     #{ $0 } --wsdl myapp.wsdl --type server
56   For client side:
57     #{ $0 } --wsdl myapp.wsdl --type client
58
59 Options:
60   --wsdl wsdl_location
61   --type server|client
62     --type server implies;
63         --classdef --mapping_registry --servant_skelton --standalone_server_stub
64     --type client implies;
65         --classdef --mapping_registry --client_skelton --driver
66   --classdef [filenameprefix]
67   --mapping_registry
68   --client_skelton [servicename]
69   --servant_skelton [porttypename]
70   --cgi_stub [servicename]
71   --standalone_server_stub [servicename]
72   --driver [porttypename]
73   --module_path [Module::Path::Name]
74   --force
75   --quiet
76
77 Terminology:
78   Client <-> Driver <-(SOAP)-> Stub <-> Servant
79
80   Driver and Stub: Automatically generated
81   Client and Servant: Skelton generated (you should change)
82 __EOU__
83     exit 1
84   end
85
86   def parse_opt(getoptlong)
87     opt = {}
88     wsdl = nil
89     begin
90       getoptlong.each do |name, arg|
91         case name
92         when "--wsdl"
93           wsdl = arg
94         when "--module_path"
95           opt['module_path'] = arg
96         when "--type"
97           case arg
98           when "server"
99             opt['classdef'] ||= nil
100             opt['mapping_registry'] ||= nil
101             opt['servant_skelton'] ||= nil
102             opt['standalone_server_stub'] ||= nil
103           when "client"
104             opt['classdef'] ||= nil
105             opt['mapping_registry'] ||= nil
106             opt['driver'] ||= nil
107             opt['client_skelton'] ||= nil
108           else
109             raise ArgumentError.new("Unknown type #{ arg }")
110           end
111         when "--classdef", "--mapping_registry",
112             "--client_skelton", "--servant_skelton",
113             "--cgi_stub", "--standalone_server_stub",
114             "--driver"
115           opt[name.sub(/^--/, '')] = arg.empty? ? nil : arg
116         when "--force"
117           opt['force'] = true
118         when "--quiet"
119           opt['quiet'] = true
120         else
121           raise ArgumentError.new("Unknown type #{ arg }")
122         end
123       end
124     rescue
125       usage_exit
126     end
127     return wsdl, opt
128   end
129 end
130
131 WSDL2RubyApp.new.start
Note: See TracBrowser for help on using the browser.