KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > carol > cmi > CmiInputStream


1 /*
2  * Copyright (C) 2002-2003, Simon Nieuviarts
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17  * USA
18  */

19 package org.objectweb.carol.cmi;
20
21 import java.io.IOException JavaDoc;
22 import java.io.InputStream JavaDoc;
23 import java.io.ObjectInputStream JavaDoc;
24 import java.io.ObjectStreamClass JavaDoc;
25 import java.io.StreamCorruptedException JavaDoc;
26 import java.rmi.server.RMIClassLoader JavaDoc;
27
28 public class CmiInputStream extends ObjectInputStream JavaDoc {
29     public CmiInputStream(InputStream JavaDoc in)
30         throws IOException JavaDoc, StreamCorruptedException JavaDoc {
31         super(in);
32     }
33
34     protected Class JavaDoc resolveClass(ObjectStreamClass JavaDoc classDesc)
35         throws IOException JavaDoc, ClassNotFoundException JavaDoc {
36         Object JavaDoc annotation = readLocation();
37         String JavaDoc className = classDesc.getName();
38
39         try {
40             return super.resolveClass(classDesc);
41         } catch (ClassNotFoundException JavaDoc e) {
42         }
43
44         if (annotation != null && (annotation instanceof String JavaDoc)) {
45             String JavaDoc location = (String JavaDoc) annotation;
46             return RMIClassLoader.loadClass(location, className);
47         } else {
48             return RMIClassLoader.loadClass((String JavaDoc) null, className);
49         }
50     }
51
52     protected Class JavaDoc resolveProxyClass(String JavaDoc[] interfaces)
53         throws IOException JavaDoc, ClassNotFoundException JavaDoc {
54         Object JavaDoc annotation = readLocation();
55
56         ClassLoader JavaDoc loader;
57         if (annotation != null && (annotation instanceof String JavaDoc)) {
58             String JavaDoc location = (String JavaDoc) annotation;
59             loader = RMIClassLoader.getClassLoader(location);
60         } else {
61             loader = RMIClassLoader.getClassLoader(null);
62         }
63
64         Class JavaDoc[] classObjs = new Class JavaDoc[interfaces.length];
65         for (int i = 0; i < interfaces.length; i++) {
66             classObjs[i] = Class.forName(interfaces[i], false, loader);
67         }
68         return java.lang.reflect.Proxy.getProxyClass(loader, classObjs);
69     }
70
71     protected Object JavaDoc readLocation()
72         throws IOException JavaDoc, ClassNotFoundException JavaDoc {
73         return readObject();
74     }
75 }
76
Popular Tags