some clarifications for java classes extended support

This commit is contained in:
tshirtman 2012-12-31 00:15:25 +01:00
parent 5d143331a8
commit 9b758a81c3
3 changed files with 42 additions and 30 deletions

View File

@ -63,7 +63,8 @@ class MetaJavaClass(type):
interfaces[n] = jcs.j_env[0].FindClass(jcs.j_env, <char*>i)
getProxyClass = jcs.j_env[0].GetStaticMethodID(
jcs.j_env, Proxy, "getProxyClass", "(Ljava/lang/ClassLoader,[Ljava/lang/Class;)Ljava/lang/Class;")
jcs.j_env, Proxy, "getProxyClass",
"(Ljava/lang/ClassLoader,[Ljava/lang/Class;)Ljava/lang/Class;")
getClassLoader = jcs.j_env[0].GetStaticMethodID(
jcs.j_env, baseclass, "getClassLoader", "()Ljava/lang/Class;")

View File

@ -616,6 +616,23 @@ cdef class GenericNativeWrapper(object):
# return self.callback(*args)
cdef class PythonJavaClass(object):
'''
base class to create a java class from python
'''
cdef JNIEnv *j_env
cdef jclass j_cls
cdef LocalRef j_self
def __cinit__(self, *args):
self.j_env = NULL
self.j_cls = NULL
self.j_self = NULL
pass
def __init__(self, *args, **kwargs):
self.j_self = create_proxy_instance()
cdef jobject invoke0(
JNIEnv *j_env,
jobject this,
@ -624,8 +641,7 @@ cdef jobject invoke0(
cdef jfieldID ptrField = j_env[0].GetFieldID(j_env.GetObjectClass(this), "ptr", "J")
cdef jlong jptr = j_env.GetLongField(this, ptrField)
cdef NativeInvocationHandler *h = reinterpret_cast<NativeInvocationHandler>(jptr)
return h.Invoke(env, method, args);
return h.fnPtr(env, method, args);
# now we need to create a proxy and pass it an invocation handler

View File

@ -1,6 +1,7 @@
import java.lang.reflect.InvocationHandler;
package jnius;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
public class NativeInvocationHandler implements InvocationHandler {
public NativeInvocationHandler(long ptr) {
this.ptr = ptr;
@ -14,9 +15,3 @@ public class NativeInvocationHandler implements InvocationHandler {
private long ptr;
}
class NativeInvocationHandler {
public:
virtual ~NativeInvocationHandler();
virtual jobject Invoke(JNIEnv *, jobject method, jobjectArray args) = 0;
};