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

- (Java) initialize

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

- (Object) java (readonly)

Returns the value of attribute java



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

def java
  @java
end

Class Method Details

+ (java.util.ArrayList) convert_to_java_list(ruby_array)

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

+ (Array) convert_to_ruby_array(java_array, to_string = false)

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

+ (Hash) convert_to_ruby_hash(java_hash, to_string = false)

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

+ (Object) create(target_class, *args)

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

+ (Object) exec_static_method(target_class, target_method, params, types = nil)

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

+ (Object) internal_load_paths(paths)

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

+ (Object) internal_loaded_paths



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

+ (Object) load_paths(paths)

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

+ (Array) loaded_paths

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