Class: JRubyFX::PolyglotClassLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/jrubyfx/module.rb

Overview

FXML requires loading both ruby and java classes. JRuby has no such single classloader builtin, so we proxy them all This is a minimal classloader only for classes, resources not supported

Instance Method Summary collapse

Constructor Details

#initializePolyglotClassLoader

Returns a new instance of PolyglotClassLoader.



189
190
191
192
# File 'lib/jrubyfx/module.rb', line 189

def initialize()
  super(JRuby.runtime.jruby_class_loader)
  @prefix = File.basename(fxml_root) + "."
end

Instance Method Details

#findClass(a) ⇒ Object



194
195
196
197
198
199
200
201
202
# File 'lib/jrubyfx/module.rb', line 194

def findClass(a)
  return nil unless a.start_with? @prefix or a[0].upcase == a[0]
  a = a[@prefix.length..-1] unless a[0].upcase == a[0]
  begin # TODO: become_java! idempotent?
    return a.constantize_by(/[.$]/).tap{|x| x.become_java!}.java_class
  rescue NameError
    raise java.lang.ClassNotFoundException.new("Could not find Ruby or Java class '#{a.gsub(/[.$]/, "::")}' or '#{a}'") # Must be a java CNF, not a Ruby Name Error
  end
end