01: /****************************************************************
02: * Licensed to the Apache Software Foundation (ASF) under one *
03: * or more contributor license agreements. See the NOTICE file *
04: * distributed with this work for additional information *
05: * regarding copyright ownership. The ASF licenses this file *
06: * to you under the Apache License, Version 2.0 (the *
07: * "License"); you may not use this file except in compliance *
08: * with the License. You may obtain a copy of the License at *
09: * *
10: * http://www.apache.org/licenses/LICENSE-2.0 *
11: * *
12: * Unless required by applicable law or agreed to in writing, *
13: * software distributed under the License is distributed on an *
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
15: * KIND, either express or implied. See the License for the *
16: * specific language governing permissions and limitations *
17: * under the License. *
18: ****************************************************************/package org.apache.james.util.io;
19:
20: import java.io.IOException;
21: import java.io.InputStream;
22: import java.io.ObjectInputStream;
23: import java.io.ObjectStreamClass;
24: import java.io.StreamCorruptedException;
25:
26: /**
27: * A special ObjectInputStream to handle highly transient classes hosted
28: * by Avalon components that are juggling many classloaders.
29: *
30: * @author <a href="mailto:paul_hammant@yahoo.com">Paul Hammant</a>
31: * @version $Revision: 494012 $ $Date: 2007-01-08 11:23:58 +0100 (Mo, 08 Jan 2007) $
32: */
33: public class ClassLoaderObjectInputStream extends ObjectInputStream {
34: private ClassLoader m_classLoader;
35:
36: public ClassLoaderObjectInputStream(final ClassLoader classLoader,
37: final InputStream inputStream) throws IOException,
38: StreamCorruptedException {
39: super (inputStream);
40: m_classLoader = classLoader;
41: }
42:
43: protected Class resolveClass(
44: final ObjectStreamClass objectStreamClass)
45: throws IOException, ClassNotFoundException {
46: final Class clazz = Class.forName(objectStreamClass.getName(),
47: false, m_classLoader);
48:
49: if (null != clazz) {
50: return clazz; // the classloader knows of the class
51: } else {
52: // classloader knows not of class, let the super classloader do it
53: return super.resolveClass(objectStreamClass);
54: }
55: }
56: }
|