1 7 15 16 package com.sun.corba.se.impl.ior; 17 18 import java.io.ObjectInputStream ; 19 import java.io.ObjectOutputStream ; 20 import java.io.IOException ; 21 import java.io.StringWriter ; 22 23 import org.omg.CORBA.ORB ; 24 25 import org.omg.CORBA.portable.Delegate ; 26 import org.omg.CORBA.portable.InputStream ; 27 import org.omg.CORBA.portable.OutputStream ; 28 29 import com.sun.corba.se.spi.presentation.rmi.StubAdapter ; 33 import com.sun.corba.se.impl.orbutil.HexOutputStream ; 34 35 40 public class StubIORImpl 41 { 42 private int hashCode; 44 45 private byte[] typeData; 47 private int[] profileTags; 48 private byte[][] profileData; 49 50 public StubIORImpl() 51 { 52 hashCode = 0 ; 53 typeData = null ; 54 profileTags = null ; 55 profileData = null ; 56 } 57 58 public String getRepositoryId() 59 { 60 if (typeData == null) 61 return null ; 62 63 return new String ( typeData ) ; 64 } 65 66 public StubIORImpl( org.omg.CORBA.Object obj ) 67 { 68 OutputStream ostr = StubAdapter.getORB( obj ).create_output_stream(); 70 ostr.write_Object(obj); 71 InputStream istr = ostr.create_input_stream(); 72 73 int typeLength = istr.read_long(); 75 typeData = new byte[typeLength]; 76 istr.read_octet_array(typeData, 0, typeLength); 77 int numProfiles = istr.read_long(); 78 profileTags = new int[numProfiles]; 79 profileData = new byte[numProfiles][]; 80 for (int i = 0; i < numProfiles; i++) { 81 profileTags[i] = istr.read_long(); 82 profileData[i] = new byte[istr.read_long()]; 83 istr.read_octet_array(profileData[i], 0, profileData[i].length); 84 } 85 } 86 87 public Delegate getDelegate( ORB orb ) 88 { 89 OutputStream ostr = orb.create_output_stream(); 91 ostr.write_long(typeData.length); 92 ostr.write_octet_array(typeData, 0, typeData.length); 93 ostr.write_long(profileTags.length); 94 for (int i = 0; i < profileTags.length; i++) { 95 ostr.write_long(profileTags[i]); 96 ostr.write_long(profileData[i].length); 97 ostr.write_octet_array(profileData[i], 0, profileData[i].length); 98 } 99 100 InputStream istr = ostr.create_input_stream() ; 101 102 org.omg.CORBA.Object obj = (org.omg.CORBA.Object )istr.read_Object(); 104 return StubAdapter.getDelegate( obj ) ; 105 } 106 107 public void doRead( java.io.ObjectInputStream stream ) 108 throws IOException , ClassNotFoundException 109 { 110 int typeLength = stream.readInt(); 112 typeData = new byte[typeLength]; 113 stream.readFully(typeData); 114 int numProfiles = stream.readInt(); 115 profileTags = new int[numProfiles]; 116 profileData = new byte[numProfiles][]; 117 for (int i = 0; i < numProfiles; i++) { 118 profileTags[i] = stream.readInt(); 119 profileData[i] = new byte[stream.readInt()]; 120 stream.readFully(profileData[i]); 121 } 122 } 123 124 public void doWrite( ObjectOutputStream stream ) 125 throws IOException 126 { 127 stream.writeInt(typeData.length); 129 stream.write(typeData); 130 stream.writeInt(profileTags.length); 131 for (int i = 0; i < profileTags.length; i++) { 132 stream.writeInt(profileTags[i]); 133 stream.writeInt(profileData[i].length); 134 stream.write(profileData[i]); 135 } 136 } 137 138 143 public synchronized int hashCode() 144 { 145 if (hashCode == 0) { 146 147 for (int i = 0; i < typeData.length; i++) { 149 hashCode = hashCode * 37 + typeData[i]; 150 } 151 152 for (int i = 0; i < profileTags.length; i++) { 153 hashCode = hashCode * 37 + profileTags[i]; 154 for (int j = 0; j < profileData[i].length; j++) { 155 hashCode = hashCode * 37 + profileData[i][j]; 156 } 157 } 158 } 159 160 return hashCode; 161 } 162 163 private boolean equalArrays( int[] data1, int[] data2 ) 164 { 165 if (data1.length != data2.length) 166 return false ; 167 168 for (int ctr=0; ctr<data1.length; ctr++) { 169 if (data1[ctr] != data2[ctr]) 170 return false ; 171 } 172 173 return true ; 174 } 175 176 private boolean equalArrays( byte[] data1, byte[] data2 ) 177 { 178 if (data1.length != data2.length) 179 return false ; 180 181 for (int ctr=0; ctr<data1.length; ctr++) { 182 if (data1[ctr] != data2[ctr]) 183 return false ; 184 } 185 186 return true ; 187 } 188 189 private boolean equalArrays( byte[][] data1, byte[][] data2 ) 190 { 191 if (data1.length != data2.length) 192 return false ; 193 194 for (int ctr=0; ctr<data1.length; ctr++) { 195 if (!equalArrays( data1[ctr], data2[ctr] )) 196 return false ; 197 } 198 199 return true ; 200 } 201 202 public boolean equals(java.lang.Object obj) 203 { 204 if (this == obj) { 205 return true; 206 } 207 208 if (!(obj instanceof StubIORImpl)) { 209 return false; 210 } 211 212 StubIORImpl other = (StubIORImpl) obj; 213 if (other.hashCode() != this.hashCode()) { 214 return false; 215 } 216 217 return equalArrays( typeData, other.typeData ) && 218 equalArrays( profileTags, other.profileTags ) && 219 equalArrays( profileData, other.profileData ) ; 220 } 221 222 private void appendByteArray( StringBuffer result, byte[] data ) 223 { 224 for ( int ctr=0; ctr<data.length; ctr++ ) { 225 result.append( Integer.toHexString( data[ctr] ) ) ; 226 } 227 } 228 229 235 public String toString() 236 { 237 StringBuffer result = new StringBuffer () ; 238 result.append( "SimpleIORImpl[" ) ; 239 String repositoryId = new String ( typeData ) ; 240 result.append( repositoryId ) ; 241 for (int ctr=0; ctr<profileTags.length; ctr++) { 242 result.append( ",(" ) ; 243 result.append( profileTags[ctr] ) ; 244 result.append( ")" ) ; 245 appendByteArray( result, profileData[ctr] ) ; 246 } 247 248 result.append( "]" ) ; 249 return result.toString() ; 250 } 251 } 252 | Popular Tags |