commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r790187 - in /commons/sandbox/runtime/trunk/src: main/native/include/ main/native/shared/ main/native/test/ test/org/apache/commons/runtime/
Date Wed, 01 Jul 2009 14:36:50 GMT
Author: mturk
Date: Wed Jul  1 14:36:49 2009
New Revision: 790187

URL: http://svn.apache.org/viewvc?rev=790187&view=rev
Log:
Add Class API

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/shared/object.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=790187&r1=790186&r2=790187&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 Jul  1 14:36:49
2009
@@ -33,6 +33,19 @@
  */
 
 /**
+ * Class type flags
+ */
+#define ACR_CLASS_ANNOTATION        0x00000001
+#define ACR_CLASS_ANONYMOUS         0x00000002
+#define ACR_CLASS_ARRAY             0x00000004
+#define ACR_CLASS_ENUM              0x00000008
+#define ACR_CLASS_INTERFACE         0x00000010
+#define ACR_CLASS_LOCAL             0x00000020
+#define ACR_CLASS_MEMBER            0x00000040
+#define ACR_CLASS_PRIMITIVE         0x00000080
+#define ACR_CLASS_SYNTHETIC         0x00000100
+
+/**
  * Add class to the local cache and create global
  * rference to it.
  * @param env Current JNI environment.
@@ -95,6 +108,13 @@
  */
 ACR_DECLARE(void) ACR_UnloadRuntimeClasses(JNIEnv *env);
 
+/**
+ * Get the Class Flags. See ACR_CLASS_* defines.
+ * @param env Current JNI environment.
+ * @param obj Class to use.
+ */
+ACR_DECLARE(int) ACR_ClassGetFlags(JNIEnv *env, jobject obj);
+
 #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=790187&r1=790186&r2=790187&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 Wed Jul  1 14:36:49
