Class: Ooor::XMLJavaClient

Inherits:
Object
  • Object
show all
Defined in:
lib/app/models/ooor_java_client.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ooor, url, p, timeout) ⇒ XMLJavaClient

Returns a new instance of XMLJavaClient.



24
25
26
27
28
29
30
31
32
# File 'lib/app/models/ooor_java_client.rb', line 24

def initialize(ooor, url, p, timeout)
  @ooor = ooor
  @config = org.apache.xmlrpc.client.XmlRpcClientConfigImpl.new
  @config.setServerURL(java.net.URL.new(url))
  @config.setEnabledForExtensions(true);
  @client = org.apache.xmlrpc.client.XmlRpcClient.new
  @client.setTransportFactory(org.apache.xmlrpc.client.XmlRpcLiteHttpTransportFactory.new(@client));
  @client.setConfig(@config)
end

Class Method Details

.new2(ooor, url, p, timeout) ⇒ Object



34
35
36
# File 'lib/app/models/ooor_java_client.rb', line 34

def self.new2(ooor, url, p, timeout)
  XMLJavaClient.new(ooor, url, p, timeout)
end

Instance Method Details

#call(method, *args) ⇒ Object



77
78
79
80
81
82
83
84
85
# File 'lib/app/models/ooor_java_client.rb', line 77

def call(method, *args)
  begin
    res = @client.execute(method, javaize_array(args))
    return rubyize(res)
  rescue
    @error_ruby__wrapper ||= @ooor.get_ruby_rpc_client(@client.getConfig().getServerURL().to_s)
    @error_ruby__wrapper.call2(method, *args)
  end
end

#javaize_array(array) ⇒ Object



52
53
54
# File 'lib/app/models/ooor_java_client.rb', line 52

def javaize_array(array)
  array.map{|e| javaize_item(e)} #TODO: test if we need a t=[] array
end

#javaize_item(e) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/app/models/ooor_java_client.rb', line 38

def javaize_item(e)
  if e.is_a? Array
    return javaize_array(e)
  elsif e.is_a? Integer
    return e.to_java(java.lang.Integer)
  elsif e.is_a? Hash
    map = {}
    e.each {|k, v| map[k] = javaize_item(v)}
    return map
  else
    return e
  end
end

#rubyize(e) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/app/models/ooor_java_client.rb', line 56

def rubyize(e)
  if e.is_a? Java::JavaUtil::HashMap
    map = {}
    e.keys.each do |k|
      v = e[k]
      if (! v.is_a? String) && v.respond_to?('each') && (! v.is_a?(Java::JavaUtil::HashMap))
        map[k] = v.map {|i| rubyize(i)} #array
      else
        map[k] = rubyize(v)#v
      end
    end

    return map

  elsif (! e.is_a? String) && e.respond_to?('each') && (! e.is_a?(Java::JavaUtil::HashMap))
    return e.map {|i| rubyize(i)}
  else
    return e
  end
end