annotate libinterp/octave-value/ov-java.cc @ 21733:cb0fdd941d84

use namespace for system file_ops class * file-ops.h, file-ops.cc: Put file_ops class and related functions in octave::sys:: namespace. Change all uses.
author John W. Eaton <jwe@octave.org>
date Thu, 19 May 2016 00:33:18 -0400
parents 6a1eded90355
children 0504351a45e6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15746
da26f72408a7 update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents: 15745
diff changeset
1 /*
da26f72408a7 update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents: 15745
diff changeset
2
17744
d63878346099 maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents: 17281
diff changeset
3 Copyright (C) 2007, 2013 Michael Goffioul
15746
da26f72408a7 update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents: 15745
diff changeset
4
da26f72408a7 update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents: 15745
diff changeset
5 This file is part of Octave.
da26f72408a7 update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents: 15745
diff changeset
6
da26f72408a7 update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents: 15745
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
da26f72408a7 update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents: 15745
diff changeset
8 under the terms of the GNU General Public License as published by the
da26f72408a7 update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents: 15745
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
da26f72408a7 update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents: 15745
diff changeset
10 option) any later version.
da26f72408a7 update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents: 15745
diff changeset
11
da26f72408a7 update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents: 15745
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
da26f72408a7 update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents: 15745
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
da26f72408a7 update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents: 15745
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
da26f72408a7 update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents: 15745
diff changeset
15 for more details.
da26f72408a7 update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents: 15745
diff changeset
16
da26f72408a7 update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents: 15745
diff changeset
17 You should have received a copy of the GNU General Public License
da26f72408a7 update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents: 15745
diff changeset
18 along with Octave; see the file COPYING. If not, see
da26f72408a7 update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents: 15745
diff changeset
19 <http://www.gnu.org/licenses/>.
da26f72408a7 update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents: 15745
diff changeset
20
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21 */
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21691
diff changeset
23 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21211
diff changeset
24 # include "config.h"
15736
6faa01ff2967 build: Add --disable-java option to configure (bug #37838).
Rik <rik@octave.org>
parents: 15625
diff changeset
25 #endif
6faa01ff2967 build: Add --disable-java option to configure (bug #37838).
Rik <rik@octave.org>
parents: 15625
diff changeset
26
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
27 #include "defun.h"
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
28 #include "error.h"
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
29 #include "errwarn.h"
16078
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
30 #include "fpucw.h"
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
31
21211
2cf8bc5c7017 use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
32 #if defined (HAVE_FPU_CONTROL_H)
21200
fcac5dbbf9ed maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents: 21042
diff changeset
33 # include <fpu_control.h>
16078
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
34 #endif
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
35
15755
3216dafbbd48 ov-java.cc: Correcty typo HAVE_WINDWOS_H to HAVE_WINDOWS_H
Rik <rik@octave.org>
parents: 15754
diff changeset
36 #if defined (HAVE_WINDOWS_H)
21200
fcac5dbbf9ed maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents: 21042
diff changeset
37 # include <windows.h>
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38 #endif
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40 #include <algorithm>
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 #include <map>
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 #include <iostream>
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43 #include <fstream>
20028
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
44 #include <string>
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46 #include <clocale>
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
48 #include "Cell.h"
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
49 #include "cmd-edit.h"
15752
f96faf028d90 make java functions part of core octave_value classes
John W. Eaton <jwe@octave.org>
parents: 15747
diff changeset
50 #include "defaults.h"
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
51 #include "file-ops.h"
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
52 #include "file-stat.h"
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
53 #include "load-path.h"
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
54 #include "oct-env.h"
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
55 #include "oct-shlib.h"
15752
f96faf028d90 make java functions part of core octave_value classes
John W. Eaton <jwe@octave.org>
parents: 15747
diff changeset
56 #include "ov-java.h"
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
57 #include "parse.h"
15747
4be890c5527c * __java__.cc, __java__.h: Clean up lists of include files.
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
58 #include "variables.h"
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
59
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
60 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
61 #include <jni.h>
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
62 #endif
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
63
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
64 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
65
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
66 #define TO_JOBJECT(obj) reinterpret_cast<jobject> (obj)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
67 #define TO_JCLASS(obj) reinterpret_cast<jclass> (obj)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
68
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
69 #define TO_JNIENV(env) reinterpret_cast<JNIEnv *> (env)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
70
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19598
diff changeset
71 typedef jint (JNICALL *JNI_CreateJavaVM_t) (JavaVM **pvm, JNIEnv **penv,
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19598
diff changeset
72 void *args);
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
73
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19598
diff changeset
74 typedef jint (JNICALL *JNI_GetCreatedJavaVMs_t) (JavaVM **pvm, jsize bufLen,
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19598
diff changeset
75 jsize *nVMs);
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
77 template <typename T>
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
78 class java_local_ref
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
79 {
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
80 public:
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
81
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
82 java_local_ref (JNIEnv *_env)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
83 : jobj (0), detached (false), env (_env) { }
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
84
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
85 java_local_ref (JNIEnv *_env, T obj)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
86 : jobj (obj), detached (false), env (_env) { }
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
87
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
88 ~java_local_ref (void) { release (); }
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
89
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
90 T& operator = (T obj)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
91 {
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
92 release ();
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
93
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
94 jobj = obj;
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
95 detached = false;
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
96
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
97 return jobj;
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
98 }
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
99
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
100 operator bool () const { return (jobj != 0); }
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
101 operator T () { return jobj; }
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
102
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
103 void detach (void) { detached = true; }
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
104
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
105 private:
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
106
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
107 void release (void)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
108 {
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
109 if (env && jobj && ! detached)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
110 env->DeleteLocalRef (jobj);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
111
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
112 jobj = 0;
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
113 }
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
114
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
115 java_local_ref (void)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
116 : jobj (0), detached (false), env (0)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
117 { }
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
118
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
119 protected:
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
120
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
121 T jobj;
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
122 bool detached;
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
123 JNIEnv *env;
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
124 };
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
125
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
126 typedef java_local_ref<jobject> jobject_ref;
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
127 typedef java_local_ref<jclass> jclass_ref;
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
128 typedef java_local_ref<jstring> jstring_ref;
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
129 typedef java_local_ref<jobjectArray> jobjectArray_ref;
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
130 typedef java_local_ref<jintArray> jintArray_ref;
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
131 typedef java_local_ref<jbyteArray> jbyteArray_ref;
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
132 typedef java_local_ref<jdoubleArray> jdoubleArray_ref;
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
133 typedef java_local_ref<jthrowable> jthrowable_ref;
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
134
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
135 static std::string
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
136 jstring_to_string (JNIEnv* jni_env, jstring s);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
137
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
138 static std::string
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
139 jstring_to_string (JNIEnv* jni_env, jobject obj);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
140
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
141 static octave_value
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
142 box (JNIEnv* jni_env, void *jobj, void *jcls_arg = 0);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
143
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
144 static octave_value
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
145 box_more (JNIEnv* jni_env, void *jobj_arg, void *jcls_arg = 0);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
146
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
147 static bool
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
148 unbox (JNIEnv* jni_env, const octave_value& val, jobject_ref& jobj,
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
149 jclass_ref& jcls);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
150
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
151 static bool
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
152 unbox (JNIEnv* jni_env, const octave_value_list& args,
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
153 jobjectArray_ref& jobjs, jobjectArray_ref& jclss);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
154
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
155 extern "C"
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
156 {
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
157 JNIEXPORT jboolean JNICALL
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
158 Java_org_octave_Octave_call (JNIEnv *, jclass, jstring, jobjectArray,
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
159 jobjectArray);
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
160
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
161 JNIEXPORT void JNICALL
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
162 Java_org_octave_OctaveReference_doFinalize (JNIEnv *, jclass, jint);
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
163
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
164 JNIEXPORT void JNICALL
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
165 Java_org_octave_Octave_doInvoke (JNIEnv *, jclass, jint, jobjectArray);
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
166
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
167 JNIEXPORT void JNICALL
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
168 Java_org_octave_Octave_doEvalString (JNIEnv *, jclass, jstring);
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
169
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
170 JNIEXPORT jboolean JNICALL
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
171 Java_org_octave_Octave_needThreadedInvokation (JNIEnv *, jclass);
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
172 }
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
173
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
174 static JavaVM *jvm = 0;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
175 static bool jvm_attached = false;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
176
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
177 // Need to keep hold of the shared library handle until exit.
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
178 static octave_shlib jvm_lib;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
179
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
180 static std::map<int,octave_value> listener_map;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
181 static std::map<int,octave_value> octave_ref_map;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
182 static int octave_java_refcount = 0;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
183 static long octave_thread_ID = -1;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
184
15800
d9b8333df5e4 Deprecate java_debug, java_convert_matrix, java_unsigned_conversion.
Rik <rik@octave.org>
parents: 15798
diff changeset
185 bool Vjava_matrix_autoconversion = false;
d9b8333df5e4 Deprecate java_debug, java_convert_matrix, java_unsigned_conversion.
Rik <rik@octave.org>
parents: 15798
diff changeset
186 bool Vjava_unsigned_autoconversion = true;
d9b8333df5e4 Deprecate java_debug, java_convert_matrix, java_unsigned_conversion.
Rik <rik@octave.org>
parents: 15798
diff changeset
187 bool Vdebug_java = false;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
188
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
189 class JVMArgs
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
190 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
191 public:
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
192
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
193 JVMArgs (void)
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
194 {
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
195 vm_args.version = JNI_VERSION_1_2;
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
196 vm_args.nOptions = 0;
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
197 vm_args.options = 0;
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
198 vm_args.ignoreUnrecognized = false;
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
199 }
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
200
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
201 ~JVMArgs (void)
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
202 {
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
203 clean ();
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
204 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
205
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
206 JavaVMInitArgs *to_args ()
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
207 {
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
208 update ();
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
209 return &vm_args;
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
210 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
211
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
212 void add (const std::string& opt)
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
213 {
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
214 java_opts.push_back (opt);
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
215 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
216
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
217 void read_java_opts (const std::string& filename)
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
218 {
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
219 std::ifstream js (filename.c_str ());
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
220
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
221 if (! js.bad () && ! js.fail ())
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
222 {
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
223 std::string line;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
224
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
225 while (! js.eof () && ! js.fail ())
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
226 {
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
227 std::getline (js, line);
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
228
20765
a972a2dc2735 Don't overly restrict options passed to Java jvm (bug #39063).
Rik <rik@octave.org>
parents: 20559
diff changeset
229 if (line.find ("-") == 0)
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
230 java_opts.push_back (line);
15800
d9b8333df5e4 Deprecate java_debug, java_convert_matrix, java_unsigned_conversion.
Rik <rik@octave.org>
parents: 15798
diff changeset
231 else if (line.length () > 0 && Vdebug_java)
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
232 std::cerr << "invalid JVM option, skipping: " << line << std::endl;
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
233 }
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
234 }
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
235 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
236
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
237 private:
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
238
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
239 void clean (void)
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
240 {
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
241 if (vm_args.options != 0)
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
242 {
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
243 for (int i = 0; i < vm_args.nOptions; i++)
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
244 delete [] vm_args.options[i].optionString;
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
245
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
246 delete [] vm_args.options;
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
247
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
248 vm_args.options = 0;
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
249 vm_args.nOptions = 0;
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
250 }
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
251 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
252
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
253 void update (void)
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
254 {
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
255 clean ();
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
256
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
257 if (java_opts.size () > 0)
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
258 {
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
259 int index = 0;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
260
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
261 vm_args.nOptions = java_opts.size ();
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
262 vm_args.options = new JavaVMOption [vm_args.nOptions];
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
263
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
264 for (std::list<std::string>::const_iterator it = java_opts.begin ();
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
265 it != java_opts.end (); ++it)
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
266 {
15800
d9b8333df5e4 Deprecate java_debug, java_convert_matrix, java_unsigned_conversion.
Rik <rik@octave.org>
parents: 15798
diff changeset
267 if (Vdebug_java)
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
268 std::cout << *it << std::endl;
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
269 vm_args.options[index++].optionString = strsave ((*it).c_str ());
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
270 }
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
271
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
272 java_opts.clear ();
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
273 }
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
274 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
275
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
276 private:
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
277
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
278 JavaVMInitArgs vm_args;
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
279
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
280 std::list<std::string> java_opts;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
281 };
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
282
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21691
diff changeset
283 #if defined (__WIN32__)
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
284
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
285 static std::string
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
286 read_registry_string (const std::string& key, const std::string& value)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
287 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
288 HKEY hkey;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
289 DWORD len;
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
290
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
291 std::string retval;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
292
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
293 if (! RegOpenKeyEx (HKEY_LOCAL_MACHINE, key.c_str (), 0, KEY_READ, &hkey))
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
294 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
295 if (! RegQueryValueEx (hkey, value.c_str (), 0, 0, 0, &len))
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
296 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
297 retval.resize (len);
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
298 if (RegQueryValueEx (hkey, value.c_str (), 0, 0,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
299 (LPBYTE)&retval[0], &len))
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
300 retval = "";
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
301 else if (retval[len-1] == '\0')
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
302 retval.resize (--len);
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
303 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
304 RegCloseKey (hkey);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
305 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
306
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
307 return retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
308 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
309
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
310 static std::string
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
311 get_module_filename (HMODULE hMod)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
312 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
313 int n = 1024;
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
314 std::string retval (n, '\0');
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
315 bool found = false;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
316
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
317 while (n < 65536)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
318 {
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
319 int status = GetModuleFileName (hMod, &retval[0], n);
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
320
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
321 if (status < n)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
322 {
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
323 retval.resize (n);
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
324 found = true;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
325 break;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
326 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
327 else
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
328 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
329 n *= 2;
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
330 retval.resize (n);
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
331 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
332 }
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
333
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
334 return (found ? retval : "");
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
335 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
336
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
337 static void
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
338 set_dll_directory (const std::string& dir = "")
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
339 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
340 typedef BOOL (WINAPI *dllfcn_t) (LPCTSTR path);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
341
17898
8c33abdd2f9a maint: Avoid using NULL in C++ code.
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
342 static dllfcn_t dllfcn = 0;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
343 static bool first = true;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
344
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
345 if (! dllfcn && first)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
346 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
347 HINSTANCE hKernel32 = GetModuleHandle ("kernel32");
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
348 dllfcn = reinterpret_cast<dllfcn_t> (GetProcAddress (hKernel32,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
349 "SetDllDirectoryA"));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
350 first = false;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
351 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
352
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
353 if (dllfcn)
17898
8c33abdd2f9a maint: Avoid using NULL in C++ code.
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
354 dllfcn (dir.empty () ? 0 : dir.c_str ());
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
355 }
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
356
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
357 #endif
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
358
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
359 static std::string
15752
f96faf028d90 make java functions part of core octave_value classes
John W. Eaton <jwe@octave.org>
parents: 15747
diff changeset
360 initial_java_dir (void)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
361 {
15752
f96faf028d90 make java functions part of core octave_value classes
John W. Eaton <jwe@octave.org>
parents: 15747
diff changeset
362 static std::string java_dir;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
363
15752
f96faf028d90 make java functions part of core octave_value classes
John W. Eaton <jwe@octave.org>
parents: 15747
diff changeset
364 if (java_dir.empty ())
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
365 {
21732
6a1eded90355 use namespace for system env class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
366 java_dir = octave::sys::env::getenv ("OCTAVE_JAVA_DIR");
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
367
15752
f96faf028d90 make java functions part of core octave_value classes
John W. Eaton <jwe@octave.org>
parents: 15747
diff changeset
368 if (java_dir.empty ())
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
369 java_dir = Vfcn_file_dir + octave::sys::file_ops::dir_sep_str () + "java";
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
370 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
371
15752
f96faf028d90 make java functions part of core octave_value classes
John W. Eaton <jwe@octave.org>
parents: 15747
diff changeset
372 return java_dir;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
373 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
374
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
375 // Read the content of a file filename (usually "classpath.txt")
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
376 //
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
377 // Returns a string with all lines concatenated and separated
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
378 // by the path separator character.
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
379 // The return string also starts with a path separator so that
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
380 // it can be appended easily to a base classpath.
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
381 //
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
382 // The file "classpath.txt" must contain single lines, each
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
383 // with a classpath.
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
384 // Comment lines starting with a '#' or a '%' in column 1 are allowed.
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
385
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
386 static std::string
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
387 read_classpath_txt (const std::string& filepath)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
388 {
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
389 std::string classpath;
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
390
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
391 std::ifstream fs (filepath.c_str ());
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
392
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
393 if (! fs.bad () && ! fs.fail ())
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
394 {
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
395 std::string line;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
396
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
397 while (! fs.eof () && ! fs.fail ())
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
398 {
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
399 std::getline (fs, line);
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
400
15798
ac9e34f83522 Allow one char paths, like '/', in javaclasspath.txt
Rik <rik@octave.org>
parents: 15797
diff changeset
401 if (line.length () > 0)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
402 {
15798
ac9e34f83522 Allow one char paths, like '/', in javaclasspath.txt
Rik <rik@octave.org>
parents: 15797
diff changeset
403 if (line[0] == '#' || line[0] == '%')
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
404 ; // skip comments
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
405 else
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
406 {
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
407 // prepend separator character
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
408 classpath.append (dir_path::path_sep_str ());
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
409
15798
ac9e34f83522 Allow one char paths, like '/', in javaclasspath.txt
Rik <rik@octave.org>
parents: 15797
diff changeset
410 // append content of line without whitespace
ac9e34f83522 Allow one char paths, like '/', in javaclasspath.txt
Rik <rik@octave.org>
parents: 15797
diff changeset
411 int last = line.find_last_not_of (" \t\f\v\r\n");
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
412
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
413 classpath.append (octave::sys::file_ops::tilde_expand (line.substr (0, last+1)));
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
414 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
415 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
416 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
417 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
418
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
419 return (classpath);
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
420 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
421
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
422 static std::string
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
423 initial_class_path (void)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
424 {
15752
f96faf028d90 make java functions part of core octave_value classes
John W. Eaton <jwe@octave.org>
parents: 15747
diff changeset
425 std::string java_dir = initial_java_dir ();
f96faf028d90 make java functions part of core octave_value classes
John W. Eaton <jwe@octave.org>
parents: 15747
diff changeset
426
f96faf028d90 make java functions part of core octave_value classes
John W. Eaton <jwe@octave.org>
parents: 15747
diff changeset
427 std::string retval = java_dir;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
428
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
429 // find octave.jar file
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
430 if (! retval.empty ())
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
431 {
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
432 std::string sep = octave::sys::file_ops::dir_sep_str ();
15752
f96faf028d90 make java functions part of core octave_value classes
John W. Eaton <jwe@octave.org>
parents: 15747
diff changeset
433
f96faf028d90 make java functions part of core octave_value classes
John W. Eaton <jwe@octave.org>
parents: 15747
diff changeset
434 std::string jar_file = java_dir + sep + "octave.jar";
f96faf028d90 make java functions part of core octave_value classes
John W. Eaton <jwe@octave.org>
parents: 15747
diff changeset
435
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
436 file_stat jar_exists (jar_file);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
437
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
438 if (jar_exists)
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
439 {
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
440 // initialize static classpath to octave.jar
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
441 retval = jar_file;
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
442
15797
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
443 // The base classpath has been set.
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
444 // Try to find an optional file specifying classpaths in 3 places.
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
445 // 1) Current directory
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
446 // 2) User's home directory
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
447 // 3) Octave installation directory where octave.jar resides
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
448
21732
6a1eded90355 use namespace for system env class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
449 std::string cwd = octave::sys::env::get_current_directory ();
6a1eded90355 use namespace for system env class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
450 std::string home_dir = octave::sys::env::get_home_directory ();
20422
4262598620ae Don't add duplicates to javaclasspath when run in home directory (bug #45683).
Rik <rik@octave.org>
parents: 20274
diff changeset
451
15797
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
452 // The filename is "javaclasspath.txt", but historically
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
453 // has been "classpath.txt" so both are supported.
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
454 std::string cp_list[] = {"javaclasspath.txt", "classpath.txt"};
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
455
15797
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
456 for (int i=0; i<2; i++)
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
457 {
15797
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
458 std::string filename = cp_list[i];
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
459 std::string cp_file = filename;
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
460 file_stat cp_exists;
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
461
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
462 // Try to find classpath file in the current directory.
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
463
15797
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
464 cp_exists = file_stat (cp_file);
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
465 if (cp_exists)
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
466 {
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
467 // File found. Add its contents to the static classpath.
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
468 std::string classpath = read_classpath_txt (cp_file);
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
469 retval.append (classpath);
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
470 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
471
15797
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
472 // Try to find classpath file in the user's home directory.
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
473
20422
4262598620ae Don't add duplicates to javaclasspath when run in home directory (bug #45683).
Rik <rik@octave.org>
parents: 20274
diff changeset
474 if (cwd != home_dir)
15797
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
475 {
20422
4262598620ae Don't add duplicates to javaclasspath when run in home directory (bug #45683).
Rik <rik@octave.org>
parents: 20274
diff changeset
476 cp_file = "~" + sep + filename;
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
477 cp_file = octave::sys::file_ops::tilde_expand (cp_file);
20422
4262598620ae Don't add duplicates to javaclasspath when run in home directory (bug #45683).
Rik <rik@octave.org>
parents: 20274
diff changeset
478 cp_exists = file_stat (cp_file);
4262598620ae Don't add duplicates to javaclasspath when run in home directory (bug #45683).
Rik <rik@octave.org>
parents: 20274
diff changeset
479 if (cp_exists)
4262598620ae Don't add duplicates to javaclasspath when run in home directory (bug #45683).
Rik <rik@octave.org>
parents: 20274
diff changeset
480 {
4262598620ae Don't add duplicates to javaclasspath when run in home directory (bug #45683).
Rik <rik@octave.org>
parents: 20274
diff changeset
481 // File found. Add its contents to the static classpath.
4262598620ae Don't add duplicates to javaclasspath when run in home directory (bug #45683).
Rik <rik@octave.org>
parents: 20274
diff changeset
482 std::string classpath = read_classpath_txt (cp_file);
4262598620ae Don't add duplicates to javaclasspath when run in home directory (bug #45683).
Rik <rik@octave.org>
parents: 20274
diff changeset
483 retval.append (classpath);
4262598620ae Don't add duplicates to javaclasspath when run in home directory (bug #45683).
Rik <rik@octave.org>
parents: 20274
diff changeset
484 }
15797
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
485 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
486
15797
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
487 // Try to find classpath file in the Octave install directory.
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
488
20422
4262598620ae Don't add duplicates to javaclasspath when run in home directory (bug #45683).
Rik <rik@octave.org>
parents: 20274
diff changeset
489 if (cwd != java_dir)
15797
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
490 {
20422
4262598620ae Don't add duplicates to javaclasspath when run in home directory (bug #45683).
Rik <rik@octave.org>
parents: 20274
diff changeset
491 cp_file = java_dir + sep + filename;
4262598620ae Don't add duplicates to javaclasspath when run in home directory (bug #45683).
Rik <rik@octave.org>
parents: 20274
diff changeset
492 cp_exists = file_stat (cp_file);
4262598620ae Don't add duplicates to javaclasspath when run in home directory (bug #45683).
Rik <rik@octave.org>
parents: 20274
diff changeset
493 if (cp_exists)
4262598620ae Don't add duplicates to javaclasspath when run in home directory (bug #45683).
Rik <rik@octave.org>
parents: 20274
diff changeset
494 {
4262598620ae Don't add duplicates to javaclasspath when run in home directory (bug #45683).
Rik <rik@octave.org>
parents: 20274
diff changeset
495 // File found. Add its contents to the static classpath.
4262598620ae Don't add duplicates to javaclasspath when run in home directory (bug #45683).
Rik <rik@octave.org>
parents: 20274
diff changeset
496 std::string classpath = read_classpath_txt (cp_file);
4262598620ae Don't add duplicates to javaclasspath when run in home directory (bug #45683).
Rik <rik@octave.org>
parents: 20274
diff changeset
497 retval.append (classpath);
4262598620ae Don't add duplicates to javaclasspath when run in home directory (bug #45683).
Rik <rik@octave.org>
parents: 20274
diff changeset
498 }
15797
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
499 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
500 }
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
501 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
502 else
21380
460943554233 * ov-java.cc: Call error instead of throwing std::string objects.
John W. Eaton <jwe@octave.org>
parents: 21379
diff changeset
503 error ("octave.jar does not exist: %s", jar_file.c_str ());
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
504 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
505 else
21380
460943554233 * ov-java.cc: Call error instead of throwing std::string objects.
John W. Eaton <jwe@octave.org>
parents: 21379
diff changeset
506 error ("initial java dir is empty");
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
507
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
508 return retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
509 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
510
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21691
diff changeset
511 #if ! defined (_FPU_DEFAULT)
21200
fcac5dbbf9ed maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents: 21042
diff changeset
512 # if defined __i386__ || defined __x86_64__
fcac5dbbf9ed maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents: 21042
diff changeset
513 # define _FPU_DEFAULT 0x037f
fcac5dbbf9ed maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents: 21042
diff changeset
514 # else
fcac5dbbf9ed maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents: 21042
diff changeset
515 # define _FPU_DEFAULT 0
fcac5dbbf9ed maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents: 21042
diff changeset
516 # endif
16078
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
517 #endif
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
518
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
519 static void
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
520 restore_fpu_state (void)
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
521 {
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
522 fpucw_t cw = GET_FPUCW ();
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
523
16078
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
524 if (cw != _FPU_DEFAULT)
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
525 SET_FPUCW (_FPU_DEFAULT);
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
526 }
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
527
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
528 static void
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
529 initialize_jvm (void)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
530 {
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
531 // Most of the time JVM already exists and has been initialized.
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
532 if (jvm)
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
533 return;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
534
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
535 JNIEnv *current_env;
17898
8c33abdd2f9a maint: Avoid using NULL in C++ code.
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
536 const char *static_locale = setlocale (LC_ALL, 0);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
537 const std::string locale (static_locale);
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
538
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
539 #if defined (__WIN32__)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
540
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
541 HMODULE hMod = GetModuleHandle ("jvm.dll");
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
542 std::string jvm_lib_path;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
543 std::string old_cwd;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
544
17898
8c33abdd2f9a maint: Avoid using NULL in C++ code.
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
545 if (hMod)
8c33abdd2f9a maint: Avoid using NULL in C++ code.
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
546 {
8c33abdd2f9a maint: Avoid using NULL in C++ code.
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
547 // JVM seems to be already loaded, better to use that DLL instead
8c33abdd2f9a maint: Avoid using NULL in C++ code.
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
548 // of looking in the registry, to avoid opening a different JVM.
8c33abdd2f9a maint: Avoid using NULL in C++ code.
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
549 jvm_lib_path = get_module_filename (hMod);
8c33abdd2f9a maint: Avoid using NULL in C++ code.
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
550
8c33abdd2f9a maint: Avoid using NULL in C++ code.
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
551 if (jvm_lib_path.empty ())
21380
460943554233 * ov-java.cc: Call error instead of throwing std::string objects.
John W. Eaton <jwe@octave.org>
parents: 21379
diff changeset
552 error ("unable to find Java Runtime Environment");
17898
8c33abdd2f9a maint: Avoid using NULL in C++ code.
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
553 }
8c33abdd2f9a maint: Avoid using NULL in C++ code.
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
554 else
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
555 {
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
556 // In windows, find the location of the JRE from the registry
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
557 // and load the symbol from the dll.
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
558 std::string key, value;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
559
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
560 key = "software\\javasoft\\java runtime environment";
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
561
21732
6a1eded90355 use namespace for system env class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
562 value = octave::sys::env::getenv ("JAVA_VERSION");
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
563 if (value.empty ())
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
564 {
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
565 value = "Currentversion";
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
566 std::string regval = read_registry_string (key,value);
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
567
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
568 if (regval.empty ())
21380
460943554233 * ov-java.cc: Call error instead of throwing std::string objects.
John W. Eaton <jwe@octave.org>
parents: 21379
diff changeset
569 error ("unable to find Java Runtime Environment: %s::%s",
460943554233 * ov-java.cc: Call error instead of throwing std::string objects.
John W. Eaton <jwe@octave.org>
parents: 21379
diff changeset
570 key.c_str (), value.c_str ());
460943554233 * ov-java.cc: Call error instead of throwing std::string objects.
John W. Eaton <jwe@octave.org>
parents: 21379
diff changeset
571
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
572 value = regval;
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
573 }
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
574
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
575 key = key + "\\" + value;
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
576 value = "RuntimeLib";
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
577 jvm_lib_path = read_registry_string (key, value);
21380
460943554233 * ov-java.cc: Call error instead of throwing std::string objects.
John W. Eaton <jwe@octave.org>
parents: 21379
diff changeset
578
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
579 if (jvm_lib_path.empty ())
21380
460943554233 * ov-java.cc: Call error instead of throwing std::string objects.
John W. Eaton <jwe@octave.org>
parents: 21379
diff changeset
580 error ("unable to find Java Runtime Environment: %s::%s",
460943554233 * ov-java.cc: Call error instead of throwing std::string objects.
John W. Eaton <jwe@octave.org>
parents: 21379
diff changeset
581 key.c_str (), value.c_str ());
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
582
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
583 std::string jvm_bin_path;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
584
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
585 value = "JavaHome";
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
586 jvm_bin_path = read_registry_string (key, value);
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
587 if (! jvm_bin_path.empty ())
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
588 {
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
589 jvm_bin_path = (jvm_bin_path + std::string ("\\bin"));
15744
686580b1a934 eliminate most compilation warnings for __java__.cc
John W. Eaton <jwe@octave.org>
parents: 15743
diff changeset
590
21732
6a1eded90355 use namespace for system env class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
591 old_cwd = octave::sys::env::get_current_directory ();
15744
686580b1a934 eliminate most compilation warnings for __java__.cc
John W. Eaton <jwe@octave.org>
parents: 15743
diff changeset
592
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
593 set_dll_directory (jvm_bin_path);
21732
6a1eded90355 use namespace for system env class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
594 octave::sys::env::chdir (jvm_bin_path);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
595 }
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
596 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
597
20945
9d9270e2f98f eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents: 20939
diff changeset
598 #else
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
599
15763
56239ff815a3 build: Overhaul auto-detection of Java when JAVA_HOME is not set.
Rik <rik@octave.org>
parents: 15755
diff changeset
600 // JAVA_LDPATH determined by configure and set in config.h
21200
fcac5dbbf9ed maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents: 21042
diff changeset
601 # if defined (__APPLE__)
15763
56239ff815a3 build: Overhaul auto-detection of Java when JAVA_HOME is not set.
Rik <rik@octave.org>
parents: 15755
diff changeset
602 std::string jvm_lib_path = JAVA_LDPATH + std::string ("/libjvm.dylib");
21200
fcac5dbbf9ed maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents: 21042
diff changeset
603 # else
15763
56239ff815a3 build: Overhaul auto-detection of Java when JAVA_HOME is not set.
Rik <rik@octave.org>
parents: 15755
diff changeset
604 std::string jvm_lib_path = JAVA_LDPATH + std::string ("/libjvm.so");
21200
fcac5dbbf9ed maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents: 21042
diff changeset
605 # endif
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
606
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
607 #endif
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
608
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
609 jsize nVMs = 0;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
610
21200
fcac5dbbf9ed maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents: 21042
diff changeset
611 #if ! defined (__APPLE__) && ! defined (__MACH__)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
612
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
613 octave_shlib lib (jvm_lib_path);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
614
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20946
diff changeset
615 if (! lib)
21380
460943554233 * ov-java.cc: Call error instead of throwing std::string objects.
John W. Eaton <jwe@octave.org>
parents: 21379
diff changeset
616 error ("unable to load Java Runtime Environment from %s",
460943554233 * ov-java.cc: Call error instead of throwing std::string objects.
John W. Eaton <jwe@octave.org>
parents: 21379
diff changeset
617 jvm_lib_path.c_str ());
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
618
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
619 #if defined (__WIN32__)
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
620
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
621 set_dll_directory ();
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
622
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
623 if (! old_cwd.empty ())
21732
6a1eded90355 use namespace for system env class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
624 octave::sys::env::chdir (old_cwd);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
625
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
626 #endif
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
627
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
628 JNI_CreateJavaVM_t create_vm =
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
629 reinterpret_cast<JNI_CreateJavaVM_t> (lib.search ("JNI_CreateJavaVM"));
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
630 JNI_GetCreatedJavaVMs_t get_vm =
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
631 reinterpret_cast<JNI_GetCreatedJavaVMs_t> (lib.search ("JNI_GetCreatedJavaVMs"));
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
632
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20946
diff changeset
633 if (! create_vm)
21380
460943554233 * ov-java.cc: Call error instead of throwing std::string objects.
John W. Eaton <jwe@octave.org>
parents: 21379
diff changeset
634 error ("unable to find JNI_CreateJavaVM in %s", jvm_lib_path.c_str ());
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
635
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20946
diff changeset
636 if (! get_vm)
21380
460943554233 * ov-java.cc: Call error instead of throwing std::string objects.
John W. Eaton <jwe@octave.org>
parents: 21379
diff changeset
637 error ("unable to find JNI_GetCreatedJavaVMs in %s", jvm_lib_path.c_str ());
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
638
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
639 if (get_vm (&jvm, 1, &nVMs) == 0 && nVMs > 0)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
640
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
641 #else
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
642
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
643 // FIXME: There exists a problem on the Mac platform that
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
644 // octave_shlib lib (jvm_lib_path)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
645 // doesn't work with 'not-bundled' *.oct files.
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
646
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
647 if (JNI_GetCreatedJavaVMs (&jvm, 1, &nVMs) == 0 && nVMs > 0)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
648
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
649 #endif
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
650
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
651 {
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
652 // At least one JVM exists, try to attach to it
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
653
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19598
diff changeset
654 switch (jvm->GetEnv (reinterpret_cast<void **> (&current_env),
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19598
diff changeset
655 JNI_VERSION_1_2))
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
656 {
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
657 case JNI_EDETACHED:
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
658 // Attach the current thread
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
659 JavaVMAttachArgs vm_args;
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
660 vm_args.version = JNI_VERSION_1_2;
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
661 vm_args.name = const_cast<char *> ("octave");
17898
8c33abdd2f9a maint: Avoid using NULL in C++ code.
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
662 vm_args.group = 0;
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
663 if (jvm->AttachCurrentThread (reinterpret_cast<void **> (&current_env),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
664 &vm_args) < 0)
21380
460943554233 * ov-java.cc: Call error instead of throwing std::string objects.
John W. Eaton <jwe@octave.org>
parents: 21379
diff changeset
665 error ("JVM internal error, unable to attach octave to existing JVM");
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
666 break;
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
667
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
668 case JNI_EVERSION:
21380
460943554233 * ov-java.cc: Call error instead of throwing std::string objects.
John W. Eaton <jwe@octave.org>
parents: 21379
diff changeset
669 error ("JVM internal error, the required JNI version is not supported");
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
670 break;
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
671
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
672 case JNI_OK:
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
673 // Don't do anything, the current thread is already attached to JVM
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
674 break;
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
675 }
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
676
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
677 jvm_attached = true;
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
678 //printf ("JVM attached\n");
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
679 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
680 else
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
681 {
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
682 // No JVM exists, create one
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
683
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
684 JVMArgs vm_args;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
685
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
686 vm_args.add ("-Djava.class.path=" + initial_class_path ());
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
687 vm_args.add ("-Xrs");
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
688 vm_args.add ("-Djava.system.class.loader=org.octave.OctClassLoader");
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
689 vm_args.read_java_opts (initial_java_dir () + octave::sys::file_ops::dir_sep_str () +
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19598
diff changeset
690 "java.opts");
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
691
21200
fcac5dbbf9ed maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents: 21042
diff changeset
692 #if ! defined (__APPLE__) && ! defined (__MACH__)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
693
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
694 if (create_vm (&jvm, &current_env, vm_args.to_args ()) != JNI_OK)
21380
460943554233 * ov-java.cc: Call error instead of throwing std::string objects.
John W. Eaton <jwe@octave.org>
parents: 21379
diff changeset
695 error ("unable to start Java VM in %s", jvm_lib_path.c_str ());
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
696 }
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
697
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
698 jvm_lib = lib;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
699
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
700 #else
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
701
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
702 if (JNI_CreateJavaVM (&jvm, reinterpret_cast<void **> (&current_env),
15752
f96faf028d90 make java functions part of core octave_value classes
John W. Eaton <jwe@octave.org>
parents: 15747
diff changeset
703 vm_args.to_args ()) != JNI_OK)
21380
460943554233 * ov-java.cc: Call error instead of throwing std::string objects.
John W. Eaton <jwe@octave.org>
parents: 21379
diff changeset
704 error ("unable to start Java VM in %s", jvm_lib_path.c_str ());
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
705
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
706 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
707
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
708 #endif
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
709
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
710 setlocale (LC_ALL, locale.c_str ());
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
711 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
712
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
713 static void
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
714 terminate_jvm (void)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
715 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
716 if (jvm)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
717 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
718 if (jvm_attached)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
719 jvm->DetachCurrentThread ();
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
720 else
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
721 jvm->DestroyJavaVM ();
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
722
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
723 jvm = 0;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
724 jvm_attached = false;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
725
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
726 if (jvm_lib)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
727 jvm_lib.close ();
16078
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
728
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
729 restore_fpu_state ();
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
730 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
731 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
732
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
733 static std::string
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
734 jstring_to_string (JNIEnv *jni_env, jstring s)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
735 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
736 std::string retval;
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
737
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
738 if (jni_env)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
739 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
740 const char *cstr = jni_env->GetStringUTFChars (s, 0);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
741 retval = cstr;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
742 jni_env->ReleaseStringUTFChars (s, cstr);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
743 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
744
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
745 return retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
746 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
747
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
748 static std::string
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
749 jstring_to_string (JNIEnv *jni_env, jobject obj)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
750 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
751 std::string retval;
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
752
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
753 if (jni_env && obj)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
754 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
755 jclass_ref cls (jni_env, jni_env->FindClass ("java/lang/String"));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
756 if (cls)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
757 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
758 if (jni_env->IsInstanceOf (obj, cls))
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
759 retval = jstring_to_string (jni_env,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
760 reinterpret_cast<jstring> (obj));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
761 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
762 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
763
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
764 return retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
765 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
766
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
767 static inline JNIEnv *
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
768 thread_jni_env (void)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
769 {
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
770 JNIEnv *env = 0;
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
771
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
772 if (jvm)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
773 jvm->GetEnv (reinterpret_cast<void **> (&env), JNI_VERSION_1_2);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
774
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
775 return env;
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
776 }
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
777
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
778 #endif
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
779
15824
abc9e5f3c661 Return correct value for ischar() predicate test on octave_java objects.
Rik <rik@octave.org>
parents: 15822
diff changeset
780 bool
abc9e5f3c661 Return correct value for ischar() predicate test on octave_java objects.
Rik <rik@octave.org>
parents: 15822
diff changeset
781 octave_java::is_java_string (void) const
abc9e5f3c661 Return correct value for ischar() predicate test on octave_java objects.
Rik <rik@octave.org>
parents: 15822
diff changeset
782 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
783 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
784
15824
abc9e5f3c661 Return correct value for ischar() predicate test on octave_java objects.
Rik <rik@octave.org>
parents: 15822
diff changeset
785 JNIEnv *current_env = thread_jni_env ();
abc9e5f3c661 Return correct value for ischar() predicate test on octave_java objects.
Rik <rik@octave.org>
parents: 15822
diff changeset
786
abc9e5f3c661 Return correct value for ischar() predicate test on octave_java objects.
Rik <rik@octave.org>
parents: 15822
diff changeset
787 if (current_env && java_object)
abc9e5f3c661 Return correct value for ischar() predicate test on octave_java objects.
Rik <rik@octave.org>
parents: 15822
diff changeset
788 {
abc9e5f3c661 Return correct value for ischar() predicate test on octave_java objects.
Rik <rik@octave.org>
parents: 15822
diff changeset
789 jclass_ref cls (current_env, current_env->FindClass ("java/lang/String"));
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
790 return current_env->IsInstanceOf (TO_JOBJECT (java_object), cls);
15824
abc9e5f3c661 Return correct value for ischar() predicate test on octave_java objects.
Rik <rik@octave.org>
parents: 15822
diff changeset
791 }
abc9e5f3c661 Return correct value for ischar() predicate test on octave_java objects.
Rik <rik@octave.org>
parents: 15822
diff changeset
792
abc9e5f3c661 Return correct value for ischar() predicate test on octave_java objects.
Rik <rik@octave.org>
parents: 15822
diff changeset
793 return false;
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
794
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
795 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
796
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
797 // This shouldn't happen because construction of octave_java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
798 // objects is supposed to be impossible if Java is not available.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
799
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
800 panic_impossible ();
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
801
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
802 #endif
15824
abc9e5f3c661 Return correct value for ischar() predicate test on octave_java objects.
Rik <rik@octave.org>
parents: 15822
diff changeset
803 }
abc9e5f3c661 Return correct value for ischar() predicate test on octave_java objects.
Rik <rik@octave.org>
parents: 15822
diff changeset
804
20028
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
805 bool
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
806 octave_java::is_instance_of (const std::string& cls_name) const
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
807 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
808 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
809
20028
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
810 JNIEnv *current_env = thread_jni_env ();
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
811
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
812 std::string cls_cpp = cls_name;
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
813 std::replace (cls_cpp.begin (), cls_cpp.end (), '.', '/');
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
814
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
815 if (current_env && java_object)
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
816 {
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
817 jclass_ref cls (current_env, current_env->FindClass (cls_cpp.c_str ()));
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
818 if (current_env->ExceptionCheck ())
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
819 current_env->ExceptionClear ();
20028
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
820 else
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
821 return current_env->IsInstanceOf (TO_JOBJECT (java_object), cls);
20028
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
822 }
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
823 return false;
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
824
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
825 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
826
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
827 octave_unused_parameter (cls_name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
828
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
829 // This shouldn't happen because construction of octave_java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
830 // objects is supposed to be impossible if Java is not available.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
831
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
832 panic_impossible ();
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
833
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
834 #endif
20028
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
835 }
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
836
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
837 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
838
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
839 static octave_value
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
840 check_exception (JNIEnv *jni_env)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
841 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
842 octave_value retval;
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
843
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
844 jthrowable_ref ex (jni_env, jni_env->ExceptionOccurred ());
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
845
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
846 if (ex)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
847 {
15800
d9b8333df5e4 Deprecate java_debug, java_convert_matrix, java_unsigned_conversion.
Rik <rik@octave.org>
parents: 15798
diff changeset
848 if (Vdebug_java)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
849 jni_env->ExceptionDescribe ();
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
850
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
851 jni_env->ExceptionClear ();
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
852
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
853 jclass_ref jcls (jni_env, jni_env->GetObjectClass (ex));
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
854 jmethodID mID = jni_env->GetMethodID (jcls, "toString",
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
855 "()Ljava/lang/String;");
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
856 jstring_ref js (jni_env,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
857 reinterpret_cast<jstring> (jni_env->CallObjectMethod (ex, mID)));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
858 std::string msg = jstring_to_string (jni_env, js);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
859
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
860 error ("[java] %s", msg.c_str ());
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
861 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
862 else
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
863 retval = Matrix ();
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
864
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
865 return retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
866 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
867
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
868 static jclass
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
869 find_octave_class (JNIEnv *jni_env, const char *name)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
870 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
871 static std::string class_loader;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
872 static jclass uiClass = 0;
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
873
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
874 jclass jcls = jni_env->FindClass (name);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
875
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
876 if (jcls == 0)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
877 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
878 jni_env->ExceptionClear ();
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
879
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
880 if (! uiClass)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
881 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
882 if (class_loader.empty ())
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
883 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
884 jclass_ref syscls (jni_env,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
885 jni_env->FindClass ("java/lang/System"));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
886 jmethodID mID = jni_env->GetStaticMethodID (syscls, "getProperty", "(Ljava/lang/String;)Ljava/lang/String;");
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
887 jstring_ref js (jni_env, jni_env->NewStringUTF ("octave.class.loader"));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
888 js = reinterpret_cast<jstring> (jni_env->CallStaticObjectMethod (syscls, mID, jstring (js)));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
889 class_loader = jstring_to_string (jni_env, jstring (js));
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19598
diff changeset
890 std::replace (class_loader.begin (), class_loader.end (),
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19598
diff changeset
891 '.', '/');
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
892 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
893
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
894 jclass_ref uicls (jni_env, jni_env->FindClass (class_loader.c_str ()));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
895
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
896 if (! uicls)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
897 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
898 jni_env->ExceptionClear ();
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
899
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20945
diff changeset
900 // Try the netbeans way
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19598
diff changeset
901 std::replace (class_loader.begin (), class_loader.end (),
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19598
diff changeset
902 '/', '.');
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
903 jclass_ref jcls2 (jni_env, jni_env->FindClass ("org/openide/util/Lookup"));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
904 jmethodID mID = jni_env->GetStaticMethodID (jcls2, "getDefault", "()Lorg/openide/util/Lookup;");
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
905 jobject_ref lObj (jni_env, jni_env->CallStaticObjectMethod (jcls2, mID));
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19598
diff changeset
906 mID = jni_env->GetMethodID (jcls2, "lookup",
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19598
diff changeset
907 "(Ljava/lang/Class;)Ljava/lang/Object;");
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
908 jclass_ref cLoaderCls (jni_env, jni_env->FindClass ("java/lang/ClassLoader"));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
909 jobject_ref cLoader (jni_env, jni_env->CallObjectMethod (lObj, mID, jclass (cLoaderCls)));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
910 mID = jni_env->GetMethodID (cLoaderCls, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;");
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
911 jstring_ref js (jni_env, jni_env->NewStringUTF (class_loader.c_str ()));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
912 uicls = reinterpret_cast<jclass> (jni_env->CallObjectMethod (cLoader, mID, jstring (js)));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
913 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
914
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
915 if (uicls)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
916 uiClass = reinterpret_cast<jclass> (jni_env->NewGlobalRef (jclass (uicls)));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
917 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
918
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
919 if (uiClass)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
920 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
921 jmethodID mID = jni_env->GetStaticMethodID (uiClass, "findClass", "(Ljava/lang/String;)Ljava/lang/Class;");
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
922 jstring_ref js (jni_env, jni_env->NewStringUTF (name));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
923 jcls = reinterpret_cast<jclass> (jni_env->CallStaticObjectMethod (uiClass, mID, jstring (js)));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
924 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
925 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
926
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
927 return jcls;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
928 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
929
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
930 static dim_vector
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
931 compute_array_dimensions (JNIEnv *jni_env, jobject obj)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
932 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
933 jobjectArray_ref jobj (jni_env, reinterpret_cast<jobjectArray> (obj));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
934 jclass_ref jcls (jni_env, jni_env->GetObjectClass (obj));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
935 jclass_ref ccls (jni_env, jni_env->GetObjectClass (jcls));
15859
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
936 jmethodID isArray_ID = jni_env->GetMethodID (ccls, "isArray", "()Z");
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
937 jmethodID getComponentType_ID = jni_env->GetMethodID (ccls, "getComponentType", "()Ljava/lang/Class;");
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
938
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
939 dim_vector dv (1, 1);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
940 int idx = 0;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
941
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
942 jobj.detach ();
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
943 while (jcls && jni_env->CallBooleanMethod (jcls, isArray_ID))
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
944 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
945 int len = (jobj ? jni_env->GetArrayLength (jobj) : 0);
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21580
diff changeset
946 if (idx >= dv.ndims ())
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
947 dv.resize (idx+1);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
948 dv(idx) = len;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
949 jcls = reinterpret_cast<jclass> (jni_env->CallObjectMethod (jcls, getComponentType_ID));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
950 jobj = (len > 0 ? reinterpret_cast<jobjectArray> (jni_env->GetObjectArrayElement (jobj, 0)) : 0);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
951 idx++;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
952 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
953
16078
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
954 restore_fpu_state ();
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
955
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
956 return dv;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
957 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
958
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
959 static jobject
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
960 make_java_index (JNIEnv *jni_env, const octave_value_list& idx)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
961 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
962 jclass_ref ocls (jni_env, jni_env->FindClass ("[I"));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
963 jobjectArray retval = jni_env->NewObjectArray (idx.length (), ocls, 0);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
964
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
965 for (int i = 0; i < idx.length (); i++)
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20531
diff changeset
966 try
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20531
diff changeset
967 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20531
diff changeset
968 idx_vector v = idx(i).index_vector ();
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20531
diff changeset
969
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
970 jintArray_ref i_array (jni_env, jni_env->NewIntArray (v.length ()));
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
971 jint *buf = jni_env->GetIntArrayElements (i_array, 0);
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
972
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
973 for (int k = 0; k < v.length (); k++)
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
974 buf[k] = v(k);
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
975
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
976 jni_env->ReleaseIntArrayElements (i_array, buf, 0);
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
977 jni_env->SetObjectArrayElement (retval, i, i_array);
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
978
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
979 check_exception (jni_env);
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20531
diff changeset
980 }
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20531
diff changeset
981 catch (index_exception& e)
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20531
diff changeset
982 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20531
diff changeset
983 // Rethrow to allow more info to be reported later.
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20531
diff changeset
984 e.set_pos_if_unset (idx.length (), i+1);
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20531
diff changeset
985 throw;
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20531
diff changeset
986 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
987
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
988 return retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
989 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
990
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
991 static octave_value
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
992 get_array_elements (JNIEnv *jni_env, jobject jobj,
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
993 const octave_value_list& idx)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
994 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
995 octave_value retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
996 jobject_ref resObj (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
997 jobject_ref java_idx (jni_env, make_java_index (jni_env, idx));
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
998
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
999 jclass_ref helperClass (jni_env, find_octave_class (jni_env, "org/octave/ClassHelper"));
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1000 jmethodID mID = jni_env->GetStaticMethodID (helperClass, "arraySubsref", "(Ljava/lang/Object;[[I)Ljava/lang/Object;");
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1001 resObj = jni_env->CallStaticObjectMethod (helperClass, mID, jobj, jobject (java_idx));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1002
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1003 if (resObj)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1004 retval = box (jni_env, resObj);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1005 else
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1006 retval = check_exception (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1007
16078
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
1008 restore_fpu_state ();
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
1009
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1010 return retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1011 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1012
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1013 static octave_value
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1014 set_array_elements (JNIEnv *jni_env, jobject jobj,
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1015 const octave_value_list& idx, const octave_value& rhs)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1016 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1017 octave_value retval;
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1018
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1019 jclass_ref rhsCls (jni_env);
15859
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
1020 jobject_ref resObj (jni_env);
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
1021 jobject_ref rhsObj (jni_env);
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1022 jobject_ref java_idx (jni_env, make_java_index (jni_env, idx));
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1023
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1024 if (unbox (jni_env, rhs, rhsObj, rhsCls))
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1025 {
15744
686580b1a934 eliminate most compilation warnings for __java__.cc
John W. Eaton <jwe@octave.org>
parents: 15743
diff changeset
1026 jclass_ref helperClass (jni_env, find_octave_class (jni_env, "org/octave/ClassHelper"));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1027 jmethodID mID = jni_env->GetStaticMethodID (helperClass, "arraySubsasgn",
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1028 "(Ljava/lang/Object;[[ILjava/lang/Object;)Ljava/lang/Object;");
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1029 resObj = jni_env->CallStaticObjectMethod (helperClass, mID,
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1030 jobj, jobject (java_idx), jobject (rhsObj));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1031 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1032
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1033 if (resObj)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1034 retval = box (jni_env, resObj);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1035 else
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1036 retval = check_exception (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1037
16078
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
1038 restore_fpu_state ();
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
1039
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1040 return retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1041 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1042
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1043 static string_vector
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1044 get_invoke_list (JNIEnv *jni_env, void *jobj_arg)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1045 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1046 jobject jobj = TO_JOBJECT (jobj_arg);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1047
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1048 std::list<std::string> name_list;
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1049
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1050 if (jni_env)
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1051 {
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1052 jclass_ref cls (jni_env, jni_env->GetObjectClass (jobj));
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1053 jclass_ref ccls (jni_env, jni_env->GetObjectClass (cls));
15859
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
1054 jmethodID getMethods_ID = jni_env->GetMethodID (ccls, "getMethods", "()[Ljava/lang/reflect/Method;");
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
1055 jmethodID getFields_ID = jni_env->GetMethodID (ccls, "getFields", "()[Ljava/lang/reflect/Field;");
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
1056 jobjectArray_ref mList (jni_env, reinterpret_cast<jobjectArray> (jni_env->CallObjectMethod (cls, getMethods_ID)));
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
1057 jobjectArray_ref fList (jni_env, reinterpret_cast<jobjectArray> (jni_env->CallObjectMethod (cls, getFields_ID)));
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
1058 int mLen = jni_env->GetArrayLength (mList);
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
1059 int fLen = jni_env->GetArrayLength (fList);
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
1060 jclass_ref mCls (jni_env, jni_env->FindClass ("java/lang/reflect/Method"));
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
1061 jclass_ref fCls (jni_env, jni_env->FindClass ("java/lang/reflect/Field"));
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
1062 jmethodID m_getName_ID = jni_env->GetMethodID (mCls, "getName", "()Ljava/lang/String;");
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
1063 jmethodID f_getName_ID = jni_env->GetMethodID (fCls, "getName", "()Ljava/lang/String;");
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1064
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1065 for (int i = 0; i < mLen; i++)
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1066 {
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1067 jobject_ref meth (jni_env, jni_env->GetObjectArrayElement (mList, i));
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1068 jstring_ref methName (jni_env, reinterpret_cast<jstring> (jni_env->CallObjectMethod (meth, m_getName_ID)));
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1069 name_list.push_back (jstring_to_string (jni_env, methName));
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1070 }
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1071
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1072 for (int i = 0; i < fLen; i++)
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1073 {
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1074 jobject_ref field (jni_env, jni_env->GetObjectArrayElement (fList, i));
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1075 jstring_ref fieldName (jni_env, reinterpret_cast<jstring> (jni_env->CallObjectMethod (field, f_getName_ID)));
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1076 name_list.push_back (jstring_to_string (jni_env, fieldName));
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1077 }
16078
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
1078
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
1079 restore_fpu_state ();
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1080 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1081
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1082 string_vector v (name_list);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1083
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1084 return v.sort (true);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1085 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1086
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1087 static octave_value
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1088 convert_to_string (JNIEnv *jni_env, jobject java_object, bool force, char type)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1089 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1090 octave_value retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1091
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1092 if (jni_env && java_object)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1093 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1094 jclass_ref cls (jni_env, jni_env->FindClass ("java/lang/String"));
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1095
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1096 if (jni_env->IsInstanceOf (java_object, cls))
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1097 retval = octave_value (jstring_to_string (jni_env, java_object), type);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1098 else if (force)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1099 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1100 cls = jni_env->FindClass ("[Ljava/lang/String;");
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1101
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1102 if (jni_env->IsInstanceOf (java_object, cls))
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1103 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1104 jobjectArray array = reinterpret_cast<jobjectArray> (java_object);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1105 int len = jni_env->GetArrayLength (array);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1106 Cell c (len, 1);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1107
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1108 for (int i = 0; i < len; i++)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1109 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1110 jstring_ref js (jni_env, reinterpret_cast<jstring> (jni_env->GetObjectArrayElement (array, i)));
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1111
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1112 if (js)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1113 c(i) = octave_value (jstring_to_string (jni_env, js), type);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1114 else
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1115 c(i) = check_exception (jni_env);
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1116 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1117
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1118 retval = octave_value (c);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1119 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1120 else
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1121 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1122 cls = jni_env->FindClass ("java/lang/Object");
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1123 jmethodID mID = jni_env->GetMethodID (cls, "toString", "()Ljava/lang/String;");
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1124 jstring_ref js (jni_env, reinterpret_cast<jstring> (jni_env->CallObjectMethod (java_object, mID)));
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1125
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1126 if (js)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1127 retval = octave_value (jstring_to_string (jni_env, js), type);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1128 else
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1129 retval = check_exception (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1130 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1131 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1132 else
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1133 error ("unable to convert Java object to string");
16078
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
1134
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
1135 restore_fpu_state ();
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1136 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1137
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1138 return retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1139 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1140
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1141 #define TO_JAVA(obj) dynamic_cast<octave_java*> ((obj).internal_rep ())
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1142
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1143 static octave_value
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1144 box (JNIEnv *jni_env, void *jobj_arg, void *jcls_arg)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1145 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1146 octave_value retval;
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1147
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1148 jobject jobj = TO_JOBJECT (jobj_arg);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1149 jclass jcls = TO_JCLASS (jcls_arg);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1150
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1151 jclass_ref cls (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1152
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1153 if (! jobj)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1154 retval = Matrix ();
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1155
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1156 while (retval.is_undefined ())
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1157 {
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1158 // Convert a scalar of any numeric class (byte, short, integer, long,
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1159 // float, double) to a double value. Matlab does the same thing.
15820
00172e5c2302 Add autoconversion of Java numeric types (byte, short, integer, long, float) to Octave double.
Rik <rik@octave.org>
parents: 15816
diff changeset
1160 cls = jni_env->FindClass ("java/lang/Number");
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1161 if (jni_env->IsInstanceOf (jobj, cls))
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1162 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1163 jmethodID m = jni_env->GetMethodID (cls, "doubleValue", "()D");
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1164 retval = jni_env->CallDoubleMethod (jobj, m);
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1165 break;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1166 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1167
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1168 cls = jni_env->FindClass ("java/lang/Boolean");
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1169 if (jni_env->IsInstanceOf (jobj, cls))
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1170 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1171 jmethodID m = jni_env->GetMethodID (cls, "booleanValue", "()Z");
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1172 retval = (jni_env->CallBooleanMethod (jobj, m) ? true : false);
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1173 break;
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1174 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1175
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1176 cls = jni_env->FindClass ("java/lang/String");
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1177 if (jni_env->IsInstanceOf (jobj, cls))
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1178 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1179 retval = jstring_to_string (jni_env, jobj);
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1180 break;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1181 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1182
15815
f28b3dcbaa9a Add autoconversion between java.lang.Character class and Octave string class.
Rik <rik@octave.org>
parents: 15813
diff changeset
1183 cls = jni_env->FindClass ("java/lang/Character");
f28b3dcbaa9a Add autoconversion between java.lang.Character class and Octave string class.
Rik <rik@octave.org>
parents: 15813
diff changeset
1184 if (jni_env->IsInstanceOf (jobj, cls))
f28b3dcbaa9a Add autoconversion between java.lang.Character class and Octave string class.
Rik <rik@octave.org>
parents: 15813
diff changeset
1185 {
f28b3dcbaa9a Add autoconversion between java.lang.Character class and Octave string class.
Rik <rik@octave.org>
parents: 15813
diff changeset
1186 jmethodID m = jni_env->GetMethodID (cls, "charValue", "()C");
f28b3dcbaa9a Add autoconversion between java.lang.Character class and Octave string class.
Rik <rik@octave.org>
parents: 15813
diff changeset
1187 retval = jni_env->CallCharMethod (jobj, m);
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17898
diff changeset
1188 retval = retval.convert_to_str (false, true);
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1189 break;
15815
f28b3dcbaa9a Add autoconversion between java.lang.Character class and Octave string class.
Rik <rik@octave.org>
parents: 15813
diff changeset
1190 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1191
20120
2db2db2df55b Automatically convert arrays of java primitives into Octave types (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20028
diff changeset
1192 #define BOX_PRIMITIVE_ARRAY(JAVA_TYPE, JAVA_ID, JAVA_TYPE_CAP, OCTAVE_ID) \
2db2db2df55b Automatically convert arrays of java primitives into Octave types (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20028
diff changeset
1193 cls = jni_env->FindClass (JAVA_ID); \
2db2db2df55b Automatically convert arrays of java primitives into Octave types (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20028
diff changeset
1194 if (jni_env->IsInstanceOf (jobj, cls)) \
2db2db2df55b Automatically convert arrays of java primitives into Octave types (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20028
diff changeset
1195 { \
2db2db2df55b Automatically convert arrays of java primitives into Octave types (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20028
diff changeset
1196 const JAVA_TYPE ## Array jarr = reinterpret_cast<JAVA_TYPE ## Array> (jobj); \
2db2db2df55b Automatically convert arrays of java primitives into Octave types (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20028
diff changeset
1197 const jsize len = jni_env->GetArrayLength (jarr); \
2db2db2df55b Automatically convert arrays of java primitives into Octave types (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20028
diff changeset
1198 OCTAVE_ID ## NDArray d (dim_vector (len, 1)); \
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1199 JAVA_TYPE *buffer = reinterpret_cast<JAVA_TYPE *> (d.fortran_vec ()); \
20120
2db2db2df55b Automatically convert arrays of java primitives into Octave types (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20028
diff changeset
1200 jni_env->Get ## JAVA_TYPE_CAP ## ArrayRegion (jarr, 0, len, buffer); \
2db2db2df55b Automatically convert arrays of java primitives into Octave types (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20028
diff changeset
1201 retval = d; \
2db2db2df55b Automatically convert arrays of java primitives into Octave types (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20028
diff changeset
1202 break; \
2db2db2df55b Automatically convert arrays of java primitives into Octave types (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20028
diff changeset
1203 }
2db2db2df55b Automatically convert arrays of java primitives into Octave types (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20028
diff changeset
1204
20254
a51fe1b60e3f Put most used conversions first in Java box/unbox routines.
Rik <rik@octave.org>
parents: 20253
diff changeset
1205 BOX_PRIMITIVE_ARRAY (jdouble, "[D", Double, )
a51fe1b60e3f Put most used conversions first in Java box/unbox routines.
Rik <rik@octave.org>
parents: 20253
diff changeset
1206 BOX_PRIMITIVE_ARRAY (jboolean, "[Z", Boolean, bool)
a51fe1b60e3f Put most used conversions first in Java box/unbox routines.
Rik <rik@octave.org>
parents: 20253
diff changeset
1207 BOX_PRIMITIVE_ARRAY (jfloat, "[F", Float, Float)
a51fe1b60e3f Put most used conversions first in Java box/unbox routines.
Rik <rik@octave.org>
parents: 20253
diff changeset
1208 BOX_PRIMITIVE_ARRAY (jchar, "[C", Char, char)
a51fe1b60e3f Put most used conversions first in Java box/unbox routines.
Rik <rik@octave.org>
parents: 20253
diff changeset
1209 BOX_PRIMITIVE_ARRAY (jbyte, "[B", Byte, int8)
a51fe1b60e3f Put most used conversions first in Java box/unbox routines.
Rik <rik@octave.org>
parents: 20253
diff changeset
1210 BOX_PRIMITIVE_ARRAY (jshort, "[S", Short, int16)
a51fe1b60e3f Put most used conversions first in Java box/unbox routines.
Rik <rik@octave.org>
parents: 20253
diff changeset
1211 BOX_PRIMITIVE_ARRAY (jint, "[I", Int, int32)
a51fe1b60e3f Put most used conversions first in Java box/unbox routines.
Rik <rik@octave.org>
parents: 20253
diff changeset
1212 BOX_PRIMITIVE_ARRAY (jlong, "[J", Long, int64)
20120
2db2db2df55b Automatically convert arrays of java primitives into Octave types (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20028
diff changeset
1213
2db2db2df55b Automatically convert arrays of java primitives into Octave types (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20028
diff changeset
1214 #undef BOX_PRIMITIVE_ARRAY
2db2db2df55b Automatically convert arrays of java primitives into Octave types (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20028
diff changeset
1215
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1216 if (Vjava_matrix_autoconversion)
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1217 {
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1218 cls = find_octave_class (jni_env, "org/octave/Matrix");
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1219
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1220 if (jni_env->IsInstanceOf (jobj, cls))
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1221 {
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1222 jmethodID mID = jni_env->GetMethodID (cls, "getDims", "()[I");
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1223 jintArray_ref iv (jni_env, reinterpret_cast<jintArray> (jni_env->CallObjectMethod (jobj, mID)));
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1224 jint *iv_data = jni_env->GetIntArrayElements (jintArray (iv), 0);
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1225 dim_vector dims;
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1226 dims.resize (jni_env->GetArrayLength (jintArray (iv)));
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1227
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21580
diff changeset
1228 for (int i = 0; i < dims.ndims (); i++)
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1229 dims(i) = iv_data[i];
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1230
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1231 jni_env->ReleaseIntArrayElements (jintArray (iv), iv_data, 0);
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1232 mID = jni_env->GetMethodID (cls, "getClassName", "()Ljava/lang/String;");
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1233 jstring_ref js (jni_env, reinterpret_cast<jstring> (jni_env->CallObjectMethod (jobj, mID)));
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1234
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1235 std::string s = jstring_to_string (jni_env, js);
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1236
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1237 if (s == "double")
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1238 {
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1239 NDArray m (dims);
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1240 mID = jni_env->GetMethodID (cls, "toDouble", "()[D");
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1241 jdoubleArray_ref dv (jni_env, reinterpret_cast<jdoubleArray> (jni_env->CallObjectMethod (jobj, mID)));
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20163
diff changeset
1242 jni_env->GetDoubleArrayRegion (dv, 0, m.numel (), m.fortran_vec ());
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1243 retval = m;
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1244 break;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1245 }
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1246 else if (s == "byte")
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1247 {
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1248 if (Vjava_unsigned_autoconversion)
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1249 {
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1250 uint8NDArray m (dims);
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1251 mID = jni_env->GetMethodID (cls, "toByte", "()[B");
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1252 jbyteArray_ref dv (jni_env, reinterpret_cast<jbyteArray> (jni_env->CallObjectMethod (jobj, mID)));
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20163
diff changeset
1253 jni_env->GetByteArrayRegion (dv, 0, m.numel (), reinterpret_cast<jbyte *> (m.fortran_vec ()));
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1254 retval = m;
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1255 break;
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1256 }
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1257 else
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1258 {
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1259 int8NDArray m (dims);
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1260 mID = jni_env->GetMethodID (cls, "toByte", "()[B");
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1261 jbyteArray_ref dv (jni_env, reinterpret_cast<jbyteArray> (jni_env->CallObjectMethod (jobj, mID)));
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20163
diff changeset
1262 jni_env->GetByteArrayRegion (dv, 0, m.numel (), reinterpret_cast<jbyte *> (m.fortran_vec ()));
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1263 retval = m;
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1264 break;
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1265 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1266 }
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1267 else if (s == "integer")
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1268 {
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1269 if (Vjava_unsigned_autoconversion)
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1270 {
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1271 uint32NDArray m (dims);
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1272 mID = jni_env->GetMethodID (cls, "toInt", "()[I");
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1273 jintArray_ref dv (jni_env, reinterpret_cast<jintArray> (jni_env->CallObjectMethod (jobj, mID)));
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20163
diff changeset
1274 jni_env->GetIntArrayRegion (dv, 0, m.numel (), reinterpret_cast<jint *> (m.fortran_vec ()));
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1275 retval = m;
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1276 break;
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1277 }
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1278 else
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1279 {
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1280 int32NDArray m (dims);
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1281 mID = jni_env->GetMethodID (cls, "toInt", "()[I");
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1282 jintArray_ref dv (jni_env, reinterpret_cast<jintArray> (jni_env->CallObjectMethod (jobj, mID)));
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20163
diff changeset
1283 jni_env->GetIntArrayRegion (dv, 0, m.numel (), reinterpret_cast<jint *> (m.fortran_vec ()));
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1284 retval = m;
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1285 break;
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1286 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1287 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1288 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1289 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1290
15744
686580b1a934 eliminate most compilation warnings for __java__.cc
John W. Eaton <jwe@octave.org>
parents: 15743
diff changeset
1291 cls = find_octave_class (jni_env, "org/octave/OctaveReference");
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1292 if (jni_env->IsInstanceOf (jobj, cls))
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1293 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1294 jmethodID mID = jni_env->GetMethodID (cls, "getID", "()I");
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1295 int ID = jni_env->CallIntMethod (jobj, mID);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1296 std::map<int,octave_value>::iterator it = octave_ref_map.find (ID);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1297
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1298 if (it != octave_ref_map.end ())
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1299 retval = it->second;
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1300
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1301 break;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1302 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1303
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1304 // No suitable class found. Return a generic octave_java object
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1305 retval = octave_value (new octave_java (jobj, jcls));
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1306 break;
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1307 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1308
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1309 return retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1310 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1311
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1312 static octave_value
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1313 box_more (JNIEnv *jni_env, void *jobj_arg, void *jcls_arg)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1314 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1315 jobject jobj = TO_JOBJECT (jobj_arg);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1316 jclass jcls = TO_JCLASS (jcls_arg);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1317
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1318 octave_value retval = box (jni_env, jobj, jcls);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1319
15813
10d6ab9b1b4f Implement octave_value function class_name() for class "octave_java"
Rik <rik@octave.org>
parents: 15806
diff changeset
1320 if (retval.is_java ())
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1321 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1322 retval = octave_value ();
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1323
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1324 jclass_ref cls (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1325
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1326 if (retval.is_undefined ())
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1327 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1328 cls = jni_env->FindClass ("[D");
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1329
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1330 if (jni_env->IsInstanceOf (jobj, cls))
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1331 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1332 jdoubleArray jarr = reinterpret_cast<jdoubleArray> (jobj);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1333 int len = jni_env->GetArrayLength (jarr);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1334
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1335 if (len > 0)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1336 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1337 Matrix m (1, len);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1338 jni_env->GetDoubleArrayRegion (jarr, 0, len, m.fortran_vec ());
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1339 retval = m;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1340 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1341 else
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1342 retval = Matrix ();
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1343 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1344 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1345
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1346 if (retval.is_undefined ())
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1347 {
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1348 cls = jni_env->FindClass ("[[D");
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1349
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1350 if (jni_env->IsInstanceOf (jobj, cls))
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1351 {
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1352 jobjectArray jarr = reinterpret_cast<jobjectArray> (jobj);
18100
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17898
diff changeset
1353 int rows = jni_env->GetArrayLength (jarr);
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17898
diff changeset
1354 int cols = 0;
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1355
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1356 if (rows > 0)
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1357 {
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1358 Matrix m;
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1359
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1360 for (int r = 0; r < rows; r++)
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1361 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1362 jdoubleArray_ref row (jni_env,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1363 reinterpret_cast<jdoubleArray> (jni_env->GetObjectArrayElement (jarr, r)));
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1364
20974
1edf15793cac maint: Use is_empty rather than "numel () == 0" for clarity.
Rik <rik@octave.org>
parents: 20957
diff changeset
1365 if (m.is_empty ())
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1366 {
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1367 cols = jni_env->GetArrayLength (row);
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1368 m.resize (cols, rows);
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1369 }
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1370 jni_env->GetDoubleArrayRegion (row, 0, cols, m.fortran_vec () + r * cols);
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1371 }
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1372 retval = m.transpose ();
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1373 }
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1374 else
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1375 retval = Matrix ();
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1376 }
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1377 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1378
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1379 if (retval.is_undefined ())
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1380 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1381 cls = jni_env->FindClass ("[Ljava/lang/String;");
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1382
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1383 if (jni_env->IsInstanceOf (jobj, cls))
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1384 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1385 jobjectArray jarr = reinterpret_cast<jobjectArray> (jobj);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1386 int len = jni_env->GetArrayLength (jarr);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1387 Cell m (len, 1);
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1388
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1389 for (int i = 0; i < len; i++)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1390 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1391 jstring_ref js (jni_env,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1392 reinterpret_cast<jstring> (jni_env->GetObjectArrayElement (jarr, i)));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1393 m(i) = jstring_to_string (jni_env, js);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1394 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1395
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1396 retval = m;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1397 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1398 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1399 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1400
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1401 if (retval.is_undefined ())
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1402 retval = octave_value (new octave_java (jobj, jcls));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1403
16078
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
1404 restore_fpu_state ();
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
1405
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1406 return retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1407 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1408
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1409 static bool
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1410 unbox (JNIEnv *jni_env, const octave_value& val, jobject_ref& jobj,
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1411 jclass_ref& jcls)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1412 {
20121
41064c150724 Return bools instead of ints in oc-java box and unbox internal functions.
Carnë Draug <carandraug@octave.org>
parents: 20120
diff changeset
1413 bool found = true;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1414
15813
10d6ab9b1b4f Implement octave_value function class_name() for class "octave_java"
Rik <rik@octave.org>
parents: 15806
diff changeset
1415 if (val.is_java ())
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1416 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1417 octave_java *ovj = TO_JAVA (val);
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1418 jobj = TO_JOBJECT (ovj->to_java ());
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1419 jobj.detach ();
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1420 jcls = jni_env->GetObjectClass (jobj);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1421 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1422 else if (val.is_string ())
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1423 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1424 std::string s = val.string_value ();
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1425
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1426 jobj = jni_env->NewStringUTF (s.c_str ());
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1427 jcls = jni_env->GetObjectClass (jobj);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1428 }
20260
137f183b7dee Fix conversion from string cell array into java's String[] (bug #45290)
Carnë Draug <carandraug@octave.org>
parents: 20250
diff changeset
1429 else if (val.is_cellstr ())
137f183b7dee Fix conversion from string cell array into java's String[] (bug #45290)
Carnë Draug <carandraug@octave.org>
parents: 20250
diff changeset
1430 {
137f183b7dee Fix conversion from string cell array into java's String[] (bug #45290)
Carnë Draug <carandraug@octave.org>
parents: 20250
diff changeset
1431 const Array<std::string> str_arr = val.cellstr_value ();
137f183b7dee Fix conversion from string cell array into java's String[] (bug #45290)
Carnë Draug <carandraug@octave.org>
parents: 20250
diff changeset
1432 const octave_idx_type n = str_arr.numel ();
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1433
20260
137f183b7dee Fix conversion from string cell array into java's String[] (bug #45290)
Carnë Draug <carandraug@octave.org>
parents: 20250
diff changeset
1434 jclass_ref scls (jni_env, jni_env->FindClass ("java/lang/String"));
137f183b7dee Fix conversion from string cell array into java's String[] (bug #45290)
Carnë Draug <carandraug@octave.org>
parents: 20250
diff changeset
1435 jobjectArray array = jni_env->NewObjectArray (n, scls, NULL);
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1436
20260
137f183b7dee Fix conversion from string cell array into java's String[] (bug #45290)
Carnë Draug <carandraug@octave.org>
parents: 20250
diff changeset
1437 for (octave_idx_type i = 0; i < n; i++)
137f183b7dee Fix conversion from string cell array into java's String[] (bug #45290)
Carnë Draug <carandraug@octave.org>
parents: 20250
diff changeset
1438 {
137f183b7dee Fix conversion from string cell array into java's String[] (bug #45290)
Carnë Draug <carandraug@octave.org>
parents: 20250
diff changeset
1439 jstring_ref jstr (jni_env, jni_env->NewStringUTF (str_arr(i).c_str ()));
137f183b7dee Fix conversion from string cell array into java's String[] (bug #45290)
Carnë Draug <carandraug@octave.org>
parents: 20250
diff changeset
1440 jni_env->SetObjectArrayElement (array, i, jstr);
137f183b7dee Fix conversion from string cell array into java's String[] (bug #45290)
Carnë Draug <carandraug@octave.org>
parents: 20250
diff changeset
1441 }
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1442
20260
137f183b7dee Fix conversion from string cell array into java's String[] (bug #45290)
Carnë Draug <carandraug@octave.org>
parents: 20250
diff changeset
1443 jobj = array;
137f183b7dee Fix conversion from string cell array into java's String[] (bug #45290)
Carnë Draug <carandraug@octave.org>
parents: 20250
diff changeset
1444 jcls = jni_env->GetObjectClass (jobj);
137f183b7dee Fix conversion from string cell array into java's String[] (bug #45290)
Carnë Draug <carandraug@octave.org>
parents: 20250
diff changeset
1445 }
20122
81fcf4aa9e03 Automatically convert octave vectors into java primitive arrays (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20121
diff changeset
1446 else if (val.numel () > 1 && val.dims ().is_vector ())
81fcf4aa9e03 Automatically convert octave vectors into java primitive arrays (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20121
diff changeset
1447 {
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1448 // FIXME: Is there any way to avoid code duplication here without
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1449 // using a macro?
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1450
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1451 #define UNBOX_PRIMITIVE_ARRAY(METHOD_T, OCTAVE_T, JAVA_T, JAVA_T_CAP) \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1452 do \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1453 { \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1454 const OCTAVE_T ## NDArray v = val.METHOD_T ## array_value (); \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1455 JAVA_T ## Array jarr = jni_env->New ## JAVA_T_CAP ## Array (v.numel ()); \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1456 const JAVA_T *jv = reinterpret_cast<const JAVA_T*> (v.data ()); \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1457 jni_env->Set ## JAVA_T_CAP ## ArrayRegion (jarr, 0, v.numel (), jv); \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1458 jobj = reinterpret_cast<jobject> (jarr); \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1459 jcls = jni_env->GetObjectClass (jobj); \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1460 } \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1461 while (0)
20122
81fcf4aa9e03 Automatically convert octave vectors into java primitive arrays (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20121
diff changeset
1462
81fcf4aa9e03 Automatically convert octave vectors into java primitive arrays (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20121
diff changeset
1463 // Note that we do NOT handle char here because they are unboxed
81fcf4aa9e03 Automatically convert octave vectors into java primitive arrays (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20121
diff changeset
1464 // into a String[], not into a char array
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1465
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1466 if (val.is_double_type ())
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1467 UNBOX_PRIMITIVE_ARRAY ( , , jdouble, Double);
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1468 else if (val.is_bool_type ())
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1469 UNBOX_PRIMITIVE_ARRAY (bool_, bool, jboolean, Boolean);
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1470 else if (val.is_float_type ())
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1471 UNBOX_PRIMITIVE_ARRAY (float_, Float, jfloat, Float);
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1472 else if (val.is_int8_type ())
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1473 UNBOX_PRIMITIVE_ARRAY (int8_, int8, jbyte, Byte);
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1474 else if (val.is_uint8_type ())
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1475 UNBOX_PRIMITIVE_ARRAY (uint8_, uint8, jbyte, Byte);
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1476 else if (val.is_int16_type ())
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1477 UNBOX_PRIMITIVE_ARRAY (int16_, int16, jshort, Short);
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1478 else if (val.is_uint16_type ())
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1479 UNBOX_PRIMITIVE_ARRAY (uint16_, uint16, jshort, Short);
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1480 else if (val.is_int32_type ())
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1481 UNBOX_PRIMITIVE_ARRAY (int32_, int32, jint, Int);
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1482 else if (val.is_uint32_type ())
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1483 UNBOX_PRIMITIVE_ARRAY (uint32_, uint32, jint, Int);
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1484 else if (val.is_int64_type ())
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1485 UNBOX_PRIMITIVE_ARRAY (int64_, int64, jlong, Long);
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1486 else if (val.is_uint64_type ())
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1487 UNBOX_PRIMITIVE_ARRAY (uint64_, uint64, jlong, Long);
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1488
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1489 #undef UNBOX_PRIMITIVE_ARRAY
20122
81fcf4aa9e03 Automatically convert octave vectors into java primitive arrays (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20121
diff changeset
1490 }
20123
8261c4a11250 Convert octave integer scalars into closest java type (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20122
diff changeset
1491 else if (val.is_real_scalar () || val.is_bool_scalar ())
15822
e7d9db9531d1 Add conversion for Octave integer and single classes to Java int and float classes.
Rik <rik@octave.org>
parents: 15821
diff changeset
1492 {
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1493 // FIXME: Is there any way to avoid code duplication here without
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1494 // using a macro?
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1495
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1496 #define UNBOX_PRIMITIVE_SCALAR(OCTAVE_T, METHOD_T, JAVA_T, JAVA_CON) \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1497 do \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1498 { \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1499 const OCTAVE_T ov = val.METHOD_T ## _value (); \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1500 jclass_ref dcls (jni_env, jni_env->FindClass (JAVA_T)); \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1501 const jfieldID fid = jni_env->GetStaticFieldID (dcls, "TYPE", "Ljava/lang/Class;"); \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1502 const jmethodID mid = jni_env->GetMethodID (dcls, "<init>", JAVA_CON); \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1503 jcls = reinterpret_cast<jclass> (jni_env->GetStaticObjectField (dcls, fid)); \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1504 jobj = jni_env->NewObject (dcls, mid, ov); \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1505 } \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1506 while (0)
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1507
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1508 if (val.is_double_type ())
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1509 UNBOX_PRIMITIVE_SCALAR (double, double, "java/lang/Double", "(D)V");
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1510 else if (val.is_bool_type ())
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1511 UNBOX_PRIMITIVE_SCALAR (bool, bool, "java/lang/Boolean", "(Z)V");
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1512 else if (val.is_float_type ())
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1513 UNBOX_PRIMITIVE_SCALAR (float, float, "java/lang/Float", "(F)V");
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1514 else if (val.is_int8_type ())
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1515 UNBOX_PRIMITIVE_SCALAR (int8_t, int8_scalar, "java/lang/Byte", "(B)V");
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1516 else if (val.is_uint8_type ())
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1517 UNBOX_PRIMITIVE_SCALAR (uint8_t, uint8_scalar, "java/lang/Byte", "(B)V");
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1518 else if (val.is_int16_type ())
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1519 UNBOX_PRIMITIVE_SCALAR (int16_t, int16_scalar, "java/lang/Short", "(S)V");
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1520 else if (val.is_uint16_type ())
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1521 UNBOX_PRIMITIVE_SCALAR (uint16_t, uint16_scalar, "java/lang/Short", "(S)V");
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1522 else if (val.is_int32_type ())
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1523 UNBOX_PRIMITIVE_SCALAR (int32_t, int32_scalar, "java/lang/Int", "(I)V");
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1524 else if (val.is_uint32_type ())
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1525 UNBOX_PRIMITIVE_SCALAR (uint32_t, uint32_scalar, "java/lang/Int", "(I)V");
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1526 else if (val.is_int64_type ())
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1527 UNBOX_PRIMITIVE_SCALAR (int64_t, int64_scalar, "java/lang/Long", "(L)V");
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1528 else if (val.is_uint64_type ())
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1529 UNBOX_PRIMITIVE_SCALAR (uint64_t, uint64_scalar, "java/lang/Long", "(L)V");
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1530
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1531 #undef UNBOX_PRIMITIVE_SCALAR
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1532 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1533 else if (val.is_empty ())
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1534 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1535 jobj = 0;
15822
e7d9db9531d1 Add conversion for Octave integer and single classes to Java int and float classes.
Rik <rik@octave.org>
parents: 15821
diff changeset
1536 jcls = 0;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1537 //jcls = jni_env->FindClass ("java/lang/Object");
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1538 }
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20946
diff changeset
1539 else if (! Vjava_matrix_autoconversion
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1540 && ((val.is_real_matrix ()
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1541 && (val.rows () == 1 || val.columns () == 1))
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1542 || val.is_range ()))
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1543 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1544 Matrix m = val.matrix_value ();
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20163
diff changeset
1545 jdoubleArray dv = jni_env->NewDoubleArray (m.numel ());
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20163
diff changeset
1546 jni_env->SetDoubleArrayRegion (dv, 0, m.numel (), m.fortran_vec ());
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1547 jobj = dv;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1548 jcls = jni_env->GetObjectClass (jobj);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1549 }
15800
d9b8333df5e4 Deprecate java_debug, java_convert_matrix, java_unsigned_conversion.
Rik <rik@octave.org>
parents: 15798
diff changeset
1550 else if (Vjava_matrix_autoconversion
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1551 && (val.is_matrix_type () || val.is_range ()) && val.is_real_type ())
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1552 {
15744
686580b1a934 eliminate most compilation warnings for __java__.cc
John W. Eaton <jwe@octave.org>
parents: 15743
diff changeset
1553 jclass_ref mcls (jni_env, find_octave_class (jni_env, "org/octave/Matrix"));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1554 dim_vector dims = val.dims ();
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21580
diff changeset
1555 jintArray_ref iv (jni_env, jni_env->NewIntArray (dims.ndims ()));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1556 jint *iv_data = jni_env->GetIntArrayElements (jintArray (iv), 0);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1557
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21580
diff changeset
1558 for (int i = 0; i < dims.ndims (); i++)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1559 iv_data[i] = dims(i);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1560
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1561 jni_env->ReleaseIntArrayElements (jintArray (iv), iv_data, 0);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1562
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1563 if (val.is_double_type ())
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1564 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1565 NDArray m = val.array_value ();
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20163
diff changeset
1566 jdoubleArray_ref dv (jni_env, jni_env->NewDoubleArray (m.numel ()));
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20163
diff changeset
1567 jni_env->SetDoubleArrayRegion (jdoubleArray (dv), 0, m.numel (),
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1568 m.fortran_vec ());
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1569 jmethodID mID = jni_env->GetMethodID (mcls, "<init>", "([D[I)V");
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1570 jobj = jni_env->NewObject (jclass (mcls), mID, jdoubleArray (dv),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1571 jintArray (iv));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1572 jcls = jni_env->GetObjectClass (jobj);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1573 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1574 else if (val.is_int8_type ())
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1575 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1576 int8NDArray m = val.int8_array_value ();
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20163
diff changeset
1577 jbyteArray_ref bv (jni_env, jni_env->NewByteArray (m.numel ()));
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20163
diff changeset
1578 jni_env->SetByteArrayRegion (jbyteArray (bv), 0, m.numel (),
21661
1b9a36a66b01 maint: Octave coding convention cleanups.
Rik <rik@octave.org>
parents: 21660
diff changeset
1579 reinterpret_cast<jbyte *> (m.fortran_vec ()));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1580 jmethodID mID = jni_env->GetMethodID (mcls, "<init>", "([B[I)V");
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1581 jobj = jni_env->NewObject (jclass (mcls), mID, jbyteArray (bv), jintArray (iv));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1582 jcls = jni_env->GetObjectClass (jobj);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1583 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1584 else if (val.is_uint8_type ())
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1585 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1586 uint8NDArray m = val.uint8_array_value ();
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20163
diff changeset
1587 jbyteArray_ref bv (jni_env, jni_env->NewByteArray (m.numel ()));
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20163
diff changeset
1588 jni_env->SetByteArrayRegion (jbyteArray (bv), 0, m.numel (),
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1589 reinterpret_cast<jbyte *> (m.fortran_vec ()));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1590 jmethodID mID = jni_env->GetMethodID (mcls, "<init>", "([B[I)V");
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1591 jobj = jni_env->NewObject (jclass (mcls), mID, jbyteArray (bv), jintArray (iv));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1592 jcls = jni_env->GetObjectClass (jobj);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1593 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1594 else if (val.is_int32_type ())
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1595 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1596 int32NDArray m = val.int32_array_value ();
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20163
diff changeset
1597 jintArray_ref v (jni_env, jni_env->NewIntArray (m.numel ()));
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20163
diff changeset
1598 jni_env->SetIntArrayRegion (jintArray (v), 0, m.numel (),
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1599 reinterpret_cast<jint *> (m.fortran_vec ()));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1600 jmethodID mID = jni_env->GetMethodID (mcls, "<init>", "([I[I)V");
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1601 jobj = jni_env->NewObject (jclass (mcls), mID, jintArray (v), jintArray (iv));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1602 jcls = jni_env->GetObjectClass (jobj);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1603 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1604 else
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1605 {
20121
41064c150724 Return bools instead of ints in oc-java box and unbox internal functions.
Carnë Draug <carandraug@octave.org>
parents: 20120
diff changeset
1606 found = false;
16766
7268845c0a1e avoid backquote in error messages, some uses in doc strings
John W. Eaton <jwe@octave.org>
parents: 16295
diff changeset
1607 error ("cannot convert matrix of type '%s'", val.class_name ().c_str ());
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1608 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1609 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1610 else
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1611 {
15744
686580b1a934 eliminate most compilation warnings for __java__.cc
John W. Eaton <jwe@octave.org>
parents: 15743
diff changeset
1612 jclass rcls = find_octave_class (jni_env, "org/octave/OctaveReference");
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1613 jmethodID mID = jni_env->GetMethodID (rcls, "<init>", "(I)V");
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1614 int ID = octave_java_refcount++;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1615
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1616 jobj = jni_env->NewObject (rcls, mID, ID);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1617 jcls = rcls;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1618 octave_ref_map[ID] = val;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1619 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1620
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1621 return found;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1622 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1623
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1624 static bool
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1625 unbox (JNIEnv *jni_env, const octave_value_list& args,
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1626 jobjectArray_ref& jobjs, jobjectArray_ref& jclss)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1627 {
20121
41064c150724 Return bools instead of ints in oc-java box and unbox internal functions.
Carnë Draug <carandraug@octave.org>
parents: 20120
diff changeset
1628 bool found = true;
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1629
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1630 jclass_ref ocls (jni_env, jni_env->FindClass ("java/lang/Object"));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1631 jclass_ref ccls (jni_env, jni_env->FindClass ("java/lang/Class"));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1632
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1633 if (! jobjs)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1634 jobjs = jni_env->NewObjectArray (args.length (), ocls, 0);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1635
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1636 if (! jclss)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1637 jclss = jni_env->NewObjectArray (args.length (), ccls, 0);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1638
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1639 for (int i = 0; i < args.length (); i++)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1640 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1641 jobject_ref jobj (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1642 jclass_ref jcls (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1643
20121
41064c150724 Return bools instead of ints in oc-java box and unbox internal functions.
Carnë Draug <carandraug@octave.org>
parents: 20120
diff changeset
1644 found = unbox (jni_env, args(i), jobj, jcls);
41064c150724 Return bools instead of ints in oc-java box and unbox internal functions.
Carnë Draug <carandraug@octave.org>
parents: 20120
diff changeset
1645 if (! found)
41064c150724 Return bools instead of ints in oc-java box and unbox internal functions.
Carnë Draug <carandraug@octave.org>
parents: 20120
diff changeset
1646 break;
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1647
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1648 jni_env->SetObjectArrayElement (jobjs, i, jobj);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1649 jni_env->SetObjectArrayElement (jclss, i, jcls);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1650 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1651
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1652 return found;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1653 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1654
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1655 static long
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1656 get_current_thread_ID (JNIEnv *jni_env)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1657 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1658 if (jni_env)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1659 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1660 jclass_ref cls (jni_env, jni_env->FindClass ("java/lang/Thread"));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1661 jmethodID mID = jni_env->GetStaticMethodID (cls, "currentThread", "()Ljava/lang/Thread;");
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1662 jobject_ref jthread (jni_env, jni_env->CallStaticObjectMethod (cls, mID));
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1663
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1664 if (jthread)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1665 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1666 jclass_ref jth_cls (jni_env, jni_env->GetObjectClass (jthread));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1667 mID = jni_env->GetMethodID (jth_cls, "getId", "()J");
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1668 long result = jni_env->CallLongMethod (jthread, mID);
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1669 //printf ("current java thread ID = %ld\n", result);
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1670 return result;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1671 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1672 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1673
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1674 return -1;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1675 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1676
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1677 static int
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1678 java_event_hook (void)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1679 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1680 JNIEnv *current_env = thread_jni_env ();
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1681
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1682 if (current_env)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1683 {
15744
686580b1a934 eliminate most compilation warnings for __java__.cc
John W. Eaton <jwe@octave.org>
parents: 15743
diff changeset
1684 jclass_ref cls (current_env, find_octave_class (current_env, "org/octave/Octave"));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1685 jmethodID mID = current_env->GetStaticMethodID (cls, "checkPendingAction", "()V");
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1686 current_env->CallStaticVoidMethod (cls, mID);
16078
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
1687
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
1688 restore_fpu_state ();
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1689 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1690
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1691 return 0;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1692 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1693
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1694 static void
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1695 initialize_java (void)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1696 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1697 if (! jvm)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1698 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1699 try
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1700 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1701 initialize_jvm ();
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1702
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1703 JNIEnv *current_env = thread_jni_env ();
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1704
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1705 command_editor::add_event_hook (java_event_hook);
15754
bf77f7f66bdf register octave_java type at Octave startup
John W. Eaton <jwe@octave.org>
parents: 15752
diff changeset
1706
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1707 octave_thread_ID = get_current_thread_ID (current_env);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1708 //printf ("octave thread ID=%ld\n", octave_thread_ID);
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1709 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1710 catch (std::string msg)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1711 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1712 error (msg.c_str ());
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1713 }
16078
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
1714
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
1715 restore_fpu_state ();
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1716 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1717 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1718
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1719 JNIEXPORT jboolean JNICALL
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1720 Java_org_octave_Octave_call (JNIEnv *env, jclass, jstring funcName,
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1721 jobjectArray argin, jobjectArray argout)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1722 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1723 std::string fname = jstring_to_string (env, funcName);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1724
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1725 int nargout = env->GetArrayLength (argout);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1726 int nargin = env->GetArrayLength (argin);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1727
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1728 octave_value_list varargin, varargout;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1729
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1730 for (int i = 0; i < nargin; i++)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1731 varargin(i) = box (env, env->GetObjectArrayElement (argin, i), 0);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1732
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1733 varargout = feval (fname, varargin, nargout);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1734
20121
41064c150724 Return bools instead of ints in oc-java box and unbox internal functions.
Carnë Draug <carandraug@octave.org>
parents: 20120
diff changeset
1735 jobjectArray_ref out_objs (env, argout), out_clss (env);
41064c150724 Return bools instead of ints in oc-java box and unbox internal functions.
Carnë Draug <carandraug@octave.org>
parents: 20120
diff changeset
1736 out_objs.detach ();
41064c150724 Return bools instead of ints in oc-java box and unbox internal functions.
Carnë Draug <carandraug@octave.org>
parents: 20120
diff changeset
1737 return unbox (env, varargout, out_objs, out_clss);
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1738 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1739
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1740 JNIEXPORT void JNICALL
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1741 Java_org_octave_OctaveReference_doFinalize (JNIEnv *, jclass, jint ID)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1742 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1743 octave_ref_map.erase (ID);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1744 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1745
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1746 JNIEXPORT void JNICALL
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1747 Java_org_octave_Octave_doInvoke (JNIEnv *env, jclass, jint ID,
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1748 jobjectArray args)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1749 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1750 std::map<int,octave_value>::iterator it = octave_ref_map.find (ID);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1751
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1752 if (it != octave_ref_map.end ())
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1753 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1754 octave_value val = it->second;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1755 int len = env->GetArrayLength (args);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1756 octave_value_list oct_args;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1757
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1758 for (int i = 0; i < len; i++)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1759 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1760 jobject_ref jobj (env, env->GetObjectArrayElement (args, i));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1761 oct_args(i) = box (env, jobj, 0);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1762 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1763
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1764 BEGIN_INTERRUPT_WITH_EXCEPTIONS;
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1765
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1766 if (val.is_function_handle ())
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1767 {
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1768 octave_function *fcn = val.function_value ();
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1769 feval (fcn, oct_args);
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1770 }
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1771 else if (val.is_cell () && val.length () > 0
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1772 && (val.rows () == 1 || val.columns () == 1)
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1773 && val.cell_value()(0).is_function_handle ())
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1774 {
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1775 Cell c = val.cell_value ();
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1776 octave_function *fcn = c(0).function_value ();
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1777
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1778 for (int i=1; i<c.numel (); i++)
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1779 oct_args(len+i-1) = c(i);
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1780
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1781 feval (fcn, oct_args);
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1782 }
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1783 else
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1784 error ("trying to invoke non-invocable object");
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1785
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1786 END_INTERRUPT_WITH_EXCEPTIONS;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1787 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1788 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1789
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1790 JNIEXPORT void JNICALL
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1791 Java_org_octave_Octave_doEvalString (JNIEnv *env, jclass, jstring cmd)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1792 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1793 std::string s = jstring_to_string (env, cmd);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1794 int pstatus;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1795 eval_string (s, false, pstatus, 0);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1796 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1797
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1798 JNIEXPORT jboolean JNICALL
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1799 Java_org_octave_Octave_needThreadedInvokation (JNIEnv *env, jclass)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1800 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1801 return (get_current_thread_ID (env) != octave_thread_ID);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1802 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1803
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1804 #endif
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1805
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1806 // octave_java class definition
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1807
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1808 octave_java::octave_java (void)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1809 : octave_base_value (), java_object (0), java_class (0)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1810 {
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1811 #if ! defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1812
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1813 err_disabled_feature ("Java Objects", "Java");
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1814
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1815 #endif
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1816 }
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1817
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1818 octave_java::octave_java (const voidptr& jobj, void *jcls)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1819 : octave_base_value (), java_object (0), java_class (0)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1820 {
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1821 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1822
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1823 init (jobj, jcls);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1824
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1825 #else
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1826
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
1827 octave_unused_parameter (jobj);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
1828 octave_unused_parameter (jcls);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
1829
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1830 err_disabled_feature ("Java Objects", "Java");
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1831
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1832 #endif
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1833 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1834
15813
10d6ab9b1b4f Implement octave_value function class_name() for class "octave_java"
Rik <rik@octave.org>
parents: 15806
diff changeset
1835 int octave_java::t_id (-1);
10d6ab9b1b4f Implement octave_value function class_name() for class "octave_java"
Rik <rik@octave.org>
parents: 15806
diff changeset
1836
10d6ab9b1b4f Implement octave_value function class_name() for class "octave_java"
Rik <rik@octave.org>
parents: 15806
diff changeset
1837 const std::string octave_java::t_name ("octave_java");
10d6ab9b1b4f Implement octave_value function class_name() for class "octave_java"
Rik <rik@octave.org>
parents: 15806
diff changeset
1838
10d6ab9b1b4f Implement octave_value function class_name() for class "octave_java"
Rik <rik@octave.org>
parents: 15806
diff changeset
1839 void
10d6ab9b1b4f Implement octave_value function class_name() for class "octave_java"
Rik <rik@octave.org>
parents: 15806
diff changeset
1840 octave_java::register_type (void)
10d6ab9b1b4f Implement octave_value function class_name() for class "octave_java"
Rik <rik@octave.org>
parents: 15806
diff changeset
1841 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1842 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1843
15813
10d6ab9b1b4f Implement octave_value function class_name() for class "octave_java"
Rik <rik@octave.org>
parents: 15806
diff changeset
1844 t_id = octave_value_typeinfo::register_type
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1845 (octave_java::t_name, "<unknown>", octave_value (new octave_java ()));
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1846
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1847 #endif
15813
10d6ab9b1b4f Implement octave_value function class_name() for class "octave_java"
Rik <rik@octave.org>
parents: 15806
diff changeset
1848 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1849
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1850 dim_vector
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1851 octave_java::dims (void) const
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1852 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1853 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1854
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1855 JNIEnv *current_env = thread_jni_env ();
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1856
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1857 if (current_env && java_object)
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1858 return compute_array_dimensions (current_env, TO_JOBJECT (java_object));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1859 else
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1860 return dim_vector (1, 1);
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1861
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1862 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
1863
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1864 // This shouldn't happen because construction of octave_java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1865 // objects is supposed to be impossible if Java is not available.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1866
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1867 panic_impossible ();
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
1868
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1869 #endif
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1870 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1871
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1872 octave_value_list
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1873 octave_java::subsref (const std::string& type,
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1874 const std::list<octave_value_list>& idx, int nargout)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1875 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1876 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1877
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1878 octave_value_list retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1879 int skip = 1;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1880
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1881 JNIEnv *current_env = thread_jni_env ();
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1882
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1883 switch (type[0])
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1884 {
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1885 case '.':
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1886 if (type.length () > 1 && type[1] == '(')
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1887 {
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1888 octave_value_list ovl;
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1889 count++;
15790
921912c92102 Deprecate java_invoke, replace with javaMethod.
Rik <rik@octave.org>
parents: 15771
diff changeset
1890 ovl(1) = octave_value (this);
921912c92102 Deprecate java_invoke, replace with javaMethod.
Rik <rik@octave.org>
parents: 15771
diff changeset
1891 ovl(0) = (idx.front ())(0);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1892 std::list<octave_value_list>::const_iterator it = idx.begin ();
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1893 ovl.append (*++it);
15790
921912c92102 Deprecate java_invoke, replace with javaMethod.
Rik <rik@octave.org>
parents: 15771
diff changeset
1894 retval = feval (std::string ("javaMethod"), ovl, 1);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1895 skip++;
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1896 }
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1897 else
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1898 {
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1899 octave_value_list ovl;
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1900 count++;
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1901 ovl(0) = octave_value (this);
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1902 ovl(1) = (idx.front ())(0);
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
1903 retval = feval (std::string ("__java_get__"), ovl, 1);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1904 }
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1905 break;
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1906
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1907 case '(':
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1908 if (current_env)
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1909 retval = get_array_elements (current_env, TO_JOBJECT (to_java ()), idx.front ());
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1910 break;
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1911
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1912 default:
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1913 error ("subsref: Java object cannot be indexed with %c", type[0]);
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1914 break;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1915 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1916
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1917 if (idx.size () > 1 && type.length () > 1)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1918 retval = retval(0).next_subsref (nargout, type, idx, skip);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1919
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1920 return retval;
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1921
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1922 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
1923
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
1924 octave_unused_parameter (type);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
1925 octave_unused_parameter (idx);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
1926 octave_unused_parameter (nargout);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
1927
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1928 // This shouldn't happen because construction of octave_java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1929 // objects is supposed to be impossible if Java is not available.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1930
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1931 panic_impossible ();
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
1932
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1933 #endif
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1934 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1935
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1936 octave_value
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1937 octave_java::subsasgn (const std::string& type,
21661
1b9a36a66b01 maint: Octave coding convention cleanups.
Rik <rik@octave.org>
parents: 21660
diff changeset
1938 const std::list<octave_value_list>& idx,
1b9a36a66b01 maint: Octave coding convention cleanups.
Rik <rik@octave.org>
parents: 21660
diff changeset
1939 const octave_value& rhs)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1940 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1941 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1942
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1943 octave_value retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1944
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1945 JNIEnv *current_env = thread_jni_env ();
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1946
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1947 switch (type[0])
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1948 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1949 case '.':
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1950 if (type.length () == 1)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1951 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1952 // field assignment
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1953 octave_value_list ovl;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1954 count++;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1955 ovl(0) = octave_value (this);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1956 ovl(1) = (idx.front ())(0);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1957 ovl(2) = rhs;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1958 feval ("__java_set__", ovl, 0);
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1959
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1960 count++;
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1961 retval = octave_value (this);
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1962 }
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1963 else if (type.length () > 2 && type[1] == '(')
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1964 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1965 std::list<octave_value_list> new_idx;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1966 std::list<octave_value_list>::const_iterator it = idx.begin ();
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1967 new_idx.push_back (*it++);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1968 new_idx.push_back (*it++);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1969 octave_value_list u = subsref (type.substr (0, 2), new_idx, 1);
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1970
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1971 std::list<octave_value_list> next_idx (idx);
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1972 next_idx.erase (next_idx.begin ());
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1973 next_idx.erase (next_idx.begin ());
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1974 u(0).subsasgn (type.substr (2), next_idx, rhs);
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1975
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1976 count++;
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1977 retval = octave_value (this);
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1978 }
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1979 else if (type[1] == '.')
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1980 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1981 octave_value_list u = subsref (type.substr (0, 1), idx, 1);
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1982
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1983 std::list<octave_value_list> next_idx (idx);
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1984 next_idx.erase (next_idx.begin ());
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1985 u(0).subsasgn (type.substr (1), next_idx, rhs);
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1986
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1987 count++;
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1988 retval = octave_value (this);
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1989 }
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1990 else
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1991 error ("invalid indexing/assignment on Java object");
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1992 break;
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1993
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1994 case '(':
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1995 if (current_env)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1996 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1997 set_array_elements (current_env, TO_JOBJECT (to_java ()), idx.front (), rhs);
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1998
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1999 count++;
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2000 retval = octave_value (this);
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2001 }
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2002 break;
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2003
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2004 default:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2005 error ("Java object cannot be indexed with %c", type[0]);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2006 break;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2007 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2008
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2009 return retval;
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2010
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2011 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2012
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2013 octave_unused_parameter (type);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2014 octave_unused_parameter (idx);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2015 octave_unused_parameter (rhs);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2016
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2017 // This shouldn't happen because construction of octave_java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2018 // objects is supposed to be impossible if Java is not available.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2019
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2020 panic_impossible ();
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2021
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2022 #endif
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2023 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2024
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2025 string_vector
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2026 octave_java::map_keys (void) const
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2027 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2028 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2029
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2030 JNIEnv *current_env = thread_jni_env ();
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2031
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2032 if (current_env)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2033 return get_invoke_list (current_env, to_java ());
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2034 else
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2035 return string_vector ();
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2036
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2037 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2038
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2039 // This shouldn't happen because construction of octave_java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2040 // objects is supposed to be impossible if Java is not available.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2041
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2042 panic_impossible ();
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2043
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2044 #endif
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2045 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2046
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2047 octave_value
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2048 octave_java::convert_to_str_internal (bool, bool force, char type) const
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2049 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2050 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2051
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2052 JNIEnv *current_env = thread_jni_env ();
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2053
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2054 if (current_env)
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2055 return convert_to_string (current_env, TO_JOBJECT (to_java ()), force, type);
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2056 else
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2057 return octave_value ("");
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2058
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2059 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2060
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2061 octave_unused_parameter (force);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2062 octave_unused_parameter (type);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2063
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2064 // This shouldn't happen because construction of octave_java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2065 // objects is supposed to be impossible if Java is not available.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2066
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2067 panic_impossible ();
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2068
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2069 #endif
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2070 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2071
15859
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
2072 void
18416
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18100
diff changeset
2073 octave_java::print (std::ostream& os, bool)
15859
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
2074 {
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
2075 print_raw (os);
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
2076 newline (os);
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
2077 }
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
2078
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
2079 void
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
2080 octave_java::print_raw (std::ostream& os, bool) const
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
2081 {
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
2082 os << "<Java object: " << java_classname << ">";
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
2083 }
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
2084
20441
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2085 // FIXME: Need routines to actually save/load java objects through Serialize.
20531
dcfbf4c1c3c8 eliminate trailing whitespace and tabs from sources
John W. Eaton <jwe@octave.org>
parents: 20468
diff changeset
2086 // See bug #42112.
20441
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2087
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2088 bool
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2089 octave_java::save_ascii (std::ostream& /* os */)
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2090 {
20531
dcfbf4c1c3c8 eliminate trailing whitespace and tabs from sources
John W. Eaton <jwe@octave.org>
parents: 20468
diff changeset
2091 warning ("save: unable to save java objects, skipping");
20441
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2092
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2093 return true;
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2094 }
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2095
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2096 bool
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2097 octave_java::load_ascii (std::istream& /* is */)
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2098 {
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2099 // Silently skip over java object that was not saved
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2100 return true;
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2101 }
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2102
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2103 bool
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2104 octave_java::save_binary (std::ostream& /* os */, bool& /* save_as_floats */)
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2105 {
20531
dcfbf4c1c3c8 eliminate trailing whitespace and tabs from sources
John W. Eaton <jwe@octave.org>
parents: 20468
diff changeset
2106 warning ("save: unable to save java objects, skipping");
20441
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2107
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2108 return true;
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2109 }
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2110
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2111 bool
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2112 octave_java::load_binary (std::istream& /* is */, bool /* swap*/,
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2113 oct_mach_info::float_format /* fmt */)
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2114 {
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2115 // Silently skip over java object that was not saved
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2116 return true;
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2117 }
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2118
20468
2f94652de9ff Add placeholder functions for save_hdf5, load_hdf5 for octave_java functions.
Rik <rik@octave.org>
parents: 20441
diff changeset
2119 bool
2f94652de9ff Add placeholder functions for save_hdf5, load_hdf5 for octave_java functions.
Rik <rik@octave.org>
parents: 20441
diff changeset
2120 octave_java::save_hdf5 (octave_hdf5_id /* loc_id */, const char * /* name */,
2f94652de9ff Add placeholder functions for save_hdf5, load_hdf5 for octave_java functions.
Rik <rik@octave.org>
parents: 20441
diff changeset
2121 bool /* save_as_floats */)
2f94652de9ff Add placeholder functions for save_hdf5, load_hdf5 for octave_java functions.
Rik <rik@octave.org>
parents: 20441
diff changeset
2122 {
2f94652de9ff Add placeholder functions for save_hdf5, load_hdf5 for octave_java functions.
Rik <rik@octave.org>
parents: 20441
diff changeset
2123 warning ("save: unable to save java objects, skipping");
2f94652de9ff Add placeholder functions for save_hdf5, load_hdf5 for octave_java functions.
Rik <rik@octave.org>
parents: 20441
diff changeset
2124
2f94652de9ff Add placeholder functions for save_hdf5, load_hdf5 for octave_java functions.
Rik <rik@octave.org>
parents: 20441
diff changeset
2125 return true;
2f94652de9ff Add placeholder functions for save_hdf5, load_hdf5 for octave_java functions.
Rik <rik@octave.org>
parents: 20441
diff changeset
2126 }
2f94652de9ff Add placeholder functions for save_hdf5, load_hdf5 for octave_java functions.
Rik <rik@octave.org>
parents: 20441
diff changeset
2127
2f94652de9ff Add placeholder functions for save_hdf5, load_hdf5 for octave_java functions.
Rik <rik@octave.org>
parents: 20441
diff changeset
2128 bool
2f94652de9ff Add placeholder functions for save_hdf5, load_hdf5 for octave_java functions.
Rik <rik@octave.org>
parents: 20441
diff changeset
2129 octave_java::load_hdf5 (octave_hdf5_id /* loc_id */, const char * /* name */)
2f94652de9ff Add placeholder functions for save_hdf5, load_hdf5 for octave_java functions.
Rik <rik@octave.org>
parents: 20441
diff changeset
2130 {
2f94652de9ff Add placeholder functions for save_hdf5, load_hdf5 for octave_java functions.
Rik <rik@octave.org>
parents: 20441
diff changeset
2131 // Silently skip object that was not saved
2f94652de9ff Add placeholder functions for save_hdf5, load_hdf5 for octave_java functions.
Rik <rik@octave.org>
parents: 20441
diff changeset
2132 return true;
2f94652de9ff Add placeholder functions for save_hdf5, load_hdf5 for octave_java functions.
Rik <rik@octave.org>
parents: 20441
diff changeset
2133 }
2f94652de9ff Add placeholder functions for save_hdf5, load_hdf5 for octave_java functions.
Rik <rik@octave.org>
parents: 20441
diff changeset
2134
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2135 octave_value
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2136 octave_java::do_javaMethod (void *jni_env_arg, const std::string& name,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2137 const octave_value_list& args)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2138 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2139 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2140
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2141 octave_value retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2142
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2143 JNIEnv *jni_env = TO_JNIENV (jni_env_arg);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2144
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2145 if (jni_env)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2146 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2147 jobjectArray_ref arg_objs (jni_env), arg_types (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2148 if (unbox (jni_env, args, arg_objs, arg_types))
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2149 {
15744
686580b1a934 eliminate most compilation warnings for __java__.cc
John W. Eaton <jwe@octave.org>
parents: 15743
diff changeset
2150 jclass_ref helperClass (jni_env, find_octave_class (jni_env, "org/octave/ClassHelper"));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2151 jmethodID mID = jni_env->GetStaticMethodID (helperClass, "invokeMethod",
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2152 "(Ljava/lang/Object;Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/Class;)Ljava/lang/Object;");
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2153 jstring_ref methName (jni_env, jni_env->NewStringUTF (name.c_str ()));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2154 jobjectArray_ref resObj (jni_env, reinterpret_cast<jobjectArray> (jni_env->CallStaticObjectMethod (helperClass, mID,
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2155 to_java (), jstring (methName), jobjectArray (arg_objs), jobjectArray (arg_types))));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2156 if (resObj)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2157 retval = box (jni_env, resObj);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2158 else
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2159 retval = check_exception (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2160 }
16078
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
2161
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
2162 restore_fpu_state ();
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2163 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2164
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2165 return retval;
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2166
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2167 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2168
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2169 octave_unused_parameter (jni_env_arg);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2170 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2171 octave_unused_parameter (args);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2172
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2173 // This shouldn't happen because construction of octave_java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2174 // objects is supposed to be impossible if Java is not available.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2175
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2176 panic_impossible ();
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2177
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2178 #endif
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2179 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2180
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2181 octave_value
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2182 octave_java::do_javaMethod (const std::string& name, const octave_value_list& args)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2183 {
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2184 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2185
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2186 return do_javaMethod (thread_jni_env (), name, args);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2187
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2188 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2189
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2190 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2191 octave_unused_parameter (args);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2192
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2193 // This shouldn't happen because construction of octave_java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2194 // objects is supposed to be impossible if Java is not available.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2195
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2196 panic_impossible ();
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2197
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2198 #endif
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2199 }
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2200
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2201 octave_value
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2202 octave_java:: do_javaMethod (void *jni_env_arg,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2203 const std::string& class_name,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2204 const std::string& name,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2205 const octave_value_list& args)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2206 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2207 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2208
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2209 octave_value retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2210
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2211 JNIEnv *jni_env = TO_JNIENV (jni_env_arg);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2212
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2213 if (jni_env)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2214 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2215 jobjectArray_ref arg_objs (jni_env), arg_types (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2216 if (unbox (jni_env, args, arg_objs, arg_types))
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2217 {
15744
686580b1a934 eliminate most compilation warnings for __java__.cc
John W. Eaton <jwe@octave.org>
parents: 15743
diff changeset
2218 jclass_ref helperClass (jni_env, find_octave_class (jni_env, "org/octave/ClassHelper"));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2219 jmethodID mID = jni_env->GetStaticMethodID (helperClass, "invokeStaticMethod",
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2220 "(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/Class;)Ljava/lang/Object;");
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2221 jstring_ref methName (jni_env, jni_env->NewStringUTF (name.c_str ()));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2222 jstring_ref clsName (jni_env, jni_env->NewStringUTF (class_name.c_str ()));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2223 jobject_ref resObj (jni_env, jni_env->CallStaticObjectMethod (helperClass, mID,
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2224 jstring (clsName), jstring (methName), jobjectArray (arg_objs), jobjectArray (arg_types)));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2225 if (resObj)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2226 retval = box (jni_env, resObj);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2227 else
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2228 retval = check_exception (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2229 }
16078
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
2230
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
2231 restore_fpu_state ();
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2232 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2233
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2234 return retval;
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2235
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2236 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2237
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2238 octave_unused_parameter (jni_env_arg);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2239 octave_unused_parameter (class_name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2240 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2241 octave_unused_parameter (args);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2242
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2243 // This shouldn't happen because construction of octave_java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2244 // objects is supposed to be impossible if Java is not available.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2245
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2246 panic_impossible ();
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2247
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2248 #endif
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2249 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2250
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2251 octave_value
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2252 octave_java::do_javaMethod (const std::string& class_name,
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2253 const std::string& name,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2254 const octave_value_list& args)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2255 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2256 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2257
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2258 return do_javaMethod (thread_jni_env (), class_name, name, args);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2259
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2260 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2261
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2262 octave_unused_parameter (class_name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2263 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2264 octave_unused_parameter (args);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2265
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2266 // This shouldn't happen because construction of octave_java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2267 // objects is supposed to be impossible if Java is not available.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2268
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2269 panic_impossible ();
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2270
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2271 #endif
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2272 }
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2273
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2274 octave_value
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2275 octave_java::do_javaObject (void *jni_env_arg, const std::string& name,
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2276 const octave_value_list& args)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2277 {
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2278 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2279
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2280 octave_value retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2281
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2282 JNIEnv *jni_env = TO_JNIENV (jni_env_arg);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2283
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2284 if (jni_env)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2285 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2286 jobjectArray_ref arg_objs (jni_env), arg_types (jni_env);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2287
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2288 if (unbox (jni_env, args, arg_objs, arg_types))
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2289 {
15744
686580b1a934 eliminate most compilation warnings for __java__.cc
John W. Eaton <jwe@octave.org>
parents: 15743
diff changeset
2290 jclass_ref helperClass (jni_env, find_octave_class (jni_env, "org/octave/ClassHelper"));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2291 jmethodID mID = jni_env->GetStaticMethodID (helperClass, "invokeConstructor",
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2292 "(Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/Class;)Ljava/lang/Object;");
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2293 jstring_ref clsName (jni_env, jni_env->NewStringUTF (name.c_str ()));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2294 jobject_ref resObj (jni_env, jni_env->CallStaticObjectMethod (helperClass, mID,
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2295 jstring (clsName), jobjectArray (arg_objs), jobjectArray (arg_types)));
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2296
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2297 if (resObj)
15816
59b6c6aee042 Don't box return values from javaObject. Always return a Java object.
Rik <rik@octave.org>
parents: 15815
diff changeset
2298 retval = octave_value (new octave_java (resObj, 0));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2299 else
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2300 check_exception (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2301 }
16078
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
2302
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
2303 restore_fpu_state ();
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2304 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2305
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2306 return retval;
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2307
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2308 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2309
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2310 octave_unused_parameter (jni_env_arg);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2311 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2312 octave_unused_parameter (args);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2313
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2314 // This shouldn't happen because construction of octave_java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2315 // objects is supposed to be impossible if Java is not available.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2316
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2317 panic_impossible ();
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2318
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2319 #endif
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2320 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2321
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2322 octave_value
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2323 octave_java::do_javaObject (const std::string& name, const octave_value_list& args)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2324 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2325 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2326
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2327 return do_javaObject (thread_jni_env (), name, args);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2328
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2329 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2330
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2331 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2332 octave_unused_parameter (args);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2333
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2334 // This shouldn't happen because construction of octave_java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2335 // objects is supposed to be impossible if Java is not available.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2336
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2337 panic_impossible ();
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2338
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2339 #endif
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2340 }
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2341
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2342 octave_value
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2343 octave_java::do_java_get (void *jni_env_arg, const std::string& name)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2344 {
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2345 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2346
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2347 octave_value retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2348
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2349 JNIEnv *jni_env = TO_JNIENV (jni_env_arg);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2350
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2351 if (jni_env)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2352 {
15744
686580b1a934 eliminate most compilation warnings for __java__.cc
John W. Eaton <jwe@octave.org>
parents: 15743
diff changeset
2353 jclass_ref helperClass (jni_env, find_octave_class (jni_env, "org/octave/ClassHelper"));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2354 jmethodID mID = jni_env->GetStaticMethodID (helperClass, "getField",
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2355 "(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;");
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2356 jstring_ref fName (jni_env, jni_env->NewStringUTF (name.c_str ()));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2357 jobject_ref resObj (jni_env, jni_env->CallStaticObjectMethod (helperClass, mID,
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2358 to_java (), jstring (fName)));
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2359
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2360 if (resObj)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2361 retval = box (jni_env, resObj);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2362 else
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2363 retval = check_exception (jni_env);
16078
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
2364
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
2365 restore_fpu_state ();
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2366 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2367
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2368 return retval;
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2369
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2370 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2371
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2372 octave_unused_parameter (jni_env_arg);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2373 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2374
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2375 // This shouldn't happen because construction of octave_java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2376 // objects is supposed to be impossible if Java is not available.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2377
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2378 panic_impossible ();
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2379
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2380 #endif
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2381 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2382
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2383 octave_value
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2384 octave_java::do_java_get (const std::string& name)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2385 {
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2386 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2387
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2388 return do_java_get (thread_jni_env (), name);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2389
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2390 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2391
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2392 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2393
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2394 // This shouldn't happen because construction of octave_java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2395 // objects is supposed to be impossible if Java is not available.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2396
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2397 panic_impossible ();
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2398
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2399 #endif
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2400 }
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2401
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2402 octave_value
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2403 octave_java::do_java_get (void *jni_env_arg, const std::string& class_name,
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2404 const std::string& name)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2405 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2406 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2407
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2408 octave_value retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2409
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2410 JNIEnv *jni_env = TO_JNIENV (jni_env_arg);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2411
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2412 if (jni_env)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2413 {
15744
686580b1a934 eliminate most compilation warnings for __java__.cc
John W. Eaton <jwe@octave.org>
parents: 15743
diff changeset
2414 jclass_ref helperClass (jni_env, find_octave_class (jni_env, "org/octave/ClassHelper"));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2415 jmethodID mID = jni_env->GetStaticMethodID (helperClass, "getStaticField",
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2416 "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;");
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2417 jstring_ref cName (jni_env, jni_env->NewStringUTF (class_name.c_str ()));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2418 jstring_ref fName (jni_env, jni_env->NewStringUTF (name.c_str ()));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2419 jobject_ref resObj (jni_env, jni_env->CallStaticObjectMethod (helperClass, mID,
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2420 jstring (cName), jstring (fName)));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2421 if (resObj)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2422 retval = box (jni_env, resObj);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2423 else
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2424 retval = check_exception (jni_env);
16078
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
2425
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
2426 restore_fpu_state ();
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2427 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2428
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2429 return retval;
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2430
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2431 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2432
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2433 octave_unused_parameter (jni_env_arg);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2434 octave_unused_parameter (class_name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2435 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2436
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2437 // This shouldn't happen because construction of octave_java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2438 // objects is supposed to be impossible if Java is not available.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2439
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2440 panic_impossible ();
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2441
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2442 #endif
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2443 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2444
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2445 octave_value
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2446 octave_java::do_java_get (const std::string& class_name, const std::string& name)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2447 {
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2448 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2449
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2450 return do_java_get (thread_jni_env (), class_name, name);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2451
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2452 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2453
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2454 octave_unused_parameter (class_name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2455 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2456
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2457 // This shouldn't happen because construction of octave_java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2458 // objects is supposed to be impossible if Java is not available.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2459
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2460 panic_impossible ();
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2461
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2462 #endif
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2463 }
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2464
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2465 octave_value
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2466 octave_java::do_java_set (void *jni_env_arg, const std::string& name,
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2467 const octave_value& val)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2468 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2469 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2470
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2471 octave_value retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2472
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2473 JNIEnv *jni_env = TO_JNIENV (jni_env_arg);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2474
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2475 if (jni_env)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2476 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2477 jobject_ref jobj (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2478 jclass_ref jcls (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2479
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2480 if (unbox (jni_env, val, jobj, jcls))
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2481 {
15744
686580b1a934 eliminate most compilation warnings for __java__.cc
John W. Eaton <jwe@octave.org>
parents: 15743
diff changeset
2482 jclass_ref helperClass (jni_env, find_octave_class (jni_env, "org/octave/ClassHelper"));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2483 jmethodID mID = jni_env->GetStaticMethodID (helperClass, "setField",
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2484 "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)V");
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2485 jstring_ref fName (jni_env, jni_env->NewStringUTF (name.c_str ()));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2486 jni_env->CallStaticObjectMethod (helperClass, mID, to_java (), jstring (fName), jobject (jobj));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2487 check_exception (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2488 }
16078
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
2489
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
2490 restore_fpu_state ();
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2491 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2492
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2493 return retval;
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2494
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2495 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2496
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2497 octave_unused_parameter (jni_env_arg);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2498 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2499 octave_unused_parameter (val);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2500
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2501 // This shouldn't happen because construction of octave_java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2502 // objects is supposed to be impossible if Java is not available.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2503
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2504 panic_impossible ();
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2505
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2506 #endif
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2507 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2508
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2509 octave_value
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2510 octave_java::do_java_set (const std::string& name, const octave_value& val)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2511 {
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2512 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2513
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2514 return do_java_set (thread_jni_env (), name, val);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2515
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2516 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2517
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2518 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2519 octave_unused_parameter (val);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2520
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2521 // This shouldn't happen because construction of octave_java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2522 // objects is supposed to be impossible if Java is not available.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2523
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2524 panic_impossible ();
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2525
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2526 #endif
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2527 }
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2528
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2529 octave_value
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2530 octave_java::do_java_set (void *jni_env_arg, const std::string& class_name,
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2531 const std::string& name, const octave_value& val)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2532 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2533 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2534
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2535 octave_value retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2536
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2537 JNIEnv *jni_env = TO_JNIENV (jni_env_arg);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2538
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2539 if (jni_env)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2540 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2541 jobject_ref jobj (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2542 jclass_ref jcls (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2543
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2544 if (unbox (jni_env, val, jobj, jcls))
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2545 {
15744
686580b1a934 eliminate most compilation warnings for __java__.cc
John W. Eaton <jwe@octave.org>
parents: 15743
diff changeset
2546 jclass_ref helperClass (jni_env, find_octave_class (jni_env, "org/octave/ClassHelper"));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2547 jmethodID mID = jni_env->GetStaticMethodID (helperClass, "setStaticField",
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2548 "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Object;)V");
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2549 jstring_ref cName (jni_env, jni_env->NewStringUTF (class_name.c_str ()));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2550 jstring_ref fName (jni_env, jni_env->NewStringUTF (name.c_str ()));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2551 jni_env->CallStaticObjectMethod (helperClass, mID, jstring (cName), jstring (fName), jobject (jobj));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2552 check_exception (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2553 }
16078
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
2554
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
2555 restore_fpu_state ();
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2556 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2557
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2558 return retval;
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2559
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2560 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2561
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2562 octave_unused_parameter (jni_env_arg);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2563 octave_unused_parameter (class_name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2564 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2565 octave_unused_parameter (val);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2566
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2567 // This shouldn't happen because construction of octave_java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2568 // objects is supposed to be impossible if Java is not available.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2569
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2570 panic_impossible ();
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2571
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2572 #endif
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2573 }
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2574
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2575 octave_value
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2576 octave_java::do_java_set (const std::string& class_name, const std::string& name,
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2577 const octave_value& val)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2578 {
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2579 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2580
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2581 return do_java_set (thread_jni_env (), class_name, name, val);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2582
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2583 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2584
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2585 octave_unused_parameter (class_name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2586 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2587 octave_unused_parameter (val);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2588
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2589 // This shouldn't happen because construction of octave_java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2590 // objects is supposed to be impossible if Java is not available.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2591
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2592 panic_impossible ();
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2593
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2594 #endif
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2595 }
15736
6faa01ff2967 build: Add --disable-java option to configure (bug #37838).
Rik <rik@octave.org>
parents: 15625
diff changeset
2596
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2597 void
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2598 octave_java::init (void *jobj_arg, void *jcls_arg)
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2599 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2600 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2601
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2602 jobject jobj = TO_JOBJECT (jobj_arg);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2603 jclass jcls = TO_JCLASS (jcls_arg);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2604
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2605 JNIEnv *current_env = thread_jni_env ();
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2606
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2607 if (current_env)
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2608 {
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2609 if (jobj)
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2610 java_object = current_env->NewGlobalRef (jobj);
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2611
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2612 if (jcls)
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2613 java_class = current_env->NewGlobalRef (jcls);
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2614 else if (java_object)
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2615 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2616 jclass_ref ocls (current_env, current_env->GetObjectClass (TO_JOBJECT (java_object)));
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2617 java_class = current_env->NewGlobalRef (jclass (ocls));
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2618 }
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2619
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2620 if (java_class)
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2621 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2622 jclass_ref clsCls (current_env, current_env->GetObjectClass (TO_JCLASS (java_class)));
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2623 jmethodID mID = current_env->GetMethodID (clsCls, "getCanonicalName", "()Ljava/lang/String;");
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2624 jobject_ref resObj (current_env, current_env->CallObjectMethod (TO_JCLASS (java_class), mID));
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2625 java_classname = jstring_to_string (current_env, resObj);
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2626 }
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2627 }
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2628
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2629 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2630
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2631 octave_unused_parameter (jobj_arg);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2632 octave_unused_parameter (jcls_arg);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2633
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2634 // This shouldn't happen because construction of octave_java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2635 // objects is supposed to be impossible if Java is not available.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2636
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2637 panic_impossible ();
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2638
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2639 #endif
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2640 }
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2641
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2642 void
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2643 octave_java::release (void)
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2644 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2645 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2646
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2647 JNIEnv *current_env = thread_jni_env ();
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2648
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2649 if (current_env)
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2650 {
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2651 if (java_object)
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2652 current_env->DeleteGlobalRef (TO_JOBJECT (java_object));
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2653
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2654 if (java_class)
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2655 current_env->DeleteGlobalRef (TO_JCLASS (java_class));
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2656
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2657 java_object = 0;
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2658 java_class = 0;
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2659 }
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2660
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2661 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2662
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2663 // This shouldn't happen because construction of octave_java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2664 // objects is supposed to be impossible if Java is not available.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2665
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2666 panic_impossible ();
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2667
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2668 #endif
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2669 }
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2670
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2671 // DEFUN blocks below must be outside of HAVE_JAVA block so that
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2672 // documentation strings are always available, even when functions are not.
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2673
15879
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
2674 DEFUN (__java_init__, , ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2675 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20797
diff changeset
2676 @deftypefn {} {} __java_init__ ()\n\
15879
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
2677 Internal function used @strong{only} when debugging Java interface.\n\
20163
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20152
diff changeset
2678 \n\
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2679 Function will directly call initialize_java to create an instance of a JVM.\n\
15879
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
2680 @end deftypefn")
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
2681 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2682 #if defined (HAVE_JAVA)
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2683
15879
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
2684 octave_value retval;
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
2685
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
2686 retval = 0;
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
2687
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
2688 initialize_java ();
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
2689
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2690 retval = 1;
15879
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
2691
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
2692 return retval;
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2693
15879
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
2694 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2695
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2696 err_disabled_feature ("__java_init__", "Java");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2697
15879
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
2698 #endif
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
2699 }
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
2700
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
2701 DEFUN (__java_exit__, , ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2702 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20797
diff changeset
2703 @deftypefn {} {} __java_exit__ ()\n\
15879
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
2704 Internal function used @strong{only} when debugging Java interface.\n\
20163
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20152
diff changeset
2705 \n\
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2706 Function will directly call terminate_jvm to destroy the current JVM\n\
15879
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
2707 instance.\n\
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
2708 @end deftypefn")
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
2709 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2710 #if defined (HAVE_JAVA)
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2711
15879
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
2712 terminate_jvm ();
20957
9db35d2042be maint: eliminate special cases of statements after error.
Rik <rik@octave.org>
parents: 20955
diff changeset
2713
9db35d2042be maint: eliminate special cases of statements after error.
Rik <rik@octave.org>
parents: 20955
diff changeset
2714 return ovl ();
9db35d2042be maint: eliminate special cases of statements after error.
Rik <rik@octave.org>
parents: 20955
diff changeset
2715
15879
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
2716 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2717
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2718 err_disabled_feature ("__java_exit__", "Java");
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2719
15879
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
2720 #endif
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
2721 }
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
2722
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2723 DEFUN (javaObject, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2724 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20797
diff changeset
2725 @deftypefn {} {@var{jobj} =} javaObject (@var{classname})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20797
diff changeset
2726 @deftypefnx {} {@var{jobj} =} javaObject (@var{classname}, @var{arg1}, @dots{})\n\
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2727 Create a Java object of class @var{classsname}, by calling the class\n\
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2728 constructor with the arguments @var{arg1}, @dots{}\n\
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2729 \n\
20163
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20152
diff changeset
2730 The first example below creates an uninitialized object, while the second\n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20152
diff changeset
2731 example supplies an initial argument to the constructor.\n\
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2732 \n\
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2733 @example\n\
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2734 @group\n\
15792
12394261da0f doc: tweak docstrings for javaObject and javaArray.
Rik <rik@octave.org>
parents: 15790
diff changeset
2735 x = javaObject (\"java.lang.StringBuffer\")\n\
12394261da0f doc: tweak docstrings for javaObject and javaArray.
Rik <rik@octave.org>
parents: 15790
diff changeset
2736 x = javaObject (\"java.lang.StringBuffer\", \"Initial string\")\n\
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2737 @end group\n\
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2738 @end example\n\
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2739 \n\
15792
12394261da0f doc: tweak docstrings for javaObject and javaArray.
Rik <rik@octave.org>
parents: 15790
diff changeset
2740 @seealso{javaMethod, javaArray}\n\
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2741 @end deftypefn")
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2742 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2743 #if defined (HAVE_JAVA)
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2744
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2745 if (args.length () == 0)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2746 print_usage ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2747
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2748 std::string classname = args(0).xstring_value ("javaObject: CLASSNAME must be a string");
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2749
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2750 initialize_java ();
15790
921912c92102 Deprecate java_invoke, replace with javaMethod.
Rik <rik@octave.org>
parents: 15771
diff changeset
2751
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2752 JNIEnv *current_env = thread_jni_env ();
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2753
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2754 octave_value_list tmp;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2755 for (int i=1; i<args.length (); i++)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2756 tmp(i-1) = args(i);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2757
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2758 return ovl (octave_java::do_javaObject (current_env, classname, tmp));
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20765
diff changeset
2759
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20765
diff changeset
2760 #else
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2761
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2762 octave_unused_parameter (args);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2763
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2764 err_disabled_feature ("javaObject", "Java");
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2765
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20765
diff changeset
2766 #endif
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2767 }
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2768
15825
9854666df787 ov-java.cc: tests added for javaObject and javaMethod
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 15824
diff changeset
2769 /*
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2770 ## The tests below merely check if javaObject works at all. Whether
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2771 ## it works properly, i.e., creates the right values, is a matter of
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2772 ## Java itself. Create a Short and check if it really is a short, i.e.,
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2773 ## whether it overflows.
15825
9854666df787 ov-java.cc: tests added for javaObject and javaMethod
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 15824
diff changeset
2774 %!testif HAVE_JAVA
9854666df787 ov-java.cc: tests added for javaObject and javaMethod
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 15824
diff changeset
2775 %! assert (javaObject ("java.lang.Short", 40000).doubleValue < 0);
9854666df787 ov-java.cc: tests added for javaObject and javaMethod
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 15824
diff changeset
2776 */
9854666df787 ov-java.cc: tests added for javaObject and javaMethod
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 15824
diff changeset
2777
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2778 DEFUN (javaMethod, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2779 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20797
diff changeset
2780 @deftypefn {} {@var{ret} =} javaMethod (@var{methodname}, @var{obj})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20797
diff changeset
2781 @deftypefnx {} {@var{ret} =} javaMethod (@var{methodname}, @var{obj}, @var{arg1}, @dots{})\n\
15806
01d4f742d75d doc: Re-organize and improve Java Interface documentation.
Rik <rik@octave.org>
parents: 15800
diff changeset
2782 Invoke the method @var{methodname} on the Java object @var{obj} with the\n\
20163
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20152
diff changeset
2783 arguments @var{arg1}, @dots{}.\n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20152
diff changeset
2784 \n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20152
diff changeset
2785 For static methods, @var{obj} can be a string representing the fully\n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20152
diff changeset
2786 qualified name of the corresponding class.\n\
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2787 \n\
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2788 When @var{obj} is a regular Java object, structure-like indexing can be\n\
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2789 used as a shortcut syntax. For instance, the two following statements are\n\
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2790 equivalent\n\
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2791 \n\
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2792 @example\n\
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2793 @group\n\
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2794 ret = javaMethod (\"method1\", x, 1.0, \"a string\")\n\
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2795 ret = x.method1 (1.0, \"a string\")\n\
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2796 @end group\n\
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2797 @end example\n\
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2798 \n\
20163
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20152
diff changeset
2799 @code{javaMethod} returns the result of the method invocation.\n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20152
diff changeset
2800 \n\
15790
921912c92102 Deprecate java_invoke, replace with javaMethod.
Rik <rik@octave.org>
parents: 15771
diff changeset
2801 @seealso{methods, javaObject}\n\
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2802 @end deftypefn")
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2803 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2804 #if defined (HAVE_JAVA)
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2805
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2806 if (args.length () < 2)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2807 print_usage ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2808
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2809 std::string methodname = args(0).xstring_value ("javaMethod: METHODNAME must be a string");
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2810
15790
921912c92102 Deprecate java_invoke, replace with javaMethod.
Rik <rik@octave.org>
parents: 15771
diff changeset
2811 initialize_java ();
921912c92102 Deprecate java_invoke, replace with javaMethod.
Rik <rik@octave.org>
parents: 15771
diff changeset
2812
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2813 JNIEnv *current_env = thread_jni_env ();
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2814
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2815 octave_value retval;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2816
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2817 octave_value_list tmp;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2818 for (int i=2; i<args.length (); i++)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2819 tmp(i-2) = args(i);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2820
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2821 if (args(1).is_java ())
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2822 {
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2823 octave_java *jobj = TO_JAVA (args(1));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2824 retval = jobj->do_javaMethod (current_env, methodname, tmp);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2825 }
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2826 else if (args(1).is_string ())
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2827 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2828 std::string cls = args(1).string_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2829 retval = octave_java::do_javaMethod (current_env, cls, methodname, tmp);
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2830 }
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2831 else
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2832 error ("javaMethod: OBJ must be a Java object or a string");
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2833
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2834 return retval;
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20765
diff changeset
2835
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20765
diff changeset
2836 #else
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2837
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2838 octave_unused_parameter (args);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2839
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2840 err_disabled_feature ("javaMethod", "Java");
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2841
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20765
diff changeset
2842 #endif
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2843 }
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2844
15825
9854666df787 ov-java.cc: tests added for javaObject and javaMethod
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 15824
diff changeset
2845 /*
9854666df787 ov-java.cc: tests added for javaObject and javaMethod
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 15824
diff changeset
2846 %!testif HAVE_JAVA
20152
8187a66039e4 Don't run Java BIST tests if HAVA_JAVA is false.
Rik <rik@octave.org>
parents: 20124
diff changeset
2847 %! ## Check for valid first two Java version numbers
8187a66039e4 Don't run Java BIST tests if HAVA_JAVA is false.
Rik <rik@octave.org>
parents: 20124
diff changeset
2848 %! jver = strsplit (javaMethod ("getProperty", "java.lang.System", "java.version"), ".");
15825
9854666df787 ov-java.cc: tests added for javaObject and javaMethod
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 15824
diff changeset
2849 %! assert (isfinite (str2double (jver{1})) && isfinite (str2double (jver{2})));
9854666df787 ov-java.cc: tests added for javaObject and javaMethod
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 15824
diff changeset
2850 */
9854666df787 ov-java.cc: tests added for javaObject and javaMethod
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 15824
diff changeset
2851
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2852 DEFUN (__java_get__, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2853 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20797
diff changeset
2854 @deftypefn {} {@var{val} =} __java_get__ (@var{obj}, @var{name})\n\
20163
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20152
diff changeset
2855 Get the value of the field @var{name} of the Java object @var{obj}.\n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20152
diff changeset
2856 \n\
21547
ad0599a0acc6 doc: Wrap C++ docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents: 21380
diff changeset
2857 For static fields, @var{obj} can be a string representing the fully\n\
ad0599a0acc6 doc: Wrap C++ docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents: 21380
diff changeset
2858 qualified name of the corresponding class.\n\
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2859 \n\
20163
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20152
diff changeset
2860 When @var{obj} is a regular Java object, structure-like indexing can be used\n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20152
diff changeset
2861 as a shortcut syntax. For instance, the two following statements are\n\
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2862 equivalent\n\
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2863 \n\
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2864 @example\n\
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2865 @group\n\
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2866 __java_get__ (x, \"field1\")\n\
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2867 x.field1\n\
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2868 @end group\n\
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2869 @end example\n\
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2870 \n\
15790
921912c92102 Deprecate java_invoke, replace with javaMethod.
Rik <rik@octave.org>
parents: 15771
diff changeset
2871 @seealso{__java_set__, javaMethod, javaObject}\n\
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2872 @end deftypefn")
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2873 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2874 #if defined (HAVE_JAVA)
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2875
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2876 if (args.length () != 2)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2877 print_usage ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2878
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2879 std::string name = args(1).string_value ("__java_get__: NAME must be a string");
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2880
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2881 initialize_java ();
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2882
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2883 JNIEnv *current_env = thread_jni_env ();
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2884
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2885 octave_value retval;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2886
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2887 if (args(0).is_java ())
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2888 {
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2889 octave_java *jobj = TO_JAVA (args(0));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2890 retval = jobj->do_java_get (current_env, name);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2891 }
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2892 else if (args(0).is_string ())
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2893 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2894 std::string cls = args(0).string_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2895 retval = octave_java::do_java_get (current_env, cls, name);
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2896 }
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2897 else
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2898 error ("__java_get__: OBJ must be a Java object or a string");
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2899
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2900 return retval;
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20765
diff changeset
2901
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20765
diff changeset
2902 #else
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2903
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2904 octave_unused_parameter (args);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2905
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2906 err_disabled_feature ("__java_get__", "Java");
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2907
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20765
diff changeset
2908 #endif
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2909 }
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2910
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2911 DEFUN (__java_set__, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2912 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20797
diff changeset
2913 @deftypefn {} {@var{obj} =} __java_set__ (@var{obj}, @var{name}, @var{val})\n\
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2914 Set the value of the field @var{name} of the Java object @var{obj} to\n\
20163
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20152
diff changeset
2915 @var{val}.\n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20152
diff changeset
2916 \n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20152
diff changeset
2917 For static fields, @var{obj} can be a string representing the fully\n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20152
diff changeset
2918 qualified named of the corresponding Java class.\n\
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2919 \n\
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2920 When @var{obj} is a regular Java object, structure-like indexing can be\n\
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2921 used as a shortcut syntax. For instance, the two following statements are\n\
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2922 equivalent\n\
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2923 \n\
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2924 @example\n\
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2925 @group\n\
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2926 __java_set__ (x, \"field1\", val)\n\
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2927 x.field1 = val\n\
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2928 @end group\n\
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2929 @end example\n\
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2930 \n\
15790
921912c92102 Deprecate java_invoke, replace with javaMethod.
Rik <rik@octave.org>
parents: 15771
diff changeset
2931 @seealso{__java_get__, javaMethod, javaObject}\n\
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2932 @end deftypefn")
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2933 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2934 #if defined (HAVE_JAVA)
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2935
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2936 if (args.length () != 3)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2937 print_usage ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2938
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2939 std::string name = args(1).xstring_value ("__java_set__: NAME must be a string");
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2940
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2941 initialize_java ();
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2942
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2943 JNIEnv *current_env = thread_jni_env ();
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2944
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2945 octave_value retval;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2946
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2947 if (args(0).is_java ())
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2948 {
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2949 octave_java *jobj = TO_JAVA (args(0));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2950 retval = jobj->do_java_set (current_env, name, args(2));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2951 }
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2952 else if (args(0).is_string ())
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2953 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2954 std::string cls = args(0).string_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2955 retval = octave_java::do_java_set (current_env, cls, name, args(2));
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2956 }
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2957 else
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2958 error ("__java_set__: OBJ must be a Java object or a string");
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2959
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2960 return retval;
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20765
diff changeset
2961
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20765
diff changeset
2962 #else
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2963
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2964 octave_unused_parameter (args);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2965
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2966 err_disabled_feature ("__java_set__", "Java");
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2967
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20765
diff changeset
2968 #endif
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2969 }
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2970
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2971 DEFUN (java2mat, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2972 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20797
diff changeset
2973 @deftypefn {} {} java2mat (@var{javaobj})\n\
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2974 Undocumented internal function.\n\
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2975 @end deftypefn")
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2976 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2977 #if defined (HAVE_JAVA)
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2978
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2979 if (args.length () != 1)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2980 print_usage ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2981
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2982 initialize_java ();
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2983
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2984 JNIEnv *current_env = thread_jni_env ();
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2985
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2986 octave_value_list retval;
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20765
diff changeset
2987
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20765
diff changeset
2988 if (args(0).is_java ())
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2989 {
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20765
diff changeset
2990 octave_java *jobj = TO_JAVA (args(0));
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2991 retval = ovl (box_more (current_env, jobj->to_java (), 0));
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
2992 }
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2993 else
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2994 retval = ovl (args(0));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2995
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
2996 return retval;
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20765
diff changeset
2997
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20765
diff changeset
2998 #else
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2999
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3000 octave_unused_parameter (args);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3001
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3002 err_disabled_feature ("java2mat", "Java");
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3003
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20765
diff changeset
3004 #endif
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3005 }
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3006
15800
d9b8333df5e4 Deprecate java_debug, java_convert_matrix, java_unsigned_conversion.
Rik <rik@octave.org>
parents: 15798
diff changeset
3007 DEFUN (java_matrix_autoconversion, args, nargout,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3008 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20797
diff changeset
3009 @deftypefn {} {@var{val} =} java_matrix_autoconversion ()\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20797
diff changeset
3010 @deftypefnx {} {@var{old_val} =} java_matrix_autoconversion (@var{new_val})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20797
diff changeset
3011 @deftypefnx {} {} java_matrix_autoconversion (@var{new_val}, \"local\")\n\
15800
d9b8333df5e4 Deprecate java_debug, java_convert_matrix, java_unsigned_conversion.
Rik <rik@octave.org>
parents: 15798
diff changeset
3012 Query or set the internal variable that controls whether Java arrays are\n\
20163
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20152
diff changeset
3013 automatically converted to Octave matrices.\n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20152
diff changeset
3014 \n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20152
diff changeset
3015 The default value is false.\n\
15800
d9b8333df5e4 Deprecate java_debug, java_convert_matrix, java_unsigned_conversion.
Rik <rik@octave.org>
parents: 15798
diff changeset
3016 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16766
diff changeset
3017 When called from inside a function with the @qcode{\"local\"} option, the\n\
20163
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20152
diff changeset
3018 variable is changed locally for the function and any subroutines it calls.\n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16766
diff changeset
3019 The original variable value is restored when exiting the function.\n\
15800
d9b8333df5e4 Deprecate java_debug, java_convert_matrix, java_unsigned_conversion.
Rik <rik@octave.org>
parents: 15798
diff changeset
3020 @seealso{java_unsigned_autoconversion, debug_java}\n\
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3021 @end deftypefn")
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3022 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3023 #if defined (HAVE_JAVA)
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3024
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3025 return SET_INTERNAL_VARIABLE (java_matrix_autoconversion);
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3026
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3027 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3028
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3029 octave_unused_parameter (args);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3030 octave_unused_parameter (nargout);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3031
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3032 err_disabled_feature ("java_matrix_autoconversion", "Java");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3033
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3034 #endif
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3035 }
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3036
15800
d9b8333df5e4 Deprecate java_debug, java_convert_matrix, java_unsigned_conversion.
Rik <rik@octave.org>
parents: 15798
diff changeset
3037 DEFUN (java_unsigned_autoconversion, args, nargout,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3038 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20797
diff changeset
3039 @deftypefn {} {@var{val} =} java_unsigned_autoconversion ()\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20797
diff changeset
3040 @deftypefnx {} {@var{old_val} =} java_unsigned_autoconversion (@var{new_val})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20797
diff changeset
3041 @deftypefnx {} {} java_unsigned_autoconversion (@var{new_val}, \"local\")\n\
15800
d9b8333df5e4 Deprecate java_debug, java_convert_matrix, java_unsigned_conversion.
Rik <rik@octave.org>
parents: 15798
diff changeset
3042 Query or set the internal variable that controls how integer classes are\n\
20163
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20152
diff changeset
3043 converted when @code{java_matrix_autoconversion} is enabled.\n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20152
diff changeset
3044 \n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20152
diff changeset
3045 When enabled, Java arrays of class Byte or Integer are converted to matrices\n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20152
diff changeset
3046 of class uint8 or uint32 respectively. The default value is true.\n\
15800
d9b8333df5e4 Deprecate java_debug, java_convert_matrix, java_unsigned_conversion.
Rik <rik@octave.org>
parents: 15798
diff changeset
3047 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16766
diff changeset
3048 When called from inside a function with the @qcode{\"local\"} option, the\n\
20163
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20152
diff changeset
3049 variable is changed locally for the function and any subroutines it calls.\n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16766
diff changeset
3050 The original variable value is restored when exiting the function.\n\
15800
d9b8333df5e4 Deprecate java_debug, java_convert_matrix, java_unsigned_conversion.
Rik <rik@octave.org>
parents: 15798
diff changeset
3051 @seealso{java_matrix_autoconversion, debug_java}\n\
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3052 @end deftypefn")
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3053 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3054 #if defined (HAVE_JAVA)
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3055
15800
d9b8333df5e4 Deprecate java_debug, java_convert_matrix, java_unsigned_conversion.
Rik <rik@octave.org>
parents: 15798
diff changeset
3056 return SET_INTERNAL_VARIABLE (java_unsigned_autoconversion);
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3057
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3058 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3059
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3060 octave_unused_parameter (args);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3061 octave_unused_parameter (nargout);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3062
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3063 err_disabled_feature ("java_unsigned_autoconversion", "Java");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3064
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3065 #endif
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3066 }
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3067
15800
d9b8333df5e4 Deprecate java_debug, java_convert_matrix, java_unsigned_conversion.
Rik <rik@octave.org>
parents: 15798
diff changeset
3068 DEFUN (debug_java, args, nargout,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3069 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20797
diff changeset
3070 @deftypefn {} {@var{val} =} debug_java ()\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20797
diff changeset
3071 @deftypefnx {} {@var{old_val} =} debug_java (@var{new_val})\n\
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20797
diff changeset
3072 @deftypefnx {} {} debug_java (@var{new_val}, \"local\")\n\
15800
d9b8333df5e4 Deprecate java_debug, java_convert_matrix, java_unsigned_conversion.
Rik <rik@octave.org>
parents: 15798
diff changeset
3073 Query or set the internal variable that determines whether extra debugging\n\
d9b8333df5e4 Deprecate java_debug, java_convert_matrix, java_unsigned_conversion.
Rik <rik@octave.org>
parents: 15798
diff changeset
3074 information regarding the initialization of the JVM and any Java exceptions\n\
d9b8333df5e4 Deprecate java_debug, java_convert_matrix, java_unsigned_conversion.
Rik <rik@octave.org>
parents: 15798
diff changeset
3075 is printed.\n\
d9b8333df5e4 Deprecate java_debug, java_convert_matrix, java_unsigned_conversion.
Rik <rik@octave.org>
parents: 15798
diff changeset
3076 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16766
diff changeset
3077 When called from inside a function with the @qcode{\"local\"} option, the\n\
20163
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20152
diff changeset
3078 variable is changed locally for the function and any subroutines it calls.\n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16766
diff changeset
3079 The original variable value is restored when exiting the function.\n\
15800
d9b8333df5e4 Deprecate java_debug, java_convert_matrix, java_unsigned_conversion.
Rik <rik@octave.org>
parents: 15798
diff changeset
3080 @seealso{java_matrix_autoconversion, java_unsigned_autoconversion}\n\
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3081 @end deftypefn")
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3082 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3083 #if defined (HAVE_JAVA)
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3084
15800
d9b8333df5e4 Deprecate java_debug, java_convert_matrix, java_unsigned_conversion.
Rik <rik@octave.org>
parents: 15798
diff changeset
3085 return SET_INTERNAL_VARIABLE (debug_java);
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3086
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3087 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3088
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3089 octave_unused_parameter (args);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3090 octave_unused_parameter (nargout);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3091
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3092 err_disabled_feature ("debug_java", "Java");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3093
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3094 #endif
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3095 }
15736
6faa01ff2967 build: Add --disable-java option to configure (bug #37838).
Rik <rik@octave.org>
parents: 15625
diff changeset
3096
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3097 // Outside of #if defined (HAVE_JAVA) because it is desirable to be able
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3098 // to test for the presence of a Java object without having Java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3099 // installed.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3100
15770
e61405133a76 Add new isjava function.
Rik <rik@octave.org>
parents: 15763
diff changeset
3101 DEFUN (isjava, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3102 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20797
diff changeset
3103 @deftypefn {} {} isjava (@var{x})\n\
15770
e61405133a76 Add new isjava function.
Rik <rik@octave.org>
parents: 15763
diff changeset
3104 Return true if @var{x} is a Java object.\n\
15790
921912c92102 Deprecate java_invoke, replace with javaMethod.
Rik <rik@octave.org>
parents: 15771
diff changeset
3105 @seealso{class, typeinfo, isa, javaObject}\n\
15770
e61405133a76 Add new isjava function.
Rik <rik@octave.org>
parents: 15763
diff changeset
3106 @end deftypefn")
e61405133a76 Add new isjava function.
Rik <rik@octave.org>
parents: 15763
diff changeset
3107 {
e61405133a76 Add new isjava function.
Rik <rik@octave.org>
parents: 15763
diff changeset
3108 if (args.length () != 1)
e61405133a76 Add new isjava function.
Rik <rik@octave.org>
parents: 15763
diff changeset
3109 print_usage ();
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20765
diff changeset
3110
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3111 return ovl (args(0).is_java ());
15770
e61405133a76 Add new isjava function.
Rik <rik@octave.org>
parents: 15763
diff changeset
3112 }
e61405133a76 Add new isjava function.
Rik <rik@octave.org>
parents: 15763
diff changeset
3113
20120
2db2db2df55b Automatically convert arrays of java primitives into Octave types (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20028
diff changeset
3114 /*
20152
8187a66039e4 Don't run Java BIST tests if HAVA_JAVA is false.
Rik <rik@octave.org>
parents: 20124
diff changeset
3115 ## Check automatic conversion of java primitive arrays into octave types.
8187a66039e4 Don't run Java BIST tests if HAVA_JAVA is false.
Rik <rik@octave.org>
parents: 20124
diff changeset
3116 %!testif HAVE_JAVA
8187a66039e4 Don't run Java BIST tests if HAVA_JAVA is false.
Rik <rik@octave.org>
parents: 20124
diff changeset
3117 %! assert (javaObject ("java.lang.String", "hello").getBytes (),
8187a66039e4 Don't run Java BIST tests if HAVA_JAVA is false.
Rik <rik@octave.org>
parents: 20124
diff changeset
3118 %! int8 ([104 101 108 108 111]'));
8187a66039e4 Don't run Java BIST tests if HAVA_JAVA is false.
Rik <rik@octave.org>
parents: 20124
diff changeset
3119
8187a66039e4 Don't run Java BIST tests if HAVA_JAVA is false.
Rik <rik@octave.org>
parents: 20124
diff changeset
3120 ## Check automatic conversion of octave types into java primitive arrays.
8187a66039e4 Don't run Java BIST tests if HAVA_JAVA is false.
Rik <rik@octave.org>
parents: 20124
diff changeset
3121 ## Note that uint8 is casted to int8.
8187a66039e4 Don't run Java BIST tests if HAVA_JAVA is false.
Rik <rik@octave.org>
parents: 20124
diff changeset
3122 %!testif HAVE_JAVA
8187a66039e4 Don't run Java BIST tests if HAVA_JAVA is false.
Rik <rik@octave.org>
parents: 20124
diff changeset
3123 %! assert (javaMethod ("binarySearch", "java.util.Arrays", [90 100 255], 255), 2);
8187a66039e4 Don't run Java BIST tests if HAVA_JAVA is false.
Rik <rik@octave.org>
parents: 20124
diff changeset
3124 %! assert (javaMethod ("binarySearch", "java.util.Arrays", uint8 ([90 100 255]), uint8 (255)) < 0);
8187a66039e4 Don't run Java BIST tests if HAVA_JAVA is false.
Rik <rik@octave.org>
parents: 20124
diff changeset
3125 %! assert (javaMethod ("binarySearch", "java.util.Arrays", uint8 ([90 100 128]), uint8 (128)) < 0);
8187a66039e4 Don't run Java BIST tests if HAVA_JAVA is false.
Rik <rik@octave.org>
parents: 20124
diff changeset
3126 %! assert (javaMethod ("binarySearch", "java.util.Arrays", uint8 ([90 100 127]), uint8 (127)), 2);
8187a66039e4 Don't run Java BIST tests if HAVA_JAVA is false.
Rik <rik@octave.org>
parents: 20124
diff changeset
3127 %! assert (javaMethod ("binarySearch", "java.util.Arrays", uint16 ([90 100 128]), uint16 (128)), 2);
8187a66039e4 Don't run Java BIST tests if HAVA_JAVA is false.
Rik <rik@octave.org>
parents: 20124
diff changeset
3128
8187a66039e4 Don't run Java BIST tests if HAVA_JAVA is false.
Rik <rik@octave.org>
parents: 20124
diff changeset
3129 ## Check we can create objects that wrap java literals (bug #38821).
8187a66039e4 Don't run Java BIST tests if HAVA_JAVA is false.
Rik <rik@octave.org>
parents: 20124
diff changeset
3130 %!testif HAVE_JAVA
8187a66039e4 Don't run Java BIST tests if HAVA_JAVA is false.
Rik <rik@octave.org>
parents: 20124
diff changeset
3131 %! assert (class (javaObject ("java.lang.Byte", uint8 (1))), "java.lang.Byte");
8187a66039e4 Don't run Java BIST tests if HAVA_JAVA is false.
Rik <rik@octave.org>
parents: 20124
diff changeset
3132 %! assert (class (javaObject ("java.lang.Byte", int8 (1))), "java.lang.Byte");
8187a66039e4 Don't run Java BIST tests if HAVA_JAVA is false.
Rik <rik@octave.org>
parents: 20124
diff changeset
3133 %! assert (class (javaObject ("java.lang.Short", uint16 (1))), "java.lang.Short");
8187a66039e4 Don't run Java BIST tests if HAVA_JAVA is false.
Rik <rik@octave.org>
parents: 20124
diff changeset
3134 %! assert (class (javaObject ("java.lang.Short", int16 (1))), "java.lang.Short");
20260
137f183b7dee Fix conversion from string cell array into java's String[] (bug #45290)
Carnë Draug <carandraug@octave.org>
parents: 20250
diff changeset
3135
137f183b7dee Fix conversion from string cell array into java's String[] (bug #45290)
Carnë Draug <carandraug@octave.org>
parents: 20250
diff changeset
3136 ## Automatic conversion from string cell array into String[] (bug #45290)
137f183b7dee Fix conversion from string cell array into java's String[] (bug #45290)
Carnë Draug <carandraug@octave.org>
parents: 20250
diff changeset
3137 %!testif HAVE_JAVA
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21547
diff changeset
3138 %! assert (javaMethod ("binarySearch", "java.util.Arrays", {"aaa", "bbb", "ccc", "zzz"}, "aaa"), 0);
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21547
diff changeset
3139 %! assert (javaMethod ("binarySearch", "java.util.Arrays", {"aaa", "bbb", "ccc", "zzz"}, "zzz"), 3);
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21547
diff changeset
3140 %! assert (javaMethod ("binarySearch", "java.util.Arrays", {"aaa", "bbb", "ccc", "zzz"}, "hhh") < 0);
20120
2db2db2df55b Automatically convert arrays of java primitives into Octave types (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20028
diff changeset
3141 */