Plug ruby2java java2ruby marshalling
------------------------------------
Key: JRUBY-4670
URL: http://jira.codehaus.org/browse/JRUBY-4670
Project: JRuby
Issue Type: New Feature
Components: Embedding
Affects Versions: JRuby 1.5
Reporter: Alex K
Priority: Minor
It would be nice to have plug in mechanism for the marshalling of ruby objects.
Currently i need a wrapper method to do this:
-- snip
private Object ruby2Java(Object obj) {
Object l_ret;
if (obj == null || obj instanceof RubyNil) {
return null;
}
if (!(obj instanceof IRubyObject)) {
return obj;
}
l_ret = (IRubyObject) obj;
if (l_ret instanceof RubyObject) {
if (l_ret instanceof RubyHash) {
RubyHash l_hash = RubyHash.newHash(_rubyObj.getRuntime());
for (Object l_key : ((RubyHash) l_ret).keys()) {
l_hash.put(ruby2Java(l_key), ruby2Java(((RubyHash)
l_ret).get(l_key)));
}
return l_hash;
}
if (l_ret instanceof RubyArray) {
RubyArray l_array = RubyArray.newArray(_rubyObj.getRuntime());
for (int i = 0; i < ((RubyArray) l_ret).size(); i++) {
l_array.add(ruby2Java(((RubyArray) l_ret).get(i)));
}
return l_array;
}
if( l_ret instanceof RubyTime ) {
return new Date( ((RubyTime)l_ret).getDateTime().getMillis() );
}
if ("DateTime".equals(((RubyObject) l_ret).getType().toString()) ||
"Date".equals(((RubyObject) l_ret).getType().toString()) ||
"Time".equals(((RubyObject) l_ret).getType().toString()) ) {
RubyString l_value = (RubyString) ((RubyObject)
l_ret).callMethod("strftime", new
IRubyObject[]{RubyString.newString(_rubyObj.getRuntime(), "%Q")});
return new Date(Long.parseLong(l_value.asJavaString()));
}
if ("At::Illumine::DomainCenter::DateSpan".equals(((RubyObject)
l_ret).getType().toString())) {
RubyString l_value = (RubyString) ((RubyObject)
l_ret).callMethod("to_s", new IRubyObject[]{});
return new DateSpan(l_value.asJavaString());
}
Object l_native =
((RubyObject)l_ret).toJava(((RubyObject)l_ret).getJavaClass() );
if( l_native != null && !(l_native instanceof RubyObject))
return l_native;
Object l_domain = ((RubyObject)
l_ret).callMethod("session_context", new
IRubyObject[]{RubyString.newString(_rubyObj.getRuntime(), "java")});
if (l_domain instanceof RubyNil) {
l_ret = DomainContainer.getInstance().create((RubyObject)
l_ret);
} else {
l_ret = ((ConcreteJavaProxy) l_domain).getObject();
}
}
return l_ret;
}
-- snip
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email