KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jmx > mbeanserver > ObjectInputStreamWithLoader


1 /*
2  * @(#)ObjectInputStreamWithLoader.java 4.20 04/02/06
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.jmx.mbeanserver;
9
10 // Java import
11
import java.io.ObjectInputStream JavaDoc;
12 import java.io.InputStream JavaDoc;
13 import java.io.IOException JavaDoc;
14 import java.io.StreamCorruptedException JavaDoc;
15 import java.io.ObjectStreamClass JavaDoc;
16
17 import javax.management.* ;
18  
19
20
21
22 /**
23  * This class deserializes an object in the context of a specific class loader.
24  *
25  * @since 1.5
26  */

27 class ObjectInputStreamWithLoader extends ObjectInputStream JavaDoc {
28
29     
30     private ClassLoader JavaDoc loader;
31
32
33     /**
34      * @exception IOException Signals that an I/O exception of some
35      * sort has occurred.
36      * @exception StreamCorruptedException The object stream is corrupt.
37      */

38     public ObjectInputStreamWithLoader(InputStream JavaDoc in, ClassLoader JavaDoc theLoader)
39         throws IOException JavaDoc {
40     super(in);
41     this.loader = theLoader;
42     }
43     
44     protected Class JavaDoc resolveClass(ObjectStreamClass JavaDoc aClass)
45         throws IOException JavaDoc, ClassNotFoundException JavaDoc {
46     if (loader == null) {
47         return super.resolveClass(aClass);
48     } else {
49         String JavaDoc name = aClass.getName();
50         // Query the class loader ...
51
return Class.forName(name, false, loader);
52     }
53     }
54 }
55
Popular Tags