From df731e37a1953755edfedd1462995fa824ca22bf Mon Sep 17 00:00:00 2001 From: nahi Date: Sat, 3 Jul 2004 13:33:20 +0000 Subject: * added files: * lib/soap/header/* * lib/soap/rpc/httpserver.rb * lib/wsdl/soap/cgiStubCreator.rb * lib/wsdl/soap/classDefCreator.rb * lib/wsdl/soap/classDefCreatorSupport.rb * lib/wsdl/soap/clientSkeltonCreator.rb * lib/wsdl/soap/driverCreator.rb * lib/wsdl/soap/mappingRegistryCreator.rb * lib/wsdl/soap/methodDefCreator.rb * lib/wsdl/soap/servantSkeltonCreator.rb * lib/wsdl/soap/standaloneServerStubCreator.rb * lib/wsdl/xmlSchema/enumeration.rb * lib/wsdl/xmlSchema/simpleRestriction.rb * lib/wsdl/xmlSchema/simpleType.rb * lib/xsd/codegen/* * lib/xsd/codegen.rb * sample/soap/authheader/* * sample/soap/raa2.4/* * sample/soap/ssl/* * sample/soap/swa/* * sample/soap/whois.rb * sample/wsdl/raa2.4/* * test/soap/header/* * test/soap/ssl/* * test/soap/struct/* * test/soap/swa/* * test/soap/wsdlDriver/* * test/wsdl/multiplefault.wsdl * test/wsdl/simpletype/* * test/wsdl/test_multiplefault.rb * modified files: * lib/soap/baseData.rb * lib/soap/element.rb * lib/soap/generator.rb * lib/soap/netHttpClient.rb * lib/soap/parser.rb * lib/soap/property.rb * lib/soap/soap.rb * lib/soap/streamHandler.rb * lib/soap/wsdlDriver.rb * lib/soap/wsdlDriver.rb * lib/soap/encodingstyle/handler.rb * lib/soap/encodingstyle/literalHandler.rb * lib/soap/encodingstyle/soapHandler.rb * lib/soap/mapping/factory.rb * lib/soap/mapping/mapping.rb * lib/soap/mapping/registry.rb * lib/soap/mapping/rubytypeFactory.rb * lib/soap/mapping/wsdlRegistry.rb * lib/soap/rpc/cgistub.rb * lib/soap/rpc/driver.rb * lib/soap/rpc/proxy.rb * lib/soap/rpc/router.rb * lib/soap/rpc/soaplet.rb * lib/soap/rpc/standaloneServer.rb * lib/wsdl/data.rb * lib/wsdl/definitions.rb * lib/wsdl/operation.rb * lib/wsdl/parser.rb * lib/wsdl/soap/definitions.rb * lib/wsdl/xmlSchema/complexContent.rb * lib/wsdl/xmlSchema/complexType.rb * lib/wsdl/xmlSchema/data.rb * lib/wsdl/xmlSchema/parser.rb * lib/wsdl/xmlSchema/schema.rb * lib/xsd/datatypes.rb * lib/xsd/qname.rb * sample/soap/sampleStruct/server.rb * sample/wsdl/amazon/AmazonSearch.rb * sample/wsdl/amazon/AmazonSearchDriver.rb * test/soap/test_property.rb * test/soap/calc/test_calc_cgi.rb * test/wsdl/test_emptycomplextype.rb * summary * add SOAP Header mustUnderstand support. * add HTTP client SSL configuration and Cookies support (works completely with http-access2). * add header handler for handling sending/receiving SOAP Header. * map Ruby's anonymous Struct to common SOAP Struct in SOAP Object Model. it caused error. * add WSDL simpleType support to restrict lexical value space. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6565 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/soap/encodingstyle/handler.rb | 4 +- lib/soap/encodingstyle/literalHandler.rb | 50 ++++++++++++++++++------- lib/soap/encodingstyle/soapHandler.rb | 63 ++++++++++++++++++++------------ 3 files changed, 77 insertions(+), 40 deletions(-) (limited to 'lib/soap/encodingstyle') diff --git a/lib/soap/encodingstyle/handler.rb b/lib/soap/encodingstyle/handler.rb index 8ea23ef146..7bf65a2fd5 100644 --- a/lib/soap/encodingstyle/handler.rb +++ b/lib/soap/encodingstyle/handler.rb @@ -44,8 +44,8 @@ class Handler attr_reader :charset attr_accessor :generate_explicit_type - def decode_typemap=(complextypes) - @decode_typemap = complextypes + def decode_typemap=(definedtypes) + @decode_typemap = definedtypes end def initialize(charset) diff --git a/lib/soap/encodingstyle/literalHandler.rb b/lib/soap/encodingstyle/literalHandler.rb index 995e1a5361..72a10b2daa 100644 --- a/lib/soap/encodingstyle/literalHandler.rb +++ b/lib/soap/encodingstyle/literalHandler.rb @@ -1,5 +1,5 @@ # SOAP4R - XML Literal EncodingStyle handler library -# Copyright (C) 2001, 2003 NAKAMURA, Hiroshi . +# Copyright (C) 2001, 2003, 2004 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; @@ -41,14 +41,18 @@ class LiteralHandler < Handler generator.encode_rawstring(data.to_s) when XSD::XSDString generator.encode_tag(name, attrs) - generator.encode_string(@charset ? XSD::Charset.encoding_to_xml(data.to_s, @charset) : data.to_s) + str = data.to_s + str = XSD::Charset.encoding_to_xml(str, @charset) if @charset + generator.encode_string(str) when XSD::XSDAnySimpleType generator.encode_tag(name, attrs) generator.encode_string(data.to_s) when SOAPStruct generator.encode_tag(name, attrs) data.each do |key, value| - value.elename.namespace = data.elename.namespace if !value.elename.namespace + if !value.elename.namespace + value.elename.namespace = data.elename.namespace + end yield(value, true) end when SOAPArray @@ -61,8 +65,6 @@ class LiteralHandler < Handler generator.encode_tag(name, attrs.update(data.extraattr)) generator.encode_rawstring(data.text) if data.text data.each do |key, value| - value.elename.namespace = data.elename.namespace if !value.elename.namespace - #yield(value, data.qualified) yield(value, qualified) end else @@ -76,7 +78,8 @@ class LiteralHandler < Handler else data.elename.name end - generator.encode_tag_end(name) + cr = data.is_a?(SOAPElement) && !data.text + generator.encode_tag_end(name, cr) end @@ -92,15 +95,17 @@ class LiteralHandler < Handler end class SOAPUnknown < SOAPTemporalObject - def initialize(handler, elename) + def initialize(handler, elename, extraattr) super() @handler = handler @elename = elename + @extraattr = extraattr end - def as_struct - o = SOAPStruct.decode(@elename, XSD::AnyTypeName) + def as_element + o = SOAPElement.decode(@elename) o.parent = @parent + o.extraattr.update(@extraattr) @handler.decode_parent(@parent, o) o end @@ -108,6 +113,7 @@ class LiteralHandler < Handler def as_string o = SOAPString.decode(@elename) o.parent = @parent + o.extraattr.update(@extraattr) @handler.decode_parent(@parent, o) o end @@ -115,6 +121,7 @@ class LiteralHandler < Handler def as_nil o = SOAPNil.decode(@elename) o.parent = @parent + o.extraattr.update(@extraattr) @handler.decode_parent(@parent, o) o end @@ -123,7 +130,7 @@ class LiteralHandler < Handler def decode_tag(ns, elename, attrs, parent) # ToDo: check if @textbuf is empty... @textbuf = '' - o = SOAPUnknown.new(self, elename) + o = SOAPUnknown.new(self, elename, decode_attrs(ns, attrs)) o.parent = parent o end @@ -132,7 +139,7 @@ class LiteralHandler < Handler o = node.node if o.is_a?(SOAPUnknown) newnode = if /\A\s*\z/ =~ @textbuf - o.as_struct + o.as_element else o.as_string end @@ -149,6 +156,15 @@ class LiteralHandler < Handler @textbuf << text end + def decode_attrs(ns, attrs) + extraattr = {} + attrs.each do |key, value| + qname = ns.parse(key) + extraattr[qname] = value + end + extraattr + end + def decode_prologue end @@ -158,13 +174,18 @@ class LiteralHandler < Handler def decode_parent(parent, node) case parent.node when SOAPUnknown - newparent = parent.node.as_struct + newparent = parent.node.as_element node.parent = newparent parent.replace_node(newparent) decode_parent(parent, node) + when SOAPElement + parent.node.add(node) + node.parent = parent.node + when SOAPStruct - parent.node.add(node.name, node) + parent.node.add(node.elename.name, node) + node.parent = parent.node when SOAPArray if node.position @@ -173,13 +194,14 @@ class LiteralHandler < Handler else parent.node.add(node) end + node.parent = parent.node when SOAPBasetype raise EncodingStyleError.new("SOAP base type must not have a child.") else # SOAPUnknown does not have parent. - # raise EncodingStyleError.new("Illegal parent: #{ parent }.") + raise EncodingStyleError.new("Illegal parent: #{ parent }.") end end diff --git a/lib/soap/encodingstyle/soapHandler.rb b/lib/soap/encodingstyle/soapHandler.rb index d755d7b952..114060bd02 100644 --- a/lib/soap/encodingstyle/soapHandler.rb +++ b/lib/soap/encodingstyle/soapHandler.rb @@ -33,7 +33,7 @@ class SOAPHandler < Handler attrs = encode_attrs(generator, ns, data, parent) if parent && parent.is_a?(SOAPArray) && parent.position - attrs[ns.name(AttrPositionName)] = '[' << parent.position.join(',') << ']' + attrs[ns.name(AttrPositionName)] = "[#{ parent.position.join(',') }]" end name = nil @@ -207,16 +207,12 @@ class SOAPHandler < Handler node.replace_node(newnode) o = node.node end - if o.is_a?(SOAPCompoundtype) - o.definedtype = nil - end - decode_textbuf(o) - @textbuf = '' + # unlink definedtype + o.definedtype = nil end def decode_text(ns, text) - # @textbuf is set at decode_tag_end. @textbuf << text end @@ -240,11 +236,9 @@ class SOAPHandler < Handler end parent.replace_node(newparent) decode_parent(parent, node) - when SOAPStruct parent.node.add(node.elename.name, node) node.parent = parent.node - when SOAPArray if node.position parent.node[*(decode_arypos(node.position))] = node @@ -253,10 +247,8 @@ class SOAPHandler < Handler parent.node.add(node) end node.parent = parent.node - when SOAPBasetype raise EncodingStyleError.new("SOAP base type must not have a child.") - else raise EncodingStyleError.new("Illegal parent: #{ parent.node }.") end @@ -274,7 +266,7 @@ private def create_arytype(ns, data) XSD::QName.new(data.arytype.namespace, - content_typename(data.arytype.name) << '[' << data.size.join(',') << ']') + content_typename(data.arytype.name) + "[#{ data.size.join(',') }]") end def encode_attrs(generator, ns, data, parent) @@ -353,8 +345,7 @@ private typename = ns.parse(typestr) typedef = @decode_typemap[typename] if typedef - return decode_defined_compoundtype(elename, typename, typedef, - arytypestr) + return decode_definedtype(elename, typename, typedef, arytypestr) end end return decode_tag_by_type(ns, elename, typestr, parent, arytypestr, @@ -376,21 +367,42 @@ private definedtype_name = parenttype.child_type(elename) if definedtype_name and (klass = TypeMap[definedtype_name]) - return klass.decode(elename) + return decode_basetype(klass, elename) elsif definedtype_name == XSD::AnyTypeName return decode_tag_by_type(ns, elename, typestr, parent, arytypestr, extraattr) end - typedef = definedtype_name ? @decode_typemap[definedtype_name] : - parenttype.child_defined_complextype(elename) - decode_defined_compoundtype(elename, definedtype_name, typedef, arytypestr) + if definedtype_name + typedef = @decode_typemap[definedtype_name] + else + typedef = parenttype.child_defined_complextype(elename) + end + decode_definedtype(elename, definedtype_name, typedef, arytypestr) end - def decode_defined_compoundtype(elename, typename, typedef, arytypestr) + def decode_definedtype(elename, typename, typedef, arytypestr) unless typedef raise EncodingStyleError.new("Unknown type '#{ typename }'.") end + if typedef.is_a?(::WSDL::XMLSchema::SimpleType) + decode_defined_simpletype(elename, typename, typedef, arytypestr) + else + decode_defined_complextype(elename, typename, typedef, arytypestr) + end + end + + def decode_basetype(klass, elename) + klass.decode(elename) + end + + def decode_defined_simpletype(elename, typename, typedef, arytypestr) + o = decode_basetype(TypeMap[typedef.base], elename) + o.definedtype = typedef + o + end + + def decode_defined_complextype(elename, typename, typedef, arytypestr) case typedef.compoundtype when :TYPE_STRUCT o = SOAPStruct.decode(elename, typename) @@ -410,7 +422,7 @@ private o.definedtype = typedef return o end - return nil + nil end def decode_tag_by_type(ns, elename, typestr, parent, arytypestr, extraattr) @@ -435,7 +447,7 @@ private end if (klass = TypeMap[type]) - node = klass.decode(elename) + node = decode_basetype(klass, elename) node.extraattr.update(extraattr) return node end @@ -450,10 +462,12 @@ private node.set_encoded(@textbuf) when XSD::XSDString if @charset - node.set(XSD::Charset.encoding_from_xml(@textbuf, @charset)) - else - node.set(@textbuf) + @textbuf = XSD::Charset.encoding_from_xml(@textbuf, @charset) + end + if node.definedtype + node.definedtype.check_lexical_format(@textbuf) end + node.set(@textbuf) when SOAPNil # Nothing to do. when SOAPBasetype @@ -461,6 +475,7 @@ private else # Nothing to do... end + @textbuf = '' end NilLiteralMap = { -- cgit v1.2.3