Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * To change this template, choose Tools | Templates
  * and open the template in the editor.
  */
 
 package org.jruby.java.proxies;
 
 import org.jruby.Ruby;

Author(s):
headius
public class InterfaceJavaProxy extends JavaProxy {
    public InterfaceJavaProxy(Ruby runtimeRubyClass klazz) {
        super(runtimeklazz);
    }
    public static RubyClass createInterfaceJavaProxy(ThreadContext context) {
        Ruby runtime = context.runtime;
        
        RubyClass ifcJavaProxy = runtime.defineClass(
                "InterfaceJavaProxy",
                runtime.getJavaSupport().getJavaProxyClass(), new ObjectAllocator() {
            public IRubyObject allocate(Ruby runtimeRubyClass klazz) {
                return new InterfaceJavaProxy(runtimeklazz);
            }
        });
        RubyClass javaIfcExtender = runtime.defineClass(
                "JavaInterfaceExtender"runtime.getObject(), runtime.getObject().getAllocator());
        javaIfcExtender.defineAnnotatedMethods(JavaInterfaceExtender.class);
        return ifcJavaProxy;
    }
    public static class JavaInterfaceExtender {
        @JRubyMethod
        public static IRubyObject initialize(ThreadContext contextIRubyObject selfIRubyObject javaClassNameBlock block) {
            Ruby runtime = context.runtime;
            
            self.getInstanceVariables().setInstanceVariable("@java_class", JavaClass.forNameVerbose(runtimejavaClassName.asJavaString()));
            self.getInstanceVariables().setInstanceVariable("@block", RubyProc.newProc(runtimeblockblock.type));
            return runtime.getNil();
        }
        @JRubyMethod
        public static IRubyObject extend_proxy(ThreadContext contextIRubyObject selfIRubyObject proxyClass) {
            return proxyClass.callMethod(context"class_eval".,
                    ((RubyProc)self.getInstanceVariables().getInstanceVariable("@block")).getBlock());
        }
    }
New to GrepCode? Check out our FAQ X