Module: JMS::MapMessage

Includes:
Enumerable
Defined in:
lib/jms/map_message.rb

Overview

Interface javax.jms.MapMessage

Instance Method Summary collapse

Instance Method Details

#dataObject

Return Map Message as a hash



15
16
17
# File 'lib/jms/map_message.rb', line 15

def data
  to_h
end

#data=(data) ⇒ Object

Copy values from supplied hash into this MapMessage Converts Ruby types to Java native Data types as follows:

Fixnum   => long
Float    => double
Bignum   => long
true     => boolean
false    => boolean
nil      => null
Otherwise it calls ::to_s on the supplied data type


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/jms/map_message.rb', line 28

def data=(data)
  data.each_pair do |key, val|
    case
    when val.class == Fixnum # 1
      setLong(key.to_s, val)
    when val.class == Float #1.1
      setDouble(key.to_s, val)
    when val.class == Bignum # 11111111111111111
      setLong(key.to_s, val)
    when (val.class == TrueClass) || (val.class == FalseClass)
      setBoolean(key.to_s, val)
    when val.class == NilClass
      setObject(key.to_s, val)
    else
      setString(key.to_s, val.to_s)
    end
  end
end

#each(&proc) ⇒ Object

Return each name value pair



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/jms/map_message.rb', line 48

def each(&proc)
  # When key and value are expected separately. Should actually be calling each_pair anyway
  if proc.arity == 2
    each_pair(proc)
  else
    enum = getMapNames
    while enum.has_more_elements
      key = enum.next_element
      proc.call [key, getObject(key)]
    end
  end
end

#each_pair(&proc) ⇒ Object

Return each name value pair



62
63
64
65
66
67
68
# File 'lib/jms/map_message.rb', line 62

def each_pair(&proc)
  enum = getMapNames
  while enum.has_more_elements
    key = enum.next_element
    proc.call key, getObject(key)
  end
end

#include?(key) ⇒ Boolean

Does map include specified key

Returns:

  • (Boolean)


71
72
73
74
# File 'lib/jms/map_message.rb', line 71

def include?(key)
  # Ensure a Ruby true is returned
  item_exists(key) == true
end

#to_hObject

Return Map Message as a hash



8
9
10
11
12
# File 'lib/jms/map_message.rb', line 8

def to_h
  h = {}
  each_pair { |key, value| h[key] = value }
  h
end