1 7 15 16 package com.sun.corba.se.impl.io; 17 18 import java.io.InputStream ; 19 import java.io.IOException ; 20 import java.io.StreamCorruptedException ; 21 import java.io.ObjectInputValidation ; 22 import java.io.NotActiveException ; 23 import java.io.InvalidObjectException ; 24 import java.io.InvalidClassException ; 25 import java.io.DataInputStream ; 26 import java.io.OptionalDataException ; 27 import java.io.WriteAbortedException ; 28 import java.io.Externalizable ; 29 import java.io.EOFException ; 30 import java.lang.reflect.*; 31 import java.util.Vector ; 32 import java.util.Stack ; 33 import java.util.Hashtable ; 34 import java.util.Enumeration ; 35 36 import sun.corba.Bridge ; 37 38 import java.security.AccessController ; 39 import java.security.PrivilegedAction ; 40 41 import com.sun.corba.se.impl.io.ObjectStreamClass; 42 import com.sun.corba.se.impl.util.Utility; 43 44 import org.omg.CORBA.portable.ValueInputStream ; 45 46 import org.omg.CORBA.ValueMember ; 47 import org.omg.CORBA.SystemException ; 48 import org.omg.CORBA.TCKind ; 49 import org.omg.CORBA.ORB ; 50 import org.omg.CORBA.CompletionStatus ; 51 import org.omg.CORBA.portable.IndirectionException ; 52 import org.omg.CORBA.MARSHAL ; 53 import org.omg.CORBA.TypeCode ; 54 55 import com.sun.org.omg.CORBA.ValueDefPackage.FullValueDescription; 56 import com.sun.org.omg.SendingContext.CodeBase; 57 58 import javax.rmi.PortableRemoteObject ; 59 import javax.rmi.CORBA.Util ; 60 import javax.rmi.CORBA.ValueHandler ; 61 62 import java.security.*; 63 import java.util.*; 64 65 import com.sun.corba.se.impl.orbutil.ObjectUtility ; 66 import com.sun.corba.se.impl.logging.OMGSystemException ; 67 import com.sun.corba.se.impl.logging.UtilSystemException ; 68 69 import com.sun.corba.se.spi.logging.CORBALogDomains ; 70 71 78 79 public class IIOPInputStream 80 extends com.sun.corba.se.impl.io.InputStreamHook 81 { 82 private static Bridge bridge = 83 (Bridge)AccessController.doPrivileged( 84 new PrivilegedAction () { 85 public Object run() { 86 return Bridge.get() ; 87 } 88 } 89 ) ; 90 91 private static OMGSystemException omgWrapper = OMGSystemException.get( 92 CORBALogDomains.RPC_ENCODING ) ; 93 private static UtilSystemException utilWrapper = UtilSystemException.get( 94 CORBALogDomains.RPC_ENCODING ) ; 95 96 private ValueMember defaultReadObjectFVDMembers[] = null; 108 109 private org.omg.CORBA_2_3.portable.InputStream orbStream; 110 111 private CodeBase cbSender; 112 113 private ValueHandlerImpl vhandler; 115 private Object currentObject = null; 116 117 private ObjectStreamClass currentClassDesc = null; 118 119 private Class currentClass = null; 120 121 private int recursionDepth = 0; 122 123 private int simpleReadDepth = 0; 124 125 ActiveRecursionManager activeRecursionMgr = new ActiveRecursionManager(); 134 135 private IOException abortIOException = null; 136 137 138 private ClassNotFoundException abortClassNotFoundException = null; 139 140 144 private Vector callbacks; 145 146 150 ObjectStreamClass[] classdesc; 151 Class [] classes; 152 int spClass; 153 154 private static final String kEmptyStr = ""; 155 156 public static final TypeCode kRemoteTypeCode = ORB.init().get_primitive_tc(TCKind.tk_objref); 161 public static final TypeCode kValueTypeCode = ORB.init().get_primitive_tc(TCKind.tk_value); 162 163 private static final boolean useFVDOnly = false; 166 167 private byte streamFormatVersion; 168 169 private static final Constructor OPT_DATA_EXCEPTION_CTOR; 173 174 private Object [] readObjectArgList = { this } ; 175 176 static { 177 OPT_DATA_EXCEPTION_CTOR = getOptDataExceptionCtor(); 178 } 179 180 private static Constructor getOptDataExceptionCtor() { 184 185 try { 186 187 Constructor result = 188 189 (Constructor) AccessController.doPrivileged( 190 new PrivilegedExceptionAction() { 191 public java.lang.Object run() 192 throws NoSuchMethodException , 193 SecurityException { 194 195 Constructor boolCtor 196 = OptionalDataException.class.getDeclaredConstructor( 197 new Class [] { 198 Boolean.TYPE }); 199 200 boolCtor.setAccessible(true); 201 202 return boolCtor; 203 }}); 204 205 if (result == null) 206 throw new Error ("Unable to find OptionalDataException constructor"); 208 209 return result; 210 211 } catch (Exception ex) { 212 throw new ExceptionInInitializerError (ex); 214 } 215 } 216 217 private OptionalDataException createOptionalDataException() { 220 try { 221 OptionalDataException result 222 = (OptionalDataException) 223 OPT_DATA_EXCEPTION_CTOR.newInstance(new Object [] { 224 Boolean.TRUE }); 225 226 if (result == null) 227 throw new Error ("Created null OptionalDataException"); 229 230 return result; 231 232 } catch (Exception ex) { 233 throw new Error ("Couldn't create OptionalDataException", ex); 235 } 236 } 237 238 protected byte getStreamFormatVersion() { 241 return streamFormatVersion; 242 } 243 244 private void readFormatVersion() throws IOException { 248 249 streamFormatVersion = orbStream.read_octet(); 250 251 if (streamFormatVersion < 1 || 252 streamFormatVersion > vhandler.getMaximumStreamFormatVersion()) { 253 SystemException sysex = omgWrapper.unsupportedFormatVersion( 254 CompletionStatus.COMPLETED_MAYBE); 255 IOException result = new IOException ("Unsupported format version: " 257 + streamFormatVersion); 258 result.initCause( sysex ) ; 259 throw result ; 260 } 261 262 if (streamFormatVersion == 2) { 263 if (!(orbStream instanceof ValueInputStream )) { 264 SystemException sysex = omgWrapper.notAValueinputstream( 265 CompletionStatus.COMPLETED_MAYBE); 266 IOException result = new IOException ("Not a ValueInputStream"); 268 result.initCause( sysex ) ; 269 throw result; 270 } 271 } 272 } 273 274 public static void setTestFVDFlag(boolean val){ 275 } 277 278 281 public IIOPInputStream() 282 throws java.io.IOException { 283 super(); 284 resetStream(); 285 } 286 287 public final void setOrbStream(org.omg.CORBA_2_3.portable.InputStream os) { 288 orbStream = os; 289 } 290 291 public final org.omg.CORBA_2_3.portable.InputStream getOrbStream() { 292 return orbStream; 293 } 294 295 public final void setSender(CodeBase cb) { 297 cbSender = cb; 298 } 299 300 public final CodeBase getSender() { 301 return cbSender; 302 } 303 304 public final void setValueHandler(ValueHandler vh) { 307 vhandler = (com.sun.corba.se.impl.io.ValueHandlerImpl) vh; 308 } 309 310 public final ValueHandler getValueHandler() { 311 return (javax.rmi.CORBA.ValueHandler ) vhandler; 312 } 313 314 public final void increaseRecursionDepth(){ 315 recursionDepth++; 316 } 317 318 public final int decreaseRecursionDepth(){ 319 return --recursionDepth; 320 } 321 322 357 public final Object readObjectDelegate() throws IOException 358 { 359 try { 360 361 readObjectState.readData(this); 362 363 return orbStream.read_abstract_interface(); 364 } catch (MARSHAL marshalException) { 365 handleOptionalDataMarshalException(marshalException, true); 366 throw marshalException; 367 } catch(IndirectionException cdrie) 368 { 369 return activeRecursionMgr.getObject(cdrie.offset); 373 } 374 } 375 376 final Object simpleReadObject(Class clz, 377 String repositoryID, 378 com.sun.org.omg.SendingContext.CodeBase sender, 379 int offset) 380 381 { 382 383 384 Object prevObject = currentObject; 385 ObjectStreamClass prevClassDesc = currentClassDesc; 386 Class prevClass = currentClass; 387 byte oldStreamFormatVersion = streamFormatVersion; 388 389 simpleReadDepth++; Object obj = null; 391 392 395 try { 396 if (vhandler.useFullValueDescription(clz, repositoryID)) { 398 obj = inputObjectUsingFVD(clz, repositoryID, sender, offset); 399 } else { 400 obj = inputObject(clz, repositoryID, sender, offset); 401 } 402 403 obj = currentClassDesc.readResolve(obj); 404 } 405 catch(ClassNotFoundException cnfe) 406 { 407 bridge.throwException( cnfe ) ; 408 return null; 409 } 410 catch(IOException ioe) 411 { 412 bridge.throwException(ioe) ; 414 return null; 415 } 416 finally { 417 simpleReadDepth --; 418 currentObject = prevObject; 419 currentClassDesc = prevClassDesc; 420 currentClass = prevClass; 421 streamFormatVersion = oldStreamFormatVersion; 422 } 423 424 425 428 IOException exIOE = abortIOException; 429 if (simpleReadDepth == 0) 430 abortIOException = null; 431 if (exIOE != null){ 432 bridge.throwException( exIOE ) ; 433 return null; 434 } 435 436 437 ClassNotFoundException exCNF = abortClassNotFoundException; 438 if (simpleReadDepth == 0) 439 abortClassNotFoundException = null; 440 if (exCNF != null) { 441 bridge.throwException( exCNF ) ; 442 return null; 443 } 444 445 return obj; 446 } 447 448 public final void simpleSkipObject(String repositoryID, 449 com.sun.org.omg.SendingContext.CodeBase sender) 450 451 { 452 453 454 Object prevObject = currentObject; 455 ObjectStreamClass prevClassDesc = currentClassDesc; 456 Class prevClass = currentClass; 457 byte oldStreamFormatVersion = streamFormatVersion; 458 459 simpleReadDepth++; Object obj = null; 461 462 465 try { 466 skipObjectUsingFVD(repositoryID, sender); 467 } 468 catch(ClassNotFoundException cnfe) 469 { 470 bridge.throwException( cnfe ) ; 471 return; 472 } 473 catch(IOException ioe) 474 { 475 bridge.throwException( ioe ) ; 476 return; 477 } 478 finally { 479 simpleReadDepth --; 480 streamFormatVersion = oldStreamFormatVersion; 481 currentObject = prevObject; 482 currentClassDesc = prevClassDesc; 483 currentClass = prevClass; 484 } 485 486 487 490 IOException exIOE = abortIOException; 491 if (simpleReadDepth == 0) 492 abortIOException = null; 493 if (exIOE != null){ 494 bridge.throwException( exIOE ) ; 495 return; 496 } 497 498 499 ClassNotFoundException exCNF = abortClassNotFoundException; 500 if (simpleReadDepth == 0) 501 abortClassNotFoundException = null; 502 if (exCNF != null) { 503 bridge.throwException( exCNF ) ; 504 return; 505 } 506 507 return; 508 } 509 511 523 protected final Object readObjectOverride() 524 throws OptionalDataException, ClassNotFoundException , IOException 525 { 526 return readObjectDelegate(); 527 } 528 529 546 public final void defaultReadObjectDelegate() 547 548 { 549 try { 550 if (currentObject == null || currentClassDesc == null) 551 throw new NotActiveException ("defaultReadObjectDelegate"); 553 554 if (defaultReadObjectFVDMembers != null && 559 defaultReadObjectFVDMembers.length > 0) { 560 561 569 inputClassFields(currentObject, 571 currentClass, 572 currentClassDesc, 573 defaultReadObjectFVDMembers, 574 cbSender); 575 576 } else { 577 578 ObjectStreamField[] fields = 580 currentClassDesc.getFieldsNoCopy(); 581 if (fields.length > 0) { 582 inputClassFields(currentObject, currentClass, fields, cbSender); 583 } 584 } 585 } 586 catch(NotActiveException nae) 587 { 588 bridge.throwException( nae ) ; 589 } 590 catch(IOException ioe) 591 { 592 bridge.throwException( ioe ) ; 593 } 594 catch(ClassNotFoundException cnfe) 595 { 596 bridge.throwException( cnfe ) ; 597 } 598 599 } 600 601 616 public final boolean enableResolveObjectDelegate(boolean enable) 617 618 { 619 return false; 620 } 621 622 625 public final void mark(int readAheadLimit) { 626 orbStream.mark(readAheadLimit); 627 } 628 629 public final boolean markSupported() { 630 return orbStream.markSupported(); 631 } 632 633 public final void reset() throws IOException { 634 try { 635 orbStream.reset(); 636 } catch (Error e) { 637 IOException err = new IOException (e.getMessage()); 638 err.initCause(e) ; 639 throw err ; 640 } 641 } 642 643 public final int available() throws IOException { 644 return 0; } 646 647 public final void close() throws IOException { 648 } 650 651 public final int read() throws IOException { 652 try{ 653 readObjectState.readData(this); 654 655 return (orbStream.read_octet() << 0) & 0x000000FF; 656 } catch (MARSHAL marshalException) { 657 if (marshalException.minor 658 == OMGSystemException.RMIIIOP_OPTIONAL_DATA_INCOMPATIBLE1) { 659 setState(IN_READ_OBJECT_NO_MORE_OPT_DATA); 660 return -1; 661 } 662 663 throw marshalException; 664 } catch(Error e) { 665 IOException exc = new IOException (e.getMessage()); 666 exc.initCause(e) ; 667 throw exc ; 668 } 669 } 670 671 public final int read(byte data[], int offset, int length) throws IOException { 672 try{ 673 readObjectState.readData(this); 674 675 orbStream.read_octet_array(data, offset, length); 676 return length; 677 } catch (MARSHAL marshalException) { 678 if (marshalException.minor 679 == OMGSystemException.RMIIIOP_OPTIONAL_DATA_INCOMPATIBLE1) { 680 setState(IN_READ_OBJECT_NO_MORE_OPT_DATA); 681 return -1; 682 } 683 684 throw marshalException; 685 } catch(Error e) { 686 IOException exc = new IOException (e.getMessage()); 687 exc.initCause(e) ; 688 throw exc ; 689 } 690 691 } 692 693 public final boolean readBoolean() throws IOException { 694 try{ 695 readObjectState.readData(this); 696 697 return orbStream.read_boolean(); 698 } catch (MARSHAL marshalException) { 699 handleOptionalDataMarshalException(marshalException, false); 700 throw marshalException; 701 702 } catch(Error e) { 703 IOException exc = new IOException (e.getMessage()); 704 exc.initCause(e); 705 throw exc ; 706 } 707 } 708 709 public final byte readByte() throws IOException { 710 try{ 711 readObjectState.readData(this); 712 713 return orbStream.read_octet(); 714 } catch (MARSHAL marshalException) { 715 handleOptionalDataMarshalException(marshalException, false); 716 throw marshalException; 717 718 } catch(Error e) { 719 IOException exc = new IOException (e.getMessage()); 720 exc.initCause(e); 721 throw exc ; 722 } 723 } 724 725 public final char readChar() throws IOException { 726 try{ 727 readObjectState.readData(this); 728 729 return orbStream.read_wchar(); 730 } catch (MARSHAL marshalException) { 731 handleOptionalDataMarshalException(marshalException, false); 732 throw marshalException; 733 734 } catch(Error e) { 735 IOException exc = new IOException (e.getMessage()); 736 exc.initCause(e); 737 throw exc ; 738 } 739 } 740 741 public final double readDouble() throws IOException { 742 try{ 743 readObjectState.readData(this); 744 745 return orbStream.read_double(); 746 } catch (MARSHAL marshalException) { 747 handleOptionalDataMarshalException(marshalException, false); 748 throw marshalException; 749 } catch(Error e) { 750 IOException exc = new IOException (e.getMessage()); 751 exc.initCause(e); 752 throw exc ; 753 } 754 } 755 756 public final float readFloat() throws IOException { 757 try{ 758 readObjectState.readData(this); 759 760 return orbStream.read_float(); 761 } catch (MARSHAL marshalException) { 762 handleOptionalDataMarshalException(marshalException, false); 763 throw marshalException; 764 } catch(Error e) { 765 IOException exc = new IOException (e.getMessage()); 766 exc.initCause(e); 767 throw exc ; 768 } 769 } 770 771 public final void readFully(byte data[]) throws IOException { 772 774 readFully(data, 0, data.length); 775 } 776 777 public final void readFully(byte data[], int offset, int size) throws IOException { 778 try{ 780 readObjectState.readData(this); 781 782 orbStream.read_octet_array(data, offset, size); 783 } catch (MARSHAL marshalException) { 784 handleOptionalDataMarshalException(marshalException, false); 785 786 throw marshalException; 787 } catch(Error e) { 788 IOException exc = new IOException (e.getMessage()); 789 exc.initCause(e); 790 throw exc ; 791 } 792 } 793 794 public final int readInt() throws IOException { 795 try{ 796 readObjectState.readData(this); 797 798 return orbStream.read_long(); 799 } catch (MARSHAL marshalException) { 800 handleOptionalDataMarshalException(marshalException, false); 801 throw marshalException; 802 } catch(Error e) { 803 IOException exc = new IOException (e.getMessage()); 804 exc.initCause(e); 805 throw exc ; 806 } 807 } 808 809 public final String readLine() throws IOException { 810 throw new IOException ("Method readLine not supported"); 812 } 813 814 public final long readLong() throws IOException { 815 try{ 816 readObjectState.readData(this); 817 818 return orbStream.read_longlong(); 819 } catch (MARSHAL marshalException) { 820 handleOptionalDataMarshalException(marshalException, false); 821 throw marshalException; 822 } catch(Error e) { 823 IOException exc = new IOException (e.getMessage()); 824 exc.initCause(e); 825 throw exc ; 826 } 827 } 828 829 public final short readShort() throws IOException { 830 try{ 831 readObjectState.readData(this); 832 833 return orbStream.read_short(); 834 } catch (MARSHAL marshalException) { 835 handleOptionalDataMarshalException(marshalException, false); 836 throw marshalException; 837 } catch(Error e) { 838 IOException exc = new IOException (e.getMessage()); 839 exc.initCause(e); 840 throw exc ; 841 } 842 } 843 844 protected final void readStreamHeader() throws IOException , StreamCorruptedException { 845 } 847 848 public final int readUnsignedByte() throws IOException { 849 try{ 850 readObjectState.readData(this); 851 852 return (orbStream.read_octet() << 0) & 0x000000FF; 853 } catch (MARSHAL marshalException) { 854 handleOptionalDataMarshalException(marshalException, false); 855 throw marshalException; 856 } catch(Error e) { 857 IOException exc = new IOException (e.getMessage()); 858 exc.initCause(e); 859 throw exc ; 860 } 861 } 862 863 public final int readUnsignedShort() throws IOException { 864 try{ 865 readObjectState.readData(this); 866 867 return (orbStream.read_ushort() << 0) & 0x0000FFFF; 868 } catch (MARSHAL marshalException) { 869 handleOptionalDataMarshalException(marshalException, false); 870 throw marshalException; 871 } catch(Error e) { 872 IOException exc = new IOException (e.getMessage()); 873 exc.initCause(e); 874 throw exc ; 875 } 876 } 877 878 884 protected String internalReadUTF(org.omg.CORBA.portable.InputStream stream) 885 { 886 return stream.read_wstring(); 887 } 888 889 public final String readUTF() throws IOException { 890 try{ 891 readObjectState.readData(this); 892 893 return internalReadUTF(orbStream); 894 } catch (MARSHAL marshalException) { 895 handleOptionalDataMarshalException(marshalException, false); 896 throw marshalException; 897 } catch(Error e) { 898 IOException exc = new IOException (e.getMessage()); 899 exc.initCause(e); 900 throw exc ; 901 } 902 } 903 904 private void handleOptionalDataMarshalException(MARSHAL marshalException, 912 boolean objectRead) 913 throws IOException { 914 915 if (marshalException.minor 922 == OMGSystemException.RMIIIOP_OPTIONAL_DATA_INCOMPATIBLE1) { 923 924 IOException result; 925 926 if (!objectRead) 927 result = new EOFException ("No more optional data"); 928 else 929 result = createOptionalDataException(); 930 931 result.initCause(marshalException); 932 933 setState(IN_READ_OBJECT_NO_MORE_OPT_DATA); 934 935 throw result; 936 } 937 } 938 939 public final synchronized void registerValidation(ObjectInputValidation obj, 940 int prio) 941 throws NotActiveException , InvalidObjectException { 942 throw new Error ("Method registerValidation not supported"); 944 } 945 946 protected final Class resolveClass(ObjectStreamClass v) 947 throws IOException , ClassNotFoundException { 948 throw new IOException ("Method resolveClass not supported"); 950 } 951 952 protected final Object resolveObject(Object obj) throws IOException { 953 throw new IOException ("Method resolveObject not supported"); 955 } 956 957 public final int skipBytes(int len) throws IOException { 958 try{ 959 readObjectState.readData(this); 960 961 byte buf[] = new byte[len]; 962 orbStream.read_octet_array(buf, 0, len); 963 return len; 964 } catch (MARSHAL marshalException) { 965 handleOptionalDataMarshalException(marshalException, false); 966 967 throw marshalException; 968 } catch(Error e) { 969 IOException exc = new IOException (e.getMessage()); 970 exc.initCause(e) ; 971 throw exc ; 972 } 973 } 974 975 private Object inputObject(Class clz, 976 String repositoryID, 977 com.sun.org.omg.SendingContext.CodeBase sender, 978 int offset) 979 throws IOException , ClassNotFoundException 980 { 981 982 985 986 currentClassDesc = ObjectStreamClass.lookup(clz); 987 currentClass = currentClassDesc.forClass(); 988 if (currentClass == null) 990 throw new ClassNotFoundException (currentClassDesc.getName()); 992 993 try { 994 999 if (currentClassDesc.isExternalizable()) { 1000 try { 1001 currentObject = (currentClass == null) ? 1002 null : currentClassDesc.newInstance(); 1003 if (currentObject != null) { 1004 1005 activeRecursionMgr.addObject(offset, currentObject); 1009 1010 readFormatVersion(); 1012 1013 Externalizable ext = (Externalizable )currentObject; 1014 ext.readExternal(this); 1015 } 1016 } catch (InvocationTargetException e) { 1017 InvalidClassException exc = new InvalidClassException ( 1018 currentClass.getName(), 1019 "InvocationTargetException accessing no-arg constructor"); 1020 exc.initCause( e ) ; 1021 throw exc ; 1022 } catch (UnsupportedOperationException e) { 1023 InvalidClassException exc = new InvalidClassException ( 1024 currentClass.getName(), 1025 "UnsupportedOperationException accessing no-arg constructor"); 1026 exc.initCause( e ) ; 1027 throw exc ; 1028 } catch (InstantiationException e) { 1029 InvalidClassException exc = new InvalidClassException ( 1030 currentClass.getName(), 1031 "InstantiationException accessing no-arg constructor"); 1032 exc.initCause( e ) ; 1033 throw exc ; 1034 } 1035 } else { 1037 1040 1041 ObjectStreamClass currdesc = currentClassDesc; 1042 Class currclass = currentClass; 1043 1044 int spBase = spClass; 1046 1061 1062 1066 1075 for (currdesc = currentClassDesc, currclass = currentClass; 1076 currdesc != null && currdesc.isSerializable(); 1077 currdesc = currdesc.getSuperclass()) { 1078 1079 1086 Class cc = currdesc.forClass(); 1087 Class cl; 1088 for (cl = currclass; cl != null; cl = cl.getSuperclass()) { 1089 if (cc == cl) { 1090 break; 1092 } else { 1093 1097 } 1098 } 1102 spClass++; 1103 if (spClass >= classes.length) { 1104 int newlen = classes.length * 2; 1105 Class [] newclasses = new Class [newlen]; 1106 ObjectStreamClass[] newclassdesc = new ObjectStreamClass[newlen]; 1107 1108 System.arraycopy(classes, 0, 1109 newclasses, 0, 1110 classes.length); 1111 System.arraycopy(classdesc, 0, 1112 newclassdesc, 0, 1113 classes.length); 1114 1115 classes = newclasses; 1116 classdesc = newclassdesc; 1117 } 1118 1119 if (cl == null) { 1120 1124 classdesc[spClass] = currdesc; 1125 classes[spClass] = null; 1126 } else { 1127 1132 classdesc[spClass] = currdesc; 1133 classes[spClass] = cl; 1134 currclass = cl.getSuperclass(); 1135 } 1136 } 1138 1142 try { 1143 currentObject = (currentClass == null) ? 1144 null : currentClassDesc.newInstance() ; 1145 1146 activeRecursionMgr.addObject(offset, currentObject); 1150 } catch (InvocationTargetException e) { 1151 InvalidClassException exc = new InvalidClassException ( 1152 currentClass.getName(), 1153 "InvocationTargetException accessing no-arg constructor"); 1154 exc.initCause( e ) ; 1155 throw exc ; 1156 } catch (UnsupportedOperationException e) { 1157 InvalidClassException exc = new InvalidClassException ( 1158 currentClass.getName(), 1159 "UnsupportedOperationException accessing no-arg constructor"); 1160 exc.initCause( e ) ; 1161 throw exc ; 1162 } catch (InstantiationException e) { 1163 InvalidClassException exc = new InvalidClassException ( 1164 currentClass.getName(), 1165 "InstantiationException accessing no-arg constructor"); 1166 exc.initCause( e ) ; 1167 throw exc ; 1168 } 1169 1170 1177 try { 1178 for (spClass = spClass; spClass > spBase; spClass--) { 1179 1182 currentClassDesc = classdesc[spClass]; 1183 currentClass = classes[spClass]; 1184 if (classes[spClass] != null) { 1185 1188 1189 ReadObjectState oldState = readObjectState; 1190 setState(DEFAULT_STATE); 1191 1192 try { 1193 1194 if (currentClassDesc.hasWriteObject()) { 1196 1197 readFormatVersion(); 1199 1200 boolean calledDefaultWriteObject = readBoolean(); 1202 1203 readObjectState.beginUnmarshalCustomValue(this, 1204 calledDefaultWriteObject, 1205 (currentClassDesc.readObjectMethod 1206 != null)); 1207 } else { 1208 if (currentClassDesc.hasReadObject()) 1209 setState(IN_READ_OBJECT_REMOTE_NOT_CUSTOM_MARSHALED); 1210 } 1211 1212 if (!invokeObjectReader(currentClassDesc, currentObject, currentClass) || 1213 readObjectState == IN_READ_OBJECT_DEFAULTS_SENT) { 1214 1215 1218 ObjectStreamField[] fields = 1219 currentClassDesc.getFieldsNoCopy(); 1220 if (fields.length > 0) { 1221 inputClassFields(currentObject, currentClass, fields, sender); 1222 } 1223 } 1224 1225 if (currentClassDesc.hasWriteObject()) 1226 readObjectState.endUnmarshalCustomValue(this); 1227 1228 } finally { 1229 setState(oldState); 1230 } 1231 1232 } else { 1233 1234 1240 ObjectStreamField[] fields = 1241 currentClassDesc.getFieldsNoCopy(); 1242 if (fields.length > 0) { 1243 inputClassFields(null, currentClass, fields, sender); 1244 } 1245 1246 } 1247 1248 } 1249 } finally { 1250 spClass = spBase; 1252 } 1253 } 1254 } finally { 1255 activeRecursionMgr.removeObject(offset); 1260 } 1261 1262 return currentObject; 1263 } 1264 1265 private Vector getOrderedDescriptions(String repositoryID, 1269 com.sun.org.omg.SendingContext.CodeBase sender) { 1270 Vector descs = new Vector (); 1271 1272 if (sender == null) { 1273 return descs; 1274 } 1275 1276 FullValueDescription aFVD = sender.meta(repositoryID); 1277 while (aFVD != null) { 1278 descs.insertElementAt(aFVD, 0); 1279 if ((aFVD.base_value != null) && !kEmptyStr.equals(aFVD.base_value)) { 1280 aFVD = sender.meta(aFVD.base_value); 1281 } 1282 else return descs; 1283 } 1284 1285 return descs; 1286 } 1287 1288 1300 private Object inputObjectUsingFVD(Class clz, 1301 String repositoryID, 1302 com.sun.org.omg.SendingContext.CodeBase sender, 1303 int offset) 1304 throws IOException , ClassNotFoundException 1305 { 1306 int spBase = spClass; try{ 1308 1309 1312 1313 ObjectStreamClass currdesc = currentClassDesc = ObjectStreamClass.lookup(clz); 1314 Class currclass = currentClass = clz; 1315 1316 1321 if (currentClassDesc.isExternalizable()) { 1322 try { 1323 currentObject = (currentClass == null) ? 1324 null : currentClassDesc.newInstance(); 1325 if (currentObject != null) { 1326 activeRecursionMgr.addObject(offset, currentObject); 1330 1331 readFormatVersion(); 1333 1334 Externalizable ext = (Externalizable )currentObject; 1335 ext.readExternal(this); 1336 } 1337 } catch (InvocationTargetException e) { 1338 InvalidClassException exc = new InvalidClassException ( 1339 currentClass.getName(), 1340 "InvocationTargetException accessing no-arg constructor"); 1341 exc.initCause( e ) ; 1342 throw exc ; 1343 } catch (UnsupportedOperationException e) { 1344 InvalidClassException exc = new InvalidClassException ( 1345 currentClass.getName(), 1346 "UnsupportedOperationException accessing no-arg constructor"); 1347 exc.initCause( e ) ; 1348 throw exc ; 1349 } catch (InstantiationException e) { 1350 InvalidClassException exc = new InvalidClassException ( 1351 currentClass.getName(), 1352 "InstantiationException accessing no-arg constructor"); 1353 exc.initCause( e ) ; 1354 throw exc ; 1355 } 1356 } else { 1357 1361 for (currdesc = currentClassDesc, currclass = currentClass; 1362 currdesc != null && currdesc.isSerializable(); 1363 1364 currdesc = currdesc.getSuperclass()) { 1365 1366 1373 Class cc = currdesc.forClass(); 1374 Class cl; 1375 for (cl = currclass; cl != null; cl = cl.getSuperclass()) { 1376 if (cc == cl) { 1377 break; 1379 } else { 1380 1384 } 1385 } 1389 spClass++; 1390 if (spClass >= classes.length) { 1391 int newlen = classes.length * 2; 1392 Class [] newclasses = new Class [newlen]; 1393 ObjectStreamClass[] newclassdesc = new ObjectStreamClass[newlen]; 1394 1395 System.arraycopy(classes, 0, 1396 newclasses, 0, 1397 classes.length); 1398 System.arraycopy(classdesc, 0, 1399 newclassdesc, 0, 1400 classes.length); 1401 1402 classes = newclasses; 1403 classdesc = newclassdesc; 1404 } 1405 1406 if (cl == null) { 1407 1411 classdesc[spClass] = currdesc; 1412 classes[spClass] = null; 1413 } else { 1414 1419 classdesc[spClass] = currdesc; 1420 classes[spClass] = cl; 1421 currclass = cl.getSuperclass(); 1422 } 1423 } 1425 1427 try { 1428 currentObject = (currentClass == null) ? 1429 null : currentClassDesc.newInstance(); 1430 1431 activeRecursionMgr.addObject(offset, currentObject); 1435 } catch (InvocationTargetException e) { 1436 InvalidClassException exc = new InvalidClassException ( 1437 currentClass.getName(), 1438 "InvocationTargetException accessing no-arg constructor"); 1439 exc.initCause( e ) ; 1440 throw exc ; 1441 } catch (UnsupportedOperationException e) { 1442 InvalidClassException exc = new InvalidClassException ( 1443 currentClass.getName(), 1444 "UnsupportedOperationException accessing no-arg constructor"); 1445 exc.initCause( e ) ; 1446 throw exc ; 1447 } catch (InstantiationException e) { 1448 InvalidClassException exc = new InvalidClassException ( 1449 currentClass.getName(), 1450 "InstantiationException accessing no-arg constructor"); 1451 exc.initCause( e ) ; 1452 throw exc ; 1453 } 1454 1455 Enumeration fvdsList = getOrderedDescriptions(repositoryID, sender).elements(); 1456 1457 while((fvdsList.hasMoreElements()) && (spClass > spBase)) { 1458 FullValueDescription fvd = (FullValueDescription)fvdsList.nextElement(); 1459 String repIDForFVD = vhandler.getClassName(fvd.id); 1461 String repIDForClass = vhandler.getClassName(vhandler.getRMIRepositoryID(currentClass)); 1462 1463 while ((spClass > spBase) && 1464 (!repIDForFVD.equals(repIDForClass))) { 1465 int pos = findNextClass(repIDForFVD, classes, spClass, spBase); 1466 if (pos != -1) { 1467 spClass = pos; 1468 currclass = currentClass = classes[spClass]; 1469 repIDForClass = vhandler.getClassName(vhandler.getRMIRepositoryID(currentClass)); 1470 } 1471 else { 1473 1476 if (fvd.is_custom) { 1477 1478 readFormatVersion(); 1479 boolean calledDefaultWriteObject = readBoolean(); 1480 1481 if (calledDefaultWriteObject) 1482 inputClassFields(null, null, null, fvd.members, sender); 1483 1484 if (getStreamFormatVersion() == 2) { 1485 1486 ((ValueInputStream )getOrbStream()).start_value(); 1487 ((ValueInputStream )getOrbStream()).end_value(); 1488 } 1489 1490 1494 } else { 1495 1496 inputClassFields(null, currentClass, null, fvd.members, sender); 1497 } 1498 1499 if (fvdsList.hasMoreElements()){ 1500 fvd = (FullValueDescription)fvdsList.nextElement(); 1501 repIDForFVD = vhandler.getClassName(fvd.id); 1502 } 1503 else return currentObject; 1504 } 1505 } 1506 1507 currdesc = currentClassDesc = ObjectStreamClass.lookup(currentClass); 1508 1509 if (!repIDForClass.equals("java.lang.Object")) { 1510 1511 1516 ReadObjectState oldState = readObjectState; 1517 setState(DEFAULT_STATE); 1518 1519 try { 1520 1521 if (fvd.is_custom) { 1522 1523 readFormatVersion(); 1525 1526 boolean calledDefaultWriteObject = readBoolean(); 1528 1529 readObjectState.beginUnmarshalCustomValue(this, 1530 calledDefaultWriteObject, 1531 (currentClassDesc.readObjectMethod 1532 != null)); 1533 } 1534 1535 boolean usedReadObject = false; 1536 1537 try { 1540 1541 if (!fvd.is_custom && currentClassDesc.hasReadObject()) 1542 setState(IN_READ_OBJECT_REMOTE_NOT_CUSTOM_MARSHALED); 1543 1544 defaultReadObjectFVDMembers = fvd.members; 1548 usedReadObject = invokeObjectReader(currentClassDesc, 1549 currentObject, 1550 currentClass); 1551 1552 } finally { 1553 defaultReadObjectFVDMembers = null; 1554 } 1555 1556 if (!usedReadObject || readObjectState == IN_READ_OBJECT_DEFAULTS_SENT) 1560 inputClassFields(currentObject, currentClass, currdesc, fvd.members, sender); 1561 1562 if (fvd.is_custom) 1563 readObjectState.endUnmarshalCustomValue(this); 1564 1565 } finally { 1566 setState(oldState); 1567 } 1568 1569 currclass = currentClass = classes[--spClass]; 1570 1571 } else { 1572 1573 inputClassFields(null, currentClass, null, fvd.members, sender); 1577 1578 while (fvdsList.hasMoreElements()){ 1579 fvd = (FullValueDescription)fvdsList.nextElement(); 1580 1581 if (fvd.is_custom) 1582 skipCustomUsingFVD(fvd.members, sender); 1583 else 1584 inputClassFields(null, currentClass, null, fvd.members, sender); 1585 } 1586 1587 } 1588 1589 } while (fvdsList.hasMoreElements()){ 1591 1592 FullValueDescription fvd = (FullValueDescription)fvdsList.nextElement(); 1593 if (fvd.is_custom) 1594 skipCustomUsingFVD(fvd.members, sender); 1595 else 1596 throwAwayData(fvd.members, sender); 1597 } 1598 } 1599 1600 return currentObject; 1601 } 1602 finally { 1603 spClass = spBase; 1605 1606 activeRecursionMgr.removeObject(offset); 1611 } 1612 1613 } 1614 1615 1625 private Object skipObjectUsingFVD(String repositoryID, 1626 com.sun.org.omg.SendingContext.CodeBase sender) 1627 throws IOException , ClassNotFoundException 1628 { 1629 1630 Enumeration fvdsList = getOrderedDescriptions(repositoryID, sender).elements(); 1631 1632 while(fvdsList.hasMoreElements()) { 1633 FullValueDescription fvd = (FullValueDescription)fvdsList.nextElement(); 1634 String repIDForFVD = vhandler.getClassName(fvd.id); 1635 1636 if (!repIDForFVD.equals("java.lang.Object")) { 1637 if (fvd.is_custom) { 1638 1639 readFormatVersion(); 1640 1641 boolean calledDefaultWriteObject = readBoolean(); 1642 1643 if (calledDefaultWriteObject) 1644 inputClassFields(null, null, null, fvd.members, sender); 1645 1646 if (getStreamFormatVersion() == 2) { 1647 1648 ((ValueInputStream )getOrbStream()).start_value(); 1649 ((ValueInputStream )getOrbStream()).end_value(); 1650 } 1651 1652 1656 } else { 1657 inputClassFields(null, null, null, fvd.members, sender); 1659 } 1660 } 1661 1662 } return null; 1664 1665 } 1666 1667 1669 private int findNextClass(String classname, Class classes[], int _spClass, int _spBase){ 1670 1671 for (int i = _spClass; i > _spBase; i--){ 1672 if (classname.equals(classes[i].getName())) { 1673 return i; 1674 } 1675 } 1676 1677 return -1; 1678 } 1679 1680 1685 private boolean invokeObjectReader(ObjectStreamClass osc, Object obj, Class aclass) 1686 throws InvalidClassException , StreamCorruptedException , 1687 ClassNotFoundException , IOException 1688 { 1689 if (osc.readObjectMethod == null) { 1690 return false; 1691 } 1692 1693 try { 1694 osc.readObjectMethod.invoke( obj, readObjectArgList ) ; 1695 return true; 1696 } catch (InvocationTargetException e) { 1697 Throwable t = e.getTargetException(); 1698 if (t instanceof ClassNotFoundException ) 1699 throw (ClassNotFoundException )t; 1700 else if (t instanceof IOException ) 1701 throw (IOException )t; 1702 else if (t instanceof RuntimeException ) 1703 throw (RuntimeException ) t; 1704 else if (t instanceof Error ) 1705 throw (Error ) t; 1706 else 1707 throw new Error ("internal error"); 1709 } catch (IllegalAccessException e) { 1710 return false; 1711 } 1712 } 1713 1714 1717 private void resetStream() throws IOException { 1718 1719 if (classes == null) 1720 classes = new Class [20]; 1721 else { 1722 for (int i = 0; i < classes.length; i++) 1723 classes[i] = null; 1724 } 1725 if (classdesc == null) 1726 classdesc = new ObjectStreamClass[20]; 1727 else { 1728 for (int i = 0; i < classdesc.length; i++) 1729 classdesc[i] = null; 1730 } 1731 spClass = 0; 1732 1733 if (callbacks != null) 1734 callbacks.setSize(0); } 1736 1737 1744 private void inputPrimitiveField(Object o, Class cl, ObjectStreamField field) 1745 throws InvalidClassException , IOException { 1746 1747 try { 1748 switch (field.getTypeCode()) { 1749 case 'B': 1750 byte byteValue = orbStream.read_octet(); 1751 bridge.putByte( o, field.getFieldID(), byteValue ) ; 1752 break; 1754 case 'Z': 1755 boolean booleanValue = orbStream.read_boolean(); 1756 bridge.putBoolean( o, field.getFieldID(), booleanValue ) ; 1757 break; 1759 case 'C': 1760 char charValue = orbStream.read_wchar(); 1761 bridge.putChar( o, field.getFieldID(), charValue ) ; 1762 break; 1764 case 'S': 1765 short shortValue = orbStream.read_short(); 1766 bridge.putShort( o, field.getFieldID(), shortValue ) ; 1767 break; 1769 case 'I': 1770 int intValue = orbStream.read_long(); 1771 bridge.putInt( o, field.getFieldID(), intValue ) ; 1772 break; 1774 case 'J': 1775 long longValue = orbStream.read_longlong(); 1776 bridge.putLong( o, field.getFieldID(), longValue ) ; 1777 break; 1779 case 'F' : 1780 float floatValue = orbStream.read_float(); 1781 bridge.putFloat( o, field.getFieldID(), floatValue ) ; 1782 break; 1784 case 'D' : 1785 double doubleValue = orbStream.read_double(); 1786 bridge.putDouble( o, field.getFieldID(), doubleValue ) ; 1787 break; 1789 default: 1790 throw new InvalidClassException (cl.getName()); 1792 } 1793 } catch (IllegalArgumentException e) { 1794 1797 ClassCastException cce = new ClassCastException ("Assigning instance of class " + 1798 field.getType().getName() + 1799 " to field " + 1800 currentClassDesc.getName() + '#' + 1801 field.getField().getName()); 1802 cce.initCause( e ) ; 1803 throw cce ; 1804 } 1805 } 1806 1807 private Object inputObjectField(org.omg.CORBA.ValueMember field, 1808 com.sun.org.omg.SendingContext.CodeBase sender) 1809 throws IndirectionException , ClassNotFoundException , IOException , 1810 StreamCorruptedException { 1811 1812 Object objectValue = null; 1813 Class type = null; 1814 String id = field.id; 1815 1816 try { 1817 type = vhandler.getClassFromType(id); 1818 } catch(ClassNotFoundException cnfe) { 1819 type = null; 1821 } 1822 1823 String signature = null; 1824 if (type != null) 1825 signature = ValueUtility.getSignature(field); 1826 1827 if (signature != null && (signature.equals("Ljava/lang/Object;") || 1828 signature.equals("Ljava/io/Serializable;") || 1829 signature.equals("Ljava/io/Externalizable;"))) { 1830 objectValue = javax.rmi.CORBA.Util.readAny(orbStream); 1831 } else { 1832 1840 int callType = ValueHandlerImpl.kValueType; 1841 1842 if (!vhandler.isSequence(id)) { 1843 1844 if (field.type.kind().value() == kRemoteTypeCode.kind().value()) { 1845 1846 callType = ValueHandlerImpl.kRemoteType; 1848 1849 } else { 1850 1851 1857 1864 if (type != null && type.isInterface() && 1865 (vhandler.isAbstractBase(type) || 1866 ObjectStreamClassCorbaExt.isAbstractInterface(type))) { 1867 1868 callType = ValueHandlerImpl.kAbstractType; 1869 } 1870 } 1871 } 1872 1873 1877 switch (callType) { 1878 case ValueHandlerImpl.kRemoteType: 1879 if (type != null) 1880 objectValue = Utility.readObjectAndNarrow(orbStream, type); 1881 else 1882 objectValue = orbStream.read_Object(); 1883 break; 1884 case ValueHandlerImpl.kAbstractType: 1885 if (type != null) 1886 objectValue = Utility.readAbstractAndNarrow(orbStream, type); 1887 else 1888 objectValue = orbStream.read_abstract_interface(); 1889 break; 1890 case ValueHandlerImpl.kValueType: 1891 if (type != null) 1892 objectValue = orbStream.read_value(type); 1893 else 1894 objectValue = orbStream.read_value(); 1895 break; 1896 default: 1897 throw new StreamCorruptedException ("Unknown callType: " + callType); 1899 } 1900 } 1901 1902 return objectValue; 1903 } 1904 1905 1912 private Object inputObjectField(ObjectStreamField field) 1913 throws InvalidClassException , StreamCorruptedException , 1914 ClassNotFoundException , IndirectionException , IOException { 1915 1916 if (ObjectStreamClassCorbaExt.isAny(field.getTypeString())) { 1917 return javax.rmi.CORBA.Util.readAny(orbStream); 1918 } 1919 1920 Object objectValue = null; 1921 1922 Class fieldType = field.getType(); 1926 Class actualType = fieldType; 1928 1932 int callType = ValueHandlerImpl.kValueType; 1933 boolean narrow = false; 1934 1935 if (fieldType.isInterface()) { 1936 boolean loadStubClass = false; 1937 1938 if (java.rmi.Remote .class.isAssignableFrom(fieldType)) { 1939 1940 callType = ValueHandlerImpl.kRemoteType; 1942 1943 } else if (org.omg.CORBA.Object .class.isAssignableFrom(fieldType)){ 1944 1945 callType = ValueHandlerImpl.kRemoteType; 1947 loadStubClass = true; 1948 1949 } else if (vhandler.isAbstractBase(fieldType)) { 1950 1952 callType = ValueHandlerImpl.kAbstractType; 1953 loadStubClass = true; 1954 } else if (ObjectStreamClassCorbaExt.isAbstractInterface(fieldType)) { 1955 1957 callType = ValueHandlerImpl.kAbstractType; 1958 } 1959 1960 if (loadStubClass) { 1961 try { 1962 String codebase = Util.getCodebase(fieldType); 1963 String repID = vhandler.createForAnyType(fieldType); 1964 Class stubType = 1965 Utility.loadStubClass(repID, codebase, fieldType); 1966 actualType = stubType; 1967 } catch (ClassNotFoundException e) { 1968 narrow = true; 1969 } 1970 } else { 1971 narrow = true; 1972 } 1973 } 1974 1975 switch (callType) { 1976 case ValueHandlerImpl.kRemoteType: 1977 if (!narrow) 1978 objectValue = (Object )orbStream.read_Object(actualType); 1979 else 1980 objectValue = Utility.readObjectAndNarrow(orbStream, actualType); 1981 break; 1982 case ValueHandlerImpl.kAbstractType: 1983 if (!narrow) 1984 objectValue = (Object )orbStream.read_abstract_interface(actualType); 1985 else 1986 objectValue = Utility.readAbstractAndNarrow(orbStream, actualType); 1987 break; 1988 case ValueHandlerImpl.kValueType: 1989 objectValue = (Object )orbStream.read_value(actualType); 1990 break; 1991 default: 1992 throw new StreamCorruptedException ("Unknown callType: " + callType); 1994 } 1995 1996 return objectValue; 1997 } 1998 1999 private final boolean mustUseRemoteValueMembers() { 2000 return defaultReadObjectFVDMembers != null; 2001 } 2002 2003 void readFields(java.util.Map fieldToValueMap) 2004 throws InvalidClassException , StreamCorruptedException , 2005 ClassNotFoundException , IOException { 2006 2007 if (mustUseRemoteValueMembers()) { 2008 inputRemoteMembersForReadFields(fieldToValueMap); 2009 } else 2010 inputCurrentClassFieldsForReadFields(fieldToValueMap); 2011 } 2012 2013 private final void inputRemoteMembersForReadFields(java.util.Map fieldToValueMap) 2014 throws InvalidClassException , StreamCorruptedException , 2015 ClassNotFoundException , IOException { 2016 2017 ValueMember fields[] = defaultReadObjectFVDMembers; 2020 2021 try { 2022 2023 for (int i = 0; i < fields.length; i++) { 2024 2025 switch (fields[i].type.kind().value()) { 2026 2027 case TCKind._tk_octet: 2028 byte byteValue = orbStream.read_octet(); 2029 fieldToValueMap.put(fields[i].name, new Byte (byteValue)); 2030 break; 2031 case TCKind._tk_boolean: 2032 boolean booleanValue = orbStream.read_boolean(); 2033 fieldToValueMap.put(fields[i].name, new Boolean (booleanValue)); 2034 break; 2035 case TCKind._tk_char: 2036 case TCKind._tk_wchar: 2042 char charValue = orbStream.read_wchar(); 2043 fieldToValueMap.put(fields[i].name, new Character (charValue)); 2044 break; 2045 case TCKind._tk_short: 2046 short shortValue = orbStream.read_short(); 2047 fieldToValueMap.put(fields[i].name, new Short (shortValue)); 2048 break; 2049 case TCKind._tk_long: 2050 int intValue = orbStream.read_long(); 2051 fieldToValueMap.put(fields[i].name, new Integer (intValue)); 2052 break; 2053 case TCKind._tk_longlong: 2054 long longValue = orbStream.read_longlong(); 2055 fieldToValueMap.put(fields[i].name, new Long (longValue)); 2056 break; 2057 case TCKind._tk_float: 2058 float floatValue = orbStream.read_float(); 2059 fieldToValueMap.put(fields[i].name, new Float (floatValue)); 2060 break; 2061 case TCKind._tk_double: 2062 double doubleValue = orbStream.read_double(); 2063 fieldToValueMap.put(fields[i].name, new Double (doubleValue)); 2064 break; 2065 case TCKind._tk_value: 2066 case TCKind._tk_objref: 2067 case TCKind._tk_value_box: 2068 Object objectValue = null; 2069 try { 2070 objectValue = inputObjectField(fields[i], 2071 cbSender); 2072 2073 } catch (IndirectionException cdrie) { 2074 objectValue = activeRecursionMgr.getObject(cdrie.offset); 2078 } 2079 2080 fieldToValueMap.put(fields[i].name, objectValue); 2081 break; 2082 default: 2083 throw new StreamCorruptedException ("Unknown kind: " 2085 + fields[i].type.kind().value()); 2086 } 2087 } 2088 } catch (Throwable t) { 2089 StreamCorruptedException result = new StreamCorruptedException (t.getMessage()); 2090 result.initCause(t); 2091 throw result; 2092 } 2093 } 2094 2095 2103 private final void inputCurrentClassFieldsForReadFields(java.util.Map fieldToValueMap) 2104 throws InvalidClassException , StreamCorruptedException , 2105 ClassNotFoundException , IOException { 2106 2107 ObjectStreamField[] fields = currentClassDesc.getFieldsNoCopy(); 2108 2109 int primFields = fields.length - currentClassDesc.objFields; 2110 2111 for (int i = 0; i < primFields; ++i) { 2113 2114 switch (fields[i].getTypeCode()) { 2115 case 'B': 2116 byte byteValue = orbStream.read_octet(); 2117 fieldToValueMap.put(fields[i].getName(), 2118 new Byte (byteValue)); 2119 break; 2120 case 'Z': 2121 boolean booleanValue = orbStream.read_boolean(); 2122 fieldToValueMap.put(fields[i].getName(), 2123 new Boolean (booleanValue)); 2124 break; 2125 case 'C': 2126 char charValue = orbStream.read_wchar(); 2127 fieldToValueMap.put(fields[i].getName(), 2128 new Character (charValue)); 2129 break; 2130 case 'S': 2131 short shortValue = orbStream.read_short(); 2132 fieldToValueMap.put(fields[i].getName(), 2133 new Short (shortValue)); 2134 break; 2135 case 'I': 2136 int intValue = orbStream.read_long(); 2137 fieldToValueMap.put(fields[i].getName(), 2138 new Integer (intValue)); 2139 break; 2140 case 'J': 2141 long longValue = orbStream.read_longlong(); 2142 fieldToValueMap.put(fields[i].getName(), 2143 new Long (longValue)); 2144 break; 2145 case 'F' : 2146 float floatValue = orbStream.read_float(); 2147 fieldToValueMap.put(fields[i].getName(), 2148 new Float (floatValue)); 2149 break; 2150 case 'D' : 2151 double doubleValue = orbStream.read_double(); 2152 fieldToValueMap.put(fields[i].getName(), 2153 new Double (doubleValue)); 2154 break; 2155 default: 2156 throw new InvalidClassException (currentClassDesc.getName()); 2158 } 2159 } 2160 2161 2162 if (currentClassDesc.objFields > 0) { 2163 for (int i = primFields; i < fields.length; i++) { 2164 Object objectValue = null; 2165 try { 2166 objectValue = inputObjectField(fields[i]); 2167 } catch(IndirectionException cdrie) { 2168 objectValue = activeRecursionMgr.getObject(cdrie.offset); 2172 } 2173 2174 fieldToValueMap.put(fields[i].getName(), objectValue); 2175 } 2176 } 2177 } 2178 2179 2189 private void inputClassFields(Object o, Class cl, 2190 ObjectStreamField[] fields, 2191 com.sun.org.omg.SendingContext.CodeBase sender) 2192 throws InvalidClassException , StreamCorruptedException , 2193 ClassNotFoundException , IOException 2194 { 2195 2196 int primFields = fields.length - currentClassDesc.objFields; 2197 2198 if (o != null) { 2199 for (int i = 0; i < primFields; ++i) { 2200 if (fields[i].getField() == null) 2201 continue; 2202 2203 inputPrimitiveField(o, cl, fields[i]); 2204 } 2205 } 2206 2207 2208 if (currentClassDesc.objFields > 0) { 2209 for (int i = primFields; i < fields.length; i++) { 2210 Object objectValue = null; 2211 2212 try { 2213 objectValue = inputObjectField(fields[i]); 2214 } catch(IndirectionException cdrie) { 2215 objectValue = activeRecursionMgr.getObject(cdrie.offset); 2219 } 2220 2221 if ((o == null) || (fields[i].getField() == null)) { 2222 continue; 2223 } 2224 2225 try { 2226 bridge.putObject( o, fields[i].getFieldID(), objectValue ) ; 2227 } catch (IllegalArgumentException e) { 2229 ClassCastException exc = new ClassCastException ("Assigning instance of class " + 2230 objectValue.getClass().getName() + 2231 " to field " + 2232 currentClassDesc.getName() + 2233 '#' + 2234 fields[i].getField().getName()); 2235 exc.initCause( e ) ; 2236 throw exc ; 2237 } 2238 } } 2240 } 2241 2242 2249 private void inputClassFields(Object o, Class cl, 2250 ObjectStreamClass osc, 2251 ValueMember [] fields, 2252 com.sun.org.omg.SendingContext.CodeBase sender) 2253 throws InvalidClassException , StreamCorruptedException , 2254 ClassNotFoundException , IOException 2255 { 2256 try{ 2257 for (int i = 0; i < fields.length; ++i) { 2258 try { 2259 switch (fields[i].type.kind().value()) { 2260 case TCKind._tk_octet: 2261 byte byteValue = orbStream.read_octet(); 2262 if ((o != null) && osc.hasField(fields[i])) 2263 setByteField(o, cl, fields[i].name, byteValue); 2264 break; 2265 case TCKind._tk_boolean: 2266 boolean booleanValue = orbStream.read_boolean(); 2267 if ((o != null) && osc.hasField(fields[i])) 2268 setBooleanField(o, cl, fields[i].name, booleanValue); 2269 break; 2270 case TCKind._tk_char: 2271 case TCKind._tk_wchar: 2277 char charValue = orbStream.read_wchar(); 2278 if ((o != null) && osc.hasField(fields[i])) 2279 setCharField(o, cl, fields[i].name, charValue); 2280 break; 2281 case TCKind._tk_short: 2282 short shortValue = orbStream.read_short(); 2283 if ((o != null) && osc.hasField(fields[i])) 2284 setShortField(o, cl, fields[i].name, shortValue); 2285 break; 2286 case TCKind._tk_long: 2287 int intValue = orbStream.read_long(); 2288 if ((o != null) && osc.hasField(fields[i])) 2289 setIntField(o, cl, fields[i].name, intValue); 2290 break; 2291 case TCKind._tk_longlong: 2292 long longValue = orbStream.read_longlong(); 2293 if ((o != null) && osc.hasField(fields[i])) 2294 setLongField(o, cl, fields[i].name, longValue); 2295 break; 2296 case TCKind._tk_float: 2297 float floatValue = orbStream.read_float(); 2298 if ((o != null) && osc.hasField(fields[i])) 2299 setFloatField(o, cl, fields[i].name, floatValue); 2300 break; 2301 case TCKind._tk_double: 2302 double doubleValue = orbStream.read_double(); 2303 if ((o != null) && osc.hasField(fields[i])) 2304 setDoubleField(o, cl, fields[i].name, doubleValue); 2305 break; 2306 case TCKind._tk_value: 2307 case TCKind._tk_objref: 2308 case TCKind._tk_value_box: 2309 Object objectValue = null; 2310 try { 2311 objectValue = inputObjectField(fields[i], sender); 2312 } catch (IndirectionException cdrie) { 2313 objectValue = activeRecursionMgr.getObject(cdrie.offset); 2317 } 2318 2319 if (o == null) 2320 continue; 2321 try { 2322 if (osc.hasField(fields[i])){ 2323 setObjectField(o, 2324 cl, 2325 fields[i].name, 2326 objectValue); 2327 } else { 2328 2338 } 2339 } catch (IllegalArgumentException e) { 2340 ClassCastException cce = new ClassCastException ("Assigning instance of class " + 2342 objectValue.getClass().getName() + " to field " + fields[i].name); 2343 cce.initCause(e) ; 2344 throw cce ; 2345 } 2346 break; 2347 default: 2348 throw new StreamCorruptedException ("Unknown kind: " 2350 + fields[i].type.kind().value()); 2351 } 2352 } catch (IllegalArgumentException e) { 2353 2356 ClassCastException cce = new ClassCastException ("Assigning instance of class " + fields[i].id + 2358 " to field " + currentClassDesc.getName() + '#' + fields[i].name); 2359 cce.initCause( e ) ; 2360 throw cce ; 2361 } 2362 } 2363 } catch(Throwable t){ 2364 StreamCorruptedException sce = new StreamCorruptedException (t.getMessage()); 2366 sce.initCause(t) ; 2367 throw sce ; 2368 } 2369 } 2370 2371 private void skipCustomUsingFVD(ValueMember [] fields, 2372 com.sun.org.omg.SendingContext.CodeBase sender) 2373 throws InvalidClassException , StreamCorruptedException , 2374 ClassNotFoundException , IOException 2375 { 2376 readFormatVersion(); 2377 boolean calledDefaultWriteObject = readBoolean(); 2378 2379 if (calledDefaultWriteObject) 2380 throwAwayData(fields, sender); 2381 2382 if (getStreamFormatVersion() == 2) { 2383 2384 ((ValueInputStream )getOrbStream()).start_value(); 2385 ((ValueInputStream )getOrbStream()).end_value(); 2386 } 2387 } 2388 2389 2393 private void throwAwayData(ValueMember [] fields, 2394 com.sun.org.omg.SendingContext.CodeBase sender) 2395 throws InvalidClassException , StreamCorruptedException , 2396 ClassNotFoundException , IOException 2397 { 2398 for (int i = 0; i < fields.length; ++i) { 2399 2400 try { 2401 2402 switch (fields[i].type.kind().value()) { 2403 case TCKind._tk_octet: 2404 orbStream.read_octet(); 2405 break; 2406 case TCKind._tk_boolean: 2407 orbStream.read_boolean(); 2408 break; 2409 case TCKind._tk_char: 2410 case TCKind._tk_wchar: 2416 orbStream.read_wchar(); 2417 break; 2418 case TCKind._tk_short: 2419 orbStream.read_short(); 2420 break; 2421 case TCKind._tk_long: 2422 orbStream.read_long(); 2423 break; 2424 case TCKind._tk_longlong: 2425 orbStream.read_longlong(); 2426 break; 2427 case TCKind._tk_float: 2428 orbStream.read_float(); 2429 break; 2430 case TCKind._tk_double: 2431 orbStream.read_double(); 2432 break; 2433 case TCKind._tk_value: 2434 case TCKind._tk_objref: 2435 case TCKind._tk_value_box: 2436 Class type = null; 2437 String id = fields[i].id; 2438 2439 try { 2440 type = vhandler.getClassFromType(id); 2441 } 2442 catch(ClassNotFoundException cnfe){ 2443 type = null; 2445 } 2446 String signature = null; 2447 if (type != null) 2448 signature = ValueUtility.getSignature(fields[i]); 2449 2450 try { 2452 if ((signature != null) && ( signature.equals("Ljava/lang/Object;") || 2453 signature.equals("Ljava/io/Serializable;") || 2454 signature.equals("Ljava/io/Externalizable;")) ) { 2455 javax.rmi.CORBA.Util.readAny(orbStream); 2456 } 2457 else { 2458 2464 int callType = ValueHandlerImpl.kValueType; 2465 2466 if (!vhandler.isSequence(id)) { 2467 FullValueDescription fieldFVD = sender.meta(fields[i].id); 2468 if (kRemoteTypeCode == fields[i].type) { 2469 2470 callType = ValueHandlerImpl.kRemoteType; 2472 } else if (fieldFVD.is_abstract) { 2473 2475 callType = ValueHandlerImpl.kAbstractType; 2476 } 2477 } 2478 2479 2483 switch (callType) { 2484 case ValueHandlerImpl.kRemoteType: 2485 orbStream.read_Object(); 2486 break; 2487 case ValueHandlerImpl.kAbstractType: 2488 orbStream.read_abstract_interface(); 2489 break; 2490 case ValueHandlerImpl.kValueType: 2491 if (type != null) { 2492 orbStream.read_value(type); 2493 } else { 2494 orbStream.read_value(); 2495 } 2496 break; 2497 default: 2498 throw new StreamCorruptedException ("Unknown callType: " 2500 + callType); 2501 } 2502 } 2503 2504 } 2505 catch(IndirectionException cdrie) { 2506 continue; 2508 } 2509 2510 break; 2511 default: 2512 throw new StreamCorruptedException ("Unknown kind: " 2514 + fields[i].type.kind().value()); 2515 2516 } 2517 } catch (IllegalArgumentException e) { 2518 2521 ClassCastException cce = new ClassCastException ("Assigning instance of class " + 2523 fields[i].id + " to field " + currentClassDesc.getName() + 2524 '#' + fields[i].name); 2525 cce.initCause(e) ; 2526 throw cce ; 2527 } 2528 } 2529 2530 } 2531 2532 private static void setObjectField(Object o, Class c, String fieldName, Object v) 2533 { 2534 try { 2535 Field fld = c.getDeclaredField( fieldName ) ; 2536 long key = bridge.objectFieldOffset( fld ) ; 2537 bridge.putObject( o, key, v ) ; 2538 } catch (Exception e) { 2539 throw utilWrapper.errorSetObjectField( e, fieldName, 2540 ObjectUtility.compactObjectToString( o ), 2541 ObjectUtility.compactObjectToString( v )) ; 2542 } 2543 } 2544 2545 private static void setBooleanField(Object o, Class c, String fieldName, boolean v) 2546 { 2547 try { 2548 Field fld = c.getDeclaredField( fieldName ) ; 2549 long key = bridge.objectFieldOffset( fld ) ; 2550 bridge.putBoolean( o, key, v ) ; 2551 } catch (Exception e) { 2552 throw utilWrapper.errorSetBooleanField( e, fieldName, 2553 ObjectUtility.compactObjectToString( o ), 2554 new Boolean (v) ) ; 2555 } 2556 } 2557 2558 private static void setByteField(Object o, Class c, String fieldName, byte v) 2559 { 2560 try { 2561 Field fld = c.getDeclaredField( fieldName ) ; 2562 long key = bridge.objectFieldOffset( fld ) ; 2563 bridge.putByte( o, key, v ) ; 2564 } catch (Exception e) { 2565 throw utilWrapper.errorSetByteField( e, fieldName, 2566 ObjectUtility.compactObjectToString( o ), 2567 new Byte (v) ) ; 2568 } 2569 } 2570 2571 private static void setCharField(Object o, Class c, String fieldName, char v) 2572 { 2573 try { 2574 Field fld = c.getDeclaredField( fieldName ) ; 2575 long key = bridge.objectFieldOffset( fld ) ; 2576 bridge.putChar( o, key, v ) ; 2577 } catch (Exception e) { 2578 throw utilWrapper.errorSetCharField( e, fieldName, 2579 ObjectUtility.compactObjectToString( o ), 2580 new Character (v) ) ; 2581 } 2582 } 2583 2584 private static void setShortField(Object o, Class c, String fieldName, short v) 2585 { 2586 try { 2587 Field fld = c.getDeclaredField( fieldName ) ; 2588 long key = bridge.objectFieldOffset( fld ) ; 2589 bridge.putShort( o, key, v ) ; 2590 } catch (Exception e) { 2591 throw utilWrapper.errorSetShortField( e, fieldName, 2592 ObjectUtility.compactObjectToString( o ), 2593 new Short (v) ) ; 2594 } 2595 } 2596 2597 private static void setIntField(Object o, Class c, String fieldName, int v) 2598 { 2599 try { 2600 Field fld = c.getDeclaredField( fieldName ) ; 2601 long key = bridge.objectFieldOffset( fld ) ; 2602 bridge.putInt( o, key, v ) ; 2603 } catch (Exception e) { 2604 throw utilWrapper.errorSetIntField( e, fieldName, 2605 ObjectUtility.compactObjectToString( o ), 2606 new Integer (v) ) ; 2607 } 2608 } 2609 2610 private static void setLongField(Object o, Class c, String fieldName, long v) 2611 { 2612 try { 2613 Field fld = c.getDeclaredField( fieldName ) ; 2614 long key = bridge.objectFieldOffset( fld ) ; 2615 bridge.putLong( o, key, v ) ; 2616 } catch (Exception e) { 2617 throw utilWrapper.errorSetLongField( e, fieldName, 2618 ObjectUtility.compactObjectToString( o ), 2619 new Long (v) ) ; 2620 } 2621 } 2622 2623 private static void setFloatField(Object o, Class c, String fieldName, float v) 2624 { 2625 try { 2626 Field fld = c.getDeclaredField( fieldName ) ; 2627 long key = bridge.objectFieldOffset( fld ) ; 2628 bridge.putFloat( o, key, v ) ; 2629 } catch (Exception e) { 2630 throw utilWrapper.errorSetFloatField( e, fieldName, 2631 ObjectUtility.compactObjectToString( o ), 2632 new Float (v) ) ; 2633 } 2634 } 2635 2636 private static void setDoubleField(Object o, Class c, String fieldName, double v) 2637 { 2638 try { 2639 Field fld = c.getDeclaredField( fieldName ) ; 2640 long key = bridge.objectFieldOffset( fld ) ; 2641 bridge.putDouble( o, key, v ) ; 2642 } catch (Exception e) { 2643 throw utilWrapper.errorSetDoubleField( e, fieldName, 2644 ObjectUtility.compactObjectToString( o ), 2645 new Double (v) ) ; 2646 } 2647 } 2648 2649 2657 static class ActiveRecursionManager 2658 { 2659 private Map offsetToObjectMap; 2660 2661 public ActiveRecursionManager() { 2662 offsetToObjectMap = new HashMap(); 2665 } 2666 2667 public void addObject(int offset, Object value) { 2671 offsetToObjectMap.put(new Integer (offset), value); 2672 } 2673 2674 public Object getObject(int offset) throws IOException { 2680 Integer position = new Integer (offset); 2681 2682 if (!offsetToObjectMap.containsKey(position)) 2683 throw new IOException ("Invalid indirection to offset " 2685 + offset); 2686 2687 return offsetToObjectMap.get(position); 2688 } 2689 2690 public void removeObject(int offset) { 2695 offsetToObjectMap.remove(new Integer (offset)); 2696 } 2697 2698 public boolean containsObject(int offset) { 2702 return offsetToObjectMap.containsKey(new Integer (offset)); 2703 } 2704 } 2705} 2706 | Popular Tags |