PageRenderTime 48ms CodeModel.GetById 43ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/tools/Ruby/lib/ruby/1.8/soap/header/handlerset.rb

http://github.com/agross/netopenspace
Ruby | 70 lines | 46 code | 17 blank | 7 comment | 2 complexity | 027b7f00f741c56c07a496648284ba7f MD5 | raw file
 1# SOAP4R - SOAP Header handler set
 2# Copyright (C) 2003, 2004  NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
 3
 4# This program is copyrighted free software by NAKAMURA, Hiroshi.  You can
 5# redistribute it and/or modify it under the same terms of Ruby's license;
 6# either the dual license version in 2003, or any later version.
 7
 8
 9require 'xsd/namedelements'
10
11
12module SOAP
13module Header
14
15
16class HandlerSet
17  def initialize
18    @store = XSD::NamedElements.new
19  end
20
21  def dup
22    obj = HandlerSet.new
23    obj.store = @store.dup
24    obj
25  end
26
27  def add(handler)
28    @store << handler
29  end
30  alias << add
31
32  def delete(handler)
33    @store.delete(handler)
34  end
35
36  def include?(handler)
37    @store.include?(handler)
38  end
39
40  # returns: Array of SOAPHeaderItem
41  def on_outbound
42    @store.collect { |handler|
43      handler.on_outbound_headeritem
44    }.compact
45  end
46
47  # headers: SOAPHeaderItem enumerable object
48  def on_inbound(headers)
49    headers.each do |name, item|
50      handler = @store.find { |handler|
51        handler.elename == item.element.elename
52      }
53      if handler
54        handler.on_inbound_headeritem(item)
55      elsif item.mustunderstand
56        raise UnhandledMustUnderstandHeaderError.new(item.element.elename.to_s)
57      end
58    end
59  end
60
61protected
62
63  def store=(store)
64    @store = store
65  end
66end
67
68
69end
70end