| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# $Header: /cvsroot/javaserver/javaserver/JavaServer/perl/Java.pm,v 1.3 2004/02/25 07:52:15 zzo Exp $ |
|
2
|
|
|
|
|
|
|
# $Revision: 1.3 $ |
|
3
|
|
|
|
|
|
|
# $Log: Java.pm,v $ |
|
4
|
|
|
|
|
|
|
# Revision 1.3 2004/02/25 07:52:15 zzo |
|
5
|
|
|
|
|
|
|
# - Fix test scripts to use local Java.pm & Test & Test2 classes in the |
|
6
|
|
|
|
|
|
|
# com.zzo.javaserver package |
|
7
|
|
|
|
|
|
|
# - added 'destroy' method to Java.pm so y'all can hand destroy objects |
|
8
|
|
|
|
|
|
|
# |
|
9
|
|
|
|
|
|
|
# Revision 1.2 2004/01/19 23:28:59 zzo |
|
10
|
|
|
|
|
|
|
# Moved the java files around to put them in 'com.zzo.javaserver' package |
|
11
|
|
|
|
|
|
|
# Fixed test script |
|
12
|
|
|
|
|
|
|
# |
|
13
|
|
|
|
|
|
|
# Revision 1.1.1.1 2003/11/17 22:08:07 zzo |
|
14
|
|
|
|
|
|
|
# Initial import. |
|
15
|
|
|
|
|
|
|
# |
|
16
|
|
|
|
|
|
|
# Revision 1.16 2003/06/24 17:28:48 mark |
|
17
|
|
|
|
|
|
|
# - Correctly encode parameter value for static set_field calls |
|
18
|
|
|
|
|
|
|
# - 'die' instead of exit on authentication failure |
|
19
|
|
|
|
|
|
|
# - anchor 'false:b' regex in pretty_args |
|
20
|
|
|
|
|
|
|
# - try to make install more platform independent |
|
21
|
|
|
|
|
|
|
# |
|
22
|
|
|
|
|
|
|
# Revision 1.15 2003/04/14 22:50:51 mark |
|
23
|
|
|
|
|
|
|
# allow negative integers, test fix |
|
24
|
|
|
|
|
|
|
# |
|
25
|
|
|
|
|
|
|
# Revision 1.14 2002/09/03 17:26:43 mark |
|
26
|
|
|
|
|
|
|
# bump version # |
|
27
|
|
|
|
|
|
|
# |
|
28
|
|
|
|
|
|
|
# Revision 1.13 2002/09/03 17:21:03 mark |
|
29
|
|
|
|
|
|
|
# Fix Makefile.PL so EXE_FILES are an anon array |
|
30
|
|
|
|
|
|
|
# When checking for ERROR make sure it must begin on beginning of line! |
|
31
|
|
|
|
|
|
|
# Better perldocs |
|
32
|
|
|
|
|
|
|
# |
|
33
|
|
|
|
|
|
|
# Revision 1.12 2001/11/30 19:18:52 mark |
|
34
|
|
|
|
|
|
|
# Windows fix |
|
35
|
|
|
|
|
|
|
# |
|
36
|
|
|
|
|
|
|
# Revision 1.11 2001/08/13 18:36:08 mark |
|
37
|
|
|
|
|
|
|
# Make the auth secret stuff work w/Winblows & Krapple by getting rid of |
|
38
|
|
|
|
|
|
|
# '\015' chars @ end of line |
|
39
|
|
|
|
|
|
|
# |
|
40
|
|
|
|
|
|
|
# Revision 1.10 2001/08/02 16:05:14 mark |
|
41
|
|
|
|
|
|
|
# Fix for Windows authentication |
|
42
|
|
|
|
|
|
|
# |
|
43
|
|
|
|
|
|
|
# Revision 1.9 2001/08/01 21:53:08 mark |
|
44
|
|
|
|
|
|
|
# version to 4.1.1 |
|
45
|
|
|
|
|
|
|
# |
|
46
|
|
|
|
|
|
|
# Revision 1.8 2001/08/01 21:51:38 mark |
|
47
|
|
|
|
|
|
|
# Fixed generic handling of pulling out instance data from 'java' object |
|
48
|
|
|
|
|
|
|
# |
|
49
|
|
|
|
|
|
|
# Revision 1.7 2001/07/29 21:18:37 mark |
|
50
|
|
|
|
|
|
|
# VERSION up to 4.1 |
|
51
|
|
|
|
|
|
|
# |
|
52
|
|
|
|
|
|
|
# Revision 1.6 2001/07/20 22:39:44 mark |
|
53
|
|
|
|
|
|
|
# Allow blank lines for callbacks |
|
54
|
|
|
|
|
|
|
# |
|
55
|
|
|
|
|
|
|
# Revision 1.5 2001/07/17 15:50:25 mark |
|
56
|
|
|
|
|
|
|
# Made sure exceptions are stored in the 'java' object & not the |
|
57
|
|
|
|
|
|
|
# instantiated object. added some convenience functions for this too |
|
58
|
|
|
|
|
|
|
# |
|
59
|
|
|
|
|
|
|
# Revision 1.4 2001/07/13 14:59:51 mark |
|
60
|
|
|
|
|
|
|
# Put eval'ed callbacks in package main by default like it should have been |
|
61
|
|
|
|
|
|
|
# in the first place |
|
62
|
|
|
|
|
|
|
# |
|
63
|
|
|
|
|
|
|
# Revision 1.3 2001/07/10 18:47:36 mark |
|
64
|
|
|
|
|
|
|
# Changed '\r' to more portable '\015' |
|
65
|
|
|
|
|
|
|
# |
|
66
|
|
|
|
|
|
|
# Revision 1.2 2001/07/09 23:05:51 mark |
|
67
|
|
|
|
|
|
|
# Clean up |
|
68
|
|
|
|
|
|
|
# |
|
69
|
|
|
|
|
|
|
# Revision 1.1.1.1 2001/07/09 22:33:57 mark |
|
70
|
|
|
|
|
|
|
# Initial Toss In |
|
71
|
|
|
|
|
|
|
# |
|
72
|
|
|
|
|
|
|
# Revision 1.2 2000/05/15 21:24:37 markt |
|
73
|
|
|
|
|
|
|
# This is da Big Daddy |
|
74
|
|
|
|
|
|
|
# |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
package Java; |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# Perl5 is good enough for me I think |
|
79
|
|
|
|
|
|
|
require 5; |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
## |
|
82
|
|
|
|
|
|
|
# If you 'use strict' you have to do 'no strict 'subs'' 'cuz all Java |
|
83
|
|
|
|
|
|
|
# function calls are AUTOLOAD'ed - sorry. |
|
84
|
|
|
|
|
|
|
## |
|
85
|
|
|
|
|
|
|
|
|
86
|
1
|
|
|
1
|
|
6966
|
use Socket; |
|
|
1
|
|
|
|
|
4396
|
|
|
|
1
|
|
|
|
|
598
|
|
|
87
|
1
|
|
|
1
|
|
866
|
use Symbol; |
|
|
1
|
|
|
|
|
883
|
|
|
|
1
|
|
|
|
|
65
|
|
|
88
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
|
1
|
|
|
|
|
7
|
|
|
|
1
|
|
|
|
|
51
|
|
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# NOTE - you may have to 'use IO::Socket::INET' if yer perl install |
|
91
|
|
|
|
|
|
|
# is cracked... |
|
92
|
1
|
|
|
1
|
|
822
|
use IO::Socket; |
|
|
1
|
|
|
|
|
20607
|
|
|
|
1
|
|
|
|
|
5
|
|
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# Fancy pants array stuff |
|
95
|
1
|
|
|
1
|
|
1884
|
use JavaArray; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
40
|
|
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# Now allow '==' to mimic 'same' functionality |
|
98
|
1
|
|
|
1
|
|
1787
|
use overload '==' => "same", 'fallback' => 1; |
|
|
1
|
|
|
|
|
966
|
|
|
|
1
|
|
|
|
|
6
|
|
|
99
|
|
|
|
|
|
|
|
|
100
|
1
|
|
|
1
|
|
62
|
use vars qw ($AUTOLOAD @ISA $VERSION); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
82
|
|
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
require Exporter; |
|
103
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
$VERSION = '4.7'; |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
|
108
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
|
109
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# This allows declaration use Java ':all'; |
|
112
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
|
113
|
|
|
|
|
|
|
# will save memory. |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# Extremely cheesy |
|
116
|
1
|
|
|
1
|
|
5
|
use constant PARAMETER_SEPARATOR => ""; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
77
|
|
|
117
|
|
|
|
|
|
|
|
|
118
|
1
|
|
|
1
|
|
4
|
use constant NULL_TOKEN => "___NULL___"; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
2985
|
|
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# Preloaded methods go here. |
|
121
|
|
|
|
|
|
|
sub new |
|
122
|
|
|
|
|
|
|
{ |
|
123
|
1
|
|
|
1
|
0
|
15
|
my $self = {}; |
|
124
|
1
|
|
|
|
|
3
|
bless $self, shift; |
|
125
|
1
|
|
|
|
|
8
|
$self->_init(@_); |
|
126
|
0
|
|
|
|
|
0
|
return $self; |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
## |
|
130
|
|
|
|
|
|
|
# When ya first create one of these monsters it'll try to connect |
|
131
|
|
|
|
|
|
|
# to JavaServer running on |
|
132
|
|
|
|
|
|
|
# host => host |
|
133
|
|
|
|
|
|
|
# port => port |
|
134
|
|
|
|
|
|
|
# |
|
135
|
|
|
|
|
|
|
# And the JavaServer will attempt to connect to US on event_port... |
|
136
|
|
|
|
|
|
|
# event_port => event port |
|
137
|
|
|
|
|
|
|
# |
|
138
|
|
|
|
|
|
|
# supplied in 'new' arguments or use defaults |
|
139
|
|
|
|
|
|
|
# 'localhost', 2000 & 2001 |
|
140
|
|
|
|
|
|
|
# |
|
141
|
|
|
|
|
|
|
# Also it'll use old-style arrays if specified. |
|
142
|
|
|
|
|
|
|
sub _init |
|
143
|
|
|
|
|
|
|
{ |
|
144
|
1
|
|
|
1
|
|
4
|
my($self,%attrs) = @_; |
|
145
|
|
|
|
|
|
|
|
|
146
|
1
|
|
50
|
|
|
86
|
$self->{port} = $attrs{port} || 2000; |
|
147
|
1
|
|
50
|
|
|
8
|
$self->{host} = $attrs{host} || "localhost"; |
|
148
|
1
|
|
50
|
|
|
8
|
$self->{event_port} = $attrs{event_port} || 2001; |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
# It's now the default! |
|
151
|
1
|
50
|
|
|
|
4
|
$self->{use_tied_arrays} = 1 unless $attrs{use_old_style_arrays}; |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
## |
|
154
|
|
|
|
|
|
|
# Set up them sockets! |
|
155
|
|
|
|
|
|
|
## |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
# Client/control socket |
|
158
|
1
|
|
|
|
|
17
|
$self->{socket} = IO::Socket::INET->new |
|
159
|
|
|
|
|
|
|
( |
|
160
|
|
|
|
|
|
|
PeerAddr => $self->{host}, |
|
161
|
|
|
|
|
|
|
PeerPort => $self->{port} |
|
162
|
|
|
|
|
|
|
); |
|
163
|
|
|
|
|
|
|
|
|
164
|
1
|
50
|
|
|
|
1389
|
if (!$self->{socket}) |
|
165
|
|
|
|
|
|
|
{ |
|
166
|
1
|
|
|
|
|
557
|
croak("Client socket error: $!"); |
|
167
|
|
|
|
|
|
|
} |
|
168
|
|
|
|
|
|
|
# Make sure we're autoflushed |
|
169
|
0
|
|
|
|
|
0
|
$self->{socket}->autoflush(1); |
|
170
|
|
|
|
|
|
|
|
|
171
|
0
|
|
|
|
|
0
|
my $authSecret = ""; |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
# Check for authorization file & use it! |
|
174
|
0
|
0
|
|
|
|
0
|
if (defined($attrs{authfile})) |
|
175
|
|
|
|
|
|
|
{ |
|
176
|
0
|
0
|
|
|
|
0
|
open(AUTH,$attrs{authfile}) or croak("Could not open ".$attrs{authfile}.": $!\n"); |
|
177
|
0
|
|
|
|
|
0
|
$authSecret=; |
|
178
|
0
|
|
|
|
|
0
|
close(AUTH); |
|
179
|
0
|
|
|
|
|
0
|
$authSecret =~ s/\015//g; # clean up input from Winblows |
|
180
|
0
|
|
|
|
|
0
|
chomp($authSecret); |
|
181
|
|
|
|
|
|
|
} |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
# Send Auth token |
|
184
|
0
|
|
|
|
|
0
|
$self->{socket}->print("AUTH: ".$authSecret."\n"); |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
# Check response |
|
187
|
0
|
|
|
|
|
0
|
my $line = $self->{socket}->getline; |
|
188
|
0
|
|
|
|
|
0
|
$line =~ s/\015//g; # clean up input from Winblows |
|
189
|
0
|
|
|
|
|
0
|
chomp $line; |
|
190
|
|
|
|
|
|
|
|
|
191
|
0
|
0
|
|
|
|
0
|
die("Authentication Failed: $line") unless ($line =~ 'OK'); |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
# Set to '-1' to disable events |
|
194
|
0
|
0
|
|
|
|
0
|
if ($self->{event_port} > 0) |
|
195
|
|
|
|
|
|
|
{ |
|
196
|
|
|
|
|
|
|
# |
|
197
|
|
|
|
|
|
|
# Set up our event_socket server |
|
198
|
|
|
|
|
|
|
# |
|
199
|
0
|
|
|
|
|
0
|
$self->{event_server} = IO::Socket::INET->new |
|
200
|
|
|
|
|
|
|
( |
|
201
|
|
|
|
|
|
|
Listen => 5, |
|
202
|
|
|
|
|
|
|
LocalPort => $self->{event_port}, |
|
203
|
|
|
|
|
|
|
Proto => 'tcp', |
|
204
|
|
|
|
|
|
|
Reuse => 1 |
|
205
|
|
|
|
|
|
|
); |
|
206
|
|
|
|
|
|
|
|
|
207
|
0
|
0
|
|
|
|
0
|
if (!$self->{event_server}) |
|
208
|
|
|
|
|
|
|
{ |
|
209
|
0
|
|
|
|
|
0
|
croak("Couldn't create event_server socket: $!"); |
|
210
|
|
|
|
|
|
|
} |
|
211
|
|
|
|
|
|
|
} |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
## Tell JavaServer what port we want our events on... |
|
214
|
0
|
|
|
|
|
0
|
$self->{socket}->print($self->{event_port}."\n"); |
|
215
|
|
|
|
|
|
|
|
|
216
|
0
|
0
|
|
|
|
0
|
if ($self->{event_port} > 0) |
|
217
|
|
|
|
|
|
|
{ |
|
218
|
|
|
|
|
|
|
# Don't wanna do nuthin' until we hear from JavaServer on our |
|
219
|
|
|
|
|
|
|
# event_server port |
|
220
|
0
|
|
|
|
|
0
|
my $peer_address; |
|
221
|
0
|
|
|
|
|
0
|
($self->{event_socket}, $peer_address) = $self->{event_server}->accept; |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
#my($port, $iaddr) = sockaddr_in($peer_address); |
|
224
|
|
|
|
|
|
|
#$iaddr = inet_ntoa($iaddr); |
|
225
|
|
|
|
|
|
|
#print STDERR "Event port connexion from $iaddr:$port!\n"; |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
# Don't wanna accept any more event_server connexions |
|
228
|
0
|
|
|
|
|
0
|
undef $self->{event_server}; |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
# AutoFlush this bad boy |
|
231
|
|
|
|
|
|
|
# We're only gonna use this monster to read events |
|
232
|
0
|
|
|
|
|
0
|
$self->{event_socket}->autoflush(1); |
|
233
|
|
|
|
|
|
|
} |
|
234
|
|
|
|
|
|
|
} |
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
### |
|
237
|
|
|
|
|
|
|
# This is used to create a new Java object |
|
238
|
|
|
|
|
|
|
### |
|
239
|
|
|
|
|
|
|
sub create_object |
|
240
|
|
|
|
|
|
|
{ |
|
241
|
0
|
|
|
0
|
0
|
0
|
my($self,$what,@args) = @_; |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
# pretty up the arguments for java-land |
|
244
|
0
|
|
|
|
|
0
|
@args = pretty_args(@args); |
|
245
|
|
|
|
|
|
|
|
|
246
|
0
|
|
|
|
|
0
|
local($") = PARAMETER_SEPARATOR; |
|
247
|
0
|
|
|
|
|
0
|
my $resp = $self->send_command_and_get_response("NEW $what(@args)"); |
|
248
|
|
|
|
|
|
|
# |
|
249
|
|
|
|
|
|
|
# Create a new java object |
|
250
|
|
|
|
|
|
|
# |
|
251
|
0
|
|
|
|
|
0
|
$self->new_java_object($resp); |
|
252
|
|
|
|
|
|
|
} |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
# Get callback object so server side can make perl calls |
|
255
|
|
|
|
|
|
|
sub get_callback_object |
|
256
|
|
|
|
|
|
|
{ |
|
257
|
0
|
|
|
0
|
0
|
0
|
my($self) = @_; |
|
258
|
|
|
|
|
|
|
|
|
259
|
0
|
|
|
|
|
0
|
my $resp = $self->send_command_and_get_response("BCK"); |
|
260
|
|
|
|
|
|
|
|
|
261
|
0
|
|
|
|
|
0
|
$self->new_java_object($resp); |
|
262
|
|
|
|
|
|
|
} |
|
263
|
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
# Guess what this does... |
|
265
|
|
|
|
|
|
|
sub create_array |
|
266
|
|
|
|
|
|
|
{ |
|
267
|
0
|
|
|
0
|
0
|
0
|
my($self,$what,@indicies) = @_; |
|
268
|
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
# We don't need to pretty args here.... all assumed to be ints |
|
270
|
|
|
|
|
|
|
# and need to be separated by commans NOT PARAMETER_SEPARATOR |
|
271
|
0
|
|
|
|
|
0
|
local($") = ","; |
|
272
|
0
|
|
|
|
|
0
|
my $resp = $self->send_command_and_get_response("NEW [L$what;(@indicies)"); |
|
273
|
0
|
|
|
|
|
0
|
$self->new_java_object($resp); |
|
274
|
|
|
|
|
|
|
} |
|
275
|
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
# Hmmm... wonder what this does? |
|
277
|
|
|
|
|
|
|
sub set_field |
|
278
|
|
|
|
|
|
|
{ |
|
279
|
0
|
|
|
0
|
0
|
0
|
my($self,$index,@args) = @_; |
|
280
|
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
# pretty up the arguments for java-land |
|
282
|
0
|
|
|
|
|
0
|
@args = pretty_args(@args); |
|
283
|
|
|
|
|
|
|
|
|
284
|
0
|
|
|
|
|
0
|
local($") = PARAMETER_SEPARATOR; |
|
285
|
0
|
|
|
|
|
0
|
my $line; |
|
286
|
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
# Figure out what we're dealing with... |
|
288
|
0
|
0
|
|
|
|
0
|
if ($self->_is_java) |
|
289
|
|
|
|
|
|
|
{ |
|
290
|
|
|
|
|
|
|
# static object |
|
291
|
0
|
|
|
|
|
0
|
$line = "SET $_[1]#$_[2](@args[1..$#args])"; |
|
292
|
0
|
|
|
|
|
0
|
print "STATIC LINE: $line\n"; |
|
293
|
|
|
|
|
|
|
} |
|
294
|
|
|
|
|
|
|
else |
|
295
|
|
|
|
|
|
|
{ |
|
296
|
|
|
|
|
|
|
# instantiated object |
|
297
|
0
|
|
|
|
|
0
|
$line = "SET $self->{name}#$index(@args)"; |
|
298
|
|
|
|
|
|
|
} |
|
299
|
|
|
|
|
|
|
|
|
300
|
0
|
|
|
|
|
0
|
my $resp = $self->send_command_and_get_response($line); |
|
301
|
0
|
|
|
|
|
0
|
$self->new_java_object($resp); |
|
302
|
|
|
|
|
|
|
} |
|
303
|
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
sub get_length |
|
305
|
|
|
|
|
|
|
{ |
|
306
|
|
|
|
|
|
|
# Get an array's length |
|
307
|
0
|
|
|
0
|
0
|
0
|
my($self) = @_; |
|
308
|
0
|
|
|
|
|
0
|
my $line = "GET $self->{name}#LEN"; |
|
309
|
0
|
|
|
|
|
0
|
my $resp = $self->send_command_and_get_response($line); |
|
310
|
|
|
|
|
|
|
# We're just getting a raw integer back here... |
|
311
|
0
|
|
|
|
|
0
|
chomp $resp; |
|
312
|
0
|
|
|
|
|
0
|
$resp; |
|
313
|
|
|
|
|
|
|
} |
|
314
|
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
### |
|
318
|
|
|
|
|
|
|
# Bless the returned string into a 'Java' object |
|
319
|
|
|
|
|
|
|
# & be mindful of if this 'self' already points to a |
|
320
|
|
|
|
|
|
|
# java object or not |
|
321
|
|
|
|
|
|
|
### |
|
322
|
|
|
|
|
|
|
sub new_java_object |
|
323
|
|
|
|
|
|
|
{ |
|
324
|
0
|
|
|
0
|
0
|
0
|
my($self, $line) = @_; |
|
325
|
0
|
|
|
|
|
0
|
chomp $line; |
|
326
|
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
# NULL! |
|
328
|
0
|
0
|
|
|
|
0
|
return 0 if ($line eq 'NUL'); |
|
329
|
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
# |
|
331
|
|
|
|
|
|
|
# If we're creating this object from another one |
|
332
|
|
|
|
|
|
|
# i.e. from a method call |
|
333
|
|
|
|
|
|
|
# pull the 'java' portion outta there... |
|
334
|
0
|
|
|
|
|
0
|
my $java = $self->_get_in_java('java'); |
|
335
|
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
#print STDERR "Created Java Object $line\n"; |
|
337
|
0
|
|
|
|
|
0
|
my $obj = (bless { name => $line, java => $java }, ref $self); |
|
338
|
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
# |
|
340
|
|
|
|
|
|
|
# If we're using the tied array syntax convert this guy into |
|
341
|
|
|
|
|
|
|
# a tied array IF INDEED it is an array that is! |
|
342
|
|
|
|
|
|
|
# |
|
343
|
0
|
0
|
|
|
|
0
|
if ($java->{use_tied_arrays}) |
|
344
|
|
|
|
|
|
|
{ |
|
345
|
0
|
0
|
|
|
|
0
|
if ($line =~ /^\[/) |
|
346
|
|
|
|
|
|
|
{ |
|
347
|
0
|
|
|
|
|
0
|
my @java_object; |
|
348
|
0
|
|
|
|
|
0
|
tie @java_object, 'JavaArray', $obj; |
|
349
|
0
|
|
|
|
|
0
|
return \@java_object; |
|
350
|
|
|
|
|
|
|
} |
|
351
|
|
|
|
|
|
|
} |
|
352
|
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
# Otherwise just return the thang |
|
354
|
0
|
|
|
|
|
0
|
return $obj; |
|
355
|
|
|
|
|
|
|
} |
|
356
|
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
# Gets the client socket |
|
358
|
|
|
|
|
|
|
sub get_socket |
|
359
|
|
|
|
|
|
|
{ |
|
360
|
0
|
|
|
0
|
0
|
0
|
my ($self) = shift; |
|
361
|
0
|
|
|
|
|
0
|
$self->_get_in_java('socket'); |
|
362
|
|
|
|
|
|
|
} |
|
363
|
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
# Gets the incoming event socket |
|
365
|
|
|
|
|
|
|
sub get_event_socket |
|
366
|
|
|
|
|
|
|
{ |
|
367
|
0
|
|
|
0
|
0
|
0
|
my ($self) = shift; |
|
368
|
0
|
|
|
|
|
0
|
$self->_get_in_java('event_socket'); |
|
369
|
|
|
|
|
|
|
} |
|
370
|
|
|
|
|
|
|
|
|
371
|
|
|
|
|
|
|
sub send_line |
|
372
|
|
|
|
|
|
|
{ |
|
373
|
0
|
|
|
0
|
0
|
0
|
my($self,$line) = @_; |
|
374
|
0
|
0
|
0
|
|
|
0
|
return if (!$self || !defined($line)); |
|
375
|
0
|
0
|
|
|
|
0
|
print "Sending line: $line\n" if $DEBUG; |
|
376
|
0
|
|
|
|
|
0
|
$self->get_socket->print("$line\n\n"); |
|
377
|
|
|
|
|
|
|
} |
|
378
|
|
|
|
|
|
|
|
|
379
|
|
|
|
|
|
|
sub send_command_and_get_response |
|
380
|
|
|
|
|
|
|
{ |
|
381
|
0
|
|
|
0
|
0
|
0
|
my($self,$line) = @_; |
|
382
|
0
|
|
|
|
|
0
|
my $resp = ""; |
|
383
|
0
|
0
|
|
|
|
0
|
if ($self->send_line($line)) |
|
384
|
|
|
|
|
|
|
{ |
|
385
|
|
|
|
|
|
|
# The response ends w/a on a line by itself |
|
386
|
0
|
|
|
|
|
0
|
while (1) |
|
387
|
|
|
|
|
|
|
{ |
|
388
|
0
|
|
|
|
|
0
|
my $line; |
|
389
|
0
|
|
|
|
|
0
|
$line = $self->get_socket->getline; |
|
390
|
0
|
0
|
|
|
|
0
|
if (!defined $line) |
|
391
|
|
|
|
|
|
|
{ |
|
392
|
0
|
|
|
|
|
0
|
croak("Error receiving response"); |
|
393
|
|
|
|
|
|
|
} |
|
394
|
0
|
|
|
|
|
0
|
$line =~ s/\015//g; # clean up input from Winblows |
|
395
|
|
|
|
|
|
|
|
|
396
|
|
|
|
|
|
|
# Check for end of response |
|
397
|
0
|
0
|
|
|
|
0
|
last if ($line =~ /^$/); |
|
398
|
|
|
|
|
|
|
|
|
399
|
0
|
|
|
|
|
0
|
$resp .= $line; |
|
400
|
|
|
|
|
|
|
} |
|
401
|
|
|
|
|
|
|
|
|
402
|
0
|
|
|
|
|
0
|
chomp $resp; # clean up last newline |
|
403
|
|
|
|
|
|
|
|
|
404
|
|
|
|
|
|
|
# Pull out the Exception object if it's there |
|
405
|
0
|
0
|
|
|
|
0
|
if ($resp =~ /^ERROR/) |
|
406
|
|
|
|
|
|
|
{ |
|
407
|
|
|
|
|
|
|
# Peel off Exception object if it's there |
|
408
|
0
|
0
|
|
|
|
0
|
if ($resp =~ s/%%%(.*)$//) |
|
409
|
|
|
|
|
|
|
{ |
|
410
|
|
|
|
|
|
|
# & keep track of it in the Java object |
|
411
|
0
|
|
|
|
|
0
|
my $ex_obj = $self->new_java_object($1); |
|
412
|
0
|
|
|
|
|
0
|
$self->_set_in_java('last_exception',$ex_obj); |
|
413
|
|
|
|
|
|
|
} |
|
414
|
0
|
|
|
|
|
0
|
croak($resp); |
|
415
|
|
|
|
|
|
|
} |
|
416
|
|
|
|
|
|
|
|
|
417
|
0
|
|
|
|
|
0
|
return $resp; |
|
418
|
|
|
|
|
|
|
} |
|
419
|
|
|
|
|
|
|
else |
|
420
|
|
|
|
|
|
|
{ |
|
421
|
0
|
|
|
|
|
0
|
croak("Error sending $line"); |
|
422
|
|
|
|
|
|
|
} |
|
423
|
|
|
|
|
|
|
} |
|
424
|
|
|
|
|
|
|
|
|
425
|
|
|
|
|
|
|
# Gets the most recent Exception object |
|
426
|
|
|
|
|
|
|
sub get_exception |
|
427
|
|
|
|
|
|
|
{ |
|
428
|
0
|
|
|
0
|
1
|
0
|
my($self) = @_; |
|
429
|
0
|
|
|
|
|
0
|
$self->_get_in_java('last_exception'); |
|
430
|
|
|
|
|
|
|
} |
|
431
|
|
|
|
|
|
|
|
|
432
|
|
|
|
|
|
|
# |
|
433
|
|
|
|
|
|
|
# Does the nasty work for ya to get the Stack Trace for |
|
434
|
|
|
|
|
|
|
# the most recent Exception |
|
435
|
|
|
|
|
|
|
# Returns array of stack trace lines |
|
436
|
|
|
|
|
|
|
# |
|
437
|
|
|
|
|
|
|
sub get_stack_trace |
|
438
|
|
|
|
|
|
|
{ |
|
439
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
|
440
|
|
|
|
|
|
|
|
|
441
|
0
|
|
|
|
|
0
|
my $exception_object = $self->get_exception; |
|
442
|
|
|
|
|
|
|
|
|
443
|
|
|
|
|
|
|
# Get the Stack Trace - blame Java for this mess! |
|
444
|
0
|
|
|
|
|
0
|
my $string_writer = $self->create_object("java.io.StringWriter"); |
|
445
|
0
|
|
|
|
|
0
|
my $print_writer = $self->create_object("java.io.PrintWriter", $string_writer); |
|
446
|
0
|
|
|
|
|
0
|
$exception_object->printStackTrace($print_writer); |
|
447
|
|
|
|
|
|
|
|
|
448
|
0
|
|
|
|
|
0
|
my $line = $string_writer->toString->get_value; |
|
449
|
0
|
|
|
|
|
0
|
$line =~ s/\015//g; # Get rid of Windows/Krapple nastiness |
|
450
|
0
|
|
|
|
|
0
|
split(/\n/, $line); |
|
451
|
|
|
|
|
|
|
} |
|
452
|
|
|
|
|
|
|
|
|
453
|
|
|
|
|
|
|
## This'll return an objectified field from a static or instantiated reference |
|
454
|
|
|
|
|
|
|
# you ken this call 'get_value' on this monster to string-ify it... |
|
455
|
|
|
|
|
|
|
# Also gets array elements... |
|
456
|
|
|
|
|
|
|
sub get_field |
|
457
|
|
|
|
|
|
|
{ |
|
458
|
0
|
|
|
0
|
0
|
0
|
my($self) = shift; |
|
459
|
0
|
|
|
|
|
0
|
my $resp; |
|
460
|
0
|
0
|
|
|
|
0
|
if ($self->_is_java) |
|
461
|
|
|
|
|
|
|
{ |
|
462
|
|
|
|
|
|
|
# Get static field |
|
463
|
0
|
|
|
|
|
0
|
$resp = $self->send_command_and_get_response("GET $_[0]#$_[1]"); |
|
464
|
|
|
|
|
|
|
} |
|
465
|
|
|
|
|
|
|
else |
|
466
|
|
|
|
|
|
|
{ |
|
467
|
|
|
|
|
|
|
# Get instantiated field |
|
468
|
0
|
|
|
|
|
0
|
$resp = $self->send_command_and_get_response("GET $self->{name}#$_[0]"); |
|
469
|
|
|
|
|
|
|
} |
|
470
|
|
|
|
|
|
|
|
|
471
|
|
|
|
|
|
|
# Objectify it |
|
472
|
0
|
|
|
|
|
0
|
return $self->new_java_object($resp); |
|
473
|
|
|
|
|
|
|
} |
|
474
|
|
|
|
|
|
|
|
|
475
|
|
|
|
|
|
|
## This'll return an STRING value from a static or instantiated reference |
|
476
|
|
|
|
|
|
|
sub get_value |
|
477
|
|
|
|
|
|
|
{ |
|
478
|
0
|
|
|
0
|
0
|
0
|
my($self) = shift; |
|
479
|
0
|
0
|
|
|
|
0
|
if ($self->_is_java) |
|
480
|
|
|
|
|
|
|
{ |
|
481
|
|
|
|
|
|
|
# Get static value |
|
482
|
0
|
|
|
|
|
0
|
$self->send_command_and_get_response("VAL $_[0]"); |
|
483
|
|
|
|
|
|
|
} |
|
484
|
|
|
|
|
|
|
else |
|
485
|
|
|
|
|
|
|
{ |
|
486
|
|
|
|
|
|
|
# Get instantiated field value |
|
487
|
0
|
|
|
|
|
0
|
$self->send_command_and_get_response("VAL $self->{name}"); |
|
488
|
|
|
|
|
|
|
} |
|
489
|
|
|
|
|
|
|
} |
|
490
|
|
|
|
|
|
|
|
|
491
|
|
|
|
|
|
|
# Convert 'perl' type args to 'java' type args |
|
492
|
|
|
|
|
|
|
sub pretty_args |
|
493
|
|
|
|
|
|
|
{ |
|
494
|
|
|
|
|
|
|
## |
|
495
|
|
|
|
|
|
|
# Append type name to each primitive arg |
|
496
|
|
|
|
|
|
|
# Gotta add all them other primitive types here... |
|
497
|
|
|
|
|
|
|
## |
|
498
|
0
|
|
|
0
|
0
|
0
|
foreach (@_) |
|
499
|
|
|
|
|
|
|
{ |
|
500
|
0
|
0
|
0
|
|
|
0
|
if (!defined) |
|
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
501
|
|
|
|
|
|
|
{ |
|
502
|
|
|
|
|
|
|
# Wanna pass 'null' in |
|
503
|
0
|
|
|
|
|
0
|
$_ = NULL_TOKEN; |
|
504
|
|
|
|
|
|
|
} |
|
505
|
|
|
|
|
|
|
elsif (/^-?\d+$/) |
|
506
|
|
|
|
|
|
|
{ |
|
507
|
|
|
|
|
|
|
# If it looks like an INT it is an int... |
|
508
|
0
|
|
|
|
|
0
|
$_ .= ":int"; |
|
509
|
|
|
|
|
|
|
} |
|
510
|
|
|
|
|
|
|
elsif (/^true:b$/i || /^false:b$/i) |
|
511
|
|
|
|
|
|
|
{ |
|
512
|
|
|
|
|
|
|
# Stick that 'oolean' @ the end of ':b'! |
|
513
|
0
|
|
|
|
|
0
|
$_ .= "oolean"; |
|
514
|
|
|
|
|
|
|
} |
|
515
|
|
|
|
|
|
|
elsif (/:char$/i || /:short$/ || /:float$/ || /:double$/ |
|
516
|
|
|
|
|
|
|
|| /:byte$/ || /:long$/) |
|
517
|
|
|
|
|
|
|
{ |
|
518
|
|
|
|
|
|
|
#leave it alone |
|
519
|
|
|
|
|
|
|
} |
|
520
|
|
|
|
|
|
|
elsif (ref $_) |
|
521
|
|
|
|
|
|
|
{ |
|
522
|
|
|
|
|
|
|
# It's a JavaArray - we get the actual underlying |
|
523
|
|
|
|
|
|
|
# 'Java' object by pop'ing the array... |
|
524
|
|
|
|
|
|
|
# who knew? |
|
525
|
0
|
0
|
|
|
|
0
|
if (ref $_ eq 'ARRAY') |
|
526
|
|
|
|
|
|
|
{ |
|
527
|
0
|
|
|
|
|
0
|
$_ = pop @$_; |
|
528
|
|
|
|
|
|
|
} |
|
529
|
|
|
|
|
|
|
|
|
530
|
|
|
|
|
|
|
# It's a Java object already |
|
531
|
0
|
|
|
|
|
0
|
$_ = $_->{name}; |
|
532
|
|
|
|
|
|
|
} |
|
533
|
|
|
|
|
|
|
else |
|
534
|
|
|
|
|
|
|
{ |
|
535
|
|
|
|
|
|
|
# It's a string |
|
536
|
|
|
|
|
|
|
# in case it's an integer w/a ':string' already at the |
|
537
|
|
|
|
|
|
|
# end of it |
|
538
|
|
|
|
|
|
|
# Or it is an encoding string like "Unicdoe:string_UTF" |
|
539
|
|
|
|
|
|
|
|
|
540
|
|
|
|
|
|
|
# Either way we gotta put quotes around it & append |
|
541
|
|
|
|
|
|
|
# it w/:string or w/:string_ |
|
542
|
|
|
|
|
|
|
|
|
543
|
|
|
|
|
|
|
# Put quotes around it |
|
544
|
0
|
|
|
|
|
0
|
$_ = "\"".$_; |
|
545
|
0
|
0
|
|
|
|
0
|
unless (s/:string/\":string/) |
|
546
|
|
|
|
|
|
|
{ |
|
547
|
|
|
|
|
|
|
# Regular string |
|
548
|
0
|
|
|
|
|
0
|
$_ .= "\":string"; |
|
549
|
|
|
|
|
|
|
} |
|
550
|
|
|
|
|
|
|
|
|
551
|
|
|
|
|
|
|
} |
|
552
|
|
|
|
|
|
|
} |
|
553
|
0
|
|
|
|
|
0
|
@_; |
|
554
|
|
|
|
|
|
|
} |
|
555
|
|
|
|
|
|
|
|
|
556
|
|
|
|
|
|
|
sub get_chars_from_dec |
|
557
|
|
|
|
|
|
|
{ |
|
558
|
|
|
|
|
|
|
# Makes 2-byte hex ints... |
|
559
|
0
|
|
|
0
|
0
|
0
|
unpack("H*",pack("n",shift)); |
|
560
|
|
|
|
|
|
|
} |
|
561
|
|
|
|
|
|
|
|
|
562
|
|
|
|
|
|
|
sub create_raw_string |
|
563
|
|
|
|
|
|
|
{ |
|
564
|
|
|
|
|
|
|
# This is dicey!!! |
|
565
|
|
|
|
|
|
|
|
|
566
|
0
|
|
|
0
|
0
|
0
|
my($self,$encoding,$string) = @_; |
|
567
|
|
|
|
|
|
|
|
|
568
|
0
|
|
|
|
|
0
|
my @all_bytes; |
|
569
|
0
|
|
|
|
|
0
|
my @chars = split //, $string; |
|
570
|
0
|
|
|
|
|
0
|
foreach (@chars) |
|
571
|
|
|
|
|
|
|
{ |
|
572
|
|
|
|
|
|
|
# Makes integers outta chars... |
|
573
|
0
|
|
|
|
|
0
|
push @all_bytes, unpack("C",$_); |
|
574
|
|
|
|
|
|
|
} |
|
575
|
|
|
|
|
|
|
|
|
576
|
|
|
|
|
|
|
## @all_bytes is now an array of integer bytes values representing |
|
577
|
|
|
|
|
|
|
# the unicode string |
|
578
|
|
|
|
|
|
|
## |
|
579
|
|
|
|
|
|
|
|
|
580
|
0
|
|
|
|
|
0
|
my $len = @all_bytes; |
|
581
|
0
|
|
|
|
|
0
|
my $line = "BYTE java.lang.String $encoding $len"; |
|
582
|
0
|
|
|
|
|
0
|
$self->send_line($line); |
|
583
|
|
|
|
|
|
|
|
|
584
|
|
|
|
|
|
|
# Wait for response |
|
585
|
0
|
|
|
|
|
0
|
my $resp = $self->get_socket->getline; |
|
586
|
|
|
|
|
|
|
|
|
587
|
|
|
|
|
|
|
# Send bytes |
|
588
|
0
|
|
|
|
|
0
|
local($") = " "; |
|
589
|
0
|
|
|
|
|
0
|
$resp = $self->send_command_and_get_response("@all_bytes"); |
|
590
|
0
|
|
|
|
|
0
|
$self->new_java_object($resp); |
|
591
|
|
|
|
|
|
|
} |
|
592
|
|
|
|
|
|
|
|
|
593
|
|
|
|
|
|
|
sub do_event |
|
594
|
|
|
|
|
|
|
{ |
|
595
|
0
|
|
|
0
|
0
|
0
|
my($self,$object,$func,$callback) = @_; |
|
596
|
|
|
|
|
|
|
|
|
597
|
0
|
|
|
|
|
0
|
my $object_name = $object->{name}; |
|
598
|
0
|
|
|
|
|
0
|
my $resp = $self->send_command_and_get_response("EVT $object_name(\"$func\")"); |
|
599
|
0
|
|
|
|
|
0
|
$func =~ s/listener//i; |
|
600
|
|
|
|
|
|
|
|
|
601
|
|
|
|
|
|
|
## |
|
602
|
|
|
|
|
|
|
# So this'll look like |
|
603
|
|
|
|
|
|
|
# $self->events->java.awt.Frame^234->Window = $callback |
|
604
|
|
|
|
|
|
|
# so all 'Window' events for java.awt.Frame^234 will point |
|
605
|
|
|
|
|
|
|
# to a 2-keyed hash containing the object itself & the callback |
|
606
|
|
|
|
|
|
|
# to callback... |
|
607
|
|
|
|
|
|
|
# |
|
608
|
0
|
0
|
|
|
|
0
|
if ($func =~ s/^add//) |
|
609
|
|
|
|
|
|
|
{ |
|
610
|
0
|
|
|
|
|
0
|
$self->{events}->{$object_name}->{$func} = |
|
611
|
|
|
|
|
|
|
{ |
|
612
|
|
|
|
|
|
|
obj => $object, |
|
613
|
|
|
|
|
|
|
callback => $callback |
|
614
|
|
|
|
|
|
|
}; |
|
615
|
|
|
|
|
|
|
} |
|
616
|
|
|
|
|
|
|
else |
|
617
|
|
|
|
|
|
|
{ |
|
618
|
0
|
|
|
|
|
0
|
$func =~ s/remove//; |
|
619
|
0
|
|
|
|
|
0
|
delete $self->{events}->{$object_name}->{$func}; |
|
620
|
|
|
|
|
|
|
} |
|
621
|
|
|
|
|
|
|
} |
|
622
|
|
|
|
|
|
|
|
|
623
|
|
|
|
|
|
|
## |
|
624
|
|
|
|
|
|
|
# One of our java objects has gone out of scope so tell JavaServer about it |
|
625
|
|
|
|
|
|
|
# OR the main java object is gone & we're done... |
|
626
|
|
|
|
|
|
|
sub DESTROY |
|
627
|
|
|
|
|
|
|
{ |
|
628
|
1
|
|
|
1
|
|
4
|
my($self) = shift; |
|
629
|
1
|
50
|
|
|
|
6
|
if ($self->_is_java) |
|
630
|
|
|
|
|
|
|
{ |
|
631
|
|
|
|
|
|
|
# Entire Java hash going out of scope |
|
632
|
0
|
0
|
|
|
|
0
|
$self->{socket}->close() if ($self->{socket}); |
|
633
|
0
|
0
|
|
|
|
0
|
$self->{event_socket}->close() if ($self->{event_socket}); |
|
634
|
0
|
|
|
|
|
0
|
undef $self; |
|
635
|
|
|
|
|
|
|
} |
|
636
|
|
|
|
|
|
|
else |
|
637
|
|
|
|
|
|
|
{ |
|
638
|
|
|
|
|
|
|
# Plain old scalar - java object |
|
639
|
|
|
|
|
|
|
# Tell JavaServer we're done w/it... |
|
640
|
1
|
|
|
|
|
138
|
my $resp = |
|
641
|
|
|
|
|
|
|
$self->{java}->send_command_and_get_response("BYE $self->{name}"); |
|
642
|
0
|
|
|
|
|
0
|
undef $self; |
|
643
|
|
|
|
|
|
|
} |
|
644
|
|
|
|
|
|
|
} |
|
645
|
|
|
|
|
|
|
|
|
646
|
|
|
|
|
|
|
sub destroy |
|
647
|
|
|
|
|
|
|
{ |
|
648
|
0
|
|
|
0
|
0
|
0
|
my($self) = shift; |
|
649
|
0
|
0
|
|
|
|
0
|
if (!$self->_is_java) |
|
650
|
|
|
|
|
|
|
{ |
|
651
|
0
|
|
|
|
|
0
|
my $resp = |
|
652
|
|
|
|
|
|
|
$self->{java}->send_command_and_get_response("BYE $self->{name}"); |
|
653
|
0
|
|
|
|
|
0
|
undef $self; |
|
654
|
|
|
|
|
|
|
} |
|
655
|
|
|
|
|
|
|
} |
|
656
|
|
|
|
|
|
|
|
|
657
|
|
|
|
|
|
|
## |
|
658
|
|
|
|
|
|
|
# This'll capture all function calls... |
|
659
|
|
|
|
|
|
|
## |
|
660
|
|
|
|
|
|
|
sub AUTOLOAD |
|
661
|
|
|
|
|
|
|
{ |
|
662
|
0
|
|
|
0
|
|
0
|
my($self,@args) = @_; |
|
663
|
0
|
|
|
|
|
0
|
my ($func) = $Java::AUTOLOAD =~ /::(.+)$/; |
|
664
|
0
|
|
|
|
|
0
|
my @goo; |
|
665
|
|
|
|
|
|
|
|
|
666
|
|
|
|
|
|
|
# it's a static call UNLESS $self is an instantiated class |
|
667
|
0
|
0
|
0
|
|
|
0
|
if ($func =~ /_/ && $self->_is_java) |
|
668
|
|
|
|
|
|
|
{ |
|
669
|
|
|
|
|
|
|
# called like $java->java_lang_Class("forName","java.lang.String"); |
|
670
|
|
|
|
|
|
|
# Pull out object name |
|
671
|
0
|
|
|
|
|
0
|
my $obj; |
|
672
|
0
|
|
|
|
|
0
|
($obj = $func) =~ s/_/\./g; |
|
673
|
0
|
|
|
|
|
0
|
push @goo, $obj; |
|
674
|
|
|
|
|
|
|
} |
|
675
|
|
|
|
|
|
|
else |
|
676
|
|
|
|
|
|
|
{ |
|
677
|
|
|
|
|
|
|
# regular method call |
|
678
|
|
|
|
|
|
|
# called like $frame->setSize(200,200); |
|
679
|
|
|
|
|
|
|
# Pull out object name & function name |
|
680
|
0
|
|
|
|
|
0
|
push @goo, $self->{name}, $func; |
|
681
|
|
|
|
|
|
|
} |
|
682
|
|
|
|
|
|
|
|
|
683
|
0
|
|
|
|
|
0
|
return base_call($self,@goo,@args); |
|
684
|
|
|
|
|
|
|
} |
|
685
|
|
|
|
|
|
|
|
|
686
|
|
|
|
|
|
|
# |
|
687
|
|
|
|
|
|
|
# Make a static function call if yer object ain't in a package... |
|
688
|
|
|
|
|
|
|
# |
|
689
|
|
|
|
|
|
|
# Called like |
|
690
|
|
|
|
|
|
|
# $java->static_call("MyStaticClass","function_name","param1","param2"....); |
|
691
|
|
|
|
|
|
|
# |
|
692
|
|
|
|
|
|
|
sub static_call |
|
693
|
|
|
|
|
|
|
{ |
|
694
|
0
|
|
|
0
|
0
|
0
|
return base_call(@_); |
|
695
|
|
|
|
|
|
|
} |
|
696
|
|
|
|
|
|
|
|
|
697
|
|
|
|
|
|
|
# wrapper routine for instantiated calls |
|
698
|
|
|
|
|
|
|
sub call |
|
699
|
|
|
|
|
|
|
{ |
|
700
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
|
701
|
0
|
|
|
|
|
0
|
return base_call($self,$self->{name},@_); |
|
702
|
|
|
|
|
|
|
} |
|
703
|
|
|
|
|
|
|
|
|
704
|
|
|
|
|
|
|
sub base_call |
|
705
|
|
|
|
|
|
|
{ |
|
706
|
0
|
|
|
0
|
0
|
0
|
my($self,$obj,$func,@args) = @_; |
|
707
|
0
|
|
|
|
|
0
|
local($") = PARAMETER_SEPARATOR; |
|
708
|
|
|
|
|
|
|
|
|
709
|
|
|
|
|
|
|
# Make args java-friendly |
|
710
|
0
|
|
|
|
|
0
|
@args = pretty_args(@args); |
|
711
|
|
|
|
|
|
|
|
|
712
|
0
|
|
|
|
|
0
|
my $resp=$self->send_command_and_get_response("CAL $obj%$func(@args)"); |
|
713
|
|
|
|
|
|
|
|
|
714
|
|
|
|
|
|
|
# Handle a callback request |
|
715
|
0
|
|
|
|
|
0
|
while ($resp =~ s/^CALLBACK //) |
|
716
|
|
|
|
|
|
|
{ |
|
717
|
|
|
|
|
|
|
# eval it - put it in package main if they don't |
|
718
|
|
|
|
|
|
|
# specify one themselves |
|
719
|
0
|
|
|
|
|
0
|
my $ret = eval("package main;$resp"); |
|
720
|
0
|
0
|
|
|
|
0
|
if ($@) |
|
721
|
|
|
|
|
|
|
{ |
|
722
|
0
|
|
|
|
|
0
|
chomp $@; |
|
723
|
|
|
|
|
|
|
|
|
724
|
|
|
|
|
|
|
# Something went wrong - send a response back |
|
725
|
0
|
|
|
|
|
0
|
$resp = $self->send_command_and_get_response($@); |
|
726
|
|
|
|
|
|
|
|
|
727
|
|
|
|
|
|
|
# & tell someone |
|
728
|
0
|
|
|
|
|
0
|
print STDERR "Remote callback failed: $@"; |
|
729
|
|
|
|
|
|
|
} |
|
730
|
|
|
|
|
|
|
|
|
731
|
0
|
|
0
|
|
|
0
|
$ret ||= ""; |
|
732
|
0
|
|
|
|
|
0
|
$resp = $self->send_command_and_get_response($ret); |
|
733
|
|
|
|
|
|
|
} |
|
734
|
|
|
|
|
|
|
|
|
735
|
0
|
|
|
|
|
0
|
return $self->new_java_object($resp); |
|
736
|
|
|
|
|
|
|
} |
|
737
|
|
|
|
|
|
|
|
|
738
|
|
|
|
|
|
|
## |
|
739
|
|
|
|
|
|
|
# This compares two objects to see if they're the same one! |
|
740
|
|
|
|
|
|
|
# pretty much only useful for event handling I think... |
|
741
|
|
|
|
|
|
|
## |
|
742
|
|
|
|
|
|
|
sub same |
|
743
|
|
|
|
|
|
|
{ |
|
744
|
0
|
|
|
0
|
0
|
0
|
my($self,$other_obj) = @_; |
|
745
|
0
|
|
|
|
|
0
|
$self->{name} eq $other_obj->{name}; |
|
746
|
|
|
|
|
|
|
} |
|
747
|
|
|
|
|
|
|
|
|
748
|
|
|
|
|
|
|
### |
|
749
|
|
|
|
|
|
|
# The Event Loop |
|
750
|
|
|
|
|
|
|
# Just sit around & wait for 1 line from the JVM |
|
751
|
|
|
|
|
|
|
# return undef is there's a problem |
|
752
|
|
|
|
|
|
|
# return whatever the event handler returned if alls kool |
|
753
|
|
|
|
|
|
|
## |
|
754
|
|
|
|
|
|
|
sub go |
|
755
|
|
|
|
|
|
|
{ |
|
756
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
|
757
|
|
|
|
|
|
|
|
|
758
|
|
|
|
|
|
|
# Mite not be using events |
|
759
|
0
|
0
|
|
|
|
0
|
return if (!$self->get_event_socket); |
|
760
|
|
|
|
|
|
|
|
|
761
|
0
|
|
|
|
|
0
|
my $READBITS = 0; |
|
762
|
0
|
|
|
|
|
0
|
vec($READBITS,$self->get_event_socket->fileno,1) = 1; |
|
763
|
0
|
|
|
|
|
0
|
my $nf = select(my $rb = $READBITS,undef,undef,0); |
|
764
|
|
|
|
|
|
|
|
|
765
|
0
|
0
|
|
|
|
0
|
return if (!$nf); |
|
766
|
|
|
|
|
|
|
|
|
767
|
0
|
|
|
|
|
0
|
my $line = $self->get_event_socket->getline; |
|
768
|
0
|
0
|
|
|
|
0
|
return if (!defined $line); # lost somebody |
|
769
|
|
|
|
|
|
|
|
|
770
|
0
|
|
|
|
|
0
|
$self->decipher_event($line); |
|
771
|
|
|
|
|
|
|
} |
|
772
|
|
|
|
|
|
|
|
|
773
|
|
|
|
|
|
|
## |
|
774
|
|
|
|
|
|
|
# Decipher & Dispatch this event |
|
775
|
|
|
|
|
|
|
## |
|
776
|
|
|
|
|
|
|
sub decipher_event |
|
777
|
|
|
|
|
|
|
{ |
|
778
|
0
|
|
|
0
|
0
|
0
|
my($self,$line) = @_; |
|
779
|
|
|
|
|
|
|
|
|
780
|
0
|
|
|
|
|
0
|
chomp $line; |
|
781
|
0
|
|
|
|
|
0
|
$line =~ s/\015//g; # Clean up input from Winblows... |
|
782
|
|
|
|
|
|
|
|
|
783
|
|
|
|
|
|
|
# figure out who wanted this event |
|
784
|
0
|
|
|
|
|
0
|
$line =~ s/^EVE:\s+//; |
|
785
|
|
|
|
|
|
|
|
|
786
|
|
|
|
|
|
|
# Get the two strings |
|
787
|
0
|
|
|
|
|
0
|
my($event_object,$object_name) = split / /,$line; |
|
788
|
|
|
|
|
|
|
|
|
789
|
|
|
|
|
|
|
# Get rid of 'Event' |
|
790
|
0
|
|
|
|
|
0
|
my($event) = $event_object =~ /\.(\w+)Event/; |
|
791
|
|
|
|
|
|
|
|
|
792
|
|
|
|
|
|
|
# Get the hash for this event object |
|
793
|
0
|
|
|
|
|
0
|
my $hash = $self->{events}->{$object_name}->{$event}; |
|
794
|
|
|
|
|
|
|
|
|
795
|
|
|
|
|
|
|
# Make the Event object a 'blessed' java object |
|
796
|
0
|
|
|
|
|
0
|
my $new_event_obj = $self->new_java_object($event_object); |
|
797
|
|
|
|
|
|
|
|
|
798
|
|
|
|
|
|
|
# Call the event callback |
|
799
|
0
|
|
|
|
|
0
|
$hash->{callback}->($hash->{obj},$new_event_obj); |
|
800
|
|
|
|
|
|
|
} |
|
801
|
|
|
|
|
|
|
|
|
802
|
|
|
|
|
|
|
## |
|
803
|
|
|
|
|
|
|
# In case someone wants to do the event loop themselves... |
|
804
|
|
|
|
|
|
|
## |
|
805
|
|
|
|
|
|
|
sub get_event_FH |
|
806
|
|
|
|
|
|
|
{ |
|
807
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
|
808
|
0
|
|
|
|
|
0
|
$self->get_event_socket; |
|
809
|
|
|
|
|
|
|
} |
|
810
|
|
|
|
|
|
|
|
|
811
|
|
|
|
|
|
|
sub _get_in_java |
|
812
|
|
|
|
|
|
|
{ |
|
813
|
0
|
|
|
0
|
|
0
|
my($self,$what) = @_; |
|
814
|
0
|
0
|
|
|
|
0
|
if ($self->_is_java) |
|
815
|
|
|
|
|
|
|
{ |
|
816
|
0
|
0
|
0
|
|
|
0
|
return $self if ($what eq 'java' && !$self->{java}); |
|
817
|
0
|
|
|
|
|
0
|
return $self->{$what}; |
|
818
|
|
|
|
|
|
|
} |
|
819
|
|
|
|
|
|
|
else |
|
820
|
|
|
|
|
|
|
{ |
|
821
|
0
|
0
|
|
|
|
0
|
return $self->{java} if ($what eq 'java'); |
|
822
|
0
|
|
|
|
|
0
|
return $self->{java}->{$what}; |
|
823
|
|
|
|
|
|
|
} |
|
824
|
|
|
|
|
|
|
} |
|
825
|
|
|
|
|
|
|
|
|
826
|
|
|
|
|
|
|
sub _set_in_java |
|
827
|
|
|
|
|
|
|
{ |
|
828
|
0
|
|
|
0
|
|
0
|
my($self,$what,$value) = @_; |
|
829
|
0
|
0
|
|
|
|
0
|
if ($self->_is_java) |
|
830
|
|
|
|
|
|
|
{ |
|
831
|
0
|
|
|
|
|
0
|
return $self->{$what} = $value |
|
832
|
|
|
|
|
|
|
} |
|
833
|
|
|
|
|
|
|
else |
|
834
|
|
|
|
|
|
|
{ |
|
835
|
0
|
|
|
|
|
0
|
$self->{java}->{$what} = $value; |
|
836
|
|
|
|
|
|
|
} |
|
837
|
|
|
|
|
|
|
} |
|
838
|
|
|
|
|
|
|
|
|
839
|
|
|
|
|
|
|
sub _is_java |
|
840
|
|
|
|
|
|
|
{ |
|
841
|
1
|
|
|
1
|
|
6
|
shift->{socket}; |
|
842
|
|
|
|
|
|
|
} |
|
843
|
|
|
|
|
|
|
|
|
844
|
|
|
|
|
|
|
# Autoload methods go after =cut, and are processed by the autosplit program. |
|
845
|
|
|
|
|
|
|
|
|
846
|
|
|
|
|
|
|
1; |
|
847
|
|
|
|
|
|
|
__END__ |