2009
@@ -63,8 +63,9 @@
 
 /* Standard Java classes */
 typedef enum {
-    ACR_CC_OBJECT,  /* Ljava/lang/Object;   - String          */
-    ACR_CC_STRING,  /* Ljava/lang/String;   - Object          */
+    ACR_CC_OBJECT,  /* Ljava/lang/Object;   - Object          */
+    ACR_CC_CLASS,   /* Ljava/lang/Class;    - Class           */
+    ACR_CC_STRING,  /* Ljava/lang/String;   - String          */
     ACR_CC_DBBUFF,  /* Ljava/nio/ByteBuffer - ByteBuffer      */
     ACR_CC_IOFILE,  /* Ljava/io/File        - File            */
     ACR_CC_ZARRAY,  /* [Z                   - boolean[]       */

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=790187&r1=790186&r2=790187&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c Wed Jul  1 14:36:49 2009
@@ -28,11 +28,109 @@
 #define CLAZZ_INI_SIZE  128
 static acr_table_t *clazz_cache;
 
+J_DECLARE_CLAZZ = {
+    NULL,
+    NULL,
+    "java/lang/Class"
+};
+
+J_DECLARE_M_ID(0000) = {
+    NULL,
+    "getName",
+    "()Ljava/lang/String;"
+};
+
+J_DECLARE_M_ID(0001) = {
+    NULL,
+    "getSimpleName",
+    "()Ljava/lang/String;"
+};
+
+J_DECLARE_M_ID(0002) = {
+    NULL,
+    "getComponentType",
+    "()Ljava/lang/Class;"
+};
+
+J_DECLARE_M_ID(0003) = {
+    NULL,
+    "getDeclaringClass",
+    "()Ljava/lang/Class;"
+};
+
+J_DECLARE_M_ID(0004) = {
+    NULL,
+    "getEnclosingClass",
+    "()Ljava/lang/Class;"
+};
+
+
+J_DECLARE_M_ID(0005) = {
+    NULL,
+    "getSuperclass",
+    "()Ljava/lang/Class;"
+};
+
+J_DECLARE_M_ID(0006) = {
+    NULL,
+    "isAnnotation",
+    "()Z"
+};
+
+J_DECLARE_M_ID(0007) = {
+    NULL,
+    "isAnonymousClass",
+    "()Z"
+};
+
+J_DECLARE_M_ID(0008) = {
+    NULL,
+    "isArray",
+    "()Z"
+};
+
+J_DECLARE_M_ID(0009) = {
+    NULL,
+    "isEnum",
+    "()Z"
+};
+
+J_DECLARE_M_ID(0010) = {
+    NULL,
+    "isInterface",
+    "()Z"
+};
+
+J_DECLARE_M_ID(0011) = {
+    NULL,
+    "isLocalClass",
+    "()Z"
+};
+
+J_DECLARE_M_ID(0012) = {
+    NULL,
+    "isMemberClass",
+    "()Z"
+};
+
+J_DECLARE_M_ID(0013) = {
+    NULL,
+    "isPrimitive",
+    "()Z"
+};
+
+J_DECLARE_M_ID(0014) = {
+    NULL,
+    "isSynthetic",
+    "()Z"
+};
+
 struct {
     const char *name;
     jclass      clazz;
 } core_classes[] = {
     { "java/lang/Object",       NULL },
+    { "java/lang/Class",        NULL },
     { "java/lang/String",       NULL },
     { "java/nio/ByteBuffer",    NULL },
     { "java/io/File",           NULL },
@@ -63,6 +161,31 @@
     return ACR_SUCCESS;
 }
 
+ACR_CLASS_LDEF(Class)
+{
+    int rv;
+
+    if ((rv = ACR_LoadClass(_E, &_clazzn, 0)) != ACR_SUCCESS)
+        return rv;
+    J_LOAD_METHOD(0000);
+    J_LOAD_METHOD(0001);
+    J_LOAD_METHOD(0002);
+    J_LOAD_METHOD(0003);
+    J_LOAD_METHOD(0004);
+    J_LOAD_METHOD(0005);
+    J_LOAD_METHOD(0006);
+    J_LOAD_METHOD(0007);
+    J_LOAD_METHOD(0008);
+    J_LOAD_METHOD(0009);
+    J_LOAD_METHOD(0010);
+    J_LOAD_METHOD(0011);
+    J_LOAD_METHOD(0012);
+    J_LOAD_METHOD(0013);
+    J_LOAD_METHOD(0014);
+
+    return ACR_SUCCESS;
+}
+
 /* Core classes forward declarations */
 ACR_CLASS_LDEF(Object);
 ACR_CLASS_LDEF(String);
@@ -99,6 +222,7 @@
     }
     /* Init some core Objects and it's methods */
     ACR_CLASS_LRUN(Object);
+    ACR_CLASS_LRUN(Class);
     ACR_CLASS_LRUN(String);
 
     return ACR_SUCCESS;
@@ -284,6 +408,34 @@
 
 }
 
+ACR_DECLARE(int) ACR_ClassGetFlags(ACR_JNISTDARGS)
+{
+    int flags = 0;
+    if (IS_JOBJECT_NULL(_E, _O))
+        return 0;
+
+    if (_clazzn.i && J4MID(0000)) {
+        if (CALL_METHOD0(Boolean, 0006, _O) == JNI_TRUE)
+            flags |= ACR_CLASS_ANNOTATION;
+        if (CALL_METHOD0(Boolean, 0007, _O) == JNI_TRUE)
+            flags |= ACR_CLASS_ANONYMOUS;
+        if (CALL_METHOD0(Boolean, 0008, _O) == JNI_TRUE)
+            flags |= ACR_CLASS_ARRAY;
+        if (CALL_METHOD0(Boolean, 0009, _O) == JNI_TRUE)
+            flags |= ACR_CLASS_ENUM;
+        if (CALL_METHOD0(Boolean, 0010, _O) == JNI_TRUE)
+            flags |= ACR_CLASS_INTERFACE;
+        if (CALL_METHOD0(Boolean, 0011, _O) == JNI_TRUE)
+            flags |= ACR_CLASS_LOCAL;
+        if (CALL_METHOD0(Boolean, 0012, _O) == JNI_TRUE)
+            flags |= ACR_CLASS_MEMBER;
+        if (CALL_METHOD0(Boolean, 0013, _O) == JNI_TRUE)
+            flags |= ACR_CLASS_PRIMITIVE;
+        if (CALL_METHOD0(Boolean, 0014, _O) == JNI_TRUE)
+            flags |= ACR_CLASS_SYNTHETIC;
+    }
+    return flags;
+}
 
 #ifdef ACR_ENABLE_TEST
 /* Just for testing the cache table */
