JRuby class with BeanInfo capabilities


This is the scenario: I’m using JRuby to create a small DSL for creating
Apache Camel routes in an OSGi environment. Things are working nicely,
and it’s possible to load jruby scripts such as:

 require 'lib/dsl'
 Route.create do

This works for simple camel-routes, but what I’d like to do is to use
some of the ‘bean-binding’ capabilities in Camel components (for example
Xstream - to marshall to/from XML):

 class PersonType
     attr_accessor :id, :name

 xs = XStream.new
 xs.alias("person", PersonType.java_class)
 fmt = XStreamDataFormat.new(xs)

 # The XML files would look like:
 # <list>
 #   <person>
 #       <id>2</id>
 #       <name>Foo</name>
 #   </person>
 #   <person>....</person>
 # </list>
 from("file:some/path").marshal().string().unmarshal(fmt).process do
     # Process the XML data as a list of Person instances.

This fails because (I believe) the PersonType.java_class does not return
a JavaBean compatible class.

I’ve made some experiments to create a Ruby class and have it “quack”
like a java-bean by looking at it with the java.beans.Introspector -
but without success.

Any ideas on how to approach this?

Best Regards //Anders

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs