1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
use strict ;
use Test ;
BEGIN {
plan(tests => 5) ;
}
use Inline Config =>
DIRECTORY => './_Inline_test' ;
use Inline::Java qw(caught) ;
use Inline (
Java => 'DATA',
) ;
eval {
t121->init() ;
my $t = new t121() ;
ok($t->types_stub(1, 2, 3, 4, 5, 6, 1, 2, "1000"), 1024) ;
ok($t->array_stub([34, 56], ["toto", "789"]), 789 + 34) ;
my $t2 = new t1212() ;
ok($t2->types_stub(1, 2, 3, 4, 5, 6, 1, 2, "1000"), 1024) ;
ok($t->callback_stub(), "toto") ;
ok($t->__get_private()->{proto}->ObjectCount(), 2) ;
} ;
if ($@){
if (caught("java.lang.Throwable")){
$@->printStackTrace() ;
die("Caught Java Exception") ;
}
else{
die $@ ;
}
}
##################################
package t121 ;
sub types {
my $this = shift ;
my $sum = 0 ;
map {$sum += $_} @_ ;
return $sum ;
}
sub array {
my $this = shift ;
my $i = shift ;
my $str = shift ;
return $i->[0] + $str->[1] ;
}
sub callback {
my $this = shift ;
return $this->get_name() ;
}
package main ;
__DATA__
__Java__
import java.io.* ;
import org.perl.inline.java.* ;
class t121 extends InlineJavaPerlNatives {
static public boolean got14(){
return System.getProperty("java.version").startsWith("1.4") ;
}
public t121() throws InlineJavaException {
}
static public void init() throws InlineJavaException {
init("test") ;
}
public String types_stub(byte b, short s, int i, long j, float f, double d,
boolean x, char c, String str){
return types(b, s, i, j, f, d, x, c, str) ;
}
public native String types(byte b, short s, int i, long j, float f, double d,
boolean x, char c, String str) ;
public String array_stub(int i[], String str[]){
return array(i, str) ;
}
private native String array(int i[], String str[]) ;
public String callback_stub(){
return callback() ;
}
public native String callback() ;
public String get_name(){
return "toto" ;
}
} ;
class t1212 extends t121 {
public t1212() throws InlineJavaException {
}
} ;
|