KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > util > pool > ObjectInputStreamForContext


1 package org.apache.turbine.util.pool;
2
3 /*
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License")
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import java.io.IOException JavaDoc;
20 import java.io.InputStream JavaDoc;
21 import java.io.ObjectInputStream JavaDoc;
22 import java.io.ObjectStreamClass JavaDoc;
23
24 /**
25  * A deserialization stream for a specific class loader context.
26  *
27  * @author <a HREF="mailto:ilkka.priha@simsoft.fi">Ilkka Priha</a>
28  * @version $Id: ObjectInputStreamForContext.java,v 1.3.2.2 2004/05/20 03:25:50 seade Exp $
29  */

30 public class ObjectInputStreamForContext extends ObjectInputStream JavaDoc
31 {
32     /**
33      * The class loader of the context.
34      */

35     private ClassLoader JavaDoc classLoader;
36
37     /**
38      * Contructs a new object stream for a context.
39      *
40      * @param in the serialized input stream.
41      * @param loader the class loader of the context.
42      * @throws IOException on errors.
43      */

44     public ObjectInputStreamForContext(InputStream JavaDoc in,
45                                        ClassLoader JavaDoc loader)
46             throws IOException JavaDoc
47     {
48         super(in);
49         classLoader = loader;
50     }
51
52     protected Class JavaDoc resolveClass(ObjectStreamClass JavaDoc v)
53             throws IOException JavaDoc,
54             ClassNotFoundException JavaDoc
55     {
56         return classLoader == null ?
57                 super.resolveClass(v) : classLoader.loadClass(v.getName());
58     }
59 }
60
Popular Tags