Class: Naether::Java

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/naether/java.rb,
lib/naether/java/ruby.rb,
lib/naether/java/jruby.rb

Defined Under Namespace

Classes: JRuby, Ruby

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeJava

Creates new instance by loading the Naether jar to the parent ClassLoader and creating the internal Naether ClassLoader



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/naether/java.rb', line 20

def initialize()
  naether_jar = Naether::Configuration.naether_jar
  
  unless File.exists? naether_jar
    raise "Cannot create Naether::Java: #{naether_jar} does not exist"
  end
  
  if Naether::Configuration.platform == 'java'
    require "#{File.dirname(__FILE__)}/java/jruby"
    @java = Naether::Java::JRuby.new
  else
    require "#{File.dirname(__FILE__)}/java/ruby"
    @java = Naether::Java::Ruby.new
  end
end

Instance Attribute Details

#javaObject (readonly)

Returns the value of attribute java.



14
15
16
# File 'lib/naether/java.rb', line 14

def java
  @java
end

Class Method Details

.convert_to_java_list(ruby_array) ⇒ java.util.ArrayList

Convert a Ruby Array to a java.util.ArrayList

Parameters:

  • ruby_array (Array)

    to convert to Java.util.ArrayList

Returns:

  • (java.util.ArrayList)


94
95
96
# File 'lib/naether/java.rb', line 94

def self.convert_to_java_list( ruby_array )
  instance.java.convert_to_java_list( ruby_array )
end

.convert_to_ruby_array(java_array, to_string = false) ⇒ Array

Convert a java,util.List to a Ruby Array

Parameters:

  • java_array (java.util.ArrayList)
  • to_string (Boolean) (defaults to: false)

    platform dependent helper

Returns:

  • (Array)


105
106
107
# File 'lib/naether/java.rb', line 105

def self.convert_to_ruby_array( java_array, to_string = false )
  instance.java.convert_to_ruby_array( java_array, to_string )
end

.convert_to_ruby_hash(java_hash, to_string = false) ⇒ Hash

Convert a java.util.Map to a Ruby Hash

Parameters:

  • java_hash (java.util.Map)
  • to_string (Boolean) (defaults to: false)

    platform dependent helper

Returns:

  • (Hash)


116
117
118
# File 'lib/naether/java.rb', line 116

def self.convert_to_ruby_hash( java_hash, to_string = false )
  instance.java.convert_to_ruby_hash( java_hash, to_string )
end

.create(target_class, *args) ⇒ Object

Create a Java Object from the Naether Class Loader

Parameters:

  • target_class (String)

    to create

  • args (Array)

    Array of constructor arguments



72
73
74
# File 'lib/naether/java.rb', line 72

def self.create( target_class, *args )
  instance.java.create( target_class, *args )
end

.exec_static_method(target_class, target_method, params, types = nil) ⇒ Object

Execute a Staic method on a Java class from the Naether Class Loader

Parameters:

  • target_class (String)
  • target_method (String)
  • params (Array)

    Array of method parameters

  • types (Array) (defaults to: nil)

    if defined, a Array of String classes of params type that lines up with params one to one.

Returns:

  • (Object)


84
85
86
# File 'lib/naether/java.rb', line 84

def self.exec_static_method( target_class, target_method, params, types = nil ) 
  instance.java.exec_static_method( target_class, target_method, params, types )
end

.internal_load_paths(paths) ⇒ Object

Load a path into the internal Naether ClassLoader

Parameters:

  • paths (Array)

    as an Array of String paths or a String path



63
64
65
# File 'lib/naether/java.rb', line 63

def self.internal_load_paths(paths)
  instance.java.internal_load_paths(paths)
end

.internal_loaded_pathsObject



54
55
56
# File 'lib/naether/java.rb', line 54

def self.internal_loaded_paths
  convert_to_ruby_array( instance.java.class_loader.getLoadedPaths, true )
end

.load_paths(paths) ⇒ Object

Load a path onto the parent ClassLoader

Parameters:

  • paths (Array)

    as an Array of String paths or a String path



50
51
52
# File 'lib/naether/java.rb', line 50

def self.load_paths(paths)
  instance.java.load_paths(paths)
end

.loaded_pathsArray

Paths loaded

Returns:

  • (Array)

    of String paths



41
42
43
# File 'lib/naether/java.rb', line 41

def self.loaded_paths
  instance.java.loaded_paths
end