~ubuntu-branches/ubuntu/hardy/ruby1.8/hardy-updates

« back to all changes in this revision

Viewing changes to lib/wsdl/soap/driverCreator.rb

  • Committer: Bazaar Package Importer
  • Author(s): akira yamada
  • Date: 2007-03-13 22:11:58 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070313221158-h3oql37brlaf2go2
Tags: 1.8.6-1
* new upstream version, 1.8.6.
* libruby1.8 conflicts with libopenssl-ruby1.8 (< 1.8.6) (closes: #410018)
* changed packaging style to cdbs from dbs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# WSDL4R - Creating driver code from WSDL.
 
2
# Copyright (C) 2002, 2003, 2005  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
 
 
25
  def initialize(definitions)
 
26
    @definitions = definitions
 
27
  end
 
28
 
 
29
  def dump(porttype = nil)
 
30
    if porttype.nil?
 
31
      result = ""
 
32
      @definitions.porttypes.each do |type|
 
33
        result << dump_porttype(type.name)
 
34
        result << "\n"
 
35
      end
 
36
    else
 
37
      result = dump_porttype(porttype)
 
38
    end
 
39
    result
 
40
  end
 
41
 
 
42
private
 
43
 
 
44
  def dump_porttype(name)
 
45
    class_name = create_class_name(name)
 
46
    methoddef, types = MethodDefCreator.new(@definitions).dump(name)
 
47
    mr_creator = MappingRegistryCreator.new(@definitions)
 
48
    binding = @definitions.bindings.find { |item| item.type == name }
 
49
    return '' unless binding.soapbinding        # not a SOAP binding
 
50
    address = @definitions.porttype(name).locations[0]
 
51
 
 
52
    c = XSD::CodeGen::ClassDef.new(class_name, "::SOAP::RPC::Driver")
 
53
    c.def_require("soap/rpc/driver")
 
54
    c.def_const("MappingRegistry", "::SOAP::Mapping::Registry.new")
 
55
    c.def_const("DefaultEndpointUrl", ndq(address))
 
56
    c.def_code(mr_creator.dump(types))
 
57
    c.def_code <<-EOD
 
58
Methods = [
 
59
#{methoddef.gsub(/^/, "  ")}
 
60
]
 
61
    EOD
 
62
    c.def_method("initialize", "endpoint_url = nil") do
 
63
      <<-EOD
 
64
        endpoint_url ||= DefaultEndpointUrl
 
65
        super(endpoint_url, nil)
 
66
        self.mapping_registry = MappingRegistry
 
67
        init_methods
 
68
      EOD
 
69
    end
 
70
    c.def_privatemethod("init_methods") do
 
71
      <<-EOD
 
72
        Methods.each do |definitions|
 
73
          opt = definitions.last
 
74
          if opt[:request_style] == :document
 
75
            add_document_operation(*definitions)
 
76
          else
 
77
            add_rpc_operation(*definitions)
 
78
            qname = definitions[0]
 
79
            name = definitions[2]
 
80
            if qname.name != name and qname.name.capitalize == name.capitalize
 
81
              ::SOAP::Mapping.define_singleton_method(self, qname.name) do |*arg|
 
82
                __send__(name, *arg)
 
83
              end
 
84
            end
 
85
          end
 
86
        end
 
87
      EOD
 
88
    end
 
89
    c.dump
 
90
  end
 
91
end
 
92
 
 
93
 
 
94
end
 
95
end