00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef JNIOBJECT_H
00010 #define JNIOBJECT_H
00011
00012 #include "JavaQxCommon.h"
00013
00014
00015
00016
00017
00024 class JAVAQX_EXPORT JNIObject
00025 {
00026 public:
00027 JNIObject(JNIEnv *env, jobject obj);
00028 virtual ~JNIObject();
00029 private:
00030 JNIObject(const JNIObject &);
00031 public:
00032 inline JNIEnv *env() const;
00033 inline jweak ref() const;
00034 inline bool isSameThread(JNIEnv *env) const;
00035 public:
00036 bool isLive();
00037 void checkException();
00038 bool testException();
00039 void fatalError(const char *errorMessage);
00040 void throwInternalError(const char *errorMessage = 0);
00041 void throwOutOfMemoryError(const char *errorMessage = 0);
00042 void throwRuntimeExcpetion(const char *exceptionMessage = 0);
00043 jfieldID getFieldID(const char *name, const char *sig);
00044 jmethodID getMethodID(const char *name, const char *sig);
00045 jobject getObjectField(jfieldID fieldID);
00046 void setObjectField(jfieldID fieldID, jobject val);
00047 jboolean getBooleanField(jfieldID fieldID);
00048 void setBooleanField(jfieldID fieldID, jboolean val);
00049 jbyte getByteField(jfieldID fieldID);
00050 void setByteField(jfieldID fieldID, jbyte val);
00051 jchar getCharField(jfieldID fieldID);
00052 void setCharField(jfieldID fieldID, jchar val);
00053 jshort getShortField(jfieldID fieldID);
00054 void setShortField(jfieldID fieldID, jshort val);
00055 jint getIntField(jfieldID fieldID);
00056 void setIntField(jfieldID fieldID, jint val);
00057 jlong getLongField(jfieldID fieldID);
00058 void setLongField(jfieldID fieldID, jlong val);
00059 jfloat getFloatField(jfieldID fieldID);
00060 void setFloatField(jfieldID fieldID, jfloat val);
00061 jdouble getDoubleField(jfieldID fieldID);
00062 void setDoubleField(jfieldID fieldID, jdouble val);
00063 jclass getObjectClass();
00064 bool callObjectMethod(jobject &result, jmethodID methodID, ...);
00065 bool callBooleanMethod(jboolean &result, jmethodID methodID, ...);
00066 bool callByteMethod(jbyte &result, jmethodID methodID, ...);
00067 bool callCharMethod(jchar &result, jmethodID methodID, ...);
00068 bool callShortMethod(jshort &result, jmethodID methodID, ...);
00069 bool callIntMethod(jint &result, jmethodID methodID, ...);
00070 bool callLongMethod(jlong &result, jmethodID methodID, ...);
00071 bool callFloatMethod(jfloat &result, jmethodID methodID, ...);
00072 bool callDoubleMethod(jdouble &result, jmethodID methodID, ...);
00073 bool callVoidMethod(jmethodID methodID, ...);
00074 jstring toJString();
00075 jstring newJString(const jchar *uchars, jsize len);
00076 jstring newJStringUTF(const char *bytes);
00077 private:
00078 JNIEnv *m_env;
00079 jweak m_ref;
00080 };
00081
00082
00083
00084
00085
00091 inline JNIEnv *JNIObject::env() const
00092 {
00093 return m_env;
00094 }
00095
00101 inline jweak JNIObject::ref() const
00102 {
00103 return m_ref;
00104 }
00105
00111 inline bool JNIObject::isSameThread(JNIEnv *env) const
00112 {
00113 return (m_env == env);
00114 }
00115
00116 #endif // JNIOBJECT_H
00117
00118
00119
00120
00121
00122
00123
00124