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