@@ -300,3 +452,4 @@
 }
 #endif
 
+

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/object.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/object.c?rev=790187&r1=790186&r2=790187&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/object.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/object.c Wed Jul  1 14:36:49 2009
@@ -70,6 +70,12 @@
     "()V"
 };
 
+J_DECLARE_M_ID(0007) = {
+    NULL,
+    "getClass",
+    "()Ljava/lang/Class;"
+};
+
 ACR_CLASS_LDEF(Object)
 {
     int rv;
@@ -83,6 +89,7 @@
     J_LOAD_METHOD(0004);
     J_LOAD_METHOD(0005);
     J_LOAD_METHOD(0006);
+    J_LOAD_METHOD(0007);
 
     return ACR_SUCCESS;
 }
@@ -191,3 +198,34 @@
     }
 }
 
+ACR_DECLARE(jmethodID) ACR_ObjectGetMethod(ACR_JNISTDARGS, const char *name,
+                                           const char *sig)
+{
+    jmethodID id;
+    jclass clazz;
+
+    if (IS_JOBJECT_NULL(_E, _O))
+        return NULL;
+    clazz = (*_E)->GetObjectClass(_E, _O);
+    if (!clazz)
+        return NULL;
+
+    id = (*_E)->GetMethodID(_E, clazz, name, sig);
+    (*_E)->DeleteLocalRef(_E, clazz);
+
+    return id;
+}
+
+ACR_DECLARE(jobject) ACR_ObjectGetClass(ACR_JNISTDARGS)
+{
+    jobject c = NULL;
+
+    if (IS_JOBJECT_NULL(_E, _O))
+        return NULL;
+    if (_clazzn.i && J4MID(0000)) {
+        c = CALL_METHOD0(Object, 0007, _O);
+    }
+
+    return c;
+}
+

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=790187&r1=790186&r2=790187&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/test/testcase.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/test/testcase.c Wed Jul  1 14:36:49 2009
@@ -376,6 +376,11 @@
     return ACR_DescriptorSetCtx(_E, d, s);
 }
 
+ACR_JNI_EXPORT_DECLARE(jint, TestPrivate, test035)(ACR_JNISTDARGS, jobject c)
+{
+    return ACR_ClassGetFlags(_E, c);
+}
+
 ACR_JNI_EXPORT_DECLARE(jint, TestFile, ftest00)(ACR_JNISTDARGS, jint d)
 {
     return ldfile(_E);

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=790187&r1=790186&r2=790187&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
Jul  1 14:36:49 2009
@@ -84,6 +84,7 @@
     private static native String[] test032(String s);
     private static native int      test033(int d);
     private static native int      test034(Descriptor p);
+    private static native int      test035(Class c);
 
 
     private static native String test100(String s);
@@ -244,7 +245,7 @@
     public void testCCore()
         throws Exception
     {
-        Class c = test014(1);
+        Class c = test014(2);
         assertEquals("Class name", "java.lang.String", c.getName());
     }
 
@@ -262,6 +263,15 @@
         assertEquals("Value", 0, i);
     }
 
+    public void testClassFlags()
+        throws Exception
+    {
+        String[] s = new String[2];
+        int i = test035(s.getClass());
+        // see: #define ACR_CLASS_ARRAY 0x00000004
+        assertEquals("Flags", 4, i);
+    }
+
     public void testPointerCb()
         throws Throwable
     {



Mime
View raw message