JavaContext Class Reference

When the Invocation Interface is being used (that is, when a C++ program calls into Java code), the getContext() method of the JavaVirtualMachine class is used to obtain an appropriate JavaContext object. More...

#include <JavaContext.h++>

Collaboration diagram for JavaContext:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 JavaContext (JNIEnv *env)
 Construct a new JavaContext for the given JNI environment pointer.
 ~JavaContext ()
 Destructor.
jclass findClass (const String &name) throw (JavaException)
 Look up a class by name.
jmethodID findMethod (jclass clazz, const String &signature) throw (JavaException)
 Look up a method or constructor by signature.
jobject createObject (jclass clazz, jmethodID constructor,...) throw (JavaException)
 Instantiate a new Java object.
jobject createObjectVA (jclass clazz, jmethodID constructor, va_list args) throw (JavaException)
 Instantiate a new Java object.
void callVoidMethod (jobject object, jmethodID method,...) throw (JavaException)
 Call a Java method that returns void.
jobject callObjectMethod (jobject object, jmethodID method,...) throw (JavaException)
 Call a Java method that returns a Java Object.
String callStringMethod (jobject object, jmethodID method,...) throw (JavaException)
 Call a Java method that returns a java.lang.String.
WString callWStringMethod (jobject object, jmethodID method,...) throw (JavaException)
 Call a Java method that returns a java.lang.String.
jboolean callBooleanMethod (jobject object, jmethodID method,...) throw (JavaException)
 Call a Java method that returns a boolean.
jbyte callByteMethod (jobject object, jmethodID method,...) throw (JavaException)
 Call a Java method that returns a byte.
jchar callCharMethod (jobject object, jmethodID method,...) throw (JavaException)
 Call a Java method that returns a char.
jshort callShortMethod (jobject object, jmethodID method,...) throw (JavaException)
 Call a Java method that returns a short.
jint callIntMethod (jobject object, jmethodID method,...) throw (JavaException)
 Call a Java method that returns an int.
jlong callLongMethod (jobject object, jmethodID method,...) throw (JavaException)
 Call a Java method that returns a long.
jfloat callFloatMethod (jobject object, jmethodID method,...) throw (JavaException)
 Call a Java method that returns a float.
jdouble callDoubleMethod (jobject object, jmethodID method,...) throw (JavaException)
 Call a Java method that returns a double.
void callNonvirtualVoidMethod (jobject object, jclass clazz, jmethodID method,...) throw (JavaException)
 Call a non-virtual Java method that returns void.
jobject callNonvirtualObjectMethod (jobject object, jclass clazz, jmethodID method,...) throw (JavaException)
 Call a non-virtual Java method that returns a Java object.
jboolean callNonvirtualBooleanMethod (jobject object, jclass clazz, jmethodID method,...) throw (JavaException)
 Call a non-virtual Java method that returns a boolean.
jbyte callNonvirtualByteMethod (jobject object, jclass clazz, jmethodID method,...) throw (JavaException)
 Call a non-virtual Java method that returns a byte.
jchar callNonvirtualCharMethod (jobject object, jclass clazz, jmethodID method,...) throw (JavaException)
 Call a non-virtual Java method that returns a char.
jshort callNonvirtualShortMethod (jobject object, jclass clazz, jmethodID method,...) throw (JavaException)
 Call a non-virtual Java method that returns a short.
jint callNonvirtualIntMethod (jobject object, jclass clazz, jmethodID method,...) throw (JavaException)
 Call a non-virtual Java method that returns an int.
jlong callNonvirtualLongMethod (jobject object, jclass clazz, jmethodID method,...) throw (JavaException)
 Call a non-virtual Java method that returns a long.
jfloat callNonvirtualFloatMethod (jobject object, jclass clazz, jmethodID method,...) throw (JavaException)
 Call a non-virtual Java method that returns a float.
jdouble callNonvirtualDoubleMethod (jobject object, jclass clazz, jmethodID method,...) throw (JavaException)
 Call a non-virtual Java method that returns a double.
void callStaticVoidMethod (jclass clazz, jmethodID method,...) throw (JavaException)
 Call a static Java method that returns void.
jobject callStaticObjectMethod (jclass clazz, jmethodID method,...) throw (JavaException)
 Call a static Java method that returns a Java Object.
String callStaticStringMethod (jclass clazz, jmethodID method,...) throw (JavaException)
 Call a static Java method that returns a java.lang.String.
WString callStaticWStringMethod (jclass clazz, jmethodID method,...) throw (JavaException)
 Call a static Java method that returns a java.lang.String.
jboolean callStaticBooleanMethod (jclass clazz, jmethodID method,...) throw (JavaException)
 Call a static Java method that returns a boolean.
jbyte callStaticByteMethod (jclass clazz, jmethodID method,...) throw (JavaException)
 Call a static Java method that returns a byte.
jchar callStaticCharMethod (jclass clazz, jmethodID method,...) throw (JavaException)
 Call a static Java method that returns a char.
jshort callStaticShortMethod (jclass clazz, jmethodID method,...) throw (JavaException)
 Call a static Java method that returns a short.
jint callStaticIntMethod (jclass clazz, jmethodID method,...) throw (JavaException)
 Call a static Java method that returns an int.
jlong callStaticLongMethod (jclass clazz, jmethodID method,...) throw (JavaException)
 Call a static Java method that returns a long.
jfloat callStaticFloatMethod (jclass clazz, jmethodID method,...) throw (JavaException)
 Call a static Java method that returns a float.
jdouble callStaticDoubleMethod (jclass clazz, jmethodID method,...) throw (JavaException)
 Call a static Java method that returns a double.
bool checkException (bool verbose=false)
 Determine if a Java exception has been thrown in the current thread.
void clearException () throw ()
 Clear any pending Java exception that is currently being thrown in the current thread.
jthrowable getException () throw ()
 Get the pending Java exception, if one is currently being thrown in the current thread.
bool throwException (jclass exception, const String &message)
 Throw a Java exception.
jfieldID findField (jclass clazz, const String &signature) throw (JavaException)
 Look up a field by signature.
