JNIObject Class Reference

JNI Object Wrapper. More...

#include <JNIObject.h>

List of all members.

Public Member Functions

 JNIObject (JNIEnv *env, jobject obj)
 Constructs new JNIObject object.
virtual ~JNIObject ()
 Destructs JNIObject object.
JNIEnv * env () const
 Returns JNIEnv pointer.
jweak ref () const
 Returns weak reference to the Java object.
bool isSameThread (JNIEnv *env) const
 Returns true if the specified JNIEnv pointer is same as m_env.
bool isLive ()
 Returns true if the JNI object is alive (not collected).
void checkException ()
 Checks for JNI exceptions.
bool testException ()
 Test if an exception has occurred.
void fatalError (const char *errorMessage)
 Prints the error message and terminates virtual machine.
void throwInternalError (const char *errorMessage=0)
 Throws java's internal error.
void throwOutOfMemoryError (const char *errorMessage=0)
 Throws java's out of memory error.
void throwRuntimeExcpetion (const char *exceptionMessage=0)
 Throws java's runtime exception.
jfieldID getFieldID (const char *name, const char *sig)
 Returns the fieldID.
jmethodID getMethodID (const char *name, const char *sig)
 Returns the jmethodID.
jobject getObjectField (jfieldID fieldID)
 Returns the value of the object field.
void setObjectField (jfieldID fieldID, jobject val)
 Sets the value of the object field.
jboolean getBooleanField (jfieldID fieldID)
 Returns the value of the boolean field.
void setBooleanField (jfieldID fieldID, jboolean val)
 Sets the value of the boolean field.
jbyte getByteField (jfieldID fieldID)
 Returns the value of the byte field.
void setByteField (jfieldID fieldID, jbyte val)
 Sets the value of the byte field.
jchar getCharField (jfieldID fieldID)
 Returns the value of the char field.
void setCharField (jfieldID fieldID, jchar val)
 Sets the value of the char field.
jshort getShortField (jfieldID fieldID)
 Returns the value of the short field.
void setShortField (jfieldID fieldID, jshort val)
 Sets the value of the short field.
jint getIntField (jfieldID fieldID)
 Returns the value of the int field.
void setIntField (jfieldID fieldID, jint val)
 Sets the value of the int field.
jlong getLongField (jfieldID fieldID)
 Returns the value of the long field.
void setLongField (jfieldID fieldID, jlong val)
 Sets the value of the long field.
jfloat getFloatField (jfieldID fieldID)
 Returns the value of the float field.
void setFloatField (jfieldID fieldID, jfloat val)
 Sets the value of the float field.
jdouble getDoubleField (jfieldID fieldID)
 Returns the value of the double field.
void setDoubleField (jfieldID fieldID, jdouble val)
 Sets the value of the double field.
jclass getObjectClass ()
 Returns JNI object class.
bool callObjectMethod (jobject &result, jmethodID methodID,...)
 Calls JNI object method.
bool callBooleanMethod (jboolean &result, jmethodID methodID,...)
 Calls JNI boolean method.
bool callByteMethod (jbyte &result, jmethodID methodID,...)
 Calls JNI byte method.
bool callCharMethod (jchar &result, jmethodID methodID,...)
 Calls JNI char method.
bool callShortMethod (jshort &result, jmethodID methodID,...)
 Calls JNI short method.
bool callIntMethod (jint &result, jmethodID methodID,...)
 Calls JNI int method.
bool callLongMethod (jlong &result, jmethodID methodID,...)
 Calls JNI long method.
bool callFloatMethod (jfloat &result, jmethodID methodID,...)
 Calls JNI float method.
bool callDoubleMethod (jdouble &result, jmethodID methodID,...)
 Calls JNI doble method.
bool callVoidMethod (jmethodID methodID,...)
 Calls JNI void method.
jstring toJString ()
 Returns jstring representation of the specified object.
jstring newJString (const jchar *uchars, jsize len)
 Creates new java string.
jstring newJStringUTF (const char *bytes)
 Creates new java string.


Detailed Description

JNI Object Wrapper.

