summaryrefslogtreecommitdiff
path: root/lib/soap/mapping/mapping.rb
diff options
context:
space:
mode:
authornahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-12-20 13:50:15 +0000
committernahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-12-20 13:50:15 +0000
commite5a3aba50e2bd7e0327aacd8fe1ab7963fc4a007 (patch)
treeb56a6e784df74331c28e4a94901b96837f214e35 /lib/soap/mapping/mapping.rb
parent643dc132113489749c333a6bda14730d9b175ed1 (diff)
* added files:
* lib/soap/mapping/wsdl*.rb * lib/wsdl/soap/element.rb * lib/wsdl/xmlSchema/simpleContent.rb * modified files: * lib/soap/* * lib/wsdl/* * lib/xsd/* * test/soap/* * test/wsdl/* * test/xsd/* * summary * imported from the soap4r repository. Version: 1.5.3-ruby1.8.2 * added several XSD basetype support: nonPositiveInteger, negativeInteger, nonNegativeInteger, unsignedLong, unsignedInt, unsignedShort, unsignedByte, positiveInteger * HTTP client connection/send/receive timeout support. * HTTP client/server gzipped content encoding support. * improved WSDL schema definition support; still is far from complete, but is making step by step improovement. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7612 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/soap/mapping/mapping.rb')
-rw-r--r--lib/soap/mapping/mapping.rb56
1 files changed, 53 insertions, 3 deletions
diff --git a/lib/soap/mapping/mapping.rb b/lib/soap/mapping/mapping.rb
index db7ea607fd..17a0d3bcf4 100644
--- a/lib/soap/mapping/mapping.rb
+++ b/lib/soap/mapping/mapping.rb
@@ -1,11 +1,14 @@
# SOAP4R - Ruby type mapping utility.
-# Copyright (C) 2000, 2001, 2003 NAKAMURA Hiroshi <nahi@ruby-lang.org>.
+# Copyright (C) 2000, 2001, 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 'xsd/codegen/gensupport'
+
+
module SOAP
@@ -101,8 +104,10 @@ module Mapping
def self._obj2soap(obj, registry, type = nil)
if referent = Thread.current[:SOAPMarshalDataKey][obj.__id__]
SOAPReference.new(referent)
+ elsif registry
+ registry.obj2soap(obj, type)
else
- registry.obj2soap(obj.class, obj, type)
+ raise MappingError.new("No mapping registry given.")
end
end
@@ -116,9 +121,41 @@ module Mapping
return _soap2obj(target, registry)
end
end
- return registry.soap2obj(node.class, node)
+ return registry.soap2obj(node)
end
+ if Object.respond_to?(:allocate)
+ # ruby/1.7 or later.
+ def self.create_empty_object(klass)
+ klass.allocate
+ end
+ else
+ MARSHAL_TAG = {
+ String => ['"', 1],
+ Regexp => ['/', 2],
+ Array => ['[', 1],
+ Hash => ['{', 1]
+ }
+ def self.create_empty_object(klass)
+ if klass <= Struct
+ name = klass.name
+ return ::Marshal.load(sprintf("\004\006S:%c%s\000", name.length + 5, name))
+ end
+ if MARSHAL_TAG.has_key?(klass)
+ tag, terminate = MARSHAL_TAG[klass]
+ return ::Marshal.load(sprintf("\004\006%s%s", tag, "\000" * terminate))
+ end
+ MARSHAL_TAG.each do |k, v|
+ if klass < k
+ name = klass.name
+ tag, terminate = v
+ return ::Marshal.load(sprintf("\004\006C:%c%s%s%s", name.length + 5, name, tag, "\000" * terminate))
+ end
+ end
+ name = klass.name
+ ::Marshal.load(sprintf("\004\006o:%c%s\000", name.length + 5, name))
+ end
+ end
def self.set_instance_vars(obj, values)
values.each do |name, value|
setter = name + "="
@@ -200,6 +237,19 @@ module Mapping
end
end
+ def self.find_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
+ obj.instance_eval("@#{name}")
+ end
+ end
+ end
+
class << Mapping
private
def add_md_ary(md_ary, ary, indices, registry)