jobject getObjectField (jobject object, jfieldID field) throw (JavaException)
 Get the value of an Object field in an Object.
jboolean getBooleanField (jobject object, jfieldID field) throw (JavaException)
 Get the value of an boolean field in an Object.
jbyte getByteField (jobject object, jfieldID field) throw (JavaException)
 Get the value of a byte field in an Object.
jchar getCharField (jobject object, jfieldID field) throw (JavaException)
 Get the value of a char field in an Object.
jshort getShortField (jobject object, jfieldID field) throw (JavaException)
 Get the value of a short field in an Object.
jint getIntField (jobject object, jfieldID field) throw (JavaException)
 Get the value of an int field in an Object.
jlong getLongField (jobject object, jfieldID field) throw (JavaException)
 Get the value of a long field in an Object.
jfloat getFloatField (jobject object, jfieldID field) throw (JavaException)
 Get the value of a float field in an Object.
jdouble getDoubleField (jobject object, jfieldID field) throw (JavaException)
 Get the value of a double field in an Object.
String getStringField (jobject object, jfieldID field) throw (JavaException)
 Get the value of a java.lang.String field in an Object.
WString getWStringField (jobject object, jfieldID field) throw (JavaException)
 Get the value of a java.lang.String field in an Object.
jobject getStaticObjectField (jclass clazz, jfieldID field) throw (JavaException)
 Get the value of a static Object field in a class.
jboolean getStaticBooleanField (jclass clazz, jfieldID field) throw (JavaException)
 Get the value of a static boolean field in a class.
jbyte getStaticByteField (jclass clazz, jfieldID field) throw (JavaException)
 Get the value of a static byte field in a class.
jchar getStaticCharField (jclass clazz, jfieldID field) throw (JavaException)
 Get the value of a static char field in a class.
jshort getStaticShortField (jclass clazz, jfieldID field) throw (JavaException)
 Get the value of a static short field in a class.
jint getStaticIntField (jclass clazz, jfieldID field) throw (JavaException)
 Get the value of a static int field in a class.
jlong getStaticLongField (jclass clazz, jfieldID field) throw (JavaException)
 Get the value of a static long field in a class.
jfloat getStaticFloatField (jclass clazz, jfieldID field) throw (JavaException)
 Get the value of a static float field in a class.
jdouble getStaticDoubleField (jclass clazz, jfieldID field) throw (JavaException)
 Get the value of a static double field in a class.
String getStaticStringField (jclass clazz, jfieldID field) throw (JavaException)
 Get the value of a static String field in a class.
WString getStaticWStringField (jclass clazz, jfieldID field) throw (JavaException)
 Get the value of a static String field in a class.
void setObjectField (jobject object, jfieldID field, jobject value) throw (JavaException)
 Set the value of an Object field in an object.
void setBooleanField (jobject object, jfieldID field, jboolean value) throw (JavaException)
 Set the value of a boolean field in an object.
void setByteField (jobject object, jfieldID field, jbyte value) throw (JavaException)
 Set the value of a byte field in an object.
void setCharField (jobject object, jfieldID field, jchar value) throw (JavaException)
 Set the value of a char field in an object.
void setShortField (jobject object, jfieldID field, jshort value) throw (JavaException)
 Set the value of a short field in an object.
void setIntField (jobject object, jfieldID field, jint value) throw (JavaException)
 Set the value of an int field in an object.
void setLongField (jobject object, jfieldID field, jlong value) throw (JavaException)
 Set the value of a long field in an object.
void setFloatField (jobject object, jfieldID field, jfloat value) throw (JavaException)
 Set the value of a float field in an object.
void setDoubleField (jobject object, jfieldID field, jdouble value) throw (JavaException)
 Set the value of a double field in an object.
void setStringField (jobject object, jfieldID field, const String &value) throw (JavaException)
 Set the value of a java.lang.String field in an object.
void setWStringField (jobject object, jfieldID field, const WString &value) throw (JavaException)
 Set the value of a java.lang.String field in an object.
void setStaticObjectField (jclass clazz, jfieldID field, jobject value) throw (JavaException)
 Set the value of a static Object field in a class.
void setStaticBooleanField (jclass clazz, jfieldID field, jboolean value) throw (JavaException)
 Set the value of a static boolean field in a class.
void setStaticByteField (jclass clazz, jfieldID field, jbyte value) throw (JavaException)
 Set the value of a static byte field in a class.
void setStaticCharField (jclass clazz, jfieldID field, jchar value) throw (JavaException)
 Set the value of a static char field in a class.
void setStaticShortField (jclass clazz, jfieldID field, jshort value) throw (JavaException)
 Set the value of a static short field in a class.
void setStaticIntField (jclass clazz, jfieldID field, jint value) throw (JavaException)
 Set the value of a static int field in a class.
void setStaticLongField (jclass clazz, jfieldID field, jlong value) throw (JavaException)
 Set the value of a static long field in a class.
void setStaticFloatField (jclass clazz, jfieldID field, jfloat value) throw (JavaException)
 Set the value of a static float field in a class.
void setStaticDoubleField (jclass clazz, jfieldID field, jdouble value) throw (JavaException)
 Set the value of a static double field in a class.
jbyteArray createByteArray (uint_t length) throw (JavaException)
 Create a Java byte array.
void setObjectArrayElement (jobjectArray array, uint_t index, jobject value) throw (JavaException)
 Set an element of a Java object array.
jobject getObjectArrayElement (jobjectArray array, uint_t index) throw (JavaException)
 Get an element of a Java object array.
uint_t getArrayLength (jarray array) throw (JavaException)
 Get the length of a Java array.
jobject createDirectByteBuffer (byte_t *buf, size_t size) throw (JavaException)
 Create a new Java DirectByteBuffer.
void * getDirectBufferRegion (jobject buf, uint64_t &size)
 Get a pointer to and the size of the memory region occupied by a Java DirectBuffer.
jobject createLocalRef (jobject object) throw (JavaException)
 Create a local reference to a Java object.
