commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r766301 - in /commons/sandbox/runtime/trunk/src: main/native/include/acr_clazz.h main/native/include/acr_types.h main/native/shared/clazz.c main/native/test/testcase.c test/org/apache/commons/runtime/TestPrivate.java
Date Sat, 18 Apr 2009 11:25:48 GMT
Author: mturk
Date: Sat Apr 18 11:25:48 2009
New Revision: 766301

URL: http://svn.apache.org/viewvc?rev=766301&view=rev
Log:
Add java.io.File creation support

Modified:
    commons/sandbox/runtime/trunk/src/main/native/include/acr_clazz.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr_types.h
    commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c
    commons/sandbox/runtime/trunk/src/main/native/test/testcase.c
    commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_clazz.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_clazz.h?rev=766301&r1=766300&r2=766301&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_clazz.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_clazz.h Sat Apr 18 11:25:48
2009
@@ -79,6 +79,14 @@
  */
 ACR_DECLARE(void) ACR_UnloadClass(JNIEnv *env, JAVA_C_ID *clazz);
 
+/**
+ * Crete new java.io.File object.
+ * @param env Current JNI environment.
+ * @param pathname Pathname used to construct File object.
+ */
+ACR_DECLARE(jobject) ACR_NewCoreFileObjectU(JNIEnv *_E,
+                                            const char *pathname);
+
 #ifdef __cplusplus
 }
 #endif

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_types.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_types.h?rev=766301&r1=766300&r2=766301&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_types.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_types.h Sat Apr 18 11:25:48
2009
@@ -66,6 +66,7 @@
     ACR_CC_OBJECT,  /* Ljava/lang/Object;   - String          */
     ACR_CC_STRING,  /* Ljava/lang/String;   - Object          */
     ACR_CC_DBBUFF,  /* Ljava/nio/ByteBuffer - ByteBuffer      */
+    ACR_CC_IOFILE,  /* Ljava/io/File        - File            */
     ACR_CC_ZARRAY,  /* [Z                   - boolean[]       */
     ACR_CC_BARRAY,  /* [B                   - byte[]          */
     ACR_CC_CARRAY,  /* [C                   - char[]          */

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c?rev=766301&r1=766300&r2=766301&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c Sat Apr 18 11:25:48 2009
@@ -35,6 +35,7 @@
     { "Ljava/lang/Object;",     NULL },
     { "Ljava/lang/String;",     NULL },
     { "Ljava/nio/ByteBuffer;",  NULL },
+    { "Ljava/io/File;",         NULL },
     { "[Z",                     NULL },
     { "[B",                     NULL },
     { "[C",                     NULL },
@@ -62,6 +63,18 @@
     return ACR_SUCCESS;
 }
 
+static jmethodID    fo_cc_init;
+
+static ACR_INLINE jmethodID init_constructor(JNIEnv *_E, jclass c, const char *sig)
+{
+    jmethodID m = (*_E)->GetMethodID(_E, c, "<init>", sig);
+
+    if (m == NULL || (*_E)->ExceptionCheck(_E))
+        return NULL;
+    else
+        return m;
+}
+
 int ACR_InitCoreClasses(JNIEnv *_E)
 {
     int i = 0;
@@ -92,7 +105,8 @@
         }
         i++;
     }
-
+    fo_cc_init = init_constructor(_E, core_classes[ACR_CC_IOFILE].clazz,
+                                  "(Ljava/lang/String;)V");
     return ACR_SUCCESS;
 }
 
@@ -173,6 +187,14 @@
         return NULL;
 }
 
+ACR_DECLARE(jobject) ACR_NewCoreFileObjectU(JNIEnv *_E,
+                                            const char *pathname)
+{
+    jstring p = (*_E)->NewStringUTF(_E, pathname);
+    return (*_E)->NewObject(_E, core_classes[ACR_CC_IOFILE].clazz,
+                            fo_cc_init, p);
+}
+
 ACR_DECLARE(int) ACR_LoadClass(JNIEnv *_E, JAVA_C_ID *clazz, int init_array)
 {
     int rv = ACR_SUCCESS;

Modified: commons/sandbox/runtime/trunk/src/main/native/test/testcase.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/test/testcase.c?rev=766301&r1=766300&r2=766301&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/test/testcase.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/test/testcase.c Sat Apr 18 11:25:48 2009
@@ -299,3 +299,8 @@
 {
     RETURN_JWSTR(L"Hello world");
 }
+
+ACR_JNI_EXPORT_DECLARE(jobject, TestPrivate, test029)(ACR_JNISTDARGS, int d)
+{
+    return ACR_NewCoreFileObjectU(_E, "/tmp/foo");
+}

Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java?rev=766301&r1=766300&r2=766301&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java Sat
Apr 18 11:25:48 2009
@@ -19,6 +19,7 @@
 import java.lang.System;
 import java.util.Properties;
 import java.nio.ByteBuffer;
+import java.io.File;
 import junit.framework.*;
 
 /**
@@ -73,6 +74,7 @@
     private static native Descriptor[] test027(int size);
 
     private static native String test028(int d);
+    private static native File   test029(int d);
 
 
     protected void setUp()
@@ -529,4 +531,13 @@
         String s = test028(0);
         assertEquals("Equals", "Hello world", s);
     }
+
+    public void testIoFile()
+        throws Throwable
+    {
+        File f = test029(0);
+        assertEquals("Pathname", "/tmp/foo", f.getPath());
+        assertEquals("Name", "foo", f.getName());
+    }
+
 }



Mime
View raw message