KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > aop > util > MarshalledValueOutputStream


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.aop.util;
23
24 import java.io.IOException JavaDoc;
25 import java.io.ObjectOutputStream JavaDoc;
26 import java.io.OutputStream JavaDoc;
27 import java.rmi.Remote JavaDoc;
28 import java.rmi.server.RemoteObject JavaDoc;
29 import java.rmi.server.RemoteStub JavaDoc;
30
31 /**
32  * An ObjectOutputStream subclass used by the MarshalledValue class to
33  * ensure the classes and proxies are loaded using the thread context
34  * class loader. Currently this does not do anything as neither class or
35  * proxy annotations are used.
36  *
37  * @author Scott.Stark@jboss.org
38  * @version $Revision: 37406 $
39  */

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

48    public MarshalledValueOutputStream(OutputStream JavaDoc os) throws IOException JavaDoc
49    {
50       super(os);
51       enableReplaceObject(true);
52    }
53
54    /**
55     * @throws java.io.IOException Any exception thrown by the underlying OutputStream.
56     */

57    protected void annotateClass(Class JavaDoc cl) throws IOException JavaDoc
58    {
59       super.annotateClass(cl);
60    }
61    
62    /**
63     * @throws java.io.IOException Any exception thrown by the underlying OutputStream.
64     */

65    protected void annotateProxyClass(Class JavaDoc cl) throws IOException JavaDoc
66    {
67       super.annotateProxyClass(cl);
68    }
69
70    /** Override replaceObject to check for Remote objects that are
71     not RemoteStubs.
72    */

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