void deleteLocalRef (jobject ref)
 Delete a local reference.
void ensureLocalCapacity (size_t capacity) throw (JavaException)
 Reserve space for local references.
jobject createGlobalRef (jobject object) throw (JavaException)
 Create a global reference to a Java object.
void deleteGlobalRef (jobject ref)
 Delete a local reference.
String decodeString (jstring str) throw (JavaException)
 Decode a java.lang.String into a String.
WString decodeWString (jstring str) throw (JavaException)
 Decode a java.lang.String into a WString.
jstring encodeString (const String &str) throw (JavaException)
 Encode a String into a java.lang.String.
jstring encodeWString (const WString &str) throw (JavaException)
 Encode a WString into a java.lang.String.
size_t getStringLength (jstring str)
 Get the length of a Java string.
void * getArrayData (jarray array, size_t &length, bool *isCopy=NULL) throw (JavaException)
 Obtain a pointer to the body of a primitive Java array.
void releaseArrayData (jarray array, void *data)
 Release the buffer returned by getArrayData().
jbyteArray createByteArray (const byte_t *data, size_t length) throw (JavaException)
 Create a Java byte array.
jarray createObjectArray (jclass type, size_t length, jobject initialValue=NULL) throw (JavaException)
 Create a Java object array.
bool isSameObject (jobject object1, jobject object2)
 Test two Java object references for equality.
bool isInstanceOf (jobject object, jclass clazz)
 Test if a Java object is an instance of an interface or another class.
bool isAssignableFrom (jclass clazz1, jclass clazz2)
 Test if an object of a class or interface can be safely cast to a class or interface of another class.
jclass getClassForObject (jobject object)
 Get the class for a Java object.
jclass getSuperclass (jclass clazz)
 Get the superclass for a Java class.
void enterMonitor (jobject object) throw (JavaException)
 Enter the monitor associated with a Java object.
void exitMonitor (jobject object) throw (JavaException)
 Exit the monitor associated with a Java object.
void registerNativeMethods (jclass clazz, const JavaNativeMethod methods[]) throw (JavaException)
 Register native methods for a Java class.
void unregisterNativeMethods (jclass clazz)
 Unregister all native methods for a Java class.
void pushLocalFrame (uint_t capacity=8) throw (JavaException)
 Create a new local reference frame.
void popLocalFrame ()
 Destroy the topmost local reference frame.
bool isVerbose () const throw ()
 Determine if verbose mode is enabled for this context.

Static Public Member Functions

static String encodeType (const String &type)
 Encode a datatype into a JNI datatype descriptor.
static bool parseSignature (const String &signature, String &method, String &descriptor, bool &isStatic)
 Parse a method signature into a method name, a JNI method descriptor, and a static flag.

Friends

class JavaVirtualMachine


Detailed Description

When the Invocation Interface is being used (that is, when a C++ program calls into Java code), the getContext() method of the JavaVirtualMachine class is used to obtain an appropriate JavaContext object.

In C++ code that implements a Java native method, on the other hand, a JavaContext instance must be explicitly constructed from the JNIEnv pointer that was passed into the native function.

This is a lightweight object that should typically be stack-allocated, and may be passed and copied by value.

Author:
Mark Lindner

Constructor & Destructor Documentation

JavaContext ( JNIEnv *  env  ) 

Construct a new JavaContext for the given JNI environment pointer.

Parameters:
env The JNI environment pointer.

~JavaContext (  ) 

Destructor.


Member Function Documentation

jboolean callBooleanMethod ( jobject  object,
jmethodID  method,
  ... 
) throw (JavaException)

Call a Java method that returns a boolean.

Parameters:
object The object instance.
method The method to call.
Returns:
The method's return value.
Exceptions:
JavaException If the called method throws an exception, or if an invocation error occurs.

jbyte callByteMethod ( jobject  object,
jmethodID  method,
  ... 
) throw (JavaException)

Call a Java method that returns a byte.

Parameters:
object The object instance.
method The method to call.
Returns:
The method's return value.
Exceptions:
JavaException If the called method throws an exception, or if an invocation error occurs.

jchar callCharMethod ( jobject  object,
jmethodID  method,
  ... 
) throw (JavaException)

Call a Java method that returns a char.

Parameters:
object The object instance.
method The method to call.
Returns:
The method's return value.
Exceptions:
JavaException If the called method throws an exception, or if an invocation error occurs.

jdouble callDoubleMethod ( jobject  object,
jmethodID  method,
  ... 
) throw (JavaException)

Call a Java method that returns a double.

Parameters:
object The object instance.
method The method to call.
Returns:
The method's return value.
Exceptions:
JavaException If the called method throws an exception, or if an invocation error occurs.

jfloat callFloatMethod ( jobject  object,
jmethodID  method,
  ... 
) throw (JavaException)

Call a Java method that returns a float.

Parameters:
object The object instance.
method The method to call.
Returns:
The method's return value.
Exceptions:
JavaException If the called method throws an exception, or if an invocation error occurs.

jint callIntMethod ( jobject  object,
jmethodID  method,
  ... 
) throw (JavaException)

Call a Java method that returns an int.

Parameters:
object The object instance.
method The method to call.
Returns:
The method's return value.
Exceptions:
JavaException If the called method throws an exception, or if an invocation error occurs.

jlong callLongMethod ( jobject  object,
jmethodID  method,
  ... 
) throw (JavaException)

Call a Java method that returns a long.

Parameters:
object The object instance.
method The method to call.
Returns:
The method's return value.
Exceptions:
JavaException If the called method throws an exception, or if an invocation error occurs.

jboolean callNonvirtualBooleanMethod ( jobject  object,
jclass  clazz,
jmethodID  method,
  ... 
) throw (JavaException)

Call a non-virtual Java method that returns a boolean.

Parameters:
object The object instance.
clazz The method's defining class.
method The method to call.
Returns:
The method's return value.
Exceptions:
JavaException If the called method throws an exception, or if an invocation error occurs.

jbyte callNonvirtualByteMethod ( jobject  object,
jclass  clazz,
jmethodID  method,
  ... 
) throw (JavaException)

