01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
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.
16: *
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.
21: */
22: package org.jboss.invocation.pooled.interfaces;
23:
24: import java.io.IOException;
25: import java.io.OutputStream;
26: import java.io.ObjectOutputStream;
27: import java.io.ObjectStreamClass;
28: import java.rmi.Remote;
29: import java.rmi.server.RemoteObject;
30: import java.rmi.server.RemoteStub;
31:
32: /**
33: * An ObjectOutputStream subclass used by the MarshalledValue class to
34: * ensure the classes and proxies are loaded using the thread context
35: * class loader. Currently this does not do anything as neither class or
36: * proxy annotations are used.
37: *
38: * @author Scott.Stark@jboss.org
39: * @author Clebert.Suconic@jboss.org
40: * @version $Revision: 57209 $
41: */
42: public class OptimizedObjectOutputStream extends ObjectOutputStream {
43:
44: /** Creates a new instance of MarshalledValueOutputStream
45: If there is a security manager installed, this method requires a
46: SerializablePermission("enableSubstitution") permission to ensure it's
47: ok to enable the stream to do replacement of objects in the stream.
48: */
49: public OptimizedObjectOutputStream(OutputStream os)
50: throws IOException {
51: super (os);
52: enableReplaceObject(true);
53: }
54:
55: /**
56: * Writes just the class name to this output stream.
57: *
58: * @param classdesc class description object
59: */
60: protected void writeClassDescriptor(ObjectStreamClass classdesc)
61: throws IOException {
62: if (CompatibilityVersion.pooledInvokerLegacy) {
63: writeUTF(classdesc.getName());
64: } else {
65: super .writeClassDescriptor(classdesc);
66: }
67: }
68:
69: /** Override replaceObject to check for Remote objects that are
70: not RemoteStubs.
71: */
72: protected Object replaceObject(Object obj) throws IOException {
73: if ((obj instanceof Remote) && !(obj instanceof RemoteStub)) {
74: Remote remote = (Remote) obj;
75: try {
76: obj = RemoteObject.toStub(remote);
77: } catch (IOException ignore) {
78: // Let the Serialization layer try with the orignal obj
79: }
80: }
81: return obj;
82: }
83: }
|