| 1 |
# WSDL4R - Creating CGI stub 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 |
|
|---|
| 14 |
|
|---|
| 15 |
module WSDL |
|---|
| 16 |
module SOAP |
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class CGIStubCreator |
|---|
| 20 |
include ClassDefCreatorSupport |
|---|
| 21 |
|
|---|
| 22 |
attr_reader :definitions |
|---|
| 23 |
|
|---|
| 24 |
def initialize(definitions, name_creator, modulepath = nil) |
|---|
| 25 |
@definitions = definitions |
|---|
| 26 |
@name_creator = name_creator |
|---|
| 27 |
@modulepath = modulepath |
|---|
| 28 |
end |
|---|
| 29 |
|
|---|
| 30 |
def dump(service_name) |
|---|
| 31 |
warn("CGI stub can have only 1 port. Creating stub for the first port... Rests are ignored.") |
|---|
| 32 |
services = @definitions.service(service_name) |
|---|
| 33 |
unless services |
|---|
| 34 |
raise RuntimeError.new("service not defined: #{service_name}") |
|---|
| 35 |
end |
|---|
| 36 |
ports = services.ports |
|---|
| 37 |
if ports.empty? |
|---|
| 38 |
raise RuntimeError.new("ports not found for #{service_name}") |
|---|
| 39 |
end |
|---|
| 40 |
port = ports[0] |
|---|
| 41 |
if port.porttype.nil? |
|---|
| 42 |
raise RuntimeError.new("porttype not found for #{port}") |
|---|
| 43 |
end |
|---|
| 44 |
dump_porttype(port.porttype) |
|---|
| 45 |
end |
|---|
| 46 |
|
|---|
| 47 |
private |
|---|
| 48 |
|
|---|
| 49 |
def dump_porttype(porttype) |
|---|
| 50 |
class_name = mapped_class_name(porttype.name, @modulepath) |
|---|
| 51 |
defined_const = {} |
|---|
| 52 |
result = MethodDefCreator.new(@definitions, @name_creator, @modulepath, defined_const).dump(porttype.name) |
|---|
| 53 |
methoddef = result[:methoddef] |
|---|
| 54 |
wsdl_name = @definitions.name ? @definitions.name.name : 'default' |
|---|
| 55 |
mrname = safeconstname(wsdl_name + 'MappingRegistry') |
|---|
| 56 |
c1 = XSD::CodeGen::ClassDef.new(class_name) |
|---|
| 57 |
c1.def_require("soap/rpc/cgistub") |
|---|
| 58 |
c1.def_code <<-EOD |
|---|
| 59 |
Methods = [ |
|---|
| 60 |
#{methoddef.gsub(/^/, " ")} |
|---|
| 61 |
] |
|---|
| 62 |
EOD |
|---|
| 63 |
defined_const.each do |ns, tag| |
|---|
| 64 |
c1.def_const(tag, dq(ns)) |
|---|
| 65 |
end |
|---|
| 66 |
c2 = XSD::CodeGen::ClassDef.new(class_name + "App", |
|---|
| 67 |
"::SOAP::RPC::CGIStub") |
|---|
| 68 |
c2.def_method("initialize", "*arg") do |
|---|
| 69 |
<<-EOD |
|---|
| 70 |
super(*arg) |
|---|
| 71 |
servant = #{class_name}.new |
|---|
| 72 |
#{class_name}::Methods.each do |definitions| |
|---|
| 73 |
opt = definitions.last |
|---|
| 74 |
if opt[:request_style] == :document |
|---|
| 75 |
@router.add_document_operation(servant, *definitions) |
|---|
| 76 |
else |
|---|
| 77 |
@router.add_rpc_operation(servant, *definitions) |
|---|
| 78 |
end |
|---|
| 79 |
end |
|---|
| 80 |
self.mapping_registry = #{mrname}::EncodedRegistry |
|---|
| 81 |
self.literal_mapping_registry = #{mrname}::LiteralRegistry |
|---|
| 82 |
self.level = Logger::Severity::ERROR |
|---|
| 83 |
EOD |
|---|
| 84 |
end |
|---|
| 85 |
c1.dump + "\n" + c2.dump + format(<<-EOD) |
|---|
| 86 |
#{class_name}App.new('app', nil).start |
|---|
| 87 |
EOD |
|---|
| 88 |
end |
|---|
| 89 |
end |
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
end |
|---|
| 93 |
end |
|---|