Call a non-virtual Java method that returns a byte.

Parameters:
object The object instance.
clazz The method's defining class.
method The method to call.
Returns:
The method's return value.
Exceptions:
JavaException If the called method throws an exception, or if an invocation error occurs.

jchar callNonvirtualCharMethod ( jobject  object,
jclass  clazz,
jmethodID  method,
  ... 
) throw (JavaException)

Call a non-virtual Java method that returns a char.

Parameters:
object The object instance.
clazz The method's defining class.
method The method to call.
Returns:
The method's return value.
Exceptions:
JavaException If the called method throws an exception, or if an invocation error occurs.

jdouble callNonvirtualDoubleMethod ( jobject  object,
jclass  clazz,
jmethodID  method,
  ... 
) throw (JavaException)

Call a non-virtual Java method that returns a double.

Parameters:
object The object instance.
clazz The method's defining class.
method The method to call.
Returns:
The method's return value.
Exceptions:
JavaException If the called method throws an exception, or if an invocation error occurs.

jfloat callNonvirtualFloatMethod ( jobject  object,
jclass  clazz,
jmethodID  method,
  ... 
) throw (JavaException)

Call a non-virtual Java method that returns a float.

Parameters:
object The object instance.
clazz The method's defining class.
method The method to call.
Returns:
The method's return value.
Exceptions:
JavaException If the called method throws an exception, or if an invocation error occurs.

jint callNonvirtualIntMethod ( jobject  object,
jclass  clazz,
jmethodID  method,
  ... 
) throw (JavaException)

Call a non-virtual Java method that returns an int.

Parameters:
object The object instance.
clazz The method's defining class.
method The method to call.
Returns:
The method's return value.
Exceptions:
JavaException If the called method throws an exception, or if an invocation error occurs.

jlong callNonvirtualLongMethod ( jobject  object,
jclass  clazz,
jmethodID  method,
  ... 
) throw (JavaException)

Call a non-virtual Java method that returns a long.

Parameters:
object The object instance.
clazz The method's defining class.
method The method to call.
Returns:
The method's return value.
Exceptions:
JavaException If the called method throws an exception, or if an invocation error occurs.

jobject callNonvirtualObjectMethod ( jobject  object,
jclass  clazz,
jmethodID  method,
  ... 
) throw (JavaException)

Call a non-virtual Java method that returns a Java object.

Parameters:
object The object instance.
clazz The method's defining class.
method The method to call.
Returns:
The method's return value.
Exceptions:
JavaException If the called method throws an exception, or if an invocation error occurs.

jshort callNonvirtualShortMethod ( jobject  object,
jclass  clazz,
jmethodID  method,
  ... 
) throw (JavaException)

Call a non-virtual Java method that returns a short.

Parameters:
object The object instance.
clazz The method's defining class.
method The method to call.
Returns:
The method's return value.
Exceptions:
JavaException If the called method throws an exception, or if an invocation error occurs.

void callNonvirtualVoidMethod ( jobject  object,
jclass  clazz,
jmethodID  method,
  ... 
) throw (JavaException)

Call a non-virtual Java method that returns void.

Parameters:
object The object instance.
clazz The method's defining class.
method The method to call.
Exceptions:
JavaException If the called method throws an exception, or if an invocation error occurs.

jobject callObjectMethod ( jobject  object,
jmethodID  method,
  ... 
) throw (JavaException)

Call a Java method that returns a Java Object.

Parameters:
object The object instance.
method The method to call.
Returns:
The method's return value.
Exceptions:
JavaException If the called method throws an exception, or if an invocation error occurs.

jshort callShortMethod ( jobject  object,
jmethodID  method,
  ... 
) throw (JavaException)

Call a Java method that returns a short.

Parameters:
object The object instance.
method The method to call.
Returns:
The method's return value.
Exceptions:
JavaException If the called method throws an exception, or if an invocation error occurs.

jboolean callStaticBooleanMethod ( jclass  clazz,
jmethodID  method,
  ... 
) throw (JavaException)

Call a static Java method that returns a boolean.

Parameters:
clazz The Java class.
method The method to call.
Returns:
The method's return value.
Exceptions:
JavaException If the called method throws an exception, or if an invocation error occurs.

jbyte callStaticByteMethod ( jclass  clazz,
jmethodID  method,
  ... 
) throw (JavaException)

Call a static Java method that returns a byte.

Parameters:
clazz The Java class.
method The method to call.
Returns:
The method's return value.
Exceptions:
JavaException If the called method throws an exception, or if an invocation error occurs.

jchar callStaticCharMethod ( jclass  clazz,
jmethodID  method,
  ... 
) throw (JavaException)

Call a static Java method that returns a char.

Parameters:
clazz The Java class.
method The method to call.
Returns:
The method's return value.
Exceptions:
JavaException If the called method throws an exception, or if an invocation error occurs.

jdouble callStaticDoubleMethod ( jclass  clazz,
jmethodID  method,
  ... 
) throw (JavaException)

Call a static Java method that returns a double.

Parameters:
clazz The Java class.
method The method to call.
Returns:
The method's return value.
Exceptions:
JavaException If the called method throws an exception, or if an invocation error occurs.

jfloat callStaticFloatMethod ( jclass  clazz,
jmethodID  method,
  ... 
) throw (JavaException)

Call a static Java method that returns a float.

Parameters:
clazz The Java class.
method The method to call.
Returns:
The method's return value.
Exceptions:
JavaException If the called method throws an exception, or if an invocation error occurs.

jint callStaticIntMethod ( jclass  clazz,
jmethodID  method,
  ... 
) throw (JavaException)

Call a static Java method that returns an int.

Parameters:
clazz The Java class.
method The method to call.
Returns:
The method's return value.
Exceptions:
JavaException If the called method throws an exception, or if an invocation error occurs.

jlong callStaticLongMethod ( jclass  clazz,
jmethodID  method,
  ... 
) throw (JavaException)

Call a static Java method that returns a long.

