Jruby annotation support - something new?

Hello there,

a few month ago, I wanted to know whether jruby supports annotations.
Now I am at a point where I have the same question again. I read
something about using annotation-based frameworks like here:


But I don’t really understand how to use it.

In detail my idea is to use the jackrabbit object content manager
(annotation based) within jruby. I want to create a webb app which uses
jackrabbit as a kind of database.

http://jackrabbit.apache.org/5-with-jackrabbit-ocm.html

Has anyone some hints?

regards,
marco


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Fri, Jan 15, 2010 at 7:18 AM, Marco D. [email protected] wrote:

jackrabbit as a kind of database.

http://jackrabbit.apache.org/5-with-jackrabbit-ocm.html

Has anyone some hints?

Hi Marco,

Yes, the support is there, but it is still relatively new and still
subject to some change and hopefully improvements.

The basics of what is there right now boil down to the following:

  1. require ‘jruby/core_ext’. This loads the annotation methods into
    the Class class.
  2. add_method_signature(method_name,
    signature_array_with_return_type_first) sets a Java method signature
    for a Ruby method on the class.
  3. add_method_annotation(method_name,
    hash_with_annotation_type_keys_to_hash_values) set a method annotation
    on a Ruby method.
  4. add_class_annotation(hash_with_annotation_type_keys_to_hash_values)
    does the same but puts the annotation on the Ruby class.
  5. add_parameter_annotations(method_name, array_of_annotation_hashes)
    adds annotations to the parameters.
  6. When you’ve set all the signature and annotations on your Ruby
    classes, you call Class.becom_java! to turn the Ruby class into a real
    Java class that you can now hand to Java APIs that look for
    annotations.

My ruby-jersey stuff contains some small wrappers around these
low-level methods so that I could create something that looked like a
Ruby-ish annotation API in the code. Take a look at lib/annotated.rb
and lib/ruby-jersey.rb to see what I did.

The biggest limitations of this API so far are that 1) become_java!
can only be called once, and has to be done at runtime; 2) the
signature and annotation methods need existing class types to be
defined, so you can’t do annotations that refer to other Ruby-defined
types.

If you decide to play with the APIs, please share some examples and
let us know what works and what doesn’t. We’ll almost certainly be
improving that area of the code for the 1.5 release and beyond.

/Nick

class SomeRubyClass
def foo
end
add_method_annotation
end


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Hi,

until now I got it (jackrabbit ocm+jruby) working with a Java/jRuby mix.
The annotations itself I wrote in java classes, the rest in jRuby. I
will play around with the annotation api when I find the time. In my
case the annotated classes are known, so there’s nothing generic until
now. I’ll see what is possible and what not.
Any place where to put the samples best?

regards,
marco

Nick S. schrieb:

In detail my idea is to use the jackrabbit object content manager
Yes, the support is there, but it is still relatively new and still
hash_with_annotation_type_keys_to_hash_values) set a method annotation
My ruby-jersey stuff contains some small wrappers around these
If you decide to play with the APIs, please share some examples and


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Hey Nick,

it’s me again. I tried to translate my Java (annotated) class into a
ruby class. Unfortunately I don’t understand your example (ruby-jersey).
Can u provide an example (java and ruby class) where I can see how to
map Java annotations on ruby annotations. Or can I find such sample
somewhere?

thanks!

regards,
marco

Marco D. schrieb:

marco

http://github.com/nicksieger/ruby-jersey

signature_array_with_return_type_first) sets a Java method signature
Java class that you can now hand to Java APIs that look for
defined, so you can’t do annotations that refer to other Ruby-defined
end


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Hi Charlie,

I’ll give my very best :wink:
Thanks for your advices.

kind regards,
marco

Charles Oliver N. schrieb:

You need to dig a bit deeper. The annotation logic in Nick’s example

  • Charlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Mon, Jan 18, 2010 at 7:44 AM, Marco D. [email protected] wrote:

Hey Nick,

it’s me again. I tried to translate my Java (annotated) class into a ruby
class. Unfortunately I don’t understand your example (ruby-jersey). Can u
provide an example (java and ruby class) where I can see how to map Java
annotations on ruby annotations. Or can I find such sample somewhere?

You need to dig a bit deeper. The annotation logic in Nick’s example
is wrapping the actual core JRuby calls that bind extensions. Look in
his annotated.rb file to see how it’s mapping to real JRuby calls:
http://github.com/nicksieger/ruby-jersey/blob/master/lib/annotated.rb

Another option would be to look at Chris N.'s annotation-based
Hibernate experiment here: http://github.com/superchris/hibernate

Look under the covers a bit :slight_smile: It’s not too difficult, and can easily
be improved.

  • Charlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

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