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.ObjectOutputStream;
28
import java.io.OutputStream;
29
import java.rmi.Remote;
30
import java.rmi.server.RemoteObject;
31
import java.rmi.server.RemoteStub;
32
import java.security.AccessController;
33
import java.security.PrivilegedAction;
36
* An ObjectOutputStream subclass used by the MarshalledValue class to
37
* ensure the classes and proxies are loaded using the thread context
38
* class loader. Currently this does not do anything as neither class or
39
* proxy annotations are used.
41
* @author Scott.Stark@jboss.org
42
* @author Clebert.suconic@jboss.org - refactored packages only
43
* @version $Revision: 566 $
45
public class MarshalledValueOutputStream
46
extends ObjectOutputStream
49
* Creates a new instance of MarshalledValueOutputStream
50
* If there is a security manager installed, this method requires a
51
* SerializablePermission("enableSubstitution") permission to ensure it's
52
* ok to enable the stream to do replacement of objects in the stream.
54
public MarshalledValueOutputStream(OutputStream os) throws IOException
57
EnableReplaceObjectAction.enableReplaceObject(this);
61
* @throws java.io.IOException Any exception thrown by the underlying OutputStream.
63
protected void annotateClass(Class cl) throws IOException
65
super.annotateClass(cl);
69
* @throws java.io.IOException Any exception thrown by the underlying OutputStream.
71
protected void annotateProxyClass(Class cl) throws IOException
73
super.annotateProxyClass(cl);
77
* Override replaceObject to check for Remote objects that are
80
protected Object replaceObject(Object obj) throws IOException
82
if((obj instanceof Remote) && !(obj instanceof RemoteStub))
84
Remote remote = (Remote) obj;
87
obj = RemoteObject.toStub(remote);
89
catch(IOException ignore)
91
// Let the Serialization layer try with the orignal obj
97
private static class EnableReplaceObjectAction implements PrivilegedAction
99
MarshalledValueOutputStream os;
101
EnableReplaceObjectAction(MarshalledValueOutputStream os)
108
os.enableReplaceObject(true);
112
static void enableReplaceObject(MarshalledValueOutputStream os)
114
EnableReplaceObjectAction action = new EnableReplaceObjectAction(os);
115
AccessController.doPrivileged(action);