Parameters:
clazz The Java class.
method The method to call.
Returns:
The method's return value.
Exceptions:
JavaException If the called method throws an exception, or if an invocation error occurs.

jobject callStaticObjectMethod ( jclass  clazz,
jmethodID  method,
  ... 
) throw (JavaException)

Call a static Java method that returns a Java Object.

Parameters:
clazz The Java class.
method The method to call.
Returns:
The method's return value.
Exceptions:
JavaException If the called method throws an exception, or if an invocation error occurs.

jshort callStaticShortMethod ( jclass  clazz,
jmethodID  method,
  ... 
) throw (JavaException)

Call a static Java method that returns a short.

Parameters:
clazz The Java class.
method The method to call.
Returns:
The method's return value.
Exceptions:
JavaException If the called method throws an exception, or if an invocation error occurs.

String callStaticStringMethod ( jclass  clazz,
jmethodID  method,
  ... 
) throw (JavaException)

Call a static Java method that returns a java.lang.String.

Parameters:
clazz The Java class.
method The method to call.
Returns:
The method's return value, as a String.
Exceptions:
JavaException If the called method throws an exception, or if an invocation error occurs.

void callStaticVoidMethod ( jclass  clazz,
jmethodID  method,
  ... 
) throw (JavaException)

Call a static Java method that returns void.

Parameters:
clazz The Java class.
method The method to call.
Returns:
The method's return value.
Exceptions:
JavaException If the called method throws an exception, or if an invocation error occurs.

WString callStaticWStringMethod ( jclass  clazz,
jmethodID  method,
  ... 
) throw (JavaException)

Call a static Java method that returns a java.lang.String.

Parameters:
clazz The Java class.
method The method to call.
Returns:
The method's return value, as a WString.
Exceptions:
JavaException If the called method throws an exception, or if an invocation error occurs.

String callStringMethod ( jobject  object,
jmethodID  method,
  ... 
) throw (JavaException)

Call a Java method that returns a java.lang.String.

Parameters:
object The object instance.
method The method to call.
Returns:
The method's return value, encoded as a String.
Exceptions:
JavaException If the called method throws an exception, or if an invocation error occurs.

void callVoidMethod ( jobject  object,
jmethodID  method,
  ... 
) throw (JavaException)

Call a Java method that returns void.

Parameters:
object The object instance.
method The method to call.
Exceptions:
JavaException If the called method throws an exception, or if an invocation error occurs.

WString callWStringMethod ( jobject  object,
jmethodID  method,
  ... 
) throw (JavaException)

Call a Java method that returns a java.lang.String.

Parameters:
object The object instance.
method The method to call.
Returns:
The method's return value, encoded as a WString.
Exceptions:
JavaException If the called method throws an exception, or if an invocation error occurs.

bool checkException ( bool  verbose = false  ) 

Determine if a Java exception has been thrown in the current thread.

Parameters:
verbose If true, print the exception stack trace to standard error.
Returns:
true if an exception has been thrown, false otherwise.

void clearException (  )  throw ()

Clear any pending Java exception that is currently being thrown in the current thread.

jbyteArray createByteArray ( const byte_t data,
size_t  length 
) throw (JavaException)

Create a Java byte array.

Parameters:
data The data to copy into the array.
length The length of the array.
Returns:
The newly created array.
Exceptions:
JavaException If an error occurs.

jbyteArray createByteArray ( uint_t  length  )  throw (JavaException)

Create a Java byte array.

Parameters:
length The length of the array.
Returns:
The array.
Exceptions:
JavaException If an error occurs.

jobject createDirectByteBuffer ( byte_t buf,
size_t  size 
) throw (JavaException)

Create a new Java DirectByteBuffer.

Parameters:
buf A pointer to the natively-allocated memory block for the buffer.
size The size of the memory block, in bytes.
Returns:
The newly created DirectByteBuffer object.
Exceptions:
JavaException If an error occurs.

jobject createGlobalRef ( jobject  object  )  throw (JavaException)

Create a global reference to a Java object.

Parameters:
object The object.
Returns:
The new global reference.
Exceptions:
JavaException If an error occurs.

jobject createLocalRef ( jobject  object  )  throw (JavaException)

Create a local reference to a Java object.

Parameters:
object The object.
Returns:
The new local reference.
Exceptions:
JavaException If an error occurs.

jobject createObject ( jclass  clazz,
jmethodID  constructor,
  ... 
) throw (JavaException)

Instantiate a new Java object.

Parameters:
clazz The class.
constructor The constructor to invoke.
Exceptions:
JavaException If the constructor throws an exception, or if an invocation error occurs.

jarray createObjectArray ( jclass  type,
size_t  length,
jobject  initialValue = NULL 
) throw (JavaException)

Create a Java object array.

Parameters:
type The array type.
length The length of the array.
initialValue An optional initial value to store into every element in the new array.
Returns:
The newly created array.
Exceptions:
JavaException If an error occurs.

jobject createObjectVA ( jclass  clazz,
jmethodID  constructor,
va_list  args 
) throw (JavaException)

Instantiate a new Java object.

Parameters:
clazz The class.
constructor The constructor to invoke.
args The arguments to pass to the constructor.
Exceptions:
JavaException If the constructor throws an exception, or if an invocation error occurs.

String decodeString ( jstring  str  )  throw (JavaException)

Decode a java.lang.String into a String.

Parameters:
str The Java string.
Returns:
The decoded String.
Exceptions:
JavaException If an error occurs.

WString decodeWString ( jstring  str  )  throw (JavaException)

Decode a java.lang.String into a WString.

Parameters:
str The Java string.
Returns:
The decoded WString.
Exceptions:
JavaException If an error occurs.

void deleteGlobalRef ( jobject  ref  ) 

Delete a local reference.

Parameters:
ref The reference.

void deleteLocalRef ( jobject  ref  ) 

Delete a local reference.

Parameters:
ref The reference.

jstring encodeString ( const String str  )  throw (JavaException)

Encode a String into a java.lang.String.

Parameters:
str The String.
Returns:
The encoded Java string.
Exceptions:
JavaException If an error occurs.

