Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add to new utility functions :
authorcherierm <cherierm@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 9 Jul 2008 08:05:20 +0000 (08:05 +0000)
committercherierm <cherierm@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 9 Jul 2008 08:05:20 +0000 (08:05 +0000)
jxbt_get_static_jmethod() and jxbt_get_static_smethod() to get the static method of a Java class.

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@5862 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/java/jxbt_utilities.c
src/java/jxbt_utilities.h

index aa2b5c6..97d41be 100644 (file)
@@ -60,6 +60,57 @@ jmethodID jxbt_get_jmethod(JNIEnv* env, jclass cls,
   return id;
 }
 
   return id;
 }
 
+jmethodID jxbt_get_static_jmethod(JNIEnv* env, jclass cls, 
+                          const char *name,const char *signature) {
+  jmethodID id;
+
+  if (!cls)
+    return 0;
+  id = (*env)->GetStaticMethodID(env, cls, name,signature);
+       
+  if(!id) {
+
+    jmethodID tostr_id = (*env)->GetMethodID(env, cls, "getName", "()Ljava/lang/String;");
+    jstring jclassname = (jstring) (*env)->CallObjectMethod(env, cls, tostr_id, NULL);
+    const char *classname = (*env)->GetStringUTFChars(env, jclassname, 0);
+
+    char *m=bprintf("Cannot find static method %s(%s) in %s", name, signature ,classname);
+
+    (*env)->ReleaseStringUTFChars(env, jclassname, classname);         
+
+    jxbt_throw_jni(env,m);
+
+    free(m);
+    return 0;
+  }
+
+  return id;
+}
+
+jmethodID jxbt_get_static_smethod(JNIEnv* env, const char *classname, 
+                         const char *name,const char *signature) { 
+  
+       jclass cls;
+
+       jmethodID id;
+       cls = jxbt_get_class(env,classname);
+
+  if (!cls)
+    return 0;
+
+  id = (*env)->GetStaticMethodID(env, cls, name,signature);
+       
+  if(!id) {
+    char *m=bprintf("Cannot find static method %s(%s) in %s", name, signature,classname);
+
+    jxbt_throw_jni(env,m);
+
+    free(m);
+    return 0;
+  }
+  return id;
+}
+
 jmethodID jxbt_get_smethod(JNIEnv* env, const char *classname, 
                          const char *name,const char *signature) { 
   
 jmethodID jxbt_get_smethod(JNIEnv* env, const char *classname, 
                          const char *name,const char *signature) { 
   
index 97e5eb4..570645b 100644 (file)
@@ -27,6 +27,10 @@ jclass jxbt_get_class(JNIEnv* env, const char*name);
    (it's ok to to pass a NULL class: it's a noop) */
 jmethodID jxbt_get_jmethod(JNIEnv* env, jclass class, 
                           const char *name,const char *signature);
    (it's ok to to pass a NULL class: it's a noop) */
 jmethodID jxbt_get_jmethod(JNIEnv* env, jclass class, 
                           const char *name,const char *signature);
+                          
+/* Like the jxbt_get_class() but get a static method */
+jmethodID jxbt_get_static_jmethod(JNIEnv* env, jclass cls, 
+                          const char *name,const char *signature);
 
 /* Search a field in a class and throw an exception if not found
    (it's ok to to pass a NULL class: it's a noop) */
 
 /* Search a field in a class and throw an exception if not found
    (it's ok to to pass a NULL class: it's a noop) */
@@ -39,6 +43,10 @@ jfieldID jxbt_get_jfield(JNIEnv* env, jclass class,
 jmethodID jxbt_get_smethod(JNIEnv* env, const char *classname, 
                          const char *name,const char *signature);
 
 jmethodID jxbt_get_smethod(JNIEnv* env, const char *classname, 
                          const char *name,const char *signature);
 
+/* Like the jxbt_get_smethod() but get a static method */
+jmethodID jxbt_get_static_smethod(JNIEnv* env, const char *classname, 
+                         const char *name,const char *signature);
+
 /* Search a field in a class and throw an exception if not found
    (it's ok to to pass a NULL class: it's a noop) */
 jfieldID jxbt_get_sfield(JNIEnv* env, const char *classname, 
 /* Search a field in a class and throw an exception if not found
    (it's ok to to pass a NULL class: it's a noop) */
 jfieldID jxbt_get_sfield(JNIEnv* env, const char *classname,