Welcome to the "trac"-ing site of soap4r!
[soap4r] [httpclient] [openpgp4u] [pkcs1] [logger] [csv] [vtr]

Changeset 1970

Show
Ignore:
Timestamp:
09/17/07 12:10:11 (10 months ago)
Author:
nahi
Message:
  • non user visible changes
    • reduce String object allocation.
    • streamline XML attribute parsing.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/soap/baseData.rb

    r1962 r1970  
    2828    d.elename = elename 
    2929    d 
     30  end 
     31 
     32  def to_data(str) 
     33    new(str).data 
    3034  end 
    3135end 
     
    544548 
    545549  def add(name, value) 
    546     add_member(name, value) 
     550    value = SOAPNil.new if value.nil? 
     551    @array.push(name) 
     552    value.elename = value.elename.dup_name(name) 
     553    @data.push(value) 
     554    value.parent = self if value.respond_to?(:parent=) 
     555    value 
    547556  end 
    548557 
     
    623632    s 
    624633  end 
    625  
    626 private 
    627  
    628   def add_member(name, value = nil) 
    629     value = SOAPNil.new if value.nil? 
    630     @array.push(name) 
    631     value.elename = value.elename.dup_name(name) 
    632     @data.push(value) 
    633     value.parent = self if value.respond_to?(:parent=) 
    634     value 
    635   end 
    636634end 
    637635 
     
    676674  # Element interfaces. 
    677675  def add(value) 
    678     add_member(value.elename.name, value) 
     676    name = value.elename.name 
     677    @array.push(name) 
     678    @data.push(value) 
     679    value.parent = self if value.respond_to?(:parent=) 
     680    value 
    679681  end 
    680682 
     
    823825    end 
    824826  end 
    825  
    826 private 
    827  
    828   def add_member(name, value) 
    829     @array.push(name) 
    830     @data.push(value) 
    831     value.parent = self if value.respond_to?(:parent=) 
    832     value 
    833   end 
    834827end 
    835828 
  • trunk/lib/soap/encodingstyle/literalHandler.rb

    r1946 r1970  
    5252    when XSD::XSDString 
    5353      generator.encode_tag(name, attrs) 
    54       str = data.to_s 
    55       str = XSD::Charset.encoding_to_xml(str, @charset) if @charset 
     54      str = decode_str(data.to_s) 
    5655      generator.encode_string(str) 
    5756    when XSD::XSDAnySimpleType 
     
    112111  def decode_tag(ns, elename, attrs, parent) 
    113112    @textbuf.clear 
    114     extraattrs = decode_attrs(ns, attrs) 
    115     if extraattrs[XSD::AttrNilName] == 'true' 
     113    if attrs[XSD::AttrNilName] == 'true' 
    116114      o = SOAPNil.decode(elename) 
    117115    else 
    118116      o = SOAPElement.decode(elename) 
    119117    end 
    120     if definedtype = extraattrs[XSD::AttrTypeName] 
     118    if definedtype = attrs[XSD::AttrTypeName] 
    121119      o.type = ns.parse(definedtype) 
    122120    end 
    123121    o.parent = parent 
    124     o.extraattr.update(extraattrs) 
     122    o.extraattr.update(attrs) 
    125123    decode_parent(parent, o) 
    126124    o 
     
    137135    # @textbuf is set at decode_tag_end. 
    138136    @textbuf << text 
    139   end 
    140  
    141   def decode_attrs(ns, attrs) 
    142     extraattr = {} 
    143     attrs.each do |key, value| 
    144       qname = ns.parse_local(key) 
    145       extraattr[qname] = value 
    146     end 
    147     extraattr 
    148137  end 
    149138 
     
    182171    when XSD::XSDString, SOAPElement 
    183172      if @charset 
    184         node.set(XSD::Charset.encoding_from_xml(textbufstr, @charset)) 
     173        node.set(decode_str(textbufstr)) 
    185174      else 
    186175        node.set(textbufstr) 
     
    189178      # Nothing to do... 
    190179    end 
     180  end 
     181 
     182  def decode_str(str) 
     183    @charset ? XSD::Charset.encoding_from_xml(str, @charset) : str 
    191184  end 
    192185end 
  • trunk/lib/soap/encodingstyle/soapHandler.rb

    r1936 r1970  
    88 
    99require 'soap/encodingstyle/handler' 
     10require 'soap/mapping/registry' 
    1011 
    1112 
     
    151152  def decode_tag(ns, elename, attrs, parent) 
    152153    @textbuf.clear 
    153     is_nil, type, arytype, root, offset, position, href, id, extraattr
    154       decode_attrs(ns, attrs) 
     154    is_nil, type, arytype, root, offset, position, href, id
     155      extract_attrs(ns, attrs) 
    155156    o = nil 
    156157    if is_nil 
     
    160161      @refpool << o 
    161162    elsif @decode_typemap 
    162       o = decode_tag_by_wsdl(ns, elename, type, parent.node, arytype, extraattr
    163     else 
    164       o = decode_tag_by_type(ns, elename, type, parent.node, arytype, extraattr
     163      o = decode_tag_by_wsdl(ns, elename, type, parent.node, arytype, attrs
     164    else 
     165      o = decode_tag_by_type(ns, elename, type, parent.node, arytype, attrs
    165166    end 
    166167 
     
    327328  end 
    328329 
    329   def decode_tag_by_wsdl(ns, elename, typestr, parent, arytypestr, extraattr
     330  def decode_tag_by_wsdl(ns, elename, typestr, parent, arytypestr, attrs
    330331    o = nil 
    331332    if parent.class == SOAPBody 
     
    351352        end 
    352353      end 
    353       return decode_tag_by_type(ns, elename, typestr, parent, arytypestr, 
    354         extraattr) 
     354      return decode_tag_by_type(ns, elename, typestr, parent, arytypestr, attrs) 
    355355    end 
    356356 
    357357    if parent.type == XSD::AnyTypeName 
    358       return decode_tag_by_type(ns, elename, typestr, parent, arytypestr, 
    359         extraattr) 
     358      return decode_tag_by_type(ns, elename, typestr, parent, arytypestr, attrs) 
    360359    end 
    361360 
     
    364363    parenttype = parent.definedtype || @decode_typemap[parent.type] 
    365364    unless parenttype 
    366       return decode_tag_by_type(ns, elename, typestr, parent, arytypestr, 
    367         extraattr) 
     365      return decode_tag_by_type(ns, elename, typestr, parent, arytypestr, attrs) 
    368366    end 
    369367 
     
    372370      return decode_basetype(klass, elename) 
    373371    elsif definedtype_name == XSD::AnyTypeName 
    374       return decode_tag_by_type(ns, elename, typestr, parent, arytypestr, 
    375         extraattr) 
     372      return decode_tag_by_type(ns, elename, typestr, parent, arytypestr, attrs) 
    376373    end 
    377374 
     
    439436  end 
    440437 
    441   def decode_tag_by_type(ns, elename, typestr, parent, arytypestr, extraattr
     438  def decode_tag_by_type(ns, elename, typestr, parent, arytypestr, attrs
    442439    if arytypestr 
    443440      type = typestr ? ns.parse(typestr) : ValueArrayName 
    444441      node = SOAPArray.decode(elename, type, ns.parse(arytypestr)) 
    445       node.extraattr.update(extraattr
     442      node.extraattr.update(attrs
    446443      return node 
    447444    end 
     
    462459    if klass = TypeMap[type] 
    463460      node = decode_basetype(klass, elename) 
    464       node.extraattr.update(extraattr
     461      node.extraattr.update(attrs
    465462      return node 
    466463    end 
    467464 
    468465    # Unknown type... Struct or String 
    469     SOAPUnknown.new(self, elename, type, extraattr
     466    SOAPUnknown.new(self, elename, type, attrs
    470467  end 
    471468 
     
    501498    '0' => 0 
    502499  } 
    503   def decode_attrs(ns, attrs) 
    504     is_nil = false 
    505     type = nil 
    506     arytype = nil 
    507     root = nil 
    508     offset = nil 
    509     position = nil 
    510     href = nil 
    511     id = nil 
    512     extraattr = {} 
    513  
    514     attrs.each do |key, value| 
    515       qname = ns.parse(key) 
    516       case qname.namespace 
    517       when XSD::InstanceNamespace 
    518         case qname.name 
    519         when XSD::NilLiteral 
    520           is_nil = NilLiteralMap[value] or 
    521             raise EncodingStyleError.new("cannot accept attribute value: #{value} as the value of xsi:#{XSD::NilLiteral} (expected 'true', 'false', '1', or '0')") 
    522           next 
    523         when XSD::AttrType 
    524           type = value 
    525           next 
    526         end 
    527       when EncodingNamespace 
    528         case qname.name 
    529         when AttrArrayType 
    530           arytype = value 
    531           next 
    532         when AttrRoot 
    533           root = RootLiteralMap[value] or 
    534             raise EncodingStyleError.new( 
    535               "illegal root attribute value: #{value}") 
    536           next 
    537         when AttrOffset 
    538           offset = value 
    539           next 
    540         when AttrPosition 
    541           position = value 
    542           next 
    543         end 
    544       end 
    545       if key == 'href' 
    546         href = value 
    547         next 
    548       elsif key == 'id' 
    549         id = value 
    550         next 
    551       end 
    552       qname = ns.parse_local(key) 
    553       extraattr[qname] = decode_attr_value(ns, qname, value) 
    554     end 
    555  
    556     return is_nil, type, arytype, root, offset, position, href, id, extraattr 
    557   end 
    558  
    559   def decode_attr_value(ns, qname, value) 
     500  def extract_attrs(ns, attrs) 
     501    is_nil = NilLiteralMap[attrs[XSD::AttrNilName]] 
     502    type = attrs[XSD::AttrTypeName] 
     503    arytype = attrs[AttrArrayTypeName] 
     504    root = attrs[AttrRootName] 
     505    offset = attrs[AttrOffsetName] 
     506    position = attrs[AttrPositionName] 
     507    href = attrs[AttrHrefName] 
     508    id = attrs[AttrIdName] 
     509    if attrs.key?(Mapping::RubyIVarName) 
     510      attrs[Mapping::RubyIVarName] = 
     511        decode_ref_value(ns, attrs[Mapping::RubyIVarName]) 
     512    end 
     513    return is_nil, type, arytype, root, offset, position, href, id 
     514  end 
     515 
     516  def decode_ref_value(ns, value) 
    560517    if /\A#/ =~ value 
    561518      o = SOAPReference.decode(nil, value) 
  • trunk/lib/soap/mapping/literalregistry.rb

    r1962 r1970  
    207207      end 
    208208    end 
    209     add_attributes2soap(obj, ele) 
     209    obj.__xmlattr.each do |key, value| 
     210      ele.extraattr[key] = value 
     211    end 
    210212    ele 
    211213  end 
     
    240242  def elesoap2stubobj(node, obj_class, definition) 
    241243    obj = nil 
    242     if obj_class < ::String 
     244    if obj_class == ::String 
     245      obj = node.text 
     246    elsif obj_class < ::String 
    243247      obj = obj_class.new(node.text) 
    244248    else 
     
    266270      return node.data 
    267271    end 
    268     klass = ::SOAP::Mapping::Object 
    269     obj = klass.new 
    270     obj 
     272    ::SOAP::Mapping::Object.new 
    271273  end 
    272274 
     
    325327          klass = Mapping.class_from_name(class_name) 
    326328          if klass.include?(::SOAP::SOAPBasetype) 
    327             child = klass.new(attr).data 
     329            child = klass.to_data(attr) 
    328330          end 
    329331        end 
  • trunk/lib/soap/mapping/registry.rb

    r1949 r1970  
    283283      v 
    284284    else 
    285       klass.new(v).data 
     285      klass.to_data(v) 
    286286    end 
    287287  end 
  • trunk/lib/soap/parser.rb

    r1901 r1970  
    113113  end 
    114114 
    115   def start_element(name, attrs) 
     115  def start_element(name, raw_attrs) 
    116116    lastframe = @parsestack.last 
    117117    ns = parent = parent_encodingstyle = nil 
     
    126126    end 
    127127    # ns might be the same 
    128     ns, attrs = XSD::XMLParser.filter_ns(ns, attrs) 
    129     encodingstyle = find_encodingstyle(ns, attrs) 
     128    ns, raw_attrs = XSD::XMLParser.filter_ns(ns, raw_attrs) 
     129    attrs = decode_attrs(ns, raw_attrs) 
     130    encodingstyle = attrs[AttrEncodingStyleName] 
    130131    # Children's encodingstyle is derived from its parent. 
    131132    if encodingstyle.nil? 
     
    150151 
    151152  def characters(text) 
    152     lastframe = @parsestack.last 
    153     if lastframe 
     153    # Ignore Text outside of SOAP Envelope. 
     154    if lastframe = @parsestack.last 
    154155      # Need not to be cloned because character does not have attr. 
    155156      decode_text(lastframe.ns, text, lastframe.handler) 
    156     else 
    157       # Ignore Text outside of SOAP Envelope. 
    158       p text if $DEBUG 
    159157    end 
    160158  end 
     
    171169 
    172170private 
    173  
    174   def find_encodingstyle(ns, attrs) 
    175     attrs.each do |key, value| 
    176       if (ns.compare(@envelopenamespace, AttrEncodingStyle, key)) 
    177         return value 
    178       end 
    179     end 
    180     nil 
    181   end 
    182171 
    183172  def decode_tag(ns, name, attrs, parent, handler) 
     
    195184  def decode_tag_end(ns, node, handler) 
    196185    return handler.decode_tag_end(ns, node) 
     186  end 
     187 
     188  def decode_attrs(ns, attrs) 
     189    extraattr = {} 
     190    attrs.each do |key, value| 
     191      qname = ns.parse_local(key) 
     192      extraattr[qname] = value 
     193    end 
     194    extraattr 
    197195  end 
    198196 
  • trunk/lib/soap/rpc/element.rb

    r1893 r1970  
    5757  def fault=(fault) 
    5858    @is_fault = true 
    59     add_member('fault', fault) 
     59    add('fault', fault) 
    6060  end 
    6161end 
  • trunk/lib/soap/soap.rb

    r1932 r1970  
    4040AttrOffset = 'offset' 
    4141AttrPosition = 'position' 
     42AttrHref = 'href' 
     43AttrId = 'id' 
    4244ValueArray = 'Array' 
    4345 
     
    5759AttrOffsetName = XSD::QName.new(EncodingNamespace, AttrOffset).freeze 
    5860AttrPositionName = XSD::QName.new(EncodingNamespace, AttrPosition).freeze 
     61AttrHrefName = XSD::QName.new(nil, AttrHref).freeze 
     62AttrIdName = XSD::QName.new(nil, AttrId).freeze 
    5963ValueArrayName = XSD::QName.new(EncodingNamespace, ValueArray).freeze 
    6064 
  • trunk/test/soap/test_extraattr.rb

    r1949 r1970  
    4545    header = env.header 
    4646    body = env.body 
    47     assert_equal("extraattr", env.extraattr["Id"]) 
    48     assert_equal("extraattr", header.extraattr["Id"]) 
    49     assert_equal("extraattr<>", body.extraattr["Id"]) 
     47    assert_equal("extraattr", env.extraattr[XSD::QName.new(nil, "Id")]) 
     48    assert_equal("extraattr", header.extraattr[XSD::QName.new(nil, "Id")]) 
     49    assert_equal("extraattr<>", body.extraattr[XSD::QName.new(nil, "Id")]) 
    5050    assert_equal("extraattr", header["headeritem"].element.extraattr[XSD::QName.new(nil, "Id")]) 
    5151  end