String encodeType ( const String type  )  [static]

Encode a datatype into a JNI datatype descriptor.

For example, "String[]" is encoded as "[Ljava/lang/String;".

Parameters:
type The datatype.
Returns:
The encoding of the datatype.

jstring encodeWString ( const WString str  )  throw (JavaException)

Encode a WString into a java.lang.String.

Parameters:
str The String.
Returns:
The encoded Java string.
Exceptions:
JavaException If an error occurs.

void ensureLocalCapacity ( size_t  capacity  )  throw (JavaException)

Reserve space for local references.

Parameters:
capacity The number of local references to reserve capacity for.
Exceptions:
JavaException If an error occurs.

void enterMonitor ( jobject  object  )  throw (JavaException)

Enter the monitor associated with a Java object.

The method blocks if another thread is currently in the monitor.

Parameters:
object The object.
Exceptions:
JavaException If an error occurs.

void exitMonitor ( jobject  object  )  throw (JavaException)

Exit the monitor associated with a Java object.

Parameters:
object The object.
Exceptions:
JavaException If an error occurs.

jclass findClass ( const String name  )  throw (JavaException)

Look up a class by name.

The class name must be fully qualified (for example, "java.util.Vector"), with the following classes as the only exceptions: String, Object, Class.

Parameters:
name The name of the class.
Returns:
A reference to the Java class.
Exceptions:
JavaException If the class was not found.

jfieldID findField ( jclass  clazz,
const String signature 
) throw (JavaException)

Look up a field by signature.

The signature must be specified in Java source code form, for example "String name" or "static int foo".

Parameters:
clazz The Java class.
signature The signature of the field.
Returns:
A reference to the field.
Exceptions:
JavaException If the field was not found.

jmethodID findMethod ( jclass  clazz,
const String signature 
) throw (JavaException)

Look up a method or constructor by signature.

The signature must be specified in Java source code form, without parameter names, for example "int foo(int, byte[])" or "static boolean bar(java.lang.Vector, int, String)", or "(int, String, String)" (a constructor).

Parameters:
clazz The Java class.
signature The signature of the method.
Returns:
A reference to the method.
Exceptions:
JavaException If the method was not found.

void * getArrayData ( jarray  array,
size_t &  length,
bool *  isCopy = NULL 
) throw (JavaException)

Obtain a pointer to the body of a primitive Java array.

This data may be used and modified safely (without any intervening JNI calls) until a matching call to releaseArrayData().

Parameters:
array The primitive array.
length A parameter in which to store the length of the buffer containing the array data.
isCopy If not NULL, a pointer in which to store a flag indicating whether the returned buffer is a copy of the array data.
Returns:
A pointer to a buffer containing the array data.
Exceptions:
JavaException If an error occurs.

uint_t getArrayLength ( jarray  array  )  throw (JavaException)

Get the length of a Java array.

Parameters:
array The array.
Returns:
The number of elements in the array.
Exceptions:
JavaException If an error occurs.

jboolean getBooleanField ( jobject  object,
jfieldID  field 
) throw (JavaException)

Get the value of an boolean field in an Object.

Parameters:
object The object.
field The field ID.
Returns:
The value of the field.
Exceptions:
JavaException If an error occurs.

jbyte getByteField ( jobject  object,
jfieldID  field 
) throw (JavaException)

Get the value of a byte field in an Object.

Parameters:
object The object.
field The field ID.
Returns:
The value of the field.
Exceptions:
JavaException If an error occurs.

jchar getCharField ( jobject  object,
jfieldID  field 
) throw (JavaException)

Get the value of a char field in an Object.

Parameters:
object The object.
field The field ID.
Returns:
The value of the field.
Exceptions:
JavaException If an error occurs.

jclass getClassForObject ( jobject  object  ) 

Get the class for a Java object.

Parameters:
object The object.
Returns:
The class.

void * getDirectBufferRegion ( jobject  buf,
uint64_t &  size 
)

Get a pointer to and the size of the memory region occupied by a Java DirectBuffer.

Parameters:
buf The DirectBuffer object.
size The variable in which to store the size of the memory region.
Returns:
A pointer to the beginning of the memory region, or NULL on failure.

jdouble getDoubleField ( jobject  object,
jfieldID  field 
) throw (JavaException)

Get the value of a double field in an Object.

Parameters:
object The object.
field The field ID.
Returns:
The value of the field.
Exceptions:
JavaException If an error occurs.

jthrowable getException (  )  throw ()

Get the pending Java exception, if one is currently being thrown in the current thread.

Returns:
The exception object, or NULL if none.

jfloat getFloatField ( jobject  object,
jfieldID  field 
) throw (JavaException)

Get the value of a float field in an Object.

Parameters:
object The object.
field The field ID.
Returns:
The value of the field.
Exceptions:
JavaException If an error occurs.

jint getIntField ( jobject  object,
jfieldID  field 
) throw (JavaException)

Get the value of an int field in an Object.

Parameters:
object The object.
field The field ID.
Returns:
The value of the field.
Exceptions:
JavaException If an error occurs.

jlong getLongField ( jobject  object,
jfieldID  field 
) throw (JavaException)

Get the value of a long field in an Object.

Parameters:
object The object.
field The field ID.
Returns:
The value of the field.
Exceptions:
JavaException If an error occurs.

jobject getObjectArrayElement ( jobjectArray  array,
uint_t  index 
) throw (JavaException)

Get an element of a Java object array.

Parameters:
array The array.
index The index of the element.
Returns:
The value of the element.
Exceptions:
JavaException If an error occurs.

jobject getObjectField ( jobject  object,
jfieldID  field 
) throw (JavaException)

Get the value of an Object field in an Object.

Parameters:
object The object.
field The field ID.
Returns:
The value of the field.
Exceptions:
JavaException If an error occurs.

jshort getShortField ( jobject  object,
jfieldID  field 
) throw (JavaException)

Get the value of a short field in an Object.

Parameters:
object The object.
field The field ID.
Returns:
The value of the field.
Exceptions:
JavaException If an error occurs.

