Class: Naether::Java::JRuby
- Inherits:
-
Object
- Object
- Naether::Java::JRuby
- Includes:
- Singleton
- Defined in:
- lib/naether/java/jruby.rb
Instance Attribute Summary (collapse)
-
- (Object) class_loader
readonly
Returns the value of attribute class_loader.
-
- (Object) loaded_paths
readonly
Returns the value of attribute loaded_paths.
Instance Method Summary (collapse)
-
- (Object) convert_to_java_list(ruby_array)
Convert a Ruby Array to a Java ArrayList.
-
- (Object) convert_to_ruby_array(java_array, to_string = false)
Convert a Java List to a Ruby Array.
-
- (Object) convert_to_ruby_hash(java_hash, to_string = false)
Convert a Java Map to a Ruby Hash.
-
- (Object) create(target_class, *args)
Create a Java Object.
-
- (Object) exec_static_method(target_class, target_method, params, types = nil)
Execute a Staic method on a Java class.
-
- (JRuby) initialize
constructor
Creates new instance by loading the Naether jar to the global ClassLoader and creating the internal Naether ClassLoader.
-
- (Object) internal_load_paths(paths)
Load a path into the internal Naether ClassLoader.
-
- (Object) load_paths(paths)
Load a path onto the Global ClassLoader.
Constructor Details
- (JRuby) initialize
Creates new instance by loading the Naether jar to the global ClassLoader and creating the internal Naether ClassLoader
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/naether/java/jruby.rb', line 23 def initialize require 'java' naether_jar = Naether::Configuration.naether_jar @loaded_paths = [] load_paths(naether_jar) @class_loader = com.tobedevoured.naether.PathClassLoader.new() internal_load_paths(naether_jar) end |
Instance Attribute Details
- (Object) class_loader (readonly)
Returns the value of attribute class_loader
17 18 19 |
# File 'lib/naether/java/jruby.rb', line 17 def class_loader @class_loader end |
- (Object) loaded_paths (readonly)
Returns the value of attribute loaded_paths
17 18 19 |
# File 'lib/naether/java/jruby.rb', line 17 def loaded_paths @loaded_paths end |
Instance Method Details
- (Object) convert_to_java_list(ruby_array)
Convert a Ruby Array to a Java ArrayList
104 105 106 107 108 109 110 111 |
# File 'lib/naether/java/jruby.rb', line 104 def convert_to_java_list( ruby_array ) list = java.util.ArrayList.new ruby_array.each do |item| list.add( item ) end list end |
- (Object) convert_to_ruby_array(java_array, to_string = false)
Convert a Java List to a Ruby Array
116 117 118 |
# File 'lib/naether/java/jruby.rb', line 116 def convert_to_ruby_array( java_array, to_string = false ) java_array.to_a end |
- (Object) convert_to_ruby_hash(java_hash, to_string = false)
Convert a Java Map to a Ruby Hash
123 124 125 |
# File 'lib/naether/java/jruby.rb', line 123 def convert_to_ruby_hash( java_hash, to_string = false ) java_hash.to_hash end |
- (Object) create(target_class, *args)
Create a Java Object
38 39 40 |
# File 'lib/naether/java/jruby.rb', line 38 def create( target_class, *args ) @class_loader.newInstance(target_class, *args ) end |
- (Object) exec_static_method(target_class, target_method, params, types = nil)
Execute a Staic method on a Java class
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/naether/java/jruby.rb', line 45 def exec_static_method( target_class, target_method, params, types = nil ) unless params.is_a? Array params = [params] end if types unless types.is_a? Array types = [types] end end @class_loader.execStaticMethod( target_class, target_method, params, types ) end |
- (Object) internal_load_paths(paths)
Load a path into the internal Naether ClassLoader
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/naether/java/jruby.rb', line 62 def internal_load_paths(paths) load_paths = [] unless paths.is_a? Array paths = [paths] end paths.each do |path| = File.(path) if File.exists?( ) @class_loader.addPath( ) load_paths << end end load_paths end |
- (Object) load_paths(paths)
Load a path onto the Global ClassLoader
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/naether/java/jruby.rb', line 83 def load_paths(paths) load_paths = [] unless paths.is_a? Array paths = [paths] end paths.each do |path| = File.(path) if !@loaded_paths.include?( ) && File.exists?( ) $CLASSPATH << load_paths << @loaded_paths << end end load_paths end |