diff options
author | nahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-05-22 13:20:28 +0000 |
---|---|---|
committer | nahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-05-22 13:20:28 +0000 |
commit | 991d0c409cc6b1d916330a32a9624aef808176a4 (patch) | |
tree | 5e2cc150dc84ab3f6f64685ec7f54e6b2077eae7 /lib/soap/mapping/mapping.rb | |
parent | 15b7d439885f4aa97e0f508ef485cadab4b23577 (diff) |
* 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: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8502 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/soap/mapping/mapping.rb')
-rw-r--r-- | lib/soap/mapping/mapping.rb | 152 |
1 files changed, 105 insertions, 47 deletions
diff --git a/lib/soap/mapping/mapping.rb b/lib/soap/mapping/mapping.rb index e04e3fa50d..626df8c82f 100644 --- a/lib/soap/mapping/mapping.rb +++ b/lib/soap/mapping/mapping.rb @@ -1,5 +1,5 @@ # SOAP4R - Ruby type mapping utility. -# Copyright (C) 2000, 2001, 2003, 2004 NAKAMURA Hiroshi <nahi@ruby-lang.org>. +# Copyright (C) 2000, 2001, 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; @@ -23,10 +23,12 @@ module Mapping # TraverseSupport breaks Thread.current[:SOAPMarshalDataKey]. module TraverseSupport def mark_marshalled_obj(obj, soap_obj) + raise if obj.nil? Thread.current[:SOAPMarshalDataKey][obj.__id__] = soap_obj end def mark_unmarshalled_obj(node, obj) + return if obj.nil? # node.id is not Object#id but SOAPReference#id Thread.current[:SOAPMarshalDataKey][node.id] = obj end @@ -41,10 +43,10 @@ module Mapping soap_obj end - def self.soap2obj(node, registry = nil) + def self.soap2obj(node, registry = nil, klass = nil) registry ||= Mapping::DefaultRegistry Thread.current[:SOAPMarshalDataKey] = {} - obj = _soap2obj(node, registry) + obj = _soap2obj(node, registry, klass) Thread.current[:SOAPMarshalDataKey] = nil obj end @@ -107,21 +109,21 @@ module Mapping elsif registry registry.obj2soap(obj, type) else - raise MappingError.new("No mapping registry given.") + raise MappingError.new("no mapping registry given") end end - def self._soap2obj(node, registry) + def self._soap2obj(node, registry, klass = nil) if node.is_a?(SOAPReference) target = node.__getobj__ # target.id is not Object#id but SOAPReference#id if referent = Thread.current[:SOAPMarshalDataKey][target.id] return referent else - return _soap2obj(target, registry) + return _soap2obj(target, registry, klass) end end - return registry.soap2obj(node) + return registry.soap2obj(node, klass) end if Object.respond_to?(:allocate) @@ -157,29 +159,6 @@ module Mapping end end - unless Object.respond_to?(:instance_variable_get) - class Object - def instance_variable_get(ivarname) - instance_eval(ivarname) - end - - def instance_variable_set(ivarname, value) - instance_eval("#{ivarname} = value") - end - end - end - - def self.set_instance_vars(obj, values) - values.each do |name, value| - setter = name + "=" - if obj.respond_to?(setter) - obj.__send__(setter, value) - else - obj.instance_variable_set('@' + name, value) - end - end - end - # Allow only (Letter | '_') (Letter | Digit | '-' | '_')* here. # Caution: '.' is not allowed here. # To follow XML spec., it should be NCName. @@ -198,28 +177,51 @@ module Mapping } end - def self.class_from_name(name) - if /^[A-Z]/ !~ name + def self.const_from_name(name, lenient = false) + const = ::Object + name.sub(/\A::/, '').split('::').each do |const_str| + if XSD::CodeGen::GenSupport.safeconstname?(const_str) + if const.const_defined?(const_str) + const = const.const_get(const_str) + next + end + elsif lenient + const_str = XSD::CodeGen::GenSupport.safeconstname(const_str) + if const.const_defined?(const_str) + const = const.const_get(const_str) + next + end + end return nil end - klass = ::Object - name.split('::').each do |klass_str| - if klass.const_defined?(klass_str) - klass = klass.const_get(klass_str) - else - return nil - end + const + end + + def self.class_from_name(name, lenient = false) + const = const_from_name(name, lenient) + if const.is_a?(::Class) + const + else + nil + end + end + + def self.module_from_name(name, lenient = false) + const = const_from_name(name, lenient) + if const.is_a?(::Module) + const + else + nil end - klass end def self.class2qname(klass) - name = if klass.class_variables.include?("@@schema_type") + name = if klass.class_variables.include?('@@schema_type') klass.class_eval('@@schema_type') else nil end - namespace = if klass.class_variables.include?("@@schema_ns") + namespace = if klass.class_variables.include?('@@schema_ns') klass.class_eval('@@schema_ns') else nil @@ -250,19 +252,75 @@ module Mapping end end - def self.find_attribute(obj, attr_name) + def self.define_singleton_method(obj, name, &block) + sclass = (class << obj; self; end) + sclass.__send__(:define_method, name, &block) + end + + def self.get_attribute(obj, attr_name) if obj.is_a?(::Hash) obj[attr_name] || obj[attr_name.intern] else - name = ::XSD::CodeGen::GenSupport.safevarname(attr_name) - if obj.respond_to?(name) - obj.__send__(name) - else + name = XSD::CodeGen::GenSupport.safevarname(attr_name) + if obj.instance_variables.include?('@' + name) obj.instance_variable_get('@' + name) + elsif ((obj.is_a?(::Struct) or obj.is_a?(Marshallable)) and + obj.respond_to?(name)) + obj.__send__(name) + end + end + end + + def self.set_attributes(obj, values) + if obj.is_a?(::SOAP::Mapping::Object) + values.each do |attr_name, value| + obj.__add_xmlele_value(attr_name, value) + end + else + values.each do |attr_name, value| + name = XSD::CodeGen::GenSupport.safevarname(attr_name) + setter = name + "=" + if obj.respond_to?(setter) + obj.__send__(setter, value) + else + obj.instance_variable_set('@' + name, value) + begin + define_attr_accessor(obj, name, + proc { instance_variable_get('@' + name) }, + proc { |value| instance_variable_set('@' + name, value) }) + rescue TypeError + # singleton class may not exist (e.g. Float) + end + end end end end + def self.define_attr_accessor(obj, name, getterproc, setterproc = nil) + define_singleton_method(obj, name, &getterproc) + define_singleton_method(obj, name + '=', &setterproc) if setterproc + end + + def self.schema_element_definition(klass) + return nil unless klass.class_variables.include?('@@schema_element') + elements = {} + as_array = [] + klass.class_eval('@@schema_element').each do |varname, definition| + class_name, name = definition + if /\[\]$/ =~ class_name + class_name = class_name.sub(/\[\]$/, '') + as_array << class_name + end + elements[name ? name.name : varname] = class_name + end + [elements, as_array] + end + + def self.schema_attribute_definition(klass) + return nil unless klass.class_variables.include?('@@schema_attribute') + klass.class_eval('@@schema_attribute') + end + class << Mapping private def add_md_ary(md_ary, ary, indices, registry) |