jboolean getStaticBooleanField ( jclass  clazz,
jfieldID  field 
) throw (JavaException)

Get the value of a static boolean field in a class.

Parameters:
clazz The class.
field The field ID.
Returns:
The value of the field.
Exceptions:
JavaException If an error occurs.

jbyte getStaticByteField ( jclass  clazz,
jfieldID  field 
) throw (JavaException)

Get the value of a static byte field in a class.

Parameters:
clazz The class.
field The field ID.
Returns:
The value of the field.
Exceptions:
JavaException If an error occurs.

jchar getStaticCharField ( jclass  clazz,
jfieldID  field 
) throw (JavaException)

Get the value of a static char field in a class.

Parameters:
clazz The class.
field The field ID.
Returns:
The value of the field.
Exceptions:
JavaException If an error occurs.

jdouble getStaticDoubleField ( jclass  clazz,
jfieldID  field 
) throw (JavaException)

Get the value of a static double field in a class.

Parameters:
clazz The class.
field The field ID.
Returns:
The value of the field.
Exceptions:
JavaException If an error occurs.

jfloat getStaticFloatField ( jclass  clazz,
jfieldID  field 
) throw (JavaException)

Get the value of a static float field in a class.

Parameters:
clazz The class.
field The field ID.
Returns:
The value of the field.
Exceptions:
JavaException If an error occurs.

jint getStaticIntField ( jclass  clazz,
jfieldID  field 
) throw (JavaException)

Get the value of a static int field in a class.

Parameters:
clazz The class.
field The field ID.
Returns:
The value of the field.
Exceptions:
JavaException If an error occurs.

jlong getStaticLongField ( jclass  clazz,
jfieldID  field 
) throw (JavaException)

Get the value of a static long field in a class.

Parameters:
clazz The class.
field The field ID.
Returns:
The value of the field.
Exceptions:
JavaException If an error occurs.

jobject getStaticObjectField ( jclass  clazz,
jfieldID  field 
) throw (JavaException)

Get the value of a static Object field in a class.

Parameters:
clazz The class.
field The field ID.
Returns:
The value of the field.
Exceptions:
JavaException If an error occurs.

jshort getStaticShortField ( jclass  clazz,
jfieldID  field 
) throw (JavaException)

Get the value of a static short field in a class.

Parameters:
clazz The class.
field The field ID.
Returns:
The value of the field.
Exceptions:
JavaException If an error occurs.

String getStaticStringField ( jclass  clazz,
jfieldID  field 
) throw (JavaException)

Get the value of a static String field in a class.

Parameters:
clazz The class.
field The field ID.
Returns:
The value of the field as a String.
Exceptions:
JavaException If an error occurs.

WString getStaticWStringField ( jclass  clazz,
jfieldID  field 
) throw (JavaException)

Get the value of a static String field in a class.

Parameters:
clazz The class.
field The field ID.
Returns:
The value of the field as a WString.
Exceptions:
JavaException If an error occurs.

String getStringField ( jobject  object,
jfieldID  field 
) throw (JavaException)

Get the value of a java.lang.String field in an Object.

Parameters:
object The object.
field The field ID.
Returns:
The value of the field, encoded as a String.
Exceptions:
JavaException If an error occurs.

size_t getStringLength ( jstring  str  ) 

Get the length of a Java string.

Parameters:
str The string.
Returns:
The length of the string.

jclass getSuperclass ( jclass  clazz  ) 

Get the superclass for a Java class.

Parameters:
clazz The class.
Returns:
The superclass, or NULL if the class is an interface or if it is java.lang.Object.

WString getWStringField ( jobject  object,
jfieldID  field 
) throw (JavaException)

Get the value of a java.lang.String field in an Object.

Parameters:
object The object.
field The field ID.
Returns:
The value of the field, encoded as a WString.
Exceptions:
JavaException If an error occurs.

bool isAssignableFrom ( jclass  clazz1,
jclass  clazz2 
)

Test if an object of a class or interface can be safely cast to a class or interface of another class.

Parameters:
clazz1 The class of the object to be cast.
clazz2 The class of the cast.
Returns:
true if the cast is valid, false otherwise.

bool isInstanceOf ( jobject  object,
jclass  clazz 
)

Test if a Java object is an instance of an interface or another class.

Parameters:
object The object.
clazz The class or interface.
Returns:
true if the object is an instance of the other class or interface, false otherwise.

bool isSameObject ( jobject  object1,
jobject  object2 
)

Test two Java object references for equality.

Parameters:
object1 The first object reference.
object2 The second object reference.
Returns:
true if the references both refer to the same object, false otherwise.

bool isVerbose (  )  const throw () [inline]

Determine if verbose mode is enabled for this context.

bool parseSignature ( const String signature,
String method,
String descriptor,
bool &  isStatic 
) [static]

Parse a method signature into a method name, a JNI method descriptor, and a static flag.

For example, "static int foo(int, char[])" results in a method name of "foo", a JNI method descriptor of "(I[C)I", and a static flag of true.

Parameters:
signature The signature to parse.
method The string in which to place the method name.
descriptor The string in which to place the JNI method descriptor.
isStatic The flag in which to store the static flag (true if a "static" qualifier is present, false otherwise).
Returns:
true if the signature was parsed successfully, false otherwise.

void popLocalFrame (  ) 

Destroy the topmost local reference frame.

All local references created in the frame will be freed.

void pushLocalFrame ( uint_t  capacity = 8  )  throw (JavaException)

Create a new local reference frame.

Parameters:
capacity The minimal local reference capacity of the new frame.
Exceptions:
JavaException If an error occurs.

void registerNativeMethods ( jclass  clazz,
const JavaNativeMethod  methods[] 
) throw (JavaException)

Register native methods for a Java class.

Parameters:
clazz The class.
methods An array of native methods to register. The last element in the array must have the function field set to NULL.
Exceptions:
JavaException If an error occurs.

void releaseArrayData ( jarray  array,
void *  data 
)

Release the buffer returned by getArrayData().

The data will be copied back into the original array, if necessary.

