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

root/tags/RELEASE_1_5_7/bin/xsd2ruby.rb

Revision 1857, 1.9 kB (checked in by nahi, 2 years ago)
  • let xsd2ruby.rb generate a mapping registry and a mapper from XML Schema definition. the mapper has obj2xml and xml2obj which uses the generated mapping registry. you can use this instead of XSD::Mapping.obj2xml and XSD::Mapping.xml2obj which does not know anything about mapping. closes #362, #363.
Line 
1 #!/usr/bin/env ruby
2
3 require 'getoptlong'
4 require 'logger'
5 require 'wsdl/xmlSchema/xsd2ruby'
6
7
8 class XSD2RubyApp < Logger::Application
9 private
10
11   OptSet = [
12     ['--xsd','-x', GetoptLong::REQUIRED_ARGUMENT],
13     ['--module_path','-m', GetoptLong::REQUIRED_ARGUMENT],
14     ['--classdef','-e', GetoptLong::OPTIONAL_ARGUMENT],
15     ['--mapping_registry','-r', GetoptLong::NO_ARGUMENT],
16     ['--mapper','-p', GetoptLong::NO_ARGUMENT],
17     ['--force','-f', GetoptLong::NO_ARGUMENT],
18     ['--quiet','-q', GetoptLong::NO_ARGUMENT],
19   ]
20
21   def initialize
22     super('app')
23     STDERR.sync = true
24     self.level = Logger::FATAL
25   end
26
27   def run
28     @worker = WSDL::XMLSchema::XSD2Ruby.new
29     @worker.logger = @log
30     location, opt = parse_opt(GetoptLong.new(*OptSet))
31     usage_exit unless location
32     @worker.location = location
33     if opt['quiet']
34       self.level = Logger::FATAL
35     else
36       self.level = Logger::INFO
37     end
38     @worker.opt.update(opt)
39     @worker.run
40     0
41   end
42
43   def usage_exit
44     puts <<__EOU__
45 Usage: #{ $0 } --xsd xsd_location [options]
46   xsd_location: filename or URL
47
48 Example:
49   #{ $0 } --xsd myapp.xsd --classdef foo
50
51 Options:
52   --xsd xsd_location
53   --classdef [filenameprefix]
54   --mapping_registry
55   --mapper
56   --module_path [Module::Path::Name]
57   --force
58   --quiet
59 __EOU__
60     exit 1
61   end
62
63   def parse_opt(getoptlong)
64     opt = {}
65     xsd = nil
66     begin
67       getoptlong.each do |name, arg|
68         case name
69         when "--xsd"
70           xsd = arg
71         when "--module_path"
72           opt['module_path'] = arg
73         when "--classdef", "--mapping_registry", "--mapper"
74           opt[name.sub(/^--/, '')] = arg.empty? ? nil : arg
75         when "--force"
76           opt['force'] = true
77         when "--quiet"
78           opt['quiet'] = true
79         else
80           raise ArgumentError.new("Unknown type #{ arg }")
81         end
82       end
83     rescue
84       usage_exit
85     end
86     return xsd, opt
87   end
88 end
89
90 XSD2RubyApp.new.start
Note: See TracBrowser for help on using the browser.