summaryrefslogtreecommitdiffstats
path: root/lib/wsdl/soap/classDefCreator.rb
diff options
context:
space:
mode:
authornahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-05-22 13:03:38 +0000
committernahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-05-22 13:03:38 +0000
commit810a605c34d97fa878cb5b615b9e95a2fee84ca8 (patch)
treec17440206af25b52f47b1c391f818e126a994d0a /lib/wsdl/soap/classDefCreator.rb
parent11491c909c15feef7731483824ab29ce1d434739 (diff)
downloadruby-810a605c34d97fa878cb5b615b9e95a2fee84ca8.tar.gz
ruby-810a605c34d97fa878cb5b615b9e95a2fee84ca8.tar.xz
ruby-810a605c34d97fa878cb5b615b9e95a2fee84ca8.zip
* lib/{soap,wsdl,xsd}, test/{soap,wsdl,xsd}: imported soap4r/1.5.4.
== SOAP client and server == === for both client side and server side === * improved document/literal service support. style(rpc,document)/use(encoding, literal) combination are all supported. for the detail about combination, see test/soap/test_style.rb. * let WSDLEncodedRegistry#soap2obj map SOAP/OM to Ruby according to WSDL as well as obj2soap. closes #70. * let SOAP::Mapping::Object handle XML attribute for doc/lit service. you can set/get XML attribute via accessor methods which as a name 'xmlattr_' prefixed (<foo name="bar"/> -> Foo#xmlattr_name). === client side === * WSDLDriver capitalized name operation bug fixed. from 1.5.3-ruby1.8.2, operation which has capitalized name (such as KeywordSearchRequest in AWS) is defined as a method having uncapitalized name. (converted with GenSupport.safemethodname to handle operation name 'foo-bar'). it introduced serious incompatibility; in the past, it was defined as a capitalized. define capitalized method as well under that circumstance. * added new factory interface 'WSDLDriverFactory#create_rpc_driver' to create RPC::Driver, not WSDLDriver (RPC::Driver and WSDLDriver are merged). 'WSDLDriverFactory#create_driver' still creates WSDLDriver for compatibility but it warns that the method is deprecated. please use create_rpc_driver instead of create_driver. * allow to use an URI object as an endpoint_url even with net/http, not http-access2. === server side === * added mod_ruby support to SOAP::CGIStub. rename a CGI script server.cgi to server.rb and let mod_ruby's RubyHandler handles the script. CGIStub detects if it's running under mod_ruby environment or not. * added fcgi support to SOAP::CGIStub. see the sample at sample/soap/calc/server.fcgi. (almost same as server.cgi but has fcgi handler at the bottom.) * allow to return a SOAPFault object to respond customized SOAP fault. * added the interface 'generate_explicit_type' for server side (CGIStub, HTTPServer). call 'self.generate_explicit_type = true' if you want to return simplified XML even if it's rpc/encoded service. == WSDL == === WSDL definition === * improved XML Schema support such as extension, restriction, simpleType, complexType + simpleContent, ref, length, import, include. * reduced "unknown element/attribute" warnings (warn only 1 time for each QName). * importing XSD file at schemaLocation with xsd:import. === code generation from WSDL === * generator crashed when there's '-' in defined element/attribute name. * added ApacheMap WSDL definition. * sample/{soap,wsdl}: removed. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@8500 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/wsdl/soap/classDefCreator.rb')
-rw-r--r--lib/wsdl/soap/classDefCreator.rb226
1 files changed, 152 insertions, 74 deletions
diff --git a/lib/wsdl/soap/classDefCreator.rb b/lib/wsdl/soap/classDefCreator.rb
index 13f7802b7..deda4f131 100644
--- a/lib/wsdl/soap/classDefCreator.rb
+++ b/lib/wsdl/soap/classDefCreator.rb
@@ -1,5 +1,5 @@
# WSDL4R - Creating class definition from WSDL
-# Copyright (C) 2002, 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
+# 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;
@@ -22,13 +22,16 @@ class ClassDefCreator
@elements = definitions.collect_elements
@simpletypes = definitions.collect_simpletypes
@complextypes = definitions.collect_complextypes
- @faulttypes = definitions.collect_faulttypes if definitions.respond_to?(:collect_faulttypes)
+ @faulttypes = nil
+ if definitions.respond_to?(:collect_faulttypes)
+ @faulttypes = definitions.collect_faulttypes
+ end
end
- def dump(class_name = nil)
- result = ''
- if class_name
- result = dump_classdef(class_name)
+ def dump(type = nil)
+ result = "require 'xsd/qname'\n"
+ if type
+ result = dump_classdef(type.name, type)
else
str = dump_element
unless str.empty?
@@ -53,117 +56,129 @@ private
def dump_element
@elements.collect { |ele|
- ele.local_complextype ? dump_classdef(ele) : ''
- }.join("\n")
+ if ele.local_complextype
+ dump_classdef(ele.name, ele.local_complextype)
+ 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)
- }.join("\n")
+ dump_simpletypedef(type.name, type)
+ }.compact.join("\n")
end
def dump_complextype
@complextypes.collect { |type|
case type.compoundtype
- when :TYPE_STRUCT
- dump_classdef(type)
+ when :TYPE_STRUCT, :TYPE_EMPTY
+ dump_classdef(type.name, type)
when :TYPE_ARRAY
dump_arraydef(type)
when :TYPE_SIMPLE
- STDERR.puts("not implemented: ToDo")
+ dump_simpleclassdef(type)
+ when :TYPE_MAP
+ # mapped as a general Hash
+ nil
else
raise RuntimeError.new(
- "Unknown kind of complexContent: #{type.compoundtype}")
+ "unknown kind of complexContent: #{type.compoundtype}")
end
- }.join("\n")
+ }.compact.join("\n")
end
- def dump_simpletypedef(simpletype)
- qname = simpletype.name
- if simpletype.restriction.enumeration.empty?
- STDERR.puts("#{qname}: simpleType which is not enum type not supported.")
- return ''
+ 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.namespace }"
+ c.comment = "#{qname}"
+ const = {}
simpletype.restriction.enumeration.each do |value|
- c.def_const(safeconstname(value), value.dump)
+ 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_classdef(type_or_element)
+ 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)
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.namespace }"
- c.def_classvar('schema_type', qname.name.dump)
- c.def_classvar('schema_ns', qname.namespace.dump)
- schema_attribute = []
+ c.comment = "#{qname}"
+ c.def_classvar('schema_type', ndq(qname.name))
+ c.def_classvar('schema_ns', ndq(qname.namespace))
schema_element = []
init_lines = ''
params = []
- type_or_element.each_element do |element|
- next unless element.name
- name = element.name.name
+ typedef.each_element do |element|
if element.type == XSD::AnyTypeName
type = nil
- elsif basetype = basetype_class(element.type)
- type = basetype.name
- else
+ 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"
+ init_lines << "@#{varname} = #{varname}\n"
if element.map_as_array?
- params << "#{ varname } = []"
- type << '[]'
+ params << "#{varname} = []"
+ type << '[]' if type
else
- params << "#{ varname } = nil"
+ params << "#{varname} = nil"
end
- schema_element << [name, type]
+ eleqname = (varname == name) ? nil : element.name
+ schema_element << [varname, eleqname, type]
end
- unless type_or_element.attributes.empty?
- type_or_element.attributes.each do |attribute|
- name = attribute.name.name
- if basetype = basetype_class(attribute.type)
- type = basetype_class(attribute.type).name
- else
- type = nil
- end
- varname = safevarname('attr_' + name)
- c.def_method(varname) do <<-__EOD__
- @__soap_attribute[#{name.dump}]
- __EOD__
- end
- c.def_method(varname + '=', 'value') do <<-__EOD__
- @__soap_attribute[#{name.dump}] = value
- __EOD__
- end
- schema_attribute << [name, type]
- end
- init_lines << "@__soap_attribute = {}\n"
+ unless typedef.attributes.empty?
+ define_attribute(c, typedef.attributes)
+ init_lines << "@__xmlattr = {}\n"
end
- c.def_classvar('schema_attribute',
- '{' +
- schema_attribute.collect { |name, type|
- name.dump + ' => ' + ndq(type)
- }.join(', ') +
- '}'
- )
c.def_classvar('schema_element',
- '{' +
- schema_element.collect { |name, type|
- name.dump + ' => ' + ndq(type)
+ '[' +
+ 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
@@ -171,20 +186,83 @@ private
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)
- if @simpletypes[type]
- basetype_mapped_class(@simpletypes[type].base)
+ 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
+
def dump_arraydef(complextype)
qname = complextype.name
c = XSD::CodeGen::ClassDef.new(create_class_name(qname), '::Array')
- c.comment = "#{ qname.namespace }"
- c.def_classvar('schema_type', qname.name.dump)
- c.def_classvar('schema_ns', qname.namespace.dump)
+ c.comment = "#{qname}"
+ type = complextype.child_type
+ c.def_classvar('schema_type', ndq(type.name))
+ c.def_classvar('schema_ns', ndq(type.namespace))
c.dump
end
end