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

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

Revision 2015, 3.2 kB (checked in by nahi, 12 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 driver 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/mappingRegistryCreator'
11 require 'wsdl/soap/methodDefCreator'
12 require 'wsdl/soap/classDefCreatorSupport'
13 require 'xsd/codegen'
14
15
16 module WSDL
17 module SOAP
18
19
20 class DriverCreator
21   include ClassDefCreatorSupport
22
23   attr_reader :definitions
24   attr_accessor :drivername_postfix
25
26   def initialize(definitions, name_creator, modulepath = nil)
27     @definitions = definitions
28     @name_creator = name_creator
29     @modulepath = modulepath
30     @drivername_postfix = ''
31   end
32
33   def dump(porttype = nil)
34     result = "require 'soap/rpc/driver'\n\n"
35     if @modulepath
36       result << "module #{@modulepath}\n"
37       result << "\n"
38     end
39     if porttype.nil?
40       @definitions.porttypes.each do |type|
41         result << dump_porttype(type.name)
42         result << "\n"
43       end
44     else
45       result << dump_porttype(porttype)
46     end
47     if @modulepath
48       result << "\n"
49       result << "end\n"
50     end
51     result
52   end
53
54 private
55
56   def dump_porttype(porttype)
57     drivername = porttype.name + @drivername_postfix
58     qname = XSD::QName.new(porttype.namespace, drivername)
59     class_name = mapped_class_basename(qname, @modulepath)
60     defined_const = {}
61     mdcreator = MethodDefCreator.new(@definitions, @name_creator, @modulepath, defined_const)
62     result = mdcreator.dump(porttype)
63     methoddef = result[:methoddef]
64     binding = @definitions.bindings.find { |item| item.type == porttype }
65     if binding.nil? or binding.soapbinding.nil?
66       # not bound or not a SOAP binding
67       return ''
68     end
69     address = @definitions.porttype(porttype).locations[0]
70
71     c = XSD::CodeGen::ClassDef.new(class_name, "::SOAP::RPC::Driver")
72     c.def_const("DefaultEndpointUrl", ndq(address))
73     c.def_code <<-EOD
74 Methods = [
75 #{methoddef.gsub(/^/, "  ")}
76 ]
77     EOD
78     wsdl_name = @definitions.name ? @definitions.name.name : 'default'
79     mrname = safeconstname(wsdl_name + 'MappingRegistry')
80     c.def_method("initialize", "endpoint_url = nil") do
81       %Q[endpoint_url ||= DefaultEndpointUrl\n] +
82       %Q[super(endpoint_url, nil)\n] +
83       %Q[self.mapping_registry = #{mrname}::EncodedRegistry\n] +
84       %Q[self.literal_mapping_registry = #{mrname}::LiteralRegistry\n] +
85       %Q[init_methods]
86     end
87     c.def_privatemethod("init_methods") do
88       <<-EOD
89         Methods.each do |definitions|
90           opt = definitions.last
91           if opt[:request_style] == :document
92             add_document_operation(*definitions)
93           else
94             add_rpc_operation(*definitions)
95             qname = definitions[0]
96             name = definitions[2]
97             if qname.name != name and qname.name.capitalize == name.capitalize
98               ::SOAP::Mapping.define_singleton_method(self, qname.name) do |*arg|
99                 __send__(name, *arg)
100               end
101             end
102           end
103         end
104       EOD
105     end
106     defined_const.each do |ns, tag|
107       c.def_const(tag, dq(ns))
108     end
109     c.dump
110   end
111 end
112
113
114 end
115 end
Note: See TracBrowser for help on using the browser.