add function jsetfield 16/11916/3
Sylvestre Ledru [Wed, 3 Jul 2013 11:48:33 +0000 (13:48 +0200)]
Change-Id: Idcc67446e3f83f8c70bd5c9c8c0add5824d533b3

scilab/modules/external_objects_java/Makefile.am
scilab/modules/external_objects_java/Makefile.in
scilab/modules/external_objects_java/includes/gw_external_objects_java.h
scilab/modules/external_objects_java/sci_gateway/c/gw_external_objects_java.c
scilab/modules/external_objects_java/sci_gateway/cpp/sci_jsetfield.cpp [new file with mode: 0644]
scilab/modules/external_objects_java/sci_gateway/external_objects_java_gateway.xml
scilab/modules/external_objects_java/src/cpp/ScilabJavaEnvironment.cpp
scilab/modules/external_objects_java/tests/unit_tests/jsetfield.tst [new file with mode: 0644]

index 8c7529e..5791bac 100644 (file)
@@ -61,7 +61,8 @@ sci_gateway/cpp/sci_jvoid.cpp \
 sci_gateway/cpp/sci_jarray.cpp \
 sci_gateway/cpp/sci_jcast.cpp \
 sci_gateway/cpp/sci_jallowClassReloading.cpp \
-sci_gateway/cpp/sci_jwrapinfloat.cpp
+sci_gateway/cpp/sci_jwrapinfloat.cpp \
+sci_gateway/cpp/sci_jsetfield.cpp
 
 GIWS_WRAPPERS = src/jni/ScilabObjects.giws.xml
 
index 3409a2c..f8f9aab 100644 (file)
@@ -183,7 +183,8 @@ am__objects_3 =  \
        libsciexternal_objects_java_la-sci_jarray.lo \
        libsciexternal_objects_java_la-sci_jcast.lo \
        libsciexternal_objects_java_la-sci_jallowClassReloading.lo \
-       libsciexternal_objects_java_la-sci_jwrapinfloat.lo
+       libsciexternal_objects_java_la-sci_jwrapinfloat.lo \
+       libsciexternal_objects_java_la-sci_jsetfield.lo
 am_libsciexternal_objects_java_la_OBJECTS = $(am__objects_3) \
        $(am__objects_1)
 libsciexternal_objects_java_la_OBJECTS =  \
@@ -609,7 +610,8 @@ sci_gateway/cpp/sci_jvoid.cpp \
 sci_gateway/cpp/sci_jarray.cpp \
 sci_gateway/cpp/sci_jcast.cpp \
 sci_gateway/cpp/sci_jallowClassReloading.cpp \
-sci_gateway/cpp/sci_jwrapinfloat.cpp
+sci_gateway/cpp/sci_jwrapinfloat.cpp \
+sci_gateway/cpp/sci_jsetfield.cpp
 
 GIWS_WRAPPERS = src/jni/ScilabObjects.giws.xml
 @GIWS_TRUE@BUILT_SOURCES = giws
@@ -772,6 +774,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciexternal_objects_java_la-sci_jimport.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciexternal_objects_java_la-sci_jnewInstance.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciexternal_objects_java_la-sci_jremove.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciexternal_objects_java_la-sci_jsetfield.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciexternal_objects_java_la-sci_junwrap.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciexternal_objects_java_la-sci_junwraprem.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsciexternal_objects_java_la-sci_jvoid.Plo@am__quote@
@@ -1030,6 +1033,13 @@ libsciexternal_objects_java_la-sci_jwrapinfloat.lo: sci_gateway/cpp/sci_jwrapinf
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@ $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciexternal_objects_java_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libsciexternal_objects_java_la-sci_jwrapinfloat.lo `test -f 'sci_gateway/cpp/sci_jwrapinfloat.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_jwrapinfloat.cpp
 
+libsciexternal_objects_java_la-sci_jsetfield.lo: sci_gateway/cpp/sci_jsetfield.cpp
+@am__fastdepCXX_TRUE@  $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciexternal_objects_java_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libsciexternal_objects_java_la-sci_jsetfield.lo -MD -MP -MF $(DEPDIR)/libsciexternal_objects_java_la-sci_jsetfield.Tpo -c -o libsciexternal_objects_java_la-sci_jsetfield.lo `test -f 'sci_gateway/cpp/sci_jsetfield.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_jsetfield.cpp
+@am__fastdepCXX_TRUE@  $(am__mv) $(DEPDIR)/libsciexternal_objects_java_la-sci_jsetfield.Tpo $(DEPDIR)/libsciexternal_objects_java_la-sci_jsetfield.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='sci_gateway/cpp/sci_jsetfield.cpp' object='libsciexternal_objects_java_la-sci_jsetfield.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(LIBTOOL)  --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciexternal_objects_java_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libsciexternal_objects_java_la-sci_jsetfield.lo `test -f 'sci_gateway/cpp/sci_jsetfield.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_jsetfield.cpp
+
 mostlyclean-libtool:
        -rm -f *.lo
 
