#include <JavaVoidMethodCaller.h>
Public Member Functions | |
JavaVoidMethodCaller (JNIEnv *env, jclass java_class, jobject java_object, bool swallow_java_exceptions=true) | |
Create method caller. | |
~JavaVoidMethodCaller (void) | |
Destructor. | |
bool | Call (const char *method_name, const char *method_signature) |
Call method without parameters. | |
template<typename T1> | |
bool | Call (const char *method_name, const char *method_signature, T1 param_1) |
Call method with one parameter of primitive type. | |
template<typename T1, typename T2> | |
bool | Call (const char *method_name, const char *method_signature, T1 param_1, T2 param_2) |
Call method with two parameters of primitive types. | |
template<typename T1> | |
bool | Call (const char *method_name, const char *method_signature, const std::vector< T1 > ¶m_1) |
Call method with one parameter of array of primitive type. | |
template<typename T1, typename T2> | |
bool | Call (const char *method_name, const char *method_signature, const std::vector< T1 > ¶m_1, const std::vector< T2 > ¶m_2) |
Call method with two parameters of arrays of primitive types. | |
bool | GetSwallowExceptions (void) |
Get flag for exception swallowing. | |
bool | SetSwallowException (bool se) |
Set flag for exception swallowing. | |
template<> | |
bool | Call (const char *method_name, const char *method_signature, String param_1) |
Call method with one string parameter. | |
template<> | |
bool | Call (const char *method_name, const char *method_signature, const std::vector< String > ¶m_1) |
Call method with one parameter that is array of strings. | |
Private Member Functions | |
typedef | CREATE_TYPE_LIST_09 (void, jboolean, jbyte, jchar, jshort, jint, jlong, jfloat, jdouble) JavaTypes |
Typelist which contains all basic Java types. | |
typedef | CREATE_TYPE_LIST_09 (void, jbooleanArray, jbyteArray, jcharArray, jshortArray, jintArray, jlongArray, jfloatArray, jdoubleArray) JavaArrayTypes |
Typelist which contains all primitive array Java types. | |
typedef | CREATE_TYPE_LIST_09 (void, ArrayMethodAdapter_Boolean, ArrayMethodAdapter_Byte, ArrayMethodAdapter_Char, ArrayMethodAdapter_Short, ArrayMethodAdapter_Int, ArrayMethodAdapter_Long, ArrayMethodAdapter_Float, ArrayMethodAdapter_Double) ArrayMethodAdapters |
Adapter class for boolean array methods. Adapter class for byte array methods. Adapter class for char array methods. Adapter class for short array methods. Adapter class for int array methods. Adapter class for long array methods. Adapter class for float array methods. Adapter class for double array methods. Typelist which contains all adapters for different types of arrays. | |
Private Attributes | |
JNIEnv * | jni_env |
Java environment. | |
jclass | target_class |
Type of the object on which methods will be called. | |
jobject | object |
Instance of the Java object on which methods will be called. | |
bool | swallow_exceptions |
Flag which specifies if exception state is cleared after call that throws. | |
Data Structures | |
class | ArrayMethodAdapter_String |
Adapter class for string arrays in Java. More... |
This class provides methods to call Java methods on some object with various types of parameters. Parameters of primitive types, strings and arrays of primitive types and strings are supported. Note that not all of the combinations are supported, but they can be easily added. Currently, methods with following signatures are supported:
lm::JavaVoidMethodCaller::JavaVoidMethodCaller | ( | JNIEnv * | env, | |
jclass | java_class, | |||
jobject | java_object, | |||
bool | swallow_java_exceptions = true | |||
) | [inline] |
Create method caller.
env | Java environment from which library has been initialized. | |
java_class | Java class from which methods will be called. | |
java_object | Instance of the java_class on which methods will be called. | |
swallow_java_exceptions | If set to true, exception state will be cleared after each method call. If set to false, exception state will not be cleared. |
lm::JavaVoidMethodCaller::~JavaVoidMethodCaller | ( | void | ) | [inline] |
Destructor.
bool lm::JavaVoidMethodCaller::Call | ( | const char * | method_name, | |
const char * | method_signature, | |||
const std::vector< String > & | param_1 | |||
) |
Call method with one parameter that is array of strings.
This is specialization of the Call function template for methods with one array parameter. This method works only with Unicode strings. Strings are automatically translated to the Java-compatible jstring objects.
method_name | Name of the method to call. Name is case-sensitive. | |
method_signature | Signature string of the method to call (as reported by the javap -s ). | |
param_1 | std::pair object which describes array of strings. First element of the pair contains elements of the array (that is, std::wstring * ). Second element of the pair contains length of the array (number of strings in array). |
bool lm::JavaVoidMethodCaller::Call | ( | const char * | method_name, | |
const char * | method_signature, | |||
String | param_1 | |||
) |
Call method with one string parameter.
This is specialization of the Call function template for methods which take only one argument - Unicode string. String is automatically translated to the Java-compatible jstring object and that object is passed to the method as its only parameter.
method_name | Name of the method to call. Name is case-sensitive. | |
method_signature | Signature string of the method (as reported by the javap -s ). | |
param_1 | String that will be passed as the only argument. |
bool lm::JavaVoidMethodCaller::Call | ( | const char * | method_name, | |
const char * | method_signature, | |||
const std::vector< T1 > & | param_1, | |||
const std::vector< T2 > & | param_2 | |||
) | [inline] |
Call method with two parameters of arrays of primitive types.
method_name | Name of the method to call. Name is case-sensitive. | |
method_signature | Signature string of the method (can be generated for example via javap -s ). | |
param_1 | std::vector which contains elements of the first array. Elements can be one of the following types: jboolean, jchar, jbyte, jint, jshort, jlong, jfloat, jdouble. If the type of array's elements is invalid, error is reported via COMPILE_TIME_CHECK macro. | |
param_2 | std::vector which contains elements of the second array. Elements can be one of the following types: jboolean, jchar, jbyte, jint, jshort, jlong, jfloat, jdouble. If the type of array's elements is invalid, error is reported via COMPILE_TIME_CHECK macro. |
bool lm::JavaVoidMethodCaller::Call | ( | const char * | method_name, | |
const char * | method_signature, | |||
const std::vector< T1 > & | param_1 | |||
) | [inline] |
Call method with one parameter of array of primitive type.
method_name | Name of the method to call. Name is case-sensitive. | |
method_signature | Signature string of the method (can be generated for example via javap -s ). | |
param_1 | std::vector which contains elements of the array. Elements can be one of the following types: jboolean, jchar, jbyte, jint, jshort, jlong, jfloat, jdouble. Separate specialization exists for string arrays. If the type of array's elements is invalid, error is reported via COMPILE_TIME_CHECK macro. |
bool lm::JavaVoidMethodCaller::Call | ( | const char * | method_name, | |
const char * | method_signature, | |||
T1 | param_1, | |||
T2 | param_2 | |||
) | [inline] |
Call method with two parameters of primitive types.
method_name | Name of the method to call. Name is case-sensitive. | |
method_signature | Signature string of the method (can be generated for example via javap -s ). | |
param_1 | First parameter that will be passed to the Java method. Parameter type can be one of jboolean, jchar, jbyte, jint, jshort, jlong, jfloat, jdouble. If type is incorrect, error is reported during compilation via COMPILE_TIME_CHECK macro. | |
param_2 | Second parameter that will be passed to the Java method. Parameter type can be one of jboolean, jchar, jbyte, jint, jshort, jlong, jfloat, jdouble. If type is incorrect, error is reported during compilation via COMPILE_TIME_CHECK macro. |
bool lm::JavaVoidMethodCaller::Call | ( | const char * | method_name, | |
const char * | method_signature, | |||
T1 | param_1 | |||
) | [inline] |
Call method with one parameter of primitive type.
method_name | Name of the method to call. Name is case-sensitive. | |
method_signature | Signature string of the method (can be generated for example via javap -s ). | |
param_1 | Parameter that will be passed to the Java method. Type of this parameter can be one of jchar, jbyte, jint, jshort, jlong, jfloat, jdouble, jboolean. If type is invalid, error is reported during compilation via COMPILE_TIME_CHECK macro. |
bool lm::JavaVoidMethodCaller::Call | ( | const char * | method_name, | |
const char * | method_signature | |||
) | [inline] |
Call method without parameters.
method_name | Name of the method to call. Name is case-sensitive. | |
method_signature | Signature string of the method (can be generated for example via javap -s ). |
typedef lm::JavaVoidMethodCaller::CREATE_TYPE_LIST_09 | ( | void | , | |
ArrayMethodAdapter_Boolean | , | |||
ArrayMethodAdapter_Byte | , | |||
ArrayMethodAdapter_Char | , | |||
ArrayMethodAdapter_Short | , | |||
ArrayMethodAdapter_Int | , | |||
ArrayMethodAdapter_Long | , | |||
ArrayMethodAdapter_Float | , | |||
ArrayMethodAdapter_Double | ||||
) | [private] |
Adapter class for boolean array methods. Adapter class for byte array methods. Adapter class for char array methods. Adapter class for short array methods. Adapter class for int array methods. Adapter class for long array methods. Adapter class for float array methods. Adapter class for double array methods. Typelist which contains all adapters for different types of arrays.
This typelist is used when new template instantiation of the array Call method is being created. During instantiation of the Call method correct adapter is selected based on the types of the parameters.
typedef lm::JavaVoidMethodCaller::CREATE_TYPE_LIST_09 | ( | void | , | |
jbooleanArray | , | |||
jbyteArray | , | |||
jcharArray | , | |||
jshortArray | , | |||
jintArray | , | |||
jlongArray | , | |||
jfloatArray | , | |||
jdoubleArray | ||||
) | [private] |
Typelist which contains all primitive array Java types.
This list is used when selecting correct return type in ArrayMethodAdapter_### classes.
typedef lm::JavaVoidMethodCaller::CREATE_TYPE_LIST_09 | ( | void | , | |
jboolean | , | |||
jbyte | , | |||
jchar | , | |||
jshort | , | |||
jint | , | |||
jlong | , | |||
jfloat | , | |||
jdouble | ||||
) | [private] |
Typelist which contains all basic Java types.
This list is used in all Call methods to verify types of the arguments in compilation-time.
bool lm::JavaVoidMethodCaller::GetSwallowExceptions | ( | void | ) | [inline] |
Get flag for exception swallowing.
bool lm::JavaVoidMethodCaller::SetSwallowException | ( | bool | se | ) | [inline] |
Set flag for exception swallowing.
se | New value of the flag. If this is set to true, exception state of the JVM is cleared if exception has been thrown during method call. |
JNIEnv* lm::JavaVoidMethodCaller::jni_env [private] |
Java environment.
jobject lm::JavaVoidMethodCaller::object [private] |
Instance of the Java object on which methods will be called.
bool lm::JavaVoidMethodCaller::swallow_exceptions [private] |
Flag which specifies if exception state is cleared after call that throws.
jclass lm::JavaVoidMethodCaller::target_class [private] |
Type of the object on which methods will be called.