Class: Naether::Java::JRuby
- Inherits:
-
Object
- Object
- Naether::Java::JRuby
- 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)
-
- (java.util.ArrayList) convert_to_java_list(ruby_array)
Convert a Ruby Array to a java.util.ArrayList.
-
- (Array) convert_to_ruby_array(java_array, to_string = false)
Convert a java,util.List to a Ruby Array.
-
- (Hash) convert_to_ruby_hash(java_hash, to_string = false)
Convert a java.util.Map to a Ruby Hash.
-
- (Object) create(target_class, *args)
Create a Java Object from the Naether Class Loader.
-
- (Object) exec_static_method(target_class, target_method, params, types = nil)
Execute a Staic method on a Java class from the Naether Class Loader.
-
- (JRuby) initialize
constructor
Creates new instance by loading the Naether jar to the parent 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 parent ClassLoader.
Constructor Details
- (JRuby) 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 |
# File 'lib/naether/java/jruby.rb', line 20 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
14 15 16 |
# File 'lib/naether/java/jruby.rb', line 14 def class_loader @class_loader end |
- (Object) loaded_paths (readonly)
Returns the value of attribute loaded_paths
14 15 16 |
# File 'lib/naether/java/jruby.rb', line 14 def loaded_paths @loaded_paths end |
Instance Method Details
- (java.util.ArrayList) convert_to_java_list(ruby_array)
Convert a Ruby Array to a java.util.ArrayList
115 116 117 118 119 120 121 122 |
# File 'lib/naether/java/jruby.rb', line 115 def convert_to_java_list( ruby_array ) list = java.util.ArrayList.new ruby_array.each do |item| list.add( item ) end list end |
- (Array) convert_to_ruby_array(java_array, to_string = false)
Convert a java,util.List to a Ruby Array
131 132 133 |
# File 'lib/naether/java/jruby.rb', line 131 def convert_to_ruby_array( java_array, to_string = false ) java_array.to_a end |
- (Hash) convert_to_ruby_hash(java_hash, to_string = false)
Convert a java.util.Map to a Ruby Hash
142 143 144 145 146 147 148 149 150 |
# File 'lib/naether/java/jruby.rb', line 142 def convert_to_ruby_hash( java_hash, to_string = false ) hash = java_hash.to_hash hash.each do |k,v| if v.is_a? java.util.Map hash[k] = convert_to_ruby_hash(v, to_string ) end end end |
- (Object) create(target_class, *args)
Create a Java Object from the Naether Class Loader
37 38 39 |
# File 'lib/naether/java/jruby.rb', line 37 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 from the Naether Class Loader
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/naether/java/jruby.rb', line 49 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
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/naether/java/jruby.rb', line 68 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 parent ClassLoader
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/naether/java/jruby.rb', line 91 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 |