Parameters:
array The primitive array.
data The buffer containing the array data.

void setBooleanField ( jobject  object,
jfieldID  field,
jboolean  value 
) throw (JavaException)

Set the value of a boolean field in an object.

Parameters:
object The object.
field The field ID.
value The new value for the field.
Exceptions:
JavaException If an error occurs.

void setByteField ( jobject  object,
jfieldID  field,
jbyte  value 
) throw (JavaException)

Set the value of a byte field in an object.

Parameters:
object The object.
field The field ID.
value The new value for the field.
Exceptions:
JavaException If an error occurs.

void setCharField ( jobject  object,
jfieldID  field,
jchar  value 
) throw (JavaException)

Set the value of a char field in an object.

Parameters:
object The object.
field The field ID.
value The new value for the field.
Exceptions:
JavaException If an error occurs.

void setDoubleField ( jobject  object,
jfieldID  field,
jdouble  value 
) throw (JavaException)

Set the value of a double field in an object.

Parameters:
object The object.
field The field ID.
value The new value for the field.
Exceptions:
JavaException If an error occurs.

void setFloatField ( jobject  object,
jfieldID  field,
jfloat  value 
) throw (JavaException)

Set the value of a float field in an object.

Parameters:
object The object.
field The field ID.
value The new value for the field.
Exceptions:
JavaException If an error occurs.

void setIntField ( jobject  object,
jfieldID  field,
jint  value 
) throw (JavaException)

Set the value of an int field in an object.

Parameters:
object The object.
field The field ID.
value The new value for the field.
Exceptions:
JavaException If an error occurs.

void setLongField ( jobject  object,
jfieldID  field,
jlong  value 
) throw (JavaException)

Set the value of a long field in an object.

Parameters:
object The object.
field The field ID.
value The new value for the field.
Exceptions:
JavaException If an error occurs.

void setObjectArrayElement ( jobjectArray  array,
uint_t  index,
jobject  value 
) throw (JavaException)

Set an element of a Java object array.

Parameters:
array The array.
index The index of the element.
value The new value for the element.
Exceptions:
JavaException If an error occurs.

void setObjectField ( jobject  object,
jfieldID  field,
jobject  value 
) throw (JavaException)

Set the value of an Object field in an object.

Parameters:
object The object.
field The field ID.
value The new value for the field.
Exceptions:
JavaException If an error occurs.

void setShortField ( jobject  object,
jfieldID  field,
jshort  value 
) throw (JavaException)

Set the value of a short field in an object.

Parameters:
object The object.
field The field ID.
value The new value for the field.
Exceptions:
JavaException If an error occurs.

void setStaticBooleanField ( jclass  clazz,
jfieldID  field,
jboolean  value 
) throw (JavaException)

Set the value of a static boolean field in a class.

Parameters:
clazz The class.
field The field ID.
value The new value for the field.
Exceptions:
JavaException If an error occurs.

void setStaticByteField ( jclass  clazz,
jfieldID  field,
jbyte  value 
) throw (JavaException)

Set the value of a static byte field in a class.

Parameters:
clazz The class.
field The field ID.
value The new value for the field.
Exceptions:
JavaException If an error occurs.

void setStaticCharField ( jclass  clazz,
jfieldID  field,
jchar  value 
) throw (JavaException)

Set the value of a static char field in a class.

Parameters:
clazz The class.
field The field ID.
value The new value for the field.
Exceptions:
JavaException If an error occurs.

void setStaticDoubleField ( jclass  clazz,
jfieldID  field,
jdouble  value 
) throw (JavaException)

Set the value of a static double field in a class.

Parameters:
clazz The class.
field The field ID.
value The new value for the field.
Exceptions:
JavaException If an error occurs.

void setStaticFloatField ( jclass  clazz,
jfieldID  field,
jfloat  value 
) throw (JavaException)

Set the value of a static float field in a class.

Parameters:
clazz The class.
field The field ID.
value The new value for the field.
Exceptions:
JavaException If an error occurs.

void setStaticIntField ( jclass  clazz,
jfieldID  field,
jint  value 
) throw (JavaException)

Set the value of a static int field in a class.

Parameters:
clazz The class.
field The field ID.
value The new value for the field.
Exceptions:
JavaException If an error occurs.

void setStaticLongField ( jclass  clazz,
jfieldID  field,
jlong  value 
) throw (JavaException)

Set the value of a static long field in a class.

Parameters:
clazz The class.
field The field ID.
value The new value for the field.
Exceptions:
JavaException If an error occurs.

void setStaticObjectField ( jclass  clazz,
jfieldID  field,
jobject  value 
) throw (JavaException)

Set the value of a static Object field in a class.

Parameters:
clazz The class.
field The field ID.
value The new value for the field.
Exceptions:
JavaException If an error occurs.

void setStaticShortField ( jclass  clazz,
jfieldID  field,
jshort  value 
) throw (JavaException)

Set the value of a static short field in a class.

Parameters:
clazz The class.
field The field ID.
value The new value for the field.
Exceptions:
JavaException If an error occurs.

void setStringField ( jobject  object,
jfieldID  field,
const String value 
) throw (JavaException)

Set the value of a java.lang.String field in an object.

Parameters:
object The object.
field The field ID.
value The new value for the field.
Exceptions:
JavaException If an error occurs.

void setWStringField ( jobject  object,
jfieldID  field,
const WString value 
) throw (JavaException)

Set the value of a java.lang.String field in an object.

Parameters:
object The object.
field The field ID.
value The new value for the field.
Exceptions:
JavaException If an error occurs.

bool throwException ( jclass  exception,
const String message 
)

Throw a Java exception.

Parameters:
exception The class of the exception.
message The exception message.
Returns:
true on success, false otherwise.

void unregisterNativeMethods ( jclass  clazz  ) 

Unregister all native methods for a Java class.

Parameters:
clazz The class.


Friends And Related Function Documentation

friend class JavaVirtualMachine [friend]


The documentation for this class was generated from the following files:

Generated on Sat Apr 17 23:03:09 2010 for libcommonc++ by  doxygen 1.5.9