Showing the changes to java/pkg2/java/io/ObjectInputStream_L.b (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,397 @@ | |||
| 1 | implement ObjectInputStream_L; | ||
| 2 | |||
| 3 | # javal v1.3 generated file: edit with care | ||
| 4 | |||
| 5 | include "jni.m"; | ||
| 6 | jni : JNI; | ||
| 7 | ClassModule, | ||
| 8 | JString, | ||
| 9 | JArray, | ||
| 10 | JArrayI, | ||
| 11 | JArrayC, | ||
| 12 | JArrayB, | ||
| 13 | JArrayS, | ||
| 14 | JArrayJ, | ||
| 15 | JArrayF, | ||
| 16 | JArrayD, | ||
| 17 | JArrayZ, | ||
| 18 | JArrayJObject, | ||
| 19 | JArrayJClass, | ||
| 20 | JArrayJString, | ||
| 21 | JClass, | ||
| 22 | JThread, | ||
| 23 | JObject : import jni; | ||
| 24 | |||
| 25 | #>> extra pre includes here | ||
| 26 | sys : import jni; | ||
| 27 | str : import jni; | ||
| 28 | FALSE : import jni; | ||
| 29 | TRUE : import jni; | ||
| 30 | #<< | ||
| 31 | |||
| 32 | include "ObjectInputStream_L.m"; | ||
| 33 | |||
| 34 | #>> extra post includes here | ||
| 35 | include "workdir.m"; | ||
| 36 | include "regex.m"; | ||
| 37 | str_mod : String; | ||
| 38 | ClassData, Value : import jni; | ||
| 39 | cast : Cast; | ||
| 40 | low : Low; | ||
| 41 | #<< | ||
| 42 | |||
| 43 | init( jni_p : JNI ) | ||
| 44 | { | ||
| 45 | # save java native inteface mod instance | ||
| 46 | jni = jni_p; | ||
| 47 | #>>extra initialization here | ||
| 48 | sys = jni->sys; | ||
| 49 | str_mod = jni->str; | ||
| 50 | cast = jni->CastMod(); | ||
| 51 | low = jni->LowMod(); | ||
| 52 | #<< | ||
| 53 | } | ||
| 54 | |||
| 55 | loadClass0_rClass_rString_rClass( this : ref ObjectInputStream_obj, p0 : JClass,p1 : JString) : JClass | ||
| 56 | {#>> | ||
| 57 | TRACE_1 := (this, p0); | ||
| 58 | if(p1.str[0] == '[') | ||
| 59 | return jni->LookupArrayClass(p1.str); | ||
| 60 | else | ||
| 61 | return jni->GetClassObject( jni->FindClass(p1.str) ); | ||
| 62 | }#<< | ||
| 63 | |||
| 64 | inputClassFields_rObject_rClass_aI_V( this : JObject, p0 : JObject,p1 : JClass,p2 : JArrayI) | ||
| 65 | {#>> | ||
| 66 | #p0 the object being inputted | ||
| 67 | #p1 class being referred to | ||
| 68 | #p2 fieldSequence array | ||
| 69 | |||
| 70 | ok : int; | ||
| 71 | val : ref Value; | ||
| 72 | # | ||
| 73 | # get all fields except the transient and static | ||
| 74 | # | ||
| 75 | fields_n_sigs := jni->GetFieldSignatures(p1, (JNI->ACC_STATIC|JNI->ACC_TRANSIENT)); | ||
| 76 | # | ||
| 77 | # for each field, parse out the field name and signature. Then based on the | ||
| 78 | # signature, call the appropriate read routine. | ||
| 79 | # | ||
| 80 | for (i:=0; i < len p2.ary; i += 2) { | ||
| 81 | fldindex := p2.ary[i+1]; | ||
| 82 | |||
| 83 | (str_part, tmp_str) := str_mod->splitl((fields_n_sigs.ary[fldindex]).str, " "); | ||
| 84 | sig_part := tmp_str[1]; | ||
| 85 | # | ||
| 86 | # call the appropriate read routine to get the value of this field | ||
| 87 | # | ||
| 88 | case sig_part { | ||
| 89 | # SIGNATURE_BYTE | ||
| 90 | 'B' => | ||
| 91 | (val, ok) = jni->CallMethod(this, "readByte", "()B", nil); | ||
| 92 | # SIGNATURE_CHAR | ||
| 93 | 'C' => | ||
| 94 | (val, ok) = jni->CallMethod(this, "readChar", "()C", nil); | ||
| 95 | # SIGNATURE_FLOAT | ||
| 96 | 'F' => | ||
| 97 | (val, ok) = jni->CallMethod(this, "readFloat", "()F", nil); | ||
| 98 | # SIGNATURE_DOUBLE | ||
| 99 | 'D' => | ||
| 100 | (val, ok) = jni->CallMethod(this, "readDouble", "()D", nil); | ||
| 101 | # SIGNATURE_INT | ||
| 102 | 'I' => | ||
| 103 | (val, ok) = jni->CallMethod(this, "readInt", "()I", nil); | ||
| 104 | # SIGNATURE_LONG | ||
| 105 | 'J' => | ||
| 106 | (val, ok) = jni->CallMethod(this, "readLong", "()J", nil); | ||
| 107 | # SIGNATURE_SHORT | ||
| 108 | 'S' => | ||
| 109 | (val, ok) = jni->CallMethod(this, "readShort", "()S", nil); | ||
| 110 | # SIGNATURE_BOOLEAN | ||
| 111 | 'Z' => | ||
| 112 | (val, ok) = jni->CallMethod(this, "readBoolean", "()Z", nil); | ||
| 113 | # SIGNATURE_ARRAY | ||
| 114 | '[' => | ||
| 115 | (val, ok) = jni->CallMethod(this, "readObject", "()Ljava/lang/Object;", nil); | ||
| 116 | # SIGNATURE_CLASS | ||
| 117 | 'L' => | ||
| 118 | (val, ok) = jni->CallMethod(this, "readObject", "()Ljava/lang/Object;", nil); | ||
| 119 | } | ||
| 120 | # | ||
| 121 | # now take that just readin value and store into the object. | ||
| 122 | # | ||
| 123 | if (ok == JNI->OK) | ||
| 124 | jni->SetObjField(p0, str_part, val); | ||
| 125 | } | ||
| 126 | }#<< | ||
| 127 | |||
| 128 | inputArrayValues_rObject_rClass_V( this : JObject, p0 : JObject,p1 : JClass) | ||
| 129 | {#>> | ||
| 130 | # p0 is an array of Objects. We have to look at the signature | ||
| 131 | # of the array to find what the Objects really are. | ||
| 132 | # | ||
| 133 | # p1 the class name of the elements of the array (this is also | ||
| 134 | # the arrays signature) | ||
| 135 | # | ||
| 136 | # make sure this is an array we have. If so, get its length. | ||
| 137 | # | ||
| 138 | if ( jni->IsArray(p0) == JNI->FALSE) { | ||
| 139 | jni->ThrowException("java.io.InvalidClassException", "Not an array"); | ||
| 140 | } | ||
| 141 | length := jni->GetArrayLength(cast->ToJArray(p0)); | ||
| 142 | ok : int; | ||
| 143 | val : ref Value; | ||
| 144 | |||
| 145 | # | ||
| 146 | # dispatch on the signature of the array and read in each element. | ||
| 147 | # | ||
| 148 | i : int; | ||
| 149 | case p1.aryname[1] { | ||
| 150 | # SIGNATURE_BYTE | ||
| 151 | 'B' => | ||
| 152 | { | ||
| 153 | mul_args := array[3] of ref Value; | ||
| 154 | mul_args[0] = ref Value.TObject(p0); | ||
| 155 | mul_args[1] = ref Value.TInt(0); | ||
| 156 | mul_args[2] = ref Value.TInt(length); | ||
| 157 | (val, ok) = jni->CallMethod(this, "readFully", "([BII)V", mul_args); | ||
| 158 | } | ||
| 159 | # SIGNATURE_CHAR | ||
| 160 | 'C' => | ||
| 161 | { | ||
| 162 | JAChar := cast->ToJArrayI(p0); | ||
| 163 | for (i = 0; i < length; i++) { | ||
| 164 | (val, ok) = jni->CallMethod(this, "readChar", "()C", nil); | ||
| 165 | JAChar.ary[i] = val.Char(); | ||
| 166 | } | ||
| 167 | } | ||
| 168 | # SIGNATURE_FLOAT | ||
| 169 | 'F' => | ||
| 170 | { | ||
| 171 | JAFloat := cast->ToJArrayF(p0); | ||
| 172 | for (i = 0; i < length; i++) { | ||
| 173 | (val, ok) = jni->CallMethod(this, "readFloat", "()F", nil); | ||
| 174 | JAFloat.ary[i] = val.Float(); | ||
| 175 | } | ||
| 176 | } | ||
| 177 | # SIGNATURE_DOUBLE | ||
| 178 | 'D' => | ||
| 179 | { | ||
| 180 | JADouble := cast->ToJArrayD(p0); | ||
| 181 | for (i = 0; i < length; i++) { | ||
| 182 | (val, ok) = jni->CallMethod(this, "readDouble", "()D", nil); | ||
| 183 | JADouble.ary[i] = val.Double(); | ||
| 184 | } | ||
| 185 | } | ||
| 186 | # SIGNATURE_INT | ||
| 187 | 'I' => | ||
| 188 | { | ||
| 189 | JAInt := cast->ToJArrayI(p0); | ||
| 190 | for (i = 0; i < length; i++) { | ||
| 191 | (val, ok) = jni->CallMethod(this, "readInt", "()I", nil); | ||
| 192 | JAInt.ary[i] = val.Int(); | ||
| 193 | } | ||
| 194 | } | ||
| 195 | # SIGNATURE_LONG | ||
| 196 | 'J' => | ||
| 197 | { | ||
| 198 | JALong := cast->ToJArrayJ(p0); | ||
| 199 | for (i = 0; i < length; i++) { | ||
| 200 | (val, ok) = jni->CallMethod(this, "readLong", "()J", nil); | ||
| 201 | JALong.ary[i] = val.Long(); | ||
| 202 | } | ||
| 203 | } | ||
| 204 | # SIGNATURE_SHORT | ||
| 205 | 'S' => | ||
| 206 | { | ||
| 207 | JAShort := cast->ToJArrayI(p0); | ||
| 208 | for (i = 0; i < length; i++) { | ||
| 209 | (val, ok) = jni->CallMethod(this, "readShort", "()S", nil); | ||
| 210 | JAShort.ary[i] = val.Short(); | ||
| 211 | } | ||
| 212 | } | ||
| 213 | # SIGNATURE_BOOLEAN | ||
| 214 | 'Z' => | ||
| 215 | { | ||
| 216 | JABool := cast->ToJArrayZ(p0); | ||
| 217 | for (i = 0; i < length; i++) { | ||
| 218 | (val, ok) = jni->CallMethod(this, "readBoolean", "()Z", nil); | ||
| 219 | JABool.ary[i] = byte val.Boolean(); | ||
| 220 | } | ||
| 221 | } | ||
| 222 | # SIGNATURE_ARRAY | ||
| 223 | '[' => | ||
| 224 | { | ||
| 225 | JAObj := cast->ToJArrayJObject(p0); | ||
| 226 | for (i = 0; i < length; i++) { | ||
| 227 | (val, ok) = jni->CallMethod(this, "readObject", "()Ljava/lang/Object;", nil); | ||
| 228 | JAObj.ary[i] = val.Object(); | ||
| 229 | } | ||
| 230 | } | ||
| 231 | # SIGNATURE_CLASS | ||
| 232 | 'L' => | ||
| 233 | { | ||
| 234 | JAObj := cast->ToJArrayJObject(p0); | ||
| 235 | for (i = 0; i < length; i++) { | ||
| 236 | (val, ok) = jni->CallMethod(this, "readObject", "()Ljava/lang/Object;", nil); | ||
| 237 | JAObj.ary[i] = val.Object(); | ||
| 238 | } | ||
| 239 | } | ||
| 240 | } | ||
| 241 | }#<< | ||
| 242 | |||
| 243 | # | ||
| 244 | # Does class c directly implement interface iface? | ||
| 245 | # | ||
| 246 | directImp(c: ClassData, iface: string): int | ||
| 247 | { | ||
| 248 | l := c.interdirect; | ||
| 249 | while(l != nil) { | ||
| 250 | i := hd l; | ||
| 251 | if(i.name == iface) | ||
| 252 | return 1; | ||
| 253 | l = tl l; | ||
| 254 | } | ||
| 255 | return 0; | ||
| 256 | } | ||
| 257 | |||
| 258 | # | ||
| 259 | # If c directly implements Externalizable, then call its default | ||
| 260 | # constructor (if there is one). | ||
| 261 | # Otherwise, c must directly implement Serializable. In this case, | ||
| 262 | # find the nearest super that doesn't implement Serializable and call | ||
| 263 | # its default constructor (if there is one). | ||
| 264 | # In either case, if there is a constructor to call, then it must be public. | ||
| 265 | # If not, an IllegalAccessException is thrown. | ||
| 266 | # | ||
| 267 | |||
| 268 | callCtor(c: ClassData, o: JObject) | ||
| 269 | { | ||
| 270 | if(directImp(c, "java/io/Externalizable") == 0) { | ||
| 271 | if(directImp(c, "java/io/Serializable") == 0) | ||
| 272 | return; | ||
| 273 | c = c.super; | ||
| 274 | while(c != nil) { | ||
| 275 | if(directImp(c, "java/io/Serializable") == 0) | ||
| 276 | break; | ||
| 277 | c = c.super; | ||
| 278 | } | ||
| 279 | } | ||
| 280 | if(c == nil) | ||
| 281 | return; | ||
| 282 | (mod, ix) := jni->FindMethod(c, "<init>", "()V", JNI->METH_INIT); | ||
| 283 | if(mod == nil) | ||
| 284 | return; | ||
| 285 | flags := jni->GetMethodFlags(c.this, "<init> ()V"); | ||
| 286 | if((flags & JNI->ACC_PUBLIC) == 0) | ||
| 287 | jni->ThrowException("java.lang.IllegalAccessException", ""); | ||
| 288 | low->CallMethod(mod, ix, o, array[0] of ref Value, nil); | ||
| 289 | } | ||
| 290 | |||
| 291 | # | ||
| 292 | # Allocate a new object of class p0. | ||
| 293 | # | ||
| 294 | allocateNewObject_rClass_rClass_rObject(p0 : JClass, p1 : JClass) : JObject | ||
| 295 | {#>> | ||
| 296 | TRACE_1 := p1; | ||
| 297 | o := jni->AllocObject(p0.class); | ||
| 298 | callCtor(p0.class, o); | ||
| 299 | return o; | ||
| 300 | }#<< | ||
| 301 | |||
| 302 | allocateNewArray_rClass_I_rObject( p0 : JClass,p1 : int) : JObject | ||
| 303 | {#>> | ||
| 304 | # | ||
| 305 | # p0 is the class of the array elements | ||
| 306 | # p1 is number of elelments. | ||
| 307 | # | ||
| 308 | # | ||
| 309 | # example transformation..... | ||
| 310 | # jni->MkALong(array[p1] of big) ==> JArrayJ | ||
| 311 | # cast->BigToJArray(JArrayJ (aka BigArray)) ==> JArray | ||
| 312 | # cast->FromJArray(JArray) ==> JObject | ||
| 313 | # | ||
| 314 | case p0.aryname[1] { | ||
| 315 | # SIGNATURE_BYTE | ||
| 316 | 'B' => | ||
| 317 | { | ||
| 318 | # limbo array ==>JArrayB ==>JArray ==>JObject | ||
| 319 | return (cast->FromJArray(cast->ByteToJArray(jni->MkAByte(array[p1] of byte)))); | ||
| 320 | } | ||
| 321 | # SIGNATURE_CHAR | ||
| 322 | 'C' => | ||
| 323 | { | ||
| 324 | # limbo array ==>JArrayC ==>JArray ==>JObject | ||
| 325 | return (cast->FromJArray(cast->IntToJArray(jni->MkAChar(array[p1] of int)))); | ||
| 326 | } | ||
| 327 | # SIGNATURE_FLOAT | ||
| 328 | 'F' => | ||
| 329 | { | ||
| 330 | # limbo array ==>JArrayF ==>JArray ==>JObject | ||
| 331 | return (cast->FromJArray(cast->RealToJArray(jni->MkAFloat(array[p1] of real)))); | ||
| 332 | } | ||
| 333 | # SIGNATURE_DOUBLE | ||
| 334 | 'D' => | ||
| 335 | { | ||
| 336 | # limbo array ==>JArrayD ==>JArray ==>JObject | ||
| 337 | return (cast->FromJArray(cast->RealToJArray(jni->MkADouble(array[p1] of real)))); | ||
| 338 | } | ||
| 339 | # SIGNATURE_INT | ||
| 340 | 'I' => | ||
| 341 | { | ||
| 342 | # limbo array ==>JArrayI ==>JArray ==>JObject | ||
| 343 | return (cast->FromJArray(cast->IntToJArray(jni->MkAInt(array[p1] of int)))); | ||
| 344 | } | ||
| 345 | # SIGNATURE_LONG | ||
| 346 | 'J' => | ||
| 347 | { | ||
| 348 | # limbo array ==>JArrayJ ==>JArray ==>JObject | ||
| 349 | return (cast->FromJArray(cast->BigToJArray(jni->MkALong(array[p1] of big)))); | ||
| 350 | } | ||
| 351 | # SIGNATURE_SHORT | ||
| 352 | 'S' => | ||
| 353 | { | ||
| 354 | # limbo array ==>JArrayS ==>JArray ==>JObject | ||
| 355 | return (cast->FromJArray(cast->IntToJArray(jni->MkAShort(array[p1] of int)))); | ||
| 356 | } | ||
| 357 | # SIGNATURE_BOOLEAN | ||
| 358 | 'Z' => | ||
| 359 | { | ||
| 360 | # limbo array ==>JArrayZ ==>JArray ==>JObject | ||
| 361 | return (cast->FromJArray(cast->ByteToJArray(jni->MkABoolean(array[p1] of byte)))); | ||
| 362 | } | ||
| 363 | # SIGNATURE_ARRAY | ||
| 364 | '[' => | ||
| 365 | { | ||
| 366 | objarray := cast->ObjectToJArray(jni->MkAObject(array[p1] of JObject)); | ||
| 367 | desc := jni->JSigToDescriptor(p0.aryname); | ||
| 368 | objarray.dims = desc.dims; | ||
| 369 | objarray.class = desc.class; | ||
| 370 | objarray.primitive = desc.prim; | ||
| 371 | return (cast->FromJArray(objarray)); | ||
| 372 | } | ||
| 373 | # SIGNATURE_CLASS | ||
| 374 | 'L' => | ||
| 375 | { | ||
| 376 | objarray := cast->ObjectToJArray(jni->MkAObject(array[p1] of JObject)); | ||
| 377 | objarray.class = jni->FindClass(p0.aryname[2:len p0.aryname-1]); | ||
| 378 | return (cast->FromJArray(objarray)); | ||
| 379 | } | ||
| 380 | } | ||
| 381 | jni->ThrowException("java.io.InvalidClassException", "Unknown signature"); | ||
| 382 | return nil; | ||
| 383 | }#<< | ||
| 384 | |||
| 385 | invokeObjectReader_rObject_rClass_Z( this : JObject, p0 : JObject,p1 : JClass) : int | ||
| 386 | {#>> | ||
| 387 | junk := p1; | ||
| 388 | # | ||
| 389 | # call readObject() on object "p0" with an argument of "this" | ||
| 390 | # | ||
| 391 | MyValueArray := array[] of { | ||
| 392 | ref Value.TObject(this) | ||
| 393 | }; | ||
| 394 | (a, b) := jni->CallMethod(p0, "readObject", "(Ljava/io/ObjectInputStream;)V", MyValueArray); | ||
| 395 | |||
| 396 | return b == JNI->OK; | ||
| 397 | }#<< | ||