Thou shalt not (just) match for English error messages.
[p5sagit/p5-mst-13.2.git] / jpl / JNI / JNI.pm
1 package JNI;
2
3 use strict;
4 use Carp;
5 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $AUTOLOAD $JVM @JVM_ARGS $JAVALIB);
6
7 require Exporter;
8 require DynaLoader;
9 require AutoLoader;
10
11 @ISA = qw(Exporter DynaLoader);
12
13 @EXPORT = qw(
14         JNI_ABORT
15         JNI_COMMIT
16         JNI_ERR
17         JNI_FALSE
18         JNI_H
19         JNI_OK
20         JNI_TRUE
21         GetVersion
22         DefineClass
23         FindClass
24         GetSuperclass
25         IsAssignableFrom
26         Throw
27         ThrowNew
28         ExceptionOccurred
29         ExceptionDescribe
30         ExceptionClear
31         FatalError
32         NewGlobalRef
33         DeleteGlobalRef
34         DeleteLocalRef
35         IsSameObject
36         AllocObject
37         NewObject
38         NewObjectA
39         GetObjectClass
40         IsInstanceOf
41         GetMethodID
42         CallObjectMethod
43         CallObjectMethodA
44         CallBooleanMethod
45         CallBooleanMethodA
46         CallByteMethod
47         CallByteMethodA
48         CallCharMethod
49         CallCharMethodA
50         CallShortMethod
51         CallShortMethodA
52         CallIntMethod
53         CallIntMethodA
54         CallLongMethod
55         CallLongMethodA
56         CallFloatMethod
57         CallFloatMethodA
58         CallDoubleMethod
59         CallDoubleMethodA
60         CallVoidMethod
61         CallVoidMethodA
62         CallNonvirtualObjectMethod
63         CallNonvirtualObjectMethodA
64         CallNonvirtualBooleanMethod
65         CallNonvirtualBooleanMethodA
66         CallNonvirtualByteMethod
67         CallNonvirtualByteMethodA
68         CallNonvirtualCharMethod
69         CallNonvirtualCharMethodA
70         CallNonvirtualShortMethod
71         CallNonvirtualShortMethodA
72         CallNonvirtualIntMethod
73         CallNonvirtualIntMethodA
74         CallNonvirtualLongMethod
75         CallNonvirtualLongMethodA
76         CallNonvirtualFloatMethod
77         CallNonvirtualFloatMethodA
78         CallNonvirtualDoubleMethod
79         CallNonvirtualDoubleMethodA
80         CallNonvirtualVoidMethod
81         CallNonvirtualVoidMethodA
82         GetFieldID
83         GetObjectField
84         GetBooleanField
85         GetByteField
86         GetCharField
87         GetShortField
88         GetIntField
89         GetLongField
90         GetFloatField
91         GetDoubleField
92         SetObjectField
93         SetBooleanField
94         SetByteField
95         SetCharField
96         SetShortField
97         SetIntField
98         SetLongField
99         SetFloatField
100         SetDoubleField
101         GetStaticMethodID
102         CallStaticObjectMethod
103         CallStaticObjectMethodA
104         CallStaticBooleanMethod
105         CallStaticBooleanMethodA
106         CallStaticByteMethod
107         CallStaticByteMethodA
108         CallStaticCharMethod
109         CallStaticCharMethodA
110         CallStaticShortMethod
111         CallStaticShortMethodA
112         CallStaticIntMethod
113         CallStaticIntMethodA
114         CallStaticLongMethod
115         CallStaticLongMethodA
116         CallStaticFloatMethod
117         CallStaticFloatMethodA
118         CallStaticDoubleMethod
119         CallStaticDoubleMethodA
120         CallStaticVoidMethod
121         CallStaticVoidMethodA
122         GetStaticFieldID
123         GetStaticObjectField
124         GetStaticBooleanField
125         GetStaticByteField
126         GetStaticCharField
127         GetStaticShortField
128         GetStaticIntField
129         GetStaticLongField
130         GetStaticFloatField
131         GetStaticDoubleField
132         SetStaticObjectField
133         SetStaticBooleanField
134         SetStaticByteField
135         SetStaticCharField
136         SetStaticShortField
137         SetStaticIntField
138         SetStaticLongField
139         SetStaticFloatField
140         SetStaticDoubleField
141         NewString
142         GetStringLength
143         GetStringChars
144         NewStringUTF
145         GetStringUTFLength
146         GetStringUTFChars
147         GetArrayLength
148         NewObjectArray
149         GetObjectArrayElement
150         SetObjectArrayElement
151         NewBooleanArray
152         NewByteArray
153         NewCharArray
154         NewShortArray
155         NewIntArray
156         NewLongArray
157         NewFloatArray
158         NewDoubleArray
159         GetBooleanArrayElements
160         GetByteArrayElements
161         GetCharArrayElements
162         GetShortArrayElements
163         GetIntArrayElements
164         GetLongArrayElements
165         GetFloatArrayElements
166         GetDoubleArrayElements
167         GetBooleanArrayRegion
168         GetByteArrayRegion
169         GetCharArrayRegion
170         GetShortArrayRegion
171         GetIntArrayRegion
172         GetLongArrayRegion
173         GetFloatArrayRegion
174         GetDoubleArrayRegion
175         SetBooleanArrayRegion
176         SetByteArrayRegion
177         SetCharArrayRegion
178         SetShortArrayRegion
179         SetIntArrayRegion
180         SetLongArrayRegion
181         SetFloatArrayRegion
182         SetDoubleArrayRegion
183         RegisterNatives
184         UnregisterNatives
185         MonitorEnter
186         MonitorExit
187         GetJavaVM
188 );
189
190 $VERSION = '0.01';
191
192 sub AUTOLOAD {
193     # This AUTOLOAD is used to 'autoload' constants from the constant()
194     # XS function.  If a constant is not found then control is passed
195     # to the AUTOLOAD in AutoLoader.
196
197     my $constname;
198     ($constname = $AUTOLOAD) =~ s/.*:://;
199     my $val = constant($constname, @_ ? $_[0] : 0);
200     if ($! != 0) {
201         if ($! =~ /Invalid/ || $!{EINVAL}) {
202             $AutoLoader::AUTOLOAD = $AUTOLOAD;
203             goto &AutoLoader::AUTOLOAD;
204         }
205         else {
206                 croak "Your vendor has not defined JNI macro $constname";
207         }
208     }
209     eval "sub $AUTOLOAD { $val }";
210     goto &$AUTOLOAD;
211 }
212
213 bootstrap JNI $VERSION;
214
215 if (not $JPL::_env_) {
216     $ENV{JAVA_HOME} ||= "/usr/local/java";
217
218     my ($arch, @CLASSPATH);
219     if ($^O eq 'MSWin32') {
220
221         $arch = 'MSWin32' unless -d "$ENV{JAVA_HOME}/lib/$arch";
222         @CLASSPATH = split(/;/, $ENV{CLASSPATH});
223         @CLASSPATH = "." unless @CLASSPATH;
224         push @CLASSPATH,
225             "$ENV{JAVA_HOME}\\classes",
226             "$ENV{JAVA_HOME}\\lib\\classes.zip";
227
228         $ENV{CLASSPATH} = join(';', @CLASSPATH);
229         $ENV{THREADS_TYPE} ||= "green_threads";
230
231         $JAVALIB = "$ENV{JAVA_HOME}/lib/$arch/$ENV{THREADS_TYPE}";
232         $ENV{LD_LIBRARY_PATH} .= ":$JAVALIB";
233
234         push @JVM_ARGS, "classpath", $ENV{CLASSPATH};
235         print "JVM_ARGS=@JVM_ARGS!\n";
236         $JVM = GetJavaVM("$JAVALIB/javai.dll",@JVM_ARGS);
237
238     } else {
239         chop($arch = `uname -p`);
240         chop($arch = `uname -m`) unless -d "$ENV{JAVA_HOME}/lib/$arch";
241
242         @CLASSPATH = split(/:/, $ENV{CLASSPATH});
243         @CLASSPATH = "." unless @CLASSPATH;
244         push @CLASSPATH,
245             "$ENV{JAVA_HOME}/classes",
246             "$ENV{JAVA_HOME}/lib/classes.zip";
247         $ENV{CLASSPATH} = join(':', @CLASSPATH);
248
249         $ENV{THREADS_TYPE} ||= "green_threads";
250
251         $JAVALIB = "$ENV{JAVA_HOME}/lib/$arch/$ENV{THREADS_TYPE}";
252         $ENV{LD_LIBRARY_PATH} .= ":$JAVALIB";
253         push @JVM_ARGS, "classpath", $ENV{CLASSPATH};
254         print "JVM_ARGS=@JVM_ARGS!\n";
255         $JVM = GetJavaVM("$JAVALIB/libjava.so",@JVM_ARGS);
256     }
257 }
258
259 1;
260 __END__
261
262 =head1 NAME
263
264 JNI - Perl encapsulation of the Java Native Interface
265
266 =head1 SYNOPSIS
267
268   use JNI;
269
270 =head1 DESCRIPTION
271
272 This module provides an encapsulation in Perl of the Java Native Interface.
273
274 =head1 Exported constants
275
276   JNI_ABORT
277   JNI_COMMIT
278   JNI_ERR
279   JNI_FALSE
280   JNI_H
281   JNI_OK
282   JNI_TRUE
283
284
285 =head1 AUTHOR
286
287 Copyright 1998, O'Reilly & Associates, Inc.
288
289 This package may be copied under the same terms as Perl itself.
290
291 =head1 SEE ALSO
292
293 perl(1).
294
295 =cut