01: /*
02: * Copyright 1999,2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.apache.catalina.util;
18:
19: import java.io.InputStream;
20: import java.io.IOException;
21: import java.io.ObjectInputStream;
22: import java.io.ObjectStreamClass;
23:
24: /**
25: * Custom subclass of <code>ObjectInputStream</code> that loads from the
26: * class loader for this web application. This allows classes defined only
27: * with the web application to be found correctly.
28: *
29: * @author Craig R. McClanahan
30: * @author Bip Thelin
31: * @version $Revision: 1.3 $, $Date: 2004/02/27 14:58:50 $
32: */
33:
34: public final class CustomObjectInputStream extends ObjectInputStream {
35:
36: /**
37: * The class loader we will use to resolve classes.
38: */
39: private ClassLoader classLoader = null;
40:
41: /**
42: * Construct a new instance of CustomObjectInputStream
43: *
44: * @param stream The input stream we will read from
45: * @param classLoader The class loader used to instantiate objects
46: *
47: * @exception IOException if an input/output error occurs
48: */
49: public CustomObjectInputStream(InputStream stream,
50: ClassLoader classLoader) throws IOException {
51:
52: super (stream);
53: this .classLoader = classLoader;
54: }
55:
56: /**
57: * Load the local class equivalent of the specified stream class
58: * description, by using the class loader assigned to this Context.
59: *
60: * @param classDesc Class description from the input stream
61: *
62: * @exception ClassNotFoundException if this class cannot be found
63: * @exception IOException if an input/output error occurs
64: */
65: public Class resolveClass(ObjectStreamClass classDesc)
66: throws ClassNotFoundException, IOException {
67: return Class.forName(classDesc.getName(), false, classLoader);
68: }
69:
70: }
|