add function jsetfield
[scilab.git] / scilab / modules / external_objects_java / src / cpp / ScilabJavaEnvironment.cpp
index 93859ef..8d1838e 100644 (file)
  *
  */
 
+#ifdef _MSC_VER
+#include "windows.h"
+#endif
+
 #include <jni.h>
 
 #include "ScilabJavaEnvironment.hxx"
@@ -24,6 +28,7 @@
 //#include "ScilabJavaObjectHelper.hxx"
 extern "C" {
 #include "getScilabJavaVM.h"
+#include "tmpdir.h"
 }
 
 namespace org_scilab_modules_external_objects_java
@@ -77,7 +82,7 @@ int ScilabJavaEnvironment::start()
                 ScilabJavaOStream::setStdErrStream(&instance->scilabStream);*/
         instance->helper.setUseLastName(true);
         instance->helper.setNewAllowed(true);
-        instance->enabletrace("/tmp/eo_java.log");
+        instance->enabletrace((std::string(getTMPDIR()) + std::string("/eo_java.log")).c_str());
     }
 
     return envId;
@@ -475,7 +480,7 @@ bool ScilabJavaEnvironment::isvalidobject(int id)
 {
 
     JavaVM *vm = getScilabJavaVM();
-    int ret = ScilabJavaObject::isValidJavaObject(vm, id);
+    bool ret = ScilabJavaObject::isValidJavaObject(vm, id);
     writeLog("isvalidobject", "Test the validity of object %d which is%s valid.", id, ret ? "" : " not");
     return ret;
 }
@@ -585,44 +590,16 @@ void ScilabJavaEnvironment::setfield(int id, const char * fieldName, int idarg)
         throw ScilabJavaException(__LINE__, __FILE__, gettext("Invalid field name"));
     }
 
-    if (!helper.getShowPrivate() && *fieldName == '_')
+    try
     {
-        throw ScilabJavaException(__LINE__, __FILE__, gettext("Private field: %s"), fieldName);
+        JavaVM * vm = getScilabJavaVM();
+        ScilabJavaObject::setField(vm, id, fieldName, idarg);
+    }
+    catch (const GiwsException::JniCallMethodException & e)
+    {
+        throw ScilabJavaException(__LINE__, __FILE__, gettext("Cannot set the field: %s"), fieldName);
     }
 
-    /*
-        PyObject * obj = scope.getObject(id);
-        if (!obj)
-        {
-            throw ScilabJavaException(__LINE__, __FILE__, gettext("Invalid object with id %d"), id);
-        }
-
-        if (!PyObject_HasAttrString(obj, fieldName))
-        {
-            throw ScilabJavaException(__LINE__, __FILE__, gettext("Invalid field name: %s"), fieldName);
-        }
-
-        PyObject * value = scope.getObject(idarg);
-        if (!value)
-        {
-            throw ScilabJavaException(__LINE__, __FILE__, gettext("Invalid object with id %d"), id);
-        }
-
-        int ret = PyObject_SetAttrString(obj, fieldName, value);
-        if (ret == -1)
-        {
-            if (PyErr_Occurred())
-            {
-                PyObject * type, * value, * traceback;
-                PyErr_Fetch(&type, &value, &traceback);
-                PyErr_NormalizeException(&type, &value, &traceback);
-                PyErr_Clear();
-
-                throw ScilabJavaException(__LINE__, __FILE__, type, value, traceback, gettext("Unable to set the field: %s"), fieldName);
-            }
-            throw ScilabJavaException(__LINE__, __FILE__, gettext("Unable to set the field: %s"), fieldName);
-        }
-    */
     writeLog("setfield", "Value successfully set.");
 }
 
@@ -630,56 +607,15 @@ int ScilabJavaEnvironment::getfield(int id, const char * fieldName)
 {
     writeLog("getfield", "Get the field named %s on object with id %d.", fieldName, id);
 
-    JavaVM *vm = getScilabJavaVM();
-    int ret = ScilabJavaObject::getField(vm, id, fieldName);
-    return ret;
-    //    allocator.allocate(1, 1, &str);
-
-
-
-    /*
     if (*fieldName == '\0')
     {
         throw ScilabJavaException(__LINE__, __FILE__, gettext("Invalid field name"));
     }
 
-    if (!helper.getShowPrivate() && *fieldName == '_')
-    {
-        throw ScilabJavaException(__LINE__, __FILE__, gettext("Private field: %s"), fieldName);
-    }
-
-        PyObject * obj = scope.getObject(id);
-        if (!obj)
-        {
-            throw ScilabJavaException(__LINE__, __FILE__, gettext("Invalid object with id %d"), id);
-        }
-
-        if (!PyObject_HasAttrString(obj, fieldName))
-        {
-            throw ScilabJavaException(__LINE__, __FILE__, gettext("Invalid field name: %s"), fieldName);
-        }
-
-        PyObject * field = PyObject_GetAttrString(obj, fieldName);
-        if (!field)
-        {
-            if (PyErr_Occurred())
-            {
-                PyObject * type, * value, * traceback;
-                PyErr_Fetch(&type, &value, &traceback);
-                PyErr_NormalizeException(&type, &value, &traceback);
-                PyErr_Clear();
-
-                throw ScilabJavaException(__LINE__, __FILE__, type, value, traceback, gettext("Unable to get the field value: %s"), fieldName);
-            }
-            throw ScilabJavaException(__LINE__, __FILE__, gettext("Unable to get the field value: %s"), fieldName);
-        }
-
-        int ret = scope.addObject(field);
-        writeLog("getfield", "returned id %d.", ret);
+    JavaVM * vm = getScilabJavaVM();
+    int ret = ScilabJavaObject::getField(vm, id, fieldName);
 
-        return ret;
-    */
-    return 0;
+    return ret;
 }
 
 int ScilabJavaEnvironment::getfieldtype(int id, const char * fieldName)