index 87eb314..9e7f50a 100644 (file)
@@ -37,6 +37,7 @@ EXTERNAL_OBJECTS_JAVA_SCILAB_IMPEXP int sci_jarray(char *fname, unsigned long fn
 EXTERNAL_OBJECTS_JAVA_SCILAB_IMPEXP int sci_jcast(char *fname, unsigned long fname_len);
 EXTERNAL_OBJECTS_JAVA_SCILAB_IMPEXP int sci_jallowClassReloading(char *fname, unsigned long fname_len);
 EXTERNAL_OBJECTS_JAVA_SCILAB_IMPEXP int sci_jwrapinfloat(char *fname, unsigned long fname_len);
+EXTERNAL_OBJECTS_JAVA_SCILAB_IMPEXP int sci_jsetfield(char *fname, unsigned long fname_len);
 /*--------------------------------------------------------------------------*/
 #endif /* __GW_EXTERNAL_OBJECTS_H__ */
 /*--------------------------------------------------------------------------*/
index da5123e..32e0055 100644 (file)
@@ -38,7 +38,8 @@ static gw_generic_table Tab[] =
     {sci_jarray, "jarray"},
     {sci_jcast, "jcast"},
     {sci_jallowClassReloading, "jallowClassReloading"},
-    {sci_jwrapinfloat, "jwrapinfloat"}
+    {sci_jwrapinfloat, "jwrapinfloat"},
+    {sci_jsetfield, "jsetfield"}
 };
 
 /*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/external_objects_java/sci_gateway/cpp/sci_jsetfield.cpp b/scilab/modules/external_objects_java/sci_gateway/cpp/sci_jsetfield.cpp
new file mode 100644 (file)
index 0000000..7bc08f4
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * PIMS ( http://forge.scilab.org/index.php/p/pims ) - This file is part of PIMS
+ * Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET
+ * Copyright (C) 2013 - Scilab Enterprises - Sylvestre Ledru
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+#include "ScilabJavaEnvironment.hxx"
+#include "ScilabGateway.hxx"
+
+extern "C" {
+#include "Scierror.h"
+#include "gw_external_objects_java.h"
+}
+
+using namespace org_scilab_modules_external_objects_java;
+using namespace org_modules_external_objects;
+
+int sci_jsetfield(char * fname, unsigned long fname_len)
+{
+    try
+    {
+        const int envId = ScilabJavaEnvironment::start();
+        return ScilabGateway::setField(fname, envId, pvApiCtx);
+    }
+    catch (std::exception & e)
+    {
+        Scierror(999, "%s: An error occured: %s", fname, e.what());
+        return 0;
+    }
+}
index 64a72ff..bb183f0 100644 (file)
@@ -49,4 +49,5 @@
     <PRIMITIVE gatewayId="72" primitiveId="18" primitiveName="jcast" />
     <PRIMITIVE gatewayId="72" primitiveId="19" primitiveName="jallowClassReloading" />
     <PRIMITIVE gatewayId="72" primitiveId="20" primitiveName="jwrapinfloat" />
+    <PRIMITIVE gatewayId="72" primitiveId="21" primitiveName="jsetfield" />
 </GATEWAY>
index 9d0d42e..8d1838e 100644 (file)
@@ -590,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.");
 }
 
@@ -635,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)
diff --git a/scilab/modules/external_objects_java/tests/unit_tests/jsetfield.tst b/scilab/modules/external_objects_java/tests/unit_tests/jsetfield.tst
new file mode 100644 (file)
index 0000000..683ffc7
--- /dev/null
@@ -0,0 +1,19 @@
+// ===================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Sylvestre Ledru
+//
+//  This file is distributed under the same license as the Scilab package.
+// ===================================================================
+
+s = "Hello World !";
+r = jgetfield(jwrap(s), "CASE_INSENSITIVE_ORDER");
+
+c = jcompile("Test", ["public class Test {";
+       "public int field;";
+       "public Test(int n) {";
+       "field = n;";
+       "}";
+       "}";]);
+t = c.new(128);
+jsetfield(t, "field", 256);
+assert_checkequal(int32(256), jgetfield(t, "field"));
\ No newline at end of file