Forum: JRuby JRuby class with BeanInfo capabilities

61ddaf7702fb0a4bff8f7345c958319c?d=identicon&s=25 "Anders Engström" <epirealer@gmail.com> (Guest)
on 2013-11-21 10:59
(Received via mailing list)
Hi!

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
         from("file:some/path").to("seda://queue_name")
     end

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
     end

     xs = XStream.new
     xs.setClassLoader(...)
     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.
     end

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
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.