Author:
Slobodan Vrkacevic (slobodan.vrkacevic@gmail.com)
Version:
0.2.0

Constructor & Destructor Documentation

JNIObject::JNIObject ( JNIEnv *  env,
jobject  obj 
)

Constructs new JNIObject object.

Parameters:
env the JNIEnv pointer
obj the Java object


Member Function Documentation

JNIEnv * JNIObject::env (  )  const [inline]

Returns JNIEnv pointer.

Returns:
env JNIEnv pointer

jweak JNIObject::ref (  )  const [inline]

Returns weak reference to the Java object.

Returns:
weak reference to the Java object

bool JNIObject::isSameThread ( JNIEnv *  env  )  const [inline]

Returns true if the specified JNIEnv pointer is same as m_env.

Returns:
true if JNIEnv pointer env is same as m_env

bool JNIObject::isLive (  ) 

Returns true if the JNI object is alive (not collected).

Returns:
true if if the JNI object is alive

bool JNIObject::testException (  ) 

Test if an exception has occurred.

Returns:
true if the exception has occurred

void JNIObject::fatalError ( const char *  errorMessage  ) 

Prints the error message and terminates virtual machine.

NOTE: This method does not return.

Parameters:
errorMessage the error message

void JNIObject::throwInternalError ( const char *  errorMessage = 0  ) 

Throws java's internal error.

Parameters:
errorMessage the error message

void JNIObject::throwOutOfMemoryError ( const char *  errorMessage = 0  ) 

Throws java's out of memory error.

Parameters:
errorMessage the error message

void JNIObject::throwRuntimeExcpetion ( const char *  exceptionMessage = 0  ) 

Throws java's runtime exception.

Parameters:
exceptionMessage the exception message

jfieldID JNIObject::getFieldID ( const char *  name,
const char *  sig 
)

Returns the fieldID.

Parameters:
name the field name
sig the field signature
Returns:
the fieldID

jmethodID JNIObject::getMethodID ( const char *  name,
const char *  sig 
)

Returns the jmethodID.

Parameters:
name the method name
sig the method signature
Returns:
the jmethodID

jobject JNIObject::getObjectField ( jfieldID  fieldID  ) 

Returns the value of the object field.

Parameters:
fieldID the field ID
Returns:
the value of the object field

void JNIObject::setObjectField ( jfieldID  fieldID,
jobject  val 
)

Sets the value of the object field.

Parameters:
fieldID the field ID
val the new value

jboolean JNIObject::getBooleanField ( jfieldID  fieldID  ) 

Returns the value of the boolean field.

Parameters:
fieldID the field ID
Returns:
the value of the boolean field

void JNIObject::setBooleanField ( jfieldID  fieldID,
jboolean  val 
)

Sets the value of the boolean field.

Parameters:
fieldID the field ID
val the new value

jbyte JNIObject::getByteField ( jfieldID  fieldID  ) 

Returns the value of the byte field.

Parameters:
fieldID the field ID
Returns:
the value of the byte field

void JNIObject::setByteField ( jfieldID  fieldID,
jbyte  val 
)

Sets the value of the byte field.

Parameters:
fieldID the field ID
val the new value

jchar JNIObject::getCharField ( jfieldID  fieldID  ) 

Returns the value of the char field.

Parameters:
fieldID the field ID
Returns:
the value of the char field

void JNIObject::setCharField ( jfieldID  fieldID,
jchar  val 
)

Sets the value of the char field.

Parameters:
fieldID the field ID
val the new value

jshort JNIObject::getShortField ( jfieldID  fieldID  ) 

Returns the value of the short field.

Parameters:
fieldID the field ID
Returns:
the value of the short field

void JNIObject::setShortField ( jfieldID  fieldID,
jshort  val 
)

Sets the value of the short field.

Parameters:
fieldID the field ID
val the new value

jint JNIObject::getIntField ( jfieldID  fieldID  ) 

Returns the value of the int field.

Parameters:
fieldID the field ID
Returns:
the value of the int field

void JNIObject::setIntField ( jfieldID  fieldID,
jint  val 
)

