Package org.jruby.runtime.builtin

Examples of org.jruby.runtime.builtin.IRubyObject.toJava()


        IRubyObject val = value;
        if(val.dataGetStruct() instanceof JavaObject) {
            val = (IRubyObject)val.dataGetStruct();
        }
        try {
            Object convertedValue = val.toJava(field.getType());

            field.set(javaObject, convertedValue);
        } catch (IllegalAccessException iae) {
            throw getRuntime().newTypeError(
                                "illegal access on setting variable: " + iae.getMessage());
View Full Code Here


    }

    @Override
    public Object get(Object key) {
        IRubyObject gotten = internalGet(JavaUtil.convertJavaToUsableRubyObject(getRuntime(), key));
        return gotten == null ? null : gotten.toJava(Object.class);
    }

    @Override
    public Object put(Object key, Object value) {
        internalPut(JavaUtil.convertJavaToUsableRubyObject(getRuntime(), key), JavaUtil.convertJavaToUsableRubyObject(getRuntime(), value));
View Full Code Here

        }

        public Object next() {
            IRubyObject element = elt(index);
            last = index++;
            return element.toJava(Object.class);
        }

        public void remove() {
            if (last == -1) throw new IllegalStateException();
View Full Code Here

        Object[] converted = new Object[count];
       
        for (int i = 0; i < count; i++) {
            // TODO: call ruby method
            IRubyObject ith = constructor_args.aref(getRuntime().newFixnum(i));
            converted[i] = ith.toJava(parameterTypes[i]);
        }

        JavaProxyInvocationHandler handler = new JavaProxyInvocationHandler() {
            public IRubyObject getOrig() {
                return self;
View Full Code Here

                    throw runtime.newArgumentError(newArgs.length, v);
                }
                if (m.getReturnType() == void.class) {
                    return null;
                } else {
                    return result.toJava(m.getReturnType());
                }
            }
        };

        try {
View Full Code Here

        int count = (int) constructor_args.length().getLongValue();
        Object[] converted = new Object[count];
        for (int i = 0; i < count; i++) {
            // TODO: call ruby method
            IRubyObject ith = constructor_args.aref(getRuntime().newFixnum(i));
            converted[i] = ith.toJava(parameterTypes[i]);
        }

        final IRubyObject recv = this;

        JavaProxyInvocationHandler handler = new JavaProxyInvocationHandler() {
View Full Code Here

                for (int i = 0; i < length; i++) {
                    rubyArgs[i + 2] = JavaUtil.convertJavaToRuby(getRuntime(),
                            nargs[i]);
                }
                IRubyObject call_result = proc.call(getRuntime().getCurrentContext(), rubyArgs);
                Object converted_result = call_result.toJava(method.getReturnType());
                return converted_result;
            }

        };
View Full Code Here

                        ((RubyString) arg).getBytes(), Object.class
                );
            } else {
                // must be an IO object then
                IRubyObject stream = IOJavaAddons.AnyIO.any_to_inputstream(context, arg);
                o = mapper.readValue((InputStream) stream.toJava(InputStream.class), Object.class);
            }
            return RubyUtils.rubyObject(ruby, o);
        } catch (JsonProcessingException e) {
            throw ParseError.newParseError(ruby, e.getLocalizedMessage());
        } catch (IOException e) {
View Full Code Here

    @Override
    public Connection newConnection() throws SQLException {
        final ThreadContext context = contextProvider.getRuntime().getCurrentContext();
        final IRubyObject connection = driver.callMethod(context, "connection", new IRubyObject[] { url, username, password });
        return (Connection) connection.toJava(Connection.class);
    }

    IRubyObject getDriver() { return driver; } /* for tests */

}
 
View Full Code Here

    @SuppressWarnings("unchecked")
    protected Map<IRubyObject, Savepoint> getSavepoints(final ThreadContext context) {
        if ( hasInstanceVariable("@savepoints") ) {
            IRubyObject savepoints = getInstanceVariable("@savepoints");
            return (Map<IRubyObject, Savepoint>) savepoints.toJava(Map.class);
        }
        else { // not using a RubyHash to preserve order on Ruby 1.8 as well :
            Map<IRubyObject, Savepoint> savepoints = new LinkedHashMap<IRubyObject, Savepoint>(4);
            setInstanceVariable("@savepoints", convertJavaToRuby(savepoints));
            return savepoints;
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.