Module: Rjb

Defined in:
ext/rjb.c,
lib/rjb.rb

Defined Under Namespace

Modules: JMethod, MODIFIER Classes: Rjb_JavaClass, Rjb_JavaProxy

Constant Summary

VERSION =
rb_str_new2(RJB_VERSION)

Class Method Summary collapse

Class Method Details

.add_classpathObject

Rjb::add_classpath(jarname)



# File 'ext/rjb.c'

static VALUE rjb_s_add_classpath(VALUE self, VALUE jarname)
{
    VALUE cpath = rb_cvar_get(self, cvar_classpath);
    SafeStringValue(jarname);
    rb_ary_push(cpath, jarname);
    return cpath;
}

.add_jarObject

Rjb::add_jar(jarname)



# File 'ext/rjb.c'

static VALUE rjb_s_add_jar(VALUE self, VALUE jarname)
{
size_t i;
JNIEnv* jenv;
size_t count;
jvalue args[2];

if (rb_type(jarname) != T_ARRAY)
{
    SafeStringValue(jarname);
    count = 0;
}

.bindObject

jclass Rjb::bind(rbobj, interface_name)



# File 'ext/rjb.c'

static VALUE rjb_s_bind(VALUE self, VALUE rbobj, VALUE itfname)
{
VALUE result = Qnil;
jclass itf;
JNIEnv* jenv = rjb_prelude();

itf = rjb_find_class(jenv, itfname); 
rjb_check_exception(jenv, 1);
if (itf)
{
struct rj_bridge* ptr = ALLOC(struct rj_bridge);
memset(ptr, 0, sizeof(struct rj_bridge));
ptr->bridge = (*jenv)->NewGlobalRef(jenv,
                               (*jenv)->AllocObject(jenv, rjb_rbridge));
if (!ptr->bridge)
{
    free(ptr);
    rjb_check_exception(jenv, 1);
    return Qnil;
}

.classesObject

return all classes that were already loaded. this method simply returns the global hash, but it's safe because the hash was frozen.



# File 'ext/rjb.c'

static VALUE rjb_s_classes(VALUE self)
{
    return rjb_loaded_classes;
}

.importObject

Jclass Rjb::import(classname)



# File 'ext/rjb.c'

static VALUE rjb_s_import(VALUE self, VALUE clsname)
{
JNIEnv* jenv;
jclass jcls;
VALUE v = rb_hash_aref(rjb_loaded_classes, clsname);
if (v != Qnil)
{
return v;
}

.loadObject

load Java Virtual Machine def load(class_path = '', vmargs = []) class_path: passes for the class dir and jar name vmargs: strng array of vmarg (such as -Xrs)

change in rjb 0.1.7, omit first argument for JNI version.

because I misunderstood the number means (JVM but JNI).


# File 'ext/rjb.c'

static VALUE rjb_s_load(int argc, VALUE* argv, VALUE self)
{
JNIEnv* jenv;
JavaVMInitArgs vm_args;
jint res;
VALUE classpath;
VALUE user_path;
VALUE vm_argv;
char* userpath;
ID stradd = rb_intern("<<");
ID pathsep = rb_intern("PATH_SEPARATOR");
int i;
jclass jmethod;
jclass jfield;
jclass jconstructor;

if (rjb_jvm)
{
return Qnil;
}

.loaded?Boolean

.primitive_conversionObject

*

For JRuby conpatible option


# File 'ext/rjb.c'

static VALUE rjb_s_get_pconversion(VALUE self)
{
    return primitive_conversion;
}

.primitive_conversion=Object

*

For JRuby conpatible option


# File 'ext/rjb.c'

static VALUE rjb_s_set_pconversion(VALUE self, VALUE val)
{
    primitive_conversion = (RTEST(val)) ? Qtrue : Qfalse;
    return val;
}

.throwObject

.unbindObject

jclass Rjb::bind(rbobj, interface_name)



# File 'ext/rjb.c'

static VALUE rjb_s_unbind(VALUE self, VALUE rbobj)
{
#if defined(RUBINIUS)
    return rb_funcall(proxies, rb_intern("delete"), 1, rbobj);
#else
    return rb_ary_delete(proxies, rbobj);
#endif
}

.unloadObject