Sets the value of the int field.

Parameters:
fieldID the field ID
val the new value

jlong JNIObject::getLongField ( jfieldID  fieldID  ) 

Returns the value of the long field.

Parameters:
fieldID the field ID
Returns:
the value of the long field

void JNIObject::setLongField ( jfieldID  fieldID,
jlong  val 
)

Sets the value of the long field.

Parameters:
fieldID the field ID
val the new value

jfloat JNIObject::getFloatField ( jfieldID  fieldID  ) 

Returns the value of the float field.

Parameters:
fieldID the field ID
Returns:
the value of the float field

void JNIObject::setFloatField ( jfieldID  fieldID,
jfloat  val 
)

Sets the value of the float field.

Parameters:
fieldID the field ID
val the new value

jdouble JNIObject::getDoubleField ( jfieldID  fieldID  ) 

Returns the value of the double field.

Parameters:
fieldID the field ID
Returns:
the value of the double field

void JNIObject::setDoubleField ( jfieldID  fieldID,
jdouble  val 
)

Sets the value of the double field.

Parameters:
fieldID the field ID
val the new value

jclass JNIObject::getObjectClass (  ) 

Returns JNI object class.

Returns:
JNI object class

bool JNIObject::callObjectMethod ( jobject &  result,
jmethodID  methodID,
  ... 
)

Calls JNI object method.

Parameters:
result the result
methodID the method ID
... the method arguments
Returns:
true if no exception is thrown

bool JNIObject::callBooleanMethod ( jboolean &  result,
jmethodID  methodID,
  ... 
)

Calls JNI boolean method.

Parameters:
result the result
methodID the method ID
... the method arguments
Returns:
true if no exception is thrown

bool JNIObject::callByteMethod ( jbyte &  result,
jmethodID  methodID,
  ... 
)

Calls JNI byte method.

Parameters:
result the result
methodID the method ID
... the method arguments
Returns:
true if no exception is thrown

bool JNIObject::callCharMethod ( jchar &  result,
jmethodID  methodID,
  ... 
)

Calls JNI char method.

Parameters:
result the result
methodID the method ID
... the method arguments
Returns:
true if no exception is thrown

bool JNIObject::callShortMethod ( jshort &  result,
jmethodID  methodID,
  ... 
)

Calls JNI short method.

Parameters:
result the result
methodID the method ID
... the method arguments
Returns:
true if no exception is thrown

bool JNIObject::callIntMethod ( jint &  result,
jmethodID  methodID,
  ... 
)

Calls JNI int method.

Parameters:
result the result
methodID the method ID
... the method arguments
Returns:
true if no exception is thrown

bool JNIObject::callLongMethod ( jlong &  result,
jmethodID  methodID,
  ... 
)

Calls JNI long method.

Parameters:
result the result
methodID the method ID
... the method arguments
Returns:
true if no exception is thrown

bool JNIObject::callFloatMethod ( jfloat &  result,
jmethodID  methodID,
  ... 
)

Calls JNI float method.

Parameters:
result the result
methodID the method ID
... the method arguments
Returns:
true if no exception is thrown

bool JNIObject::callDoubleMethod ( jdouble &  result,
jmethodID  methodID,
  ... 
)

Calls JNI doble method.

Parameters:
result the result
methodID the method ID
... the method arguments
Returns:
true if no exception is thrown

bool JNIObject::callVoidMethod ( jmethodID  methodID,
  ... 
)

Calls JNI void method.

Parameters:
methodID the method ID
... the method arguments
Returns:
true if no exception is thrown

jstring JNIObject::toJString (  ) 

Returns jstring representation of the specified object.

Returns:
jstring representation of the specified object

jstring JNIObject::newJString ( const jchar *  uchars,
jsize  len 
)

Creates new java string.

Parameters:
uchars the unicode char array
len the length of the char array
Returns:
new Java string object

jstring JNIObject::newJStringUTF ( const char *  bytes  ) 

Creates new java string.

Parameters:
bytes the UTF-8 char array
Returns:
new Java string object


Copyright © 2007 ETF and contributors. All Rights Reserved.