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);
    }
    private static final ObjectAllocator ALLOCATOR = new ObjectAllocator() {
        public IRubyObject allocate(Ruby runtimeRubyClass klazz) {
            return new InterfaceJavaProxy(runtimeklazz);
        }
    };
    public static RubyClass createInterfaceJavaProxy(ThreadContext context) {
        final Ruby runtime = context.runtime;
        RubyClass InterfaceJavaProxy = runtime.defineClass(
            "InterfaceJavaProxy"runtime.getJavaSupport().getJavaProxyClass(), 
        );
        RubyClass JavaInterfaceExtended = runtime.defineClass(
            "JavaInterfaceExtender"runtime.getObject(), runtime.getObject().getAllocator()
        );
        JavaInterfaceExtended.defineAnnotatedMethods(JavaInterfaceExtender.class);
        return InterfaceJavaProxy;
    }
    public static class JavaInterfaceExtender {
        @JRubyMethod(visibility = .)
        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));
            self.getInternalVariables().getInternalVariable("@block");
            return context.nil;
        }
        @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