Fri, 24 Sep 2010 22:42:14 -0700
6891766: Vulnerabilities in use of reflection in CORBA
Reviewed-by: hawtin
duke@1 | 1 | /* |
ohair@158 | 2 | * Copyright (c) 2000, 2002, 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.orbutil; |
duke@1 | 33 | |
duke@1 | 34 | import java.util.StringTokenizer; |
duke@1 | 35 | import java.util.Hashtable; |
duke@1 | 36 | import java.io.IOException; |
duke@1 | 37 | import java.lang.reflect.Method; |
duke@1 | 38 | |
duke@1 | 39 | // Imports for using codebase URL to load class |
duke@1 | 40 | import java.net.MalformedURLException; |
duke@1 | 41 | import org.omg.CORBA.portable.ValueBase; |
duke@1 | 42 | import org.omg.CORBA.portable.IDLEntity; |
duke@1 | 43 | |
duke@1 | 44 | import com.sun.corba.se.impl.util.JDKBridge; |
duke@1 | 45 | import com.sun.corba.se.impl.util.Utility; |
duke@1 | 46 | import com.sun.corba.se.impl.util.PackagePrefixChecker; |
duke@1 | 47 | import com.sun.corba.se.impl.util.IdentityHashtable; |
duke@1 | 48 | import com.sun.corba.se.impl.io.ObjectStreamClass; |
duke@1 | 49 | |
duke@1 | 50 | import javax.rmi.CORBA.Util; |
duke@1 | 51 | |
duke@1 | 52 | // keeping the original RepositoryId class that was shipped in |
duke@1 | 53 | // JDK 1.3. It has interoperability bugs |
duke@1 | 54 | |
duke@1 | 55 | public class RepositoryId_1_3 { |
duke@1 | 56 | |
duke@1 | 57 | // Legal IDL Identifier characters (1 = legal). Note |
duke@1 | 58 | // that '.' (2E) is marked as legal even though it is |
duke@1 | 59 | // not legal in IDL. This allows us to treat a fully |
duke@1 | 60 | // qualified Java name with '.' package separators |
duke@1 | 61 | // uniformly, and is safe because that is the only |
duke@1 | 62 | // legal use of '.' in a Java name. |
duke@1 | 63 | |
duke@1 | 64 | public static final RepositoryIdCache_1_3 cache = new RepositoryIdCache_1_3(); |
duke@1 | 65 | public static final byte[] IDL_IDENTIFIER_CHARS = { |
duke@1 | 66 | |
duke@1 | 67 | // 0 1 2 3 4 5 6 7 8 9 a b c d e f |
duke@1 | 68 | 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 00-0f |
duke@1 | 69 | 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 10-1f |
duke@1 | 70 | 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,1,0, // 20-2f |
duke@1 | 71 | 1,1,1,1, 1,1,1,1, 1,1,0,0, 0,0,0,0, // 30-3f |
duke@1 | 72 | 0,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, // 40-4f |
duke@1 | 73 | 1,1,1,1, 1,1,1,1, 1,1,1,0, 0,0,0,1, // 50-5f |
duke@1 | 74 | 0,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, // 60-6f |
duke@1 | 75 | 1,1,1,1, 1,1,1,1, 1,1,1,0, 0,0,0,0, // 70-7f |
duke@1 | 76 | 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 80-8f |
duke@1 | 77 | 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // 90-9f |
duke@1 | 78 | 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // a0-af |
duke@1 | 79 | 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, // b0-bf |
duke@1 | 80 | 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, // c0-cf |
duke@1 | 81 | 0,1,1,1, 1,1,1,0, 1,1,1,1, 1,0,0,1, // d0-df |
duke@1 | 82 | 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, // e0-ef |
duke@1 | 83 | 0,1,1,1, 1,1,1,0, 1,1,1,1, 1,0,0,1, // f0-ff |
duke@1 | 84 | }; |
duke@1 | 85 | |
duke@1 | 86 | private static String defaultServerURL = null; |
duke@1 | 87 | private static boolean useCodebaseOnly = false; |
duke@1 | 88 | |
duke@1 | 89 | static { |
duke@1 | 90 | if (defaultServerURL == null) |
duke@1 | 91 | defaultServerURL = (String)JDKBridge.getLocalCodebase(); |
duke@1 | 92 | useCodebaseOnly = JDKBridge.useCodebaseOnly(); |
duke@1 | 93 | |
duke@1 | 94 | } |
duke@1 | 95 | |
duke@1 | 96 | private static IdentityHashtable classToRepStr = new IdentityHashtable(); |
duke@1 | 97 | private static IdentityHashtable classIDLToRepStr = new IdentityHashtable(); |
duke@1 | 98 | private static IdentityHashtable classSeqToRepStr = new IdentityHashtable(); |
duke@1 | 99 | |
duke@1 | 100 | private static IdentityHashtable repStrToByteArray = new IdentityHashtable(); |
duke@1 | 101 | private static Hashtable repStrToClass = new Hashtable(); |
duke@1 | 102 | |
duke@1 | 103 | private String repId = null; |
duke@1 | 104 | private boolean isSupportedFormat = true; |
duke@1 | 105 | private String typeString = null; |
duke@1 | 106 | private String versionString = null; |
duke@1 | 107 | private boolean isSequence = false; |
duke@1 | 108 | private boolean isRMIValueType = false; |
duke@1 | 109 | private boolean isIDLType = false; |
duke@1 | 110 | private String completeClassName = null; |
duke@1 | 111 | private String unqualifiedName = null; |
duke@1 | 112 | private String definedInId = null; |
duke@1 | 113 | private Class clazz = null; |
duke@1 | 114 | private String suid = null, actualSuid = null; |
duke@1 | 115 | private long suidLong = ObjectStreamClass.kDefaultUID, actualSuidLong = ObjectStreamClass.kDefaultUID; |
duke@1 | 116 | |
duke@1 | 117 | // Repository ID fragments |
duke@1 | 118 | private static final String kValuePrefix = "RMI:"; |
duke@1 | 119 | private static final String kIDLPrefix = "IDL:"; |
duke@1 | 120 | private static final String kIDLNamePrefix = "omg.org/"; |
duke@1 | 121 | private static final String kIDLClassnamePrefix = "org.omg."; |
duke@1 | 122 | private static final String kSequencePrefix = "["; |
duke@1 | 123 | private static final String kCORBAPrefix = "CORBA/"; |
duke@1 | 124 | private static final String kArrayPrefix = kValuePrefix + kSequencePrefix + kCORBAPrefix; |
duke@1 | 125 | private static final int kValuePrefixLength = kValuePrefix.length(); |
duke@1 | 126 | private static final int kIDLPrefixLength = kIDLPrefix.length(); |
duke@1 | 127 | private static final int kSequencePrefixLength = kSequencePrefix.length(); |
duke@1 | 128 | private static final String kInterfaceHashCode = ":0000000000000000"; |
duke@1 | 129 | private static final String kInterfaceOnlyHashStr = "0000000000000000"; |
duke@1 | 130 | private static final String kExternalizableHashStr = "0000000000000001"; |
duke@1 | 131 | |
duke@1 | 132 | // Value tag utility methods and constants |
duke@1 | 133 | public static final int kInitialValueTag= 0x7fffff00; |
duke@1 | 134 | public static final int kNoTypeInfo = 0; |
duke@1 | 135 | public static final int kSingleRepTypeInfo = 0x02; |
duke@1 | 136 | public static final int kPartialListTypeInfo = 0x06; |
duke@1 | 137 | public static final int kChunkedMask = 0x08; |
duke@1 | 138 | |
duke@1 | 139 | // Public, well known repository IDs |
duke@1 | 140 | |
duke@1 | 141 | // _REVISIT_ : A table structure with a good search routine for all of this |
duke@1 | 142 | // would be more efficient and easier to maintain... |
duke@1 | 143 | |
duke@1 | 144 | // String |
duke@1 | 145 | public static final String kWStringValueVersion = "1.0"; |
duke@1 | 146 | public static final String kWStringValueHash = ":"+kWStringValueVersion; |
duke@1 | 147 | public static final String kWStringStubValue = "WStringValue"; |
duke@1 | 148 | public static final String kWStringTypeStr = "omg.org/CORBA/"+kWStringStubValue; |
duke@1 | 149 | public static final String kWStringValueRepID = kIDLPrefix + kWStringTypeStr + kWStringValueHash; |
duke@1 | 150 | |
duke@1 | 151 | // Any |
duke@1 | 152 | public static final String kAnyRepID = kIDLPrefix + "omg.org/CORBA/Any"; |
duke@1 | 153 | |
duke@1 | 154 | // Class |
duke@1 | 155 | public static final String kClassDescValueHash = ":" + Long.toHexString( |
duke@1 | 156 | ObjectStreamClass.getSerialVersionUID(javax.rmi.CORBA.ClassDesc.class)); |
duke@1 | 157 | public static final String kClassDescStubValue = "ClassDesc"; |
duke@1 | 158 | public static final String kClassDescTypeStr = "javax.rmi.CORBA."+kClassDescStubValue; |
duke@1 | 159 | public static final String kClassDescValueRepID = kValuePrefix + kClassDescTypeStr + kClassDescValueHash; |
duke@1 | 160 | |
duke@1 | 161 | // Object |
duke@1 | 162 | public static final String kObjectValueHash = ":1.0"; |
duke@1 | 163 | public static final String kObjectStubValue = "Object"; |
duke@1 | 164 | |
duke@1 | 165 | // Sequence |
duke@1 | 166 | public static final String kSequenceValueHash = ":1.0"; |
duke@1 | 167 | public static final String kPrimitiveSequenceValueHash = ":0000000000000000"; |
duke@1 | 168 | |
duke@1 | 169 | // Serializable |
duke@1 | 170 | public static final String kSerializableValueHash = ":1.0"; |
duke@1 | 171 | public static final String kSerializableStubValue = "Serializable"; |
duke@1 | 172 | |
duke@1 | 173 | // Externalizable |
duke@1 | 174 | public static final String kExternalizableValueHash = ":1.0"; |
duke@1 | 175 | public static final String kExternalizableStubValue = "Externalizable"; |
duke@1 | 176 | |
duke@1 | 177 | // Remote (The empty string is used for java.rmi.Remote) |
duke@1 | 178 | public static final String kRemoteValueHash = ""; |
duke@1 | 179 | public static final String kRemoteStubValue = ""; |
duke@1 | 180 | public static final String kRemoteTypeStr = ""; |
duke@1 | 181 | public static final String kRemoteValueRepID = ""; |
duke@1 | 182 | |
duke@1 | 183 | public static final Hashtable kSpecialArrayTypeStrings = new Hashtable(); |
duke@1 | 184 | |
duke@1 | 185 | static { |
duke@1 | 186 | kSpecialArrayTypeStrings.put("CORBA.WStringValue", new StringBuffer(java.lang.String.class.getName())); |
duke@1 | 187 | kSpecialArrayTypeStrings.put("javax.rmi.CORBA.ClassDesc", new StringBuffer(java.lang.Class.class.getName())); |
duke@1 | 188 | kSpecialArrayTypeStrings.put("CORBA.Object", new StringBuffer(java.rmi.Remote.class.getName())); |
duke@1 | 189 | |
duke@1 | 190 | } |
duke@1 | 191 | |
duke@1 | 192 | public static final Hashtable kSpecialCasesRepIDs = new Hashtable(); |
duke@1 | 193 | |
duke@1 | 194 | static { |
duke@1 | 195 | kSpecialCasesRepIDs.put(java.lang.String.class, kWStringValueRepID); |
duke@1 | 196 | kSpecialCasesRepIDs.put(java.lang.Class.class, kClassDescValueRepID); |
duke@1 | 197 | kSpecialCasesRepIDs.put(java.rmi.Remote.class, kRemoteValueRepID); |
duke@1 | 198 | } |
duke@1 | 199 | |
duke@1 | 200 | public static final Hashtable kSpecialCasesStubValues = new Hashtable(); |
duke@1 | 201 | |
duke@1 | 202 | static { |
duke@1 | 203 | kSpecialCasesStubValues.put(java.lang.String.class, kWStringStubValue); |
duke@1 | 204 | kSpecialCasesStubValues.put(java.lang.Class.class, kClassDescStubValue); |
duke@1 | 205 | kSpecialCasesStubValues.put(java.lang.Object.class, kObjectStubValue); |
duke@1 | 206 | kSpecialCasesStubValues.put(java.io.Serializable.class, kSerializableStubValue); |
duke@1 | 207 | kSpecialCasesStubValues.put(java.io.Externalizable.class, kExternalizableStubValue); |
duke@1 | 208 | kSpecialCasesStubValues.put(java.rmi.Remote.class, kRemoteStubValue); |
duke@1 | 209 | } |
duke@1 | 210 | |
duke@1 | 211 | |
duke@1 | 212 | public static final Hashtable kSpecialCasesVersions = new Hashtable(); |
duke@1 | 213 | |
duke@1 | 214 | static { |
duke@1 | 215 | kSpecialCasesVersions.put(java.lang.String.class, kWStringValueHash); |
duke@1 | 216 | kSpecialCasesVersions.put(java.lang.Class.class, kClassDescValueHash); |
duke@1 | 217 | kSpecialCasesVersions.put(java.lang.Object.class, kObjectValueHash); |
duke@1 | 218 | kSpecialCasesVersions.put(java.io.Serializable.class, kSerializableValueHash); |
duke@1 | 219 | kSpecialCasesVersions.put(java.io.Externalizable.class, kExternalizableValueHash); |
duke@1 | 220 | kSpecialCasesVersions.put(java.rmi.Remote.class, kRemoteValueHash); |
duke@1 | 221 | } |
duke@1 | 222 | |
duke@1 | 223 | public static final Hashtable kSpecialCasesClasses = new Hashtable(); |
duke@1 | 224 | |
duke@1 | 225 | static { |
duke@1 | 226 | kSpecialCasesClasses.put(kWStringTypeStr, java.lang.String.class); |
duke@1 | 227 | kSpecialCasesClasses.put(kClassDescTypeStr, java.lang.Class.class); |
duke@1 | 228 | kSpecialCasesClasses.put(kRemoteTypeStr, java.rmi.Remote.class); |
duke@1 | 229 | |
duke@1 | 230 | kSpecialCasesClasses.put("org.omg.CORBA.WStringValue", java.lang.String.class); |
duke@1 | 231 | kSpecialCasesClasses.put("javax.rmi.CORBA.ClassDesc", java.lang.Class.class); |
duke@1 | 232 | //kSpecialCasesClasses.put(kRemoteTypeStr, java.rmi.Remote.class); |
duke@1 | 233 | } |
duke@1 | 234 | |
duke@1 | 235 | public static final Hashtable kSpecialCasesArrayPrefix = new Hashtable(); |
duke@1 | 236 | |
duke@1 | 237 | static { |
duke@1 | 238 | kSpecialCasesArrayPrefix.put(java.lang.String.class, kValuePrefix + kSequencePrefix + kCORBAPrefix); |
duke@1 | 239 | kSpecialCasesArrayPrefix.put(java.lang.Class.class, kValuePrefix + kSequencePrefix + "javax/rmi/CORBA/"); |
duke@1 | 240 | kSpecialCasesArrayPrefix.put(java.lang.Object.class, kValuePrefix + kSequencePrefix + "java/lang/"); |
duke@1 | 241 | kSpecialCasesArrayPrefix.put(java.io.Serializable.class, kValuePrefix + kSequencePrefix + "java/io/"); |
duke@1 | 242 | kSpecialCasesArrayPrefix.put(java.io.Externalizable.class, kValuePrefix + kSequencePrefix + "java/io/"); |
duke@1 | 243 | kSpecialCasesArrayPrefix.put(java.rmi.Remote.class, kValuePrefix + kSequencePrefix + kCORBAPrefix); |
duke@1 | 244 | } |
duke@1 | 245 | |
duke@1 | 246 | public static final Hashtable kSpecialPrimitives = new Hashtable(); |
duke@1 | 247 | |
duke@1 | 248 | static { |
duke@1 | 249 | kSpecialPrimitives.put("int","long"); |
duke@1 | 250 | kSpecialPrimitives.put("long","longlong"); |
duke@1 | 251 | kSpecialPrimitives.put("byte","octet"); |
duke@1 | 252 | } |
duke@1 | 253 | |
duke@1 | 254 | /** |
duke@1 | 255 | * Used to convert ascii to hex. |
duke@1 | 256 | */ |
duke@1 | 257 | private static final byte ASCII_HEX[] = { |
duke@1 | 258 | (byte)'0', |
duke@1 | 259 | (byte)'1', |
duke@1 | 260 | (byte)'2', |
duke@1 | 261 | (byte)'3', |
duke@1 | 262 | (byte)'4', |
duke@1 | 263 | (byte)'5', |
duke@1 | 264 | (byte)'6', |
duke@1 | 265 | (byte)'7', |
duke@1 | 266 | (byte)'8', |
duke@1 | 267 | (byte)'9', |
duke@1 | 268 | (byte)'A', |
duke@1 | 269 | (byte)'B', |
duke@1 | 270 | (byte)'C', |
duke@1 | 271 | (byte)'D', |
duke@1 | 272 | (byte)'E', |
duke@1 | 273 | (byte)'F', |
duke@1 | 274 | }; |
duke@1 | 275 | |
duke@1 | 276 | |
duke@1 | 277 | // Interface Rep ID Strings |
duke@1 | 278 | public static final String kjava_rmi_Remote = createForAnyType(java.rmi.Remote.class); |
duke@1 | 279 | public static final String korg_omg_CORBA_Object = createForAnyType(org.omg.CORBA.Object.class); |
duke@1 | 280 | |
duke@1 | 281 | // Dummy arguments for getIdFromHelper method |
duke@1 | 282 | public static final Class kNoParamTypes[] ={}; |
duke@1 | 283 | public static final Object kNoArgs[] = {}; |
duke@1 | 284 | |
duke@1 | 285 | |
duke@1 | 286 | RepositoryId_1_3(){} |
duke@1 | 287 | |
duke@1 | 288 | RepositoryId_1_3(String aRepId){ |
duke@1 | 289 | init(aRepId); |
duke@1 | 290 | } |
duke@1 | 291 | |
duke@1 | 292 | RepositoryId_1_3 init(String aRepId){ |
duke@1 | 293 | |
duke@1 | 294 | this.repId = aRepId; |
duke@1 | 295 | |
duke@1 | 296 | // Special case for remote |
duke@1 | 297 | if (aRepId.length() == 0) { |
duke@1 | 298 | clazz = java.rmi.Remote.class; |
duke@1 | 299 | typeString = ""; |
duke@1 | 300 | isRMIValueType = true; |
duke@1 | 301 | suid = kInterfaceOnlyHashStr; |
duke@1 | 302 | return this; |
duke@1 | 303 | } |
duke@1 | 304 | else if (aRepId.equals(kWStringValueRepID)) { |
duke@1 | 305 | clazz = java.lang.String.class; |
duke@1 | 306 | typeString = kWStringTypeStr; |
duke@1 | 307 | isIDLType = true; |
duke@1 | 308 | versionString = kWStringValueVersion; |
duke@1 | 309 | return this; |
duke@1 | 310 | } |
duke@1 | 311 | else { |
duke@1 | 312 | |
duke@1 | 313 | String repId = convertFromISOLatin1(aRepId); |
duke@1 | 314 | |
duke@1 | 315 | versionString = repId.substring(repId.indexOf(':', repId.indexOf(':')+1)); |
duke@1 | 316 | if (repId.startsWith(kIDLPrefix)) { |
duke@1 | 317 | typeString = |
duke@1 | 318 | repId.substring(kIDLPrefixLength, repId.indexOf(':', kIDLPrefixLength)); |
duke@1 | 319 | isIDLType = true; |
duke@1 | 320 | if (typeString.startsWith(kIDLNamePrefix)) |
duke@1 | 321 | completeClassName = kIDLClassnamePrefix + |
duke@1 | 322 | typeString.substring(kIDLNamePrefix.length()).replace('/','.'); |
duke@1 | 323 | else completeClassName = typeString.replace('/','.'); |
duke@1 | 324 | |
duke@1 | 325 | } |
duke@1 | 326 | else if (repId.startsWith(kValuePrefix)) { |
duke@1 | 327 | typeString = |
duke@1 | 328 | repId.substring(kValuePrefixLength, repId.indexOf(':', kValuePrefixLength)); |
duke@1 | 329 | isRMIValueType = true; |
duke@1 | 330 | |
duke@1 | 331 | if (versionString.indexOf('.') == -1) { |
duke@1 | 332 | actualSuid = versionString.substring(1); |
duke@1 | 333 | suid = actualSuid; // default if not explicitly specified |
duke@1 | 334 | |
duke@1 | 335 | if (actualSuid.indexOf(':') != -1){ |
duke@1 | 336 | // we have a declared hash also |
duke@1 | 337 | int pos = actualSuid.indexOf(':')+1; |
duke@1 | 338 | // actualSuid = suid.substring(pos); |
duke@1 | 339 | // suid = suid.substring(0, pos-1); |
duke@1 | 340 | suid = actualSuid.substring(pos); |
duke@1 | 341 | actualSuid = actualSuid.substring(0, pos-1); |
duke@1 | 342 | } |
duke@1 | 343 | |
duke@1 | 344 | } |
duke@1 | 345 | else { |
duke@1 | 346 | // _REVISIT_ : Special case version failure ? |
duke@1 | 347 | } |
duke@1 | 348 | } |
duke@1 | 349 | else isSupportedFormat = false; |
duke@1 | 350 | |
duke@1 | 351 | if (typeString.startsWith(kSequencePrefix)) { |
duke@1 | 352 | isSequence = true; |
duke@1 | 353 | } |
duke@1 | 354 | |
duke@1 | 355 | |
duke@1 | 356 | return this; |
duke@1 | 357 | } |
duke@1 | 358 | } |
duke@1 | 359 | |
duke@1 | 360 | public final String getUnqualifiedName() { |
duke@1 | 361 | if (unqualifiedName == null){ |
duke@1 | 362 | String className = getClassName(); |
duke@1 | 363 | int index = (className != null) ? className.lastIndexOf('.') : -1; |
duke@1 | 364 | if (index == -1){ |
duke@1 | 365 | unqualifiedName = className; |
duke@1 | 366 | definedInId = "IDL::1.0"; |
duke@1 | 367 | } |
duke@1 | 368 | else { |
duke@1 | 369 | unqualifiedName = className.substring(index); |
duke@1 | 370 | definedInId = "IDL:" + className.substring(0, index).replace('.','/') + ":1.0"; |
duke@1 | 371 | } |
duke@1 | 372 | } |
duke@1 | 373 | |
duke@1 | 374 | return unqualifiedName; |
duke@1 | 375 | } |
duke@1 | 376 | |
duke@1 | 377 | public final String getDefinedInId() { |
duke@1 | 378 | if (definedInId == null){ |
duke@1 | 379 | getUnqualifiedName(); |
duke@1 | 380 | } |
duke@1 | 381 | |
duke@1 | 382 | return definedInId; |
duke@1 | 383 | } |
duke@1 | 384 | |
duke@1 | 385 | public final String getTypeString() { |
duke@1 | 386 | return typeString; |
duke@1 | 387 | } |
duke@1 | 388 | |
duke@1 | 389 | public final String getVersionString() { |
duke@1 | 390 | return versionString; |
duke@1 | 391 | } |
duke@1 | 392 | |
duke@1 | 393 | public final String getSerialVersionUID() { |
duke@1 | 394 | return suid; |
duke@1 | 395 | } |
duke@1 | 396 | |
duke@1 | 397 | public final String getActualSerialVersionUID() { |
duke@1 | 398 | return actualSuid; |
duke@1 | 399 | } |
duke@1 | 400 | public final long getSerialVersionUIDAsLong() { |
duke@1 | 401 | return suidLong; |
duke@1 | 402 | } |
duke@1 | 403 | |
duke@1 | 404 | public final long getActualSerialVersionUIDAsLong() { |
duke@1 | 405 | return actualSuidLong; |
duke@1 | 406 | } |
duke@1 | 407 | |
duke@1 | 408 | public final boolean isRMIValueType() { |
duke@1 | 409 | return isRMIValueType; |
duke@1 | 410 | } |
duke@1 | 411 | |
duke@1 | 412 | public final boolean isIDLType() { |
duke@1 | 413 | return isIDLType; |
duke@1 | 414 | } |
duke@1 | 415 | |
duke@1 | 416 | public final String getRepositoryId() { |
duke@1 | 417 | return repId; |
duke@1 | 418 | } |
duke@1 | 419 | |
duke@1 | 420 | public static byte[] getByteArray(String repStr) { |
duke@1 | 421 | synchronized (repStrToByteArray){ |
duke@1 | 422 | return (byte[]) repStrToByteArray.get(repStr); |
duke@1 | 423 | } |
duke@1 | 424 | } |
duke@1 | 425 | |
duke@1 | 426 | public static void setByteArray(String repStr, byte[] repStrBytes) { |
duke@1 | 427 | synchronized (repStrToByteArray){ |
duke@1 | 428 | repStrToByteArray.put(repStr, repStrBytes); |
duke@1 | 429 | } |
duke@1 | 430 | } |
duke@1 | 431 | |
duke@1 | 432 | public final boolean isSequence() { |
duke@1 | 433 | return isSequence; |
duke@1 | 434 | } |
duke@1 | 435 | |
duke@1 | 436 | public final boolean isSupportedFormat() { |
duke@1 | 437 | return isSupportedFormat; |
duke@1 | 438 | } |
duke@1 | 439 | |
duke@1 | 440 | |
duke@1 | 441 | // This method will return the classname from the typestring OR if the classname turns out to be |
duke@1 | 442 | // a special class "pseudo" name, then the matching real classname is returned. |
duke@1 | 443 | public final String getClassName() { |
duke@1 | 444 | |
duke@1 | 445 | if (isRMIValueType) |
duke@1 | 446 | return typeString; |
duke@1 | 447 | else if (isIDLType) |
duke@1 | 448 | return completeClassName; |
duke@1 | 449 | else return null; |
duke@1 | 450 | |
duke@1 | 451 | } |
duke@1 | 452 | |
duke@1 | 453 | // This method calls getClazzFromType() and falls back to the repStrToClass |
duke@1 | 454 | // cache if no class was found. It's used where any class matching the |
duke@1 | 455 | // given repid is an acceptable result. |
duke@1 | 456 | public final Class getAnyClassFromType() throws ClassNotFoundException { |
duke@1 | 457 | try { |
duke@1 | 458 | return getClassFromType(); |
duke@1 | 459 | } catch (ClassNotFoundException cnfe) { |
duke@1 | 460 | Class clz = (Class)repStrToClass.get(repId); |
duke@1 | 461 | if (clz != null) |
duke@1 | 462 | return clz; |
duke@1 | 463 | else |
duke@1 | 464 | throw cnfe; |
duke@1 | 465 | } |
duke@1 | 466 | } |
duke@1 | 467 | |
duke@1 | 468 | public final Class getClassFromType() |
duke@1 | 469 | throws ClassNotFoundException { |
duke@1 | 470 | if (clazz != null) |
duke@1 | 471 | return clazz; |
duke@1 | 472 | |
duke@1 | 473 | Class specialCase = (Class)kSpecialCasesClasses.get(getClassName()); |
duke@1 | 474 | |
duke@1 | 475 | if (specialCase != null){ |
duke@1 | 476 | clazz = specialCase; |
duke@1 | 477 | return specialCase; |
duke@1 | 478 | } |
duke@1 | 479 | else |
duke@1 | 480 | { |
duke@1 | 481 | try{ |
duke@1 | 482 | return Util.loadClass(getClassName(), null, null); |
duke@1 | 483 | } |
duke@1 | 484 | catch(ClassNotFoundException cnfe){ |
duke@1 | 485 | if (defaultServerURL != null) { |
duke@1 | 486 | try{ |
duke@1 | 487 | return getClassFromType(defaultServerURL); |
duke@1 | 488 | } |
duke@1 | 489 | catch(MalformedURLException mue){ |
duke@1 | 490 | throw cnfe; |
duke@1 | 491 | } |
duke@1 | 492 | } |
duke@1 | 493 | else throw cnfe; |
duke@1 | 494 | } |
duke@1 | 495 | } |
duke@1 | 496 | |
duke@1 | 497 | } |
duke@1 | 498 | |
duke@1 | 499 | public final Class getClassFromType(Class expectedType, String codebase) |
duke@1 | 500 | throws ClassNotFoundException { |
duke@1 | 501 | if (clazz != null) |
duke@1 | 502 | return clazz; |
duke@1 | 503 | |
duke@1 | 504 | Class specialCase = (Class)kSpecialCasesClasses.get(getClassName()); |
duke@1 | 505 | |
duke@1 | 506 | if (specialCase != null){ |
duke@1 | 507 | clazz = specialCase; |
duke@1 | 508 | return specialCase; |
duke@1 | 509 | } else { |
duke@1 | 510 | ClassLoader expectedTypeClassLoader = (expectedType == null ? null : expectedType.getClassLoader()); |
duke@1 | 511 | return loadClassOfType(getClassName(), |
duke@1 | 512 | codebase, |
duke@1 | 513 | expectedTypeClassLoader, |
duke@1 | 514 | expectedType, |
duke@1 | 515 | expectedTypeClassLoader); |
duke@1 | 516 | } |
duke@1 | 517 | |
duke@1 | 518 | } |
duke@1 | 519 | |
duke@1 | 520 | public final Class getClassFromType(String url) |
duke@1 | 521 | throws ClassNotFoundException, MalformedURLException { |
duke@1 | 522 | return Util.loadClass(getClassName(), url, null); |
duke@1 | 523 | } |
duke@1 | 524 | |
duke@1 | 525 | public final String toString() { |
duke@1 | 526 | return repId; |
duke@1 | 527 | } |
duke@1 | 528 | |
duke@1 | 529 | private static String createHashString(java.io.Serializable ser) { |
duke@1 | 530 | |
duke@1 | 531 | return createHashString(ser.getClass()); |
duke@1 | 532 | } |
duke@1 | 533 | |
duke@1 | 534 | private static String createHashString(java.lang.Class clazz) { |
duke@1 | 535 | |
duke@1 | 536 | if (clazz.isInterface() || !java.io.Serializable.class.isAssignableFrom(clazz)) |
duke@1 | 537 | return kInterfaceHashCode; |
duke@1 | 538 | |
duke@1 | 539 | |
duke@1 | 540 | long actualLong = ObjectStreamClassUtil_1_3.computeStructuralUID(false, clazz); |
duke@1 | 541 | String hash = null; |
duke@1 | 542 | if (actualLong == 0) |
duke@1 | 543 | hash = kInterfaceOnlyHashStr; |
duke@1 | 544 | else if (actualLong == 1) |
duke@1 | 545 | hash = kExternalizableHashStr; |
duke@1 | 546 | else |
duke@1 | 547 | hash = Long.toHexString(actualLong).toUpperCase(); |
duke@1 | 548 | while(hash.length() < 16){ |
duke@1 | 549 | hash = "0" + hash; |
duke@1 | 550 | } |
duke@1 | 551 | |
duke@1 | 552 | long declaredLong = ObjectStreamClassUtil_1_3.computeSerialVersionUID(clazz); |
duke@1 | 553 | String declared = null; |
duke@1 | 554 | if (declaredLong == 0) |
duke@1 | 555 | declared = kInterfaceOnlyHashStr; |
duke@1 | 556 | else if (declaredLong == 1) |
duke@1 | 557 | declared = kExternalizableHashStr; |
duke@1 | 558 | else |
duke@1 | 559 | declared = Long.toHexString(declaredLong).toUpperCase(); |
duke@1 | 560 | while (declared.length() < 16){ |
duke@1 | 561 | declared = "0" + declared; |
duke@1 | 562 | } |
duke@1 | 563 | hash = hash + ":" + declared; |
duke@1 | 564 | |
duke@1 | 565 | return ":" + hash; |
duke@1 | 566 | } |
duke@1 | 567 | |
duke@1 | 568 | /** |
duke@1 | 569 | * Creates a repository ID for a sequence. This is for expert users only as |
duke@1 | 570 | * this method assumes the object passed is an array. If passed an object |
duke@1 | 571 | * that is not an array, it will produce a rep id for a sequence of zero |
duke@1 | 572 | * length. This would be an error. |
duke@1 | 573 | * @param ser The Java object to create a repository ID for |
duke@1 | 574 | **/ |
duke@1 | 575 | public static String createSequenceRepID(java.lang.Object ser){ |
duke@1 | 576 | return createSequenceRepID(ser.getClass()); |
duke@1 | 577 | } |
duke@1 | 578 | |
duke@1 | 579 | /** |
duke@1 | 580 | * Creates a repository ID for a sequence. This is for expert users only as |
duke@1 | 581 | * this method assumes the object passed is an array. If passed an object |
duke@1 | 582 | * that is not an array, it will produce a malformed rep id. |
duke@1 | 583 | * @param clazz The Java class to create a repository ID for |
duke@1 | 584 | **/ |
duke@1 | 585 | public static String createSequenceRepID(java.lang.Class clazz){ |
duke@1 | 586 | synchronized (classSeqToRepStr){ |
duke@1 | 587 | |
duke@1 | 588 | String repid = (String)classSeqToRepStr.get(clazz); |
duke@1 | 589 | if (repid != null) |
duke@1 | 590 | return repid; |
duke@1 | 591 | |
duke@1 | 592 | Class originalClazz = clazz; |
duke@1 | 593 | |
duke@1 | 594 | Class type = null; |
duke@1 | 595 | int numOfDims = 0; |
duke@1 | 596 | |
duke@1 | 597 | while ((type = clazz.getComponentType()) != null) { |
duke@1 | 598 | numOfDims++; |
duke@1 | 599 | clazz = type; |
duke@1 | 600 | } |
duke@1 | 601 | |
duke@1 | 602 | if (clazz.isPrimitive()) |
duke@1 | 603 | repid = kValuePrefix + originalClazz.getName() + kPrimitiveSequenceValueHash; |
duke@1 | 604 | else { |
duke@1 | 605 | StringBuffer buf = new StringBuffer(); |
duke@1 | 606 | buf.append(kValuePrefix); |
duke@1 | 607 | while(numOfDims-- > 0) { |
duke@1 | 608 | buf.append("["); |
duke@1 | 609 | } |
duke@1 | 610 | buf.append("L"); |
duke@1 | 611 | buf.append(convertToISOLatin1(clazz.getName())); |
duke@1 | 612 | buf.append(";"); |
duke@1 | 613 | buf.append(createHashString(clazz)); |
duke@1 | 614 | repid = buf.toString(); |
duke@1 | 615 | } |
duke@1 | 616 | classSeqToRepStr.put(originalClazz,repid); |
duke@1 | 617 | return repid; |
duke@1 | 618 | } |
duke@1 | 619 | |
duke@1 | 620 | } |
duke@1 | 621 | |
duke@1 | 622 | |
duke@1 | 623 | public static String createForSpecialCase(java.lang.Class clazz){ |
duke@1 | 624 | if (clazz.isArray()){ |
duke@1 | 625 | return createSequenceRepID(clazz); |
duke@1 | 626 | } |
duke@1 | 627 | else { |
duke@1 | 628 | return (String)kSpecialCasesRepIDs.get(clazz); |
duke@1 | 629 | } |
duke@1 | 630 | } |
duke@1 | 631 | |
duke@1 | 632 | public static String createForSpecialCase(java.io.Serializable ser){ |
duke@1 | 633 | Class clazz = ser.getClass(); |
duke@1 | 634 | if (clazz.isArray()){ |
duke@1 | 635 | return createSequenceRepID(ser); |
duke@1 | 636 | } |
duke@1 | 637 | else |
duke@1 | 638 | return createForSpecialCase(clazz); |
duke@1 | 639 | } |
duke@1 | 640 | |
duke@1 | 641 | /** |
duke@1 | 642 | * Creates a repository ID for a normal Java Type. |
duke@1 | 643 | * @param ser The Java object to create a repository ID for |
duke@1 | 644 | * @exception com.sun.corba.se.impl.io.TypeMismatchException if ser implements the |
duke@1 | 645 | * org.omg.CORBA.portable.IDLEntity interface which indicates it is an IDL Value type. |
duke@1 | 646 | **/ |
duke@1 | 647 | public static String createForJavaType(java.io.Serializable ser) |
duke@1 | 648 | throws com.sun.corba.se.impl.io.TypeMismatchException |
duke@1 | 649 | { |
duke@1 | 650 | synchronized (classToRepStr) { |
duke@1 | 651 | String repid = createForSpecialCase(ser); |
duke@1 | 652 | if (repid != null) |
duke@1 | 653 | return repid; |
duke@1 | 654 | Class clazz = ser.getClass(); |
duke@1 | 655 | repid = (String)classToRepStr.get(clazz); |
duke@1 | 656 | |
duke@1 | 657 | if (repid != null) |
duke@1 | 658 | return repid; |
duke@1 | 659 | |
duke@1 | 660 | repid = kValuePrefix + convertToISOLatin1(clazz.getName()) + |
duke@1 | 661 | createHashString(clazz); |
duke@1 | 662 | |
duke@1 | 663 | classToRepStr.put(clazz, repid); |
duke@1 | 664 | repStrToClass.put(repid, clazz); |
duke@1 | 665 | return repid; |
duke@1 | 666 | } |
duke@1 | 667 | } |
duke@1 | 668 | |
duke@1 | 669 | /** |
duke@1 | 670 | * Creates a repository ID for a normal Java Type. |
duke@1 | 671 | * @param clz The Java class to create a repository ID for |
duke@1 | 672 | * @exception com.sun.corba.se.impl.io.TypeMismatchException if ser implements the |
duke@1 | 673 | * org.omg.CORBA.portable.IDLEntity interface which indicates it is an IDL Value type. |
duke@1 | 674 | **/ |
duke@1 | 675 | public static String createForJavaType(Class clz) |
duke@1 | 676 | throws com.sun.corba.se.impl.io.TypeMismatchException |
duke@1 | 677 | { |
duke@1 | 678 | synchronized (classToRepStr){ |
duke@1 | 679 | String repid = createForSpecialCase(clz); |
duke@1 | 680 | if (repid != null) |
duke@1 | 681 | return repid; |
duke@1 | 682 | |
duke@1 | 683 | repid = (String)classToRepStr.get(clz); |
duke@1 | 684 | if (repid != null) |
duke@1 | 685 | return repid; |
duke@1 | 686 | |
duke@1 | 687 | repid = kValuePrefix + convertToISOLatin1(clz.getName()) + |
duke@1 | 688 | createHashString(clz); |
duke@1 | 689 | |
duke@1 | 690 | classToRepStr.put(clz, repid); |
duke@1 | 691 | repStrToClass.put(repid, clz); |
duke@1 | 692 | return repid; |
duke@1 | 693 | } |
duke@1 | 694 | } |
duke@1 | 695 | |
duke@1 | 696 | /** |
duke@1 | 697 | * Creates a repository ID for an IDL Java Type. |
duke@1 | 698 | * @param ser The IDL Value object to create a repository ID for |
duke@1 | 699 | * @param major The major version number |
duke@1 | 700 | * @param minor The minor version number |
duke@1 | 701 | * @exception com.sun.corba.se.impl.io.TypeMismatchException if ser does not implement the |
duke@1 | 702 | * org.omg.CORBA.portable.IDLEntity interface which indicates it is an IDL Value type. |
duke@1 | 703 | **/ |
duke@1 | 704 | public static String createForIDLType(Class ser, int major, int minor) |
duke@1 | 705 | throws com.sun.corba.se.impl.io.TypeMismatchException |
duke@1 | 706 | { |
duke@1 | 707 | synchronized (classIDLToRepStr){ |
duke@1 | 708 | String repid = (String)classIDLToRepStr.get(ser); |
duke@1 | 709 | if (repid != null) |
duke@1 | 710 | return repid; |
duke@1 | 711 | |
duke@1 | 712 | repid = kIDLPrefix + convertToISOLatin1(ser.getName()).replace('.','/') + |
duke@1 | 713 | ":" + major + "." + minor; |
duke@1 | 714 | classIDLToRepStr.put(ser, repid); |
duke@1 | 715 | return repid; |
duke@1 | 716 | } |
duke@1 | 717 | } |
duke@1 | 718 | |
duke@1 | 719 | private static String getIdFromHelper(Class clazz){ |
duke@1 | 720 | try { |
duke@1 | 721 | Class helperClazz = Utility.loadClassForClass(clazz.getName()+"Helper", null, |
duke@1 | 722 | clazz.getClassLoader(), clazz, clazz.getClassLoader()); |
duke@1 | 723 | Method idMethod = helperClazz.getDeclaredMethod("id", kNoParamTypes); |
duke@1 | 724 | return (String)idMethod.invoke(null, kNoArgs); |
duke@1 | 725 | } |
duke@1 | 726 | catch(java.lang.ClassNotFoundException cnfe) |
duke@1 | 727 | { |
duke@1 | 728 | throw new org.omg.CORBA.MARSHAL(cnfe.toString()); |
duke@1 | 729 | } |
duke@1 | 730 | catch(java.lang.NoSuchMethodException nsme) |
duke@1 | 731 | { |
duke@1 | 732 | throw new org.omg.CORBA.MARSHAL(nsme.toString()); |
duke@1 | 733 | } |
duke@1 | 734 | catch(java.lang.reflect.InvocationTargetException ite) |
duke@1 | 735 | { |
duke@1 | 736 | throw new org.omg.CORBA.MARSHAL(ite.toString()); |
duke@1 | 737 | } |
duke@1 | 738 | catch(java.lang.IllegalAccessException iae) |
duke@1 | 739 | { |
duke@1 | 740 | throw new org.omg.CORBA.MARSHAL(iae.toString()); |
duke@1 | 741 | } |
duke@1 | 742 | } |
duke@1 | 743 | |
duke@1 | 744 | /** |
duke@1 | 745 | * Createa a repository ID for the type if it is either a java type |
duke@1 | 746 | * or an IDL type. |
duke@1 | 747 | * @param type The type to create rep. id for |
duke@1 | 748 | * @return The rep. id. |
duke@1 | 749 | **/ |
duke@1 | 750 | public static String createForAnyType(Class type) { |
duke@1 | 751 | try{ |
duke@1 | 752 | if (type.isArray()) |
duke@1 | 753 | return createSequenceRepID(type); |
duke@1 | 754 | else if (IDLEntity.class.isAssignableFrom(type)) |
duke@1 | 755 | { |
duke@1 | 756 | try{ |
duke@1 | 757 | return getIdFromHelper(type); |
duke@1 | 758 | } |
duke@1 | 759 | catch(Throwable t) { |
duke@1 | 760 | return createForIDLType(type, 1, 0); |
duke@1 | 761 | } |
duke@1 | 762 | } |
duke@1 | 763 | else return createForJavaType(type); |
duke@1 | 764 | } |
duke@1 | 765 | catch(com.sun.corba.se.impl.io.TypeMismatchException e){ |
duke@1 | 766 | return null; |
duke@1 | 767 | } |
duke@1 | 768 | |
duke@1 | 769 | } |
duke@1 | 770 | |
duke@1 | 771 | public static boolean isAbstractBase(Class clazz) { |
duke@1 | 772 | return (clazz.isInterface() && |
duke@1 | 773 | IDLEntity.class.isAssignableFrom(clazz) && |
duke@1 | 774 | (!ValueBase.class.isAssignableFrom(clazz)) && |
duke@1 | 775 | (!org.omg.CORBA.Object.class.isAssignableFrom(clazz))); |
duke@1 | 776 | |
duke@1 | 777 | } |
duke@1 | 778 | |
duke@1 | 779 | /** |
duke@1 | 780 | * Convert strings with illegal IDL identifier characters. |
duke@1 | 781 | * <p> |
duke@1 | 782 | * Section 5.5.7 of OBV spec. |
duke@1 | 783 | */ |
duke@1 | 784 | private static String convertToISOLatin1 (String name) { |
duke@1 | 785 | |
duke@1 | 786 | int length = name.length(); |
duke@1 | 787 | if (length == 0) { |
duke@1 | 788 | return name; |
duke@1 | 789 | } |
duke@1 | 790 | StringBuffer buffer = null; |
duke@1 | 791 | |
duke@1 | 792 | for (int i = 0; i < length; i++) { |
duke@1 | 793 | |
duke@1 | 794 | char c = name.charAt(i); |
duke@1 | 795 | |
duke@1 | 796 | if (c > 255 || IDL_IDENTIFIER_CHARS[c] == 0) { |
duke@1 | 797 | |
duke@1 | 798 | // We gotta convert. Have we already started? |
duke@1 | 799 | |
duke@1 | 800 | if (buffer == null) { |
duke@1 | 801 | |
duke@1 | 802 | // No, so get set up... |
duke@1 | 803 | |
duke@1 | 804 | buffer = new StringBuffer(name.substring(0,i)); |
duke@1 | 805 | } |
duke@1 | 806 | |
duke@1 | 807 | // Convert the character into the IDL escape syntax... |
duke@1 | 808 | buffer.append( |
duke@1 | 809 | "\\U" + |
duke@1 | 810 | (char)ASCII_HEX[(c & 0xF000) >>> 12] + |
duke@1 | 811 | (char)ASCII_HEX[(c & 0x0F00) >>> 8] + |
duke@1 | 812 | (char)ASCII_HEX[(c & 0x00F0) >>> 4] + |
duke@1 | 813 | (char)ASCII_HEX[(c & 0x000F)]); |
duke@1 | 814 | |
duke@1 | 815 | } else { |
duke@1 | 816 | if (buffer != null) { |
duke@1 | 817 | buffer.append(c); |
duke@1 | 818 | } |
duke@1 | 819 | } |
duke@1 | 820 | } |
duke@1 | 821 | |
duke@1 | 822 | if (buffer != null) { |
duke@1 | 823 | name = buffer.toString(); |
duke@1 | 824 | } |
duke@1 | 825 | |
duke@1 | 826 | return name; |
duke@1 | 827 | } |
duke@1 | 828 | |
duke@1 | 829 | /** |
duke@1 | 830 | * Convert strings with ISO Latin 1 escape sequences back to original strings. |
duke@1 | 831 | * <p> |
duke@1 | 832 | * Section 5.5.7 of OBV spec. |
duke@1 | 833 | */ |
duke@1 | 834 | private static String convertFromISOLatin1 (String name) { |
duke@1 | 835 | |
duke@1 | 836 | int index = -1; |
duke@1 | 837 | StringBuffer buf = new StringBuffer(name); |
duke@1 | 838 | |
duke@1 | 839 | while ((index = buf.toString().indexOf("\\U")) != -1){ |
duke@1 | 840 | String str = "0000" + buf.toString().substring(index+2, index+6); |
duke@1 | 841 | |
duke@1 | 842 | // Convert Hexadecimal |
duke@1 | 843 | byte[] buffer = new byte[(str.length() - 4) / 2]; |
duke@1 | 844 | for (int i=4, j=0; i < str.length(); i +=2, j++) { |
duke@1 | 845 | buffer[j] = (byte)((ORBUtility.hexOf(str.charAt(i)) << 4) & 0xF0); |
duke@1 | 846 | buffer[j] |= (byte)((ORBUtility.hexOf(str.charAt(i+1)) << 0) & 0x0F); |
duke@1 | 847 | } |
duke@1 | 848 | buf = new StringBuffer(delete(buf.toString(), index, index+6)); |
duke@1 | 849 | buf.insert(index, (char)buffer[1]); |
duke@1 | 850 | } |
duke@1 | 851 | |
duke@1 | 852 | return buf.toString(); |
duke@1 | 853 | |
duke@1 | 854 | |
duke@1 | 855 | } |
duke@1 | 856 | |
duke@1 | 857 | private static String delete(String str, int from, int to) |
duke@1 | 858 | { |
duke@1 | 859 | return str.substring(0, from) + str.substring(to, str.length()); |
duke@1 | 860 | } |
duke@1 | 861 | |
duke@1 | 862 | private static String replace(String target, String arg, String source) |
duke@1 | 863 | { |
duke@1 | 864 | int i = 0; |
duke@1 | 865 | i = target.indexOf(arg); |
duke@1 | 866 | |
duke@1 | 867 | while(i != -1) |
duke@1 | 868 | { |
duke@1 | 869 | String left = target.substring(0, i); |
duke@1 | 870 | String right = target.substring(i+arg.length()); |
duke@1 | 871 | target = new String(left+source+right); |
duke@1 | 872 | i = target.indexOf(arg); |
duke@1 | 873 | } |
duke@1 | 874 | return target; |
duke@1 | 875 | } |
duke@1 | 876 | |
duke@1 | 877 | /* |
duke@1 | 878 | * Load a class and check that it is assignable to a given type. |
duke@1 | 879 | * @param className the class name. |
duke@1 | 880 | * @param remoteCodebase the codebase to use. May be null. |
duke@1 | 881 | * @param loader the class loader of last resort. May be null. |
duke@1 | 882 | * @param expectedType the expected type. May be null. |
duke@1 | 883 | * @return the loaded class. |
duke@1 | 884 | */ |
duke@1 | 885 | private Class loadClassOfType (String className, |
duke@1 | 886 | String remoteCodebase, |
duke@1 | 887 | ClassLoader loader, |
duke@1 | 888 | Class expectedType, |
duke@1 | 889 | ClassLoader expectedTypeClassLoader) |
duke@1 | 890 | throws ClassNotFoundException { |
duke@1 | 891 | |
duke@1 | 892 | Class loadedClass = null; |
duke@1 | 893 | |
duke@1 | 894 | try { |
duke@1 | 895 | //Sequence finding of the stubs according to spec |
duke@1 | 896 | try{ |
duke@1 | 897 | //If-else is put here for speed up of J2EE. |
duke@1 | 898 | //According to the OMG spec, the if clause is not dead code. |
duke@1 | 899 | //It can occur if some compiler has allowed generation |
duke@1 | 900 | //into org.omg.stub hierarchy for non-offending |
duke@1 | 901 | //classes. This will encourage people to |
duke@1 | 902 | //produce non-offending class stubs in their own hierarchy. |
duke@1 | 903 | if(!PackagePrefixChecker |
duke@1 | 904 | .hasOffendingPrefix(PackagePrefixChecker |
duke@1 | 905 | .withoutPackagePrefix(className))){ |
duke@1 | 906 | loadedClass = Util.loadClass |
duke@1 | 907 | (PackagePrefixChecker.withoutPackagePrefix(className), |
duke@1 | 908 | remoteCodebase, |
duke@1 | 909 | loader); |
duke@1 | 910 | } else { |
duke@1 | 911 | loadedClass = Util.loadClass |
duke@1 | 912 | (className, |
duke@1 | 913 | remoteCodebase, |
duke@1 | 914 | loader); |
duke@1 | 915 | } |
duke@1 | 916 | } catch (ClassNotFoundException cnfe) { |
duke@1 | 917 | loadedClass = Util.loadClass |
duke@1 | 918 | (className, |
duke@1 | 919 | remoteCodebase, |
duke@1 | 920 | loader); |
duke@1 | 921 | } |
duke@1 | 922 | if (expectedType == null) |
duke@1 | 923 | return loadedClass; |
duke@1 | 924 | } catch (ClassNotFoundException cnfe) { |
duke@1 | 925 | if (expectedType == null) |
duke@1 | 926 | throw cnfe; |
duke@1 | 927 | } |
duke@1 | 928 | |
duke@1 | 929 | // If no class was not loaded, or if the loaded class is not of the |
duke@1 | 930 | // correct type, make a further attempt to load the correct class |
duke@1 | 931 | // using the classloader of the expected type. |
duke@1 | 932 | // _REVISIT_ Is this step necessary, or should the Util,loadClass |
duke@1 | 933 | // algorithm always produce a valid class if the setup is correct? |
duke@1 | 934 | // Does the OMG standard algorithm need to be changed to include |
duke@1 | 935 | // this step? |
duke@1 | 936 | if (loadedClass == null || !expectedType.isAssignableFrom(loadedClass)) { |
duke@1 | 937 | if (expectedType.getClassLoader() != expectedTypeClassLoader) |
duke@1 | 938 | throw new IllegalArgumentException("expectedTypeClassLoader not class loader of expectedType."); |
duke@1 | 939 | |
duke@1 | 940 | if (expectedTypeClassLoader != null) |
duke@1 | 941 | loadedClass = expectedTypeClassLoader.loadClass(className); |
duke@1 | 942 | else |
duke@1 | 943 | loadedClass = ORBClassLoader.loadClass(className); |
duke@1 | 944 | } |
duke@1 | 945 | |
duke@1 | 946 | return loadedClass; |
duke@1 | 947 | } |
duke@1 | 948 | |
duke@1 | 949 | /** |
duke@1 | 950 | * Checks to see if the FullValueDescription should be retrieved. |
duke@1 | 951 | * @exception Throws IOException if suids do not match or if the repositoryID |
duke@1 | 952 | * is not an RMIValueType |
duke@1 | 953 | */ |
duke@1 | 954 | public static boolean useFullValueDescription(Class clazz, String repositoryID) |
duke@1 | 955 | throws IOException{ |
duke@1 | 956 | |
duke@1 | 957 | String clazzRepIDStr = createForAnyType(clazz); |
duke@1 | 958 | |
duke@1 | 959 | if (clazzRepIDStr.equals(repositoryID)) |
duke@1 | 960 | return false; |
duke@1 | 961 | |
duke@1 | 962 | RepositoryId_1_3 targetRepid; |
duke@1 | 963 | RepositoryId_1_3 clazzRepid; |
duke@1 | 964 | |
duke@1 | 965 | synchronized(cache) { |
duke@1 | 966 | // to avoid race condition where multiple threads could be |
duke@1 | 967 | // accessing this method, and their access to the cache may |
duke@1 | 968 | // be interleaved giving unexpected results |
duke@1 | 969 | |
duke@1 | 970 | targetRepid = cache.getId(repositoryID); |
duke@1 | 971 | clazzRepid = cache.getId(clazzRepIDStr); |
duke@1 | 972 | } |
duke@1 | 973 | |
duke@1 | 974 | if ((targetRepid.isRMIValueType()) && (clazzRepid.isRMIValueType())){ |
duke@1 | 975 | if (!targetRepid.getSerialVersionUID().equals(clazzRepid.getSerialVersionUID())) { |
duke@1 | 976 | |
duke@1 | 977 | String mssg = "Mismatched serialization UIDs : Source (Rep. ID" + |
duke@1 | 978 | clazzRepid + ") = " + |
duke@1 | 979 | clazzRepid.getSerialVersionUID() + " whereas Target (Rep. ID " + repositoryID + |
duke@1 | 980 | ") = " + targetRepid.getSerialVersionUID(); |
duke@1 | 981 | throw new IOException(mssg); |
duke@1 | 982 | } else { |
duke@1 | 983 | return true; |
duke@1 | 984 | } |
duke@1 | 985 | } else { |
duke@1 | 986 | |
duke@1 | 987 | throw new IOException("The repository ID is not of an RMI value type (Expected ID = " + clazzRepIDStr + "; Received ID = " + repositoryID +")"); |
duke@1 | 988 | } |
duke@1 | 989 | } |
duke@1 | 990 | } |