Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add to new utility functions :
[simgrid.git] / src / java / jxbt_utilities.c
index 2ef04a3..97d41be 100644 (file)
@@ -16,8 +16,6 @@
 #include "xbt/str.h"
 #include "jxbt_utilities.h"
 
-XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
-
 /* *********** */
 /* JNI GETTERS */
 /* *********** */
@@ -62,13 +60,68 @@ jmethodID jxbt_get_jmethod(JNIEnv* env, jclass cls,
   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) { 
-  jclass cls = jxbt_get_class(env,classname);
-  jmethodID id;
+  
+       jclass cls;
+
+       jmethodID id;
+       cls = jxbt_get_class(env,classname);
 
   if (!cls)
     return 0;
+
   id = (*env)->GetMethodID(env, cls, name,signature);
        
   if(!id) {
@@ -79,7 +132,6 @@ jmethodID jxbt_get_smethod(JNIEnv* env, const char *classname,
     free(m);
     return 0;
   }
-
   return id;
 }