Tue, 27 Feb 2018 19:59:46 -0800
8198494: 8u171 and 8u172 - Build failure on non-SE Linux Platforms
Reviewed-by: dfuchs, rriggs, coffeys, aefimov
duke@1 | 1 | /* |
rpatil@1692 | 2 | * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. |
duke@1 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 4 | * |
duke@1 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@1 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@158 | 7 | * published by the Free Software Foundation. Oracle designates this |
duke@1 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@158 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
duke@1 | 10 | * |
duke@1 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 15 | * accompanied this code). |
duke@1 | 16 | * |
duke@1 | 17 | * You should have received a copy of the GNU General Public License version |
duke@1 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 20 | * |
ohair@158 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@158 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@158 | 23 | * questions. |
duke@1 | 24 | */ |
duke@1 | 25 | /* |
duke@1 | 26 | * Licensed Materials - Property of IBM |
duke@1 | 27 | * RMI-IIOP v1.0 |
duke@1 | 28 | * Copyright IBM Corp. 1998 1999 All Rights Reserved |
duke@1 | 29 | * |
duke@1 | 30 | */ |
duke@1 | 31 | |
duke@1 | 32 | package com.sun.corba.se.impl.ior; |
duke@1 | 33 | |
rpatil@1699 | 34 | import java.io.IOException; |
rpatil@1699 | 35 | import java.io.ObjectOutputStream; |
rpatil@1699 | 36 | import sun.corba.SharedSecrets; |
duke@1 | 37 | |
duke@1 | 38 | import org.omg.CORBA.ORB ; |
duke@1 | 39 | |
duke@1 | 40 | import org.omg.CORBA.portable.Delegate ; |
duke@1 | 41 | import org.omg.CORBA.portable.InputStream ; |
duke@1 | 42 | import org.omg.CORBA.portable.OutputStream ; |
duke@1 | 43 | |
duke@1 | 44 | // Be very careful: com.sun.corba imports must not depend on |
duke@1 | 45 | // PEORB internal classes in ways that prevent portability to |
duke@1 | 46 | // other vendor's ORBs. |
duke@1 | 47 | import com.sun.corba.se.spi.presentation.rmi.StubAdapter ; |
duke@1 | 48 | import com.sun.corba.se.impl.orbutil.HexOutputStream ; |
duke@1 | 49 | |
duke@1 | 50 | /** |
duke@1 | 51 | * This class implements a very simply IOR representation |
duke@1 | 52 | * which must be completely ORBImpl free so that this class |
duke@1 | 53 | * can be used in the implementation of a portable StubDelegateImpl. |
duke@1 | 54 | */ |
duke@1 | 55 | public class StubIORImpl |
duke@1 | 56 | { |
duke@1 | 57 | // cached hash code |
duke@1 | 58 | private int hashCode; |
duke@1 | 59 | |
duke@1 | 60 | // IOR components |
duke@1 | 61 | private byte[] typeData; |
duke@1 | 62 | private int[] profileTags; |
duke@1 | 63 | private byte[][] profileData; |
duke@1 | 64 | |
duke@1 | 65 | public StubIORImpl() |
duke@1 | 66 | { |
duke@1 | 67 | hashCode = 0 ; |
duke@1 | 68 | typeData = null ; |
duke@1 | 69 | profileTags = null ; |
duke@1 | 70 | profileData = null ; |
duke@1 | 71 | } |
duke@1 | 72 | |
duke@1 | 73 | public String getRepositoryId() |
duke@1 | 74 | { |
duke@1 | 75 | if (typeData == null) |
duke@1 | 76 | return null ; |
duke@1 | 77 | |
duke@1 | 78 | return new String( typeData ) ; |
duke@1 | 79 | } |
duke@1 | 80 | |
duke@1 | 81 | public StubIORImpl( org.omg.CORBA.Object obj ) |
duke@1 | 82 | { |
duke@1 | 83 | // write the IOR to an OutputStream and get an InputStream |
duke@1 | 84 | OutputStream ostr = StubAdapter.getORB( obj ).create_output_stream(); |
duke@1 | 85 | ostr.write_Object(obj); |
duke@1 | 86 | InputStream istr = ostr.create_input_stream(); |
duke@1 | 87 | |
duke@1 | 88 | // read the IOR components back from the stream |
duke@1 | 89 | int typeLength = istr.read_long(); |
duke@1 | 90 | typeData = new byte[typeLength]; |
duke@1 | 91 | istr.read_octet_array(typeData, 0, typeLength); |
duke@1 | 92 | int numProfiles = istr.read_long(); |
duke@1 | 93 | profileTags = new int[numProfiles]; |
duke@1 | 94 | profileData = new byte[numProfiles][]; |
duke@1 | 95 | for (int i = 0; i < numProfiles; i++) { |
duke@1 | 96 | profileTags[i] = istr.read_long(); |
duke@1 | 97 | profileData[i] = new byte[istr.read_long()]; |
duke@1 | 98 | istr.read_octet_array(profileData[i], 0, profileData[i].length); |
duke@1 | 99 | } |
duke@1 | 100 | } |
duke@1 | 101 | |
duke@1 | 102 | public Delegate getDelegate( ORB orb ) |
duke@1 | 103 | { |
duke@1 | 104 | // write the IOR components to an org.omg.CORBA.portable.OutputStream |
duke@1 | 105 | OutputStream ostr = orb.create_output_stream(); |
duke@1 | 106 | ostr.write_long(typeData.length); |
duke@1 | 107 | ostr.write_octet_array(typeData, 0, typeData.length); |
duke@1 | 108 | ostr.write_long(profileTags.length); |
duke@1 | 109 | for (int i = 0; i < profileTags.length; i++) { |
duke@1 | 110 | ostr.write_long(profileTags[i]); |
duke@1 | 111 | ostr.write_long(profileData[i].length); |
duke@1 | 112 | ostr.write_octet_array(profileData[i], 0, profileData[i].length); |
duke@1 | 113 | } |
duke@1 | 114 | |
duke@1 | 115 | InputStream istr = ostr.create_input_stream() ; |
duke@1 | 116 | |
duke@1 | 117 | // read the IOR back from the stream |
duke@1 | 118 | org.omg.CORBA.Object obj = (org.omg.CORBA.Object)istr.read_Object(); |
duke@1 | 119 | return StubAdapter.getDelegate( obj ) ; |
duke@1 | 120 | } |
duke@1 | 121 | |
duke@1 | 122 | public void doRead( java.io.ObjectInputStream stream ) |
duke@1 | 123 | throws IOException, ClassNotFoundException |
duke@1 | 124 | { |
duke@1 | 125 | // read the IOR from the ObjectInputStream |
duke@1 | 126 | int typeLength = stream.readInt(); |
rpatil@1692 | 127 | SharedSecrets.getJavaOISAccess().checkArray(stream, byte[].class, typeLength); |
duke@1 | 128 | typeData = new byte[typeLength]; |
duke@1 | 129 | stream.readFully(typeData); |
rpatil@1692 | 130 | |
duke@1 | 131 | int numProfiles = stream.readInt(); |
rpatil@1692 | 132 | SharedSecrets.getJavaOISAccess().checkArray(stream, int[].class, numProfiles); |
rpatil@1692 | 133 | SharedSecrets.getJavaOISAccess().checkArray(stream, byte[].class, numProfiles); |
duke@1 | 134 | profileTags = new int[numProfiles]; |
duke@1 | 135 | profileData = new byte[numProfiles][]; |
duke@1 | 136 | for (int i = 0; i < numProfiles; i++) { |
duke@1 | 137 | profileTags[i] = stream.readInt(); |
rpatil@1692 | 138 | int dataSize = stream.readInt(); |
rpatil@1692 | 139 | SharedSecrets.getJavaOISAccess().checkArray(stream, byte[].class, dataSize); |
rpatil@1692 | 140 | profileData[i] = new byte[dataSize]; |
duke@1 | 141 | stream.readFully(profileData[i]); |
duke@1 | 142 | } |
duke@1 | 143 | } |
duke@1 | 144 | |
duke@1 | 145 | public void doWrite( ObjectOutputStream stream ) |
duke@1 | 146 | throws IOException |
duke@1 | 147 | { |
duke@1 | 148 | // write the IOR to the ObjectOutputStream |
duke@1 | 149 | stream.writeInt(typeData.length); |
duke@1 | 150 | stream.write(typeData); |
duke@1 | 151 | stream.writeInt(profileTags.length); |
duke@1 | 152 | for (int i = 0; i < profileTags.length; i++) { |
duke@1 | 153 | stream.writeInt(profileTags[i]); |
duke@1 | 154 | stream.writeInt(profileData[i].length); |
duke@1 | 155 | stream.write(profileData[i]); |
duke@1 | 156 | } |
duke@1 | 157 | } |
duke@1 | 158 | |
duke@1 | 159 | /** |
duke@1 | 160 | * Returns a hash code value for the object which is the same for all stubs |
duke@1 | 161 | * that represent the same remote object. |
duke@1 | 162 | * @return the hash code value. |
duke@1 | 163 | */ |
duke@1 | 164 | public synchronized int hashCode() |
duke@1 | 165 | { |
duke@1 | 166 | if (hashCode == 0) { |
duke@1 | 167 | |
duke@1 | 168 | // compute the hash code |
duke@1 | 169 | for (int i = 0; i < typeData.length; i++) { |
duke@1 | 170 | hashCode = hashCode * 37 + typeData[i]; |
duke@1 | 171 | } |
duke@1 | 172 | |
duke@1 | 173 | for (int i = 0; i < profileTags.length; i++) { |
duke@1 | 174 | hashCode = hashCode * 37 + profileTags[i]; |
duke@1 | 175 | for (int j = 0; j < profileData[i].length; j++) { |
duke@1 | 176 | hashCode = hashCode * 37 + profileData[i][j]; |
duke@1 | 177 | } |
duke@1 | 178 | } |
duke@1 | 179 | } |
duke@1 | 180 | |
duke@1 | 181 | return hashCode; |
duke@1 | 182 | } |
duke@1 | 183 | |
duke@1 | 184 | private boolean equalArrays( int[] data1, int[] data2 ) |
duke@1 | 185 | { |
duke@1 | 186 | if (data1.length != data2.length) |
duke@1 | 187 | return false ; |
duke@1 | 188 | |
duke@1 | 189 | for (int ctr=0; ctr<data1.length; ctr++) { |
duke@1 | 190 | if (data1[ctr] != data2[ctr]) |
duke@1 | 191 | return false ; |
duke@1 | 192 | } |
duke@1 | 193 | |
duke@1 | 194 | return true ; |
duke@1 | 195 | } |
duke@1 | 196 | |
duke@1 | 197 | private boolean equalArrays( byte[] data1, byte[] data2 ) |
duke@1 | 198 | { |
duke@1 | 199 | if (data1.length != data2.length) |
duke@1 | 200 | return false ; |
duke@1 | 201 | |
duke@1 | 202 | for (int ctr=0; ctr<data1.length; ctr++) { |
duke@1 | 203 | if (data1[ctr] != data2[ctr]) |
duke@1 | 204 | return false ; |
duke@1 | 205 | } |
duke@1 | 206 | |
duke@1 | 207 | return true ; |
duke@1 | 208 | } |
duke@1 | 209 | |
duke@1 | 210 | private boolean equalArrays( byte[][] data1, byte[][] data2 ) |
duke@1 | 211 | { |
duke@1 | 212 | if (data1.length != data2.length) |
duke@1 | 213 | return false ; |
duke@1 | 214 | |
duke@1 | 215 | for (int ctr=0; ctr<data1.length; ctr++) { |
duke@1 | 216 | if (!equalArrays( data1[ctr], data2[ctr] )) |
duke@1 | 217 | return false ; |
duke@1 | 218 | } |
duke@1 | 219 | |
duke@1 | 220 | return true ; |
duke@1 | 221 | } |
duke@1 | 222 | |
duke@1 | 223 | public boolean equals(java.lang.Object obj) |
duke@1 | 224 | { |
duke@1 | 225 | if (this == obj) { |
duke@1 | 226 | return true; |
duke@1 | 227 | } |
duke@1 | 228 | |
duke@1 | 229 | if (!(obj instanceof StubIORImpl)) { |
duke@1 | 230 | return false; |
duke@1 | 231 | } |
duke@1 | 232 | |
duke@1 | 233 | StubIORImpl other = (StubIORImpl) obj; |
duke@1 | 234 | if (other.hashCode() != this.hashCode()) { |
duke@1 | 235 | return false; |
duke@1 | 236 | } |
duke@1 | 237 | |
duke@1 | 238 | return equalArrays( typeData, other.typeData ) && |
duke@1 | 239 | equalArrays( profileTags, other.profileTags ) && |
duke@1 | 240 | equalArrays( profileData, other.profileData ) ; |
duke@1 | 241 | } |
duke@1 | 242 | |
duke@1 | 243 | private void appendByteArray( StringBuffer result, byte[] data ) |
duke@1 | 244 | { |
duke@1 | 245 | for ( int ctr=0; ctr<data.length; ctr++ ) { |
duke@1 | 246 | result.append( Integer.toHexString( data[ctr] ) ) ; |
duke@1 | 247 | } |
duke@1 | 248 | } |
duke@1 | 249 | |
duke@1 | 250 | /** |
duke@1 | 251 | * Returns a string representation of this stub. Returns the same string |
duke@1 | 252 | * for all stubs that represent the same remote object. |
duke@1 | 253 | * "SimpleIORImpl[<typeName>,[<profileID>]data, ...]" |
duke@1 | 254 | * @return a string representation of this stub. |
duke@1 | 255 | */ |
duke@1 | 256 | public String toString() |
duke@1 | 257 | { |
duke@1 | 258 | StringBuffer result = new StringBuffer() ; |
duke@1 | 259 | result.append( "SimpleIORImpl[" ) ; |
duke@1 | 260 | String repositoryId = new String( typeData ) ; |
duke@1 | 261 | result.append( repositoryId ) ; |
duke@1 | 262 | for (int ctr=0; ctr<profileTags.length; ctr++) { |
duke@1 | 263 | result.append( ",(" ) ; |
duke@1 | 264 | result.append( profileTags[ctr] ) ; |
duke@1 | 265 | result.append( ")" ) ; |
duke@1 | 266 | appendByteArray( result, profileData[ctr] ) ; |
duke@1 | 267 | } |
duke@1 | 268 | |
duke@1 | 269 | result.append( "]" ) ; |
duke@1 | 270 | return result.toString() ; |
duke@1 | 271 | } |
duke@1 | 272 | } |