01: /*
02: * Javassist, a Java-bytecode translator toolkit.
03: * Copyright (C) 1999-2006 Shigeru Chiba. All Rights Reserved.
04: *
05: * The contents of this file are subject to the Mozilla Public License Version
06: * 1.1 (the "License"); you may not use this file except in compliance with
07: * the License. Alternatively, the contents of this file may be used under
08: * the terms of the GNU Lesser General Public License Version 2.1 or later.
09: *
10: * Software distributed under the License is distributed on an "AS IS" basis,
11: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12: * for the specific language governing rights and limitations under the
13: * License.
14: */
15:
16: package javassist.util.proxy;
17:
18: import java.io.Serializable;
19: import java.io.ObjectStreamException;
20:
21: /**
22: * A proxy object is converted into an instance of this class
23: * when it is written to an output stream.
24: *
25: * @see RuntimeSupport#makeSerializedProxy(Object)
26: */
27: class SerializedProxy implements Serializable {
28: private String super Class;
29: private String[] interfaces;
30: private MethodFilter filter;
31: private MethodHandler handler;
32:
33: SerializedProxy(Class proxy, MethodFilter f, MethodHandler h) {
34: filter = f;
35: handler = h;
36: super Class = proxy.getSuperclass().getName();
37: Class[] infs = proxy.getInterfaces();
38: int n = infs.length;
39: interfaces = new String[n - 1];
40: String setterInf = ProxyObject.class.getName();
41: for (int i = 0; i < n; i++) {
42: String name = infs[i].getName();
43: if (!name.equals(setterInf))
44: interfaces[i] = name;
45: }
46: }
47:
48: Object readResolve() throws ObjectStreamException {
49: try {
50: int n = interfaces.length;
51: Class[] infs = new Class[n];
52: for (int i = 0; i < n; i++)
53: infs[i] = Class.forName(interfaces[i]);
54:
55: ProxyFactory f = new ProxyFactory();
56: f.setSuperclass(Class.forName(super Class));
57: f.setInterfaces(infs);
58: f.setFilter(filter);
59: f.setHandler(handler);
60: return f.createClass().newInstance();
61: } catch (ClassNotFoundException e) {
62: throw new java.io.InvalidClassException(e.getMessage());
63: } catch (InstantiationException e2) {
64: throw new java.io.InvalidObjectException(e2.getMessage());
65: } catch (IllegalAccessException e3) {
66: throw new java.io.InvalidClassException(e3.getMessage());
67: }
68: }
69: }
|