blob: 62ea5fbac02308c9869cd490bd493e27bb40745a [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 1998 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24package extension;
25
26import java.util.Hashtable;
27import java.io.*;
28
29public class ExtendedObjectInputStream extends ObjectInputStream {
30
31 static private 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 static public 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}