Author: mturk Date: Wed Apr 15 19:46:20 2009 New Revision: 765330 URL: http://svn.apache.org/viewvc?rev=765330&view=rev Log: Add core class object array API
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_clazz.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=765330&r1=765329&r2=765330&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 Wed Apr 15 19:46:20 2009 @@ -52,6 +52,15 @@ */ ACR_DECLARE(jclass) ACR_GetCoreClass(acr_cclass_e clazz); +/** + * Get core object array instance. + * @param env Current JNI environment. + * @param clazz Class to get. See acr_cclass_e enum + * @param len Nuber of array objects + */ +ACR_DECLARE(jobjectArray) ACR_NewCoreObjectArray(JNIEnv *env, + acr_cclass_e clazz, + jsize len); #ifdef __cplusplus } 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=765330&r1=765329&r2=765330&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c Wed Apr 15 19:46:20 2009 @@ -131,6 +131,16 @@ return NULL; } +ACR_DECLARE(jobjectArray) ACR_NewCoreObjectArray(JNIEnv *_E, + acr_cclass_e clazz, + jsize len) +{ + if (clazz >= 0 && clazz < ACR_CC_MAX) + return (*_E)->NewObjectArray(_E, len, core_classes[clazz].clazz, NULL); + else + return NULL; +} + #ifdef ACR_ENABLE_TEST /* Just for testing the cache table */ int acr_clazz_cache_size() 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=765330&r1=765329&r2=765330&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/test/testcase.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/test/testcase.c Wed Apr 15 19:46:20 2009 @@ -195,3 +195,9 @@ jclass c = ACR_GetCoreClass(d); return (jobject)c; } + +ACR_JNI_EXPORT_DECLARE(jobjectArray, TestPrivate, test015)(ACR_JNISTDARGS, jint d) +{ + jobjectArray a = ACR_NewCoreObjectArray(_E, ACR_CC_STRING, d); + return a; +} 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=765330&r1=765329&r2=765330&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 Wed Apr 15 19:46:20 2009 @@ -54,6 +54,7 @@ private static native int test012(int d); private static native int test013(int d); private static native Class test014(int d); + private static native String[] test015(int d); protected void setUp() @@ -207,9 +208,15 @@ public void testCCore() throws Exception { - // Shuold not be called as last Class c = test014(1); - assertEquals("Name", "java.lang.String", c.getName()); + assertEquals("Class name", "java.lang.String", c.getName()); + } + + public void testCCoreArray() + throws Exception + { + String [] a = test015(33); + assertEquals("Size", 33, a.length); }