getBeanInfo from jruby

I’ve created a Bean and BeanInfo class on the java side, but I can’t
seem to call the introspector on it. The error seems to imply it’s
getting passed some kind of Ruby wrapper.

Introspector.getBeanInfo(Foo.class)

:34: no getBeanInfo with arguments matching [class org.jruby.RubyClass] on object Java::JavaBeans::Introspector (NameError) org.jruby.embed.EvalFailedException: no getBeanInfo with arguments matching [class org.jruby.RubyClass] on object Java::JavaBeans::Introspector Should org.jruby.RubyClass really be there? I've tried to explicit javaize it just to make sure it's not creating a wrapper, but it's not working either. Introspector.getBeanInfo(Foo.class.to_java)

The following should work:

require ‘java’
require ‘jruby/core_ext’

include_class “java.beans.Introspector”

class Test
attr_reader :getHello
end

result = Introspector.getBeanInfo(Test.become_java!)

props = result.getPropertyDescriptors()

props.each() do |prop|
p prop.getReadMethod().getName() if prop.getReadMethod() != nil
end

Regards
Roger

Am 15.11.2010 um 02:01 schrieb Josh S.:

Here you’re making a class in ruby and getting the BeanInfo from it?
I’m creating an object in jruby from a java class, where it doesn’t
have a become_java method.

Hi,

Did you try Introspector.setBeanInfoPath() to find out your BeanInfo
class?

On Tue, Nov 16, 2010 at 2:47 AM, Roger G. [email protected] wrote:

props.each() do |prop|
p prop.getReadMethod().getName() if prop.getReadMethod() != nil
end

At least, this Roger’s sample code worked when I created JTable class
in Java code and put that to ScriptingContainer:

ScriptingContainer container = new
ScriptingContainer(LocalContextScope.SINGLETHREAD);
JTable x = new JTable();
container.put(“x”, x);

Otherwise some example code would be nice…

Right. If you show us code example, you can get more help.

-Yoko

Maybe like this:

require ‘java’

include_class “java.beans.Introspector”
include_class “javax.swing.JTable”

x = JTable.new

result = Introspector.getBeanInfo(x.java_class)

props = result.getPropertyDescriptors()

props.each() do |prop|
p prop.getReadMethod().getName() if prop.getReadMethod() != nil
end

Otherwise some example code would be nice…

Regards
Roger

Am 16.11.2010 um 03:45 schrieb Josh S.:

.java_class was what I was looking for. Thanks everyone!