summaryrefslogtreecommitdiff
path: root/ruby_1_8_6/lib/wsdl/soap
diff options
context:
space:
mode:
Diffstat (limited to 'ruby_1_8_6/lib/wsdl/soap')
-rw-r--r--ruby_1_8_6/lib/wsdl/soap/address.rb40
-rw-r--r--ruby_1_8_6/lib/wsdl/soap/binding.rb49
-rw-r--r--ruby_1_8_6/lib/wsdl/soap/body.rb56
-rw-r--r--ruby_1_8_6/lib/wsdl/soap/cgiStubCreator.rb76
-rw-r--r--ruby_1_8_6/lib/wsdl/soap/classDefCreator.rb314
-rw-r--r--ruby_1_8_6/lib/wsdl/soap/classDefCreatorSupport.rb126
-rw-r--r--ruby_1_8_6/lib/wsdl/soap/clientSkeltonCreator.rb78
-rw-r--r--ruby_1_8_6/lib/wsdl/soap/complexType.rb161
-rw-r--r--ruby_1_8_6/lib/wsdl/soap/data.rb42
-rw-r--r--ruby_1_8_6/lib/wsdl/soap/definitions.rb149
-rw-r--r--ruby_1_8_6/lib/wsdl/soap/driverCreator.rb95
-rw-r--r--ruby_1_8_6/lib/wsdl/soap/element.rb28
-rw-r--r--ruby_1_8_6/lib/wsdl/soap/fault.rb56
-rw-r--r--ruby_1_8_6/lib/wsdl/soap/header.rb86
-rw-r--r--ruby_1_8_6/lib/wsdl/soap/headerfault.rb56
-rw-r--r--ruby_1_8_6/lib/wsdl/soap/mappingRegistryCreator.rb92
-rw-r--r--ruby_1_8_6/lib/wsdl/soap/methodDefCreator.rb228
-rw-r--r--ruby_1_8_6/lib/wsdl/soap/operation.rb122
-rw-r--r--ruby_1_8_6/lib/wsdl/soap/servantSkeltonCreator.rb67
-rw-r--r--ruby_1_8_6/lib/wsdl/soap/standaloneServerStubCreator.rb85
-rw-r--r--ruby_1_8_6/lib/wsdl/soap/wsdl2ruby.rb176
21 files changed, 2182 insertions, 0 deletions
diff --git a/ruby_1_8_6/lib/wsdl/soap/address.rb b/ruby_1_8_6/lib/wsdl/soap/address.rb
new file mode 100644
index 0000000000..0b2b59caf0
--- /dev/null
+++ b/ruby_1_8_6/lib/wsdl/soap/address.rb
@@ -0,0 +1,40 @@
+# WSDL4R - WSDL SOAP address definition.
+# Copyright (C) 2002, 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+
+# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
+# redistribute it and/or modify it under the same terms of Ruby's license;
+# either the dual license version in 2003, or any later version.
+
+
+require 'wsdl/info'
+
+
+module WSDL
+module SOAP
+
+
+class Address < Info
+ attr_reader :location
+
+ def initialize
+ super
+ @location = nil
+ end
+
+ def parse_element(element)
+ nil
+ end
+
+ def parse_attr(attr, value)
+ case attr
+ when LocationAttrName
+ @location = value.source
+ else
+ nil
+ end
+ end
+end
+
+
+end
+end
diff --git a/ruby_1_8_6/lib/wsdl/soap/binding.rb b/ruby_1_8_6/lib/wsdl/soap/binding.rb
new file mode 100644
index 0000000000..7e15a99701
--- /dev/null
+++ b/ruby_1_8_6/lib/wsdl/soap/binding.rb
@@ -0,0 +1,49 @@
+# WSDL4R - WSDL SOAP binding definition.
+# Copyright (C) 2002, 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+
+# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
+# redistribute it and/or modify it under the same terms of Ruby's license;
+# either the dual license version in 2003, or any later version.
+
+
+require 'wsdl/info'
+
+
+module WSDL
+module SOAP
+
+
+class Binding < Info
+ attr_reader :style
+ attr_reader :transport
+
+ def initialize
+ super
+ @style = nil
+ @transport = nil
+ end
+
+ def parse_element(element)
+ nil
+ end
+
+ def parse_attr(attr, value)
+ case attr
+ when StyleAttrName
+ if ["document", "rpc"].include?(value.source)
+ @style = value.source.intern
+ else
+ raise Parser::AttributeConstraintError.new(
+ "Unexpected value #{ value }.")
+ end
+ when TransportAttrName
+ @transport = value.source
+ else
+ nil
+ end
+ end
+end
+
+
+end
+end
diff --git a/ruby_1_8_6/lib/wsdl/soap/body.rb b/ruby_1_8_6/lib/wsdl/soap/body.rb
new file mode 100644
index 0000000000..824f8121a2
--- /dev/null
+++ b/ruby_1_8_6/lib/wsdl/soap/body.rb
@@ -0,0 +1,56 @@
+# WSDL4R - WSDL SOAP body definition.
+# Copyright (C) 2002, 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+
+# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
+# redistribute it and/or modify it under the same terms of Ruby's license;
+# either the dual license version in 2003, or any later version.
+
+
+require 'wsdl/info'
+
+
+module WSDL
+module SOAP
+
+
+class Body < Info
+ attr_reader :parts
+ attr_reader :use # required
+ attr_reader :encodingstyle
+ attr_reader :namespace
+
+ def initialize
+ super
+ @parts = nil
+ @use = nil
+ @encodingstyle = nil
+ @namespace = nil
+ end
+
+ def parse_element(element)
+ nil
+ end
+
+ def parse_attr(attr, value)
+ case attr
+ when PartsAttrName
+ @parts = value.source
+ when UseAttrName
+ if ['literal', 'encoded'].include?(value.source)
+ @use = value.source.intern
+ else
+ raise RuntimeError.new("unknown use of soap:body: #{value.source}")
+ end
+ when EncodingStyleAttrName
+ @encodingstyle = value.source
+ when NamespaceAttrName
+ @namespace = value.source
+ else
+ nil
+ end
+ end
+end
+
+
+end
+end
diff --git a/ruby_1_8_6/lib/wsdl/soap/cgiStubCreator.rb b/ruby_1_8_6/lib/wsdl/soap/cgiStubCreator.rb
new file mode 100644
index 0000000000..2c4dff2f62
--- /dev/null
+++ b/ruby_1_8_6/lib/wsdl/soap/cgiStubCreator.rb
@@ -0,0 +1,76 @@
+# WSDL4R - Creating CGI stub code from WSDL.
+# Copyright (C) 2002, 2003, 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+
+# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
+# redistribute it and/or modify it under the same terms of Ruby's license;
+# either the dual license version in 2003, or any later version.
+
+
+require 'wsdl/info'
+require 'wsdl/soap/mappingRegistryCreator'
+require 'wsdl/soap/methodDefCreator'
+require 'wsdl/soap/classDefCreatorSupport'
+
+
+module WSDL
+module SOAP
+
+
+class CGIStubCreator
+ include ClassDefCreatorSupport
+
+ attr_reader :definitions
+
+ def initialize(definitions)
+ @definitions = definitions
+ end
+
+ def dump(service_name)
+ warn("CGI stub can have only 1 port. Creating stub for the first port... Rests are ignored.")
+ port = @definitions.service(service_name).ports[0]
+ dump_porttype(port.porttype.name)
+ end
+
+private
+
+ def dump_porttype(name)
+ class_name = create_class_name(name)
+ methoddef, types = MethodDefCreator.new(@definitions).dump(name)
+ mr_creator = MappingRegistryCreator.new(@definitions)
+ c1 = XSD::CodeGen::ClassDef.new(class_name)
+ c1.def_require("soap/rpc/cgistub")
+ c1.def_require("soap/mapping/registry")
+ c1.def_const("MappingRegistry", "::SOAP::Mapping::Registry.new")
+ c1.def_code(mr_creator.dump(types))
+ c1.def_code <<-EOD
+Methods = [
+#{methoddef.gsub(/^/, " ")}
+]
+ EOD
+ c2 = XSD::CodeGen::ClassDef.new(class_name + "App",
+ "::SOAP::RPC::CGIStub")
+ c2.def_method("initialize", "*arg") do
+ <<-EOD
+ super(*arg)
+ servant = #{class_name}.new
+ #{class_name}::Methods.each do |definitions|
+ opt = definitions.last
+ if opt[:request_style] == :document
+ @router.add_document_operation(servant, *definitions)
+ else
+ @router.add_rpc_operation(servant, *definitions)
+ end
+ end
+ self.mapping_registry = #{class_name}::MappingRegistry
+ self.level = Logger::Severity::ERROR
+ EOD
+ end
+ c1.dump + "\n" + c2.dump + format(<<-EOD)
+ #{class_name}App.new('app', nil).start
+ EOD
+ end
+end
+
+
+end
+end
diff --git a/ruby_1_8_6/lib/wsdl/soap/classDefCreator.rb b/ruby_1_8_6/lib/wsdl/soap/classDefCreator.rb
new file mode 100644
index 0000000000..aeb67c0613
--- /dev/null
+++ b/ruby_1_8_6/lib/wsdl/soap/classDefCreator.rb
@@ -0,0 +1,314 @@
+# WSDL4R - Creating class definition from WSDL
+# Copyright (C) 2002, 2003, 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+
+# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
+# redistribute it and/or modify it under the same terms of Ruby's license;
+# either the dual license version in 2003, or any later version.
+
+
+require 'wsdl/data'
+require 'wsdl/soap/classDefCreatorSupport'
+require 'xsd/codegen'
+
+
+module WSDL
+module SOAP
+
+
+class ClassDefCreator
+ include ClassDefCreatorSupport
+
+ def initialize(definitions)
+ @elements = definitions.collect_elements
+ @simpletypes = definitions.collect_simpletypes
+ @complextypes = definitions.collect_complextypes
+ @faulttypes = nil
+ if definitions.respond_to?(:collect_faulttypes)
+ @faulttypes = definitions.collect_faulttypes
+ end
+ end
+
+ def dump(type = nil)
+ result = "require 'xsd/qname'\n"
+ if type
+ result = dump_classdef(type.name, type)
+ else
+ str = dump_element
+ unless str.empty?
+ result << "\n" unless result.empty?
+ result << str
+ end
+ str = dump_complextype
+ unless str.empty?
+ result << "\n" unless result.empty?
+ result << str
+ end
+ str = dump_simpletype
+ unless str.empty?
+ result << "\n" unless result.empty?
+ result << str
+ end
+ end
+ result
+ end
+
+private
+
+ def dump_element
+ @elements.collect { |ele|
+ if ele.local_complextype
+ dump_classdef(ele.name, ele.local_complextype,
+ ele.elementform == 'qualified')
+ elsif ele.local_simpletype
+ dump_simpletypedef(ele.name, ele.local_simpletype)
+ else
+ nil
+ end
+ }.compact.join("\n")
+ end
+
+ def dump_simpletype
+ @simpletypes.collect { |type|
+ dump_simpletypedef(type.name, type)
+ }.compact.join("\n")
+ end
+
+ def dump_complextype
+ @complextypes.collect { |type|
+ case type.compoundtype
+ when :TYPE_STRUCT, :TYPE_EMPTY
+ dump_classdef(type.name, type)
+ when :TYPE_ARRAY
+ dump_arraydef(type)
+ when :TYPE_SIMPLE
+ dump_simpleclassdef(type)
+ when :TYPE_MAP
+ # mapped as a general Hash
+ nil
+ else
+ raise RuntimeError.new(
+ "unknown kind of complexContent: #{type.compoundtype}")
+ end
+ }.compact.join("\n")
+ end
+
+ def dump_simpletypedef(qname, simpletype)
+ if !simpletype.restriction or simpletype.restriction.enumeration.empty?
+ return nil
+ end
+ c = XSD::CodeGen::ModuleDef.new(create_class_name(qname))
+ c.comment = "#{qname}"
+ const = {}
+ simpletype.restriction.enumeration.each do |value|
+ constname = safeconstname(value)
+ const[constname] ||= 0
+ if (const[constname] += 1) > 1
+ constname += "_#{const[constname]}"
+ end
+ c.def_const(constname, ndq(value))
+ end
+ c.dump
+ end
+
+ def dump_simpleclassdef(type_or_element)
+ qname = type_or_element.name
+ base = create_class_name(type_or_element.simplecontent.base)
+ c = XSD::CodeGen::ClassDef.new(create_class_name(qname), base)
+ c.comment = "#{qname}"
+ c.dump
+ end
+
+ def dump_classdef(qname, typedef, qualified = false)
+ if @faulttypes and @faulttypes.index(qname)
+ c = XSD::CodeGen::ClassDef.new(create_class_name(qname),
+ '::StandardError')
+ else
+ c = XSD::CodeGen::ClassDef.new(create_class_name(qname))
+ end
+ c.comment = "#{qname}"
+ c.def_classvar('schema_type', ndq(qname.name))
+ c.def_classvar('schema_ns', ndq(qname.namespace))
+ c.def_classvar('schema_qualified', dq('true')) if qualified
+ schema_element = []
+ init_lines = ''
+ params = []
+ typedef.each_element do |element|
+ if element.type == XSD::AnyTypeName
+ type = nil
+ elsif klass = element_basetype(element)
+ type = klass.name
+ elsif element.type
+ type = create_class_name(element.type)
+ else
+ type = nil # means anyType.
+ # do we define a class for local complexType from it's name?
+ # type = create_class_name(element.name)
+ # <element>
+ # <complexType>
+ # <seq...>
+ # </complexType>
+ # </element>
+ end
+ name = name_element(element).name
+ attrname = safemethodname?(name) ? name : safemethodname(name)
+ varname = safevarname(name)
+ c.def_attr(attrname, true, varname)
+ init_lines << "@#{varname} = #{varname}\n"
+ if element.map_as_array?
+ params << "#{varname} = []"
+ type << '[]' if type
+ else
+ params << "#{varname} = nil"
+ end
+ # nil means @@schema_ns + varname
+ eleqname =
+ (varname == name && element.name.namespace == qname.namespace) ?
+ nil : element.name
+ schema_element << [varname, eleqname, type]
+ end
+ unless typedef.attributes.empty?
+ define_attribute(c, typedef.attributes)
+ init_lines << "@__xmlattr = {}\n"
+ end
+ c.def_classvar('schema_element',
+ '[' +
+ schema_element.collect { |varname, name, type|
+ '[' +
+ (
+ if name
+ varname.dump + ', [' + ndq(type) + ', ' + dqname(name) + ']'
+ else
+ varname.dump + ', ' + ndq(type)
+ end
+ ) +
+ ']'
+ }.join(', ') +
+ ']'
+ )
+ c.def_method('initialize', *params) do
+ init_lines
+ end
+ c.dump
+ end
+
+ def element_basetype(ele)
+ if klass = basetype_class(ele.type)
+ klass
+ elsif ele.local_simpletype
+ basetype_class(ele.local_simpletype.base)
+ else
+ nil
+ end
+ end
+
+ def attribute_basetype(attr)
+ if klass = basetype_class(attr.type)
+ klass
+ elsif attr.local_simpletype
+ basetype_class(attr.local_simpletype.base)
+ else
+ nil
+ end
+ end
+
+ def basetype_class(type)
+ return nil if type.nil?
+ if simpletype = @simpletypes[type]
+ basetype_mapped_class(simpletype.base)
+ else
+ basetype_mapped_class(type)
+ end
+ end
+
+ def define_attribute(c, attributes)
+ schema_attribute = []
+ attributes.each do |attribute|
+ name = name_attribute(attribute)
+ if klass = attribute_basetype(attribute)
+ type = klass.name
+ else
+ type = nil
+ end
+ methodname = safemethodname('xmlattr_' + name.name)
+ c.def_method(methodname) do <<-__EOD__
+ (@__xmlattr ||= {})[#{dqname(name)}]
+ __EOD__
+ end
+ c.def_method(methodname + '=', 'value') do <<-__EOD__
+ (@__xmlattr ||= {})[#{dqname(name)}] = value
+ __EOD__
+ end
+ schema_attribute << [name, type]
+ end
+ c.def_classvar('schema_attribute',
+ '{' +
+ schema_attribute.collect { |name, type|
+ dqname(name) + ' => ' + ndq(type)
+ }.join(', ') +
+ '}'
+ )
+ end
+
+ def name_element(element)
+ return element.name if element.name
+ return element.ref if element.ref
+ raise RuntimeError.new("cannot define name of #{element}")
+ end
+
+ def name_attribute(attribute)
+ return attribute.name if attribute.name
+ return attribute.ref if attribute.ref
+ raise RuntimeError.new("cannot define name of #{attribute}")
+ end
+
+ DEFAULT_ITEM_NAME = XSD::QName.new(nil, 'item')
+
+ def dump_arraydef(complextype)
+ qname = complextype.name
+ c = XSD::CodeGen::ClassDef.new(create_class_name(qname), '::Array')
+ c.comment = "#{qname}"
+ child_type = complextype.child_type
+ c.def_classvar('schema_type', ndq(child_type.name))
+ c.def_classvar('schema_ns', ndq(child_type.namespace))
+ child_element = complextype.find_aryelement
+ schema_element = []
+ if child_type == XSD::AnyTypeName
+ type = nil
+ elsif child_element and (klass = element_basetype(child_element))
+ type = klass.name
+ elsif child_type
+ type = create_class_name(child_type)
+ else
+ type = nil
+ end
+ if child_element
+ if child_element.map_as_array?
+ type << '[]' if type
+ end
+ child_element_name = child_element.name
+ else
+ child_element_name = DEFAULT_ITEM_NAME
+ end
+ schema_element << [child_element_name.name, child_element_name, type]
+ c.def_classvar('schema_element',
+ '[' +
+ schema_element.collect { |varname, name, type|
+ '[' +
+ (
+ if name
+ varname.dump + ', [' + ndq(type) + ', ' + dqname(name) + ']'
+ else
+ varname.dump + ', ' + ndq(type)
+ end
+ ) +
+ ']'
+ }.join(', ') +
+ ']'
+ )
+ c.dump
+ end
+end
+
+
+end
+end
diff --git a/ruby_1_8_6/lib/wsdl/soap/classDefCreatorSupport.rb b/ruby_1_8_6/lib/wsdl/soap/classDefCreatorSupport.rb
new file mode 100644
index 0000000000..8f335653c8
--- /dev/null
+++ b/ruby_1_8_6/lib/wsdl/soap/classDefCreatorSupport.rb
@@ -0,0 +1,126 @@
+# WSDL4R - Creating class code support from WSDL.
+# Copyright (C) 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+
+# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
+# redistribute it and/or modify it under the same terms of Ruby's license;
+# either the dual license version in 2003, or any later version.
+
+
+require 'wsdl/info'
+require 'soap/mapping'
+require 'soap/mapping/typeMap'
+require 'xsd/codegen/gensupport'
+
+
+module WSDL
+module SOAP
+
+
+module ClassDefCreatorSupport
+ include XSD::CodeGen::GenSupport
+
+ def create_class_name(qname)
+ if klass = basetype_mapped_class(qname)
+ ::SOAP::Mapping::DefaultRegistry.find_mapped_obj_class(klass).name
+ else
+ safeconstname(qname.name)
+ end
+ end
+
+ def basetype_mapped_class(name)
+ ::SOAP::TypeMap[name]
+ end
+
+ def dump_method_signature(operation)
+ name = operation.name.name
+ input = operation.input
+ output = operation.output
+ fault = operation.fault
+ signature = "#{ name }#{ dump_inputparam(input) }"
+ str = <<__EOD__
+# SYNOPSIS
+# #{name}#{dump_inputparam(input)}
+#
+# ARGS
+#{dump_inout_type(input).chomp}
+#
+# RETURNS
+#{dump_inout_type(output).chomp}
+#
+__EOD__
+ unless fault.empty?
+ faultstr = (fault.collect { |f| dump_inout_type(f).chomp }).join(', ')
+ str <<<<__EOD__
+# RAISES
+# #{faultstr}
+#
+__EOD__
+ end
+ str
+ end
+
+ def dq(ele)
+ ele.dump
+ end
+
+ def ndq(ele)
+ ele.nil? ? 'nil' : dq(ele)
+ end
+
+ def sym(ele)
+ ':' + ele
+ end
+
+ def dqname(qname)
+ qname.dump
+ end
+
+private
+
+ def dump_inout_type(param)
+ if param
+ message = param.find_message
+ params = ""
+ message.parts.each do |part|
+ name = safevarname(part.name)
+ if part.type
+ typename = safeconstname(part.type.name)
+ params << add_at("# #{name}", "#{typename} - #{part.type}\n", 20)
+ elsif part.element
+ typename = safeconstname(part.element.name)
+ params << add_at("# #{name}", "#{typename} - #{part.element}\n", 20)
+ end
+ end
+ unless params.empty?
+ return params
+ end
+ end
+ "# N/A\n"
+ end
+
+ def dump_inputparam(input)
+ message = input.find_message
+ params = ""
+ message.parts.each do |part|
+ params << ", " unless params.empty?
+ params << safevarname(part.name)
+ end
+ if params.empty?
+ ""
+ else
+ "(#{ params })"
+ end
+ end
+
+ def add_at(base, str, pos)
+ if base.size >= pos
+ base + ' ' + str
+ else
+ base + ' ' * (pos - base.size) + str
+ end
+ end
+end
+
+
+end
+end
diff --git a/ruby_1_8_6/lib/wsdl/soap/clientSkeltonCreator.rb b/ruby_1_8_6/lib/wsdl/soap/clientSkeltonCreator.rb
new file mode 100644
index 0000000000..916f0d4dc0
--- /dev/null
+++ b/ruby_1_8_6/lib/wsdl/soap/clientSkeltonCreator.rb
@@ -0,0 +1,78 @@
+# WSDL4R - Creating client skelton code from WSDL.
+# Copyright (C) 2002, 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+
+# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
+# redistribute it and/or modify it under the same terms of Ruby's license;
+# either the dual license version in 2003, or any later version.
+
+
+require 'wsdl/info'
+require 'wsdl/soap/classDefCreatorSupport'
+
+
+module WSDL
+module SOAP
+
+
+class ClientSkeltonCreator
+ include ClassDefCreatorSupport
+
+ attr_reader :definitions
+
+ def initialize(definitions)
+ @definitions = definitions
+ end
+
+ def dump(service_name)
+ result = ""
+ @definitions.service(service_name).ports.each do |port|
+ result << dump_porttype(port.porttype.name)
+ result << "\n"
+ end
+ result
+ end
+
+private
+
+ def dump_porttype(name)
+ drv_name = create_class_name(name)
+
+ result = ""
+ result << <<__EOD__
+endpoint_url = ARGV.shift
+obj = #{ drv_name }.new(endpoint_url)
+
+# run ruby with -d to see SOAP wiredumps.
+obj.wiredump_dev = STDERR if $DEBUG
+
+__EOD__
+ @definitions.porttype(name).operations.each do |operation|
+ result << dump_method_signature(operation)
+ result << dump_input_init(operation.input) << "\n"
+ result << dump_operation(operation) << "\n\n"
+ end
+ result
+ end
+
+ def dump_operation(operation)
+ name = operation.name
+ input = operation.input
+ "puts obj.#{ safemethodname(name.name) }#{ dump_inputparam(input) }"
+ end
+
+ def dump_input_init(input)
+ result = input.find_message.parts.collect { |part|
+ safevarname(part.name)
+ }.join(" = ")
+ if result.empty?
+ ""
+ else
+ result << " = nil"
+ end
+ result
+ end
+end
+
+
+end
+end
diff --git a/ruby_1_8_6/lib/wsdl/soap/complexType.rb b/ruby_1_8_6/lib/wsdl/soap/complexType.rb
new file mode 100644
index 0000000000..b2e13d0564
--- /dev/null
+++ b/ruby_1_8_6/lib/wsdl/soap/complexType.rb
@@ -0,0 +1,161 @@
+# WSDL4R - SOAP complexType definition for WSDL.
+# Copyright (C) 2002, 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+
+# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
+# redistribute it and/or modify it under the same terms of Ruby's license;
+# either the dual license version in 2003, or any later version.
+
+
+require 'wsdl/xmlSchema/complexType'
+require 'soap/mapping'
+
+
+module WSDL
+module XMLSchema
+
+
+class ComplexType < Info
+ def compoundtype
+ @compoundtype ||= check_type
+ end
+
+ def check_type
+ if content
+ if attributes.empty? and
+ content.elements.size == 1 and content.elements[0].maxoccurs != '1'
+ if name == ::SOAP::Mapping::MapQName
+ :TYPE_MAP
+ else
+ :TYPE_ARRAY
+ end
+ else
+ :TYPE_STRUCT
+ end
+ elsif complexcontent
+ if complexcontent.base == ::SOAP::ValueArrayName
+ :TYPE_ARRAY
+ else
+ complexcontent.basetype.check_type
+ end
+ elsif simplecontent
+ :TYPE_SIMPLE
+ elsif !attributes.empty?
+ :TYPE_STRUCT
+ else # empty complexType definition (seen in partner.wsdl of salesforce)
+ :TYPE_EMPTY
+ end
+ end
+
+ def child_type(name = nil)
+ case compoundtype
+ when :TYPE_STRUCT
+ if ele = find_element(name)
+ ele.type
+ elsif ele = find_element_by_name(name.name)
+ ele.type
+ end
+ when :TYPE_ARRAY
+ @contenttype ||= content_arytype
+ when :TYPE_MAP
+ item_ele = find_element_by_name("item") or
+ raise RuntimeError.new("'item' element not found in Map definition.")
+ content = item_ele.local_complextype or
+ raise RuntimeError.new("No complexType definition for 'item'.")
+ if ele = content.find_element(name)
+ ele.type
+ elsif ele = content.find_element_by_name(name.name)
+ ele.type
+ end
+ else
+ raise NotImplementedError.new("Unknown kind of complexType.")
+ end
+ end
+
+ def child_defined_complextype(name)
+ ele = nil
+ case compoundtype
+ when :TYPE_STRUCT, :TYPE_MAP
+ unless ele = find_element(name)
+ if name.namespace.nil?
+ ele = find_element_by_name(name.name)
+ end
+ end
+ when :TYPE_ARRAY
+ if content.elements.size == 1
+ ele = content.elements[0]
+ else
+ raise RuntimeError.new("Assert: must not reach.")
+ end
+ else
+ raise RuntimeError.new("Assert: Not implemented.")
+ end
+ unless ele
+ raise RuntimeError.new("Cannot find #{name} as a children of #{@name}.")
+ end
+ ele.local_complextype
+ end
+
+ def find_arytype
+ unless compoundtype == :TYPE_ARRAY
+ raise RuntimeError.new("Assert: not for array")
+ end
+ if complexcontent
+ complexcontent.attributes.each do |attribute|
+ if attribute.ref == ::SOAP::AttrArrayTypeName
+ return attribute.arytype
+ end
+ end
+ if check_array_content(complexcontent.content)
+ return element_simpletype(complexcontent.content.elements[0])
+ end
+ elsif check_array_content(content)
+ return element_simpletype(content.elements[0])
+ end
+ raise RuntimeError.new("Assert: Unknown array definition.")
+ end
+
+ def find_aryelement
+ unless compoundtype == :TYPE_ARRAY
+ raise RuntimeError.new("Assert: not for array")
+ end
+ if complexcontent
+ if check_array_content(complexcontent.content)
+ return complexcontent.content.elements[0]
+ end
+ elsif check_array_content(content)
+ return content.elements[0]
+ end
+ nil # use default item name
+ end
+
+private
+
+ def element_simpletype(element)
+ if element.type
+ element.type
+ elsif element.local_simpletype
+ element.local_simpletype.base
+ else
+ nil
+ end
+ end
+
+ def check_array_content(content)
+ content and content.elements.size == 1 and
+ content.elements[0].maxoccurs != '1'
+ end
+
+ def content_arytype
+ if arytype = find_arytype
+ ns = arytype.namespace
+ name = arytype.name.sub(/\[(?:,)*\]$/, '')
+ XSD::QName.new(ns, name)
+ else
+ nil
+ end
+ end
+end
+
+
+end
+end
diff --git a/ruby_1_8_6/lib/wsdl/soap/data.rb b/ruby_1_8_6/lib/wsdl/soap/data.rb
new file mode 100644
index 0000000000..48512d3751
--- /dev/null
+++ b/ruby_1_8_6/lib/wsdl/soap/data.rb
@@ -0,0 +1,42 @@
+# WSDL4R - WSDL SOAP binding data definitions.
+# Copyright (C) 2002, 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+
+# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
+# redistribute it and/or modify it under the same terms of Ruby's license;
+# either the dual license version in 2003, or any later version.
+
+
+require 'xsd/qname'
+require 'wsdl/soap/definitions'
+require 'wsdl/soap/binding'
+require 'wsdl/soap/operation'
+require 'wsdl/soap/body'
+require 'wsdl/soap/element'
+require 'wsdl/soap/header'
+require 'wsdl/soap/headerfault'
+require 'wsdl/soap/fault'
+require 'wsdl/soap/address'
+require 'wsdl/soap/complexType'
+
+
+module WSDL
+module SOAP
+
+
+HeaderFaultName = XSD::QName.new(SOAPBindingNamespace, 'headerfault')
+
+LocationAttrName = XSD::QName.new(nil, 'location')
+StyleAttrName = XSD::QName.new(nil, 'style')
+TransportAttrName = XSD::QName.new(nil, 'transport')
+UseAttrName = XSD::QName.new(nil, 'use')
+PartsAttrName = XSD::QName.new(nil, 'parts')
+PartAttrName = XSD::QName.new(nil, 'part')
+NameAttrName = XSD::QName.new(nil, 'name')
+MessageAttrName = XSD::QName.new(nil, 'message')
+EncodingStyleAttrName = XSD::QName.new(nil, 'encodingStyle')
+NamespaceAttrName = XSD::QName.new(nil, 'namespace')
+SOAPActionAttrName = XSD::QName.new(nil, 'soapAction')
+
+
+end
+end
diff --git a/ruby_1_8_6/lib/wsdl/soap/definitions.rb b/ruby_1_8_6/lib/wsdl/soap/definitions.rb
new file mode 100644
index 0000000000..b014d5af6b
--- /dev/null
+++ b/ruby_1_8_6/lib/wsdl/soap/definitions.rb
@@ -0,0 +1,149 @@
+# WSDL4R - WSDL additional definitions for SOAP.
+# Copyright (C) 2002-2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+
+# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
+# redistribute it and/or modify it under the same terms of Ruby's license;
+# either the dual license version in 2003, or any later version.
+
+
+require 'wsdl/info'
+require 'xsd/namedelements'
+require 'soap/mapping'
+
+
+module WSDL
+
+
+class Definitions < Info
+ def self.soap_rpc_complextypes
+ types = XSD::NamedElements.new
+ types << array_complextype
+ types << fault_complextype
+ types << exception_complextype
+ types
+ end
+
+ def self.array_complextype
+ type = XMLSchema::ComplexType.new(::SOAP::ValueArrayName)
+ type.complexcontent = XMLSchema::ComplexContent.new
+ type.complexcontent.base = ::SOAP::ValueArrayName
+ attr = XMLSchema::Attribute.new
+ attr.ref = ::SOAP::AttrArrayTypeName
+ anytype = XSD::AnyTypeName.dup
+ anytype.name += '[]'
+ attr.arytype = anytype
+ type.complexcontent.attributes << attr
+ type
+ end
+
+=begin
+<xs:complexType name="Fault" final="extension">
+ <xs:sequence>
+ <xs:element name="faultcode" type="xs:QName" />
+ <xs:element name="faultstring" type="xs:string" />
+ <xs:element name="faultactor" type="xs:anyURI" minOccurs="0" />
+ <xs:element name="detail" type="tns:detail" minOccurs="0" />
+ </xs:sequence>
+</xs:complexType>
+=end
+ def self.fault_complextype
+ type = XMLSchema::ComplexType.new(::SOAP::EleFaultName)
+ faultcode = XMLSchema::Element.new(::SOAP::EleFaultCodeName, XSD::XSDQName::Type)
+ faultstring = XMLSchema::Element.new(::SOAP::EleFaultStringName, XSD::XSDString::Type)
+ faultactor = XMLSchema::Element.new(::SOAP::EleFaultActorName, XSD::XSDAnyURI::Type)
+ faultactor.minoccurs = 0
+ detail = XMLSchema::Element.new(::SOAP::EleFaultDetailName, XSD::AnyTypeName)
+ detail.minoccurs = 0
+ type.all_elements = [faultcode, faultstring, faultactor, detail]
+ type.final = 'extension'
+ type
+ end
+
+ def self.exception_complextype
+ type = XMLSchema::ComplexType.new(XSD::QName.new(
+ ::SOAP::Mapping::RubyCustomTypeNamespace, 'SOAPException'))
+ excn_name = XMLSchema::Element.new(XSD::QName.new(nil, 'excn_type_name'), XSD::XSDString::Type)
+ cause = XMLSchema::Element.new(XSD::QName.new(nil, 'cause'), XSD::AnyTypeName)
+ backtrace = XMLSchema::Element.new(XSD::QName.new(nil, 'backtrace'), ::SOAP::ValueArrayName)
+ message = XMLSchema::Element.new(XSD::QName.new(nil, 'message'), XSD::XSDString::Type)
+ type.all_elements = [excn_name, cause, backtrace, message]
+ type
+ end
+
+ def soap_rpc_complextypes(binding)
+ types = rpc_operation_complextypes(binding)
+ types + self.class.soap_rpc_complextypes
+ end
+
+ def collect_faulttypes
+ result = []
+ collect_fault_messages.each do |name|
+ faultparts = message(name).parts
+ if faultparts.size != 1
+ raise RuntimeError.new("expecting fault message to have only 1 part")
+ end
+ if result.index(faultparts[0].type).nil?
+ result << faultparts[0].type
+ end
+ end
+ result
+ end
+
+private
+
+ def collect_fault_messages
+ result = []
+ porttypes.each do |porttype|
+ porttype.operations.each do |operation|
+ operation.fault.each do |fault|
+ if result.index(fault.message).nil?
+ result << fault.message
+ end
+ end
+ end
+ end
+ result
+ end
+
+ def rpc_operation_complextypes(binding)
+ types = XSD::NamedElements.new
+ binding.operations.each do |op_bind|
+ if op_bind_rpc?(op_bind)
+ operation = op_bind.find_operation
+ if op_bind.input
+ type = XMLSchema::ComplexType.new(op_bind.soapoperation_name)
+ message = messages[operation.input.message]
+ type.sequence_elements = elements_from_message(message)
+ types << type
+ end
+ if op_bind.output
+ type = XMLSchema::ComplexType.new(operation.outputname)
+ message = messages[operation.output.message]
+ type.sequence_elements = elements_from_message(message)
+ types << type
+ end
+ end
+ end
+ types
+ end
+
+ def op_bind_rpc?(op_bind)
+ op_bind.soapoperation_style == :rpc
+ end
+
+ def elements_from_message(message)
+ message.parts.collect { |part|
+ if part.element
+ collect_elements[part.element]
+ elsif part.name.nil? or part.type.nil?
+ raise RuntimeError.new("part of a message must be an element or typed")
+ else
+ qname = XSD::QName.new(nil, part.name)
+ XMLSchema::Element.new(qname, part.type)
+ end
+ }
+ end
+end
+
+
+end
diff --git a/ruby_1_8_6/lib/wsdl/soap/driverCreator.rb b/ruby_1_8_6/lib/wsdl/soap/driverCreator.rb
new file mode 100644
index 0000000000..eba7c158a2
--- /dev/null
+++ b/ruby_1_8_6/lib/wsdl/soap/driverCreator.rb
@@ -0,0 +1,95 @@
+# WSDL4R - Creating driver code from WSDL.
+# Copyright (C) 2002, 2003, 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+
+# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
+# redistribute it and/or modify it under the same terms of Ruby's license;
+# either the dual license version in 2003, or any later version.
+
+
+require 'wsdl/info'
+require 'wsdl/soap/mappingRegistryCreator'
+require 'wsdl/soap/methodDefCreator'
+require 'wsdl/soap/classDefCreatorSupport'
+require 'xsd/codegen'
+
+
+module WSDL
+module SOAP
+
+
+class DriverCreator
+ include ClassDefCreatorSupport
+
+ attr_reader :definitions
+
+ def initialize(definitions)
+ @definitions = definitions
+ end
+
+ def dump(porttype = nil)
+ if porttype.nil?
+ result = ""
+ @definitions.porttypes.each do |type|
+ result << dump_porttype(type.name)
+ result << "\n"
+ end
+ else
+ result = dump_porttype(porttype)
+ end
+ result
+ end
+
+private
+
+ def dump_porttype(name)
+ class_name = create_class_name(name)
+ methoddef, types = MethodDefCreator.new(@definitions).dump(name)
+ mr_creator = MappingRegistryCreator.new(@definitions)
+ binding = @definitions.bindings.find { |item| item.type == name }
+ return '' unless binding.soapbinding # not a SOAP binding
+ address = @definitions.porttype(name).locations[0]
+
+ c = XSD::CodeGen::ClassDef.new(class_name, "::SOAP::RPC::Driver")
+ c.def_require("soap/rpc/driver")
+ c.def_const("MappingRegistry", "::SOAP::Mapping::Registry.new")
+ c.def_const("DefaultEndpointUrl", ndq(address))
+ c.def_code(mr_creator.dump(types))
+ c.def_code <<-EOD
+Methods = [
+#{methoddef.gsub(/^/, " ")}
+]
+ EOD
+ c.def_method("initialize", "endpoint_url = nil") do
+ <<-EOD
+ endpoint_url ||= DefaultEndpointUrl
+ super(endpoint_url, nil)
+ self.mapping_registry = MappingRegistry
+ init_methods
+ EOD
+ end
+ c.def_privatemethod("init_methods") do
+ <<-EOD
+ Methods.each do |definitions|
+ opt = definitions.last
+ if opt[:request_style] == :document
+ add_document_operation(*definitions)
+ else
+ add_rpc_operation(*definitions)
+ qname = definitions[0]
+ name = definitions[2]
+ if qname.name != name and qname.name.capitalize == name.capitalize
+ ::SOAP::Mapping.define_singleton_method(self, qname.name) do |*arg|
+ __send__(name, *arg)
+ end
+ end
+ end
+ end
+ EOD
+ end
+ c.dump
+ end
+end
+
+
+end
+end
diff --git a/ruby_1_8_6/lib/wsdl/soap/element.rb b/ruby_1_8_6/lib/wsdl/soap/element.rb
new file mode 100644
index 0000000000..0fa6017c5b
--- /dev/null
+++ b/ruby_1_8_6/lib/wsdl/soap/element.rb
@@ -0,0 +1,28 @@
+# WSDL4R - XMLSchema element definition for WSDL.
+# Copyright (C) 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+
+# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
+# redistribute it and/or modify it under the same terms of Ruby's license;
+# either the dual license version in 2003, or any later version.
+
+
+require 'wsdl/xmlSchema/element'
+
+
+module WSDL
+module XMLSchema
+
+
+class Element < Info
+ def map_as_array?
+ maxoccurs != '1'
+ end
+
+ def attributes
+ @local_complextype.attributes
+ end
+end
+
+
+end
+end
diff --git a/ruby_1_8_6/lib/wsdl/soap/fault.rb b/ruby_1_8_6/lib/wsdl/soap/fault.rb
new file mode 100644
index 0000000000..2862b659ab
--- /dev/null
+++ b/ruby_1_8_6/lib/wsdl/soap/fault.rb
@@ -0,0 +1,56 @@
+# WSDL4R - WSDL SOAP body definition.
+# Copyright (C) 2002, 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+
+# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
+# redistribute it and/or modify it under the same terms of Ruby's license;
+# either the dual license version in 2003, or any later version.
+
+
+require 'wsdl/info'
+
+
+module WSDL
+module SOAP
+
+
+class Fault < Info
+ attr_reader :name # required
+ attr_reader :use # required
+ attr_reader :encodingstyle
+ attr_reader :namespace
+
+ def initialize
+ super
+ @name = nil
+ @use = nil
+ @encodingstyle = nil
+ @namespace = nil
+ end
+
+ def targetnamespace
+ parent.targetnamespace
+ end
+
+ def parse_element(element)
+ nil
+ end
+
+ def parse_attr(attr, value)
+ case attr
+ when NameAttrName
+ @name = XSD::QName.new(targetnamespace, value.source)
+ when UseAttrName
+ @use = value.source
+ when EncodingStyleAttrName
+ @encodingstyle = value.source
+ when NamespaceAttrName
+ @namespace = value.source
+ else
+ nil
+ end
+ end
+end
+
+
+end
+end
diff --git a/ruby_1_8_6/lib/wsdl/soap/header.rb b/ruby_1_8_6/lib/wsdl/soap/header.rb
new file mode 100644
index 0000000000..8d7c4e9d70
--- /dev/null
+++ b/ruby_1_8_6/lib/wsdl/soap/header.rb
@@ -0,0 +1,86 @@
+# WSDL4R - WSDL SOAP body definition.
+# Copyright (C) 2002, 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+
+# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
+# redistribute it and/or modify it under the same terms of Ruby's license;
+# either the dual license version in 2003, or any later version.
+
+
+require 'wsdl/info'
+
+
+module WSDL
+module SOAP
+
+
+class Header < Info
+ attr_reader :headerfault
+
+ attr_reader :message # required
+ attr_reader :part # required
+ attr_reader :use # required
+ attr_reader :encodingstyle
+ attr_reader :namespace
+
+ def initialize
+ super
+ @message = nil
+ @part = nil
+ @use = nil
+ @encodingstyle = nil
+ @namespace = nil
+ @headerfault = nil
+ end
+
+ def targetnamespace
+ parent.targetnamespace
+ end
+
+ def find_message
+ root.message(@message) or raise RuntimeError.new("#{@message} not found")
+ end
+
+ def find_part
+ find_message.parts.each do |part|
+ if part.name == @part
+ return part
+ end
+ end
+ raise RuntimeError.new("#{@part} not found")
+ end
+
+ def parse_element(element)
+ case element
+ when HeaderFaultName
+ o = WSDL::SOAP::HeaderFault.new
+ @headerfault = o
+ o
+ else
+ nil
+ end
+ end
+
+ def parse_attr(attr, value)
+ case attr
+ when MessageAttrName
+ if value.namespace.nil?
+ value = XSD::QName.new(targetnamespace, value.source)
+ end
+ @message = value
+ when PartAttrName
+ @part = value.source
+ when UseAttrName
+ @use = value.source
+ when EncodingStyleAttrName
+ @encodingstyle = value.source
+ when NamespaceAttrName
+ @namespace = value.source
+ else
+ nil
+ end
+ end
+end
+
+
+end
+end
diff --git a/ruby_1_8_6/lib/wsdl/soap/headerfault.rb b/ruby_1_8_6/lib/wsdl/soap/headerfault.rb
new file mode 100644
index 0000000000..d6b14f2646
--- /dev/null
+++ b/ruby_1_8_6/lib/wsdl/soap/headerfault.rb
@@ -0,0 +1,56 @@
+# WSDL4R - WSDL SOAP body definition.
+# Copyright (C) 2002, 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+
+# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
+# redistribute it and/or modify it under the same terms of Ruby's license;
+# either the dual license version in 2003, or any later version.
+
+
+require 'wsdl/info'
+
+
+module WSDL
+module SOAP
+
+
+class HeaderFault < Info
+ attr_reader :message # required
+ attr_reader :part # required
+ attr_reader :use # required
+ attr_reader :encodingstyle
+ attr_reader :namespace
+
+ def initialize
+ super
+ @message = nil
+ @part = nil
+ @use = nil
+ @encodingstyle = nil
+ @namespace = nil
+ end
+
+ def parse_element(element)
+ nil
+ end
+
+ def parse_attr(attr, value)
+ case attr
+ when MessageAttrName
+ @message = value
+ when PartAttrName
+ @part = value.source
+ when UseAttrName
+ @use = value.source
+ when EncodingStyleAttrName
+ @encodingstyle = value.source
+ when NamespaceAttrName
+ @namespace = value.source
+ else
+ nil
+ end
+ end
+end
+
+
+end
+end
diff --git a/ruby_1_8_6/lib/wsdl/soap/mappingRegistryCreator.rb b/ruby_1_8_6/lib/wsdl/soap/mappingRegistryCreator.rb
new file mode 100644
index 0000000000..8669339ce4
--- /dev/null
+++ b/ruby_1_8_6/lib/wsdl/soap/mappingRegistryCreator.rb
@@ -0,0 +1,92 @@
+# WSDL4R - Creating MappingRegistry code from WSDL.
+# Copyright (C) 2002, 2003, 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+
+# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
+# redistribute it and/or modify it under the same terms of Ruby's license;
+# either the dual license version in 2003, or any later version.
+
+
+require 'wsdl/info'
+require 'wsdl/soap/classDefCreatorSupport'
+
+
+module WSDL
+module SOAP
+
+
+class MappingRegistryCreator
+ include ClassDefCreatorSupport
+
+ attr_reader :definitions
+
+ def initialize(definitions)
+ @definitions = definitions
+ @complextypes = @definitions.collect_complextypes
+ @types = nil
+ end
+
+ def dump(types)
+ @types = types
+ map_cache = []
+ map = ""
+ @types.each do |type|
+ if map_cache.index(type).nil?
+ map_cache << type
+ if type.namespace != XSD::Namespace
+ if typemap = dump_typemap(type)
+ map << typemap
+ end
+ end
+ end
+ end
+ return map
+ end
+
+private
+
+ def dump_typemap(type)
+ if definedtype = @complextypes[type]
+ case definedtype.compoundtype
+ when :TYPE_STRUCT
+ dump_struct_typemap(definedtype)
+ when :TYPE_ARRAY
+ dump_array_typemap(definedtype)
+ when :TYPE_MAP, :TYPE_EMPTY
+ nil
+ else
+ raise NotImplementedError.new("must not reach here")
+ end
+ end
+ end
+
+ def dump_struct_typemap(definedtype)
+ ele = definedtype.name
+ return <<__EOD__
+MappingRegistry.set(
+ #{create_class_name(ele)},
+ ::SOAP::SOAPStruct,
+ ::SOAP::Mapping::Registry::TypedStructFactory,
+ { :type => #{dqname(ele)} }
+)
+__EOD__
+ end
+
+ def dump_array_typemap(definedtype)
+ ele = definedtype.name
+ arytype = definedtype.find_arytype || XSD::AnyTypeName
+ type = XSD::QName.new(arytype.namespace, arytype.name.sub(/\[(?:,)*\]$/, ''))
+ @types << type
+ return <<__EOD__
+MappingRegistry.set(
+ #{create_class_name(ele)},
+ ::SOAP::SOAPArray,
+ ::SOAP::Mapping::Registry::TypedArrayFactory,
+ { :type => #{dqname(type)} }
+)
+__EOD__
+ end
+end
+
+
+end
+end
diff --git a/ruby_1_8_6/lib/wsdl/soap/methodDefCreator.rb b/ruby_1_8_6/lib/wsdl/soap/methodDefCreator.rb
new file mode 100644
index 0000000000..f3ffadbe69
--- /dev/null
+++ b/ruby_1_8_6/lib/wsdl/soap/methodDefCreator.rb
@@ -0,0 +1,228 @@
+# WSDL4R - Creating driver code from WSDL.
+# Copyright (C) 2002, 2003, 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+
+# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
+# redistribute it and/or modify it under the same terms of Ruby's license;
+# either the dual license version in 2003, or any later version.
+
+
+require 'wsdl/info'
+require 'wsdl/soap/classDefCreatorSupport'
+require 'soap/rpc/element'
+
+
+module WSDL
+module SOAP
+
+
+class MethodDefCreator
+ include ClassDefCreatorSupport
+
+ attr_reader :definitions
+
+ def initialize(definitions)
+ @definitions = definitions
+ @simpletypes = @definitions.collect_simpletypes
+ @complextypes = @definitions.collect_complextypes
+ @elements = @definitions.collect_elements
+ @types = []
+ end
+
+ def dump(porttype)
+ @types.clear
+ result = ""
+ operations = @definitions.porttype(porttype).operations
+ binding = @definitions.porttype_binding(porttype)
+ operations.each do |operation|
+ op_bind = binding.operations[operation.name]
+ next unless op_bind # no binding is defined
+ next unless op_bind.soapoperation # not a SOAP operation binding
+ result << ",\n" unless result.empty?
+ result << dump_method(operation, op_bind).chomp
+ end
+ return result, @types
+ end
+
+ def collect_rpcparameter(operation)
+ result = operation.inputparts.collect { |part|
+ collect_type(part.type)
+ param_set(::SOAP::RPC::SOAPMethod::IN, part.name, rpcdefinedtype(part))
+ }
+ outparts = operation.outputparts
+ if outparts.size > 0
+ retval = outparts[0]
+ collect_type(retval.type)
+ result << param_set(::SOAP::RPC::SOAPMethod::RETVAL, retval.name,
+ rpcdefinedtype(retval))
+ cdr(outparts).each { |part|
+ collect_type(part.type)
+ result << param_set(::SOAP::RPC::SOAPMethod::OUT, part.name,
+ rpcdefinedtype(part))
+ }
+ end
+ result
+ end
+
+ def collect_documentparameter(operation)
+ param = []
+ operation.inputparts.each do |input|
+ param << param_set(::SOAP::RPC::SOAPMethod::IN, input.name,
+ documentdefinedtype(input), elementqualified(input))
+ end
+ operation.outputparts.each do |output|
+ param << param_set(::SOAP::RPC::SOAPMethod::OUT, output.name,
+ documentdefinedtype(output), elementqualified(output))
+ end
+ param
+ end
+
+private
+
+ def dump_method(operation, binding)
+ name = safemethodname(operation.name.name)
+ name_as = operation.name.name
+ style = binding.soapoperation_style
+ inputuse = binding.input.soapbody_use
+ outputuse = binding.output.soapbody_use
+ namespace = binding.input.soapbody.namespace
+ if style == :rpc
+ qname = XSD::QName.new(namespace, name_as)
+ paramstr = param2str(collect_rpcparameter(operation))
+ else
+ qname = nil
+ paramstr = param2str(collect_documentparameter(operation))
+ end
+ if paramstr.empty?
+ paramstr = '[]'
+ else
+ paramstr = "[ " << paramstr.split(/\r?\n/).join("\n ") << " ]"
+ end
+ definitions = <<__EOD__
+#{ndq(binding.soapaction)},
+ #{dq(name)},
+ #{paramstr},
+ { :request_style => #{sym(style.id2name)}, :request_use => #{sym(inputuse.id2name)},
+ :response_style => #{sym(style.id2name)}, :response_use => #{sym(outputuse.id2name)} }
+__EOD__
+ if style == :rpc
+ return <<__EOD__
+[ #{qname.dump},
+ #{definitions}]
+__EOD__
+ else
+ return <<__EOD__
+[ #{definitions}]
+__EOD__
+ end
+ end
+
+ def rpcdefinedtype(part)
+ if mapped = basetype_mapped_class(part.type)
+ ['::' + mapped.name]
+ elsif definedtype = @simpletypes[part.type]
+ ['::' + basetype_mapped_class(definedtype.base).name]
+ elsif definedtype = @elements[part.element]
+ #['::SOAP::SOAPStruct', part.element.namespace, part.element.name]
+ ['nil', part.element.namespace, part.element.name]
+ elsif definedtype = @complextypes[part.type]
+ case definedtype.compoundtype
+ when :TYPE_STRUCT, :TYPE_EMPTY # ToDo: empty should be treated as void.
+ type = create_class_name(part.type)
+ [type, part.type.namespace, part.type.name]
+ when :TYPE_MAP
+ [Hash.name, part.type.namespace, part.type.name]
+ when :TYPE_ARRAY
+ arytype = definedtype.find_arytype || XSD::AnyTypeName
+ ns = arytype.namespace
+ name = arytype.name.sub(/\[(?:,)*\]$/, '')
+ type = create_class_name(XSD::QName.new(ns, name))
+ [type + '[]', ns, name]
+ else
+ raise NotImplementedError.new("must not reach here")
+ end
+ else
+ raise RuntimeError.new("part: #{part.name} cannot be resolved")
+ end
+ end
+
+ def documentdefinedtype(part)
+ if mapped = basetype_mapped_class(part.type)
+ ['::' + mapped.name, nil, part.name]
+ elsif definedtype = @simpletypes[part.type]
+ ['::' + basetype_mapped_class(definedtype.base).name, nil, part.name]
+ elsif definedtype = @elements[part.element]
+ ['::SOAP::SOAPElement', part.element.namespace, part.element.name]
+ elsif definedtype = @complextypes[part.type]
+ ['::SOAP::SOAPElement', part.type.namespace, part.type.name]
+ else
+ raise RuntimeError.new("part: #{part.name} cannot be resolved")
+ end
+ end
+
+ def elementqualified(part)
+ if mapped = basetype_mapped_class(part.type)
+ false
+ elsif definedtype = @simpletypes[part.type]
+ false
+ elsif definedtype = @elements[part.element]
+ definedtype.elementform == 'qualified'
+ elsif definedtype = @complextypes[part.type]
+ false
+ else
+ raise RuntimeError.new("part: #{part.name} cannot be resolved")
+ end
+ end
+
+ def param_set(io_type, name, type, ele = nil)
+ [io_type, name, type, ele]
+ end
+
+ def collect_type(type)
+ # ignore inline type definition.
+ return if type.nil?
+ return if @types.include?(type)
+ @types << type
+ return unless @complextypes[type]
+ @complextypes[type].each_element do |element|
+ collect_type(element.type)
+ end
+ end
+
+ def param2str(params)
+ params.collect { |param|
+ io, name, type, ele = param
+ unless ele.nil?
+ "[#{dq(io)}, #{dq(name)}, #{type2str(type)}, #{ele2str(ele)}]"
+ else
+ "[#{dq(io)}, #{dq(name)}, #{type2str(type)}]"
+ end
+ }.join(",\n")
+ end
+
+ def type2str(type)
+ if type.size == 1
+ "[#{dq(type[0])}]"
+ else
+ "[#{dq(type[0])}, #{ndq(type[1])}, #{dq(type[2])}]"
+ end
+ end
+
+ def ele2str(ele)
+ qualified = ele
+ if qualified
+ "true"
+ else
+ "false"
+ end
+ end
+
+ def cdr(ary)
+ result = ary.dup
+ result.shift
+ result
+ end
+end
+
+
+end
+end
diff --git a/ruby_1_8_6/lib/wsdl/soap/operation.rb b/ruby_1_8_6/lib/wsdl/soap/operation.rb
new file mode 100644
index 0000000000..502d34a07d
--- /dev/null
+++ b/ruby_1_8_6/lib/wsdl/soap/operation.rb
@@ -0,0 +1,122 @@
+# WSDL4R - WSDL SOAP operation definition.
+# Copyright (C) 2002, 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+
+# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
+# redistribute it and/or modify it under the same terms of Ruby's license;
+# either the dual license version in 2003, or any later version.
+
+
+require 'wsdl/info'
+
+
+module WSDL
+module SOAP
+
+
+class Operation < Info
+ class OperationInfo
+ attr_reader :style
+ attr_reader :op_name
+ attr_reader :optype_name
+ attr_reader :headerparts
+ attr_reader :bodyparts
+ attr_reader :faultpart
+ attr_reader :soapaction
+
+ def initialize(style, op_name, optype_name, headerparts, bodyparts, faultpart, soapaction)
+ @style = style
+ @op_name = op_name
+ @optype_name = optype_name
+ @headerparts = headerparts
+ @bodyparts = bodyparts
+ @faultpart = faultpart
+ @soapaction = soapaction
+ end
+ end
+
+ attr_reader :soapaction
+ attr_reader :style
+
+ def initialize
+ super
+ @soapaction = nil
+ @style = nil
+ end
+
+ def parse_element(element)
+ nil
+ end
+
+ def parse_attr(attr, value)
+ case attr
+ when StyleAttrName
+ if ["document", "rpc"].include?(value.source)
+ @style = value.source.intern
+ else
+ raise Parser::AttributeConstraintError.new(
+ "Unexpected value #{ value }.")
+ end
+ when SOAPActionAttrName
+ @soapaction = value.source
+ else
+ nil
+ end
+ end
+
+ def input_info
+ name_info = parent.find_operation.input_info
+ param_info(name_info, parent.input)
+ end
+
+ def output_info
+ name_info = parent.find_operation.output_info
+ param_info(name_info, parent.output)
+ end
+
+ def operation_style
+ return @style if @style
+ if parent_binding.soapbinding
+ return parent_binding.soapbinding.style
+ end
+ nil
+ end
+
+private
+
+ def parent_binding
+ parent.parent
+ end
+
+ def param_info(name_info, param)
+ op_name = name_info.op_name
+ optype_name = name_info.optype_name
+
+ soapheader = param.soapheader
+ headerparts = soapheader.collect { |item| item.find_part }
+
+ soapbody = param.soapbody
+ if soapbody.encodingstyle and
+ soapbody.encodingstyle != ::SOAP::EncodingNamespace
+ raise NotImplementedError.new(
+ "EncodingStyle '#{ soapbody.encodingstyle }' not supported.")
+ end
+ if soapbody.namespace
+ op_name = XSD::QName.new(soapbody.namespace, op_name.name)
+ end
+ if soapbody.parts
+ target = soapbody.parts.split(/\s+/)
+ bodyparts = name_info.parts.find_all { |part|
+ target.include?(part.name)
+ }
+ else
+ bodyparts = name_info.parts
+ end
+
+ faultpart = nil
+ OperationInfo.new(operation_style, op_name, optype_name, headerparts, bodyparts, faultpart, parent.soapaction)
+ end
+end
+
+
+end
+end
diff --git a/ruby_1_8_6/lib/wsdl/soap/servantSkeltonCreator.rb b/ruby_1_8_6/lib/wsdl/soap/servantSkeltonCreator.rb
new file mode 100644
index 0000000000..88294ffed8
--- /dev/null
+++ b/ruby_1_8_6/lib/wsdl/soap/servantSkeltonCreator.rb
@@ -0,0 +1,67 @@
+# WSDL4R - Creating servant skelton code from WSDL.
+# Copyright (C) 2002, 2003, 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+
+# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
+# redistribute it and/or modify it under the same terms of Ruby's license;
+# either the dual license version in 2003, or any later version.
+
+
+require 'wsdl/info'
+require 'wsdl/soap/classDefCreatorSupport'
+require 'xsd/codegen'
+
+
+module WSDL
+module SOAP
+
+
+class ServantSkeltonCreator
+ include ClassDefCreatorSupport
+ include XSD::CodeGen::GenSupport
+
+ attr_reader :definitions
+
+ def initialize(definitions)
+ @definitions = definitions
+ end
+
+ def dump(porttype = nil)
+ if porttype.nil?
+ result = ""
+ @definitions.porttypes.each do |type|
+ result << dump_porttype(type.name)
+ result << "\n"
+ end
+ else
+ result = dump_porttype(porttype)
+ end
+ result
+ end
+
+private
+
+ def dump_porttype(name)
+ class_name = create_class_name(name)
+ c = XSD::CodeGen::ClassDef.new(class_name)
+ operations = @definitions.porttype(name).operations
+ operations.each do |operation|
+ name = safemethodname(operation.name.name)
+ input = operation.input
+ params = input.find_message.parts.collect { |part|
+ safevarname(part.name)
+ }
+ m = XSD::CodeGen::MethodDef.new(name, params) do <<-EOD
+ p [#{params.join(", ")}]
+ raise NotImplementedError.new
+ EOD
+ end
+ m.comment = dump_method_signature(operation)
+ c.add_method(m)
+ end
+ c.dump
+ end
+end
+
+
+end
+end
diff --git a/ruby_1_8_6/lib/wsdl/soap/standaloneServerStubCreator.rb b/ruby_1_8_6/lib/wsdl/soap/standaloneServerStubCreator.rb
new file mode 100644
index 0000000000..0b751b5153
--- /dev/null
+++ b/ruby_1_8_6/lib/wsdl/soap/standaloneServerStubCreator.rb
@@ -0,0 +1,85 @@
+# WSDL4R - Creating standalone server stub code from WSDL.
+# Copyright (C) 2002, 2003, 2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+
+# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
+# redistribute it and/or modify it under the same terms of Ruby's license;
+# either the dual license version in 2003, or any later version.
+
+
+require 'wsdl/info'
+require 'wsdl/soap/mappingRegistryCreator'
+require 'wsdl/soap/methodDefCreator'
+require 'wsdl/soap/classDefCreatorSupport'
+
+
+module WSDL
+module SOAP
+
+
+class StandaloneServerStubCreator
+ include ClassDefCreatorSupport
+
+ attr_reader :definitions
+
+ def initialize(definitions)
+ @definitions = definitions
+ end
+
+ def dump(service_name)
+ warn("- Standalone stub can have only 1 port for now. So creating stub for the first port and rests are ignored.")
+ warn("- Standalone server stub ignores port location defined in WSDL. Location is http://localhost:10080/ by default. Generated client from WSDL must be configured to point this endpoint manually.")
+ port = @definitions.service(service_name).ports[0]
+ dump_porttype(port.porttype.name)
+ end
+
+private
+
+ def dump_porttype(name)
+ class_name = create_class_name(name)
+ methoddef, types = MethodDefCreator.new(@definitions).dump(name)
+ mr_creator = MappingRegistryCreator.new(@definitions)
+
+ c1 = XSD::CodeGen::ClassDef.new(class_name)
+ c1.def_require("soap/rpc/standaloneServer")
+ c1.def_require("soap/mapping/registry")
+ c1.def_const("MappingRegistry", "::SOAP::Mapping::Registry.new")
+ c1.def_code(mr_creator.dump(types))
+ c1.def_code <<-EOD
+Methods = [
+#{methoddef.gsub(/^/, " ")}
+]
+ EOD
+ c2 = XSD::CodeGen::ClassDef.new(class_name + "App",
+ "::SOAP::RPC::StandaloneServer")
+ c2.def_method("initialize", "*arg") do
+ <<-EOD
+ super(*arg)
+ servant = #{class_name}.new
+ #{class_name}::Methods.each do |definitions|
+ opt = definitions.last
+ if opt[:request_style] == :document
+ @router.add_document_operation(servant, *definitions)
+ else
+ @router.add_rpc_operation(servant, *definitions)
+ end
+ end
+ self.mapping_registry = #{class_name}::MappingRegistry
+ EOD
+ end
+ c1.dump + "\n" + c2.dump + format(<<-EOD)
+
+ if $0 == __FILE__
+ # Change listen port.
+ server = #{class_name}App.new('app', nil, '0.0.0.0', 10080)
+ trap(:INT) do
+ server.shutdown
+ end
+ server.start
+ end
+ EOD
+ end
+end
+
+
+end
+end
diff --git a/ruby_1_8_6/lib/wsdl/soap/wsdl2ruby.rb b/ruby_1_8_6/lib/wsdl/soap/wsdl2ruby.rb
new file mode 100644
index 0000000000..16b05fb032
--- /dev/null
+++ b/ruby_1_8_6/lib/wsdl/soap/wsdl2ruby.rb
@@ -0,0 +1,176 @@
+# WSDL4R - WSDL to ruby mapping library.
+# Copyright (C) 2002-2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+
+# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
+# redistribute it and/or modify it under the same terms of Ruby's license;
+# either the dual license version in 2003, or any later version.
+
+
+require 'logger'
+require 'xsd/qname'
+require 'wsdl/importer'
+require 'wsdl/soap/classDefCreator'
+require 'wsdl/soap/servantSkeltonCreator'
+require 'wsdl/soap/driverCreator'
+require 'wsdl/soap/clientSkeltonCreator'
+require 'wsdl/soap/standaloneServerStubCreator'
+require 'wsdl/soap/cgiStubCreator'
+
+
+module WSDL
+module SOAP
+
+
+class WSDL2Ruby
+ attr_accessor :location
+ attr_reader :opt
+ attr_accessor :logger
+ attr_accessor :basedir
+
+ def run
+ unless @location
+ raise RuntimeError, "WSDL location not given"
+ end
+ @wsdl = import(@location)
+ @name = @wsdl.name ? @wsdl.name.name : 'default'
+ create_file
+ end
+
+private
+
+ def initialize
+ @location = nil
+ @opt = {}
+ @logger = Logger.new(STDERR)
+ @basedir = nil
+ @wsdl = nil
+ @name = nil
+ end
+
+ def create_file
+ create_classdef if @opt.key?('classdef')
+ create_servant_skelton(@opt['servant_skelton']) if @opt.key?('servant_skelton')
+ create_cgi_stub(@opt['cgi_stub']) if @opt.key?('cgi_stub')
+ create_standalone_server_stub(@opt['standalone_server_stub']) if @opt.key?('standalone_server_stub')
+ create_driver(@opt['driver']) if @opt.key?('driver')
+ create_client_skelton(@opt['client_skelton']) if @opt.key?('client_skelton')
+ end
+
+ def create_classdef
+ @logger.info { "Creating class definition." }
+ @classdef_filename = @name + '.rb'
+ check_file(@classdef_filename) or return
+ write_file(@classdef_filename) do |f|
+ f << WSDL::SOAP::ClassDefCreator.new(@wsdl).dump
+ end
+ end
+
+ def create_client_skelton(servicename)
+ @logger.info { "Creating client skelton." }
+ servicename ||= @wsdl.services[0].name.name
+ @client_skelton_filename = servicename + 'Client.rb'
+ check_file(@client_skelton_filename) or return
+ write_file(@client_skelton_filename) do |f|
+ f << shbang << "\n"
+ f << "require '#{@driver_filename}'\n\n" if @driver_filename
+ f << WSDL::SOAP::ClientSkeltonCreator.new(@wsdl).dump(
+ create_name(servicename))
+ end
+ end
+
+ def create_servant_skelton(porttypename)
+ @logger.info { "Creating servant skelton." }
+ @servant_skelton_filename = (porttypename || @name + 'Servant') + '.rb'
+ check_file(@servant_skelton_filename) or return
+ write_file(@servant_skelton_filename) do |f|
+ f << "require '#{@classdef_filename}'\n\n" if @classdef_filename
+ f << WSDL::SOAP::ServantSkeltonCreator.new(@wsdl).dump(
+ create_name(porttypename))
+ end
+ end
+
+ def create_cgi_stub(servicename)
+ @logger.info { "Creating CGI stub." }
+ servicename ||= @wsdl.services[0].name.name
+ @cgi_stubFilename = servicename + '.cgi'
+ check_file(@cgi_stubFilename) or return
+ write_file(@cgi_stubFilename) do |f|
+ f << shbang << "\n"
+ if @servant_skelton_filename
+ f << "require '#{@servant_skelton_filename}'\n\n"
+ end
+ f << WSDL::SOAP::CGIStubCreator.new(@wsdl).dump(create_name(servicename))
+ end
+ end
+
+ def create_standalone_server_stub(servicename)
+ @logger.info { "Creating standalone stub." }
+ servicename ||= @wsdl.services[0].name.name
+ @standalone_server_stub_filename = servicename + '.rb'
+ check_file(@standalone_server_stub_filename) or return
+ write_file(@standalone_server_stub_filename) do |f|
+ f << shbang << "\n"
+ f << "require '#{@servant_skelton_filename}'\n\n" if @servant_skelton_filename
+ f << WSDL::SOAP::StandaloneServerStubCreator.new(@wsdl).dump(
+ create_name(servicename))
+ end
+ end
+
+ def create_driver(porttypename)
+ @logger.info { "Creating driver." }
+ @driver_filename = (porttypename || @name) + 'Driver.rb'
+ check_file(@driver_filename) or return
+ write_file(@driver_filename) do |f|
+ f << "require '#{@classdef_filename}'\n\n" if @classdef_filename
+ f << WSDL::SOAP::DriverCreator.new(@wsdl).dump(
+ create_name(porttypename))
+ end
+ end
+
+ def write_file(filename)
+ if @basedir
+ filename = File.join(basedir, filename)
+ end
+ File.open(filename, "w") do |f|
+ yield f
+ end
+ end
+
+ def check_file(filename)
+ if @basedir
+ filename = File.join(basedir, filename)
+ end
+ if FileTest.exist?(filename)
+ if @opt.key?('force')
+ @logger.warn {
+ "File '#{filename}' exists but overrides it."
+ }
+ true
+ else
+ @logger.warn {
+ "File '#{filename}' exists. #{$0} did not override it."
+ }
+ false
+ end
+ else
+ @logger.info { "Creates file '#{filename}'." }
+ true
+ end
+ end
+
+ def shbang
+ "#!/usr/bin/env ruby"
+ end
+
+ def create_name(name)
+ name ? XSD::QName.new(@wsdl.targetnamespace, name) : nil
+ end
+
+ def import(location)
+ WSDL::Importer.import(location)
+ end
+end
+
+
+end
+end