Integrating with Java inner classes?

Below is a simple script (using JRuby 1.1.4 on Win2K) that tries to use
the StringTemplate library JAR. Things work OK when trying to use Java
classes that don’t have inner classes…or partially implement Java
interfaces.

I’m rewarded with a ‘cannot link Java class
org.antlr.stringtemplate.StringTemplate’ exception when trying to use
the Java class StringTemplate that has 2 final static inner classes.

There’s a decent chance I missed some bit-o-info on the wiki site, but
what am I not getting?

Thanks, Jon

===================================

begin
raise LoadError, ‘missing JRuby’ unless RUBY_PLATFORM == ‘java’
require ‘java’
require ‘D:/Jon/My Documents/JavaDev/antlr/lib/stringtemplate-3.2.jar’
rescue LoadError => e
puts “#{e.message}; exiting…”
exit -1
end

this causes a NameError saying cannot link the class.

error thrown from

$JRUBY_HOME/lib/ruby/1.8/rubygems/custom_require.rb:27

in ‘method_missing’

#import org.antlr.stringtemplate.StringTemplate

why is there nothing in the STModule.constants array after this?

module STModule
include_package org.antlr.stringtemplate
end

but there’s a Java::OrgAntlr and Java::OrgAntlrStringtemplate?

if Java.constants.index(‘OrgAntlrStringtemplate’)
ST = Java::OrgAntlrStringtemplate

begin
# can use a class that doesn’t have inner classes
aiw = ST::AutoIndentWriter.new(Java::JavaIo::PrintWriter.new(
Java::JavaLang::System.out)) # yuck!
puts “Indentation = #{aiw.get_indentation_width}”

# can partially implement a Java interface in a Ruby class
class MyListener
  include ST::StringTemplateErrorListener
  def warning(msg)
    puts msg
  end
end
MyListener.new.warning '[WARNING] just testing...'

# but can't seem to use a class with inner classes :(
st = ST::StringTemplate.new 'Hello $name$ from StringTemplate!'
st.set_attribute 'name', 'Someone'

rescue Exception => e
puts e.message
end

end


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email