23 #if !defined (octave_ov_java_h)
24 #define octave_ov_java_h 1
53 operator T () {
return jobj; }
93 box (JNIEnv* jni_env, jobject jobj, jclass jcls = 0);
96 box_more (JNIEnv* jni_env, jobject jobj, jclass jcls = 0);
134 jobject
to_java (
void)
const {
return java_object; }
135 jclass
to_class (
void)
const {
return java_class; }
144 bool is_map (
void)
const {
return false; }
152 void print (std::ostream& os,
bool pr_as_read_syntax =
false)
const;
154 void print_raw (std::ostream& os,
bool pr_as_read_syntax =
false)
const;
158 const std::list<octave_value_list>& idx,
int nargout);
161 subsref (
const std::string&
type,
const std::list<octave_value_list>& idx)
168 const std::list<octave_value_list>& idx,
173 bool is_java_string (
void)
const;
175 static JNIEnv* thread_jni_env (
void);
177 octave_value do_javaMethod (JNIEnv* jni_env,
const std::string& name,
183 return do_javaMethod(thread_jni_env (), name, args);
187 do_javaMethod (JNIEnv* jni_env,
const std::string& class_name,
191 do_javaMethod (
const std::string& class_name,
const std::string& name,
194 return do_javaMethod(thread_jni_env (), class_name, name, args);
198 do_javaObject (JNIEnv* jni_env,
const std::string& name,
204 return do_javaObject (thread_jni_env (), name, args);
207 octave_value do_java_get (JNIEnv* jni_env,
const std::string& name);
211 return do_java_get (thread_jni_env (), name);
215 do_java_get (JNIEnv* jni_env,
const std::string& class_name,
216 const std::string& name);
219 do_java_get (
const std::string& class_name,
const std::string& name)
221 return do_java_get (thread_jni_env (), class_name, name);
224 octave_value do_java_set (JNIEnv* jni_env,
const std::string& name,
229 return do_java_set (thread_jni_env (), name, val);
233 do_java_set (JNIEnv* jni_env,
const std::string& class_name,
237 do_java_set (
const std::string& class_name,
const std::string& name,
240 return do_java_set (thread_jni_env (), class_name, name, val);
245 void init (jobject jobj, jclass jcls)
247 JNIEnv *current_env = thread_jni_env ();
252 java_object = current_env->NewGlobalRef (jobj);
255 java_class =
reinterpret_cast<jclass
> (current_env->NewGlobalRef (jcls));
256 else if (java_object)
258 jclass_ref ocls (current_env, current_env->GetObjectClass (java_object));
259 java_class =
reinterpret_cast<jclass
> (current_env->NewGlobalRef (jclass (ocls)));
264 jclass_ref clsCls (current_env, current_env->GetObjectClass (java_class));
265 jmethodID mID = current_env->GetMethodID (clsCls,
"getCanonicalName",
"()Ljava/lang/String;");
266 jobject_ref resObj (current_env, current_env->CallObjectMethod (java_class, mID));
274 JNIEnv *current_env = thread_jni_env ();
279 current_env->DeleteGlobalRef (java_object);
282 current_env->DeleteGlobalRef (java_class);
302 std::string
class_name (
void)
const {
return java_classname; }