(
jni_env: *mut JNIEnv,
key_class_name: &str,
value_class_name: &str,
inv_args: &[InvocationArg],
)
| 745 | } |
| 746 | |
| 747 | fn do_create_java_map( |
| 748 | jni_env: *mut JNIEnv, |
| 749 | key_class_name: &str, |
| 750 | value_class_name: &str, |
| 751 | inv_args: &[InvocationArg], |
| 752 | ) -> errors::Result<Instance> { |
| 753 | debug(&format!( |
| 754 | "Creating a java map with keys of class {} and values of class {} with {} elements", |
| 755 | key_class_name, |
| 756 | value_class_name, |
| 757 | inv_args.len() / 2 |
| 758 | )); |
| 759 | unsafe { |
| 760 | // Factory invocation - first argument: create a jstring to pass as argument for the key_class_name |
| 761 | let key_class_name_jstring: jstring = |
| 762 | jni_utils::global_jobject_from_str(key_class_name, jni_env)?; |
| 763 | // Factory invocation - second argument: create a jstring to pass as argument for the value_class_name |
| 764 | let value_class_name_jstring: jstring = |
| 765 | jni_utils::global_jobject_from_str(value_class_name, jni_env)?; |
| 766 | |
| 767 | // Factory invocation - rest of the arguments: Create a new object list of class InvocationArg |
| 768 | let size = inv_args.len() as i32; |
| 769 | let array_ptr = { |
| 770 | let j = (opt_to_res(cache::get_jni_new_object_array())?)( |
| 771 | jni_env, |
| 772 | size, |
| 773 | cache::get_invocation_arg_class()?, |
| 774 | ptr::null_mut(), |
| 775 | ); |
| 776 | jni_utils::create_global_ref_from_local_ref(j, jni_env)? |
| 777 | }; |
| 778 | let mut inv_arg_jobjects: Vec<jobject> = Vec::with_capacity(size as usize); |
| 779 | |
| 780 | // Factory invocation - rest of the arguments: populate the array |
| 781 | for i in 0..size { |
| 782 | // Create an InvocationArg Java Object |
| 783 | let inv_arg_java = inv_args[i as usize].as_java_ptr_with_global_ref(jni_env)?; |
| 784 | // Set it in the array |
| 785 | (opt_to_res(cache::get_jni_set_object_array_element())?)( |
| 786 | jni_env, |
| 787 | array_ptr, |
| 788 | i, |
| 789 | inv_arg_java, |
| 790 | ); |
| 791 | inv_arg_jobjects.push(inv_arg_java); |
| 792 | } |
| 793 | // Call the method of the factory that instantiates a new Java Map with keys of `key_class_name` |
| 794 | // and values of `value_class_name`. |
| 795 | // This returns a Instance that acts like a proxy to the Java world. |
| 796 | let java_instance = (opt_to_res(cache::get_jni_call_static_object_method())?)( |
| 797 | jni_env, |
| 798 | cache::get_factory_class()?, |
| 799 | cache::get_factory_create_java_map_method()?, |
| 800 | key_class_name_jstring, |
| 801 | value_class_name_jstring, |
| 802 | array_ptr, |
| 803 | ); |
| 804 |
nothing calls this directly
no test coverage detected