org.jruby.javasupport
Class JavaEmbedUtils

java.lang.Object
  extended by org.jruby.javasupport.JavaEmbedUtils

public class JavaEmbedUtils
extends java.lang.Object

Utility functions to help embedders out. These function consolidate logic that is used between BSF and JSR 223. People who are embedding JRuby 'raw' should use these as well. If at a later date, we discover a flaw or change how we do things, this utility class should provide some insulation.


Constructor Summary
JavaEmbedUtils()
           
 
Method Summary
static ClassCache createClassCache(java.lang.ClassLoader loader)
          Generate a class cache.
static Ruby initialize(java.util.List loadPaths)
          Get an instance of a JRuby runtime.
static Ruby initialize(java.util.List loadPaths, ClassCache classCache)
          Get an instance of a JRuby runtime.
static Ruby initialize(java.util.List loadPaths, RubyInstanceConfig config)
          Get an instance of a JRuby runtime.
static java.lang.Object invokeMethod(Ruby runtime, java.lang.Object receiver, java.lang.String method, java.lang.Object[] args, java.lang.Class returnType)
          Convenience function for embedders
static IRubyObject javaToRuby(Ruby runtime, boolean value)
           
static IRubyObject javaToRuby(Ruby runtime, byte value)
           
static IRubyObject javaToRuby(Ruby runtime, char value)
           
static IRubyObject javaToRuby(Ruby runtime, double value)
           
static IRubyObject javaToRuby(Ruby runtime, float value)
           
static IRubyObject javaToRuby(Ruby runtime, int value)
           
static IRubyObject javaToRuby(Ruby runtime, long value)
           
static IRubyObject javaToRuby(Ruby runtime, java.lang.Object value)
          Convert a java object to a Ruby object.
static IRubyObject javaToRuby(Ruby runtime, short value)
           
static RubyObjectAdapter newObjectAdapter()
           
static RubyRuntimeAdapter newRuntimeAdapter()
           
static java.lang.Object rubyToJava(Ruby runtime, IRubyObject value, java.lang.Class type)
          Convert a Ruby object to a Java object.
static void terminate(Ruby runtime)
          Dispose of the runtime you initialized.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JavaEmbedUtils

public JavaEmbedUtils()
Method Detail

initialize

public static Ruby initialize(java.util.List loadPaths)
Get an instance of a JRuby runtime. Provide any loadpaths you want used at startup.

Parameters:
loadPaths - to specify where to look for Ruby modules.
Returns:
an instance

initialize

public static Ruby initialize(java.util.List loadPaths,
                              ClassCache classCache)
Get an instance of a JRuby runtime. Provide any loadpaths you want used at startup.

Parameters:
loadPaths - to specify where to look for Ruby modules.
classCache - to use as a common repository for cached classes
Returns:
an instance

initialize

public static Ruby initialize(java.util.List loadPaths,
                              RubyInstanceConfig config)
Get an instance of a JRuby runtime.

Parameters:
loadPaths - additional load paths you wish to add
config - a runtime configuration instance
Returns:
an instance

createClassCache

public static ClassCache createClassCache(java.lang.ClassLoader loader)
Generate a class cache. This will end up setting max cache size per JRuby preferences (e.g. jruby.jit.max).

Parameters:
loader - use the provided classloader to create the cache
Returns:

newObjectAdapter

public static RubyObjectAdapter newObjectAdapter()

newRuntimeAdapter

public static RubyRuntimeAdapter newRuntimeAdapter()

terminate

public static void terminate(Ruby runtime)
Dispose of the runtime you initialized.

Parameters:
runtime - to be disposed of

invokeMethod

public static java.lang.Object invokeMethod(Ruby runtime,
                                            java.lang.Object receiver,
                                            java.lang.String method,
                                            java.lang.Object[] args,
                                            java.lang.Class returnType)
Convenience function for embedders

Parameters:
runtime - environment where the invoke will occur
receiver - is the instance that will receive the method call
method - is method to be called
args - are the arguments to the method
returnType - is the type we want it to conform to
Returns:
the result of the invocation.

rubyToJava

public static java.lang.Object rubyToJava(Ruby runtime,
                                          IRubyObject value,
                                          java.lang.Class type)
Convert a Ruby object to a Java object.


javaToRuby

public static IRubyObject javaToRuby(Ruby runtime,
                                     java.lang.Object value)
Convert a java object to a Ruby object.


javaToRuby

public static IRubyObject javaToRuby(Ruby runtime,
                                     boolean value)

javaToRuby

public static IRubyObject javaToRuby(Ruby runtime,
                                     byte value)

javaToRuby

public static IRubyObject javaToRuby(Ruby runtime,
                                     char value)

javaToRuby

public static IRubyObject javaToRuby(Ruby runtime,
                                     double value)

javaToRuby

public static IRubyObject javaToRuby(Ruby runtime,
                                     float value)

javaToRuby

public static IRubyObject javaToRuby(Ruby runtime,
                                     int value)

javaToRuby

public static IRubyObject javaToRuby(Ruby runtime,
                                     long value)

javaToRuby

public static IRubyObject javaToRuby(Ruby runtime,
                                     short value)


Copyright © 2002-2007 JRuby Team. All Rights Reserved.