2
* JBoss, Home of Professional Open Source
3
* Copyright 2005, JBoss Inc., and individual contributors as indicated
4
* by the @authors tag. See the copyright.txt in the distribution for a
5
* full listing of individual contributors.
7
* This is free software; you can redistribute it and/or modify it
8
* under the terms of the GNU Lesser General Public License as
9
* published by the Free Software Foundation; either version 2.1 of
10
* the License, or (at your option) any later version.
12
* This software is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this software; if not, write to the Free
19
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
24
package org.jboss.remoting.serialization.impl.java;
26
import java.io.IOException;
27
import java.io.InputStream;
28
import java.io.ObjectInputStream;
29
import java.io.ObjectStreamClass;
30
import java.lang.reflect.Proxy;
31
import java.security.AccessController;
32
import java.security.PrivilegedAction;
34
import org.jboss.logging.Logger;
37
* An ObjectInputStream subclass used by the MarshalledValue class to
38
* ensure the classes and proxies are loaded using the thread context
41
* @author Scott.Stark@jboss.org
42
* @author Clebert.suconic@jboss.org - refactored packages only
43
* @version $Revision: 3844 $
45
public class MarshalledValueInputStream
46
extends ObjectInputStream
48
private static Logger log = Logger.getLogger(MarshalledValueInputStream.class);
50
static boolean useClassCache = false;
53
* Creates a new instance of MarshalledValueOutputStream
55
public MarshalledValueInputStream(InputStream is) throws IOException
61
* Use the thread context class loader to resolve the class
63
* @throws java.io.IOException Any exception thrown by the underlying OutputStream.
65
protected Class resolveClass(ObjectStreamClass v)
66
throws IOException, ClassNotFoundException
68
String className = v.getName();
69
Class resolvedClass = null;
71
if(resolvedClass == null)
73
ClassLoader loader = (ClassLoader) AccessController.doPrivileged( new PrivilegedAction()
77
return Thread.currentThread().getContextClassLoader();
82
resolvedClass = Class.forName(className, false, loader);
84
catch(ClassNotFoundException e)
86
/* Use the super.resolveClass() call which will resolve array
87
classes and primitives. We do not use this by default as this can
88
result in caching of stale values across redeployments.
90
resolvedClass = super.resolveClass(v);
96
protected Class resolveProxyClass(String[] interfaces)
97
throws IOException, ClassNotFoundException
99
if(log.isTraceEnabled())
101
StringBuffer tmp = new StringBuffer("[");
102
for(int i = 0; i < interfaces.length; i ++)
108
tmp.append(interfaces[i]);
111
log.trace("resolveProxyClass called, ifaces=" + tmp.toString());
114
// Load the interfaces from the cache or thread context class loader
115
ClassLoader loader = null;
116
Class[] ifaceClasses = new Class[interfaces.length];
117
for(int i = 0; i < interfaces.length; i++)
120
String className = interfaces[i];
121
// Check the proxy cache if it exists
123
// Load the interface class using the thread context ClassLoader
128
loader = (ClassLoader) AccessController.doPrivileged( new PrivilegedAction()
132
return Thread.currentThread().getContextClassLoader();
136
iface = Class.forName(className, false, loader);
138
ifaceClasses[i] = iface;
141
return Proxy.getProxyClass(loader, ifaceClasses);