261
|
1 |
'From Smalltalk/X, Version:3.3.1 on 16-jan-1998 at 3:08:00 pm' !
|
248
|
2 |
|
17
|
3 |
Object subclass:#Java
|
|
4 |
instanceVariableNames:''
|
201
|
5 |
classVariableNames:'Classes UnresolvedClassRefs ClassPath SourceDirectories JavaHome
|
224
|
6 |
Java_lang_String Java_lang_Class PrettyPrintStyle
|
248
|
7 |
LastArgumentString Threads'
|
17
|
8 |
poolDictionaries:''
|
|
9 |
category:'Java-Support'
|
|
10 |
!
|
|
11 |
|
|
12 |
|
135
|
13 |
!Java class methodsFor:'accessing'!
|
24
|
14 |
|
147
|
15 |
classForName:aString
|
|
16 |
"return a javaClass - either existing or loaded"
|
|
17 |
|
255
|
18 |
|cls loader classURL|
|
147
|
19 |
|
|
20 |
cls := self at:aString.
|
|
21 |
cls isNil ifTrue:[
|
261
|
22 |
('JAVA [info]: late class loading: ' , aString) infoPrintCR.
|
|
23 |
loader := JavaClassReader classLoaderQuerySignal raise.
|
|
24 |
loader isNil ifTrue:[
|
|
25 |
"/ load using default (ST/X) loader
|
|
26 |
cls := JavaClassReader loadClass:aString.
|
|
27 |
] ifFalse:[
|
|
28 |
"/ load using a Java class loader
|
255
|
29 |
"/ classURL := Java as_URL:('file:' , aString , '.class').
|
|
30 |
"/ loader loadClass:classURL.
|
261
|
31 |
loader perform:#'loadClass(Ljava/lang/String;)Ljava/lang/Class;'
|
|
32 |
with:(Java as_String:aString).
|
255
|
33 |
|
261
|
34 |
cls := self at:aString.
|
|
35 |
]
|
147
|
36 |
].
|
|
37 |
^ cls
|
|
38 |
|
255
|
39 |
"Created: / 18.3.1997 / 16:45:57 / cg"
|
|
40 |
"Modified: / 9.1.1998 / 03:43:16 / cg"
|
147
|
41 |
!
|
|
42 |
|
90
|
43 |
classNamed:aString
|
|
44 |
^ self at:aString
|
32
|
45 |
!
|
|
46 |
|
167
|
47 |
java_lang_Class
|
|
48 |
Java_lang_Class isNil ifTrue:[
|
248
|
49 |
Java_lang_Class := self at:'java.lang.Class'
|
167
|
50 |
].
|
|
51 |
^ Java_lang_Class
|
|
52 |
|
|
53 |
"Created: 26.3.1997 / 13:42:59 / cg"
|
|
54 |
"Modified: 26.3.1997 / 13:46:24 / cg"
|
|
55 |
!
|
|
56 |
|
|
57 |
java_lang_String
|
|
58 |
Java_lang_String isNil ifTrue:[
|
248
|
59 |
Java_lang_String := self at:'java.lang.String'
|
167
|
60 |
].
|
|
61 |
^ Java_lang_String
|
|
62 |
|
|
63 |
"Created: 26.3.1997 / 13:43:17 / cg"
|
|
64 |
"Modified: 26.3.1997 / 13:50:21 / cg"
|
76
|
65 |
!
|
|
66 |
|
188
|
67 |
prettyPrintStyle
|
|
68 |
^ PrettyPrintStyle
|
|
69 |
|
|
70 |
"Created: 1.8.1997 / 10:37:57 / cg"
|
248
|
71 |
!
|
|
72 |
|
|
73 |
threads
|
|
74 |
Threads isNil ifTrue:[
|
261
|
75 |
Threads := WeakIdentityDictionary new.
|
248
|
76 |
].
|
|
77 |
^ Threads
|
|
78 |
|
|
79 |
"Created: 26.8.1997 / 19:53:57 / cg"
|
|
80 |
"Modified: 26.8.1997 / 19:55:27 / cg"
|
192
|
81 |
! !
|
|
82 |
|
|
83 |
!Java class methodsFor:'accessing paths'!
|
|
84 |
|
|
85 |
addToClassPath:aPath
|
|
86 |
(ClassPath includes:aPath) ifFalse:[
|
248
|
87 |
ClassPath add:aPath
|
192
|
88 |
]
|
|
89 |
|
|
90 |
"Modified: 7.2.1997 / 19:23:55 / cg"
|
|
91 |
"Created: 1.8.1997 / 21:10:07 / cg"
|
|
92 |
!
|
|
93 |
|
198
|
94 |
addToSourcePath:aPath
|
|
95 |
(SourceDirectories includes:aPath) ifFalse:[
|
248
|
96 |
SourceDirectories add:aPath
|
198
|
97 |
]
|
|
98 |
|
|
99 |
"Modified: 7.2.1997 / 19:23:55 / cg"
|
|
100 |
"Created: 2.8.1997 / 14:12:31 / cg"
|
|
101 |
!
|
|
102 |
|
192
|
103 |
classPath
|
|
104 |
^ ClassPath
|
|
105 |
|
|
106 |
"Created: 7.2.1997 / 19:23:45 / cg"
|
|
107 |
"Modified: 7.2.1997 / 19:23:55 / cg"
|
|
108 |
!
|
|
109 |
|
|
110 |
classPath:aCollectionOfPaths
|
|
111 |
ClassPath := aCollectionOfPaths asOrderedCollection
|
|
112 |
|
|
113 |
"Created: 7.2.1997 / 19:23:45 / cg"
|
|
114 |
!
|
|
115 |
|
201
|
116 |
javaHome
|
|
117 |
^ JavaHome
|
|
118 |
|
|
119 |
"Created: 6.8.1997 / 00:53:19 / cg"
|
|
120 |
!
|
|
121 |
|
|
122 |
javaHome:aPath
|
|
123 |
JavaHome := aPath
|
|
124 |
|
|
125 |
"Created: 6.8.1997 / 00:53:23 / cg"
|
|
126 |
!
|
|
127 |
|
192
|
128 |
removeFromClassPath:aPath
|
|
129 |
(ClassPath includes:aPath) ifTrue:[
|
248
|
130 |
ClassPath remove:aPath
|
192
|
131 |
]
|
|
132 |
|
|
133 |
"Modified: 7.2.1997 / 19:23:55 / cg"
|
|
134 |
"Created: 1.8.1997 / 21:10:21 / cg"
|
188
|
135 |
!
|
|
136 |
|
198
|
137 |
removeFromSourcePath:aPath
|
|
138 |
(SourceDirectories includes:aPath) ifTrue:[
|
248
|
139 |
SourceDirectories remove:aPath
|
198
|
140 |
]
|
|
141 |
|
|
142 |
"Modified: 7.2.1997 / 19:23:55 / cg"
|
|
143 |
"Created: 2.8.1997 / 14:13:01 / cg"
|
|
144 |
!
|
|
145 |
|
76
|
146 |
sourceDirectories
|
|
147 |
^ SourceDirectories
|
|
148 |
!
|
|
149 |
|
|
150 |
sourceDirectories:aCollectionOfPaths
|
|
151 |
SourceDirectories := aCollectionOfPaths asOrderedCollection
|
|
152 |
|
|
153 |
"
|
|
154 |
Java
|
248
|
155 |
sourceDirectories:#(
|
|
156 |
'/phys/ibm3/java/src'
|
|
157 |
)
|
76
|
158 |
"
|
|
159 |
|
|
160 |
|
261
|
161 |
!
|
|
162 |
|
|
163 |
sourcePath
|
|
164 |
^ SourceDirectories
|
|
165 |
|
|
166 |
"Created: / 16.1.1998 / 13:26:55 / cg"
|
24
|
167 |
! !
|
|
168 |
|
135
|
169 |
!Java class methodsFor:'class initialization'!
|
47
|
170 |
|
|
171 |
initAllClasses
|
147
|
172 |
|system|
|
|
173 |
|
102
|
174 |
self initAllStaticFields.
|
147
|
175 |
|
198
|
176 |
system := self classForName:'java.lang.System'.
|
147
|
177 |
system isInitialized ifFalse:[
|
261
|
178 |
system classInit.
|
|
179 |
self initSystemClass.
|
147
|
180 |
].
|
|
181 |
|
47
|
182 |
self allClassesDo:[:cls |
|
261
|
183 |
cls isInitialized ifFalse:[
|
|
184 |
cls classInit
|
|
185 |
]
|
47
|
186 |
]
|
|
187 |
|
252
|
188 |
"Modified: / 4.1.1998 / 14:41:12 / cg"
|
47
|
189 |
!
|
|
190 |
|
102
|
191 |
initAllStaticFields
|
|
192 |
self allClassesDo:[:cls |
|
248
|
193 |
cls initializeStaticFields
|
102
|
194 |
]
|
|
195 |
|
|
196 |
!
|
|
197 |
|
146
|
198 |
initSystemClass
|
198
|
199 |
|system|
|
|
200 |
|
|
201 |
system := Java at:'java.lang.System'.
|
255
|
202 |
system isNil ifTrue:[
|
|
203 |
JavaVM initializeVM.
|
|
204 |
system := Java at:'java.lang.System'.
|
261
|
205 |
system isNil ifTrue:[
|
|
206 |
self error:'no ''java.lang.System'' class'.
|
|
207 |
^ self
|
|
208 |
].
|
255
|
209 |
].
|
200
|
210 |
(system implements:#'initializeSystemClass()V') ifTrue:[
|
255
|
211 |
system invokeStatic:#'initializeSystemClass()V'.
|
198
|
212 |
].
|
146
|
213 |
|
147
|
214 |
"
|
|
215 |
Java initSystemClass
|
215
|
216 |
|
|
217 |
(Java at:'java.lang.System')
|
261
|
218 |
perform:#'getProperty(Ljava/lang/String;)Ljava/lang/String;'
|
255
|
219 |
with:(Java as_String:'java.home')
|
147
|
220 |
"
|
|
221 |
|
261
|
222 |
"Modified: / 15.1.1998 / 00:29:37 / cg"
|
146
|
223 |
!
|
|
224 |
|
76
|
225 |
initialize
|
241
|
226 |
|jHome mozillaHome|
|
116
|
227 |
|
239
|
228 |
jHome := '/usr/local/java/jdk113'.
|
|
229 |
jHome asFilename exists ifFalse:[
|
261
|
230 |
jHome := '/usr/lib/java'.
|
239
|
231 |
].
|
241
|
232 |
mozillaHome := '/usr/local/java/moz3_0/lib_unix'.
|
188
|
233 |
|
239
|
234 |
self javaHome:jHome.
|
|
235 |
self classPath:(Array with:jHome , '/lib/classes').
|
|
236 |
self sourceDirectories:(Array with:jHome , '/src').
|
188
|
237 |
|
241
|
238 |
mozillaHome asFilename exists ifTrue:[
|
261
|
239 |
Java addToClassPath:(mozillaHome , '/classes').
|
241
|
240 |
].
|
188
|
241 |
self initializePrettyPrintStyle.
|
|
242 |
|
76
|
243 |
"
|
|
244 |
Java initialize
|
|
245 |
"
|
|
246 |
|
248
|
247 |
"Modified: 26.8.1997 / 20:06:19 / cg"
|
188
|
248 |
!
|
|
249 |
|
|
250 |
initializePrettyPrintStyle
|
|
251 |
PrettyPrintStyle := IdentityDictionary new.
|
|
252 |
PrettyPrintStyle at:#accessAttribute put:(#color -> (Color red:0 green:0 blue:25)).
|
|
253 |
PrettyPrintStyle at:#className put:(Array with:(#color -> Color black) with:#bold).
|
|
254 |
PrettyPrintStyle at:#methodName put:(Array with:(#color -> Color black) with:#bold).
|
|
255 |
PrettyPrintStyle at:#code put:(#color -> Color black).
|
|
256 |
|
|
257 |
|
|
258 |
"
|
|
259 |
Java initializePrettyPrintStyle
|
|
260 |
"
|
|
261 |
|
|
262 |
"Created: 1.8.1997 / 11:08:43 / cg"
|
|
263 |
"Modified: 1.8.1997 / 11:09:58 / cg"
|
76
|
264 |
!
|
|
265 |
|
47
|
266 |
reinitAllClasses
|
|
267 |
self markAllClassesUninitialized.
|
|
268 |
self initAllClasses
|
252
|
269 |
|
|
270 |
"
|
|
271 |
Java reinitAllClasses
|
|
272 |
"
|
|
273 |
|
|
274 |
"Modified: / 4.1.1998 / 00:34:29 / cg"
|
248
|
275 |
!
|
|
276 |
|
|
277 |
reinitialize
|
|
278 |
"/ all JavaThreads are lost on a restart (for now)
|
|
279 |
|
|
280 |
Threads := nil.
|
|
281 |
|
|
282 |
"
|
|
283 |
Java reinitialize
|
|
284 |
"
|
|
285 |
|
|
286 |
"Modified: 18.8.1997 / 22:30:43 / cg"
|
|
287 |
"Created: 26.8.1997 / 20:07:00 / cg"
|
|
288 |
!
|
|
289 |
|
|
290 |
startupJavaSystem
|
|
291 |
"/
|
|
292 |
"/ check if already running
|
|
293 |
"/
|
|
294 |
self threads do:[:aJavaThread |
|
261
|
295 |
aJavaThread name = 'JAVA-Screen Updater' ifTrue:[
|
|
296 |
"/ already running
|
|
297 |
^ self
|
|
298 |
]
|
248
|
299 |
].
|
|
300 |
|
|
301 |
'JAVA [info]: (re)initializing JAVA environment completely ...' infoPrintCR.
|
261
|
302 |
JavaVM releaseAllJavaResources.
|
248
|
303 |
self markAllClassesUninitialized.
|
255
|
304 |
"/ self initAllStaticFields.
|
|
305 |
"/ self reinitAllClasses.
|
|
306 |
self initSystemClass.
|
|
307 |
JavaVM initializeVM.
|
248
|
308 |
'JAVA [info]: done JAVA initialization.' infoPrintCR.
|
|
309 |
|
|
310 |
"
|
|
311 |
Java startupJavaSystem
|
|
312 |
"
|
|
313 |
|
255
|
314 |
"Modified: / 6.1.1998 / 18:23:47 / cg"
|
248
|
315 |
!
|
|
316 |
|
|
317 |
terminateAllThreads
|
|
318 |
|myself|
|
|
319 |
|
|
320 |
Threads isNil ifTrue:[
|
261
|
321 |
^ self
|
248
|
322 |
].
|
|
323 |
|
|
324 |
myself := Processor activeProcess.
|
|
325 |
|
|
326 |
Threads do:[:aJavaThread |
|
261
|
327 |
aJavaThread ~~ myself ifTrue:[
|
|
328 |
(aJavaThread isNil or:[aJavaThread == 0]) ifFalse:[
|
|
329 |
(aJavaThread isMemberOf:JavaProcess) ifTrue:[
|
|
330 |
aJavaThread terminate
|
|
331 |
]
|
|
332 |
]
|
|
333 |
]
|
248
|
334 |
].
|
|
335 |
Threads := nil.
|
|
336 |
|
|
337 |
"
|
|
338 |
Java terminateAllThreads
|
|
339 |
"
|
|
340 |
|
|
341 |
"Modified: 21.8.1997 / 16:25:25 / cg"
|
|
342 |
"Created: 26.8.1997 / 19:57:40 / cg"
|
47
|
343 |
! !
|
|
344 |
|
135
|
345 |
!Java class methodsFor:'enumerating'!
|
43
|
346 |
|
90
|
347 |
allClasses
|
208
|
348 |
^ Classes ? #()
|
|
349 |
|
|
350 |
"Modified: 12.8.1997 / 00:30:09 / cg"
|
90
|
351 |
!
|
|
352 |
|
43
|
353 |
allClassesDo:aBlock
|
|
354 |
Classes notNil ifTrue:[
|
248
|
355 |
Classes do:aBlock
|
43
|
356 |
]
|
|
357 |
! !
|
|
358 |
|
205
|
359 |
!Java class methodsFor:'object conversions'!
|
|
360 |
|
|
361 |
as_Float:aNumber
|
|
362 |
"convert an ST-float into a Java Float"
|
|
363 |
|
|
364 |
|i|
|
|
365 |
|
|
366 |
i := (Java at:'java.lang.Float') new.
|
261
|
367 |
i perform:#'<init>(F)V' with:(aNumber asShortFloat).
|
205
|
368 |
^ i
|
|
369 |
|
|
370 |
"
|
|
371 |
Java as_Float:1
|
|
372 |
Java as_Float:3.14159
|
|
373 |
"
|
|
374 |
|
|
375 |
"Created: 7.8.1997 / 21:21:13 / cg"
|
|
376 |
"Modified: 7.8.1997 / 21:22:05 / cg"
|
|
377 |
!
|
|
378 |
|
|
379 |
as_Hashtable:aDictionary
|
261
|
380 |
"given a smalltalk dictionary, create and return
|
|
381 |
a Java hashTable for it"
|
|
382 |
|
205
|
383 |
|hashTable|
|
|
384 |
|
|
385 |
hashTable := (self classForName:'java.util.Hashtable') new.
|
|
386 |
aDictionary keysAndValuesDo:[:k :v |
|
261
|
387 |
|sk sv jk jv|
|
205
|
388 |
|
261
|
389 |
(sk := k) isSymbol ifTrue:[
|
|
390 |
sk := sk asString
|
|
391 |
].
|
|
392 |
(sv := v) isSymbol ifTrue:[
|
|
393 |
sv := sv asString
|
|
394 |
].
|
|
395 |
jk := self as_Object:sk.
|
|
396 |
jv := self as_Object:sv.
|
255
|
397 |
|
261
|
398 |
hashTable
|
|
399 |
perform:#'put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;'
|
|
400 |
with:jk
|
|
401 |
with:jv.
|
205
|
402 |
].
|
|
403 |
^ hashTable
|
|
404 |
|
|
405 |
"
|
|
406 |
Java as_Hashtable:(Dictionary new
|
261
|
407 |
at:'hello' put:'Hallo';
|
|
408 |
at:'world' put:'Welt';
|
|
409 |
yourself)
|
205
|
410 |
"
|
|
411 |
|
261
|
412 |
"Modified: / 14.1.1998 / 17:02:13 / cg"
|
205
|
413 |
!
|
|
414 |
|
|
415 |
as_Integer:anInteger
|
|
416 |
"convert an ST-integer into a Java Integer"
|
|
417 |
|
|
418 |
|i|
|
|
419 |
|
|
420 |
i := (Java at:'java.lang.Integer') new.
|
261
|
421 |
i perform:#'<init>(I)V' with:anInteger.
|
205
|
422 |
^ i
|
|
423 |
|
|
424 |
"
|
|
425 |
Java as_Integer:1
|
|
426 |
"
|
|
427 |
|
|
428 |
"Modified: 7.8.1997 / 21:19:37 / cg"
|
|
429 |
"Created: 7.8.1997 / 21:21:13 / cg"
|
|
430 |
!
|
|
431 |
|
|
432 |
as_Object:anObject
|
|
433 |
"convert an ST-Object into a Java Object"
|
|
434 |
|
|
435 |
anObject isString ifTrue:[
|
248
|
436 |
^ self as_String:anObject
|
205
|
437 |
].
|
|
438 |
anObject isInteger ifTrue:[
|
248
|
439 |
^ self as_Integer:anObject
|
205
|
440 |
].
|
|
441 |
|
|
442 |
self halt.
|
|
443 |
|
|
444 |
"
|
|
445 |
Java as_Object:'hello world'
|
|
446 |
"
|
|
447 |
|
|
448 |
"Created: 7.8.1997 / 21:15:38 / cg"
|
|
449 |
"Modified: 7.8.1997 / 21:20:07 / cg"
|
|
450 |
!
|
|
451 |
|
|
452 |
as_ST_String:aJavaString
|
|
453 |
"hard-coding internas of java.lang.String here is bad ..."
|
|
454 |
|
255
|
455 |
|str count start stop|
|
|
456 |
|
|
457 |
"/ count := aJavaString instVarNamed:'count'.
|
|
458 |
count := aJavaString instVarAt:(JavaSlotIndexCache string_slot_count).
|
|
459 |
|
|
460 |
"/ str := aJavaString instVarNamed:'value'
|
|
461 |
str := aJavaString instVarAt:(JavaSlotIndexCache string_slot_value).
|
|
462 |
|
|
463 |
str size == count ifTrue:[
|
261
|
464 |
^ str
|
255
|
465 |
].
|
205
|
466 |
|
|
467 |
"/ start := (aJavaString instVarNamed:'offset') + 1.
|
|
468 |
start := (aJavaString instVarAt:(JavaSlotIndexCache string_slot_offset)) + 1.
|
|
469 |
|
|
470 |
"/ stop := start + (aJavaString instVarNamed:'count') - 1.
|
|
471 |
stop := start + (aJavaString instVarAt:(JavaSlotIndexCache string_slot_count)) - 1.
|
|
472 |
|
|
473 |
"/ ^ ((aJavaString instVarNamed:'value') copyFrom:start to:stop) asString
|
|
474 |
^ ((aJavaString instVarAt:(JavaSlotIndexCache string_slot_value))
|
261
|
475 |
copyFrom:start to:stop) asString
|
205
|
476 |
|
255
|
477 |
"Created: / 8.8.1997 / 12:02:55 / cg"
|
|
478 |
"Modified: / 9.1.1998 / 23:55:39 / cg"
|
205
|
479 |
!
|
|
480 |
|
|
481 |
as_String:aString
|
|
482 |
"convert an ST-String into a Java String"
|
|
483 |
|
|
484 |
"hard-coding internas of java.lang.String here is bad ..."
|
|
485 |
|
|
486 |
|s|
|
|
487 |
|
|
488 |
s := Java_lang_String basicNew.
|
|
489 |
s instVarNamed:'value' put: aString.
|
|
490 |
s instVarNamed:'offset' put: 0.
|
|
491 |
s instVarNamed:'count' put: aString size.
|
|
492 |
^ s
|
|
493 |
|
|
494 |
"
|
|
495 |
Java as_String:'hello world'
|
|
496 |
"
|
|
497 |
|
|
498 |
"Created: 7.8.1997 / 21:15:49 / cg"
|
|
499 |
"Modified: 7.8.1997 / 21:19:37 / cg"
|
|
500 |
!
|
|
501 |
|
|
502 |
as_URL:aString
|
|
503 |
"convert an ST-String into a Java String"
|
|
504 |
|
|
505 |
"hard-coding internas of java.lang.String here is bad ..."
|
|
506 |
|
|
507 |
|u|
|
|
508 |
|
|
509 |
u := (self at:'java.net.URL') basicNew.
|
261
|
510 |
u perform:#'<init>(Ljava/lang/String;)V' with:(self as_String:aString).
|
205
|
511 |
^ u
|
|
512 |
|
|
513 |
"
|
|
514 |
Java as_URL:'http://www.altavista.com'
|
|
515 |
Java as_URL:'file:/foo/bar'
|
|
516 |
"
|
|
517 |
|
|
518 |
"Created: 7.8.1997 / 21:15:49 / cg"
|
|
519 |
"Modified: 7.8.1997 / 21:26:42 / cg"
|
|
520 |
! !
|
|
521 |
|
168
|
522 |
!Java class methodsFor:'queries'!
|
|
523 |
|
|
524 |
smalltalkClassFor:typeRef
|
|
525 |
self halt.
|
|
526 |
"/ (typeString startsWith:'[[') ifTrue:[
|
|
527 |
"/ ^ Array
|
|
528 |
"/ ].
|
|
529 |
"/ (typeString startsWith:'[F') ifTrue:[
|
|
530 |
"/ ^ FloatArray
|
|
531 |
"/ ].
|
|
532 |
self halt.
|
|
533 |
|
|
534 |
"Modified: 7.4.1997 / 13:33:46 / cg"
|
|
535 |
!
|
|
536 |
|
|
537 |
smalltalkDerefType:typeString
|
|
538 |
(typeString startsWith:'[') ifTrue:[
|
248
|
539 |
^ typeString copyFrom:2
|
168
|
540 |
].
|
|
541 |
self halt.
|
|
542 |
|
|
543 |
"Modified: 7.4.1997 / 13:13:24 / cg"
|
|
544 |
! !
|
|
545 |
|
135
|
546 |
!Java class methodsFor:'registering java classes'!
|
17
|
547 |
|
|
548 |
at:aJavaName
|
43
|
549 |
"search & return for a class by name;
|
|
550 |
if there is no such class, return nil.
|
|
551 |
The argument, aJavaName may be either an internal name
|
|
552 |
(sep'd by slashes) or an external name (sep'd by periods).
|
|
553 |
The 'java/lang' standard packages prefix may be ommitted."
|
|
554 |
|
|
555 |
|sym nm cls|
|
|
556 |
|
17
|
557 |
Classes isNil ifTrue:[^ nil].
|
43
|
558 |
|
|
559 |
sym := aJavaName asSymbolIfInterned.
|
|
560 |
sym notNil ifTrue:[
|
248
|
561 |
cls := Classes at:sym ifAbsent:nil.
|
|
562 |
cls notNil ifTrue:[^ cls].
|
43
|
563 |
].
|
17
|
564 |
|
43
|
565 |
nm := aJavaName.
|
|
566 |
(nm includes:$.) ifTrue:[
|
252
|
567 |
nm := (nm asString copy replaceAll:$. with:$/).
|
248
|
568 |
sym := nm asSymbolIfInterned.
|
|
569 |
sym notNil ifTrue:[
|
|
570 |
cls := Classes at:sym ifAbsent:nil.
|
|
571 |
cls notNil ifTrue:[^ cls].
|
|
572 |
].
|
43
|
573 |
].
|
|
574 |
|
|
575 |
(nm includes:$/) ifFalse:[
|
248
|
576 |
"/
|
|
577 |
"/ try java.lang.Foo
|
|
578 |
"/
|
|
579 |
nm := 'java/lang/' , nm.
|
|
580 |
sym := nm asSymbolIfInterned.
|
|
581 |
sym notNil ifTrue:[
|
|
582 |
cls := Classes at:sym ifAbsent:nil.
|
|
583 |
cls notNil ifTrue:[^ cls].
|
|
584 |
].
|
43
|
585 |
].
|
|
586 |
|
|
587 |
^ nil
|
|
588 |
|
|
589 |
"
|
|
590 |
Java at:'java/lang/String'
|
|
591 |
Java at:'java.lang.String'
|
|
592 |
Java at:'String'
|
|
593 |
Java at:'System'
|
|
594 |
Java at:'Foo'
|
|
595 |
"
|
17
|
596 |
!
|
|
597 |
|
|
598 |
at:aJavaName put:aJavaClass
|
90
|
599 |
|nameSymbol|
|
|
600 |
|
17
|
601 |
Classes isNil ifTrue:[
|
248
|
602 |
Classes := IdentityDictionary new.
|
17
|
603 |
].
|
90
|
604 |
|
|
605 |
nameSymbol := aJavaName asSymbol.
|
|
606 |
(Classes includesKey:nameSymbol) ifTrue:[
|
248
|
607 |
('JAVA: class ' , aJavaName , ' is already loaded') infoPrintCR.
|
|
608 |
self updateClassRefsFrom:(Classes at:nameSymbol) to:aJavaClass.
|
65
|
609 |
].
|
54
|
610 |
|
90
|
611 |
Classes at:nameSymbol put:aJavaClass.
|
|
612 |
nameSymbol == #'java/lang/String' ifTrue:[
|
248
|
613 |
Java_lang_String := aJavaClass
|
90
|
614 |
].
|
21
|
615 |
|
43
|
616 |
"/ UnresolvedClassRefs notNil ifTrue:[
|
|
617 |
"/ UnresolvedClassRefs do:[:toResolve |
|
|
618 |
"/ ]
|
|
619 |
"/ ].
|
|
620 |
|
27
|
621 |
self changed:#classes
|
17
|
622 |
|
|
623 |
"Created: 17.4.1996 / 23:29:31 / cg"
|
205
|
624 |
"Modified: 7.8.1997 / 19:15:58 / cg"
|
21
|
625 |
!
|
|
626 |
|
168
|
627 |
flushAllJavaResources
|
|
628 |
self flushClasses.
|
|
629 |
|
|
630 |
ObjectMemory allObjectsDo:[:someObject |
|
248
|
631 |
someObject isBehavior ifTrue:[
|
|
632 |
someObject isJavaClass ifTrue:[
|
|
633 |
someObject setConstantPool:nil.
|
|
634 |
someObject setInterfaces:nil.
|
|
635 |
someObject setMethodDictionary:(MethodDictionary new).
|
168
|
636 |
someObject fullName printCR.
|
248
|
637 |
]
|
|
638 |
].
|
|
639 |
(someObject isMemberOf:JavaMethod) ifTrue:[
|
|
640 |
someObject setJavaClass:nil.
|
|
641 |
someObject setExceptionTable:nil.
|
|
642 |
].
|
|
643 |
(someObject isMemberOf:JavaUnresolvedClassConstant) ifTrue:[
|
|
644 |
someObject constantPool:nil
|
|
645 |
].
|
168
|
646 |
].
|
|
647 |
self flushClasses
|
|
648 |
|
|
649 |
"
|
|
650 |
Java flushAllJavaResources
|
|
651 |
"
|
|
652 |
|
|
653 |
"Modified: 7.4.1997 / 16:49:23 / cg"
|
|
654 |
!
|
|
655 |
|
21
|
656 |
flushClasses
|
167
|
657 |
Classes := UnresolvedClassRefs := nil.
|
168
|
658 |
Smalltalk keys copy do:[:aKey |
|
248
|
659 |
(aKey startsWith:'JAVA::') ifTrue:[ Smalltalk removeKey:aKey ]
|
168
|
660 |
].
|
167
|
661 |
Java_lang_String := Java_lang_Class := nil.
|
261
|
662 |
JavaVM releaseAllJavaResources.
|
90
|
663 |
JavaUnresolvedConstant flushPatchLists.
|
21
|
664 |
|
|
665 |
"
|
|
666 |
Java flushClasses
|
|
667 |
"
|
|
668 |
|
168
|
669 |
"Modified: 7.4.1997 / 15:25:46 / cg"
|
21
|
670 |
!
|
|
671 |
|
43
|
672 |
markAllClassesUninitialized
|
|
673 |
self allClassesDo:[:aJavaClass |
|
248
|
674 |
aJavaClass markUninitialized
|
43
|
675 |
].
|
|
676 |
|
|
677 |
"
|
|
678 |
Java markAllClassesUninitialized
|
|
679 |
"
|
|
680 |
!
|
|
681 |
|
21
|
682 |
rememberUnresolved:anUnresolvedClassRef
|
90
|
683 |
('JAVA: remember unresolved class: ' , anUnresolvedClassRef fullName) infoPrintCR.
|
|
684 |
|
|
685 |
UnresolvedClassRefs isNil ifTrue:[
|
248
|
686 |
UnresolvedClassRefs := Set new.
|
90
|
687 |
].
|
|
688 |
UnresolvedClassRefs add:anUnresolvedClassRef
|
21
|
689 |
|
|
690 |
"Created: 18.4.1996 / 00:05:31 / cg"
|
|
691 |
"Modified: 18.4.1996 / 00:05:41 / cg"
|
90
|
692 |
!
|
|
693 |
|
162
|
694 |
removeClass:aJavaClass
|
|
695 |
"/ remove it from myself
|
|
696 |
|
|
697 |
|javaName sym nm cls |
|
|
698 |
|
|
699 |
javaName := aJavaClass fullName.
|
|
700 |
|
|
701 |
sym := javaName asSymbolIfInterned.
|
|
702 |
sym notNil ifTrue:[
|
248
|
703 |
cls := Classes at:sym ifAbsent:nil.
|
162
|
704 |
].
|
|
705 |
cls isNil ifTrue:[
|
248
|
706 |
nm := javaName.
|
|
707 |
(nm includes:$.) ifTrue:[
|
|
708 |
"/
|
|
709 |
"/ try pckg/.../name
|
|
710 |
"/
|
252
|
711 |
nm := (nm asString copy replaceAll:$. with:$/).
|
248
|
712 |
sym := nm asSymbolIfInterned.
|
|
713 |
sym notNil ifTrue:[
|
|
714 |
cls := Classes at:sym ifAbsent:nil.
|
|
715 |
].
|
|
716 |
].
|
162
|
717 |
].
|
212
|
718 |
(cls notNil and:[cls == aJavaClass]) ifTrue:[
|
248
|
719 |
Classes removeKey:sym.
|
|
720 |
self updateClassRefsFrom:aJavaClass to:nil.
|
162
|
721 |
].
|
212
|
722 |
Smalltalk removeKey:('JAVA::' , aJavaClass fullName) asSymbol.
|
162
|
723 |
|
212
|
724 |
"Modified: 12.8.1997 / 02:54:34 / cg"
|
162
|
725 |
!
|
|
726 |
|
90
|
727 |
unresolvedClassRefFor:aClassName
|
|
728 |
UnresolvedClassRefs isNil ifTrue:[^ nil].
|
|
729 |
^ UnresolvedClassRefs at:aClassName ifAbsent:nil.
|
167
|
730 |
!
|
|
731 |
|
|
732 |
updateClassRefsFrom:oldClass to:newClass
|
|
733 |
"update all references to oldClass to now refer to newClass.
|
|
734 |
sent, when a class is reloaded"
|
|
735 |
|
214
|
736 |
newClass notNil ifTrue:[
|
248
|
737 |
"/
|
|
738 |
"/ kludge: the new class might have been resolved with the oldClass ...
|
|
739 |
"/
|
|
740 |
newClass constantPool
|
|
741 |
updateClassRefsFrom:oldClass to:newClass.
|
214
|
742 |
].
|
205
|
743 |
|
203
|
744 |
self allClassesDo:[:aJavaClass |
|
248
|
745 |
aJavaClass updateClassRefsFrom:oldClass to:newClass
|
203
|
746 |
].
|
167
|
747 |
|
|
748 |
"Created: 26.3.1997 / 13:49:20 / cg"
|
214
|
749 |
"Modified: 12.8.1997 / 03:04:44 / cg"
|
17
|
750 |
! !
|
|
751 |
|
135
|
752 |
!Java class methodsFor:'source management'!
|
76
|
753 |
|
|
754 |
classSourceOf:aClass
|
261
|
755 |
|package dirName binary sourceFileName sourceFile dirHolder fileName path
|
|
756 |
loader codeBaseURL protocol dir file|
|
76
|
757 |
|
|
758 |
aClass isNil ifTrue:[
|
248
|
759 |
^ nil
|
76
|
760 |
].
|
|
761 |
package := aClass package.
|
|
762 |
|
|
763 |
"/ first, look in the directory, where the binary
|
|
764 |
"/ was loaded from.
|
|
765 |
|
198
|
766 |
binary := aClass binaryFile.
|
|
767 |
binary notNil ifTrue:[
|
248
|
768 |
binary := binary asFilename.
|
|
769 |
sourceFileName := binary withSuffix:'java'.
|
|
770 |
sourceFile := sourceFileName asFilename.
|
261
|
771 |
] ifFalse:[
|
|
772 |
"/ maybe it was loaded by a java classLoader ...
|
|
773 |
(loader := aClass classLoader) notNil ifTrue:[
|
|
774 |
(codeBaseURL := loader instVarNamed:'codeBaseURL') notNil ifTrue:[
|
|
775 |
(protocol := codeBaseURL instVarNamed:'protocol') notNil ifTrue:[
|
|
776 |
(Java as_ST_String:protocol) = 'file' ifTrue:[
|
|
777 |
dirName := Java as_ST_String:(codeBaseURL instVarNamed:'file').
|
|
778 |
dirName asFilename exists ifTrue:[
|
|
779 |
aClass sourceFile notNil ifTrue:[
|
|
780 |
sourceFileName := dirName asFilename construct:aClass sourceFile.
|
|
781 |
sourceFile := sourceFileName asFilename.
|
|
782 |
]
|
|
783 |
]
|
|
784 |
]
|
|
785 |
]
|
|
786 |
]
|
|
787 |
]
|
198
|
788 |
].
|
76
|
789 |
|
198
|
790 |
sourceFile notNil ifTrue:[
|
248
|
791 |
sourceFile exists ifFalse:[
|
|
792 |
sourceFileName := binary withSuffix:'jav'.
|
|
793 |
sourceFile := sourceFileName asFilename.
|
|
794 |
sourceFile exists ifFalse:[
|
|
795 |
sourceFileName := binary withSuffix:'JAV'.
|
|
796 |
sourceFile := sourceFileName asFilename.
|
|
797 |
sourceFile exists ifFalse:[
|
|
798 |
sourceFileName := binary withSuffix:'JAVA'.
|
|
799 |
sourceFile := sourceFileName asFilename.
|
|
800 |
].
|
|
801 |
].
|
|
802 |
].
|
76
|
803 |
].
|
|
804 |
|
176
|
805 |
"/ special case: there were multiple classes in a single
|
76
|
806 |
"/ source file.
|
|
807 |
|
198
|
808 |
binary notNil ifTrue:[
|
248
|
809 |
binary withoutSuffix baseName ~= aClass sourceFile asFilename withoutSuffix baseName ifTrue:[
|
|
810 |
'JAVA: trouble extracting fileName: ' print.
|
|
811 |
binary withoutSuffix baseName print. ' vs. ' print.
|
|
812 |
aClass sourceFile asFilename withoutSuffix baseName printCR.
|
|
813 |
].
|
76
|
814 |
].
|
|
815 |
|
|
816 |
"/ if that fails, look in standard places
|
|
817 |
|
198
|
818 |
(sourceFile isNil or:[sourceFile exists not]) ifTrue:[
|
248
|
819 |
sourceFileName := aClass sourceFile.
|
|
820 |
sourceFile := sourceFileName asFilename.
|
|
821 |
sourceFile exists ifFalse:[
|
|
822 |
"/
|
|
823 |
"/ mhmh - look for its directory
|
|
824 |
"/
|
|
825 |
dirName := sourceFile directoryName.
|
|
826 |
fileName := sourceFile baseName.
|
76
|
827 |
|
248
|
828 |
(dirName asFilename exists
|
|
829 |
and:[(dirName asFilename construct:(package , '/' , fileName)) exists])
|
|
830 |
ifFalse:[
|
|
831 |
(dirName asFilename exists
|
|
832 |
and:[(dirName asFilename construct:(fileName)) exists])
|
|
833 |
ifFalse:[
|
|
834 |
dirName := self findSourceDirOf:fileName inPackage:package.
|
76
|
835 |
|
|
836 |
"/ [dirName isNil] whileTrue:[
|
|
837 |
"/ dirName := Dialog requestDirectoryName:'top directory for ' , package , '/' , fileName.
|
|
838 |
"/ (dirName isNil or:[dirName isEmpty]) ifTrue:[^ self].
|
|
839 |
"/ ].
|
248
|
840 |
].
|
|
841 |
].
|
76
|
842 |
|
248
|
843 |
(dirName notNil and:[dirName asFilename exists]) ifTrue:[
|
|
844 |
path := (dirName asFilename construct:(package , '/' , fileName)) asFilename.
|
|
845 |
path exists ifFalse:[
|
|
846 |
path := (dirName asFilename construct:(fileName)) asFilename.
|
|
847 |
].
|
|
848 |
].
|
76
|
849 |
|
248
|
850 |
(path notNil and:[path exists]) ifFalse:[
|
|
851 |
^ nil
|
|
852 |
].
|
76
|
853 |
|
248
|
854 |
sourceFile := path asFilename.
|
|
855 |
].
|
76
|
856 |
].
|
|
857 |
^ (sourceFile contentsOfEntireFile).
|
|
858 |
|
261
|
859 |
"Modified: / 13.1.1998 / 14:56:39 / cg"
|
76
|
860 |
!
|
|
861 |
|
|
862 |
findSourceDirOf:fileName inPackage:aPackage
|
|
863 |
SourceDirectories notNil ifTrue:[
|
248
|
864 |
SourceDirectories do:[:aDir |
|
|
865 |
(aDir asFilename construct:('/' , aPackage , '/' , fileName))
|
|
866 |
asFilename exists ifTrue:[
|
|
867 |
^ aDir
|
|
868 |
].
|
|
869 |
(aDir asFilename construct:('/' , fileName))
|
|
870 |
asFilename exists ifTrue:[
|
|
871 |
^ aDir
|
|
872 |
].
|
|
873 |
]
|
76
|
874 |
].
|
|
875 |
^ nil
|
|
876 |
|
|
877 |
|
|
878 |
! !
|
|
879 |
|
224
|
880 |
!Java class methodsFor:'starting apps'!
|
|
881 |
|
261
|
882 |
executeMainOf:aClass
|
|
883 |
"execute main of aClass in a separate thread and wait until that thread
|
|
884 |
has terminated."
|
|
885 |
|
|
886 |
|p|
|
|
887 |
|
|
888 |
p := self javaProcessForMainOf:aClass.
|
|
889 |
p notNil ifTrue:[
|
|
890 |
p resume.
|
|
891 |
Object abortSignal handle:[:ex |
|
|
892 |
p terminate.
|
|
893 |
ex reject.
|
|
894 |
] do:[
|
|
895 |
p waitUntilTerminated
|
|
896 |
].
|
|
897 |
]
|
|
898 |
|
|
899 |
"Modified: / 15.1.1998 / 02:15:13 / cg"
|
|
900 |
"Created: / 15.1.1998 / 17:14:55 / cg"
|
|
901 |
!
|
|
902 |
|
224
|
903 |
javaProcessForMainOf:aJavaClass
|
|
904 |
"ask for a commandLine, create a java process to invoke
|
|
905 |
its main and return it. The process is not scheduled for
|
|
906 |
execution."
|
|
907 |
|
|
908 |
|args|
|
|
909 |
|
|
910 |
args := Dialog
|
261
|
911 |
request:'argument string:'
|
|
912 |
initialAnswer:LastArgumentString ? ''
|
|
913 |
onCancel:nil.
|
228
|
914 |
args isNil ifTrue:[^ nil].
|
224
|
915 |
|
|
916 |
LastArgumentString := args.
|
|
917 |
|
|
918 |
^ self javaProcessForMainOf:aJavaClass argumentString:args.
|
|
919 |
|
255
|
920 |
"Created: / 15.8.1997 / 04:51:46 / cg"
|
|
921 |
"Modified: / 9.1.1998 / 18:01:47 / cg"
|
224
|
922 |
!
|
|
923 |
|
|
924 |
javaProcessForMainOf:aJavaClass argumentString:argString
|
|
925 |
"create a java process, ready to invoke the classes main
|
|
926 |
method. Returns the process - ready to run but not yet resumed"
|
|
927 |
|
|
928 |
|p argStringArray t|
|
|
929 |
|
261
|
930 |
JavaVM initializeVMIfNoEventThreadRunning.
|
|
931 |
(Java at:'java.lang.System') instVarNamed:'security' put:nil.
|
|
932 |
|
224
|
933 |
argString isEmpty ifTrue:[
|
252
|
934 |
argStringArray := #()
|
224
|
935 |
] ifFalse:[
|
252
|
936 |
argStringArray := argString asCollectionOfWords asArray
|
|
937 |
collect:[:s | Java as_String:s].
|
224
|
938 |
].
|
|
939 |
|
|
940 |
p := JavaProcess
|
252
|
941 |
for:[
|
|
942 |
aJavaClass
|
|
943 |
invoke:#'main'
|
|
944 |
signature:#'([Ljava/lang/String;)V'
|
|
945 |
with:argStringArray
|
|
946 |
]
|
|
947 |
priority:(Processor activePriority - 1).
|
224
|
948 |
|
|
949 |
p name:(aJavaClass fullName , '::main()').
|
|
950 |
^ p
|
|
951 |
|
252
|
952 |
"Created: / 15.8.1997 / 04:41:20 / cg"
|
261
|
953 |
"Modified: / 15.1.1998 / 17:33:18 / cg"
|
224
|
954 |
! !
|
|
955 |
|
135
|
956 |
!Java class methodsFor:'documentation'!
|
17
|
957 |
|
|
958 |
version
|
261
|
959 |
^ '$Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/Java.st,v 1.48 1998/01/16 16:11:07 cg Exp $'
|
17
|
960 |
! !
|
76
|
961 |
Java initialize!
|