| 1 |
# WSDL4R - Creating servant skelton 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/classDefCreatorSupport' |
|---|
| 11 |
require 'xsd/codegen' |
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
module WSDL |
|---|
| 15 |
module SOAP |
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
class ServantSkeltonCreator |
|---|
| 19 |
include ClassDefCreatorSupport |
|---|
| 20 |
include XSD::CodeGen::GenSupport |
|---|
| 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(porttype = nil) |
|---|
| 31 |
result = "" |
|---|
| 32 |
if @modulepath |
|---|
| 33 |
result << "\n" |
|---|
| 34 |
result << "module #{@modulepath}\n" |
|---|
| 35 |
result << "\n" |
|---|
| 36 |
end |
|---|
| 37 |
if porttype.nil? |
|---|
| 38 |
@definitions.porttypes.each do |porttype| |
|---|
| 39 |
result << dump_porttype(porttype) |
|---|
| 40 |
result << "\n" |
|---|
| 41 |
end |
|---|
| 42 |
else |
|---|
| 43 |
result << dump_porttype(porttype) |
|---|
| 44 |
end |
|---|
| 45 |
if @modulepath |
|---|
| 46 |
result << "\n\n" |
|---|
| 47 |
result << "end\n" |
|---|
| 48 |
end |
|---|
| 49 |
result |
|---|
| 50 |
end |
|---|
| 51 |
|
|---|
| 52 |
private |
|---|
| 53 |
|
|---|
| 54 |
def dump_porttype(porttype) |
|---|
| 55 |
assigned_method = collect_assigned_method(@definitions, porttype.name, @modulepath) |
|---|
| 56 |
class_name = mapped_class_basename(porttype.name, @modulepath) |
|---|
| 57 |
c = XSD::CodeGen::ClassDef.new(class_name) |
|---|
| 58 |
element_definitions = @definitions.collect_elements |
|---|
| 59 |
binding = porttype.find_binding |
|---|
| 60 |
if binding |
|---|
| 61 |
binding.operations.each do |op_bind| |
|---|
| 62 |
operation = op_bind.find_operation |
|---|
| 63 |
if operation.nil? |
|---|
| 64 |
warn("operation not found for binding: #{op_bind}") |
|---|
| 65 |
next |
|---|
| 66 |
end |
|---|
| 67 |
name = assigned_method[op_bind.boundid] || operation.name |
|---|
| 68 |
methodname = safemethodname(name) |
|---|
| 69 |
input = operation.input |
|---|
| 70 |
params = input.find_message.parts.collect { |part| |
|---|
| 71 |
safevarname(part.name) |
|---|
| 72 |
} |
|---|
| 73 |
m = XSD::CodeGen::MethodDef.new(methodname, params) do <<-EOD |
|---|
| 74 |
p [#{params.join(", ")}] |
|---|
| 75 |
raise NotImplementedError.new |
|---|
| 76 |
EOD |
|---|
| 77 |
end |
|---|
| 78 |
m.comment = dump_method_signature(methodname, operation, element_definitions) |
|---|
| 79 |
c.add_method(m) |
|---|
| 80 |
end |
|---|
| 81 |
end |
|---|
| 82 |
c.dump |
|---|
| 83 |
end |
|---|
| 84 |
end |
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
end |
|---|
| 88 |
end |
|---|