Encapsulate @java_proxy_class computation in JavaProxy
------------------------------------------------------

                 Key: JRUBY-5800
                 URL: http://jira.codehaus.org/browse/JRUBY-5800
             Project: JRuby
          Issue Type: Improvement
            Reporter: Kohsuke Kawaguchi
            Assignee: Thomas E Enebo


In working with Jenkins <http://jenkins-ci.org/> & JRuby integration, I've 
identified the following problem. The issue concerns itself with the 
deserialization of JavaProxy from XML.

To deserialize JavaProxy, I need to create two objects: Ruby side of the object 
identify that is the instance of the JavaProxy class (I'll refer to this as #1) 
and Java side of the object identify that implements InternalJavaProxy (I'll 
refer to this as #2). And I need to do this *without calling the constructor of 
#2*, yet currently in JRuby, the only route to properly initialize #1 is to let 
it instantiate #2 via the special method "__jcreate!".

We need to generate a Java class on the fly to represent #2, and looking at 
{{org.jruby.javasupport.Java}}, it appears that this class is captured in 
{{@java_proxy_class}}, but this logic entirely lives in the {{Java}} class. The 
code in question is cited below for your reference:

{noformat}
        rubySubclass.addMethod("__jcreate!", new JavaMethodN(subclassSingleton, 
PUBLIC) {
            private final Map<Integer, ParameterTypes> methodCache = new 
HashMap<Integer, ParameterTypes>();
            @Override
            public IRubyObject call(ThreadContext context, IRubyObject self, 
RubyModule clazz, String name, IRubyObject[] args) {
                IRubyObject proxyClass = 
self.getMetaClass().getInstanceVariables().fastGetInstanceVariable("@java_proxy_class");
                if (proxyClass == null || proxyClass.isNil()) {
                    proxyClass = JavaProxyClass.get_with_class(self, 
self.getMetaClass());
                    
self.getMetaClass().getInstanceVariables().fastSetInstanceVariable("@java_proxy_class",
 proxyClass);
                }
{noformat}

I'd like to see this logic move to the JavaProxy class, so that I can get the 
proxy class without duplicating the above code on my side. It'd be something 
like this:

{noformat}
class JavaProxy {
    ...

    public JavaProxyClass getJavaProxyClass() {
        IRubyObject proxyClass = 
getMetaClass().getInstanceVariables().fastGetInstanceVariable("@java_proxy_class");
        if (proxyClass == null || proxyClass.isNil()) {
            proxyClass = JavaProxyClass.get_with_class(this, 
original.getMetaClass());
            
getMetaClass().getInstanceVariables().fastSetInstanceVariable("@java_proxy_class",
 proxyClass);
        }
        return (JavaProxyClass)proxyClass;
    }
}
{noformat}


-- 
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


Reply via email to