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

root/tags/RELEASE_1_5_4/bin/wsdl2ruby.rb

Revision 1437, 2.9 kB (checked in by nahi, 4 years ago)

let wsdl2ruby.rb and xsd2ruby.rb be a library. bin/wsdl2ruby.rb and bin/xsd2ruby.rb use these libraries. let tests use the libraries. fixes #69.

  • 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     ['--type','-t', GetoptLong::REQUIRED_ARGUMENT],
14     ['--classdef','-e', GetoptLong::NO_ARGUMENT],
15     ['--client_skelton','-c', GetoptLong::OPTIONAL_ARGUMENT],
16     ['--servant_skelton','-s', GetoptLong::OPTIONAL_ARGUMENT],
17     ['--cgi_stub','-g', GetoptLong::OPTIONAL_ARGUMENT],
18     ['--standalone_server_stub','-a', GetoptLong::OPTIONAL_ARGUMENT],
19     ['--driver','-d', GetoptLong::OPTIONAL_ARGUMENT],
20     ['--force','-f', GetoptLong::NO_ARGUMENT],
21     ['--quiet','-q', GetoptLong::NO_ARGUMENT],
22   ]
23
24   def initialize
25     super('app')
26     STDERR.sync = true
27     self.level = Logger::FATAL
28   end
29
30   def run
31     @worker = WSDL::SOAP::WSDL2Ruby.new
32     @worker.logger = @log
33     location, opt = parse_opt(GetoptLong.new(*OptSet))
34     usage_exit unless location
35     @worker.location = location
36     if opt['quiet']
37       self.level = Logger::FATAL
38     else
39       self.level = Logger::INFO
40     end
41     @worker.opt.update(opt)
42     @worker.run
43     0
44   end
45
46   def usage_exit
47     puts <<__EOU__
48 Usage: #{ $0 } --wsdl wsdl_location [options]
49   wsdl_location: filename or URL
50
51 Example:
52   For server side:
53     #{ $0 } --wsdl myapp.wsdl --type server
54   For client side:
55     #{ $0 } --wsdl myapp.wsdl --type client
56
57 Options:
58   --wsdl wsdl_location
59   --type server|client
60     --type server implies;
61         --classdef
62         --servant_skelton
63         --standalone_server_stub
64     --type client implies;
65         --classdef
66         --client_skelton
67         --driver
68   --classdef
69   --client_skelton [servicename]
70   --servant_skelton [porttypename]
71   --cgi_stub [servicename]
72   --standalone_server_stub [servicename]
73   --driver [porttypename]
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 "--type"
95           case arg
96           when "server"
97             opt['classdef'] = nil
98             opt['servant_skelton'] = nil
99             opt['standalone_server_stub'] = nil
100           when "client"
101             opt['classdef'] = nil
102             opt['driver'] = nil
103             opt['client_skelton'] = nil
104           else
105             raise ArgumentError.new("Unknown type #{ arg }")
106           end
107         when "--classdef", "--client_skelton", "--servant_skelton",
108             "--cgi_stub", "--standalone_server_stub", "--driver"
109           opt[name.sub(/^--/, '')] = arg.empty? ? nil : arg
110         when "--force"
111           opt['force'] = true
112         when "--quiet"
113           opt['quiet'] = true
114         else
115           raise ArgumentError.new("Unknown type #{ arg }")
116         end
117       end
118     rescue
119       usage_exit
120     end
121     return wsdl, opt
122   end
123 end
124
125 WSDL2RubyApp.new.start
Note: See TracBrowser for help on using the browser.