From eb3f829be932514064a983eb98fa7f840137f985 Mon Sep 17 00:00:00 2001 From: nahi Date: Sun, 22 May 2005 13:03:38 +0000 Subject: * 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#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: svn+ssh://ci.ruby-lang.org/ruby/trunk@8500 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/soap/baseData.rb | 128 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 103 insertions(+), 25 deletions(-) (limited to 'lib/soap/baseData.rb') diff --git a/lib/soap/baseData.rb b/lib/soap/baseData.rb index bf2fe6b25c..6d0f628be9 100644 --- a/lib/soap/baseData.rb +++ b/lib/soap/baseData.rb @@ -1,5 +1,5 @@ # soap/baseData.rb: SOAP4R - Base type library -# Copyright (C) 2000, 2001, 2003, 2004 NAKAMURA, Hiroshi . +# Copyright (C) 2000, 2001, 2003-2005 NAKAMURA, Hiroshi . # 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; @@ -56,6 +56,14 @@ module SOAPType @extraattr = {} end + def inspect + if self.is_a?(XSD::NSDBase) + sprintf("#<%s:0x%x %s %s>", self.class.name, __id__, self.elename, self.type) + else + sprintf("#<%s:0x%x %s>", self.class.name, __id__, self.elename) + end + end + def rootnode node = self while node = node.parent @@ -399,7 +407,7 @@ public def to_s() str = '' self.each do |key, data| - str << "#{ key }: #{ data }\n" + str << "#{key}: #{data}\n" end str end @@ -442,6 +450,25 @@ public @array end + def to_obj + hash = {} + proptype = {} + each do |k, v| + value = v.respond_to?(:to_obj) ? v.to_obj : v.to_s + case proptype[k] + when :single + hash[k] = [hash[k], value] + proptype[k] = :multi + when :multi + hash[k] << value + else + hash[k] = value + proptype[k] = :single + end + end + hash + end + def each for i in 0..(@array.length - 1) yield(@array[i], @data[i]) @@ -509,6 +536,10 @@ class SOAPElement @text = text end + def inspect + sprintf("#<%s:0x%x %s>", self.class.name, __id__, self.elename) + end + # Text interface. attr_accessor :text alias data text @@ -548,8 +579,19 @@ class SOAPElement @text else hash = {} + proptype = {} each do |k, v| - hash[k] = v.is_a?(SOAPElement) ? v.to_obj : v.to_s + value = v.respond_to?(:to_obj) ? v.to_obj : v.to_s + case proptype[k] + when :single + hash[k] = [hash[k], value] + proptype[k] = :multi + when :multi + hash[k] << value + else + hash[k] = value + proptype[k] = :single + end end hash end @@ -566,20 +608,41 @@ class SOAPElement o end - def self.from_obj(hash_or_string) + def self.from_obj(obj, namespace = nil) o = SOAPElement.new(nil) - if hash_or_string.is_a?(Hash) - hash_or_string.each do |k, v| - child = self.from_obj(v) - child.elename = k.is_a?(XSD::QName) ? k : XSD::QName.new(nil, k.to_s) - o.add(child) + case obj + when nil + o.text = nil + when Hash + obj.each do |elename, value| + if value.is_a?(Array) + value.each do |subvalue| + child = from_obj(subvalue, namespace) + child.elename = to_elename(elename, namespace) + o.add(child) + end + else + child = from_obj(value, namespace) + child.elename = to_elename(elename, namespace) + o.add(child) + end end else - o.text = hash_or_string + o.text = obj.to_s end o end + def self.to_elename(obj, namespace = nil) + if obj.is_a?(XSD::QName) + obj + elsif /\A(.+):([^:]+)\z/ =~ obj.to_s + XSD::QName.new($1, $2) + else + XSD::QName.new(namespace, obj.to_s) + end + end + private def add_member(name, value) @@ -590,18 +653,32 @@ private value end - def add_accessor(name) - methodname = name - if self.respond_to?(methodname) - methodname = safe_accessor_name(methodname) + if RUBY_VERSION > "1.7.0" + def add_accessor(name) + methodname = name + if self.respond_to?(methodname) + methodname = safe_accessor_name(methodname) + end + Mapping.define_singleton_method(self, methodname) do + @data[@array.index(name)] + end + Mapping.define_singleton_method(self, methodname + '=') do |value| + @data[@array.index(name)] = value + end + end + else + def add_accessor(name) + methodname = safe_accessor_name(name) + instance_eval <<-EOS + def #{methodname} + @data[@array.index(#{name.dump})] + end + + def #{methodname}=(value) + @data[@array.index(#{name.dump})] = value + end + EOS end - sclass = class << self; self; end - sclass.__send__(:define_method, methodname, proc { - @data[@array.index(name)] - }) - sclass.__send__(:define_method, methodname + '=', proc { |value| - @data[@array.index(name)] = value - }) end def safe_accessor_name(name) @@ -624,7 +701,7 @@ public def initialize(type = nil, rank = 1, arytype = nil) super() - @type = type || XSD::QName.new + @type = type || ValueArrayName @rank = rank @data = Array.new @sparse = false @@ -646,7 +723,7 @@ public def [](*idxary) if idxary.size != @rank - raise ArgumentError.new("Given #{ idxary.size } params does not match rank: #{ @rank }") + raise ArgumentError.new("given #{idxary.size} params does not match rank: #{@rank}") end retrieve(idxary) @@ -656,7 +733,8 @@ public value = idxary.slice!(-1) if idxary.size != @rank - raise ArgumentError.new("Given #{ idxary.size } params(#{ idxary }) does not match rank: #{ @rank }") + raise ArgumentError.new("given #{idxary.size} params(#{idxary})" + + " does not match rank: #{@rank}") end for i in 0..(idxary.size - 1) @@ -836,7 +914,7 @@ public private def self.create_arytype(typename, rank) - "#{ typename }[" << ',' * (rank - 1) << ']' + "#{typename}[" << ',' * (rank - 1) << ']' end TypeParseRegexp = Regexp.new('^(.+)\[([\d,]*)\]$') -- cgit v1.2.3