public IRubyObject allocate(Ruby runtime, RubyClass klazz) { return new ConcreteJavaProxy(runtime, klazz); } };
private static Class<?> getClass(final IRubyObject object) { if (object == null) return void.class; if (object instanceof ConcreteJavaProxy) { return ((ConcreteJavaProxy) object).getJavaClass(); } return object.getClass(); }
/** * Because we can't physically associate an ID with a Java object, we can * only use the identity hashcode here. * * @return The identity hashcode for the Java object. */ @Override public IRubyObject id() { return getRuntime().newFixnum(System.identityHashCode(getObject())); }
@JRubyMethod(name = "===", meta = true) public static IRubyObject op_eqq(ThreadContext context, IRubyObject recv, IRubyObject other) { Ruby runtime = context.runtime; // special case non-FlowControlException Java exceptions so they'll be caught by rescue Exception if (other instanceof ConcreteJavaProxy && (recv == runtime.getException() || recv == runtime.getStandardError())) { Object object = ((ConcreteJavaProxy)other).getObject(); if (object instanceof Throwable && !(object instanceof FlowControlException)) { return context.runtime.getTrue(); } } // fall back on default logic return ((RubyClass)recv).op_eqq(context, other); }
public static RubyClass createConcreteJavaProxy(final ThreadContext context) { final Ruby runtime = context.runtime; final RubyClass JavaProxy = runtime.getJavaSupport().getJavaProxyClass(); RubyClass ConcreteJavaProxy = runtime.defineClass("ConcreteJavaProxy", JavaProxy, ALLOCATOR); initialize(ConcreteJavaProxy); return ConcreteJavaProxy; }
ConcreteJavaProxy.createConcreteJavaProxy(context); InterfaceJavaProxy.createInterfaceJavaProxy(context); ArrayJavaProxy.createArrayJavaProxy(context);
@JRubyMethod(name = "===", meta = true) public static IRubyObject op_eqq(ThreadContext context, IRubyObject recv, IRubyObject other) { Ruby runtime = context.runtime; // special case non-FlowControlException Java exceptions so they'll be caught by rescue Exception if (other instanceof ConcreteJavaProxy && (recv == runtime.getException() || recv == runtime.getStandardError())) { Object object = ((ConcreteJavaProxy)other).getObject(); if (object instanceof Throwable && !(object instanceof FlowControlException)) { return context.runtime.getTrue(); } } // fall back on default logic return ((RubyClass)recv).op_eqq(context, other); }
public static RubyClass createMapJavaProxy(final Ruby runtime) { RubyClass MapJavaProxy = runtime.defineClass( "MapJavaProxy", runtime.getJavaSupport().getConcreteProxyClass(), ALLOCATOR ); // this is done while proxy class is created. // See org.jruby.javasuppoer.java.createProxyClass() // MapJavaProxy.defineAnnotatedMethods(MapJavaProxy.class); ConcreteJavaProxy.initialize(MapJavaProxy); return MapJavaProxy; }
ConcreteJavaProxy.createConcreteJavaProxy(context); InterfaceJavaProxy.createInterfaceJavaProxy(context); ArrayJavaProxy.createArrayJavaProxy(context);
/** * Because we can't physically associate an ID with a Java object, we can * only use the identity hashcode here. * * @return The identity hashcode for the Java object. */ @Override public IRubyObject id() { return getRuntime().newFixnum(System.identityHashCode(getObject())); }
@JRubyMethod(name = "===", meta = true) public static IRubyObject op_eqq(ThreadContext context, IRubyObject recv, IRubyObject other) { Ruby runtime = context.runtime; // special case non-FlowControlException Java exceptions so they'll be caught by rescue Exception if (other instanceof ConcreteJavaProxy && (recv == runtime.getException() || recv == runtime.getStandardError())) { Object object = ((ConcreteJavaProxy)other).getObject(); if (object instanceof Throwable && !(object instanceof FlowControlException)) { if (recv == runtime.getException() || object instanceof java.lang.Exception) { return context.tru; } } } // fall back on default logic return ((RubyClass)recv).op_eqq(context, other); }
public static RubyClass createMapJavaProxy(final Ruby runtime) { RubyClass MapJavaProxy = runtime.defineClass( "MapJavaProxy", runtime.getJavaSupport().getConcreteProxyClass(), ALLOCATOR ); // this is done while proxy class is created. // See org.jruby.javasuppoer.java.createProxyClass() // MapJavaProxy.defineAnnotatedMethods(MapJavaProxy.class); ConcreteJavaProxy.initialize(MapJavaProxy); return MapJavaProxy; }
private static Class argClassTypeError(Object object) { if (object == null) { return void.class; } if (object instanceof ConcreteJavaProxy) { return ((ConcreteJavaProxy)object).getJavaClass(); } return object.getClass(); }
public IRubyObject allocate(Ruby runtime, RubyClass klazz) { return new ConcreteJavaProxy(runtime, klazz); } };
ConcreteJavaProxy.createConcreteJavaProxy(context); InterfaceJavaProxy.createInterfaceJavaProxy(context); ArrayJavaProxy.createArrayJavaProxy(context);
/** * Because we can't physically associate an ID with a Java object, we can * only use the identity hashcode here. * * @return The identity hashcode for the Java object. */ public IRubyObject id() { return getRuntime().newFixnum(System.identityHashCode(getObject())); }
private static void maybeRaiseJavaException(final Ruby runtime, final IRubyObject[] args, final int argc, final IRubyObject cause) { // Check for a Java exception ConcreteJavaProxy exception = null; switch (argc) { case 0: IRubyObject lastException = runtime.getGlobalVariables().get("$!"); if (lastException instanceof ConcreteJavaProxy) { exception = (ConcreteJavaProxy) lastException; } break; case 1: if (args.length == 1 && args[0] instanceof ConcreteJavaProxy) { exception = (ConcreteJavaProxy) args[0]; } break; } if (exception != null) { // looks like someone's trying to raise a Java exception. Let them. Object maybeThrowable = exception.getObject(); if (!(maybeThrowable instanceof Throwable)) { throw runtime.newTypeError("can't raise a non-Throwable Java object"); } final Throwable ex = (Throwable) maybeThrowable; Helpers.throwException(ex); return; // not reached } }
public static RubyClass createConcreteJavaProxy(final ThreadContext context) { final Ruby runtime = context.runtime; final RubyClass JavaProxy = runtime.getJavaSupport().getJavaProxyClass(); RubyClass ConcreteJavaProxy = runtime.defineClass("ConcreteJavaProxy", JavaProxy, ALLOCATOR); initialize(ConcreteJavaProxy); return ConcreteJavaProxy; }
private static Class<?> getClass(final IRubyObject object) { if (object == null) return void.class; if (object instanceof ConcreteJavaProxy) { return ((ConcreteJavaProxy) object).getJavaClass(); } return object.getClass(); }
public IRubyObject allocate(Ruby runtime, RubyClass klazz) { return new ConcreteJavaProxy(runtime, klazz); } });