1/* 2 * Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24package extension; 25 26import java.util.Hashtable; 27import java.io.*; 28 29public class ExtendedObjectInputStream extends ObjectInputStream { 30 31 private static Hashtable renamedClassMap; 32 33 public ExtendedObjectInputStream(InputStream si) 34 throws IOException, StreamCorruptedException 35 { 36 super(si); 37 } 38 39 protected Class resolveClass(ObjectStreamClass v) 40 throws IOException, ClassNotFoundException 41 { 42 if (renamedClassMap != null) { 43 // System.out.println("resolveClass(" + v.getName() + ")"); 44 Class newClass = (Class)renamedClassMap.get(v.getName()); 45 if (newClass != null) { 46 v = ObjectStreamClass.lookup(newClass); 47 } 48 } 49 return super.resolveClass(v); 50 } 51 52 public static void addRenamedClassName(String oldName, String newName) 53 throws ClassNotFoundException 54 { 55 Class cl = null; 56 57 if (renamedClassMap == null) 58 renamedClassMap = new Hashtable(10); 59 if (newName.startsWith("[L")) { 60 // System.out.println("Array processing"); 61 Class componentType = 62 Class.forName(newName.substring(2)); 63 //System.out.println("ComponentType=" + componentType.getName()); 64 Object dummy = 65 java.lang.reflect.Array.newInstance(componentType, 3); 66 67 cl = dummy.getClass(); 68 // System.out.println("Class=" + cl.getName()); 69 } 70 else 71 cl = Class.forName(newName); 72 //System.out.println("oldName=" + oldName + 73 // " newName=" + cl.getName()); 74 renamedClassMap.put(oldName, cl); 75 } 76 77} 78