KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > invocation > pooled > interfaces > OptimizedObjectOutputStream


1 /*
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.
6 *
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.
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 JavaDoc;
25 import java.io.OutputStream JavaDoc;
26 import java.io.ObjectOutputStream JavaDoc;
27 import java.io.ObjectStreamClass JavaDoc;
28 import java.rmi.Remote JavaDoc;
29 import java.rmi.server.RemoteObject JavaDoc;
30 import java.rmi.server.RemoteStub JavaDoc;
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: 44821 $
41  */

42 public class OptimizedObjectOutputStream
43    extends ObjectOutputStream JavaDoc
44 {
45     
46    /** Creates a new instance of MarshalledValueOutputStream
47     If there is a security manager installed, this method requires a
48     SerializablePermission("enableSubstitution") permission to ensure it's
49     ok to enable the stream to do replacement of objects in the stream.
50     */

51    public OptimizedObjectOutputStream(OutputStream JavaDoc os) throws IOException JavaDoc
52    {
53       super(os);
54       enableReplaceObject(true);
55    }
56
57    /**
58     * Writes just the class name to this output stream.
59     *
60     * @param classdesc class description object
61     */

62    protected void writeClassDescriptor(ObjectStreamClass JavaDoc classdesc)
63       throws IOException JavaDoc
64    {
65       if (CompatibilityVersion.pooledInvokerLegacy)
66       {
67           writeUTF(classdesc.getName());
68       }
69       else
70       {
71           super.writeClassDescriptor(classdesc);
72       }
73    }
74
75    /** Override replaceObject to check for Remote objects that are
76     not RemoteStubs.
77    */

78    protected Object JavaDoc replaceObject(Object JavaDoc obj) throws IOException JavaDoc
79    {
80       if( (obj instanceof Remote JavaDoc) && !(obj instanceof RemoteStub JavaDoc) )
81       {
82          Remote JavaDoc remote = (Remote JavaDoc) obj;
83          try
84          {
85             obj = RemoteObject.toStub(remote);
86          }
87          catch(IOException JavaDoc ignore)
88          {
89             // Let the Serialization layer try with the orignal obj
90
}
91       }
92       return obj;
93    }
94 }
95
Popular Tags